Commit a0cd36e8 authored by Adrien Maglo's avatar Adrien Maglo

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

parent 9dfb69bf
......@@ -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;
}
}
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment