[Android] Use custom binder for alignMode
Geoffrey Métais
git at videolan.org
Thu Apr 21 16:36:37 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Apr 21 16:21:10 2016 +0200| [a56504bc07cf15dfaf777a62b5a0a1a4c4504c8b] | committer: Geoffrey Métais
Use custom binder for alignMode
> https://code.videolan.org/videolan/vlc-android/commit/a56504bc07cf15dfaf777a62b5a0a1a4c4504c8b
---
vlc-android/res/layout/audio_browser_item.xml | 7 +++++-
.../vlc/gui/audio/AudioBrowserListAdapter.java | 2 +-
.../src/org/videolan/vlc/gui/helpers/UiTools.java | 26 ++++++++++++++--------
3 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index 4221111..67d88a5 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<layout xmlns:android="http://schemas.android.com/apk/res/android">
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:vlc="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<import type="android.text.TextUtils"/>
@@ -7,6 +8,9 @@
name="position"
type="int" />
<variable
+ name="alignMode"
+ type="int" />
+ <variable
name="item"
type="org.videolan.vlc.gui.audio.AudioBrowserListAdapter.ListItem"/>
<variable
@@ -63,6 +67,7 @@
android:layout_height="wrap_content"
android:singleLine="false"
android:ellipsize="end"
+ vlc:alignMode="@{alignMode}"
android:maxLines="2"
android:text="@{media.title ?? item.mTitle}"
android:fontFamily="sans-serif-light"
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 c94b809..68c934d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -353,12 +353,12 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
holder = new ViewHolder();
holder.binding = DataBindingUtil.inflate(inflater, R.layout.audio_browser_item, parent, false);
v = holder.binding.getRoot();
- UiTools.setAlignModeByPref(mAlignMode, (TextView) v.findViewById(R.id.title));
holder.viewType = VIEW_MEDIA;
v.setTag(holder);
}
ListItem item = getItem(position);
+ holder.binding.setVariable(BR.alignMode, mAlignMode);
holder.binding.setVariable(BR.item, item);
holder.binding.setVariable(BR.position, position);
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 76c64ab..6c59146 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -27,6 +27,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
+import android.databinding.BindingAdapter;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
@@ -136,15 +137,22 @@ public class UiTools {
* @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(TextUtils.TruncateAt.END);
- else if(alignMode == 2)
- t.setEllipsize(TextUtils.TruncateAt.START);
- else if(alignMode == 3) {
- t.setEllipsize(TextUtils.TruncateAt.MARQUEE);
- t.setMarqueeRepeatLimit(-1);
- t.setSelected(true);
+ @BindingAdapter({"bind:alignMode"})
+ public static void setAlignModeByPref(TextView t, int alignMode) {
+ switch (alignMode) {
+ case 0:
+ break;
+ case 1:
+ t.setEllipsize(TextUtils.TruncateAt.END);
+ break;
+ case 2:
+ t.setEllipsize(TextUtils.TruncateAt.START);
+ break;
+ case 3:
+ t.setEllipsize(TextUtils.TruncateAt.MARQUEE);
+ t.setMarqueeRepeatLimit(-1);
+ t.setSelected(true);
+ break;
}
}
More information about the Android
mailing list