Fix Up and Search affordances
- UP is also shown for a SubSettings of a Shortcut - Search is never shown for a Shortcut (SubSettings or not) Change-Id: I5b87cf773ea0266a0f5dd090613bbbba905be330
This commit is contained in:
@@ -118,6 +118,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
|
import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
|
||||||
|
|
||||||
@@ -182,6 +183,7 @@ public class SettingsActivity extends Activity
|
|||||||
*/
|
*/
|
||||||
public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
|
public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
|
||||||
public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
|
public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
|
||||||
|
public static final String EXTRA_SHOW_FRAGMENT_AS_SHORTCUT = ":settings:show_fragment_as_shortcut";
|
||||||
|
|
||||||
private static final String META_DATA_KEY_FRAGMENT_CLASS =
|
private static final String META_DATA_KEY_FRAGMENT_CLASS =
|
||||||
"com.android.settings.FRAGMENT_CLASS";
|
"com.android.settings.FRAGMENT_CLASS";
|
||||||
@@ -317,6 +319,7 @@ public class SettingsActivity extends Activity
|
|||||||
private boolean mDisplaySearch;
|
private boolean mDisplaySearch;
|
||||||
|
|
||||||
private boolean mIsShowingDashboard;
|
private boolean mIsShowingDashboard;
|
||||||
|
private boolean mIsShortcut;
|
||||||
|
|
||||||
private ViewGroup mContent;
|
private ViewGroup mContent;
|
||||||
|
|
||||||
@@ -442,10 +445,21 @@ public class SettingsActivity extends Activity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isShortCutIntent(final Intent intent) {
|
||||||
|
Set<String> categories = intent.getCategories();
|
||||||
|
return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedState) {
|
protected void onCreate(Bundle savedState) {
|
||||||
if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) {
|
super.onCreate(savedState);
|
||||||
getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0));
|
|
||||||
|
// Should happen before any call to getIntent()
|
||||||
|
getMetaData();
|
||||||
|
|
||||||
|
final Intent intent = getIntent();
|
||||||
|
if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
|
||||||
|
getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
mAuthenticatorHelper = new AuthenticatorHelper();
|
mAuthenticatorHelper = new AuthenticatorHelper();
|
||||||
@@ -455,21 +469,20 @@ public class SettingsActivity extends Activity
|
|||||||
mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE,
|
||||||
Context.MODE_PRIVATE);
|
Context.MODE_PRIVATE);
|
||||||
|
|
||||||
getMetaData();
|
|
||||||
|
|
||||||
super.onCreate(savedState);
|
|
||||||
|
|
||||||
// Getting Intent properties can only be done after the super.onCreate(...)
|
// Getting Intent properties can only be done after the super.onCreate(...)
|
||||||
final String initialFragmentName = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
|
final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
|
||||||
|
|
||||||
mIsShowingDashboard = (initialFragmentName == null);
|
mIsShortcut = isShortCutIntent(intent) ||
|
||||||
|
intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);
|
||||||
|
|
||||||
|
mIsShowingDashboard = (initialFragmentName == null) && !mIsShortcut;
|
||||||
|
|
||||||
final ComponentName cn = getIntent().getComponent();
|
final ComponentName cn = getIntent().getComponent();
|
||||||
final boolean isShortcut = !cn.getClassName().equals(SubSettings.class.getName());
|
final boolean isSubSettings = cn.getClassName().equals(SubSettings.class.getName());
|
||||||
|
|
||||||
// If this is a subsettings (but not a Shortcut) then apply the correct theme for
|
// If this is a sub settings or not the main Dashboard and not a Shortcut then apply the
|
||||||
// the ActionBar content inset
|
// correct theme for the ActionBar content inset
|
||||||
if (!mIsShowingDashboard && !isShortcut) {
|
if (isSubSettings || (!mIsShowingDashboard && !mIsShortcut)) {
|
||||||
setTheme(R.style.Theme_SubSettings);
|
setTheme(R.style.Theme_SubSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -492,7 +505,7 @@ public class SettingsActivity extends Activity
|
|||||||
mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
|
mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
|
||||||
mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
|
mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
|
||||||
|
|
||||||
setTitleFromIntent(getIntent());
|
setTitleFromIntent(intent);
|
||||||
|
|
||||||
ArrayList<DashboardCategory> categories =
|
ArrayList<DashboardCategory> categories =
|
||||||
savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
|
savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
|
||||||
@@ -506,14 +519,15 @@ public class SettingsActivity extends Activity
|
|||||||
mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
|
mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
|
||||||
} else {
|
} else {
|
||||||
if (!mIsShowingDashboard) {
|
if (!mIsShowingDashboard) {
|
||||||
// No UP nor Search is shown we are launched thru a Settings "shortcut"
|
// Search is shown we are launched thru a Settings "shortcut". UP will be shown
|
||||||
if (isShortcut) {
|
// only if it is a sub settings
|
||||||
mDisplayHomeAsUpEnabled = false;
|
if (mIsShortcut) {
|
||||||
|
mDisplayHomeAsUpEnabled = isSubSettings;
|
||||||
mDisplaySearch = false;
|
mDisplaySearch = false;
|
||||||
}
|
}
|
||||||
setTitleFromIntent(getIntent());
|
setTitleFromIntent(intent);
|
||||||
|
|
||||||
Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
|
||||||
switchToFragment(initialFragmentName, initialArguments, true, false,
|
switchToFragment(initialFragmentName, initialArguments, true, false,
|
||||||
mInitialTitleResId, mInitialTitle, false);
|
mInitialTitleResId, mInitialTitle, false);
|
||||||
} else {
|
} else {
|
||||||
@@ -533,7 +547,6 @@ public class SettingsActivity extends Activity
|
|||||||
mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
|
mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
|
||||||
|
|
||||||
// see if we should show Back/Next buttons
|
// see if we should show Back/Next buttons
|
||||||
Intent intent = getIntent();
|
|
||||||
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
|
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
|
||||||
|
|
||||||
View buttonBar = findViewById(R.id.button_bar);
|
View buttonBar = findViewById(R.id.button_bar);
|
||||||
@@ -790,7 +803,7 @@ public class SettingsActivity extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
|
Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
|
||||||
titleRes, title);
|
titleRes, title, mIsShortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -528,7 +528,15 @@ public class Utils {
|
|||||||
*/
|
*/
|
||||||
public static void startWithFragment(Context context, String fragmentName, Bundle args,
|
public static void startWithFragment(Context context, String fragmentName, Bundle args,
|
||||||
Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) {
|
Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) {
|
||||||
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title);
|
startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
|
||||||
|
titleResId, title, false /* not a shortcut */);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void startWithFragment(Context context, String fragmentName, Bundle args,
|
||||||
|
Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title,
|
||||||
|
boolean isShortcut) {
|
||||||
|
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId,
|
||||||
|
title, isShortcut);
|
||||||
if (resultTo == null) {
|
if (resultTo == null) {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
@@ -541,22 +549,25 @@ public class Utils {
|
|||||||
* The implementation constructs an Intent that re-launches the current activity with the
|
* The implementation constructs an Intent that re-launches the current activity with the
|
||||||
* appropriate arguments to display the fragment.
|
* appropriate arguments to display the fragment.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
* @param context The Context.
|
* @param context The Context.
|
||||||
* @param fragmentName The name of the fragment to display.
|
* @param fragmentName The name of the fragment to display.
|
||||||
* @param args Optional arguments to supply to the fragment.
|
* @param args Optional arguments to supply to the fragment.
|
||||||
* @param titleResId Optional title resource id to show for this item.
|
* @param titleResId Optional title resource id to show for this item.
|
||||||
* @param title Optional title to show for this item.
|
* @param title Optional title to show for this item.
|
||||||
|
* @param isShortcut tell if this is a Launcher Shortcut or not
|
||||||
* @return Returns an Intent that can be launched to display the given
|
* @return Returns an Intent that can be launched to display the given
|
||||||
* fragment.
|
* fragment.
|
||||||
*/
|
*/
|
||||||
public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
|
public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
|
||||||
Bundle args, int titleResId, CharSequence title) {
|
Bundle args, int titleResId, CharSequence title, boolean isShortcut) {
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
intent.setClass(context, SubSettings.class);
|
intent.setClass(context, SubSettings.class);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
|
||||||
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user