Add option to hide checkboxes in widget

Closes #103
pull/253/head
Alex Baker 9 years ago
parent 2127fc2449
commit fe3d6ee1ea

@ -359,6 +359,10 @@ public class AndroidUtilities {
return !atLeastIceCreamSandwich();
}
public static boolean preHoneycomb() {
return !atLeastHoneycomb();
}
public static boolean atLeastFroyo() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
}

@ -30,6 +30,7 @@ import org.tasks.widget.WidgetHelper;
import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.preHoneycomb;
import static com.todoroo.andlib.utility.AndroidUtilities.preIceCreamSandwich;
public class WidgetConfigActivity extends InjectingListActivity {
@ -40,7 +41,8 @@ public class WidgetConfigActivity extends InjectingListActivity {
public static final String PREF_CUSTOM_INTENT = "widget-intent-";
public static final String PREF_CUSTOM_EXTRAS = "widget-extras-";
public static final String PREF_TAG_ID = "widget-tag-id-";
public static final String PREF_DUE_DATE = "widget-due-date-";
public static final String PREF_SHOW_DUE_DATE = "widget-show-due-date-";
public static final String PREF_HIDE_CHECKBOXES = "widget-hide-checkboxes-";
public static final String PREF_DARK_THEME = "widget-dark-theme-";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
@ -65,78 +67,84 @@ public class WidgetConfigActivity extends InjectingListActivity {
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
// Set the view layout resource to use.
setContentView(R.layout.widget_config_activity);
setTitle(R.string.WCA_title);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
// set up ui
adapter = new FilterAdapter(filterProvider, filterCounter, this, getListView(),
R.layout.filter_adapter_row, true);
adapter.filterStyle = R.style.TextAppearance_FLA_Filter_Widget;
setListAdapter(adapter);
Button button = (Button)findViewById(R.id.ok);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Save configuration options
CheckBox showDueDate = (CheckBox) findViewById(R.id.showDueDate);
CheckBox darkTheme = (CheckBox) findViewById(R.id.darkTheme);
saveConfiguration(adapter.getSelection(), showDueDate.isChecked(), darkTheme.isChecked());
updateWidget();
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
});
}
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set the result to CANCELED. This will cause the widget host to cancel
// out of the widget placement if they press the back button.
setResult(RESULT_CANCELED);
// Set the view layout resource to use.
setContentView(R.layout.widget_config_activity);
if (preHoneycomb()) {
findViewById(R.id.hideCheckboxes).setVisibility(View.GONE);
}
setTitle(R.string.WCA_title);
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
}
// If they gave us an intent without the widget id, just bail.
if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
finish();
}
// set up ui
adapter = new FilterAdapter(filterProvider, filterCounter, this, getListView(),
R.layout.filter_adapter_row, true);
adapter.filterStyle = R.style.TextAppearance_FLA_Filter_Widget;
setListAdapter(adapter);
Button button = (Button) findViewById(R.id.ok);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Save configuration options
CheckBox hideDueDate = (CheckBox) findViewById(R.id.hideDueDate);
CheckBox darkTheme = (CheckBox) findViewById(R.id.darkTheme);
CheckBox hideCheckboxes = (CheckBox) findViewById(R.id.hideCheckboxes);
saveConfiguration(adapter.getSelection(), !hideDueDate.isChecked(),
darkTheme.isChecked(), hideCheckboxes.isChecked());
updateWidget();
// Make sure we pass back the original appWidgetId
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
}
});
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Filter item = adapter.getItem(position);
adapter.setSelection(item);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Filter item = adapter.getItem(position);
adapter.setSelection(item);
}
@Override
protected void onResume() {
super.onResume();
adapter.registerRecevier();
}
protected void onResume() {
super.onResume();
adapter.registerRecevier();
}
@Override
protected void onPause() {
super.onPause();
adapter.unregisterRecevier();
}
protected void onPause() {
super.onPause();
adapter.unregisterRecevier();
}
private void saveConfiguration(FilterListItem filterListItem, boolean showDueDate, boolean darkTheme){
private void saveConfiguration(FilterListItem filterListItem, boolean showDueDate, boolean darkTheme, boolean hideCheckboxes){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
@ -156,8 +164,9 @@ public class WidgetConfigActivity extends InjectingListActivity {
preferences.setString(WidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
preferences.setString(WidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
preferences.setString(WidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString);
preferences.setBoolean(WidgetConfigActivity.PREF_DUE_DATE + mAppWidgetId, showDueDate);
preferences.setBoolean(WidgetConfigActivity.PREF_SHOW_DUE_DATE + mAppWidgetId, showDueDate);
preferences.setBoolean(WidgetConfigActivity.PREF_DARK_THEME + mAppWidgetId, darkTheme);
preferences.setBoolean(WidgetConfigActivity.PREF_HIDE_CHECKBOXES + mAppWidgetId, hideCheckboxes);
if(filterListItem instanceof FilterWithCustomIntent) {
String flattenedName = ((FilterWithCustomIntent)filterListItem).customTaskList.flattenToString();

@ -120,7 +120,7 @@ public class WidgetUpdateService extends InjectingService {
filter.getSqlQuery(), flags, sort).replaceAll("LIMIT \\d+", "") + " LIMIT " + numberOfTasks;
String tagName = preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
boolean showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_DUE_DATE + widgetId, false);
boolean showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_SHOW_DUE_DATE + widgetId, false);
query = subtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, numberOfTasks);
database.openForReading();

@ -8,6 +8,7 @@ import android.content.res.Resources;
import android.graphics.Paint;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;
@ -46,6 +47,7 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
private final int widgetId;
private final boolean dark;
private final boolean showDueDates;
private final boolean hideCheckboxes;
private final DueDateFormatter dueDateFormatter;
private TodorooCursor<Task> cursor;
@ -68,7 +70,8 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
dueDateFormatter = new DueDateFormatter(context);
dark = preferences.getBoolean(WidgetConfigActivity.PREF_DARK_THEME + widgetId, false);
showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_DUE_DATE + widgetId, false);
showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_SHOW_DUE_DATE + widgetId, false);
hideCheckboxes = preferences.getBoolean(WidgetConfigActivity.PREF_HIDE_CHECKBOXES + widgetId, false);
}
@Override
@ -168,10 +171,14 @@ public class ScrollableViewsFactory implements RemoteViewsService.RemoteViewsFac
editIntent.putExtra(TaskListActivity.OPEN_TASK, task.getId());
row.setOnClickFillInIntent(R.id.text, editIntent);
Intent completeIntent = new Intent();
completeIntent.setAction(TasksWidget.COMPLETE_TASK);
completeIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
row.setOnClickFillInIntent(R.id.completeBox, completeIntent);
if (hideCheckboxes) {
row.setViewVisibility(R.id.completeBox, View.GONE);
} else {
Intent completeIntent = new Intent();
completeIntent.setAction(TasksWidget.COMPLETE_TASK);
completeIntent.putExtra(TaskEditFragment.TOKEN_ID, task.getId());
row.setOnClickFillInIntent(R.id.completeBox, completeIntent);
}
return row;
} catch (Exception e) {

@ -10,9 +10,19 @@
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="true"
android:id="@+id/showDueDate"
android:text="@string/widget_show_due_date"
android:checked="false"
android:id="@+id/hideDueDate"
android:text="@string/widget_hide_due_date"
android:textSize="18sp"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="false"
android:id="@+id/hideCheckboxes"
android:text="@string/widget_hide_checkboxes"
android:textSize="18sp"
android:paddingTop="10dp"
android:paddingBottom="10dp" />

@ -113,7 +113,8 @@
<!-- Sync error: network connectivity problems. %s-> name of sync service-->
<string name="sync_error_offline">There was a problem connecting to the network
during the last sync with %s. Please try again later.</string>
<string name="widget_show_due_date">Show due date</string>
<string name="widget_hide_due_date">Hide due dates</string>
<string name="widget_hide_checkboxes">Hide checkboxes</string>
<string-array name="sync_SPr_interval_entries">
<!-- sync_SPr_interval_entries: Synchronization Intervals -->

Loading…
Cancel
Save