Generate tinted control buttons on-the-fly

This commit is contained in:
Christopher Eby 2010-02-26 23:43:49 -06:00
parent dc0639784e
commit 9db1789e3d
18 changed files with 52 additions and 63 deletions

View File

@ -2,9 +2,9 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/next_normal" />
android:drawable="@drawable/next" />
<item
android:state_focused="true"
android:drawable="@drawable/next_normal" />
android:drawable="@drawable/next" />
<item android:drawable="@drawable/empty" />
</selector>

View File

@ -2,9 +2,9 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/pause_normal" />
android:drawable="@drawable/pause" />
<item
android:state_focused="true"
android:drawable="@drawable/pause_normal" />
android:drawable="@drawable/pause" />
<item android:drawable="@drawable/empty" />
</selector>

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/next_focused" />
<item
android:state_focused="true"
android:drawable="@drawable/next_focused" />
<item android:drawable="@drawable/next_normal" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1003 B

After

Width:  |  Height:  |  Size: 1003 B

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/pause_focused" />
<item
android:state_focused="true"
android:drawable="@drawable/pause_focused" />
<item android:drawable="@drawable/pause_normal" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/play_focused" />
<item
android:state_focused="true"
android:drawable="@drawable/play_focused" />
<item android:drawable="@drawable/play_normal" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 910 B

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/previous_focused" />
<item
android:state_focused="true"
android:drawable="@drawable/previous_focused" />
<item android:drawable="@drawable/previous_normal" />
</selector>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -1,25 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
<org.kreed.vanilla.ControlButton
android:id="@+id/previous"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="15px"
android:background="@null"
android:src="@drawable/previous" />
<ImageButton
<org.kreed.vanilla.ControlButton
android:id="@+id/play_pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25px"
android:background="@null"
android:src="@drawable/play" />
<ImageButton
<org.kreed.vanilla.ControlButton
android:id="@+id/next"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginLeft="25px"
android:layout_marginRight="15px"
android:background="@null"
android:src="@drawable/next" />
</merge>

View File

@ -0,0 +1,32 @@
package org.kreed.vanilla;
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.widget.ImageView;
public class ControlButton extends ImageView {
private static final int ACTIVE_TINT = Color.argb(100, 0, 255, 0);
private static final int INACTIVE_TINT = Color.TRANSPARENT;
private int mTint = Color.TRANSPARENT;
public ControlButton(Context context, AttributeSet attrs)
{
super(context, attrs);
setFocusable(true);
}
@Override
protected void drawableStateChanged()
{
super.drawableStateChanged();
int tint = isPressed() || isFocused() ? ACTIVE_TINT : INACTIVE_TINT;
if (tint != mTint) {
setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
mTint = tint;
}
}
}

View File

@ -40,7 +40,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
@ -55,9 +55,9 @@ public class NowPlayingActivity extends Activity implements ServiceConnection, V
private View mControlsTop;
private View mControlsBottom;
private ImageButton mPreviousButton;
private ImageButton mPlayPauseButton;
private ImageButton mNextButton;
private View mPreviousButton;
private ImageView mPlayPauseButton;
private View mNextButton;
private SeekBar mSeekBar;
private TextView mSeekText;
private Button mReconnectButton;
@ -81,20 +81,20 @@ public class NowPlayingActivity extends Activity implements ServiceConnection, V
mCoverView.setOnClickListener(this);
mLayout = (ViewGroup)mCoverView.getParent();
mControlsTop = findViewById(R.id.controls_top);
mControlsBottom = findViewById(R.id.controls_bottom);
mPreviousButton = (ImageButton)findViewById(R.id.previous);
mPreviousButton = findViewById(R.id.previous);
mPreviousButton.setOnClickListener(this);
mPreviousButton.setOnFocusChangeListener(this);
mPlayPauseButton = (ImageButton)findViewById(R.id.play_pause);
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
mPlayPauseButton.setOnClickListener(this);
mPlayPauseButton.setOnFocusChangeListener(this);
mNextButton = (ImageButton)findViewById(R.id.next);
mNextButton = findViewById(R.id.next);
mNextButton.setOnClickListener(this);
mNextButton.setOnFocusChangeListener(this);
mSeekText = (TextView)findViewById(R.id.seek_text);
mSeekBar = (SeekBar)findViewById(R.id.seek_bar);
mSeekBar.setMax(1000);

View File

@ -32,7 +32,7 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
public class RemoteActivity extends Activity implements ServiceConnection, View.OnClickListener {
private CoverView mCoverView;
@ -40,7 +40,7 @@ public class RemoteActivity extends Activity implements ServiceConnection, View.
private View mOpenButton;
private View mKillButton;
private View mPreviousButton;
private ImageButton mPlayPauseButton;
private ImageView mPlayPauseButton;
private View mNextButton;
@Override
@ -59,7 +59,7 @@ public class RemoteActivity extends Activity implements ServiceConnection, View.
mKillButton.setOnClickListener(this);
mPreviousButton = findViewById(R.id.previous);
mPreviousButton.setOnClickListener(this);
mPlayPauseButton = (ImageButton)findViewById(R.id.play_pause);
mPlayPauseButton = (ImageView)findViewById(R.id.play_pause);
mPlayPauseButton.setOnClickListener(this);
mNextButton = findViewById(R.id.next);
mNextButton.setOnClickListener(this);