Commit 65475998 authored by RAUSHAN RAJ's avatar RAUSHAN RAJ

Commit to main branch.

Merge branch 'voice_feature'

# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/com/blanyal/remindme/NotificationHelper.java
#	app/src/main/java/com/blanyal/remindme/ReminderAddActivity.java
#	app/src/main/res/values/strings.xml
parent 699192f2
......@@ -4,6 +4,7 @@
package="com.blanyal.remindme">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
......@@ -11,8 +12,7 @@
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:icon,android:theme">
<activity android:name=".ReadTheMessage"></activity>
<activity android:name=".ReminderReceiveActivity">
<intent-filter>
......@@ -46,10 +46,11 @@
android:name=".ReminderEditActivity"
android:label="@string/activity_edit_reminder_label" />
<receiver android:name=".AlarmReceiver" />
<receiver android:name=".AlarmReceiver"/>
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
......@@ -64,6 +65,10 @@
android:resource="@xml/file_paths">
</meta-data>
</provider>
<service
android:name=".ReadTheMessage"
android:enabled="true" />
</application>
</manifest>
......@@ -42,12 +42,22 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));
//
//Get notification title from Reminder Database
ReminderDatabase rb = new ReminderDatabase(context);
Reminder reminder = rb.getReminder(mReceivedID);
String mTitle = reminder.getTitle();
// Create intent to open ReminderEditActivity on notification click
Intent editIntent = new Intent(context, ReminderEditActivity.class);
editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
......@@ -68,8 +78,44 @@ public class AlarmReceiver extends BroadcastReceiver {
// NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// nManager.notify(mReceivedID, mBuilder.build());
NotificationHelper notificationHelper = new NotificationHelper(context,intent);
NotificationCompat.Builder nb = notificationHelper.getChannelNotification();
notificationHelper.getManager().notify(mReceivedID, nb.build());
// tts
// context.startService(new Intent(context, ReadTheMessage.class));
Intent i = new Intent(context, ReadTheMessage.class);
i.putExtra("MyTitle", mTitle);
context.startService(i);
context.startService(i);
context.startService(i);
//context.startService(new Intent(context, ReadTheMessage.class));
// Intent speechIntent = new Intent();
// speechIntent.setClass(context, ReadTheMessage.class);
// speechIntent.putExtra("MESSAGE",mTitle );
// speechIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
// context.startActivity(speechIntent);
////
// Intent speechIntent = new Intent();
// speechIntent.putExtra("MESSAGE", "Bluetooth is on.");
// ReadTheMessage.enqueueWork(context, speechIntent);
//
}
public void setAlarm(Context context, Calendar calendar, int ID) {
......
......@@ -7,14 +7,19 @@ import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.speech.tts.TextToSpeech;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
public class NotificationHelper extends ContextWrapper {
......@@ -23,7 +28,12 @@ public class NotificationHelper extends ContextWrapper {
String mTitle;
PendingIntent mClick;
private NotificationManager mManager;
private TextToSpeech t1;
// public Uri getFileUri(){
//
//
// return
// }
public NotificationHelper(Context base,Intent intent) {
super(base);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......@@ -59,17 +69,31 @@ public class NotificationHelper extends ContextWrapper {
}
public NotificationCompat.Builder getChannelNotification() {
return new NotificationCompat.Builder(getApplicationContext(), channelID)
//t1.speak(mTitle, TextToSpeech.QUEUE_FLUSH, null);
// t1.synthesizeToFile(mTitle, null, "/SDCARD/speak1.wav");
//Uri alarmSound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/sample");
return new NotificationCompat.Builder(getApplicationContext(), channelID)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.ic_alarm_on_white_24dp)
.setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
.setTicker(mTitle)
.setContentText(mTitle)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
//.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
// .setSound(Uri.fromFile(new File("SDCARD/s1.mp3")))
//.setSound(null)
.setPriority(NotificationManager.IMPORTANCE_LOW)
.setContentIntent(mClick)
.setAutoCancel(true)
.setOnlyAlertOnce(true);
}
public TextToSpeech getTextToSpeech(){
return t1;
}
}
//function
\ No newline at end of file
package com.blanyal.remindme;
import android.app.Activity;
import android.app.Service;
import android.os.Bundle;
import android.os.IBinder;
import android.speech.tts.TextToSpeech;
import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
import android.os.SystemClock;
import java.util.Locale;
public class ReadTheMessage extends Service implements TextToSpeech.OnInitListener, TextToSpeech.OnUtteranceCompletedListener {
private TextToSpeech mTts;
private String spokenText;
@Override
public void onCreate() {
mTts = new TextToSpeech(this, this);
// This is a good place to set spokenText
// spokenText="raushan raushan raushan raushan";
}
@Override
public int onStartCommand (Intent intent, int flags, int startId) {
spokenText = intent.getStringExtra("MyTitle");
return START_STICKY;
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = mTts.setLanguage(Locale.US);
if (result != TextToSpeech.LANG_MISSING_DATA && result != TextToSpeech.LANG_NOT_SUPPORTED) {
mTts.speak(spokenText, TextToSpeech.QUEUE_ADD, null);
}
}
}
@Override
public void onUtteranceCompleted(String uttId) {
stopSelf();
}
@Override
public void onDestroy() {
if (mTts != null) {
mTts.stop();
mTts.shutdown();
}
super.onDestroy();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Switch;
......@@ -387,9 +388,7 @@ public class ReminderAddActivity extends AppCompatActivity {
}
}
try {
String fileContents = gson.toJson(talkingReminder);
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(fileContents.getBytes());
......@@ -486,7 +485,6 @@ public class ReminderAddActivity extends AppCompatActivity {
}
return true;
// On clicking discard reminder button
// Discard any changes
case R.id.discard_reminder:
......
......@@ -102,8 +102,8 @@ public class ReminderEditActivity extends AppCompatActivity {
mRepeatText = (TextView) findViewById(R.id.set_repeat);
mRepeatNoText = (TextView) findViewById(R.id.set_repeat_no);
mRepeatTypeText = (TextView) findViewById(R.id.set_repeat_type);
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
// mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
//mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mRepeatSwitch = (Switch) findViewById(R.id.repeat_switch);
// Setup Toolbar
......@@ -191,15 +191,15 @@ public class ReminderEditActivity extends AppCompatActivity {
mActive = savedInstanceState.getString(KEY_ACTIVE);
}
// Setup up active buttons
if (mActive.equals("false")) {
mFAB1.show();
mFAB2.hide();
} else if (mActive.equals("true")) {
mFAB1.hide();
mFAB2.show();
}
// // Setup up active buttons
// if (mActive.equals("false")) {
// mFAB1.show();
// mFAB2.hide();
//
// } else if (mActive.equals("true")) {
// mFAB1.hide();
// mFAB2.show();
// }
// Setup repeat switch
if (mRepeat.equals("false")) {
......@@ -309,22 +309,22 @@ public class ReminderEditActivity extends AppCompatActivity {
// }
// On clicking the active button
public void selectFab1(View v) {
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB1.hide();
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mFAB2.show();
mActive = "true";
}
// On clicking the inactive button
public void selectFab2(View v) {
mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
mFAB2.hide();
mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
mFAB1.show();
mActive = "false";
}
// public void selectFab1(View v) {
// mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
// mFAB1.hide();
// mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
// mFAB2.show();
// mActive = "true";
// }
//
// // On clicking the inactive button
// public void selectFab2(View v) {
// mFAB2 = (FloatingActionButton) findViewById(R.id.starred2);
// mFAB2.hide();
// mFAB1 = (FloatingActionButton) findViewById(R.id.starred1);
// mFAB1.show();
// mActive = "false";
// }
// On clicking the repeat switch
public void onSwitchRepeat(View view) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment