From 19a871d63a3522f90053247ec5de610d9d6c8249 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Tue, 12 Aug 2014 23:29:20 -0400 Subject: [PATCH] Add option to control audio title alignment Addresses a potential usability issue Close #11882 --- vlc-android/res/values/strings.xml | 23 +++++++++++++++++-- vlc-android/res/xml/preferences.xml | 17 ++++++++++---- .../videolan/vlc/gui/DirectoryAdapter.java | 8 +++++++ .../gui/audio/AudioBrowserListAdapter.java | 8 +++++++ .../vlc/gui/audio/AudioPlaylistAdapter.java | 6 +++++ .../src/org/videolan/vlc/util/Util.java | 23 +++++++++++++++++++ 6 files changed, 78 insertions(+), 7 deletions(-) diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml index d9a2a1192..cd02aab07 100644 --- a/vlc-android/res/values/strings.xml +++ b/vlc-android/res/values/strings.xml @@ -228,12 +228,18 @@ Interface - Other Enable brightness gesture Control brightness by gesture during video playback - Detect headset - Pause on headset removal; resume on headset insertion Enable jump buttons Show backward and forward buttons on the video interface + Audio title alignment + Detect headset + Pause on headset removal; resume on headset insertion Exclusive headset remote control Avoid conflicts by stealing the remote control from other apps. This prevents dialing on double click on HTC phones. + Default + Left + Centre + Right + Marquee Performance Force video chroma @@ -333,6 +339,19 @@ 9 + + @string/audio_title_alignment_default + @string/audio_title_alignment_left + @string/audio_title_alignment_right + @string/audio_title_alignment_marquee + + + 0 + 1 + 2 + 3 + + Default (Windows-1252) Universal (UTF-8) diff --git a/vlc-android/res/xml/preferences.xml b/vlc-android/res/xml/preferences.xml index 677cf7cca..3c0546ab3 100644 --- a/vlc-android/res/xml/preferences.xml +++ b/vlc-android/res/xml/preferences.xml @@ -57,21 +57,28 @@ android:key="enable_brightness_gesture" android:summary="@string/enable_brightness_gesture_summary" android:title="@string/enable_brightness_gesture" /> - + + diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java index a78483c24..15096601e 100644 --- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java +++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java @@ -34,10 +34,13 @@ import org.videolan.vlc.R; import org.videolan.vlc.VLCApplication; import org.videolan.vlc.util.AndroidDevices; import org.videolan.vlc.util.Strings; +import org.videolan.vlc.util.Util; import android.content.Context; +import android.content.SharedPreferences; import android.os.Build; import android.os.Environment; +import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -252,6 +255,8 @@ public class DirectoryAdapter extends BaseAdapter { private String mCurrentDir; private String mCurrentRoot; + private int mAlignMode; // align mode from prefs + public DirectoryAdapter(Context context) { DirectoryAdapter_Core(context, null); } @@ -265,6 +270,8 @@ public class DirectoryAdapter extends BaseAdapter { mCurrentDir = rootDir; this.populateNode(mRootNode, rootDir); mCurrentNode = mRootNode; + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activityContext); + mAlignMode = Integer.valueOf(preferences.getString("audio_title_alignment", "0")); } @Override @@ -305,6 +312,7 @@ public class DirectoryAdapter extends BaseAdapter { holder.layout = v.findViewById(R.id.layout_item); holder.title = (TextView) v.findViewById(R.id.title); holder.title.setSelected(true); + Util.setAlignModeByPref(mAlignMode, holder.title); holder.text = (TextView) v.findViewById(R.id.text); holder.icon = (ImageView) v.findViewById(R.id.dvi_icon); v.setTag(holder); diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java index c51d1ed53..4e1056ca6 100644 --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java @@ -29,9 +29,12 @@ import java.util.Map; import org.videolan.libvlc.Media; import org.videolan.vlc.R; import org.videolan.vlc.util.BitmapCache; +import org.videolan.vlc.util.Util; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Bitmap; +import android.preference.PreferenceManager; import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; @@ -54,6 +57,8 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex // A list of all the sections in the list; better performance than searching the whole list private SparseArray mSections; + private int mAlignMode; // align mode from prefs + private Context mContext; // The types of the item views: media and separator. @@ -93,6 +98,8 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex if (itemType != ITEM_WITHOUT_COVER && itemType != ITEM_WITH_COVER) throw new IllegalArgumentException(); mItemType = itemType; + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + mAlignMode = Integer.valueOf(preferences.getString("audio_title_alignment", "0")); } public void add(String title, String subTitle, Media media) { @@ -233,6 +240,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex holder = new ViewHolder(); holder.layout = v.findViewById(R.id.layout_item); holder.title = (TextView) v.findViewById(R.id.title); + Util.setAlignModeByPref(mAlignMode, holder.title); holder.cover = (ImageView) v.findViewById(R.id.cover); holder.subtitle = (TextView) v.findViewById(R.id.subtitle); holder.footer = v.findViewById(R.id.footer); diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java index 012d7c3e1..d85efaec7 100644 --- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java +++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlaylistAdapter.java @@ -29,7 +29,9 @@ import org.videolan.vlc.util.Util; import org.videolan.vlc.widget.AudioPlaylistItemViewGroup; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -47,12 +49,15 @@ public class AudioPlaylistAdapter extends ArrayAdapter { private ArrayList mMediaList; private int mCurrentIndex; private Context mContext; + private int mAlignMode; public AudioPlaylistAdapter(Context context) { super(context, 0); mContext = context; mMediaList = new ArrayList(); mCurrentIndex = -1; + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + mAlignMode = Integer.valueOf(preferences.getString("audio_title_alignment", "0")); } @Override @@ -86,6 +91,7 @@ public class AudioPlaylistAdapter extends ArrayAdapter { v = inflater.inflate(R.layout.audio_playlist_item, parent, false); holder = new ViewHolder(); holder.title = (TextView) v.findViewById(R.id.title); + Util.setAlignModeByPref(mAlignMode, holder.title); holder.artist = (TextView) v.findViewById(R.id.artist); holder.moveButton = (ImageButton) v.findViewById(R.id.move); holder.expansion = (LinearLayout)v.findViewById(R.id.item_expansion); diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java index 5d4b4d99e..a172ec3eb 100644 --- a/vlc-android/src/org/videolan/vlc/util/Util.java +++ b/vlc-android/src/org/videolan/vlc/util/Util.java @@ -29,8 +29,10 @@ import org.videolan.vlc.VLCApplication; import android.content.Context; import android.content.res.TypedArray; +import android.text.TextUtils.TruncateAt; import android.util.DisplayMetrics; import android.util.TypedValue; +import android.widget.TextView; import android.widget.Toast; public class Util { @@ -86,4 +88,25 @@ public class Util { a.recycle(); return resId; } + + /** + * Set the alignment mode of the specified TextView with the desired align + * mode from preferences. + * + * See @array/audio_title_alignment_values + * + * @param alignMode Align mode as read from preferences + * @param t Reference to the textview + */ + public static void setAlignModeByPref(int alignMode, TextView t) { + if(alignMode == 1) + t.setEllipsize(TruncateAt.END); + else if(alignMode == 2) + t.setEllipsize(TruncateAt.START); + else if(alignMode == 3) { + t.setEllipsize(TruncateAt.MARQUEE); + t.setMarqueeRepeatLimit(-1); + t.setSelected(true); + } + } } -- GitLab