[Android] Toolbar in settings

Geoffrey Métais git at videolan.org
Mon Mar 2 17:22:59 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar  2 17:22:38 2015 +0100| [96fc8b087a6f7d3dfcfeccc45c369a5392e3ca8c] | committer: Geoffrey Métais

Toolbar in settings

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

 vlc-android/AndroidManifest.xml                    |    3 +-
 vlc-android/res/layout/main.xml                    |    6 +-
 vlc-android/res/layout/toolbar.xml                 |    9 +++
 .../src/org/videolan/vlc/gui/MainActivity.java     |    2 +-
 .../org/videolan/vlc/gui/PreferencesActivity.java  |   76 ++++++++++++++++----
 5 files changed, 76 insertions(+), 20 deletions(-)

diff --git a/vlc-android/AndroidManifest.xml b/vlc-android/AndroidManifest.xml
index 67615c4..ee33a8f 100644
--- a/vlc-android/AndroidManifest.xml
+++ b/vlc-android/AndroidManifest.xml
@@ -57,7 +57,8 @@
             </intent-filter>
         </activity>
         <activity android:name=".gui.CompatErrorActivity" />
-        <activity android:name=".gui.PreferencesActivity" />
+        <activity android:name=".gui.PreferencesActivity"
+            android:theme="@style/Theme.VLC" />
         <activity
             android:name=".gui.BrowserActivity"
             android:label="@string/mediafiles"
diff --git a/vlc-android/res/layout/main.xml b/vlc-android/res/layout/main.xml
index f4f475f..f78d4f1 100644
--- a/vlc-android/res/layout/main.xml
+++ b/vlc-android/res/layout/main.xml
@@ -83,9 +83,5 @@
         <include layout="@layout/sidebar"/>
     </android.support.v4.widget.DrawerLayout>
 
-    <android.support.v7.widget.Toolbar
-        android:id="@+id/main_toolbar"
-        android:layout_height="?attr/actionBarSize"
-        android:layout_width="match_parent"
-        android:background="?attr/background_actionbar" />
+    <include layout="@layout/toolbar"/>
 </FrameLayout>
diff --git a/vlc-android/res/layout/toolbar.xml b/vlc-android/res/layout/toolbar.xml
new file mode 100644
index 0000000..1ccc78d
--- /dev/null
+++ b/vlc-android/res/layout/toolbar.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v7.widget.Toolbar
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:id="@+id/main_toolbar"
+    android:layout_width="match_parent"
+    android:layout_height="?attr/actionBarSize"
+    app:navigationContentDescription="@string/abc_action_bar_up_description"
+    android:background="?attr/background_actionbar"/>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index c6fd16d..49545a6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -188,7 +188,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
         setContentView(R.layout.main);
 
         Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
-        toolbar.setTitleTextColor(getResources().getColor(Util.getResourceFromAttribute(mContext, R.attr.font_actionbar_selected)));
+        toolbar.setTitleTextColor(Util.getColorFromAttribute(mContext, R.attr.font_actionbar_selected));
         setSupportActionBar(toolbar);
 
         mSlidingPane = (SlidingPaneLayout) findViewById(R.id.pane);
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index c21627d..58660e8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -41,7 +41,9 @@ import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.graphics.Color;
 import android.graphics.drawable.Drawable.ConstantState;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.preference.CheckBoxPreference;
@@ -54,8 +56,15 @@ import android.preference.PreferenceActivity;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceScreen;
+import android.support.v7.widget.Toolbar;
 import android.text.format.DateFormat;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
 import android.view.Window;
+import android.widget.LinearLayout;
+import android.widget.ListView;
 import android.widget.Toast;
 
 @SuppressWarnings("deprecation")
@@ -149,19 +158,19 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
                         new AlertDialog.Builder(PreferencesActivity.this)
-                        .setTitle(R.string.clear_history)
-                        .setMessage(R.string.validation)
-                        .setIcon(android.R.drawable.ic_dialog_alert)
-                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
-
-                            @Override
-                            public void onClick(DialogInterface dialog, int whichButton) {
-                                MediaDatabase db = MediaDatabase.getInstance();
-                                db.clearSearchHistory();
-                            }
-                        })
-
-                        .setNegativeButton(android.R.string.cancel, null).show();
+                                .setTitle(R.string.clear_history)
+                                .setMessage(R.string.validation)
+                                .setIcon(android.R.drawable.ic_dialog_alert)
+                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
+
+                                    @Override
+                                    public void onClick(DialogInterface dialog, int whichButton) {
+                                        MediaDatabase db = MediaDatabase.getInstance();
+                                        db.clearSearchHistory();
+                                    }
+                                })
+
+                                .setNegativeButton(android.R.string.cancel, null).show();
                         return true;
                     }
                 });
@@ -268,6 +277,47 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
     }
 
     @Override
+    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);
+            root.addView(bar, 0); // insert at top
+        } else {
+            ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
+            ListView content = (ListView) root.getChildAt(0);
+
+            root.removeAllViews();
+
+            bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.toolbar, root, false);
+            root.addView(bar);
+
+            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);
+        }
+        bar.setTitle(R.string.preferences);
+        bar.setTitleTextColor(Util.getColorFromAttribute(this, R.attr.font_actionbar_selected));
+
+        bar.setNavigationOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+    }
+
+    @Override
     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
         if(key.equalsIgnoreCase("hardware_acceleration")
                 || key.equalsIgnoreCase("subtitle_text_encoding")



More information about the Android mailing list