Consolidated three widget configuration classes into one

pull/14/head
Tim Su 14 years ago
parent 7d0b986d98
commit 24e1aa70f1

@ -127,11 +127,24 @@
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="com.todoroo.astrid.widget.WidgetConfigActivity$WithColors"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<activity android:name="com.todoroo.astrid.widget.WidgetConfigActivity$WithColorsAndEncouragements"
android:theme="@style/Theme">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
<!-- ======================================================= Receivers = --> <!-- ======================================================= Receivers = -->
<receiver android:name="com.todoroo.astrid.reminders.Notifications" /> <receiver android:name="com.todoroo.astrid.reminders.Notifications" />
<!-- widgets -->
<receiver android:name="com.todoroo.astrid.widget.TasksWidget"> <receiver android:name="com.todoroo.astrid.widget.TasksWidget">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
@ -139,16 +152,18 @@
<meta-data android:name="android.appwidget.provider" <meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info" /> android:resource="@xml/widget_provider_info" />
</receiver> </receiver>
<receiver android:name="com.todoroo.astrid.widget.PowerWidget"
<receiver android:name="com.todoroo.astrid.widget.TasksWidget"> android:label="@string/PPW_widget_44_label"
android:icon="@drawable/icon_pp">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
<meta-data android:name="android.appwidget.provider" <meta-data android:name="android.appwidget.provider"
android:resource="@xml/power_widget_44_provider_info" /> android:resource="@xml/power_widget_44_provider_info" />
</receiver> </receiver>
<receiver android:name="com.todoroo.astrid.widget.PowerWidget42"
<receiver android:name="com.todoroo.astrid.widget.TasksWidget"> android:label="@string/PPW_widget_42_label"
android:icon="@drawable/icon_pp">
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/footer"
android:orientation="vertical">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="@string/PPW_color"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<Spinner android:id="@+id/PPW_color"
android:drawSelectorOnTop="true" android:prompt="@string/PPW_color"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<!--
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<CheckBox android:id="@+id/PPW_enable_calendar"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="@string/PPW_enable_calendar"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
-->
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<CheckBox android:id="@+id/PPW_disable_encouragements"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TextView android:text="@string/PPW_disable_encouragements"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:text="@string/PPW_filter"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<!-- 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"/>
</LinearLayout>
</LinearLayout>
<RelativeLayout android:id="@+id/footer"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:paddingTop="5dp" android:paddingBottom="3dp"
android:paddingLeft="3dp" android:paddingRight="3dp">
<Button android:id="@+id/ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok"/>
</RelativeLayout>
</RelativeLayout>

@ -1,11 +1,36 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- See the file "LICENSE" for the full license governing this code. --> <!-- See the file "LICENSE" for the full license governing this code.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:orientation="vertical"
android:background="@drawable/background_gradient"> android:background="@drawable/background_gradient">
<!-- header -->
<LinearLayout android:id="@+id/colors"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="@string/PPW_color"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/PPW_color"
android:drawSelectorOnTop="true"
android:prompt="@string/PPW_color"
android:entries="@array/PPW_colors"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<CheckBox
android:id="@+id/PPW_disable_encouragements"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/PPW_disable_encouragements" />
<!-- List --> <!-- List -->
<ExpandableListView android:id="@android:id/list" <ExpandableListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"

@ -22,4 +22,12 @@
<item>Have time to finish something?</item> <item>Have time to finish something?</item>
<item>Gosh, you are looking suave today!</item> <item>Gosh, you are looking suave today!</item>
</string-array> </string-array>
<string-array name="PPW_colors">
<item>Black</item>
<item>White</item>
<item>Blue</item>
<item>Red</item>
</string-array>
</resources> </resources>

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="com.todoroo.astrid.widget.ConfigurePowerWidget42Activity" android:configure="com.todoroo.astrid.widget.WidgetConfigActivity$WithColors"
android:minWidth="294dip" android:minWidth="294dip"
android:minHeight="146dip" android:minHeight="146dip"
android:updatePeriodMillis="86400000" android:updatePeriodMillis="86400000"

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:configure="com.todoroo.astrid.widget.ConfigurePowerWidgetActivity" android:configure="com.todoroo.astrid.widget.WidgetConfigActivity$WithColorsAndEncouragements"
android:minWidth="294dip" android:minWidth="294dip"
android:minHeight="294dip" android:minHeight="294dip"
android:updatePeriodMillis="86400000" android:updatePeriodMillis="86400000"

@ -1,200 +0,0 @@
package com.todoroo.astrid.widget;
import android.app.ExpandableListActivity;
import android.appwidget.AppWidgetManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.Spinner;
import com.todoroo.astrid.service.StatisticsService;
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.Constants;
import com.todoroo.andlib.utility.Preferences;
/**
* Configure options for the Power Pack widget. Select a color, filter to use, enable/disable encouragements.
*
* @author jwong
*
*/
public class ConfigurePowerWidget42Activity extends ExpandableListActivity {
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
FilterAdapter adapter = null;
String[] colors = new String[]{
"Black",
"Blue",
"Red",
"White"
};
public ConfigurePowerWidget42Activity() {
super();
}
@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.power_widget_configure);
setTitle(R.string.PPW_configure_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();
}
ArrayAdapter<String> colorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner colorSpinner = (Spinner) findViewById(R.id.PPW_color);
colorSpinner.setAdapter(colorAdapter);
// set up ui
adapter = new FilterAdapter(this, getExpandableListView(),
R.layout.filter_adapter_row, true);
setListAdapter(adapter);
Button button = (Button)findViewById(R.id.ok);
button.setOnClickListener(mOnClickListener);
StatisticsService.reportEvent("power-widget-config"); //$NON-NLS-1$
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
final Context context = ConfigurePowerWidget42Activity.this;
Spinner colorSpinner = (Spinner) findViewById(R.id.PPW_color);
int colorPos = colorSpinner.getSelectedItemPosition();
String color = colors[colorPos];
// removed calendar option
// CheckBox chk_enableCalendar = (CheckBox) findViewById(R.id.PPW_enable_calendar);
// boolean enableCalendar = chk_enableCalendar.isChecked();
boolean enableCalendar = false;
CheckBox chk_disableEncouragements = (CheckBox) findViewById(R.id.PPW_disable_encouragements);
boolean disableEncouragements = chk_disableEncouragements.isChecked();
// Save configuration options
saveConfiguration(adapter.getSelection(), color, enableCalendar, !disableEncouragements);
// Push widget update to surface with newly set prefix
PowerWidget42.updateAppWidget(context, 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();
}
@Override
protected void onStart() {
super.onStart();
StatisticsService.sessionStart(this);
}
@Override
protected void onStop() {
super.onStop();
StatisticsService.sessionStop(this);
}
private void saveConfiguration(FilterListItem filterListItem, String color, boolean enableCalendar, boolean enableEncouragements){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
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(PowerWidget.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(PowerWidget.PREF_SQL + mAppWidgetId, sql);
Preferences.setString(PowerWidget.PREF_VALUES + mAppWidgetId, contentValuesString);
Preferences.setString(PowerWidget.PREF_COLOR + mAppWidgetId, color);
Preferences.setBoolean(PowerWidget.PREF_ENABLE_CALENDAR + mAppWidgetId, enableCalendar);
Preferences.setBoolean(PowerWidget.PREF_ENCOURAGEMENTS + mAppWidgetId, enableEncouragements);
}
}

@ -1,200 +0,0 @@
package com.todoroo.astrid.widget;
import android.app.ExpandableListActivity;
import android.appwidget.AppWidgetManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.Spinner;
import com.todoroo.astrid.service.StatisticsService;
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.Constants;
import com.todoroo.andlib.utility.Preferences;
/**
* Configure options for the Power Pack widget. Select a color, filter to use, enable/disable encouragements.
*
* @author jwong
*
*/
public class ConfigurePowerWidgetActivity extends ExpandableListActivity {
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
FilterAdapter adapter = null;
String[] colors = new String[]{
"Black",
"Blue",
"Red",
"White"
};
public ConfigurePowerWidgetActivity() {
super();
}
@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.power_widget_configure);
setTitle(R.string.PPW_configure_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();
}
ArrayAdapter<String> colorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, colors);
colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner colorSpinner = (Spinner) findViewById(R.id.PPW_color);
colorSpinner.setAdapter(colorAdapter);
// set up ui
adapter = new FilterAdapter(this, getExpandableListView(),
R.layout.filter_adapter_row, true);
setListAdapter(adapter);
Button button = (Button)findViewById(R.id.ok);
button.setOnClickListener(mOnClickListener);
StatisticsService.reportEvent("power-widget-config"); //$NON-NLS-1$
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
final Context context = ConfigurePowerWidgetActivity.this;
Spinner colorSpinner = (Spinner) findViewById(R.id.PPW_color);
int colorPos = colorSpinner.getSelectedItemPosition();
String color = colors[colorPos];
// removed calendar option
// CheckBox chk_enableCalendar = (CheckBox) findViewById(R.id.PPW_enable_calendar);
// boolean enableCalendar = chk_enableCalendar.isChecked();
boolean enableCalendar = false;
CheckBox chk_disableEncouragements = (CheckBox) findViewById(R.id.PPW_disable_encouragements);
boolean disableEncouragements = chk_disableEncouragements.isChecked();
// Save configuration options
saveConfiguration(adapter.getSelection(), color, enableCalendar, !disableEncouragements);
// Push widget update to surface with newly set prefix
PowerWidget.updateAppWidget(context, 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();
}
@Override
protected void onStart() {
super.onStart();
StatisticsService.sessionStart(this);
}
@Override
protected void onStop() {
super.onStop();
StatisticsService.sessionStop(this);
}
private void saveConfiguration(FilterListItem filterListItem, String color, boolean enableCalendar, boolean enableEncouragements){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
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(PowerWidget.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(PowerWidget.PREF_SQL + mAppWidgetId, sql);
Preferences.setString(PowerWidget.PREF_VALUES + mAppWidgetId, contentValuesString);
Preferences.setString(PowerWidget.PREF_COLOR + mAppWidgetId, color);
Preferences.setBoolean(PowerWidget.PREF_ENABLE_CALENDAR + mAppWidgetId, enableCalendar);
Preferences.setBoolean(PowerWidget.PREF_ENCOURAGEMENTS + mAppWidgetId, enableEncouragements);
}
}

@ -11,10 +11,7 @@ import com.timsu.astrid.R;
* @author jwong (jwong@dayspring-tech.com) * @author jwong (jwong@dayspring-tech.com)
* *
*/ */
@SuppressWarnings("nls")
public class PowerWidget42 extends PowerWidget { public class PowerWidget42 extends PowerWidget {
static final String LOG_TAG = "PowerWidget42";
static { static {
// set reference to my UpdateService for calls to launch the service // set reference to my UpdateService for calls to launch the service

@ -3,21 +3,24 @@ package com.todoroo.astrid.widget;
import android.app.ExpandableListActivity; import android.app.ExpandableListActivity;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView; import android.widget.ExpandableListView;
import android.widget.Spinner;
import com.todoroo.astrid.service.StatisticsService;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.adapter.FilterAdapter; import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterCategory; import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.andlib.utility.Preferences;
public class WidgetConfigActivity extends ExpandableListActivity { public class WidgetConfigActivity extends ExpandableListActivity {
@ -25,6 +28,28 @@ public class WidgetConfigActivity extends ExpandableListActivity {
FilterAdapter adapter = null; FilterAdapter adapter = null;
@SuppressWarnings("nls")
public String[] COLORS = new String[] {
"Black",
"White",
"Blue",
"Red"
};
public WidgetConfigActivity() {
super();
}
/** whether to show 'hide encouragements' */
public boolean showEncouragementSetting() {
return false;
}
/** whether to show color selection */
public boolean showColorSelectionSetting() {
return false;
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@ -36,7 +61,7 @@ public class WidgetConfigActivity extends ExpandableListActivity {
// Set the view layout resource to use. // Set the view layout resource to use.
setContentView(R.layout.widget_config_activity); setContentView(R.layout.widget_config_activity);
setTitle(R.string.WCA_title); setTitle(R.string.PPW_configure_title);
// Find the widget id from the intent. // Find the widget id from the intent.
Intent intent = getIntent(); Intent intent = getIntent();
@ -51,6 +76,12 @@ public class WidgetConfigActivity extends ExpandableListActivity {
finish(); finish();
} }
if(!showColorSelectionSetting())
findViewById(R.id.colors).setVisibility(View.GONE);
if(!showEncouragementSetting())
findViewById(R.id.PPW_disable_encouragements).setVisibility(View.GONE);
// set up ui // set up ui
adapter = new FilterAdapter(this, getExpandableListView(), adapter = new FilterAdapter(this, getExpandableListView(),
R.layout.filter_adapter_row, true); R.layout.filter_adapter_row, true);
@ -64,11 +95,24 @@ public class WidgetConfigActivity extends ExpandableListActivity {
View.OnClickListener mOnClickListener = new View.OnClickListener() { View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
final Context context = WidgetConfigActivity.this;
Spinner colorSpinner = (Spinner) findViewById(R.id.PPW_color);
int colorPos = colorSpinner.getSelectedItemPosition();
String color = COLORS[colorPos];
boolean enableCalendar = false;
CheckBox chk_disableEncouragements = (CheckBox) findViewById(R.id.PPW_disable_encouragements);
boolean disableEncouragements = chk_disableEncouragements.isChecked();
if(!showEncouragementSetting())
disableEncouragements = true;
// Save configuration options // Save configuration options
saveConfiguration(adapter.getSelection()); saveConfiguration(adapter.getSelection(), color, enableCalendar, !disableEncouragements);
// Push widget update to surface with newly set prefix // Push widget update to surface with newly set prefix
TasksWidget.updateWidget(WidgetConfigActivity.this, mAppWidgetId); PowerWidget.updateAppWidget(context, mAppWidgetId);
// Make sure we pass back the original appWidgetId // Make sure we pass back the original appWidgetId
Intent resultValue = new Intent(); Intent resultValue = new Intent();
@ -131,7 +175,10 @@ public class WidgetConfigActivity extends ExpandableListActivity {
StatisticsService.sessionStop(this); StatisticsService.sessionStop(this);
} }
private void saveConfiguration(FilterListItem filterListItem) { private void saveConfiguration(FilterListItem filterListItem, String color, boolean enableCalendar, boolean enableEncouragements){
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
String sql = null, contentValuesString = null, title = null; String sql = null, contentValuesString = null, title = null;
if(filterListItem != null && filterListItem instanceof Filter) { if(filterListItem != null && filterListItem instanceof Filter) {
@ -142,10 +189,29 @@ public class WidgetConfigActivity extends ExpandableListActivity {
title = ((Filter)filterListItem).title; title = ((Filter)filterListItem).title;
} }
Preferences.setString(TasksWidget.PREF_TITLE + mAppWidgetId, title); Preferences.setString(PowerWidget.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(TasksWidget.PREF_SQL + mAppWidgetId, sql); Preferences.setString(PowerWidget.PREF_SQL + mAppWidgetId, sql);
Preferences.setString(TasksWidget.PREF_VALUES + mAppWidgetId, contentValuesString); Preferences.setString(PowerWidget.PREF_VALUES + mAppWidgetId, contentValuesString);
StatisticsService.reportEvent("widget-config"); //$NON-NLS-1$ Preferences.setString(PowerWidget.PREF_COLOR + mAppWidgetId, color);
Preferences.setBoolean(PowerWidget.PREF_ENABLE_CALENDAR + mAppWidgetId, enableCalendar);
Preferences.setBoolean(PowerWidget.PREF_ENCOURAGEMENTS + mAppWidgetId, enableEncouragements);
}
// --- related configuration activities
public static class WithColors extends WidgetConfigActivity {
@Override
public boolean showColorSelectionSetting() {
return true;
}
}
public static class WithColorsAndEncouragements extends WithColors {
@Override
public boolean showEncouragementSetting() {
return true;
} }
} }
}

Loading…
Cancel
Save