mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-17 18:41:37 +01:00
Mise en place du TimeManager
This commit is contained in:
parent
61b0f08d76
commit
d707d4178d
3 changed files with 59 additions and 0 deletions
|
@ -43,6 +43,7 @@
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service android:name=".TimeService"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -71,6 +71,8 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
toolbar.setTitle(getTitle());
|
toolbar.setTitle(getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startService(new Intent(this, TimeService.class));
|
||||||
|
|
||||||
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
fab.setOnClickListener(new View.OnClickListener() {
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
56
app/src/main/java/net/foucry/pilldroid/TimeService.java
Normal file
56
app/src/main/java/net/foucry/pilldroid/TimeService.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package net.foucry.pilldroid;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by jacques on 22/08/16.
|
||||||
|
*/
|
||||||
|
public class TimeService extends Service {
|
||||||
|
public static final long NOTIFY_INTERVAL = 10 *1000;
|
||||||
|
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
private Timer mTimer = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
if(mTimer != null) {
|
||||||
|
mTimer.cancel();
|
||||||
|
} else {
|
||||||
|
mTimer = new Timer();
|
||||||
|
}
|
||||||
|
|
||||||
|
mTimer.scheduleAtFixedRate(new TimeDisplayTimerTask(),0, NOTIFY_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TimeDisplayTimerTask extends TimerTask {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(getApplicationContext(),getDateTime(), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDateTime() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("[yyyy/MM/dd - HH:mm:ss]");
|
||||||
|
return sdf.format(new Date());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue