Android原生电视设置界面支持翻页

Android原生设置界面不支持翻页操作体验不太友好

以下修改适配支持翻页,优化操作体验

diff --git a/Settings/AndroidManifest.xml b/Settings/AndroidManifest.xml
index c1bc772..d014cbe 100644
--- a/Settings/AndroidManifest.xml
+++ b/Settings/AndroidManifest.xml
@@ -67,6 +67,7 @@
                 android:label="@string/launcher_settings_app_name"
                 android:icon="@drawable/ic_settings_launcher_icon" >
                 <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.LEANBACK_SETTINGS" />
             </intent-filter>
         </activity>
diff --git a/Settings/src/com/android/tv/settings/BaseSettingsFragment.java b/Settings/src/com/android/tv/settings/BaseSettingsFragment.java
index 92e3fa4..7386007 100644
--- a/Settings/src/com/android/tv/settings/BaseSettingsFragment.java
+++ b/Settings/src/com/android/tv/settings/BaseSettingsFragment.java
@@ -33,6 +33,7 @@ import com.android.tv.settings.system.LeanbackPickerDialogPreference;
  */
 
 public abstract class BaseSettingsFragment extends LeanbackSettingsFragment {
+    Fragment mFrag;
     @Override
     public final boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
         final Fragment f =
@@ -43,6 +44,7 @@ public abstract class BaseSettingsFragment extends LeanbackSettingsFragment {
         } else {
             startImmersiveFragment(f);
         }
+        mFrag = f;
         return true;
     }
 
diff --git a/Settings/src/com/android/tv/settings/MainSettings.java b/Settings/src/com/android/tv/settings/MainSettings.java
index db6975b..f476795 100644
--- a/Settings/src/com/android/tv/settings/MainSettings.java
+++ b/Settings/src/com/android/tv/settings/MainSettings.java
@@ -17,15 +17,18 @@
 package com.android.tv.settings;
 
 import android.app.Fragment;
+import android.view.KeyEvent;
 
 /**
  * Main settings which loads up the top level headers.
  */
 public class MainSettings extends TvSettingsActivity {
-
+   
+    SettingsFragment mFrag; 
     @Override
     protected Fragment createSettingsFragment() {
-        return SettingsFragment.newInstance();
+        mFrag =  SettingsFragment.newInstance();
+        return mFrag;
     }
 
     public static class SettingsFragment extends BaseSettingsFragment {
@@ -38,6 +41,24 @@ public class MainSettings extends TvSettingsActivity {
         public void onPreferenceStartInitialScreen() {
             final MainFragment fragment = MainFragment.newInstance();
             startPreferenceFragment(fragment);
+            mFrag = fragment;
+        }
+
+        public void onKeyDown(int keyCode) {
+            if (mFrag instanceof SettingsPreferenceFragment) {
+                ((SettingsPreferenceFragment)mFrag).onKeyDown(keyCode, this);
+            }
+        }
+
+        public void updateContentFragment(SettingsPreferenceFragment f) {
+            mFrag = f;
         }
     }
+
+    @Override
+    public boolean onKeyDown(int keyCode, KeyEvent event) {
+        mFrag.onKeyDown(keyCode);
+        return super.onKeyDown(keyCode,event);
+    }
+
 }
diff --git a/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java b/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java
index 74e7e24..8ecc475 100644
--- a/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java
+++ b/Settings/src/com/android/tv/settings/SettingsPreferenceFragment.java
@@ -30,9 +30,12 @@ import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.v17.preference.LeanbackPreferenceFragment;
 import android.support.v7.preference.PreferenceScreen;
+import android.support.v17.leanback.widget.VerticalGridView;
 import android.view.Menu;
+import android.view.View;
 import android.view.MenuInflater;
 import android.view.MenuItem;
+import android.view.KeyEvent;
 
 import com.android.settingslib.core.instrumentation.Instrumentable;
 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -97,12 +100,15 @@ public abstract class SettingsPreferenceFragment extends LeanbackPreferenceFragm
         super.onStart();
     }
 
+    VerticalGridView vgv;
     @CallSuper
     @Override
     public void onResume() {
         mVisibilityLoggerMixin.setSourceMetricsCategory(getActivity());
         mLifecycle.handleLifecycleEvent(ON_RESUME);
         super.onResume();
+        vgv = (VerticalGridView) getListView();
+        if (mFrag != null) mFrag.updateContentFragment(this);
     }
 
     @CallSuper
@@ -149,4 +155,32 @@ public abstract class SettingsPreferenceFragment extends LeanbackPreferenceFragm
         }
         return lifecycleHandled;
     }
+
+    MainSettings.SettingsFragment mFrag;
+    public void onKeyDown(int keycode, MainSettings.SettingsFragment f) {
+        mFrag = f;
+        View item  = vgv.getChildAt(0);
+	if(item == null) return; 
+	int y0 = item.getBottom();
+	item = vgv.getChildAt(vgv.getChildCount() -1);
+	int ye = item.getBottom();
+	int dy = ye-y0;
+//	Log.e(TAG, "dispatchKeyEvent dy = ye -y0 : dy = "+ye+"- "+y0 + " = "+dy);
+        if (keycode == KeyEvent.KEYCODE_PAGE_DOWN) {
+            vgv.scrollBy(0, dy);
+//            item = vgv.getChildAt();
+            if (item.isFocusable() && !item.hasFocus()) {
+                item.requestFocus(); 
+            }
+	} else if (keycode == KeyEvent.KEYCODE_PAGE_UP) {
+	    vgv.scrollBy(0, -dy);
+            for (int i=0;i<vgv.getChildCount()-1;i++) {
+                item = vgv.getChildAt(i);
+                if (item.isFocusable() && !item.hasFocus()) {
+                    item.requestFocus(); 
+                    break;
+                }
+            }
+	}
+    }    
 }
diff --git a/Settings/src/com/android/tv/settings/connectivity/ConnectivityListener.java b/Settings/src/com/android/tv/settings/connectivity/ConnectivityListener.java
index 81147e8..1845386 100644
--- a/Settings/src/com/android/tv/settings/connectivity/ConnectivityListener.java
+++ b/Settings/src/com/android/tv/settings/connectivity/ConnectivityListener.java
@@ -101,7 +101,7 @@ public class ConnectivityListener implements WifiTracker.WifiListener, Lifecycle
         mConnectivityManager = (ConnectivityManager) mContext.getSystemService(
                 Context.CONNECTIVITY_SERVICE);
         mWifiManager = mContext.getSystemService(WifiManager.class);
-        mEthernetManager = mContext.getSystemService(EthernetManager.class);
+        mEthernetManager = (EthernetManager)(mContext.getSystemService(Context.ETHERNET_SERVICE));
         mListener = listener;
         if (lifecycle != null) {
             mWifiTracker = new WifiTracker(context, this, lifecycle, true, true);
diff --git a/Settings/src/com/android/tv/settings/device/apps/specialaccess/HighPower.java b/Settings/src/com/android/tv/settings/device/apps/specialaccess/HighPower.java
index 74845e2..b9c65bd 100644
--- a/Settings/src/com/android/tv/settings/device/apps/specialaccess/HighPower.java
+++ b/Settings/src/com/android/tv/settings/device/apps/specialaccess/HighPower.java
@@ -38,8 +38,7 @@ import com.android.tv.settings.SettingsPreferenceFragment;
 public class HighPower extends SettingsPreferenceFragment implements
         ManageApplicationsController.Callback {
 
-    private final PowerWhitelistBackend mPowerWhitelistBackend =
-            PowerWhitelistBackend.getInstance();
+    private PowerWhitelistBackend mPowerWhitelistBackend;
     private ManageApplicationsController mManageApplicationsController;
     private final ApplicationsState.AppFilter mFilter =
             new ApplicationsState.CompoundFilter(
@@ -67,6 +66,7 @@ public class HighPower extends SettingsPreferenceFragment implements
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
+        mPowerWhitelistBackend = PowerWhitelistBackend.getInstance(context);
         mManageApplicationsController = new ManageApplicationsController(context, this,
                 getLifecycle(), mFilter, ApplicationsState.ALPHA_COMPARATOR);
     }
packages-apps-TvSettings-Settings.diff

Android原生电视设置界面操作体验优化---支持翻页

修改后 操作的录屏效果。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值