Choose shortcut widget icon color

pull/513/head
Alex Baker 8 years ago
parent aae448be0c
commit fbd19e5769

@ -144,7 +144,7 @@
<activity
android:label="@string/FSA_label"
android:name=".widget.ShortcutConfigActivity"
android:theme="@style/TranslucentDialog">
android:theme="@style/Tasks">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>

@ -19,6 +19,32 @@ import org.tasks.ui.MenuColorizer;
public class ThemeColor implements ColorPickerDialog.Pickable {
public static final int DEFAULT = 7;
public static final int[] ICONS =
new int[] {
R.mipmap.ic_launcher_blue_grey,
R.mipmap.ic_launcher_dark_grey,
R.mipmap.ic_launcher_red,
R.mipmap.ic_launcher_pink,
R.mipmap.ic_launcher_purple,
R.mipmap.ic_launcher_deep_purple,
R.mipmap.ic_launcher_indigo,
R.mipmap.ic_launcher_blue,
R.mipmap.ic_launcher_light_blue,
R.mipmap.ic_launcher_cyan,
R.mipmap.ic_launcher_teal,
R.mipmap.ic_launcher_green,
R.mipmap.ic_launcher_light_green,
R.mipmap.ic_launcher_lime,
R.mipmap.ic_launcher_yellow,
R.mipmap.ic_launcher_amber,
R.mipmap.ic_launcher_orange,
R.mipmap.ic_launcher_deep_orange,
R.mipmap.ic_launcher_brown,
R.mipmap.ic_launcher_grey
};
public static final String[] LAUNCHERS =
new String[] {
".BlueGrey",

@ -10,10 +10,19 @@ import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnFocusChange;
import com.google.common.base.Strings;
import com.todoroo.astrid.api.Filter;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.ColorPickerActivity;
import org.tasks.activities.FilterSelectionActivity;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
@ -21,44 +30,155 @@ import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.intents.TaskIntents;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.MenuColorizer;
public class ShortcutConfigActivity extends InjectingAppCompatActivity {
private static final int REQUEST_FILTER = 1019;
private static final int REQUEST_COLOR_PICKER = 1020;
@Inject DefaultFilterProvider defaultFilterProvider;
@Inject Tracker tracker;
@Inject ThemeColor themeColor;
@Inject ThemeCache themeCache;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.shortcut_list_layout)
TextInputLayout shortcutListLayout;
@BindView(R.id.shortcut_list)
TextInputEditText shortcutList;
@BindView(R.id.shortcut_name)
TextInputEditText shortcutName;
@BindView(R.id.shortcut_color)
TextInputEditText shortcutColor;
private Filter selectedFilter;
private int selectedTheme = -1;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = new Intent(this, FilterSelectionActivity.class);
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
startActivityForResult(intent, REQUEST_FILTER);
setContentView(R.layout.activity_widget_shortcut_layout);
ButterKnife.bind(this);
toolbar.setTitle(R.string.FSA_label);
toolbar.setNavigationIcon(ContextCompat.getDrawable(this, R.drawable.ic_save_24dp));
toolbar.setNavigationOnClickListener(v -> save());
MenuColorizer.colorToolbar(this, toolbar);
selectedFilter = defaultFilterProvider.getDefaultFilter();
updateFilterAndTheme();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_FILTER) {
if (resultCode == Activity.RESULT_OK) {
if (selectedFilter != null && selectedFilter.listingTitle.equals(getShortcutName())) {
shortcutName.setText(null);
}
selectedFilter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
updateFilterAndTheme();
}
} else if (requestCode == REQUEST_COLOR_PICKER) {
if (resultCode == RESULT_OK) {
selectedTheme = data.getIntExtra(ColorPickerActivity.EXTRA_THEME_INDEX, 0);
updateTheme();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@OnFocusChange(R.id.shortcut_list)
void onListFocusChange(boolean focused) {
if (focused) {
shortcutList.clearFocus();
showListPicker();
}
}
@OnClick(R.id.shortcut_list)
void showListPicker() {
Intent intent = new Intent(this, FilterSelectionActivity.class);
intent.putExtra(FilterSelectionActivity.EXTRA_FILTER, selectedFilter);
intent.putExtra(FilterSelectionActivity.EXTRA_RETURN_FILTER, true);
startActivityForResult(intent, REQUEST_FILTER);
}
@OnFocusChange(R.id.shortcut_color)
void onColorFocusChange(boolean focused) {
if (focused) {
shortcutColor.clearFocus();
showThemePicker();
}
}
@OnClick(R.id.shortcut_color)
void showThemePicker() {
Intent intent = new Intent(this, ColorPickerActivity.class);
intent.putExtra(ColorPickerActivity.EXTRA_PALETTE, ColorPickerActivity.ColorPalette.COLORS);
intent.putExtra(ColorPickerActivity.EXTRA_SHOW_NONE, false);
intent.putExtra(ColorPickerActivity.EXTRA_THEME_INDEX, selectedTheme);
startActivityForResult(intent, REQUEST_COLOR_PICKER);
}
private void updateFilterAndTheme() {
if (Strings.isNullOrEmpty(getShortcutName()) && selectedFilter != null) {
shortcutName.setText(selectedFilter.listingTitle);
}
if (selectedFilter != null) {
shortcutList.setText(selectedFilter.listingTitle);
}
updateTheme();
}
private void updateTheme() {
ThemeColor color = themeCache.getThemeColor(getThemeIndex());
shortcutColor.setText(color.getName());
color.apply(toolbar);
color.applyToStatusBar(this);
}
private int getThemeIndex() {
if (selectedTheme >= 0) {
return selectedTheme;
}
return selectedFilter == null || selectedFilter.tint == -1
? themeColor.getIndex()
: selectedFilter.tint;
}
private String getShortcutName() {
return shortcutName.getText().toString().trim();
}
private void save() {
tracker.reportEvent(Tracking.Events.WIDGET_ADD, getString(R.string.FSA_label));
Filter filter = data.getParcelableExtra(FilterSelectionActivity.EXTRA_FILTER);
String filterId = defaultFilterProvider.getFilterPreferenceValue(filter);
String filterId = defaultFilterProvider.getFilterPreferenceValue(selectedFilter);
Intent shortcutIntent = TaskIntents.getTaskListByIdIntent(this, filterId);
Intent intent = new Intent();
Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, filter.listingTitle);
Drawable launcher = ContextCompat.getDrawable(this, R.mipmap.ic_launcher_blue);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getShortcutName());
Drawable launcher = ContextCompat.getDrawable(this, ThemeColor.ICONS[getThemeIndex()]);
if (launcher instanceof BitmapDrawable) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, ((BitmapDrawable) launcher).getBitmap());
} else if (atLeastOreo() && launcher instanceof AdaptiveIconDrawable) {
Bitmap bitmap =
Bitmap.createBitmap(
launcher.getIntrinsicWidth(),
launcher.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
launcher.getIntrinsicWidth(), launcher.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
launcher.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
launcher.draw(canvas);
@ -66,14 +186,8 @@ public class ShortcutConfigActivity extends InjectingAppCompatActivity {
} else {
throw new IllegalStateException("Launcher icon not found");
}
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
setResult(RESULT_OK, intent);
}
finish();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TextInputLayout
android:id="@+id/shortcut_list_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText
android:id="@+id/shortcut_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/list"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/shortcut_name_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/shortcut_list_layout"
app:layout_constraintTop_toBottomOf="@+id/shortcut_list_layout">
<android.support.design.widget.TextInputEditText
android:id="@+id/shortcut_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/shortcut_color_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginStart="@dimen/keyline_first"
android:layout_marginEnd="@dimen/keyline_first"
android:layout_marginLeft="@dimen/keyline_first"
android:layout_marginRight="@dimen/keyline_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/shortcut_name_layout"
app:layout_constraintTop_toBottomOf="@+id/shortcut_name_layout">
<android.support.design.widget.TextInputEditText
android:id="@+id/shortcut_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/color"/>
</android.support.design.widget.TextInputLayout>
</android.support.constraint.ConstraintLayout>

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:background="@color/content_background">
<include layout="@layout/toolbar"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/activity_widget_shortcut_content"/>
</ScrollView>
</LinearLayout>
Loading…
Cancel
Save