add a color picker to the widget dialog
This commit is contained in:
parent
3f98ab868d
commit
8b19ce3bdf
4 changed files with 55 additions and 7 deletions
|
@ -24,4 +24,5 @@ dependencies {
|
|||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.jakewharton:butterknife:7.0.1'
|
||||
compile 'com.squareup:otto:1.3.8'
|
||||
compile 'com.github.yukuku:ambilwarna:2.0.1'
|
||||
}
|
||||
|
|
|
@ -14,12 +14,16 @@ import android.widget.SeekBar;
|
|||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import yuku.ambilwarna.AmbilWarnaDialog;
|
||||
|
||||
public class MyWidgetConfigure extends Activity implements SeekBar.OnSeekBarChangeListener {
|
||||
@Bind(R.id.config_seekbar) SeekBar seekBar;
|
||||
@Bind(R.id.config_player) View background;
|
||||
@Bind(R.id.config_background_color) View backgroundColorPicker;
|
||||
private int widgetId;
|
||||
private int newBgColor;
|
||||
private int colorWithoutTransparency;
|
||||
private float alpha;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -27,8 +31,14 @@ public class MyWidgetConfigure extends Activity implements SeekBar.OnSeekBarChan
|
|||
setContentView(R.layout.widget_config);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
alpha = 0.5f;
|
||||
seekBar.setOnSeekBarChangeListener(this);
|
||||
seekBar.setProgress(50);
|
||||
seekBar.setProgress((int) (alpha * 100));
|
||||
newBgColor = Color.BLACK;
|
||||
newBgColor = adjustAlpha(newBgColor, alpha);
|
||||
colorWithoutTransparency = Color.BLACK;
|
||||
background.setBackgroundColor(newBgColor);
|
||||
backgroundColorPicker.setBackgroundColor(Color.BLACK);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final Bundle extras = intent.getExtras();
|
||||
|
@ -57,6 +67,24 @@ public class MyWidgetConfigure extends Activity implements SeekBar.OnSeekBarChan
|
|||
finish();
|
||||
}
|
||||
|
||||
@OnClick(R.id.config_background_color)
|
||||
public void pickBackgroundColor() {
|
||||
AmbilWarnaDialog dialog = new AmbilWarnaDialog(this, colorWithoutTransparency, new AmbilWarnaDialog.OnAmbilWarnaListener() {
|
||||
@Override
|
||||
public void onCancel(AmbilWarnaDialog dialog) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOk(AmbilWarnaDialog dialog, int color) {
|
||||
backgroundColorPicker.setBackgroundColor(color);
|
||||
colorWithoutTransparency = color;
|
||||
updateBackgroundColor();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void storeWidgetBackground() {
|
||||
final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE);
|
||||
prefs.edit().putInt(Constants.WIDGET_BG_COLOR, newBgColor).apply();
|
||||
|
@ -70,12 +98,23 @@ public class MyWidgetConfigure extends Activity implements SeekBar.OnSeekBarChan
|
|||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
final float percent = (float) progress / (float) 100;
|
||||
final int alpha = (int) (255 * percent);
|
||||
newBgColor = Color.argb(alpha, 0, 0, 0);
|
||||
alpha = (float) progress / (float) 100;
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
||||
private void updateBackgroundColor() {
|
||||
newBgColor = adjustAlpha(colorWithoutTransparency, alpha);
|
||||
background.setBackgroundColor(newBgColor);
|
||||
}
|
||||
|
||||
private int adjustAlpha(int color, float factor) {
|
||||
int alpha = Math.round(Color.alpha(color) * factor);
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
return Color.argb(alpha, red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ public class MyWidgetProvider extends AppWidgetProvider {
|
|||
|
||||
remoteViews = getRemoteViews(widgetManager, context, widgetIds[0]);
|
||||
remoteViews.setInt(R.id.widget_holder, "setBackgroundColor", newBgColor);
|
||||
updateSongInfo();
|
||||
|
||||
if (bus == null) {
|
||||
bus = BusProvider.getInstance();
|
||||
|
|
|
@ -23,6 +23,13 @@
|
|||
android:layout_alignParentBottom="true"
|
||||
android:background="@android:color/white">
|
||||
|
||||
<Button
|
||||
android:id="@+id/config_background_color"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignBottom="@+id/config_save"
|
||||
android:layout_alignTop="@+id/config_save"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/config_save"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -39,10 +46,10 @@
|
|||
android:id="@+id/config_seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="@dimen/activity_margin"
|
||||
android:layout_marginRight="@dimen/activity_margin"
|
||||
android:layout_toLeftOf="@id/config_save"/>
|
||||
android:layout_toLeftOf="@id/config_save"
|
||||
android:layout_toRightOf="@id/config_background_color"/>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue