Merge "Move Home settings to Default apps"
This commit is contained in:
@@ -864,30 +864,6 @@
|
|||||||
android:value="true" />
|
android:value="true" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$HomeSettingsActivity"
|
|
||||||
android:label="@string/home_settings"
|
|
||||||
android:icon="@drawable/ic_settings_home"
|
|
||||||
android:taskAffinity="">
|
|
||||||
<intent-filter android:priority="1">
|
|
||||||
<action android:name="android.settings.HOME_SETTINGS" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
<category android:name="android.intent.category.VOICE_LAUNCH" />
|
|
||||||
</intent-filter>
|
|
||||||
<intent-filter android:priority="10">
|
|
||||||
<action android:name="com.android.settings.action.SETTINGS" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.category"
|
|
||||||
android:value="com.android.settings.category.device" />
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.HomeSettings" />
|
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
|
||||||
android:value="true" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="Settings$DisplaySettingsActivity"
|
<activity android:name="Settings$DisplaySettingsActivity"
|
||||||
android:label="@string/display_settings"
|
android:label="@string/display_settings"
|
||||||
android:icon="@drawable/ic_settings_display"
|
android:icon="@drawable/ic_settings_display"
|
||||||
@@ -2711,6 +2687,10 @@
|
|||||||
<action android:name="android.settings.MANAGE_DEFAULT_APPS_SETTINGS" />
|
<action android:name="android.settings.MANAGE_DEFAULT_APPS_SETTINGS" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.settings.HOME_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
android:value="com.android.settings.applications.ManageDefaultApps" />
|
android:value="com.android.settings.applications.ManageDefaultApps" />
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||||
|
@@ -18,35 +18,55 @@
|
|||||||
-->
|
-->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:padding="6dip">
|
android:padding="6dip">
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/app_image"
|
android:id="@android:id/icon"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:padding="6dip"
|
android:padding="6dip"
|
||||||
/>
|
android:duplicateParentState="true"
|
||||||
<TextView
|
/>
|
||||||
android:id="@+id/app_label"
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:layout_gravity="center_vertical"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:duplicateParentState="true"
|
||||||
android:textColor="?android:attr/textColorAlertDialogListItem"
|
android:orientation="vertical">
|
||||||
android:gravity="center_vertical"
|
<TextView
|
||||||
android:paddingEnd="7dip"
|
android:id="@android:id/title"
|
||||||
android:ellipsize="marquee"
|
android:layout_width="wrap_content"
|
||||||
/>
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textColor="?android:attr/textColorAlertDialogListItem"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingEnd="7dip"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:duplicateParentState="true"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@android:id/summary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingEnd="7dip"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:duplicateParentState="true"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/default_label"
|
android:id="@+id/default_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:text="@string/default_app"
|
android:text="@string/default_app"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:paddingEnd="7dip"
|
android:paddingEnd="7dip"
|
||||||
/>
|
android:duplicateParentState="true"
|
||||||
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@@ -7001,4 +7001,10 @@
|
|||||||
<!-- Title for switch to allow app unrestricted data usage [CHAR LIMIT=30] -->
|
<!-- Title for switch to allow app unrestricted data usage [CHAR LIMIT=30] -->
|
||||||
<string name="unrestricted_app_summary">Allow unrestricted data access when Data Saver is on</string>
|
<string name="unrestricted_app_summary">Allow unrestricted data access when Data Saver is on</string>
|
||||||
|
|
||||||
|
<!-- Button to switch the default home app [CHAR LIMIT=60] -->
|
||||||
|
<string name="home_app">Home app</string>
|
||||||
|
|
||||||
|
<!-- No default home set summary [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="no_default_home">No default Home</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -25,6 +25,12 @@
|
|||||||
android:title="@string/assist_and_voice_input_title"
|
android:title="@string/assist_and_voice_input_title"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<com.android.settings.applications.DefaultHomePreference
|
||||||
|
android:key="default_home"
|
||||||
|
android:title="@string/home_app"
|
||||||
|
android:summary="@string/no_default_home"
|
||||||
|
/>
|
||||||
|
|
||||||
<com.android.settings.applications.DefaultBrowserPreference
|
<com.android.settings.applications.DefaultBrowserPreference
|
||||||
android:key="default_browser"
|
android:key="default_browser"
|
||||||
android:title="@string/default_browser_title"
|
android:title="@string/default_browser_title"
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -50,6 +49,7 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
|
|
||||||
private Drawable[] mEntryDrawables;
|
private Drawable[] mEntryDrawables;
|
||||||
private boolean mShowItemNone = false;
|
private boolean mShowItemNone = false;
|
||||||
|
private CharSequence[] mSummaries;
|
||||||
|
|
||||||
public class AppArrayAdapter extends ArrayAdapter<CharSequence> {
|
public class AppArrayAdapter extends ArrayAdapter<CharSequence> {
|
||||||
private Drawable[] mImageDrawables = null;
|
private Drawable[] mImageDrawables = null;
|
||||||
@@ -62,17 +62,31 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
mImageDrawables = imageDrawables;
|
mImageDrawables = imageDrawables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int position) {
|
||||||
|
return mSummaries == null || mSummaries[position] == null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||||
View view = inflater.inflate(R.layout.app_preference_item, parent, false);
|
View view = inflater.inflate(R.layout.app_preference_item, parent, false);
|
||||||
TextView textView = (TextView) view.findViewById(R.id.app_label);
|
TextView textView = (TextView) view.findViewById(android.R.id.title);
|
||||||
textView.setText(getItem(position));
|
textView.setText(getItem(position));
|
||||||
if (position == mSelectedIndex) {
|
if (position == mSelectedIndex) {
|
||||||
view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
ImageView imageView = (ImageView)view.findViewById(R.id.app_image);
|
ImageView imageView = (ImageView) view.findViewById(android.R.id.icon);
|
||||||
imageView.setImageDrawable(mImageDrawables[position]);
|
imageView.setImageDrawable(mImageDrawables[position]);
|
||||||
|
// Summaries are describing why a item is disabled, so anything with a summary
|
||||||
|
// is not enabled.
|
||||||
|
boolean enabled = mSummaries == null || mSummaries[position] == null;
|
||||||
|
view.setEnabled(enabled);
|
||||||
|
if (!enabled) {
|
||||||
|
TextView summary = (TextView) view.findViewById(android.R.id.summary);
|
||||||
|
summary.setText(mSummaries[position]);
|
||||||
|
summary.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +147,12 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setComponentNames(ComponentName[] componentNames, ComponentName defaultCN) {
|
public void setComponentNames(ComponentName[] componentNames, ComponentName defaultCN) {
|
||||||
|
setComponentNames(componentNames, defaultCN, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponentNames(ComponentName[] componentNames, ComponentName defaultCN,
|
||||||
|
CharSequence[] summaries) {
|
||||||
|
mSummaries = summaries;
|
||||||
// Look up all package names in PackageManager. Skip ones we can't find.
|
// Look up all package names in PackageManager. Skip ones we can't find.
|
||||||
PackageManager pm = getContext().getPackageManager();
|
PackageManager pm = getContext().getPackageManager();
|
||||||
final int entryCount = componentNames.length + (mShowItemNone ? 1 : 0);
|
final int entryCount = componentNames.length + (mShowItemNone ? 1 : 0);
|
||||||
@@ -192,7 +212,7 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
@Override
|
@Override
|
||||||
protected Parcelable onSaveInstanceState() {
|
protected Parcelable onSaveInstanceState() {
|
||||||
Parcelable superState = super.onSaveInstanceState();
|
Parcelable superState = super.onSaveInstanceState();
|
||||||
return new SavedState(getEntryValues(), getValue(), mShowItemNone, superState);
|
return new SavedState(getEntryValues(), getValue(), mSummaries, mShowItemNone, superState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -201,6 +221,7 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
SavedState savedState = (SavedState) state;
|
SavedState savedState = (SavedState) state;
|
||||||
mShowItemNone = savedState.showItemNone;
|
mShowItemNone = savedState.showItemNone;
|
||||||
setPackageNames(savedState.entryValues, savedState.value);
|
setPackageNames(savedState.entryValues, savedState.value);
|
||||||
|
mSummaries = savedState.summaries;
|
||||||
super.onRestoreInstanceState(savedState.superState);
|
super.onRestoreInstanceState(savedState.superState);
|
||||||
} else {
|
} else {
|
||||||
super.onRestoreInstanceState(state);
|
super.onRestoreInstanceState(state);
|
||||||
@@ -213,13 +234,15 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
public final CharSequence value;
|
public final CharSequence value;
|
||||||
public final boolean showItemNone;
|
public final boolean showItemNone;
|
||||||
public final Parcelable superState;
|
public final Parcelable superState;
|
||||||
|
public final CharSequence[] summaries;
|
||||||
|
|
||||||
public SavedState(CharSequence[] entryValues, CharSequence value, boolean showItemNone,
|
public SavedState(CharSequence[] entryValues, CharSequence value, CharSequence[] summaries,
|
||||||
Parcelable superState) {
|
boolean showItemNone, Parcelable superState) {
|
||||||
this.entryValues = entryValues;
|
this.entryValues = entryValues;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.showItemNone = showItemNone;
|
this.showItemNone = showItemNone;
|
||||||
this.superState = superState;
|
this.superState = superState;
|
||||||
|
this.summaries = summaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -233,6 +256,7 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
dest.writeCharSequence(value);
|
dest.writeCharSequence(value);
|
||||||
dest.writeInt(showItemNone ? 1 : 0);
|
dest.writeInt(showItemNone ? 1 : 0);
|
||||||
dest.writeParcelable(superState, flags);
|
dest.writeParcelable(superState, flags);
|
||||||
|
dest.writeCharSequenceArray(summaries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
public static Creator<SavedState> CREATOR = new Creator<SavedState>() {
|
||||||
@@ -242,7 +266,8 @@ public class AppListPreference extends CustomListPreference {
|
|||||||
CharSequence value = source.readCharSequence();
|
CharSequence value = source.readCharSequence();
|
||||||
boolean showItemNone = source.readInt() != 0;
|
boolean showItemNone = source.readInt() != 0;
|
||||||
Parcelable superState = source.readParcelable(getClass().getClassLoader());
|
Parcelable superState = source.readParcelable(getClass().getClassLoader());
|
||||||
return new SavedState(entryValues, value, showItemNone, superState);
|
CharSequence[] summaries = source.readCharSequenceArray();
|
||||||
|
return new SavedState(entryValues, value, summaries, showItemNone, superState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -29,7 +29,6 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
@@ -114,8 +113,8 @@ import com.android.settings.wifi.SavedAccessPointsWifiSettings;
|
|||||||
import com.android.settings.wifi.WifiSettings;
|
import com.android.settings.wifi.WifiSettings;
|
||||||
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
import com.android.settings.wifi.p2p.WifiP2pSettings;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -380,7 +379,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
|
private static final String MSG_DATA_FORCE_REFRESH = "msg_data_force_refresh";
|
||||||
|
|
||||||
private boolean mNeedToRevertToInitialFragment = false;
|
private boolean mNeedToRevertToInitialFragment = false;
|
||||||
private int mHomeActivitiesCount = 1;
|
|
||||||
|
|
||||||
private Intent mResultIntentData;
|
private Intent mResultIntentData;
|
||||||
private ComponentName mCurrentSuggestion;
|
private ComponentName mCurrentSuggestion;
|
||||||
@@ -561,8 +559,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
|
mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
|
||||||
mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
|
mDisplaySearch = savedState.getBoolean(SAVE_KEY_SHOW_SEARCH);
|
||||||
mHomeActivitiesCount = savedState.getInt(SAVE_KEY_HOME_ACTIVITIES_COUNT,
|
|
||||||
1 /* one home activity by default */);
|
|
||||||
} else {
|
} else {
|
||||||
if (!mIsShowingDashboard) {
|
if (!mIsShowingDashboard) {
|
||||||
mDisplaySearch = false;
|
mDisplaySearch = false;
|
||||||
@@ -651,17 +647,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mHomeActivitiesCount = getHomeActivitiesCount();
|
|
||||||
if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||||
+ " ms");
|
+ " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getHomeActivitiesCount() {
|
|
||||||
final ArrayList<ResolveInfo> homeApps = new ArrayList<ResolveInfo>();
|
|
||||||
getPackageManager().getHomeActivities(homeApps);
|
|
||||||
return homeApps.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTitleFromIntent(Intent intent) {
|
private void setTitleFromIntent(Intent intent) {
|
||||||
final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
|
final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
|
||||||
if (initialTitleResId > 0) {
|
if (initialTitleResId > 0) {
|
||||||
@@ -751,8 +740,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
|
String query = (mSearchView != null) ? mSearchView.getQuery().toString() : EMPTY_QUERY;
|
||||||
outState.putString(SAVE_KEY_SEARCH_QUERY, query);
|
outState.putString(SAVE_KEY_SEARCH_QUERY, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
outState.putInt(SAVE_KEY_HOME_ACTIVITIES_COUNT, mHomeActivitiesCount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1021,10 +1008,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
Settings.PowerUsageSummaryActivity.class.getName()),
|
Settings.PowerUsageSummaryActivity.class.getName()),
|
||||||
mBatteryPresent, isAdmin, pm);
|
mBatteryPresent, isAdmin, pm);
|
||||||
|
|
||||||
setTileEnabled(new ComponentName(packageName,
|
|
||||||
Settings.HomeSettingsActivity.class.getName()),
|
|
||||||
updateHomeSettingTiles(), isAdmin, pm);
|
|
||||||
|
|
||||||
setTileEnabled(new ComponentName(packageName,
|
setTileEnabled(new ComponentName(packageName,
|
||||||
Settings.UserSettingsActivity.class.getName()),
|
Settings.UserSettingsActivity.class.getName()),
|
||||||
UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
|
UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers()
|
||||||
@@ -1081,27 +1064,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateHomeSettingTiles() {
|
|
||||||
// Once we decide to show Home settings, keep showing it forever
|
|
||||||
SharedPreferences sp = getSharedPreferences(HomeSettings.HOME_PREFS, Context.MODE_PRIVATE);
|
|
||||||
if (sp.getBoolean(HomeSettings.HOME_PREFS_DO_SHOW, false)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
mHomeActivitiesCount = getHomeActivitiesCount();
|
|
||||||
if (mHomeActivitiesCount < 2) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Can't look up the home activity; bail on configuring the icon
|
|
||||||
Log.w(LOG_TAG, "Problem looking up home activity!", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
sp.edit().putBoolean(HomeSettings.HOME_PREFS_DO_SHOW, true).apply();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getMetaData() {
|
private void getMetaData() {
|
||||||
try {
|
try {
|
||||||
ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
|
ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(),
|
||||||
|
@@ -187,14 +187,14 @@ public final class SmsDefaultDialog extends AlertActivity implements
|
|||||||
Item item = ((Item) getItem(position));
|
Item item = ((Item) getItem(position));
|
||||||
LayoutInflater inflater = getLayoutInflater();
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
View view = inflater.inflate(R.layout.app_preference_item, parent, false);
|
View view = inflater.inflate(R.layout.app_preference_item, parent, false);
|
||||||
TextView textView = (TextView) view.findViewById(R.id.app_label);
|
TextView textView = (TextView) view.findViewById(android.R.id.title);
|
||||||
textView.setText(item.label);
|
textView.setText(item.label);
|
||||||
if (position == mSelectedIndex) {
|
if (position == mSelectedIndex) {
|
||||||
view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
|
view.findViewById(R.id.default_label).setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
view.findViewById(R.id.default_label).setVisibility(View.GONE);
|
view.findViewById(R.id.default_label).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
ImageView imageView = (ImageView)view.findViewById(R.id.app_image);
|
ImageView imageView = (ImageView)view.findViewById(android.R.id.icon);
|
||||||
imageView.setImageDrawable(item.icon);
|
imageView.setImageDrawable(item.icon);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
118
src/com/android/settings/applications/DefaultHomePreference.java
Normal file
118
src/com/android/settings/applications/DefaultHomePreference.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.applications;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import com.android.settings.AppListPreference;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DefaultHomePreference extends AppListPreference {
|
||||||
|
|
||||||
|
private final ArrayList<ComponentName> mAllHomeComponents = new ArrayList<>();
|
||||||
|
private final IntentFilter mHomeFilter;
|
||||||
|
|
||||||
|
public DefaultHomePreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
|
||||||
|
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
|
||||||
|
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||||
|
refreshHomeOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performClick() {
|
||||||
|
refreshHomeOptions();
|
||||||
|
super.performClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean persistString(String value) {
|
||||||
|
if (value != null) {
|
||||||
|
ComponentName component = ComponentName.unflattenFromString(value);
|
||||||
|
getContext().getPackageManager().replacePreferredActivity(mHomeFilter,
|
||||||
|
IntentFilter.MATCH_CATEGORY_EMPTY,
|
||||||
|
mAllHomeComponents.toArray(new ComponentName[0]), component);
|
||||||
|
setSummary(getEntry());
|
||||||
|
}
|
||||||
|
return super.persistString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshHomeOptions() {
|
||||||
|
final String myPkg = getContext().getPackageName();
|
||||||
|
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
|
||||||
|
PackageManager pm = getContext().getPackageManager();
|
||||||
|
ComponentName currentDefaultHome = pm.getHomeActivities(homeActivities);
|
||||||
|
ArrayList<ComponentName> components = new ArrayList<>();
|
||||||
|
mAllHomeComponents.clear();
|
||||||
|
List<CharSequence> summaries = new ArrayList<>();
|
||||||
|
|
||||||
|
boolean mustSupportManagedProfile = hasManagedProfile();
|
||||||
|
for (int i = 0; i < homeActivities.size(); i++) {
|
||||||
|
final ResolveInfo candidate = homeActivities.get(i);
|
||||||
|
final ActivityInfo info = candidate.activityInfo;
|
||||||
|
ComponentName activityName = new ComponentName(info.packageName, info.name);
|
||||||
|
mAllHomeComponents.add(activityName);
|
||||||
|
if (info.packageName.equals(myPkg)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
components.add(activityName);
|
||||||
|
if (mustSupportManagedProfile && !launcherHasManagedProfilesFeature(candidate, pm)) {
|
||||||
|
summaries.add(getContext().getString(R.string.home_work_profile_not_supported));
|
||||||
|
} else {
|
||||||
|
summaries.add(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setComponentNames(components.toArray(new ComponentName[0]), currentDefaultHome,
|
||||||
|
summaries.toArray(new CharSequence[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean launcherHasManagedProfilesFeature(ResolveInfo resolveInfo, PackageManager pm) {
|
||||||
|
try {
|
||||||
|
ApplicationInfo appInfo = pm.getApplicationInfo(
|
||||||
|
resolveInfo.activityInfo.packageName, 0 /* default flags */);
|
||||||
|
return versionNumberAtLeastL(appInfo.targetSdkVersion);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean versionNumberAtLeastL(int versionNumber) {
|
||||||
|
return versionNumber >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasManagedProfile() {
|
||||||
|
UserManager userManager = getContext().getSystemService(UserManager.class);
|
||||||
|
List<UserInfo> profiles = userManager.getProfiles(getContext().getUserId());
|
||||||
|
for (UserInfo userInfo : profiles) {
|
||||||
|
if (userInfo.isManagedProfile()) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user