Widgets use ButterKnife now and implement all View constructors. (#424)
The new widgets now implement all View constructors to make the code more robust to any future changes in how the widgets are used.
This commit is contained in:
parent
f947912a23
commit
4b6bb27d00
|
@ -16,7 +16,6 @@
|
||||||
package org.xbmc.kore.ui.widgets;
|
package org.xbmc.kore.ui.widgets;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.support.v7.widget.AppCompatImageButton;
|
import android.support.v7.widget.AppCompatImageButton;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
@ -28,14 +27,19 @@ public class HighlightButton extends AppCompatImageButton {
|
||||||
|
|
||||||
private boolean highlight;
|
private boolean highlight;
|
||||||
|
|
||||||
|
public HighlightButton(Context context) {
|
||||||
|
super(context);
|
||||||
|
setStyle(context);
|
||||||
|
}
|
||||||
|
|
||||||
public HighlightButton(Context context, AttributeSet attrs) {
|
public HighlightButton(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
Resources.Theme theme = context.getTheme();
|
setStyle(context);
|
||||||
TypedArray styledAttributes = theme.obtainStyledAttributes(new int[]{
|
}
|
||||||
R.attr.colorAccent});
|
|
||||||
colorFilter = styledAttributes.getColor(styledAttributes.getIndex(0),
|
public HighlightButton(Context context, AttributeSet attrs, int defStyle) {
|
||||||
context.getResources().getColor(R.color.accent_default));
|
super(context, attrs, defStyle);
|
||||||
styledAttributes.recycle();
|
setStyle(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighlight(boolean highlight) {
|
public void setHighlight(boolean highlight) {
|
||||||
|
@ -50,4 +54,12 @@ public class HighlightButton extends AppCompatImageButton {
|
||||||
public boolean isHighlighted() {
|
public boolean isHighlighted() {
|
||||||
return highlight;
|
return highlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStyle(Context context) {
|
||||||
|
TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(new int[]{
|
||||||
|
R.attr.colorAccent});
|
||||||
|
colorFilter = styledAttributes.getColor(styledAttributes.getIndex(0),
|
||||||
|
context.getResources().getColor(R.color.accent_default));
|
||||||
|
styledAttributes.recycle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,19 +22,23 @@ import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.xbmc.kore.R;
|
import org.xbmc.kore.R;
|
||||||
import org.xbmc.kore.utils.LogUtils;
|
|
||||||
import org.xbmc.kore.utils.UIUtils;
|
import org.xbmc.kore.utils.UIUtils;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.InjectView;
|
||||||
|
|
||||||
public class MediaProgressIndicator extends LinearLayout {
|
public class MediaProgressIndicator extends LinearLayout {
|
||||||
|
|
||||||
private SeekBar seekBar;
|
@InjectView(R.id.mpi_seek_bar) SeekBar seekBar;
|
||||||
private TextView durationTextView;
|
@InjectView(R.id.mpi_duration) TextView durationTextView;
|
||||||
private TextView progressTextView;
|
@InjectView(R.id.mpi_progress) TextView progressTextView;
|
||||||
|
|
||||||
private int speed = 0;
|
private int speed = 0;
|
||||||
private int maxProgress;
|
private int maxProgress;
|
||||||
private int progress;
|
private int progress;
|
||||||
|
@ -57,18 +61,15 @@ public class MediaProgressIndicator extends LinearLayout {
|
||||||
initializeView(context);
|
initializeView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeView(Context context) {
|
public MediaProgressIndicator(Context context, AttributeSet attributeSet, int defStyle) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
super(context, attributeSet, defStyle);
|
||||||
inflater.inflate(R.layout.media_progress_indicator, this);
|
initializeView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initializeView(Context context) {
|
||||||
protected void onFinishInflate() {
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
super.onFinishInflate();
|
View view = inflater.inflate(R.layout.media_progress_indicator, this);
|
||||||
|
ButterKnife.inject(view);
|
||||||
seekBar = (SeekBar) findViewById(R.id.mpi_seek_bar);
|
|
||||||
progressTextView = (TextView) findViewById(R.id.mpi_progress);
|
|
||||||
durationTextView = (TextView) findViewById(R.id.mpi_duration);
|
|
||||||
|
|
||||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -32,6 +32,9 @@ import org.xbmc.kore.R;
|
||||||
import org.xbmc.kore.jsonrpc.type.GlobalType;
|
import org.xbmc.kore.jsonrpc.type.GlobalType;
|
||||||
import org.xbmc.kore.utils.UIUtils;
|
import org.xbmc.kore.utils.UIUtils;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.InjectView;
|
||||||
|
|
||||||
public class NowPlayingPanel extends SlidingUpPanelLayout {
|
public class NowPlayingPanel extends SlidingUpPanelLayout {
|
||||||
|
|
||||||
public interface OnPanelButtonsClickListener {
|
public interface OnPanelButtonsClickListener {
|
||||||
|
@ -46,18 +49,18 @@ public class NowPlayingPanel extends SlidingUpPanelLayout {
|
||||||
|
|
||||||
private OnPanelButtonsClickListener onPanelButtonsClickListener;
|
private OnPanelButtonsClickListener onPanelButtonsClickListener;
|
||||||
|
|
||||||
private TextView title;
|
@InjectView(R.id.npp_title) TextView title;
|
||||||
private TextView details;
|
@InjectView(R.id.npp_details) TextView details;
|
||||||
private ImageView poster;
|
@InjectView(R.id.npp_poster) ImageView poster;
|
||||||
private ImageButton previousButton;
|
@InjectView(R.id.npp_previous) ImageButton previousButton;
|
||||||
private ImageButton nextButton;
|
@InjectView(R.id.npp_next) ImageButton nextButton;
|
||||||
private ImageButton playButton;
|
@InjectView(R.id.npp_play) ImageButton playButton;
|
||||||
private MediaProgressIndicator mediaProgressIndicator;
|
@InjectView(R.id.npp_progress_indicator) MediaProgressIndicator mediaProgressIndicator;
|
||||||
private VolumeLevelIndicator volumeLevelIndicator;
|
@InjectView(R.id.npp_volume_level_indicator) VolumeLevelIndicator volumeLevelIndicator;
|
||||||
private HighlightButton volumeMuteButton;
|
@InjectView(R.id.npp_volume_mute) HighlightButton volumeMuteButton;
|
||||||
private HighlightButton volumeMutedIndicatorButton;
|
@InjectView(R.id.npp_volume_muted_indicator) HighlightButton volumeMutedIndicatorButton;
|
||||||
private RepeatModeButton repeatModeButton;
|
@InjectView(R.id.npp_repeat) RepeatModeButton repeatModeButton;
|
||||||
private HighlightButton shuffleButton;
|
@InjectView(R.id.npp_shuffle) HighlightButton shuffleButton;
|
||||||
|
|
||||||
public NowPlayingPanel(Context context) {
|
public NowPlayingPanel(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -75,26 +78,8 @@ public class NowPlayingPanel extends SlidingUpPanelLayout {
|
||||||
|
|
||||||
private void initializeView(Context context) {
|
private void initializeView(Context context) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
inflater.inflate(R.layout.now_playing_panel, this);
|
View view = inflater.inflate(R.layout.now_playing_panel, this);
|
||||||
}
|
ButterKnife.inject(view);
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onFinishInflate() {
|
|
||||||
super.onFinishInflate();
|
|
||||||
|
|
||||||
title = (TextView) findViewById(R.id.npp_title);
|
|
||||||
details = (TextView) findViewById(R.id.npp_details);
|
|
||||||
poster = (ImageView) findViewById(R.id.npp_poster);
|
|
||||||
previousButton = (ImageButton) findViewById(R.id.npp_previous);
|
|
||||||
nextButton = (ImageButton) findViewById(R.id.npp_next);
|
|
||||||
playButton = (ImageButton) findViewById(R.id.npp_play);
|
|
||||||
mediaProgressIndicator = (MediaProgressIndicator) findViewById(R.id.npp_progress_indicator);
|
|
||||||
volumeLevelIndicator = (VolumeLevelIndicator) findViewById(R.id.npp_volume_level_indicator);
|
|
||||||
volumeMuteButton = (HighlightButton) findViewById(R.id.npp_volume_mute);
|
|
||||||
repeatModeButton = (RepeatModeButton) findViewById(R.id.npp_repeat);
|
|
||||||
shuffleButton = (HighlightButton) findViewById(R.id.npp_shuffle);
|
|
||||||
volumeMutedIndicatorButton = (HighlightButton) findViewById(R.id.npp_volume_muted_indicator);
|
|
||||||
|
|
||||||
setupButtonClickListeners();
|
setupButtonClickListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,13 +34,19 @@ public class RepeatModeButton extends AppCompatImageButton {
|
||||||
private static TypedArray styledAttributes;
|
private static TypedArray styledAttributes;
|
||||||
private static int accentDefaultColor;
|
private static int accentDefaultColor;
|
||||||
|
|
||||||
|
public RepeatModeButton(Context context) {
|
||||||
|
super(context);
|
||||||
|
setStyle(context);
|
||||||
|
}
|
||||||
|
|
||||||
public RepeatModeButton(Context context, AttributeSet attrs) {
|
public RepeatModeButton(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
styledAttributes = context.getTheme().obtainStyledAttributes(new int[]{
|
setStyle(context);
|
||||||
R.attr.colorAccent,
|
}
|
||||||
R.attr.iconRepeat,
|
|
||||||
R.attr.iconRepeatOne});
|
public RepeatModeButton(Context context, AttributeSet attributeSet, int defStyle) {
|
||||||
accentDefaultColor = getContext().getResources().getColor(R.color.accent_default);
|
super(context, attributeSet, defStyle);
|
||||||
|
setStyle(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMode(MODE mode) {
|
public void setMode(MODE mode) {
|
||||||
|
@ -65,4 +71,12 @@ public class RepeatModeButton extends AppCompatImageButton {
|
||||||
public MODE getMode() {
|
public MODE getMode() {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStyle(Context context) {
|
||||||
|
styledAttributes = context.getTheme().obtainStyledAttributes(new int[]{
|
||||||
|
R.attr.colorAccent,
|
||||||
|
R.attr.iconRepeat,
|
||||||
|
R.attr.iconRepeatOne});
|
||||||
|
accentDefaultColor = getContext().getResources().getColor(R.color.accent_default);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,19 @@ package org.xbmc.kore.ui.widgets;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.xbmc.kore.R;
|
import org.xbmc.kore.R;
|
||||||
|
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import butterknife.InjectView;
|
||||||
|
|
||||||
public class VolumeLevelIndicator extends LinearLayout {
|
public class VolumeLevelIndicator extends LinearLayout {
|
||||||
private SeekBar volumeSeekBar;
|
@InjectView(R.id.vli_seek_bar) SeekBar volumeSeekBar;
|
||||||
private TextView volumeTextView;
|
@InjectView(R.id.vli_volume_text) TextView volumeTextView;
|
||||||
|
|
||||||
private OnVolumeChangeListener onVolumeChangeListener;
|
private OnVolumeChangeListener onVolumeChangeListener;
|
||||||
|
|
||||||
|
@ -44,17 +48,15 @@ public class VolumeLevelIndicator extends LinearLayout {
|
||||||
initializeView(context);
|
initializeView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeView(Context context) {
|
public VolumeLevelIndicator(Context context, AttributeSet attributeSet, int defStyle) {
|
||||||
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
super(context, attributeSet, defStyle);
|
||||||
inflater.inflate(R.layout.volume_level_indicator, this);
|
initializeView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initializeView(Context context) {
|
||||||
protected void onFinishInflate() {
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
super.onFinishInflate();
|
View view = inflater.inflate(R.layout.volume_level_indicator, this);
|
||||||
|
ButterKnife.inject(view);
|
||||||
volumeSeekBar = (SeekBar) findViewById(R.id.vli_seek_bar);
|
|
||||||
volumeTextView = (TextView) findViewById(R.id.vli_volume_text);
|
|
||||||
|
|
||||||
volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue