AST-255 - when you create a widget, you get to select a filter. Awesome.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 10 KiB |
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- See the file "LICENSE" for the full license governing this code. -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@drawable/background_gradient">
|
||||||
|
|
||||||
|
<!-- List -->
|
||||||
|
<ExpandableListView android:id="@android:id/list"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight="100"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:cacheColorHint="#00000000"/>
|
||||||
|
|
||||||
|
<!-- List -->
|
||||||
|
<Button android:id="@+id/ok"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@android:string/ok"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
@ -0,0 +1,133 @@
|
|||||||
|
package com.todoroo.astrid.widget;
|
||||||
|
|
||||||
|
import android.app.ExpandableListActivity;
|
||||||
|
import android.appwidget.AppWidgetManager;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ExpandableListView;
|
||||||
|
|
||||||
|
import com.timsu.astrid.R;
|
||||||
|
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||||
|
import com.todoroo.astrid.adapter.FilterAdapter;
|
||||||
|
import com.todoroo.astrid.api.Filter;
|
||||||
|
import com.todoroo.astrid.api.FilterCategory;
|
||||||
|
import com.todoroo.astrid.api.FilterListItem;
|
||||||
|
import com.todoroo.astrid.utility.Preferences;
|
||||||
|
|
||||||
|
public class WidgetConfigActivity extends ExpandableListActivity {
|
||||||
|
|
||||||
|
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||||
|
|
||||||
|
FilterAdapter adapter = null;
|
||||||
|
|
||||||
|
@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(this, getExpandableListView(),
|
||||||
|
R.layout.filter_adapter_row, false);
|
||||||
|
setListAdapter(adapter);
|
||||||
|
|
||||||
|
Button button = (Button)findViewById(R.id.ok);
|
||||||
|
button.setOnClickListener(mOnClickListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
View.OnClickListener mOnClickListener = new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
// Save configuration options
|
||||||
|
saveConfiguration(adapter.getSelection());
|
||||||
|
|
||||||
|
// Push widget update to surface with newly set prefix
|
||||||
|
TasksWidget.updateWidget(WidgetConfigActivity.this, mAppWidgetId);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
public boolean onChildClick(ExpandableListView parent, View v,
|
||||||
|
int groupPosition, int childPosition, long id) {
|
||||||
|
FilterListItem item = (FilterListItem) adapter.getChild(groupPosition,
|
||||||
|
childPosition);
|
||||||
|
if(item instanceof Filter) {
|
||||||
|
adapter.setSelection(item);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGroupExpand(int groupPosition) {
|
||||||
|
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
|
||||||
|
if(item instanceof Filter)
|
||||||
|
adapter.setSelection(item);
|
||||||
|
else if(item instanceof FilterCategory)
|
||||||
|
adapter.saveExpansionSetting((FilterCategory) item, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGroupCollapse(int groupPosition) {
|
||||||
|
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
|
||||||
|
if(item instanceof Filter)
|
||||||
|
adapter.setSelection(item);
|
||||||
|
else if(item instanceof FilterCategory)
|
||||||
|
adapter.saveExpansionSetting((FilterCategory) item, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
adapter.registerRecevier();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
adapter.unregisterRecevier();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveConfiguration(FilterListItem filterListItem) {
|
||||||
|
String sql = null, contentValuesString = null, title = null;
|
||||||
|
|
||||||
|
if(filterListItem != null && filterListItem instanceof Filter) {
|
||||||
|
sql = ((Filter)filterListItem).sqlQuery;
|
||||||
|
ContentValues values = ((Filter)filterListItem).valuesForNewTasks;
|
||||||
|
if(values != null)
|
||||||
|
contentValuesString = AndroidUtilities.contentValuesToSerializedString(values);
|
||||||
|
title = ((Filter)filterListItem).title;
|
||||||
|
}
|
||||||
|
|
||||||
|
Preferences.setString(TasksWidget.PREF_TITLE + mAppWidgetId, title);
|
||||||
|
Preferences.setString(TasksWidget.PREF_SQL + mAppWidgetId, sql);
|
||||||
|
Preferences.setString(TasksWidget.PREF_VALUES + mAppWidgetId, contentValuesString);
|
||||||
|
}
|
||||||
|
}
|
||||||