Talking Reminder
this project is intenfed for people who are not tech savvy
NotificationHelper.java
1 package com.sudogeeks.talking_reminder;
2 
3 
4 import android.annotation.TargetApi;
5 import android.app.NotificationChannel;
6 import android.app.NotificationManager;
7 import android.app.PendingIntent;
8 import android.content.Context;
9 import android.content.ContextWrapper;
10 import android.content.Intent;
11 import android.graphics.BitmapFactory;
12 import android.os.Build;
13 import android.speech.tts.TextToSpeech;
14 
15 import androidx.core.app.NotificationCompat;
16 
20 public class NotificationHelper extends ContextWrapper {
21  public static final String channelID = "channelID";
22  public static final String channelName = "Channel Name";
23  String mTitle;
24  PendingIntent mClick;
25  private NotificationManager mManager;
26  private TextToSpeech t1;
27 
33  public NotificationHelper(Context base, Intent intent) {
34  super(base);
35  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
36  createChannel();
37  }
38  int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));
39 
40 
41  ReminderDatabase rb = new ReminderDatabase(base);
42  ReminderDO reminderDO = rb.getReminder(mReceivedID);
43  mTitle = reminderDO.getTitle();
44 
45  // Create intent to open ReminderEditActivity on notification click
46  Intent editIntent = new Intent(base, ReminderEditActivity.class);
47  editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
48  mClick = PendingIntent.getActivity(base, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
49 
50  }
51 
52  @TargetApi(Build.VERSION_CODES.O)
53  private void createChannel() {
54  NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
55 
56  getManager().createNotificationChannel(channel);
57  }
58 
59  public NotificationManager getManager() {
60  if (mManager == null) {
61  mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
62  }
63 
64  return mManager;
65  }
66 
71  public NotificationCompat.Builder getChannelNotification() {
72 
73 
74  //t1.speak(mTitle, TextToSpeech.QUEUE_FLUSH, null);
75 
76  // t1.synthesizeToFile(mTitle, null, "/SDCARD/speak1.wav");
77  //Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/sample");
78 
79  return new NotificationCompat.Builder(getApplicationContext(), channelID)
80  .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher))
81  .setSmallIcon(R.drawable.ic_alarm_on_white)
82  .setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
83  .setTicker(mTitle)
84  .setContentText(mTitle)
85  //.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
86  // .setSound(Uri.fromFile(new File("SDCARD/s1.mp3")))
87  //.setSound(null)
88  .setPriority(NotificationManager.IMPORTANCE_HIGH)
89  .setContentIntent(mClick)
90  .setAutoCancel(true)
91  .setOnlyAlertOnce(true);
92  }
93 
94  public TextToSpeech getTextToSpeech() {
95  return t1;
96  }
97 }
98 
99 //function
com.sudogeeks.talking_reminder.ReminderDatabase.getReminder
ReminderDO getReminder(int id)
Definition: ReminderDatabase.java:106
com.sudogeeks.talking_reminder.NotificationHelper.getChannelNotification
NotificationCompat.Builder getChannelNotification()
Definition: NotificationHelper.java:71
com.sudogeeks.talking_reminder.ReminderDO
Data Object class for Reminder This class conatins all the attributes of reminder.
Definition: ReminderDO.java:15
com.sudogeeks.talking_reminder.ReminderDatabase
Class to manage database This class is for managing the database.
Definition: ReminderDatabase.java:15
com.sudogeeks.talking_reminder.NotificationHelper
Class to implement notification This class is for implementing notification popup at alarm time.
Definition: NotificationHelper.java:20
com.sudogeeks.talking_reminder.NotificationHelper.NotificationHelper
NotificationHelper(Context base, Intent intent)
Definition: NotificationHelper.java:33
com.sudogeeks.talking_reminder.ReminderEditActivity
Java class for handling UI component of Edit reminder layout.
Definition: ReminderEditActivity.java:32