2015-01-07 14:00:18 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.Intent;
|
2015-01-18 22:44:38 +01:00
|
|
|
import android.content.SharedPreferences;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.os.Bundle;
|
2015-01-18 22:44:38 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.support.v4.app.NotificationCompat;
|
|
|
|
import android.support.v7.app.ActionBarActivity;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class ControlCenter extends ActionBarActivity {
|
|
|
|
// SPP Serial Device UUID
|
|
|
|
private static final UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
|
|
|
|
|
|
|
|
Button sendButton;
|
|
|
|
Button testNotificationButton;
|
2015-01-12 00:35:15 +01:00
|
|
|
Button startServiceButton;
|
2015-01-18 01:10:44 +01:00
|
|
|
Button setTimeButton;
|
2015-01-07 14:00:18 +01:00
|
|
|
EditText editTitle;
|
|
|
|
EditText editContent;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_controlcenter);
|
|
|
|
|
|
|
|
|
|
|
|
editTitle = (EditText) findViewById(R.id.editTitle);
|
|
|
|
editContent = (EditText) findViewById(R.id.editContent);
|
2015-01-12 00:35:15 +01:00
|
|
|
startServiceButton = (Button) findViewById(R.id.startServiceButton);
|
|
|
|
startServiceButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
2015-01-18 01:10:44 +01:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
|
2015-01-12 00:35:15 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
2015-01-07 14:00:18 +01:00
|
|
|
sendButton = (Button) findViewById(R.id.sendButton);
|
|
|
|
sendButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-01-12 00:35:15 +01:00
|
|
|
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
2015-01-24 12:21:15 +01:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC);
|
2015-01-12 00:35:15 +01:00
|
|
|
startIntent.putExtra("notification_title", editTitle.getText().toString());
|
2015-01-24 12:21:15 +01:00
|
|
|
startIntent.putExtra("notification_body", editContent.getText().toString());
|
2015-01-12 00:35:15 +01:00
|
|
|
startService(startIntent);
|
2015-01-18 01:10:44 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
setTimeButton = (Button) findViewById(R.id.setTimeButton);
|
|
|
|
setTimeButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_SETTIME);
|
|
|
|
startService(startIntent);
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
});
|
2015-01-12 00:35:15 +01:00
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
testNotificationButton = (Button) findViewById(R.id.testNotificationButton);
|
|
|
|
testNotificationButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
testNotification();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-18 22:44:38 +01:00
|
|
|
/*
|
|
|
|
* Ask for permission to intercept notifications on first run.
|
|
|
|
* TODO: allow re-request in preferences
|
|
|
|
*/
|
|
|
|
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
if (sharedPrefs.getBoolean("firstrun", true)) {
|
|
|
|
sharedPrefs.edit().putBoolean("firstrun", false).commit();
|
|
|
|
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
|
|
|
startActivity(enableIntent);
|
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void testNotification() {
|
|
|
|
NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
|
NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this);
|
|
|
|
ncomp.setContentTitle("Test Notification");
|
|
|
|
ncomp.setContentText("This is a Test Notification from Gadgetbridge");
|
2015-01-12 00:35:15 +01:00
|
|
|
ncomp.setTicker("This is a Test Notification from Gadgetbridge");
|
2015-01-07 14:00:18 +01:00
|
|
|
ncomp.setSmallIcon(R.drawable.ic_launcher);
|
|
|
|
ncomp.setAutoCancel(true);
|
|
|
|
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
// Handle action bar item clicks here. The action bar will
|
|
|
|
// automatically handle clicks on the Home/Up button, so long
|
|
|
|
// as you specify a parent activity in AndroidManifest.xml.
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
//noinspection SimplifiableIfStatement
|
|
|
|
if (id == R.id.action_settings) {
|
|
|
|
//Intent intent = new Intent(this, SettingsActivity.class);
|
|
|
|
//startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|