Merge pull request #882 from Bars107/wearnotification

Created method to send notifications to android wear
This commit is contained in:
vshcherb 2014-09-19 16:23:45 +02:00
commit 0e9d3278dd
3 changed files with 25 additions and 0 deletions

Binary file not shown.

View file

@ -9,6 +9,8 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.*;
@ -24,6 +26,7 @@ import net.osmand.plus.activities.SettingsGeneralActivity;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.voice.TTSCommandPlayerImpl;
import java.io.File;
import java.text.MessageFormat;

View file

@ -6,6 +6,10 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import android.app.Notification;
import android.app.PendingIntent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -27,8 +31,10 @@ import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
public final static String PEBBLE_ALERT = "PEBBLE_ALERT";
public final static String WEAR_ALERT = "WEAR_ALERT";
private static final class IntentStarter implements
DialogInterface.OnClickListener {
private final Context ctx;
@ -132,6 +138,22 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
log.info("Send message to pebble " + message);
}
public void sendAlertToAndroidWear(String message) {
int notificationId = 1;
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(mTtsContext)
.setSmallIcon(R.drawable.icon)
.setContentTitle(mTtsContext.getString(R.string.app_name))
.setContentText(message)
.setGroup(WEAR_ALERT);
// Get an instance of the NotificationManager service
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(mTtsContext);
// Build the notification and issues it with notification manager.
notificationManager.notify(notificationId, notificationBuilder.build());
}
private void initializeEngine(final Context ctx, final Activity act)
{
if (mTts != null && mTtsContext != ctx) {