Settings - update for new UI (no more Drawer)

- follow the UX spec by no more using a Drawer
- the Dashboard is now a Fragment that contains the list of Headers
- the search results are also put into a Fragment that is replacing
the initial one (Dashboard or other) when expanding the SearchView
- use a SearchView for query input
- when tapping on a Header or a Search Result, re-launch Settings as
an Activity so that we are benefiting from the Activity stack for
UP affordance and BACK button
- manage UP affordance to show it only when needed
- move some Actions to the Menu in the ActionBar for allowing space
to the Search action and removing some clutter
- fix an issue with the Index and WiFiEnabler and their cached Context
that was not updated when there was a Configuration change
- simplify the SettingsActivity code by extracting some inner classes

Change-Id: I50b5f77bb44a7fade1886114dbbc820609a5e63d
This commit is contained in:
Fabrice Di Meglio
2014-03-21 19:24:43 -07:00
parent 5f3442af6f
commit d25314d330
19 changed files with 1213 additions and 1148 deletions

View File

@@ -80,7 +80,6 @@
<!-- Settings --> <!-- Settings -->
<activity android:name="Settings" <activity android:name="Settings"
android:uiOptions="splitActionBarWhenNarrow"
android:taskAffinity="com.android.settings" android:taskAffinity="com.android.settings"
android:label="@string/settings_label_launcher" android:label="@string/settings_label_launcher"
android:launchMode="singleTask"> android:launchMode="singleTask">

View File

@@ -24,33 +24,10 @@
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<TextView android:id="@+id/dash_text" <ListView android:id="@id/android:list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_gravity="center" android:background="@color/background_drawer" />
android:text="@string/dashboard_wip"
android:padding="16dp"
android:layout_weight="0"
android:background="#ffcccccc"
android:textSize="16sp"
/>
<EditText android:id="@+id/edittext_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/query_hint_text"
android:layout_weight="0"/>
<FrameLayout android:id="@+id/dashboard"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<ListView android:id="@+id/list_results"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout> </LinearLayout>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ListView android:id="@+id/list_results"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</FrameLayout>

View File

@@ -17,65 +17,58 @@
*/ */
--> -->
<android.support.v4.widget.DrawerLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_width="match_parent"> android:layout_width="match_parent">
<android.preference.PreferenceFrameLayout android:id="@+id/prefs" <LinearLayout
android:layout_width="match_parent" android:orientation="vertical"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_width="match_parent">
/>
<RelativeLayout android:id="@+id/button_bar" <android.preference.PreferenceFrameLayout
android:layout_height="wrap_content" android:id="@+id/prefs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_weight="0" android:layout_height="match_parent"
android:visibility="gone"> android:layout_weight="1"
/>
</LinearLayout>
<Button android:id="@+id/back_button" <RelativeLayout android:id="@+id/button_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="0"
android:visibility="gone">
<Button android:id="@+id/back_button"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentStart="true"
android:text="@*android:string/back_button_label"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<Button android:id="@+id/skip_button"
android:layout_width="150dip" android:layout_width="150dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="5dip" android:layout_margin="5dip"
android:layout_alignParentStart="true" android:text="@*android:string/skip_button_label"
android:text="@*android:string/back_button_label" android:visibility="gone"
/> />
<LinearLayout
android:orientation="horizontal" <Button android:id="@+id/next_button"
android:layout_width="wrap_content" android:layout_width="150dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"> android:layout_margin="5dip"
android:text="@*android:string/next_button_label"
/>
</LinearLayout>
</RelativeLayout>
<Button android:id="@+id/skip_button" </LinearLayout>
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:text="@*android:string/skip_button_label"
android:visibility="gone"
/>
<Button android:id="@+id/next_button"
android:layout_width="150dip"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:text="@*android:string/next_button_label"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<ListView android:id="@+id/headers_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/background_drawer"/>
</android.support.v4.widget.DrawerLayout>

24
res/menu/options_menu.xml Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/search"
android:title="@string/search_menu"
android:icon="@*android:drawable/ic_search"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
</menu>

View File

@@ -4988,20 +4988,17 @@
<string name="enable_nfc">NFC is not enabled and is required for NFC Unlock. Please turn on NFC.</string> <string name="enable_nfc">NFC is not enabled and is required for NFC Unlock. Please turn on NFC.</string>
<string name="ok">NFC Settings</string> <string name="ok">NFC Settings</string>
<!--Drawer strings-->
<!-- Text to describe the "open drawer" action for accessibility purpose [CHAR LIMIT=50] -->
<string name="drawer_open">Open navigation drawer</string>
<!-- Text to describe the "close drawer" action for accessibility purpose [CHAR LIMIT=50] -->
<string name="drawer_close">Close navigation drawer</string>
<!--Dashboard strings--> <!--Dashboard strings-->
<!-- Text to describe the dashboard entry into the Drawer [CHAR LIMIT=16] --> <!-- Text to describe the dashboard fragment title [CHAR LIMIT=16] -->
<string name="dashboard_title">Overview</string> <string name="dashboard_title">Settings</string>
<string name="dashboard_wip" translatable="false">Overview and Search are work in progress and Confidential\n\nDrag the Drawer on the left to see the settings list</string>
<!-- Search strings --> <!-- Search strings -->
<!-- Text to describe the search results fragment title [CHAR LIMIT=16] -->
<string name="search_results_title">Settings</string>
<!-- Text used as a search hint into the search box --> <!-- Text used as a search hint into the search box -->
<string name="query_hint_text">What are you looking for?</string> <string name="search_menu">Search</string>
<!-- Text used as a search hint into the search box -->
<string name="query_hint_text">Search settings</string>
<!--Search Keywords--> <!--Search Keywords-->
<string name="keywords_wifi">wifi wi-fi network connection</string> <string name="keywords_wifi">wifi wi-fi network connection</string>

View File

@@ -17,14 +17,6 @@
<preference-headers <preference-headers
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Dashboard -->
<!--TODO: android:icon="@drawable/ic_settings_dashboard"-->
<header
android:id="@+id/dashboard"
android:fragment="com.android.settings.dashboard.DashboardSummary"
android:title="@string/dashboard_title" />
<!-- WIRELESS and NETWORKS --> <!-- WIRELESS and NETWORKS -->
<header android:id="@+id/wireless_section" <header android:id="@+id/wireless_section"
android:title="@string/header_category_wireless_networks" /> android:title="@string/header_category_wireless_networks" />

File diff suppressed because it is too large Load Diff

View File

@@ -55,6 +55,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TabWidget; import android.widget.TabWidget;
import com.android.settings.dashboard.Header;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -237,7 +238,7 @@ public class Utils {
} }
public static boolean updateHeaderToSpecificActivityFromMetaDataOrRemove(Context context, public static boolean updateHeaderToSpecificActivityFromMetaDataOrRemove(Context context,
List<SettingsActivity.Header> target, SettingsActivity.Header header) { List<Header> target, Header header) {
Intent intent = header.intent; Intent intent = header.intent;
if (intent != null) { if (intent != null) {

View File

@@ -129,7 +129,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
final SettingsActivity activity = (SettingsActivity) getActivity(); final SettingsActivity activity = (SettingsActivity) getActivity();
if (!activity.onIsHidingHeaders()) { if (activity.onIsHidingHeaders()) {
activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM); ActionBar.DISPLAY_SHOW_CUSTOM);
activity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams( activity.getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(
@@ -198,7 +198,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem
R.string.bluetooth_search_for_devices; R.string.bluetooth_search_for_devices;
menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId) menu.add(Menu.NONE, MENU_ID_SCAN, 0, textId)
.setEnabled(bluetoothIsEnabled && !isDiscovering) .setEnabled(bluetoothIsEnabled && !isDiscovering)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device) menu.add(Menu.NONE, MENU_ID_RENAME_DEVICE, 0, R.string.bluetooth_rename_device)
.setEnabled(bluetoothIsEnabled) .setEnabled(bluetoothIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

View File

@@ -16,339 +16,35 @@
package com.android.settings.dashboard; package com.android.settings.dashboard;
import android.app.Fragment; import android.app.ListFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.widget.ListAdapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsActivity; import com.android.settings.SettingsActivity;
import com.android.settings.search.Index;
import java.util.HashMap;
public class DashboardSummary extends Fragment {
public class DashboardSummary extends ListFragment {
private static final String LOG_TAG = "DashboardSummary"; private static final String LOG_TAG = "DashboardSummary";
private EditText mEditText;
private ListView mListView;
private SearchResultsAdapter mAdapter;
private Index mIndex;
private UpdateSearchResultsTask mUpdateSearchResultsTask;
/**
* A basic AsyncTask for updating the query results cursor
*/
private class UpdateSearchResultsTask extends AsyncTask<String, Void, Cursor> {
@Override
protected Cursor doInBackground(String... params) {
return mIndex.search(params[0]);
}
@Override
protected void onPostExecute(Cursor cursor) {
if (!isCancelled()) {
setCursor(cursor);
} else if (cursor != null) {
cursor.close();
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mIndex = Index.getInstance(getActivity());
mAdapter = new SearchResultsAdapter(getActivity());
}
@Override
public void onStop() {
super.onStop();
clearResults();
}
@Override
public void onStart() {
super.onStart();
updateSearchResults();
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.dashboard, container, false); final View view = inflater.inflate(R.layout.dashboard, container, false);
mEditText = (EditText)view.findViewById(R.id.edittext_query); ListView listView = (ListView) view.findViewById(android.R.id.list);
mEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override ListAdapter adapter = ((SettingsActivity) getActivity()).getHeaderAdapter();
public void onTextChanged(CharSequence s, int start, int before, int count) { listView.setAdapter(adapter);
updateSearchResults();
}
@Override
public void afterTextChanged(Editable s) {
}
});
mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
closeSoftKeyboard();
}
}
});
mListView = (ListView) view.findViewById(R.id.list_results);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
closeSoftKeyboard();
final Cursor cursor = mAdapter.mCursor;
cursor.moveToPosition(position);
final String className = cursor.getString(Index.COLUMN_INDEX_CLASS_NAME);
final String screenTitle = cursor.getString(Index.COLUMN_INDEX_SCREEN_TITLE);
final String action = cursor.getString(Index.COLUMN_INDEX_INTENT_ACTION);
if (TextUtils.isEmpty(action)) {
((SettingsActivity) getActivity()).startPreferencePanel(className, null, 0,
screenTitle, null, 0);
} else {
final Intent intent = new Intent(action);
final String targetPackage = cursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
final String targetClass = cursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS);
if (!TextUtils.isEmpty(targetPackage) && !TextUtils.isEmpty(targetClass)) {
final ComponentName component =
new ComponentName(targetPackage, targetClass);
intent.setComponent(component);
}
getActivity().startActivity(intent);
}
}
});
return view; return view;
} }
private void closeSoftKeyboard() { @Override
InputMethodManager imm = InputMethodManager.peekInstance(); public void onListItemClick(ListView l, View v, int position, long id) {
if (imm != null && imm.isActive(mEditText)) { ((SettingsActivity) getActivity()).onListItemClick(l, v, position, id);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}
}
private void clearResults() {
if (mUpdateSearchResultsTask != null) {
mUpdateSearchResultsTask.cancel(false);
mUpdateSearchResultsTask = null;
}
setCursor(null);
}
private void setCursor(Cursor cursor) {
Cursor oldCursor = mAdapter.swapCursor(cursor);
if (oldCursor != null) {
oldCursor.close();
}
}
private String getFilteredQueryString() {
final CharSequence query = mEditText.getText().toString();
final StringBuilder filtered = new StringBuilder();
for (int n = 0; n < query.length(); n++) {
char c = query.charAt(n);
if (!Character.isLetterOrDigit(c) && !Character.isSpaceChar(c)) {
continue;
}
filtered.append(c);
}
return filtered.toString();
}
private void updateSearchResults() {
if (mUpdateSearchResultsTask != null) {
mUpdateSearchResultsTask.cancel(false);
mUpdateSearchResultsTask = null;
}
final String query = getFilteredQueryString();
if (TextUtils.isEmpty(query)) {
setCursor(null);
} else {
mUpdateSearchResultsTask = new UpdateSearchResultsTask();
mUpdateSearchResultsTask.execute(query);
}
}
private static class SearchResult {
public String title;
public String summary;
public int iconResId;
public Context context;
public SearchResult(Context context, String title, String summary, int iconResId) {
this.context = context;
this.title = title;
this.summary = summary;
this.iconResId = iconResId;
}
}
private static class SearchResultsAdapter extends BaseAdapter {
private Cursor mCursor;
private LayoutInflater mInflater;
private boolean mDataValid;
private Context mContext;
private HashMap<String, Context> mContextMap = new HashMap<String, Context>();
public SearchResultsAdapter(Context context) {
mContext = context;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mDataValid = false;
}
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == mCursor) {
return null;
}
Cursor oldCursor = mCursor;
mCursor = newCursor;
if (newCursor != null) {
mDataValid = true;
notifyDataSetChanged();
} else {
mDataValid = false;
notifyDataSetInvalidated();
}
return oldCursor;
}
@Override
public int getCount() {
if (!mDataValid || mCursor == null || mCursor.isClosed()) return 0;
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
if (mDataValid && mCursor.moveToPosition(position)) {
final String title = mCursor.getString(Index.COLUMN_INDEX_TITLE);
final String summary = mCursor.getString(Index.COLUMN_INDEX_SUMMARY);
final String iconResStr = mCursor.getString(Index.COLUMN_INDEX_ICON);
final String className = mCursor.getString(
Index.COLUMN_INDEX_CLASS_NAME);
final String packageName = mCursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
Context packageContext;
if (TextUtils.isEmpty(className) && !TextUtils.isEmpty(packageName)) {
packageContext = mContextMap.get(packageName);
if (packageContext == null) {
try {
packageContext = mContext.createPackageContext(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Cannot create Context for package: " + packageName);
return null;
}
mContextMap.put(packageName, packageContext);
}
} else {
packageContext = mContext;
}
final int iconResId = TextUtils.isEmpty(iconResStr) ?
R.drawable.empty_icon : Integer.parseInt(iconResStr);
return new SearchResult(packageContext, title, summary, iconResId);
}
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (!mDataValid && convertView == null) {
throw new IllegalStateException(
"this should only be called when the cursor is valid");
}
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("couldn't move cursor to position " + position);
}
View view;
TextView textTitle;
TextView textSummary;
ImageView imageView;
if (convertView == null) {
view = mInflater.inflate(R.layout.search_result, parent, false);
} else {
view = convertView;
}
textTitle = (TextView) view.findViewById(R.id.title);
textSummary = (TextView) view.findViewById(R.id.summary);
imageView = (ImageView) view.findViewById(R.id.icon);
SearchResult result = (SearchResult) getItem(position);
textTitle.setText(result.title);
textSummary.setText(result.summary);
if (result.iconResId != R.drawable.empty_icon) {
final Context packageContext = result.context;
final Drawable drawable;
try {
drawable = packageContext.getDrawable(result.iconResId);
imageView.setImageDrawable(drawable);
} catch (Resources.NotFoundException nfe) {
// Not much we can do except logging
Log.e(LOG_TAG, "Cannot load Drawable for " + result.title);
}
imageView.setBackgroundResource(R.color.background_search_result_icon);
} else {
imageView.setImageDrawable(null);
imageView.setBackgroundResource(R.drawable.empty_icon);
}
return view;
}
} }
} }

View File

@@ -0,0 +1,177 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.dashboard;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Description of a single Header item that the user can select.
*/
public class Header implements Parcelable {
/**
* Default value for {@link Header#id Header.id} indicating that no
* identifier value is set. All other values (including those below -1)
* are valid.
*/
public static final long HEADER_ID_UNDEFINED = -1;
/**
* Identifier for this header, to correlate with a new list when
* it is updated. The default value is
* {@link Header#HEADER_ID_UNDEFINED}, meaning no id.
* @attr ref android.R.styleable#PreferenceHeader_id
*/
public long id = HEADER_ID_UNDEFINED;
/**
* Resource ID of title of the header that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title
*/
public int titleRes;
/**
* Title of the header that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title
*/
public CharSequence title;
/**
* Resource ID of optional summary describing what this header controls.
* @attr ref android.R.styleable#PreferenceHeader_summary
*/
public int summaryRes;
/**
* Optional summary describing what this header controls.
* @attr ref android.R.styleable#PreferenceHeader_summary
*/
public CharSequence summary;
/**
* Optional icon resource to show for this header.
* @attr ref android.R.styleable#PreferenceHeader_icon
*/
public int iconRes;
/**
* Full class name of the fragment to display when this header is
* selected.
* @attr ref android.R.styleable#PreferenceHeader_fragment
*/
public String fragment;
/**
* Optional arguments to supply to the fragment when it is
* instantiated.
*/
public Bundle fragmentArguments;
/**
* Intent to launch when the preference is selected.
*/
public Intent intent;
/**
* Optional additional data for use by subclasses of the activity
*/
public Bundle extras;
public Header() {
// Empty
}
/**
* Return the currently set title. If {@link #titleRes} is set,
* this resource is loaded from <var>res</var> and returned. Otherwise
* {@link #title} is returned.
*/
public CharSequence getTitle(Resources res) {
if (titleRes != 0) {
return res.getText(titleRes);
}
return title;
}
/**
* Return the currently set summary. If {@link #summaryRes} is set,
* this resource is loaded from <var>res</var> and returned. Otherwise
* {@link #summary} is returned.
*/
public CharSequence getSummary(Resources res) {
if (summaryRes != 0) {
return res.getText(summaryRes);
}
return summary;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeInt(titleRes);
TextUtils.writeToParcel(title, dest, flags);
dest.writeInt(summaryRes);
TextUtils.writeToParcel(summary, dest, flags);
dest.writeInt(iconRes);
dest.writeString(fragment);
dest.writeBundle(fragmentArguments);
if (intent != null) {
dest.writeInt(1);
intent.writeToParcel(dest, flags);
} else {
dest.writeInt(0);
}
dest.writeBundle(extras);
}
public void readFromParcel(Parcel in) {
id = in.readLong();
titleRes = in.readInt();
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
summaryRes = in.readInt();
summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
iconRes = in.readInt();
fragment = in.readString();
fragmentArguments = in.readBundle();
if (in.readInt() != 0) {
intent = Intent.CREATOR.createFromParcel(in);
}
extras = in.readBundle();
}
Header(Parcel in) {
readFromParcel(in);
}
public static final Creator<Header> CREATOR = new Creator<Header>() {
public Header createFromParcel(Parcel source) {
return new Header(source);
}
public Header[] newArray(int size) {
return new Header[size];
}
};
}

View File

@@ -0,0 +1,275 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.dashboard;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.accounts.AuthenticatorHelper;
import com.android.settings.accounts.ManageAccountsSettings;
import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.wifi.WifiEnabler;
import java.util.List;
/**
* A basic ArrayAdapter for dealing with the Headers
*/
public class HeaderAdapter extends ArrayAdapter<Header> {
public static final int HEADER_TYPE_CATEGORY = 0;
public static final int HEADER_TYPE_NORMAL = 1;
public static final int HEADER_TYPE_SWITCH = 2;
public static final int HEADER_TYPE_BUTTON = 3;
private static final int HEADER_TYPE_COUNT = HEADER_TYPE_BUTTON + 1;
private final WifiEnabler mWifiEnabler;
private final BluetoothEnabler mBluetoothEnabler;
private AuthenticatorHelper mAuthHelper;
private DevicePolicyManager mDevicePolicyManager;
private static class HeaderViewHolder {
ImageView mIcon;
TextView mTitle;
TextView mSummary;
Switch mSwitch;
ImageButton mButton;
View mDivider;
}
private LayoutInflater mInflater;
public static int getHeaderType(Header header) {
if (header.fragment == null && header.intent == null) {
return HEADER_TYPE_CATEGORY;
} else if (header.id == R.id.security_settings) {
return HEADER_TYPE_BUTTON;
} else {
return HEADER_TYPE_NORMAL;
}
}
@Override
public int getItemViewType(int position) {
Header header = getItem(position);
return getHeaderType(header);
}
@Override
public boolean areAllItemsEnabled() {
return false; // because of categories
}
@Override
public boolean isEnabled(int position) {
return getItemViewType(position) != HEADER_TYPE_CATEGORY;
}
@Override
public int getViewTypeCount() {
return HEADER_TYPE_COUNT;
}
@Override
public boolean hasStableIds() {
return true;
}
public HeaderAdapter(Context context, List<Header> objects,
AuthenticatorHelper authenticatorHelper, DevicePolicyManager dpm) {
super(context, 0, objects);
mAuthHelper = authenticatorHelper;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Temp Switches provided as placeholder until the adapter replaces these with actual
// Switches inflated from their layouts. Must be done before adapter is set in super
mWifiEnabler = new WifiEnabler(context, new Switch(context));
mBluetoothEnabler = new BluetoothEnabler(context, new Switch(context));
mDevicePolicyManager = dpm;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
Header header = getItem(position);
int headerType = getHeaderType(header);
View view = null;
if (convertView == null) {
holder = new HeaderViewHolder();
switch (headerType) {
case HEADER_TYPE_CATEGORY:
view = new TextView(getContext(), null,
android.R.attr.listSeparatorTextViewStyle);
holder.mTitle = (TextView) view;
break;
case HEADER_TYPE_SWITCH:
view = mInflater.inflate(R.layout.preference_header_switch_item, parent,
false);
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
holder.mTitle = (TextView)
view.findViewById(com.android.internal.R.id.title);
holder.mSummary = (TextView)
view.findViewById(com.android.internal.R.id.summary);
holder.mSwitch = (Switch) view.findViewById(R.id.switchWidget);
break;
case HEADER_TYPE_BUTTON:
view = mInflater.inflate(R.layout.preference_header_button_item, parent,
false);
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
holder.mTitle = (TextView)
view.findViewById(com.android.internal.R.id.title);
holder.mSummary = (TextView)
view.findViewById(com.android.internal.R.id.summary);
holder.mButton = (ImageButton) view.findViewById(R.id.buttonWidget);
holder.mDivider = view.findViewById(R.id.divider);
break;
case HEADER_TYPE_NORMAL:
view = mInflater.inflate(
R.layout.preference_header_item, parent,
false);
holder.mIcon = (ImageView) view.findViewById(R.id.icon);
holder.mTitle = (TextView)
view.findViewById(com.android.internal.R.id.title);
holder.mSummary = (TextView)
view.findViewById(com.android.internal.R.id.summary);
break;
}
view.setTag(holder);
} else {
view = convertView;
holder = (HeaderViewHolder) view.getTag();
}
// All view fields must be updated every time, because the view may be recycled
switch (headerType) {
case HEADER_TYPE_CATEGORY:
holder.mTitle.setText(header.getTitle(getContext().getResources()));
break;
case HEADER_TYPE_SWITCH:
// Would need a different treatment if the main menu had more switches
if (header.id == R.id.wifi_settings) {
mWifiEnabler.setSwitch(holder.mSwitch);
} else {
mBluetoothEnabler.setSwitch(holder.mSwitch);
}
updateCommonHeaderView(header, holder);
break;
case HEADER_TYPE_BUTTON:
if (header.id == R.id.security_settings) {
boolean hasCert = DevicePolicyManager.hasAnyCaCertsInstalled();
if (hasCert) {
holder.mButton.setVisibility(View.VISIBLE);
holder.mDivider.setVisibility(View.VISIBLE);
boolean isManaged = mDevicePolicyManager.getDeviceOwner() != null;
if (isManaged) {
holder.mButton.setImageResource(R.drawable.ic_settings_about);
} else {
holder.mButton.setImageResource(
android.R.drawable.stat_notify_error);
}
holder.mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(
android.provider.Settings.ACTION_MONITORING_CERT_INFO);
getContext().startActivity(intent);
}
});
} else {
holder.mButton.setVisibility(View.GONE);
holder.mDivider.setVisibility(View.GONE);
}
}
updateCommonHeaderView(header, holder);
break;
case HEADER_TYPE_NORMAL:
updateCommonHeaderView(header, holder);
break;
}
return view;
}
private void updateCommonHeaderView(Header header, HeaderViewHolder holder) {
if (header.extras != null
&& header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
String accType = header.extras.getString(
ManageAccountsSettings.KEY_ACCOUNT_TYPE);
Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
setHeaderIcon(holder, icon);
} else {
if (header.iconRes > 0) {
holder.mIcon.setImageResource(header.iconRes);
} else {
holder.mIcon.setImageDrawable(null);
}
}
if (holder.mIcon != null) {
if (header.iconRes > 0) {
holder.mIcon.setBackgroundResource(R.color.background_drawer_icon);
} else {
holder.mIcon.setBackground(null);
}
}
holder.mTitle.setText(header.getTitle(getContext().getResources()));
CharSequence summary = header.getSummary(getContext().getResources());
if (!TextUtils.isEmpty(summary)) {
holder.mSummary.setVisibility(View.VISIBLE);
holder.mSummary.setText(summary);
} else {
holder.mSummary.setVisibility(View.GONE);
}
}
private void setHeaderIcon(HeaderViewHolder holder, Drawable icon) {
ViewGroup.LayoutParams lp = holder.mIcon.getLayoutParams();
lp.width = getContext().getResources().getDimensionPixelSize(
R.dimen.header_icon_width);
lp.height = lp.width;
holder.mIcon.setLayoutParams(lp);
holder.mIcon.setImageDrawable(icon);
}
public void resume(Context context) {
mWifiEnabler.resume(context);
mBluetoothEnabler.resume(context);
}
public void pause() {
mWifiEnabler.pause();
mBluetoothEnabler.pause();
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.dashboard;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import com.android.settings.R;
public class NoHomeDialogFragment extends DialogFragment {
public static void show(Activity parent) {
final NoHomeDialogFragment dialog = new NoHomeDialogFragment();
dialog.show(parent.getFragmentManager(), null);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setMessage(R.string.only_one_home_message)
.setPositiveButton(android.R.string.ok, null)
.create();
}
}

View File

@@ -0,0 +1,331 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.dashboard;
import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.search.Index;
import java.util.HashMap;
public class SearchResultsSummary extends Fragment {
private static final String LOG_TAG = "SearchResultsSummary";
private ListView mListView;
private SearchResultsAdapter mAdapter;
private UpdateSearchResultsTask mUpdateSearchResultsTask;
/**
* A basic AsyncTask for updating the query results cursor
*/
private class UpdateSearchResultsTask extends AsyncTask<String, Void, Cursor> {
@Override
protected Cursor doInBackground(String... params) {
return Index.getInstance(getActivity()).search(params[0]);
}
@Override
protected void onPostExecute(Cursor cursor) {
if (!isCancelled()) {
setCursor(cursor);
} else if (cursor != null) {
cursor.close();
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mAdapter = new SearchResultsAdapter(getActivity());
}
@Override
public void onStop() {
super.onStop();
clearResults();
}
@Override
public void onDestroy() {
mListView = null;
mAdapter = null;
mUpdateSearchResultsTask = null;
super.onDestroy();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.search_results, container, false);
mListView = (ListView) view.findViewById(R.id.list_results);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Cursor cursor = mAdapter.mCursor;
cursor.moveToPosition(position);
final String className = cursor.getString(Index.COLUMN_INDEX_CLASS_NAME);
final String screenTitle = cursor.getString(Index.COLUMN_INDEX_SCREEN_TITLE);
final String action = cursor.getString(Index.COLUMN_INDEX_INTENT_ACTION);
final SettingsActivity sa = (SettingsActivity) getActivity();
sa.needToRevertToInitialFragment();
if (TextUtils.isEmpty(action)) {
sa.startWithFragment(className, null, null, 0, screenTitle);
} else {
final Intent intent = new Intent(action);
final String targetPackage = cursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
final String targetClass = cursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_CLASS);
if (!TextUtils.isEmpty(targetPackage) && !TextUtils.isEmpty(targetClass)) {
final ComponentName component =
new ComponentName(targetPackage, targetClass);
intent.setComponent(component);
}
sa.startActivity(intent);
}
}
});
return view;
}
public boolean onQueryTextSubmit(String query) {
updateSearchResults(query);
return true;
}
public boolean onClose() {
clearResults();
return false;
}
private void clearResults() {
if (mUpdateSearchResultsTask != null) {
mUpdateSearchResultsTask.cancel(false);
mUpdateSearchResultsTask = null;
}
setCursor(null);
}
private void setCursor(Cursor cursor) {
if (mAdapter == null) {
return;
}
Cursor oldCursor = mAdapter.swapCursor(cursor);
if (oldCursor != null) {
oldCursor.close();
}
}
private String getFilteredQueryString(CharSequence query) {
final StringBuilder filtered = new StringBuilder();
for (int n = 0; n < query.length(); n++) {
char c = query.charAt(n);
if (!Character.isLetterOrDigit(c) && !Character.isSpaceChar(c)) {
continue;
}
filtered.append(c);
}
return filtered.toString();
}
private void updateSearchResults(CharSequence cs) {
if (mUpdateSearchResultsTask != null) {
mUpdateSearchResultsTask.cancel(false);
mUpdateSearchResultsTask = null;
}
final String query = getFilteredQueryString(cs);
if (TextUtils.isEmpty(query)) {
setCursor(null);
} else {
mUpdateSearchResultsTask = new UpdateSearchResultsTask();
mUpdateSearchResultsTask.execute(query);
}
}
private static class SearchResult {
public String title;
public String summary;
public int iconResId;
public Context context;
public SearchResult(Context context, String title, String summary, int iconResId) {
this.context = context;
this.title = title;
this.summary = summary;
this.iconResId = iconResId;
}
}
private static class SearchResultsAdapter extends BaseAdapter {
private Cursor mCursor;
private LayoutInflater mInflater;
private boolean mDataValid;
private Context mContext;
private HashMap<String, Context> mContextMap = new HashMap<String, Context>();
public SearchResultsAdapter(Context context) {
mContext = context;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mDataValid = false;
}
public Cursor swapCursor(Cursor newCursor) {
if (newCursor == mCursor) {
return null;
}
Cursor oldCursor = mCursor;
mCursor = newCursor;
if (newCursor != null) {
mDataValid = true;
notifyDataSetChanged();
} else {
mDataValid = false;
notifyDataSetInvalidated();
}
return oldCursor;
}
@Override
public int getCount() {
if (!mDataValid || mCursor == null || mCursor.isClosed()) return 0;
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
if (mDataValid && mCursor.moveToPosition(position)) {
final String title = mCursor.getString(Index.COLUMN_INDEX_TITLE);
final String summary = mCursor.getString(Index.COLUMN_INDEX_SUMMARY);
final String iconResStr = mCursor.getString(Index.COLUMN_INDEX_ICON);
final String className = mCursor.getString(
Index.COLUMN_INDEX_CLASS_NAME);
final String packageName = mCursor.getString(
Index.COLUMN_INDEX_INTENT_ACTION_TARGET_PACKAGE);
Context packageContext;
if (TextUtils.isEmpty(className) && !TextUtils.isEmpty(packageName)) {
packageContext = mContextMap.get(packageName);
if (packageContext == null) {
try {
packageContext = mContext.createPackageContext(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
Log.e(LOG_TAG, "Cannot create Context for package: " + packageName);
return null;
}
mContextMap.put(packageName, packageContext);
}
} else {
packageContext = mContext;
}
final int iconResId = TextUtils.isEmpty(iconResStr) ?
R.drawable.empty_icon : Integer.parseInt(iconResStr);
return new SearchResult(packageContext, title, summary, iconResId);
}
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (!mDataValid && convertView == null) {
throw new IllegalStateException(
"this should only be called when the cursor is valid");
}
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("couldn't move cursor to position " + position);
}
View view;
TextView textTitle;
TextView textSummary;
ImageView imageView;
if (convertView == null) {
view = mInflater.inflate(R.layout.search_result_item, parent, false);
} else {
view = convertView;
}
textTitle = (TextView) view.findViewById(R.id.title);
textSummary = (TextView) view.findViewById(R.id.summary);
imageView = (ImageView) view.findViewById(R.id.icon);
SearchResult result = (SearchResult) getItem(position);
textTitle.setText(result.title);
textSummary.setText(result.summary);
if (result.iconResId != R.drawable.empty_icon) {
final Context packageContext = result.context;
final Drawable drawable;
try {
drawable = packageContext.getDrawable(result.iconResId);
imageView.setImageDrawable(drawable);
} catch (Resources.NotFoundException nfe) {
// Not much we can do except logging
Log.e(LOG_TAG, "Cannot load Drawable for " + result.title);
}
imageView.setBackgroundResource(R.color.background_search_result_icon);
} else {
imageView.setImageDrawable(null);
imageView.setBackgroundResource(R.drawable.empty_icon);
}
return view;
}
}
}

View File

@@ -96,7 +96,7 @@ public class Index {
private static Index sInstance; private static Index sInstance;
private final AtomicBoolean mIsAvailable = new AtomicBoolean(false); private final AtomicBoolean mIsAvailable = new AtomicBoolean(false);
private final UpdateData mDataToProcess = new UpdateData(); private final UpdateData mDataToProcess = new UpdateData();
private final Context mContext; private Context mContext;
/** /**
* A private class to describe the update data for the Index database * A private class to describe the update data for the Index database
@@ -124,6 +124,8 @@ public class Index {
public static Index getInstance(Context context) { public static Index getInstance(Context context) {
if (sInstance == null) { if (sInstance == null) {
sInstance = new Index(context); sInstance = new Index(context);
} else {
sInstance.setContext(context);
} }
return sInstance; return sInstance;
} }
@@ -132,6 +134,10 @@ public class Index {
mContext = context; mContext = context;
} }
public void setContext(Context context) {
mContext = context;
}
public boolean isAvailable() { public boolean isAvailable() {
return mIsAvailable.get(); return mIsAvailable.get();
} }
@@ -675,6 +681,17 @@ public class Index {
return (data != null) ? data.toString() : null; return (data != null) ? data.toString() : null;
} }
private int getResId(Context context, AttributeSet set, int[] attrs, int resId) {
final TypedArray sa = context.obtainStyledAttributes(set, attrs);
final TypedValue tv = sa.peekValue(resId);
if (tv != null && tv.type == TypedValue.TYPE_STRING) {
return tv.resourceId;
} else {
return 0;
}
}
/** /**
* A private class for updating the Index database * A private class for updating the Index database
*/ */

View File

@@ -38,7 +38,7 @@ import com.android.settings.search.Index;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
public class WifiEnabler implements CompoundButton.OnCheckedChangeListener { public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
private final Context mContext; private Context mContext;
private Switch mSwitch; private Switch mSwitch;
private AtomicBoolean mConnected = new AtomicBoolean(false); private AtomicBoolean mConnected = new AtomicBoolean(false);
@@ -77,7 +77,8 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
} }
public void resume() { public void resume(Context context) {
mContext = context;
// Wi-Fi state is sticky, so just let the receiver update UI // Wi-Fi state is sticky, so just let the receiver update UI
mContext.registerReceiver(mReceiver, mIntentFilter); mContext.registerReceiver(mReceiver, mIntentFilter);
mSwitch.setOnCheckedChangeListener(this); mSwitch.setOnCheckedChangeListener(this);

View File

@@ -416,7 +416,7 @@ public class WifiSettings extends RestrictedSettingsFragment
if (activity instanceof SettingsActivity) { if (activity instanceof SettingsActivity) {
SettingsActivity sa = (SettingsActivity) activity; SettingsActivity sa = (SettingsActivity) activity;
addSwitch = !sa.onIsHidingHeaders(); addSwitch = sa.onIsHidingHeaders();
} else if (activity instanceof WifiPickerActivity) { } else if (activity instanceof WifiPickerActivity) {
PreferenceActivity pa = (PreferenceActivity) activity; PreferenceActivity pa = (PreferenceActivity) activity;
addSwitch = pa.onIsHidingHeaders(); addSwitch = pa.onIsHidingHeaders();
@@ -458,12 +458,13 @@ public class WifiSettings extends RestrictedSettingsFragment
@Override @Override
public void onResume() { public void onResume() {
final Activity activity = getActivity();
super.onResume(); super.onResume();
if (mWifiEnabler != null) { if (mWifiEnabler != null) {
mWifiEnabler.resume(); mWifiEnabler.resume(activity);
} }
getActivity().registerReceiver(mReceiver, mFilter); activity.registerReceiver(mReceiver, mFilter);
updateAccessPoints(); updateAccessPoints();
} }
@@ -497,11 +498,11 @@ public class WifiSettings extends RestrictedSettingsFragment
menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc) menu.add(Menu.NONE, MENU_ID_WPS_PBC, 0, R.string.wifi_menu_wps_pbc)
.setIcon(ta.getDrawable(1)) .setIcon(ta.getDrawable(1))
.setEnabled(wifiIsEnabled) .setEnabled(wifiIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network) menu.add(Menu.NONE, MENU_ID_ADD_NETWORK, 0, R.string.wifi_add_network)
.setIcon(ta.getDrawable(0)) .setIcon(ta.getDrawable(0))
.setEnabled(wifiIsEnabled) .setEnabled(wifiIsEnabled)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan) menu.add(Menu.NONE, MENU_ID_SCAN, 0, R.string.wifi_menu_scan)
//.setIcon(R.drawable.ic_menu_scan_network) //.setIcon(R.drawable.ic_menu_scan_network)
.setEnabled(wifiIsEnabled) .setEnabled(wifiIsEnabled)