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">
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -48,6 +49,7 @@
|
|||
android:parentActivityName=".MedicamentListActivity"
|
||||
android:theme="@style/AppTheme">
|
||||
</activity>
|
||||
<receiver android:name=".NotificationPublisher" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,9 +1,15 @@
|
|||
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.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
@ -62,11 +68,20 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
private View mRecyclerView;
|
||||
private SimpleItemRecyclerViewAdapter mAdapter;
|
||||
|
||||
// For the notifications
|
||||
PendingIntent pendingIntent;
|
||||
AlarmManager alarmManager;
|
||||
BroadcastReceiver mReceiver;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_medicament_list);
|
||||
|
||||
// Register for alarm
|
||||
|
||||
// RegisterAlarmBroadcast();
|
||||
|
||||
dbHelper = new DBHelper(this);
|
||||
dbMedoc = new DBMedoc(this);
|
||||
|
||||
|
@ -158,7 +173,20 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
}
|
||||
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) {
|
||||
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
|
||||
//intent.putExtra("SCAN_MODE", "CODE_128");
|
||||
|
@ -233,6 +261,41 @@ public class MedicamentListActivity extends AppCompatActivity {
|
|||
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
|
||||
*/
|
||||
|
|
|
@ -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">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#D4666E"
|
||||
android:centerColor="#BD1421"
|
||||
android:endColor="#D4666E"
|
||||
android:startColor="#FFD4666E"
|
||||
android:endColor="#FFBD1421"
|
||||
android:angle="270" />
|
||||
</shape>
|
|
@ -2,8 +2,7 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#048F01"
|
||||
android:centerColor="#5CB65A"
|
||||
android:endColor="#048F01"
|
||||
android:angle="270" />
|
||||
android:startColor="#FF048F01"
|
||||
android:endColor="#FF5CB65A"
|
||||
android:angle="90" />
|
||||
</shape>
|
|
@ -2,8 +2,7 @@
|
|||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<!-- Gradient Bg for listrow -->
|
||||
<gradient
|
||||
android:startColor="#F8A253"
|
||||
android:centerColor="#F7C01E"
|
||||
android:endColor="#F8A253"
|
||||
android:angle="270" />
|
||||
android:startColor="#FFF8A253"
|
||||
android:endColor="#FFF7C01E"
|
||||
android:angle="90" />
|
||||
</shape>
|
|
@ -1,63 +1,67 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="60dp"
|
||||
android:layout_height="80dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout android:id="@+id/thumbnail"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="3dip"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_marginRight="0sp">
|
||||
<!-- Drug's name-->
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/list_image"
|
||||
android:layout_width="50sp"
|
||||
android:layout_height="50sp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:src="@drawable/stock_ok" />
|
||||
</LinearLayout>
|
||||
<!-- Drug's name-->
|
||||
<TextView
|
||||
android:id="@+id/valeur"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@+id/thumbnail"
|
||||
android:layout_toRightOf="@+id/thumbnail"
|
||||
android:text="Nom Médicament"
|
||||
android:textColor="#040404"
|
||||
android:typeface="sans"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"/>
|
||||
android:src="@drawable/stock_ok"
|
||||
android:contentDescription="Icone de stock"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/valeur"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Nom Médicament"
|
||||
android:textColor="#040404"
|
||||
android:typeface="sans"
|
||||
android:textSize="16sp"
|
||||
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) -->
|
||||
<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 -->
|
||||
<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 -->
|
||||
<ImageView android:layout_width="wrap_content"
|
||||
|
@ -66,4 +70,5 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="10sp"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in a new issue