[Android] Add actionbar in Settings sub-categories

Geoffrey Métais git at videolan.org
Fri Jul 10 16:17:22 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jul 10 16:11:20 2015 +0200| [20f5252937174a848169c9d09869f26e7fa1ee09] | committer: Geoffrey Métais

Add actionbar in Settings sub-categories

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=20f5252937174a848169c9d09869f26e7fa1ee09
---

 .../org/videolan/vlc/gui/PreferencesActivity.java  |   47 ++++++++++++++++++--
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index dec15d1..1f02935 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -314,7 +314,6 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
     protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);
         Toolbar bar;
-
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
             LinearLayout root = (LinearLayout) getListView().getParent().getParent().getParent();
             bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false);
@@ -372,9 +371,10 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
     }
 
     @Override
-    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
-    {
+    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
         super.onPreferenceTreeClick(preferenceScreen, preference);
+        if (preference instanceof PreferenceScreen)
+            setUpNestedScreen((PreferenceScreen) preference);
         try {
             if (preference!=null && preference instanceof PreferenceScreen) {
                 Dialog dialog = ((PreferenceScreen)preference).getDialog();
@@ -400,4 +400,45 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
     public void onDisconnected() {
         mService = null;
     }
+
+    public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
+        final Dialog dialog = preferenceScreen.getDialog();
+
+        Toolbar bar;
+
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
+            LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
+            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false);
+            root.addView(bar, 0); // insert at top
+        } else {
+            ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
+            ListView content = (ListView) root.getChildAt(0);
+
+            root.removeAllViews();
+
+            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false);
+
+            int height;
+            TypedValue tv = new TypedValue();
+            if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
+                height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
+            }else{
+                height = bar.getHeight();
+            }
+
+            content.setPadding(0, height, 0, 0);
+
+            root.addView(content);
+            root.addView(bar);
+        }
+
+        bar.setTitle(preferenceScreen.getTitle());
+
+        bar.setNavigationOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                dialog.dismiss();
+            }
+        });
+    }
 }



More information about the Android mailing list