From aa82330c94e9287bc685d83fa1f94098880a24f2 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 14 May 2014 14:59:05 +0200 Subject: [PATCH] Add ActionBar back button to settings. --- src/main/AndroidManifest.xml | 8 +++++- .../syncthingandroid/SettingsActivity.java | 25 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index f488b347..37beeca6 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -26,7 +26,13 @@ + android:label="@string/settings_title" > + + + + diff --git a/src/main/java/com/nutomic/syncthingandroid/SettingsActivity.java b/src/main/java/com/nutomic/syncthingandroid/SettingsActivity.java index c38c9692..aaa6c9a8 100644 --- a/src/main/java/com/nutomic/syncthingandroid/SettingsActivity.java +++ b/src/main/java/com/nutomic/syncthingandroid/SettingsActivity.java @@ -2,13 +2,15 @@ package com.nutomic.syncthingandroid; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; +import android.support.v4.app.NavUtils; +import android.view.MenuItem; import com.nutomic.syncthingandroid.service.GetTask; -import com.nutomic.syncthingandroid.service.SyncthingService; public class SettingsActivity extends PreferenceActivity { @@ -20,6 +22,12 @@ public class SettingsActivity extends PreferenceActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // There is currently no way to get ActionBar in PreferenceActivity on pre-honeycomb with + // compatibility library, so we'll have to do a version check. + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + getActionBar().setDisplayHomeAsUpEnabled(true); + } + addPreferencesFromResource(R.xml.settings); final PreferenceScreen screen = getPreferenceScreen(); final Preference version = screen.findPreference(SYNCTHING_VERSION_KEY); @@ -46,4 +54,19 @@ public class SettingsActivity extends PreferenceActivity { } return super.onPreferenceTreeClick(preferenceScreen, preference); } + + /** + * Handles ActionBar back selected. + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + NavUtils.navigateUpFromSameTask(this); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + }