[RK3399][Android7.1.1]TvSettings添加默认主界面(Home app)设置
测试平台
Platform: RK3399
OS: Android 8.1
现象
系统代码中Settings是有默认主界面(Home app)的设置项,但是TvSettings里面却没有,做了一下功能移植。
代码补丁
packages/apps/TvSettings:From dd123ca39ef930cb1fc0faa99c19fd39f348872e Mon Sep 17 00:00:00 2001
From: "sjf@t-chip.com.cn" <sjf@t-chip.com.cn>
Date: Mon, 25 Mar 2019 01:01:27 +0800
Subject: [PATCH] Android->Screen:Add HomeSettings---Settings/AndroidManifest.xml | 16 +-Settings/res/drawable/ic_menu_delete.xml | 25 ++Settings/res/layout/preference_home_app.xml | 88 +++++Settings/res/values-zh-rCN/strings.xml | 5 +Settings/res/values-zh-rHK/strings.xml | 4 +Settings/res/values-zh-rTW/strings.xml | 4 +Settings/res/values/strings.xml | 9 +Settings/res/xml/home_screen.xml | 9 +Settings/res/xml/main_prefs.xml | 5 +-.../src/com/android/tv/settings/MainFragment.java | 2 +-.../tv/settings/system/HomeScreenActivity.java | 43 +++.../tv/settings/system/HomeScreenFragment.java | 390 +++++++++++++++++++++12 files changed, 595 insertions(+), 5 deletions(-)create mode 100644 Settings/res/drawable/ic_menu_delete.xmlcreate mode 100644 Settings/res/layout/preference_home_app.xmlcreate mode 100644 Settings/res/xml/home_screen.xmlcreate mode 100644 Settings/src/com/android/tv/settings/system/HomeScreenActivity.javacreate mode 100644 Settings/src/com/android/tv/settings/system/HomeScreenFragment.javadiff --git a/Settings/AndroidManifest.xml b/Settings/AndroidManifest.xml
index 2cc97aa..c12a331 100644
--- a/Settings/AndroidManifest.xml
+++ b/Settings/AndroidManifest.xml
@@ -55,7 +55,7 @@<intent-filter><action android:name="android.intent.action.MAIN" /><action android:name="android.settings.SETTINGS" />
- <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" /></intent-filter><!-- Intent filter used to display this activity as a settings
@@ -323,6 +323,20 @@<category android:name="android.intent.category.DEFAULT" /></intent-filter></activity>
+
+ <activity
+ android:name=".system.HomeScreenActivity"
+ android:theme="@style/Theme.Settings.Transparent"
+ android:configChanges="keyboard|keyboardHidden|navigation"
+ android:excludeFromRecents="true"
+ android:exported="true" >
+ <intent-filter>
+ <action android:name="android.settings.HOME_SETTINGS" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+<activityandroid:name=".system.LocationActivity"android:theme="@style/Theme.Settings.Transparent"
diff --git a/Settings/res/drawable/ic_menu_delete.xml b/Settings/res/drawable/ic_menu_delete.xml
new file mode 100644
index 0000000..74f63c3
--- /dev/null
+++ b/Settings/res/drawable/ic_menu_delete.xml
@@ -0,0 +1,25 @@
+<!--
+ Copyright (C) 2015 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24.0dp"
+ android:height="24.0dp"
+ android:viewportWidth="48.0"
+ android:viewportHeight="48.0"
+ android:tint="?android:attr/colorAccent">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M12.0,38.0c0.0,2.21 1.79,4.0 4.0,4.0l16.0,0.0c2.21,0.0 4.0,-1.79 4.0,-4.0L36.0,14.0L12.0,14.0l0.0,24.0zM38.0,8.0l-7.0,0.0l-2.0,-2.0L19.0,6.0l-2.0,2.0l-7.0,0.0l0.0,4.0l28.0,0.0L38.0,8.0z"/>
+</vector>
diff --git a/Settings/res/layout/preference_home_app.xml b/Settings/res/layout/preference_home_app.xml
new file mode 100644
index 0000000..c74b7f1
--- /dev/null
+++ b/Settings/res/layout/preference_home_app.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:paddingStart="@*android:dimen/preference_item_padding_side">
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:id="@+id/home_app_pref"
+ android:focusable="true"
+ android:clickable="true"
+ android:gravity="center_vertical"
+ android:background="?android:attr/selectableItemBackground" >
+
+ <RadioButton
+ android:id="@+id/home_radio"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_marginStart="10dip"
+ android:layout_marginEnd="4dip"
+ android:layout_gravity="center_vertical"
+ android:orientation="vertical"
+ android:clickable="false"
+ android:focusable="false" />
+
+ <ImageView
+ android:id="@+android:id/icon"
+ android:layout_width="48dp"
+ android:layout_height="48dp"
+ android:layout_gravity="center"
+ android:minWidth="48dp"
+ android:scaleType="centerInside"
+ android:layout_marginEnd="@*android:dimen/preference_item_padding_inner" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:focusable="true"
+ android:clickable="true"
+ android:gravity="center_vertical"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+android:id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:ellipsize="end" />
+
+ <TextView
+ android:id="@+android:id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmall" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <View
+ android:id="@+id/home_divider"
+ android:layout_width="2dip"
+ android:layout_height="match_parent"
+ android:layout_marginTop="5dip"
+ android:layout_marginBottom="5dip"
+ android:background="@android:drawable/divider_horizontal_dark" />
+
+ <ImageView
+ android:id="@+id/home_app_uninstall"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:paddingStart="12dip"
+ android:paddingEnd="12dp"
+ android:src="@drawable/ic_menu_delete"
+ android:contentDescription="@string/home_app_uninstall_button"
+ android:layout_gravity="center"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?android:attr/selectableItemBackground" />
+
+</LinearLayout>
diff --git a/Settings/res/values-zh-rCN/strings.xml b/Settings/res/values-zh-rCN/strings.xml
index 54dd3c0..940c2e0 100644
--- a/Settings/res/values-zh-rCN/strings.xml
+++ b/Settings/res/values-zh-rCN/strings.xml
@@ -674,4 +674,9 @@<string name="app_permission_summary_not_allowed" msgid="3667663331476577913">"不允许"</string><string name="usage_access" msgid="1914242907684452328">"使用情况访问权限"</string><string name="usage_access_description" msgid="6290001769893747651">"使用情况访问权限允许应用跟踪您正在使用的其他应用和使用频率,以及您的运营商、语言设置及其他详细信息。"</string>
+
+ <string name="home_settings">"主屏幕"</string>
+ <string name="home_app_uninstall_button">"卸载此应用"</string>
+ <string name="only_one_home_message">"在您安装其他主屏幕应用之前,主屏幕设置将一直处于隐藏状态。"</string>
+ </resources>
diff --git a/Settings/res/values-zh-rHK/strings.xml b/Settings/res/values-zh-rHK/strings.xml
index 43c6729..aa9191b 100644
--- a/Settings/res/values-zh-rHK/strings.xml
+++ b/Settings/res/values-zh-rHK/strings.xml
@@ -674,4 +674,8 @@<string name="app_permission_summary_not_allowed" msgid="3667663331476577913">"不允許"</string><string name="usage_access" msgid="1914242907684452328">"使用記錄存取權"</string><string name="usage_access_description" msgid="6290001769893747651">"使用記錄存取權允許應用程式追蹤您正在使用的其他應用程式、使用頻率、流動服務供應商、語言設定和其他詳情。"</string>
+
+ <string name="home_settings" msgid="212375129455718176">"主畫面"</string>
+ <string name="home_app_uninstall_button">"解除安裝這個應用程式"</string>
+ <string name="only_one_home_message">"主畫面設定將會隱藏,直至您安裝另一個主畫面應用程式為止。"</string></resources>
diff --git a/Settings/res/values-zh-rTW/strings.xml b/Settings/res/values-zh-rTW/strings.xml
index 516105c..53d1913 100644
--- a/Settings/res/values-zh-rTW/strings.xml
+++ b/Settings/res/values-zh-rTW/strings.xml
@@ -674,4 +674,8 @@<string name="app_permission_summary_not_allowed" msgid="3667663331476577913">"不允許"</string><string name="usage_access" msgid="1914242907684452328">"使用紀錄存取權"</string><string name="usage_access_description" msgid="6290001769893747651">"具有使用紀錄存取權的應用程式可以追蹤你使用的其他應用程式與頻率,以及你的電信業者、語言設定和其他詳細資料。"</string>
+
+ <string name="home_settings" msgid="212375129455718176">"主畫面"</string>
+ <string name="home_app_uninstall_button">"解除安裝這個應用程式"</string>
+ <string name="only_one_home_message">"必須安裝其他主螢幕應用程式,主螢幕設定才會顯示。"</string></resources>
diff --git a/Settings/res/values/strings.xml b/Settings/res/values/strings.xml
index 88cfc1a..fe981c7 100644
--- a/Settings/res/values/strings.xml
+++ b/Settings/res/values/strings.xml
@@ -1469,4 +1469,13 @@<!-- Description of the usage access setting [CHAR LIMIT=NONE] --><string name="usage_access_description">Usage access allows an app to track what other apps you\u2019re using and how often, as well as your carrier, language settings, and other details.</string>+
+ <string name="home_settings">Home</string>
+ <!-- Home application selection - uninstall button [CHAR LIMIT=80] -->
+ <string name="home_app_uninstall_button">Uninstall this application</string>
+ <!-- Message to user that Home Settings will be hidden because there is now only one available home application -->
+ <string name="only_one_home_message">Home settings will be hidden until you install another home application.</string>
+
+ <!-- Home settings screen, text indicating that a launcer does not support work profiles [CHAR LIMIT=100] -->
+ <string name="home_work_profile_not_supported">Doesn\u2019t support work profiles</string></resources>
diff --git a/Settings/res/xml/home_screen.xml b/Settings/res/xml/home_screen.xml
new file mode 100644
index 0000000..7e09d95
--- /dev/null
+++ b/Settings/res/xml/home_screen.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:title="@string/system_home"
+ android:key="home_settings">
+
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/Settings/res/xml/main_prefs.xml b/Settings/res/xml/main_prefs.xml
index 5d4b494..d1a62a8 100644
--- a/Settings/res/xml/main_prefs.xml
+++ b/Settings/res/xml/main_prefs.xml
@@ -84,9 +84,8 @@<Preferenceandroid:icon="@drawable/ic_home"android:key="home"
- android:title="@string/system_home" >
- <intent android:action="com.google.android.tvlauncher.SETTINGS" />
- </Preference>
+ android:title="@string/system_home"
+ android:fragment="com.android.tv.settings.system.HomeScreenFragment" /><Preferenceandroid:icon="@drawable/ic_search"android:key="search"
diff --git a/Settings/src/com/android/tv/settings/MainFragment.java b/Settings/src/com/android/tv/settings/MainFragment.java
index a48a734..4970f7e 100644
--- a/Settings/src/com/android/tv/settings/MainFragment.java
+++ b/Settings/src/com/android/tv/settings/MainFragment.java
@@ -162,7 +162,7 @@ public class MainFragment extends LeanbackPreferenceFragment {updateSounds();updateGoogleSettings();- hideIfIntentUnhandled(findPreference(KEY_HOME_SETTINGS));
+ //hideIfIntentUnhandled(findPreference(KEY_HOME_SETTINGS));hideIfIntentUnhandled(findPreference(KEY_CAST_SETTINGS));hideIfIntentUnhandled(findPreference(KEY_USAGE));hideIfIntentUnhandled(findPreference(KEY_SPEECH_SETTINGS));
diff --git a/Settings/src/com/android/tv/settings/system/HomeScreenActivity.java b/Settings/src/com/android/tv/settings/system/HomeScreenActivity.java
new file mode 100644
index 0000000..ee0176f
--- /dev/null
+++ b/Settings/src/com/android/tv/settings/system/HomeScreenActivity.java
@@ -0,0 +1,43 @@
+/*
+ * 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.tv.settings.system;
+
+import android.app.Fragment;
+
+import com.android.tv.settings.BaseSettingsFragment;
+import com.android.tv.settings.TvSettingsActivity;
+
+public class HomeScreenActivity extends TvSettingsActivity {+
+ @Override
+ protected Fragment createSettingsFragment() {+ return SettingsFragment.newInstance();
+ }
+
+ public static class SettingsFragment extends BaseSettingsFragment {+
+ public static SettingsFragment newInstance() {+ return new SettingsFragment();
+ }
+
+ @Override
+ public void onPreferenceStartInitialScreen() {+ startPreferenceFragment(HomeScreenFragment.newInstance());
+ }
+ }
+
+}
diff --git a/Settings/src/com/android/tv/settings/system/HomeScreenFragment.java b/Settings/src/com/android/tv/settings/system/HomeScreenFragment.java
new file mode 100644
index 0000000..56abdb2
--- /dev/null
+++ b/Settings/src/com/android/tv/settings/system/HomeScreenFragment.java
@@ -0,0 +1,390 @@
+/*
+ * Copyright (C) 2015 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.tv.settings.system;
+
+import android.app.ActivityManager;
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.Uri;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.UserManager;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v17.preference.LeanbackPreferenceFragment;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceGroup;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.text.TextUtils;
+import android.text.format.DateFormat;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.ImageView;
+import android.widget.RadioButton;
+
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.UserInfo;
+import android.graphics.ColorFilter;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.drawable.Drawable;
+
+import com.android.tv.settings.R;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+public class HomeScreenFragment extends LeanbackPreferenceFragment implements
+ Preference.OnPreferenceChangeListener {+ static final String TAG = "HomeScreen";
+
+ public static final String HOME_PREFS = "home_prefs";
+ public static final String HOME_PREFS_DO_SHOW = "do_show";
+
+ public static final String HOME_SHOW_NOTICE = "show";
+
+ private static final String KEY_HOME_SETTINGS = "home_settings";
+
+ private static final String EXTRA_SUPPORT_MANAGED_PROFILES = "support_managed_profiles";
+
+ static final int REQUESTING_UNINSTALL = 10;
+
+ public static HomeScreenFragment newInstance() {+ return new HomeScreenFragment();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {+ setPreferencesFromResource(R.xml.home_screen, null);
+
+ mPm = getActivity().getPackageManager();
+ mPrefGroup = (PreferenceGroup) findPreference(KEY_HOME_SETTINGS);
+
+ mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
+ mHomeFilter.addCategory(Intent.CATEGORY_HOME);
+ mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
+ }
+
+ @Override
+ public void onResume() {+ super.onResume();
+
+ final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
+ filter.addDataScheme("package");
+ getActivity().registerReceiver(mHomePackageReceiver, filter);
+
+ buildHomeActivitiesList();
+
+ }
+
+ @Override
+ public void onPause() {+ super.onPause();
+ getActivity().unregisterReceiver(mHomePackageReceiver);
+ }
+
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {+ super.onActivityResult(requestCode, resultCode, data);
+
+ // Rebuild the list now that we might have nuked something
+ buildHomeActivitiesList();
+
+ // if the previous home app is now gone, fall back to the system one
+ if (requestCode > REQUESTING_UNINSTALL) {+ // if mCurrentHome has gone null, it means we didn't find the previously-
+ // default home app when rebuilding the list, i.e. it was the one we
+ // just uninstalled. When that happens we make the system-bundled
+ // home app the active default.
+ if (mCurrentHome == null) {+ for (int i = 0; i < mPrefs.size(); i++) {+ HomeAppPreference pref = mPrefs.get(i);
+ if (pref.isSystem) {+ makeCurrentHome(pref);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {+ return true;
+ }
+
+ private class HomePackageReceiver extends BroadcastReceiver {+ @Override
+ public void onReceive(Context context, Intent intent) {+ buildHomeActivitiesList();
+ }
+ }
+
+ private PreferenceGroup mPrefGroup;
+ private PackageManager mPm;
+ private ComponentName[] mHomeComponentSet;
+ private ArrayList<HomeAppPreference> mPrefs;
+ private HomeAppPreference mCurrentHome = null;
+ private IntentFilter mHomeFilter;
+ private boolean mShowNotice;
+ private HomePackageReceiver mHomePackageReceiver = new HomePackageReceiver();
+
+ private void buildHomeActivitiesList() {+ ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
+ ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
+
+ Context context = getActivity();
+ mCurrentHome = null;
+ mPrefGroup.removeAll();
+ mPrefs = new ArrayList<HomeAppPreference>();
+ mHomeComponentSet = new ComponentName[homeActivities.size()];
+ int prefIndex = 0;
+ boolean supportManagedProfilesExtra =
+ getActivity().getIntent().getBooleanExtra(EXTRA_SUPPORT_MANAGED_PROFILES, false);
+ boolean mustSupportManagedProfile = hasManagedProfile()
+ || supportManagedProfilesExtra;
+ 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);
+ mHomeComponentSet[i] = activityName;
+ try {+ Drawable icon = info.loadIcon(mPm);
+ CharSequence name = info.loadLabel(mPm);
+ HomeAppPreference pref;
+
+ if (mustSupportManagedProfile && !launcherHasManagedProfilesFeature(candidate)) {+ pref = new HomeAppPreference(context, activityName, prefIndex,
+ icon, name, this, info, false /* not enabled */,
+ context.getResources().getString(R.string.home_work_profile_not_supported));
+ } else {+ pref = new HomeAppPreference(context, activityName, prefIndex,
+ icon, name, this, info, true /* enabled */, null);
+ }
+
+ if ((info.flags & ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS) == 0){+ mPrefs.add(pref);
+ mPrefGroup.addPreference(pref);
+ }
+ if (activityName.equals(currentDefaultHome)) {+ mCurrentHome = pref;
+ }
+ prefIndex++;
+ } catch (Exception e) {+ Log.v(TAG, "Problem dealing with activity " + activityName, e);
+ }
+ }
+
+ if (mCurrentHome != null) {+ if (mCurrentHome.isEnabled()) {+ getActivity().setResult(Activity.RESULT_OK);
+ }
+
+ new Handler().post(new Runnable() {+ public void run() {+ mCurrentHome.setChecked(true);
+ }
+ });
+ }
+ }
+
+
+ private boolean hasManagedProfile() {+ Context context = getActivity();
+ UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ List<UserInfo> profiles = userManager.getProfiles(context.getUserId());
+ for (UserInfo userInfo : profiles) {+ if (userInfo.isManagedProfile()) return true;
+ }
+ return false;
+ }
+
+ private boolean launcherHasManagedProfilesFeature(ResolveInfo resolveInfo) {+ try {+ ApplicationInfo appInfo = getActivity().getPackageManager().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;
+ }
+
+ OnClickListener mHomeClickListener = new OnClickListener() {+ @Override
+ public void onClick(View v) {+ int index = (Integer)v.getTag();
+ HomeAppPreference pref = mPrefs.get(index);
+ if (!pref.isChecked) {+ makeCurrentHome(pref);
+ }
+ }
+ };
+
+ OnClickListener mDeleteClickListener = new OnClickListener() {+ @Override
+ public void onClick(View v) {+ int index = (Integer)v.getTag();
+ uninstallApp(mPrefs.get(index));
+ }
+ };
+
+ void makeCurrentHome(HomeAppPreference newHome) {+ if (mCurrentHome != null) {+ mCurrentHome.setChecked(false);
+ }
+ newHome.setChecked(true);
+ mCurrentHome = newHome;
+
+ mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,
+ mHomeComponentSet, newHome.activityName);
+
+ getActivity().setResult(Activity.RESULT_OK);
+ }
+
+ void uninstallApp(HomeAppPreference pref) {+ // Uninstallation is done by asking the OS to do it
+ Uri packageURI = Uri.parse("package:" + pref.uninstallTarget);
+ Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
+ uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, false);
+ int requestCode = REQUESTING_UNINSTALL + (pref.isChecked ? 1 : 0);
+ startActivityForResult(uninstallIntent, requestCode);
+ }
+
+
+ private class HomeAppPreference extends Preference {+ ComponentName activityName;
+ int index;
+ HomeScreenFragment fragment;
+ final ColorFilter grayscaleFilter;
+ boolean isChecked;
+
+ boolean isSystem;
+ String uninstallTarget;
+
+ public HomeAppPreference(Context context, ComponentName activity,
+ int i, Drawable icon, CharSequence title, HomeScreenFragment parent, ActivityInfo info,
+ boolean enabled, CharSequence summary) {+ super(context);
+ setLayoutResource(R.layout.preference_home_app);
+ setIcon(icon);
+ setTitle(title);
+ setEnabled(enabled);
+ setSummary(summary);
+ activityName = activity;
+ fragment = parent;
+ index = i;
+
+ ColorMatrix colorMatrix = new ColorMatrix();
+ colorMatrix.setSaturation(0f);
+ float[] matrix = colorMatrix.getArray();
+ matrix[18] = 0.5f;
+ grayscaleFilter = new ColorMatrixColorFilter(colorMatrix);
+
+ determineTargets(info);
+ }
+
+ // Check whether this activity is bundled on the system, with awareness
+ // of the META_HOME_ALTERNATE mechanism.
+ private void determineTargets(ActivityInfo info) {+ final Bundle meta = info.metaData;
+ if (meta != null) {+ final String altHomePackage = meta.getString(ActivityManager.META_HOME_ALTERNATE);
+ if (altHomePackage != null) {+ try {+ final int match = mPm.checkSignatures(info.packageName, altHomePackage);
+ if (match >= PackageManager.SIGNATURE_MATCH) {+ PackageInfo altInfo = mPm.getPackageInfo(altHomePackage, 0);
+ final int altFlags = altInfo.applicationInfo.flags;
+ isSystem = (altFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
+ uninstallTarget = altInfo.packageName;
+ return;
+ }
+ } catch (Exception e) {+ // e.g. named alternate package not found during lookup
+ Log.w(TAG, "Unable to compare/resolve alternate", e);
+ }
+ }
+ }
+ // No suitable metadata redirect, so use the package's own info
+ isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
+ uninstallTarget = info.packageName;
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder view) {+ super.onBindViewHolder(view);
+
+ RadioButton radio = (RadioButton) view.findViewById(R.id.home_radio);
+ radio.setChecked(isChecked);
+
+ Integer indexObj = new Integer(index);
+
+ ImageView icon = (ImageView) view.findViewById(R.id.home_app_uninstall);
+ if (isSystem) {+ icon.setEnabled(false);
+ icon.setColorFilter(grayscaleFilter);
+ } else {+ icon.setEnabled(true);
+ icon.setOnClickListener(mDeleteClickListener);
+ icon.setTag(indexObj);
+ }
+
+ View v = view.findViewById(R.id.home_app_pref);
+ v.setTag(indexObj);
+
+ v.setOnClickListener(mHomeClickListener);
+ }
+
+ void setChecked(boolean state) {+ if (state != isChecked) {+ isChecked = state;
+ notifyChanged();
+ }
+ }
+ }
+
+
+
+}
--
2.7.4
[RK3399][Android7.1.1]TvSettings添加默认主界面(Home app)设置相关推荐
- [RK3399][Android7.1] 调试笔记 --- 系统默认时钟配置
OS: Android 7.1 Board: Firefly-RK3399 Kernel: v4.4.55 分两个模块,一个是cpu,还有一个是pmu模块,这里只举例cpu,cpu又分在两个文件中定义 ...
- 类WebOS(添加了主界面,及相关功能代码)
上个月为了练练手,加上本学期我有网站编程(jsp相关的)这们课,而且老师要求说学期末做个网站的作品,语言和工具不限,所以我先选择了用vs2010,asp.net 相关的知识来做这个小东西,接下来先看看 ...
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(4)之 游戏主界面 -----怪物系统---赌徒来袭
兄弟们相比等这一章 等的时间比较长了吧!呵呵这几天公司的事情比较忙每天都只有晚上回来写会.所以进度慢了,不过兄弟们放心 我会坚持把这个游戏写完的写成一个可以买的游戏!哈哈 吹下牛了 其实在开发游戏的过 ...
- android+tv盒子+主界面,x96max+ 盒子 与 CoreELEC系统配置(三)AndroidTV刷机记录
x96max+ 盒子 与 CoreELEC系统配置(三)AndroidTV刷机记录 2020-03-19 22:05:49 39点赞 211收藏 59评论 本文简要记录一下AndroidTV的刷机过程 ...
- 在线拍卖系统后台,主界面布局,逻辑
这里写自定义目录标题 主界面布局 菜单栏&逻辑(未设置样式) 主界面布局 布局依旧采用的是大众款,(标题栏+菜单栏+主界面),因没设置资源字典,这里不多说,直接上代码吧 <Window ...
- android手机底噪,[RK3399][Android7.1] 调试笔记 --- Codec播放音乐会有底噪
Platform: RK3399 OS: Android 7.1 Kernel: v4.4.83 背景: 移植完Codec RT5640之后,发现播放声音的时候底部有噪声. 用示波器测量到的左右声道波 ...
- [RK3399][Android7.1] 调试笔记 --- I2S1工作输出是12MHz问题
Platform: RK3399 OS: Android 7.1 Kernel: v4.4.83 现象: 使用I2S1通道,测量到的I2S MCLK是12MHz. 理论上应该是11.288MHz. 原 ...
- java窗体添加背景图片_Java项目实战之实战之天天酷跑(四):游戏主界面
接上文,本文将实现游戏主界面,功能如下: 移动的背景图片.动态的玩家.玩家的移动功能.五种障碍物持续出现.玩家和障碍物的碰撞.暂停.继续功能. 首先,看一下整体效果: 动图实在太大,几秒钟的 Gif ...
- 【原】WPF 主界面布局中DockPanel的停靠与默认填充
在WPF中,通常的主界面大都是DockPanel 根元素,一次DockPanel .Top主菜单.DockPanel .Top Toolbar.DockPanel .Bottom Statusbar, ...
最新文章
- mysql中的if else decode
- 遇java.lang.OutOfMemoryError: PermGen space之解决方案
- pytorch iou计算
- 编辑器扩展_关于MediaWiki的编辑器
- asp.net webform 局部发布更新
- html5访问本地资源,HTML5实现一个访问本地文件的实例今
- Topcoder SRM 655 DIV1 250 CountryGroupHard
- linux 下.bashrc和.profile的区别
- B1816 扑克牌 二分答案 + 贪心
- 自己做了个微信小程序
- 如何一键开通局域网共享
- 主编编辑器怎么把文章转成长图?
- 一些成功又不失趣味的网络营销案例
- gitlab CI/CD 持续集成 部署 一文到底
- iOS App Crash 防护框架之 MKCrashGuard
- linux查询socket资源,TCP的socket资源被耗尽的问题
- Deferred Decal(延迟贴花)
- 使用AVProVideo的一点小坑
- 【Python】破解摩斯密码
- python 股票竞价数据_GitHub - TruthHun/auction-stock: 集合竞价选股(股票),基于收盘价与前收盘价的选股策略...