mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 01:21:56 +01:00
add WearableExtender with reply action to debug notification
(This is for testing new features)
This commit is contained in:
parent
ae5417b9cc
commit
803e58743a
@ -13,6 +13,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
import android.support.v4.app.RemoteInput;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@ -38,6 +39,10 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
|||||||
public class DebugActivity extends Activity {
|
public class DebugActivity extends Activity {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(DebugActivity.class);
|
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 sendSMSButton;
|
||||||
private Button sendEmailButton;
|
private Button sendEmailButton;
|
||||||
private Button incomingCallButton;
|
private Button incomingCallButton;
|
||||||
@ -56,8 +61,16 @@ public class DebugActivity extends Activity {
|
|||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction().equals(GBApplication.ACTION_QUIT)) {
|
switch (intent.getAction()) {
|
||||||
finish();
|
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);
|
setContentView(R.layout.activity_debug);
|
||||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
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);
|
editContent = (EditText) findViewById(R.id.editContent);
|
||||||
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
sendSMSButton = (Button) findViewById(R.id.sendSMSButton);
|
||||||
@ -216,7 +232,7 @@ public class DebugActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void importDB() {
|
private void importDB() {
|
||||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setTitle("Import Activity Data?")
|
.setTitle("Import Activity Data?")
|
||||||
.setMessage("Really overwrite the current activity database? All your activity data (if any) will be lost.")
|
.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() {
|
private void deleteActivityDatabase() {
|
||||||
AlertDialog dialog = new AlertDialog.Builder(this)
|
new AlertDialog.Builder(this)
|
||||||
.setCancelable(true)
|
.setCancelable(true)
|
||||||
.setTitle("Delete Activity Data?")
|
.setTitle("Delete Activity Data?")
|
||||||
.setMessage("Really delete the entire activity database? All your activity data will be lost.")
|
.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);
|
notificationIntent, 0);
|
||||||
|
|
||||||
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
|
|
||||||
ncomp.setContentTitle(getString(R.string.test_notification));
|
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY)
|
||||||
ncomp.setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
.build();
|
||||||
ncomp.setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge));
|
|
||||||
ncomp.setSmallIcon(R.drawable.ic_notification);
|
Intent replyIntent = new Intent(ACTION_REPLY);
|
||||||
ncomp.setAutoCancel(true);
|
|
||||||
ncomp.setContentIntent(pendingIntent);
|
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());
|
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user