2015-01-07 14:00:18 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge;
|
|
|
|
|
|
|
|
import android.app.NotificationManager;
|
2015-02-06 13:55:44 +01:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-01-07 14:00:18 +01:00
|
|
|
import android.content.Intent;
|
2015-02-06 13:55:44 +01:00
|
|
|
import android.content.IntentFilter;
|
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;
|
|
|
|
|
|
|
|
public class ControlCenter extends ActionBarActivity {
|
2015-02-06 13:55:44 +01:00
|
|
|
|
|
|
|
public static final String ACTION_QUIT
|
|
|
|
= "nodomain.freeyourgadget.gadgetbride.controlcenter.action.quit";
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2015-01-12 00:35:15 +01:00
|
|
|
Button startServiceButton;
|
2015-01-07 14:00:18 +01:00
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.getAction().equals(ACTION_QUIT)) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-07 14:00:18 +01:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_controlcenter);
|
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
registerReceiver(mReceiver, new IntentFilter(ACTION_QUIT));
|
2015-01-07 14:00:18 +01:00
|
|
|
|
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-02-06 13:55:44 +01:00
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_CONNECT);
|
2015-01-12 00:35:15 +01:00
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
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-02-06 13:55:44 +01:00
|
|
|
Intent startIntent = new Intent(ControlCenter.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_START);
|
|
|
|
startService(startIntent);
|
|
|
|
|
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) {
|
2015-03-06 14:00:56 +01:00
|
|
|
Intent intent = new Intent(this, SettingsActivity.class);
|
|
|
|
startActivity(intent);
|
2015-01-07 14:00:18 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-07 12:58:18 +01:00
|
|
|
if (id == R.id.action_debug) {
|
|
|
|
Intent intent = new Intent(this, DebugActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
2015-01-07 14:00:18 +01:00
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
2015-02-07 12:58:18 +01:00
|
|
|
|
2015-02-06 13:55:44 +01:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|