From 803e58743a3738b3231e86cf35fe2194269b889e Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Sat, 9 Jan 2016 15:33:18 +0100 Subject: [PATCH] add WearableExtender with reply action to debug notification (This is for testing new features) --- .../activities/DebugActivity.java | 57 +++++++++++++++---- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java index 51c5235b..a4fbe772 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DebugActivity.java @@ -13,6 +13,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.os.Bundle; import android.support.v4.app.NavUtils; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.RemoteInput; import android.view.MenuItem; import android.view.View; import android.widget.Button; @@ -38,6 +39,10 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB; public class DebugActivity extends Activity { private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class); + private static final String EXTRA_REPLY = "reply"; + private static final String ACTION_REPLY + = "nodomain.freeyourgadget.gadgetbridge.DebugActivity.action.reply"; + private Button sendSMSButton; private Button sendEmailButton; private Button incomingCallButton; @@ -56,8 +61,16 @@ public class DebugActivity extends Activity { private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(GBApplication.ACTION_QUIT)) { - finish(); + switch (intent.getAction()) { + case GBApplication.ACTION_QUIT: + finish(); + break; + case ACTION_REPLY: + Bundle remoteInput = RemoteInput.getResultsFromIntent(intent); + CharSequence reply = remoteInput.getCharSequence(EXTRA_REPLY); + LOG.info("got wearable reply: " + reply); + GB.toast(context, "got wearable reply: " + reply, Toast.LENGTH_SHORT, GB.INFO); + break; } } }; @@ -68,7 +81,10 @@ public class DebugActivity extends Activity { setContentView(R.layout.activity_debug); getActionBar().setDisplayHomeAsUpEnabled(true); - registerReceiver(mReceiver, new IntentFilter(GBApplication.ACTION_QUIT)); + IntentFilter filter = new IntentFilter(); + filter.addAction(GBApplication.ACTION_QUIT); + filter.addAction(ACTION_REPLY); + registerReceiver(mReceiver, filter); editContent = (EditText) findViewById(R.id.editContent); sendSMSButton = (Button) findViewById(R.id.sendSMSButton); @@ -216,7 +232,7 @@ public class DebugActivity extends Activity { } private void importDB() { - AlertDialog dialog = new AlertDialog.Builder(this) + new AlertDialog.Builder(this) .setCancelable(true) .setTitle("Import Activity Data?") .setMessage("Really overwrite the current activity database? All your activity data (if any) will be lost.") @@ -251,7 +267,7 @@ public class DebugActivity extends Activity { } private void deleteActivityDatabase() { - AlertDialog dialog = new AlertDialog.Builder(this) + new AlertDialog.Builder(this) .setCancelable(true) .setTitle("Delete Activity Data?") .setMessage("Really delete the entire activity database? All your activity data will be lost.") @@ -281,13 +297,30 @@ public class DebugActivity extends Activity { notificationIntent, 0); NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this); - ncomp.setContentTitle(getString(R.string.test_notification)); - ncomp.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge)); - ncomp.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge)); - ncomp.setSmallIcon(R.drawable.ic_notification); - ncomp.setAutoCancel(true); - ncomp.setContentIntent(pendingIntent); + + RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY) + .build(); + + Intent replyIntent = new Intent(ACTION_REPLY); + + PendingIntent replyPendingIntent = PendingIntent.getBroadcast(this, 0, replyIntent, 0); + + NotificationCompat.Action action = + new NotificationCompat.Action.Builder(android.R.drawable.ic_input_add, "Reply", replyPendingIntent) + .addRemoteInput(remoteInput) + .build(); + + NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(action); + + NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this) + .setContentTitle(getString(R.string.test_notification)) + .setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge)) + .setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge)) + .setSmallIcon(R.drawable.ic_notification) + .setAutoCancel(true) + .setContentIntent(pendingIntent) + .extend(wearableExtender); + nManager.notify((int) System.currentTimeMillis(), ncomp.build()); }