1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

enable back navigaton in AppManager and Debug activitys ActionBar

This commit is contained in:
Andreas Shimokawa 2015-03-27 11:23:30 +01:00
parent 6ec1fa9e23
commit b20aaf59a8
4 changed files with 55 additions and 26 deletions

View File

@ -28,7 +28,11 @@
android:label="@string/title_activity_settings" />
<activity
android:name=".AppManagerActivity"
android:label="App Manager" />
android:label="App Manager">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ControlCenter" />
</activity>
<service
android:name=".NotificationListener"
@ -90,7 +94,11 @@
<activity
android:name=".DebugActivity"
android:label="@string/title_activity_debug" />
android:label="@string/title_activity_debug">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ControlCenter" />
</activity>
</application>
</manifest>

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager;
import android.view.ContextMenu;
import android.view.MenuItem;
@ -54,6 +55,7 @@ public class AppManagerActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appmanager);
getActionBar().setDisplayHomeAsUpEnabled(true);
appListView = (ListView) findViewById(R.id.appListView);
mGBDeviceAppAdapter = new GBDeviceAppAdapter(this, appList);
@ -98,6 +100,16 @@ public class AppManagerActivity extends Activity {
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);

View File

@ -122,32 +122,28 @@ public class ControlCenter extends Activity {
@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;
} else if (id == R.id.action_debug) {
Intent intent = new Intent(this, DebugActivity.class);
startActivity(intent);
return true;
} else if (id == R.id.action_quit) {
Intent stopIntent = new Intent(this, BluetoothCommunicationService.class);
stopService(stopIntent);
switch (item.getItemId()) {
case R.id.action_settings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);
return true;
case R.id.action_debug:
Intent debugIntent = new Intent(this, DebugActivity.class);
startActivity(debugIntent);
return true;
case R.id.action_quit:
Intent stopIntent = new Intent(this, BluetoothCommunicationService.class);
stopService(stopIntent);
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
return true;
} else if (id == R.id.action_refresh) {
if (deviceList.isEmpty()) {
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
}
Intent quitIntent = new Intent(ControlCenter.ACTION_QUIT);
LocalBroadcastManager.getInstance(this).sendBroadcast(quitIntent);
return true;
case R.id.action_refresh:
if (deviceList.isEmpty()) {
refreshPairedDevices();
mGBDeviceAdapter.notifyDataSetChanged();
}
}
return super.onOptionsItemSelected(item);

View File

@ -7,7 +7,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.app.NotificationCompat;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@ -38,6 +40,7 @@ public class DebugActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_debug);
getActionBar().setDisplayHomeAsUpEnabled(true);
registerReceiver(mReceiver, new IntentFilter(ControlCenter.ACTION_QUIT));
@ -153,6 +156,16 @@ public class DebugActivity extends Activity {
nManager.notify((int) System.currentTimeMillis(), ncomp.build());
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
super.onDestroy();