mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-17 18:41:37 +01:00
Ajout du début des notifications
This commit is contained in:
parent
49a3583264
commit
4d99698930
1 changed files with 43 additions and 1 deletions
|
@ -1,8 +1,12 @@
|
||||||
package net.foucry.pilldroid;
|
package net.foucry.pilldroid;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -62,11 +66,20 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
private View mRecyclerView;
|
private View mRecyclerView;
|
||||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
|
// For the notifications
|
||||||
|
PendingIntent pendingIntent;
|
||||||
|
AlarmManager alarmManager;
|
||||||
|
BroadcastReceiver mReceiver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_medicament_list);
|
setContentView(R.layout.activity_medicament_list);
|
||||||
|
|
||||||
|
// Register for alarm
|
||||||
|
|
||||||
|
RegisterAlarmBroadcast();
|
||||||
|
|
||||||
dbHelper = new DBHelper(this);
|
dbHelper = new DBHelper(this);
|
||||||
dbMedoc = new DBMedoc(this);
|
dbMedoc = new DBMedoc(this);
|
||||||
|
|
||||||
|
@ -158,7 +171,19 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
|
||||||
|
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onDestroy() {
|
||||||
|
unregisterReceiver(mReceiver);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
public void scanNow(View view) {
|
public void scanNow(View view) {
|
||||||
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
||||||
//intent.putExtra("SCAN_MODE", "CODE_128");
|
//intent.putExtra("SCAN_MODE", "CODE_128");
|
||||||
|
@ -233,6 +258,23 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Received Alarm, display a toast
|
||||||
|
private void RegisterAlarmBroadcast() {
|
||||||
|
mReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
Toast.makeText(context, "Vous devez passer à la pharmacie", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registerReceiver(mReceiver, new IntentFilter("net.foucry.pilldroid"));
|
||||||
|
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent("net.foucry.pilldroid"),0);
|
||||||
|
alarmManager = (AlarmManager)(this.getSystemService(Context.ALARM_SERVICE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnregisterAlarmBroadcast(){
|
||||||
|
alarmManager.cancel(pendingIntent);
|
||||||
|
getBaseContext().unregisterReceiver(mReceiver);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* SimpleItemRecyclerViewAdapter
|
* SimpleItemRecyclerViewAdapter
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue