mirror of https://github.com/tasks/tasks
Merge widgets together, bump version
* Allows for seamless upgrade to scrollable widgetpull/46/merge
parent
b6d82c2689
commit
9d609986eb
@ -1,46 +0,0 @@
|
|||||||
package org.tasks.widget;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.appwidget.AppWidgetProvider;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.service.ContextManager;
|
|
||||||
|
|
||||||
import org.tasks.R;
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
|
||||||
public class ScrollableTasksWidget extends AppWidgetProvider {
|
|
||||||
|
|
||||||
private final WidgetHelper widgetHelper = new WidgetHelper();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
|
||||||
ContextManager.setContext(context);
|
|
||||||
super.onUpdate(context, appWidgetManager, appWidgetIds);
|
|
||||||
|
|
||||||
ComponentName thisWidget = new ComponentName(context, ScrollableTasksWidget.class);
|
|
||||||
int[] ids = appWidgetManager.getAppWidgetIds(thisWidget);
|
|
||||||
for (int id : ids) {
|
|
||||||
appWidgetManager.updateAppWidget(id, widgetHelper.createScrollableWidget(context, id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateWidgets(Context context) {
|
|
||||||
updateWidgets(context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateWidget(Context context, int id) {
|
|
||||||
updateWidgets(context, new int[]{id});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateWidgets(Context context, int[] widgetIds) {
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
||||||
if (widgetIds == null) {
|
|
||||||
widgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, ScrollableTasksWidget.class));
|
|
||||||
}
|
|
||||||
appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.list_view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,157 +0,0 @@
|
|||||||
package org.tasks.widget;
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ListView;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
|
||||||
import com.todoroo.andlib.utility.Preferences;
|
|
||||||
import com.todoroo.astrid.adapter.FilterAdapter;
|
|
||||||
import com.todoroo.astrid.api.Filter;
|
|
||||||
import com.todoroo.astrid.api.FilterListItem;
|
|
||||||
import com.todoroo.astrid.api.FilterWithCustomIntent;
|
|
||||||
import com.todoroo.astrid.service.ThemeService;
|
|
||||||
|
|
||||||
import org.tasks.R;
|
|
||||||
|
|
||||||
public class ScrollableWidgetConfigActivity extends ListActivity {
|
|
||||||
|
|
||||||
static final String PREF_TITLE = "widget-title-";
|
|
||||||
static final String PREF_SQL = "widget-sql-";
|
|
||||||
static final String PREF_VALUES = "widget-values-";
|
|
||||||
static final String PREF_CUSTOM_INTENT = "widget-intent-";
|
|
||||||
static final String PREF_CUSTOM_EXTRAS = "widget-extras-";
|
|
||||||
static final String PREF_TAG_ID = "widget-tag-id-";
|
|
||||||
|
|
||||||
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
||||||
|
|
||||||
FilterAdapter adapter = null;
|
|
||||||
|
|
||||||
private final WidgetHelper widgetHelper = new WidgetHelper();
|
|
||||||
|
|
||||||
public void updateWidget() {
|
|
||||||
// setup view for new widget
|
|
||||||
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
|
|
||||||
appWidgetManager.updateAppWidget(mAppWidgetId, widgetHelper.createScrollableWidget(getApplicationContext(), mAppWidgetId));
|
|
||||||
ScrollableTasksWidget.updateWidget(this, mAppWidgetId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle icicle) {
|
|
||||||
ThemeService.applyTheme(this);
|
|
||||||
ThemeService.setForceFilterInvert(true);
|
|
||||||
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(this, getListView(),
|
|
||||||
R.layout.filter_adapter_row, true, true);
|
|
||||||
adapter.filterStyle = R.style.TextAppearance_FLA_Filter_Widget;
|
|
||||||
setListAdapter(adapter);
|
|
||||||
|
|
||||||
Button button = (Button)findViewById(R.id.ok);
|
|
||||||
button.setOnClickListener(mOnClickListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
View.OnClickListener mOnClickListener = new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// Save configuration options
|
|
||||||
saveConfiguration(adapter.getSelection());
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
adapter.registerRecevier();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
adapter.unregisterRecevier();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
ThemeService.setForceFilterInvert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveConfiguration(FilterListItem filterListItem){
|
|
||||||
DisplayMetrics metrics = new DisplayMetrics();
|
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
||||||
|
|
||||||
String sql = null, contentValuesString = null, title = null;
|
|
||||||
|
|
||||||
if(filterListItem != null && filterListItem instanceof Filter) {
|
|
||||||
sql = ((Filter)filterListItem).getSqlQuery();
|
|
||||||
ContentValues values = ((Filter)filterListItem).valuesForNewTasks;
|
|
||||||
if(values != null) {
|
|
||||||
contentValuesString = AndroidUtilities.contentValuesToSerializedString(values);
|
|
||||||
}
|
|
||||||
title = ((Filter)filterListItem).title;
|
|
||||||
}
|
|
||||||
|
|
||||||
Preferences.setString(ScrollableWidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
|
|
||||||
Preferences.setString(ScrollableWidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
|
|
||||||
Preferences.setString(ScrollableWidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString);
|
|
||||||
|
|
||||||
if(filterListItem instanceof FilterWithCustomIntent) {
|
|
||||||
String flattenedName = ((FilterWithCustomIntent)filterListItem).customTaskList.flattenToString();
|
|
||||||
Preferences.setString(ScrollableWidgetConfigActivity.PREF_CUSTOM_INTENT + mAppWidgetId,
|
|
||||||
flattenedName);
|
|
||||||
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent)filterListItem).customExtras);
|
|
||||||
if (flattenedExtras != null) {
|
|
||||||
Preferences.setString(ScrollableWidgetConfigActivity.PREF_CUSTOM_EXTRAS + mAppWidgetId,
|
|
||||||
flattenedExtras);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<bool name="is_pre_api_14">false</bool>
|
|
||||||
<bool name="is_post_api_14">true</bool>
|
|
||||||
</resources>
|
|
||||||
Loading…
Reference in New Issue