mirror of https://github.com/tasks/tasks
Use radio buttons for importance control set
parent
0b6499563c
commit
e0f17708b0
@ -1,152 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.helper.TaskEditControlSetBase;
|
||||
|
||||
import org.tasks.R;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.tasks.preferences.ResourceResolver.getResource;
|
||||
|
||||
/**
|
||||
* Control Set for setting task importance
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*
|
||||
*/
|
||||
public class ImportanceControlSet extends TaskEditControlSetBase {
|
||||
private final List<CompoundButton> buttons = new LinkedList<>();
|
||||
private final int[] colors;
|
||||
private final List<ImportanceChangedListener> listeners = new LinkedList<>();
|
||||
|
||||
private static final int TEXT_SIZE = 18;
|
||||
|
||||
public interface ImportanceChangedListener {
|
||||
void importanceChanged(int i);
|
||||
}
|
||||
|
||||
public ImportanceControlSet(Activity activity) {
|
||||
super(activity, R.layout.control_set_importance);
|
||||
colors = Task.getImportanceColors(activity.getResources());
|
||||
}
|
||||
|
||||
public void setImportance(Integer i) {
|
||||
for(CompoundButton b : buttons) {
|
||||
if(b.getTag() == i) {
|
||||
b.setChecked(true);
|
||||
b.setBackgroundResource(getResource(activity, R.attr.importance_background_selected));
|
||||
} else {
|
||||
b.setChecked(false);
|
||||
b.setBackgroundResource(0);
|
||||
}
|
||||
}
|
||||
|
||||
for (ImportanceChangedListener l : listeners) {
|
||||
l.importanceChanged(i);
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getImportance() {
|
||||
for(CompoundButton b : buttons) {
|
||||
if (b.isChecked()) {
|
||||
return (Integer) b.getTag();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addListener(ImportanceChangedListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterInflate() {
|
||||
LinearLayout container = (LinearLayout) getView().findViewById(R.id.importance_container);
|
||||
|
||||
int min = Task.IMPORTANCE_MOST;
|
||||
int max = Task.IMPORTANCE_LEAST;
|
||||
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
|
||||
for(int i = max; i >= min; i--) {
|
||||
final ToggleButton button = new ToggleButton(activity);
|
||||
LinearLayout.LayoutParams params;
|
||||
|
||||
int dimension = 25;
|
||||
params = new LinearLayout.LayoutParams((int) (metrics.density * dimension), (int) (metrics.density * dimension));
|
||||
button.setLayoutParams(params);
|
||||
|
||||
StringBuilder label = new StringBuilder();
|
||||
if (i == max) {
|
||||
label.append('\u25CB');
|
||||
}
|
||||
for(int j = Task.IMPORTANCE_LEAST - 1; j >= i; j--) {
|
||||
label.append('!');
|
||||
}
|
||||
|
||||
button.setTextColor(colors[i]);
|
||||
button.setTextOff(label);
|
||||
button.setTextOn(label);
|
||||
button.setPadding(0, 1, 0, 0);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setImportance((Integer)button.getTag());
|
||||
}
|
||||
});
|
||||
button.setTag(i);
|
||||
button.setTextSize(TEXT_SIZE);
|
||||
|
||||
buttons.add(button);
|
||||
|
||||
View padding = new View(activity);
|
||||
LinearLayout.LayoutParams paddingParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 0);
|
||||
paddingParams.weight = 1.0f;
|
||||
padding.setLayoutParams(paddingParams);
|
||||
container.addView(padding);
|
||||
container.addView(button);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromTask(Task task) {
|
||||
super.readFromTask(task);
|
||||
setImportance(model.getImportance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIcon() {
|
||||
return R.drawable.ic_flag_24dp;
|
||||
}
|
||||
|
||||
// Same as above because we need the setImportance listeners to fire even in
|
||||
// the case when the UI hasn't been created yet
|
||||
@Override
|
||||
protected void readFromTaskOnInitialize() {
|
||||
setImportance(model.getImportance());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToModelAfterInitialized(Task task) {
|
||||
if(getImportance() != null) {
|
||||
task.setImportance(getImportance());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,100 @@
|
||||
package org.tasks.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.support.v7.widget.AppCompatRadioButton;
|
||||
import android.view.View;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.helper.TaskEditControlSetBase;
|
||||
|
||||
import org.tasks.R;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class PriorityControlSet extends TaskEditControlSetBase {
|
||||
|
||||
private final List<Integer> colors;
|
||||
private final List<ImportanceChangedListener> listeners = new LinkedList<>();
|
||||
private RadioGroup radioGroup;
|
||||
|
||||
public interface ImportanceChangedListener {
|
||||
void importanceChanged(int i);
|
||||
}
|
||||
|
||||
public PriorityControlSet(Activity activity) {
|
||||
super(activity, R.layout.control_set_priority);
|
||||
colors = Ints.asList(Task.getImportanceColors(activity.getResources()));
|
||||
Collections.reverse(colors);
|
||||
}
|
||||
|
||||
public void notifyImportanceChange(Integer i) {
|
||||
for (ImportanceChangedListener l : listeners) {
|
||||
l.importanceChanged(i);
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getImportance(int checkedId) {
|
||||
return getImportance(getView().findViewById(checkedId));
|
||||
}
|
||||
|
||||
private Integer getImportance(View view) {
|
||||
return Integer.parseInt((String) view.getTag());
|
||||
}
|
||||
|
||||
public void addListener(ImportanceChangedListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterInflate() {
|
||||
final View view = getView();
|
||||
radioGroup = (RadioGroup) view.findViewById(R.id.importance_group);
|
||||
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||
notifyImportanceChange(getImportance(checkedId));
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < radioGroup.getChildCount(); i++) {
|
||||
AppCompatRadioButton radioButton = (AppCompatRadioButton) radioGroup.getChildAt(i);
|
||||
radioButton.setSupportButtonTintList(new ColorStateList(new int[][]{
|
||||
new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked}},
|
||||
new int[]{colors.get(i), colors.get(i)}));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromTask(Task task) {
|
||||
super.readFromTask(task);
|
||||
setSelected(model.getImportance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIcon() {
|
||||
return R.drawable.ic_flag_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromTaskOnInitialize() {
|
||||
setSelected(model.getImportance());
|
||||
}
|
||||
|
||||
private void setSelected(int importance) {
|
||||
for (int i = 0; i < radioGroup.getChildCount(); i++) {
|
||||
AppCompatRadioButton radioButton = (AppCompatRadioButton) radioGroup.getChildAt(i);
|
||||
if (importance == getImportance(radioButton)) {
|
||||
radioButton.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToModelAfterInitialized(Task task) {
|
||||
task.setImportance(getImportance(radioGroup.getCheckedRadioButtonId()));
|
||||
}
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid
|
||||
android:color="#eee"/>
|
||||
<corners
|
||||
android:radius="4dp" />
|
||||
<size android:width="40dip"
|
||||
android:height="40dip"/>
|
||||
</shape>
|
||||
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/importance_container"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingRight="@dimen/task_edit_drawable_padding_left_right"
|
||||
android:paddingEnd="@dimen/task_edit_drawable_padding_left_right">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/display_row_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:text="@string/TEA_importance_label"
|
||||
android:textColor="?attr/asTextColor"
|
||||
android:textSize="@dimen/task_edit_text_size" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,50 @@
|
||||
<?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="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/display_row_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingEnd="@dimen/task_edit_drawable_padding_left_right"
|
||||
android:paddingRight="@dimen/task_edit_drawable_padding_left_right"
|
||||
android:text="@string/TEA_importance_label"
|
||||
android:textColor="?attr/asTextColor"
|
||||
android:textSize="@dimen/task_edit_text_size" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/importance_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end"
|
||||
android:gravity="end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="@dimen/task_edit_drawable_padding_left_right"
|
||||
android:paddingStart="@dimen/task_edit_drawable_padding_left_right">
|
||||
|
||||
<android.support.v7.widget.AppCompatRadioButton
|
||||
android:id="@+id/importance_3"
|
||||
style="@style/priority_button"
|
||||
android:tag="3" />
|
||||
|
||||
<android.support.v7.widget.AppCompatRadioButton
|
||||
android:id="@+id/importance_2"
|
||||
style="@style/priority_button"
|
||||
android:tag="2" />
|
||||
|
||||
<android.support.v7.widget.AppCompatRadioButton
|
||||
android:id="@+id/importance_1"
|
||||
style="@style/priority_button"
|
||||
android:tag="1" />
|
||||
|
||||
<android.support.v7.widget.AppCompatRadioButton
|
||||
android:id="@+id/importance_0"
|
||||
style="@style/priority_button"
|
||||
android:tag="0" />
|
||||
</RadioGroup>
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue