Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f831dcf
Merge pull request #1 from RbkGh/testHotWord
RbkGh Jan 17, 2017
e7ed349
Merge pull request #2 from RbkGh/testHotWord
RbkGh Jan 20, 2017
6662194
Added Notification Activity Handler
RbkGh Jan 20, 2017
3d62fc1
Added oncreate with dummy data
RbkGh Jan 20, 2017
63c0f0f
Added onclick handler for button in sticky notif,untested
RbkGh Jan 20, 2017
8c3732e
Added voice message to alert that voice assistant is fetching daily text
RbkGh Jan 21, 2017
4c364f2
Added fetch of daily text and reading method.Untested
RbkGh Jan 21, 2017
a7a3fa7
Added Asynctask inline ,refine later
RbkGh Jan 21, 2017
7a15d62
Added AsyncTask to retrieve dailyText and read,untested
RbkGh Jan 21, 2017
406f1e2
Fixed internet permission denied error,able to grab and read days tex…
RbkGh Jan 21, 2017
d393219
Fully working DailyTextVoice,fix other issues later
RbkGh Jan 21, 2017
3be0c02
Converted to WakefulBroadCast Service,hence reading takes place witho…
RbkGh Jan 21, 2017
a1b41ca
Minor Changes,Working Fully
RbkGh Jan 21, 2017
2640dd2
Minor Changes,Removed start speech until how to wait properly on asyn…
RbkGh Jan 21, 2017
425f3a6
Added Stop Onclick to stop playback
RbkGh Jan 21, 2017
84e1fc6
Export NotifHandler service in AndroidManifest,updated logic for butt…
RbkGh Jan 22, 2017
3707a92
Changed speech Rate to 0.8 ,which is more human friendly
RbkGh Jan 29, 2017
68fdba8
Added Fix for stop button not stoppin tts on lollipop.
RbkGh Feb 2, 2017
a2094d3
Added OnBootCompleted Listener to start sticky notification service
RbkGh Feb 2, 2017
2a214e8
Added voice message alert to show internet unavailability and other m…
RbkGh Feb 2, 2017
89f8555
Added sample screenshots
RbkGh Feb 3, 2017
f7d21bf
Set theme jekyll-theme-cayman
RbkGh Feb 3, 2017
dcb37af
Set theme jekyll-theme-architect
RbkGh Feb 3, 2017
f96875f
Updated readme
RbkGh Feb 3, 2017
72b80c6
Merge branch 'master' of https://github.com/RbkGh/DailyText-Voice
RbkGh Feb 3, 2017
e2c774a
Minor updates to readme
RbkGh Feb 3, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-architect
31 changes: 27 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swiftpot.dailytextvoice">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<service android:name=".services.HotWordDetectorService" android:enabled="true" android:exported="false"></service>


<service
android:name=".services.HotWordDetectorService"
android:enabled="true"
android:exported="false"></service>
<receiver android:name=".services.TaskWakefulBroadcastReciever"></receiver>

<activity
android:name=".SettingsActivity"
android:label="@string/app_name">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<action android:name="android.intent.action.MAIN" />-->

<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--<category android:name="android.intent.category.LAUNCHER" />-->
<!--</intent-filter>-->
</activity>
<activity
Expand All @@ -30,6 +39,20 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver
android:name=".NotificationActivityHandler"
android:enabled="true"
android:exported="true">
</receiver>
<receiver
android:name=".NotificationBarServiceStarter"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>

</manifest>
65 changes: 64 additions & 1 deletion app/src/main/java/com/swiftpot/dailytextvoice/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,83 @@
package com.swiftpot.dailytextvoice;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;


public class HomeActivity extends AppCompatActivity {
public class HomeActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback{

private final int MY_PERMISSIONS_REQUEST_INTERNET = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
checkInternetPermission();


}


@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_INTERNET: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

// permission was granted, yay! Do the
// contacts-related task you need to do.

} else {

// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}

// other 'case' lines to check for other
// permissions this app might request
}
}

void checkInternetPermission(){
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {

// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.INTERNET)) {

// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.

} else {

// No explanation needed, we can request the permission.

ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.INTERNET},
MY_PERMISSIONS_REQUEST_INTERNET);

// MY_PERMISSIONS_REQUEST_INTERNET is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.swiftpot.dailytextvoice;/**
* Created by Ace Programmer Rbk<rodney@swiftpot.com> on 20-Jan-17
* 11:30 PM
*/

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.util.Log;
import android.widget.Toast;

import com.swiftpot.dailytext.crawler.DailyTextCrawler;
import com.swiftpot.dailytext.crawler.models.DailyTextEntity;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
* Created by Ace Programmer Rbk<rodney@swiftpot.com> on 20-Jan-17
* 11:30 PM
*/
public class NotificationActivityHandler extends WakefulBroadcastReceiver {
TextToSpeech textToSpeech = null;
private static String DEFAULT_DATE_PATTERN_EXPECTED = "yyyy/MM/dd";

@Override
public void onReceive(final Context context, Intent intent) {
Log.i("LOG", "Here now,yet to process number");
String action = (String) intent.getExtras().get("PLAY_DAILY_TEXT");
Log.i("LOG", "launching action: " + action);
assert action != null;
if (action.equals("1")) {
String acknowledgedMessage = "Hello ,a moment please,I'm getting today's text online..";
Toast.makeText(context, acknowledgedMessage, Toast.LENGTH_SHORT).show();

//talk(acknowledgedMessage, context);

//use asynctask inline,not suitable for production
new AsyncTask<Void, Void, DailyTextEntity>() {
DailyTextEntity dailyTextEntity;

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
protected void onPostExecute(DailyTextEntity dailyTextEntity) {
super.onPostExecute(dailyTextEntity);
if (dailyTextEntity == null) {
talk("Please ensure you have internet and try again.", context);
} else {
String startingSpeech = "Today's text : ";
String theme = dailyTextEntity.getDailyTextTheme();
String body = dailyTextEntity.getDailyTextMsgBody();
talk(startingSpeech + theme + body, context);
}
}

@Override
protected DailyTextEntity doInBackground(Void... voids) {
DailyTextCrawler dailyTextCrawler = new DailyTextCrawler();
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN_EXPECTED);
String dateInExpectedFormat = simpleDateFormat.format(date);
Log.d("LOG", "dateInExpectedFormat: " + dateInExpectedFormat);
try {
dailyTextEntity = dailyTextCrawler.crawlForDailyText(dateInExpectedFormat);

} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return dailyTextEntity;
}
}.execute();


} else if (action.equals("2")) {
stopTalking(context);
} else {
//start athe main intent if required
}
completeWakefulIntent(intent);
}


void talk(final String speech, Context context) {
if (getTextToSpeech() != null) {
speak(speech);
} else {
textToSpeech = new TextToSpeech(context.getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
textToSpeech.setSpeechRate((float) 0.8);
textToSpeech.setLanguage(Locale.US);
if (status != TextToSpeech.ERROR) {
speak(speech);
}

}
});
setTextToSpeech(textToSpeech);
}

}

void stopTalking(Context context) {
if (textToSpeech != null) {
textToSpeech.stop();
textToSpeech.shutdown();
} else {
textToSpeech.shutdown();
}
}

/**
* ensure deprecation in lollipop still runs
*
* @param text
*/
private void speak(String text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
} else {
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}

public TextToSpeech getTextToSpeech() {
return textToSpeech;
}

public void setTextToSpeech(TextToSpeech textToSpeech) {
this.textToSpeech = textToSpeech;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.swiftpot.dailytextvoice;/**
* Created by Ace Programmer Rbk<rodney@swiftpot.com> on 02-Feb-17
* 7:05 AM
*/

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

import com.swiftpot.dailytextvoice.fragments.HomeActivityFragment;

/**
* Created by Ace Programmer Rbk<rodney@swiftpot.com> on 02-Feb-17
* 7:05 AM Use to acknowledge boot completed to set sticky notif.
*/
public class NotificationBarServiceStarter extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == "android.intent.action.BOOT_COMPLETED") {
HomeActivityFragment.setStickyNotification(context);
}
completeWakefulIntent(intent);
}
}
Loading