[Android] [PATCH] Add settings in TV app
Geoffrey Métais
geoffrey.metais at gmail.com
Mon Dec 1 17:06:31 CET 2014
---
vlc-android/res/xml/preferences.xml | 4 ++-
.../org/videolan/vlc/gui/PreferencesActivity.java | 7 +++++
.../vlc/gui/video/VideoBrowserInterface.java | 1 +
.../org/videolan/vlc/gui/tv/MainTvActivity.java | 35 +++++++---------------
.../org/videolan/vlc/gui/tv/StringPresenter.java | 10 ++++++-
5 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml
index 61510ed..9592979 100644
--- a/vlc-android/res/xml/preferences.xml
+++ b/vlc-android/res/xml/preferences.xml
@@ -36,7 +36,9 @@
android:title="@string/subtitle_text_encoding" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/extra_prefs_category" >
- <PreferenceScreen android:title="@string/interface_prefs_screen" >
+ <PreferenceScreen
+ android:title="@string/interface_prefs_screen"
+ android:key="ui_category" >
<PreferenceCategory android:title="@string/interface_secondary_display_category" >
<Preference android:summary="@string/interface_secondary_display_category_summary" />
diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 9f0109c..fc7d695 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -28,6 +28,7 @@ import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.audio.AudioService;
import org.videolan.vlc.audio.AudioServiceController;
import org.videolan.vlc.gui.audio.AudioUtil;
+import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.BitmapCache;
import org.videolan.vlc.util.Logcat;
import org.videolan.vlc.util.VLCInstance;
@@ -71,6 +72,12 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
+ if (!AndroidDevices.hasTsp()){
+ findPreference("screen_orientation").setEnabled(false);
+ findPreference("enable_black_theme").setEnabled(false);
+ findPreference("ui_category").setEnabled(false);
+ }
+
// Directories
Preference directoriesPref = findPreference("directories");
directoriesPref.setOnPreferenceClickListener(
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
index b06a5e7..89dc6ae 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoBrowserInterface.java
@@ -8,6 +8,7 @@ public interface VideoBrowserInterface {
public static final long HEADER_VIDEO = 0;
public static final long HEADER_MUSIC = 1;
public static final long HEADER_CATEGORIES = 2;
+ public static final long HEADER_MISC = 3;
public static final long FILTER_ARTIST = 3;
public static final long FILTER_GENRE = 4;
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index e3c1558..ddfdb51 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -30,6 +30,7 @@ import org.videolan.vlc.MediaDatabase;
import org.videolan.vlc.MediaLibrary;
import org.videolan.vlc.R;
import org.videolan.vlc.Thumbnailer;
+import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
import org.videolan.vlc.gui.video.VideoBrowserInterface;
import org.videolan.vlc.gui.video.VideoListHandler;
@@ -67,8 +68,8 @@ public class MainTvActivity extends Activity implements VideoBrowserInterface {
private Media mItemToUpdate;
ArrayObjectAdapter mRowsAdapter;
ArrayObjectAdapter mVideoAdapter;
- ArrayObjectAdapter mAudioAdapter;
ArrayObjectAdapter mCategoriesAdapter;
+ ArrayObjectAdapter mOtherAdapter;
HashMap<String, Integer> mVideoIndex;
Drawable mDefaultBackground;
Activity mContext;
@@ -81,8 +82,10 @@ public class MainTvActivity extends Activity implements VideoBrowserInterface {
Intent intent = new Intent(mContext, VerticalGridActivity.class);
intent.putExtra(AUDIO_CATEGORY, category);
startActivity(intent);
- } else
+ } else if (row.getId() == HEADER_VIDEO)
TvUtil.openMedia(mContext, (Media)item, row);
+ else if (row.getId() == HEADER_MISC)
+ startActivity(new Intent(mContext, PreferencesActivity.class));
}
};
@@ -244,29 +247,6 @@ public class MainTvActivity extends Activity implements VideoBrowserInterface {
mRowsAdapter.add(new ListRow(header, mVideoAdapter));
}
- /*// update audio section
- if (!audioList.isEmpty()) {
- size = audioList.size();
- if (NUM_ITEMS_PREVIEW < size)
- size = NUM_ITEMS_PREVIEW;
- mAudioAdapter = new ArrayObjectAdapter(new CardPresenter());
- for (int i = 0 ; i < size ; ++i) {
- item = audioList.get(i);
- picture = AudioUtil.getCover(mContext, item, 320);
- if (picture != null){
- MediaDatabase.setPicture(item, picture);
- picture = null;
- }
- mAudioAdapter.add(item);
-
- }
- // Empty item to launch grid activity
- mAudioAdapter.add(new Media(null, 0, 0, Media.TYPE_GROUP, null, "Browse more", null, null, null, 0, 0, null, 0, 0));
-
- HeaderItem header = new HeaderItem(HEADER_MUSIC, getString(R.string.audio), null);
- mRowsAdapter.add(new ListRow(header, mAudioAdapter));
- }*/
-
mCategoriesAdapter = new ArrayObjectAdapter(new CardPresenter());
mCategoriesAdapter.add(getString(R.string.artists));
mCategoriesAdapter.add(getString(R.string.albums));
@@ -275,6 +255,11 @@ public class MainTvActivity extends Activity implements VideoBrowserInterface {
HeaderItem header = new HeaderItem(HEADER_CATEGORIES, getString(R.string.audio), null);
mRowsAdapter.add(new ListRow(header, mCategoriesAdapter));
+ mOtherAdapter = new ArrayObjectAdapter(new StringPresenter());
+ mOtherAdapter.add(getString(R.string.preferences));
+ header = new HeaderItem(HEADER_MISC, getString(R.string.other), null);
+ mRowsAdapter.add(new ListRow(header, mOtherAdapter));
+
return null;
}
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/StringPresenter.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/StringPresenter.java
index 34941e0..8e1f350 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/StringPresenter.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/StringPresenter.java
@@ -21,6 +21,7 @@ package org.videolan.vlc.gui.tv;
import org.videolan.vlc.R;
+import android.content.res.Resources;
import android.support.v17.leanback.widget.Presenter;
import android.view.ViewGroup;
import android.widget.TextView;
@@ -38,7 +39,14 @@ public class StringPresenter extends Presenter {
}
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
- ((TextView) viewHolder.view).setText(item.toString());
+ Resources res = viewHolder.view.getContext().getResources();
+ TextView tv = (TextView) viewHolder.view;
+ tv.setText(item.toString());
+ if (res.getString(R.string.preferences).equals(item.toString())) {
+ tv.setBackground(res.getDrawable(R.drawable.ic_menu_preferences));
+ }
+ tv.setHeight(res.getDimensionPixelSize(R.dimen.tv_card_height));
+ tv.setWidth(res.getDimensionPixelSize(R.dimen.tv_card_width));
}
public void onUnbindViewHolder(ViewHolder viewHolder) {
--
1.9.1
More information about the Android
mailing list