[Android] Util: add a function to get a resource id from an attribute id

Adrien Maglo git at videolan.org
Mon Feb 24 12:18:36 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Feb 24 11:47:29 2014 +0100| [a0cd36e8f9b0648175fa0f63fc4a7d98241253dd] | committer: Adrien Maglo

Util: add a function to get a resource id from an attribute id

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

 vlc-android/src/org/videolan/vlc/Util.java               |   14 ++++++++++++++
 .../src/org/videolan/vlc/gui/expandable/JumpToTime.java  |    3 ++-
 .../org/videolan/vlc/gui/expandable/SpeedSelector.java   |    2 +-
 .../src/org/videolan/vlc/gui/expandable/TimeSleep.java   |    3 ++-
 .../src/org/videolan/vlc/widget/ExpandableLayout.java    |    7 -------
 5 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 5b2d544..02aee40 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -47,6 +47,7 @@ import org.videolan.libvlc.Media;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
+import android.content.res.TypedArray;
 import android.database.sqlite.SQLiteFullException;
 import android.graphics.Bitmap;
 import android.os.Environment;
@@ -541,4 +542,17 @@ public class Util {
     public static boolean nullEquals(String s1, String s2) {
         return (s1 == null ? s2 == null : s1.equals(s2));
     }
+
+    /**
+     * Get a resource id from an attribute id.
+     * @param context
+     * @param attrId
+     * @return the resource id
+     */
+    public static int getResourceFromAttribute(Context context, int attrId) {
+        TypedArray a = context.getTheme().obtainStyledAttributes(new int[] {attrId});
+        int resId = a.getResourceId(0, 0);
+        a.recycle();
+        return resId;
+    }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/expandable/JumpToTime.java b/vlc-android/src/org/videolan/vlc/gui/expandable/JumpToTime.java
index 223e556..d71a86b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/expandable/JumpToTime.java
+++ b/vlc-android/src/org/videolan/vlc/gui/expandable/JumpToTime.java
@@ -29,6 +29,7 @@ import kankan.wheel.widget.adapters.NumericWheelAdapter;
 import org.videolan.libvlc.LibVLC;
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.R;
+import org.videolan.vlc.Util;
 import org.videolan.vlc.widget.ExpandableLayout;
 
 import android.content.Context;
@@ -46,7 +47,7 @@ public class JumpToTime extends ExpandableLayout {
     public JumpToTime(Context context, AttributeSet attrs) {
         super(context, attrs);
         setTitle(R.string.jump_to_time);
-        setIconAttribute(R.attr.ic_jumpto_normal_style);
+        setIcon(Util.getResourceFromAttribute(context, R.attr.ic_jumpto_normal_style));
         setContent(context, R.layout.expandable_jump_to_time);
 
         mHourWheel = (WheelView) findViewById(R.id.hour);
diff --git a/vlc-android/src/org/videolan/vlc/gui/expandable/SpeedSelector.java b/vlc-android/src/org/videolan/vlc/gui/expandable/SpeedSelector.java
index 89d077c..f794d60 100644
--- a/vlc-android/src/org/videolan/vlc/gui/expandable/SpeedSelector.java
+++ b/vlc-android/src/org/videolan/vlc/gui/expandable/SpeedSelector.java
@@ -40,7 +40,7 @@ public class SpeedSelector extends ExpandableLayout {
     public SpeedSelector(Context context, AttributeSet attrs) {
         super(context, attrs);
         setTitle(R.string.playback_speed);
-        setIconAttribute(R.attr.ic_speed_normal_style);
+        setIcon(Util.getResourceFromAttribute(context, R.attr.ic_speed_normal_style));
         setContent(context, R.layout.expandable_speed_selector);
 
         mSeekbar = (SeekBar) findViewById(R.id.speed_seek_bar);
diff --git a/vlc-android/src/org/videolan/vlc/gui/expandable/TimeSleep.java b/vlc-android/src/org/videolan/vlc/gui/expandable/TimeSleep.java
index ca315a8..8d4de9a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/expandable/TimeSleep.java
+++ b/vlc-android/src/org/videolan/vlc/gui/expandable/TimeSleep.java
@@ -26,6 +26,7 @@ import kankan.wheel.widget.WheelView;
 import kankan.wheel.widget.adapters.NumericWheelAdapter;
 
 import org.videolan.vlc.R;
+import org.videolan.vlc.Util;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.widget.ExpandableLayout;
 
@@ -49,7 +50,7 @@ public class TimeSleep extends ExpandableLayout {
     public TimeSleep(Context context, AttributeSet attrs) {
         super(context, attrs);
         setTitle(R.string.sleep_title);
-        setIconAttribute(R.attr.ic_sleep_normal_style);
+        setIcon(Util.getResourceFromAttribute(context, R.attr.ic_sleep_normal_style));
         setContent(context, R.layout.expandable_time_sleep);
 
         mHourWheel = (WheelView) findViewById(R.id.hour);
diff --git a/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java b/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java
index a7fc338..c79b088 100644
--- a/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java
+++ b/vlc-android/src/org/videolan/vlc/widget/ExpandableLayout.java
@@ -88,13 +88,6 @@ public class ExpandableLayout extends LinearLayout {
         mIcon.setVisibility(View.VISIBLE);
     }
 
-    public void setIconAttribute(int attrid) {
-        TypedArray a = mContext.getTheme().obtainStyledAttributes(new int[] {attrid});
-        int resId = a.getResourceId(0, 0);
-        a.recycle();
-        setIcon(resId);
-    }
-
     public void setContent(Context context, int resid) {
         View view = LayoutInflater.from(context).inflate(resid, null, true);
         mContent.addView(view);



More information about the Android mailing list