mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-17 18:41:37 +01:00
Merge branch 'feature/prepare_notification' into develop
Fin de la préparation des notifications, reste à les mettres en place pour de vrai
This commit is contained in:
commit
6ae4f2f89e
7 changed files with 152 additions and 57 deletions
|
@ -3,6 +3,7 @@
|
||||||
package="net.foucry.pilldroid">
|
package="net.foucry.pilldroid">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
@ -48,6 +49,7 @@
|
||||||
android:parentActivityName=".MedicamentListActivity"
|
android:parentActivityName=".MedicamentListActivity"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
</activity>
|
</activity>
|
||||||
|
<receiver android:name=".NotificationPublisher" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -1,9 +1,15 @@
|
||||||
package net.foucry.pilldroid;
|
package net.foucry.pilldroid;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.Notification;
|
||||||
|
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.os.SystemClock;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
@ -62,11 +68,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 +173,20 @@ 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);
|
||||||
|
scheduleNotification(getNotification("10 second delay"), 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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 +261,41 @@ public class MedicamentListActivity extends AppCompatActivity {
|
||||||
recyclerView.setAdapter(mAdapter);
|
recyclerView.setAdapter(mAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void scheduleNotification(Notification notification, int delay) {
|
||||||
|
Intent notificationIntent = new Intent(this, NotificationPublisher.class);
|
||||||
|
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID,1);
|
||||||
|
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
|
||||||
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
long futureInMillis = SystemClock.elapsedRealtime() + delay;
|
||||||
|
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
|
||||||
|
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Notification getNotification(String content) {
|
||||||
|
Notification.Builder builder = new Notification.Builder(this);
|
||||||
|
builder.setContentTitle("Scheduled Notification");
|
||||||
|
builder.setContentText(content);
|
||||||
|
builder.setSmallIcon(R.mipmap.ic_launcher);
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
// 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
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package net.foucry.pilldroid;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Vibrator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by jfoucry on 6/23/16.
|
||||||
|
*/
|
||||||
|
public class NotificationPublisher extends BroadcastReceiver {
|
||||||
|
|
||||||
|
public static String NOTIFICATION_ID = "notification-id";
|
||||||
|
public static String NOTIFICATION = "notification";
|
||||||
|
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
Notification notification = intent.getParcelableExtra(NOTIFICATION);
|
||||||
|
int id = intent.getIntExtra(NOTIFICATION_ID,0);
|
||||||
|
notificationManager.notify(id, notification);
|
||||||
|
Vibrator vibrator = (Vibrator) context.getSystemService(context.VIBRATOR_SERVICE);
|
||||||
|
vibrator.vibrate(400);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,7 @@
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
<!-- Gradient Bg for listrow -->
|
<!-- Gradient Bg for listrow -->
|
||||||
<gradient
|
<gradient
|
||||||
android:startColor="#D4666E"
|
android:startColor="#FFD4666E"
|
||||||
android:centerColor="#BD1421"
|
android:endColor="#FFBD1421"
|
||||||
android:endColor="#D4666E"
|
|
||||||
android:angle="270" />
|
android:angle="270" />
|
||||||
</shape>
|
</shape>
|
|
@ -2,8 +2,7 @@
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
<!-- Gradient Bg for listrow -->
|
<!-- Gradient Bg for listrow -->
|
||||||
<gradient
|
<gradient
|
||||||
android:startColor="#048F01"
|
android:startColor="#FF048F01"
|
||||||
android:centerColor="#5CB65A"
|
android:endColor="#FF5CB65A"
|
||||||
android:endColor="#048F01"
|
android:angle="90" />
|
||||||
android:angle="270" />
|
|
||||||
</shape>
|
</shape>
|
|
@ -2,8 +2,7 @@
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||||
<!-- Gradient Bg for listrow -->
|
<!-- Gradient Bg for listrow -->
|
||||||
<gradient
|
<gradient
|
||||||
android:startColor="#F8A253"
|
android:startColor="#FFF8A253"
|
||||||
android:centerColor="#F7C01E"
|
android:endColor="#FFF7C01E"
|
||||||
android:endColor="#F8A253"
|
android:angle="90" />
|
||||||
android:angle="270" />
|
|
||||||
</shape>
|
</shape>
|
|
@ -1,63 +1,67 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="60dp"
|
android:layout_height="80dp"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout android:id="@+id/thumbnail"
|
<!-- Drug's name-->
|
||||||
android:layout_width="wrap_content"
|
<RelativeLayout
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:padding="3dip"
|
android:layout_height="match_parent">
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:background="@android:color/transparent"
|
|
||||||
android:layout_marginRight="0sp">
|
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/list_image"
|
android:id="@+id/list_image"
|
||||||
android:layout_width="50sp"
|
android:layout_width="50sp"
|
||||||
android:layout_height="50sp"
|
android:layout_height="50sp"
|
||||||
android:layout_marginLeft="5dp"
|
android:layout_marginLeft="5dp"
|
||||||
android:layout_marginTop="2dp"
|
android:src="@drawable/stock_ok"
|
||||||
android:src="@drawable/stock_ok" />
|
android:contentDescription="Icone de stock"
|
||||||
</LinearLayout>
|
android:layout_centerVertical="true"
|
||||||
<!-- Drug's name-->
|
android:layout_alignParentStart="true" />
|
||||||
<TextView
|
|
||||||
android:id="@+id/valeur"
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/valeur"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_alignTop="@+id/thumbnail"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toRightOf="@+id/thumbnail"
|
android:text="Nom Médicament"
|
||||||
android:text="Nom Médicament"
|
android:textColor="#040404"
|
||||||
android:textColor="#040404"
|
android:typeface="sans"
|
||||||
android:typeface="sans"
|
android:textSize="16sp"
|
||||||
android:textSize="16sp"
|
android:textStyle="bold"
|
||||||
android:textStyle="bold"/>
|
android:layout_alignTop="@+id/list_image"
|
||||||
|
android:layout_toEndOf="@+id/list_image"
|
||||||
|
android:layout_marginLeft="5dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/cip13"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="#343434"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:text="cip13 goes here"
|
||||||
|
android:layout_below="@+id/valeur"
|
||||||
|
android:layout_toEndOf="@+id/list_image"
|
||||||
|
android:layout_marginLeft="5dp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/endOfStock"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="right"
|
||||||
|
android:text="lundi 1 janvier 2001"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="#212121"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="30dp"
|
||||||
|
android:layout_marginBottom="5dp" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<!-- CIP 13 (should change) -->
|
<!-- CIP 13 (should change) -->
|
||||||
<TextView
|
|
||||||
android:id="@+id/cip13"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/valeur"
|
|
||||||
android:textColor="#343434"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:layout_marginTop="1sp"
|
|
||||||
android:layout_toRightOf="@+id/thumbnail"
|
|
||||||
android:text="cip13 goes here" />
|
|
||||||
|
|
||||||
<!-- dateEndOfStock -->
|
<!-- dateEndOfStock -->
|
||||||
<TextView
|
|
||||||
android:id="@+id/endOfStock"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignTop="@id/valeur"
|
|
||||||
android:gravity="right"
|
|
||||||
android:text="lundi 1 janvier 2001"
|
|
||||||
android:layout_marginRight="15dp"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:textColor="#212121"
|
|
||||||
android:textStyle="bold"/>
|
|
||||||
|
|
||||||
<!-- Rightend Arrow -->
|
<!-- Rightend Arrow -->
|
||||||
<ImageView android:layout_width="wrap_content"
|
<ImageView android:layout_width="wrap_content"
|
||||||
|
@ -66,4 +70,5 @@
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginRight="10sp"/>
|
android:layout_marginRight="10sp"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in a new issue