fixed up power widget, moved drawables into drawable/ folder for compatibility with Android 1.5

pull/14/head
Tim Su 14 years ago
parent 0edee4ed2a
commit 50229bed6b

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="false" android:drawable="@drawable/scroll_down_normal" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/scroll_down_pressed" />
</selector>

Before

Width:  |  Height:  |  Size: 290 B

After

Width:  |  Height:  |  Size: 290 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 285 B

After

Width:  |  Height:  |  Size: 285 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:state_enabled="true"
android:state_focused="false" android:drawable="@drawable/scroll_up_normal" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/scroll_up_pressed" />
</selector>

Before

Width:  |  Height:  |  Size: 276 B

After

Width:  |  Height:  |  Size: 276 B

Before

Width:  |  Height:  |  Size: 280 B

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Before

Width:  |  Height:  |  Size: 330 B

After

Width:  |  Height:  |  Size: 330 B

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 475 B

Before

Width:  |  Height:  |  Size: 490 B

After

Width:  |  Height:  |  Size: 490 B

Before

Width:  |  Height:  |  Size: 479 B

After

Width:  |  Height:  |  Size: 479 B

Before

Width:  |  Height:  |  Size: 480 B

After

Width:  |  Height:  |  Size: 480 B

@ -45,15 +45,21 @@
android:layout_height="36dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:paddingLeft="7dp"
android:paddingRight="0dp"
android:orientation="horizontal"
android:layout_alignParentTop="true">
<ImageButton
android:id="@+id/scroll_up"
android:background="@drawable/scroll_up"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TextView
android:id="@+id/widget_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_weight="100"
android:layout_gravity="left"
android:textColor="#ffffff"
android:textSize="20sp"
@ -62,20 +68,14 @@
android:paddingTop="3dp"
android:paddingBottom="2dp"
android:ellipsize="start" />
<LinearLayout
android:visibility="gone"
<ImageButton
android:id="@+id/scroll_down"
android:background="@drawable/scroll_down"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:paddingTop="10dp"
android:paddingBottom="9dp"
android:paddingLeft="10dp"
android:paddingRight="9dp" >
<ImageView
android:src="@drawable/button_plus"
android:layout_width="17dp"
android:layout_height="17dp"
/>
</LinearLayout>
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
@ -85,6 +85,8 @@
android:orientation="vertical"
android:layout_below="@+id/header"
android:layout_above="@+id/footer"
android:paddingTop="4dip"
android:paddingBottom="3dip"
android:gravity="fill_vertical">
<!-- body rows -->
@ -97,11 +99,11 @@
android:id="@+id/importance1"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox1"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -110,13 +112,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -127,11 +129,11 @@
android:id="@+id/importance2"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox2"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -140,13 +142,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -157,11 +159,11 @@
android:id="@+id/importance3"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox3"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -170,13 +172,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -187,11 +189,11 @@
android:id="@+id/importance4"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox4"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -200,13 +202,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -217,11 +219,11 @@
android:id="@+id/importance5"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox5"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -230,13 +232,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -247,11 +249,11 @@
android:id="@+id/importance6"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox6"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -260,13 +262,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -277,11 +279,11 @@
android:id="@+id/importance7"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox7"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -290,13 +292,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -307,11 +309,11 @@
android:id="@+id/importance8"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox8"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -320,13 +322,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -337,11 +339,11 @@
android:id="@+id/importance9"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox9"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -350,13 +352,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
@ -367,11 +369,11 @@
android:id="@+id/importance10"
android:layout_width="3dp"
android:layout_height="38dp" />
<CheckBox
<ImageButton
android:id="@+id/checkbox10"
android:src="@drawable/checkbox"
android:src="@drawable/btn_check_buttonless_off"
android:paddingLeft="2dp"
android:paddingRight="10dp"
android:paddingRight="2dp"
android:layout_width="38dp"
android:layout_height="38dp" />
<TextView
@ -380,13 +382,13 @@
android:layout_height="wrap_content"
android:layout_weight="100"
android:layout_gravity="center_vertical"
android:textSize="14sp" />
android:textSize="14sp" android:paddingLeft="5dip" />
<TextView
android:id="@+id/task_due10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="right"
android:gravity="right" android:paddingRight="4dp"
android:textSize="12sp" />
</LinearLayout>
@ -394,28 +396,18 @@
</LinearLayout>
<RelativeLayout
<FrameLayout
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="46dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_above="@+id/encouragement">
<ImageView
android:id="@+id/scroll_up"
android:src="@drawable/scroll_up"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentLeft="true"
/>
android:layout_height="wrap_content"
android:layout_above="@id/encouragement"
android:layout_alignParentBottom="true">
<!-- if no encouragement -->
<LinearLayout
android:id="@+id/button_plus"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_toRightOf="@+id/scroll_up"
android:layout_toLeftOf="@+id/scroll_down"
android:gravity="center_horizontal">
<ImageView
android:src="@drawable/button_plus"
@ -434,19 +426,12 @@
android:gravity="center_vertical"
/>
</LinearLayout>
<ImageView
android:id="@+id/scroll_down"
android:src="@drawable/scroll_down"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
<!-- encouragement -->
<RelativeLayout
android:id="@+id/encouragement"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/speech_bubble"
android:layout_alignParentLeft="true"
@ -478,6 +463,8 @@
android:layout_marginBottom="4dp"/>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
</FrameLayout>

@ -19,5 +19,7 @@
<string-array name="PPW_encouragements">
<item>Ready to work?</item>
<item>Have time to finish something?</item>
<item>Gosh, you are looking suave today!</item>
</string-array>
</resources>

@ -1,5 +1,7 @@
package com.todoroo.astrid.widget;
import java.util.Date;
import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
@ -16,11 +18,11 @@ import android.view.View;
import android.widget.RemoteViews;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.ShortcutActivity;
@ -53,9 +55,9 @@ public class PowerWidget extends AppWidgetProvider {
static final long ENCOURAGEMENT_CYCLE_TIME = 1000 * 60 * 60 * 4; // 4 hours
static final String ACTION_MARK_COMPLETE = "com.timsu.astrid.widget.ACTION_MARK_COMPLETE";
static final String ACTION_SCROLL_UP = "com.timsu.astrid.widget.ACTION_SCROLL_UP";
static final String ACTION_SCROLL_DOWN = "com.timsu.astrid.widget.ACTION_SCROLL_DOWN";
static final String ACTION_MARK_COMPLETE = "com.todoroo.astrid.widget.ACTION_MARK_COMPLETE";
static final String ACTION_SCROLL_UP = "com.todoroo.astrid.widget.ACTION_SCROLL_UP";
static final String ACTION_SCROLL_DOWN = "com.todoroo.astrid.widget.ACTION_SCROLL_DOWN";
// Prefix for Shared Preferences
static final String PREF_COLOR = "powerwidget-color-";
@ -66,10 +68,20 @@ public class PowerWidget extends AppWidgetProvider {
static final String PREF_VALUES = "powerwidget-values-";
static final String PREF_ENCOURAGEMENT_LAST_ROTATION_TIME = "powerwidget-encouragementRotationTime-";
static final String PREF_ENCOURAGEMENT_CURRENT = "powerwidget-encouragementCurrent-";
static final String PREF_LAST_COMPLETED_ID = "powerwidget-lastCompletedId-";
static final String PREF_LAST_COMPLETED_POS = "powerwidget-lastCompletedPos-";
static final String PREF_LAST_COMPLETED_DATE = "powerwidget-lastCompletedDate-";
public final static String APP_WIDGET_IDS = "com.timsu.astrid.APP_WIDGET_IDS";
public final static String COMPLETED_TASK_ID = "com.timsu.astrid.COMPLETED_TASK_ID";
public final static String EXTRA_SCROLL_OFFSET = "com.timsu.astrid.EXTRA_SCROLL_OFFSET";
/** id of task to complete */
public final static String COMPLETED_TASK_ID = "compId";
/** position in list of task that was completed */
public final static String COMPLETED_TASK_POSITION = "compPos";
/** new scroll offset */
public final static String EXTRA_SCROLL_OFFSET = "soff";
public final static int[] TASK_TITLE = { R.id.task_title1, R.id.task_title2,
R.id.task_title3, R.id.task_title4, R.id.task_title5, R.id.task_title6,
@ -87,6 +99,8 @@ public class PowerWidget extends AppWidgetProvider {
R.id.checkbox3, R.id.checkbox4, R.id.checkbox5, R.id.checkbox6,
R.id.checkbox7, R.id.checkbox8, R.id.checkbox9, R.id.checkbox10 };
private static final int ROW_LIMIT = 10;
private static int[] importanceColors = null;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
@ -108,16 +122,16 @@ public class PowerWidget extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
if (ACTION_MARK_COMPLETE.equals(intent.getAction())){
long taskId = intent.getLongExtra(COMPLETED_TASK_ID, -1);
Intent updateIntent = new Intent(context, UpdateService.class);
updateIntent.putExtra(COMPLETED_TASK_ID, taskId);
updateIntent.setAction(ACTION_MARK_COMPLETE);
updateIntent.putExtras(intent.getExtras());
context.startService(updateIntent);
} else if (ACTION_SCROLL_UP.equals(intent.getAction()) || ACTION_SCROLL_DOWN.equals(intent.getAction())){
int id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
if (id != AppWidgetManager.INVALID_APPWIDGET_ID){
int scrollOffset = intent.getIntExtra(EXTRA_SCROLL_OFFSET, 0);
Intent updateIntent = new Intent(context, UpdateService.class);
updateIntent.setAction(intent.getAction());
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
updateIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset);
context.startService(updateIntent);
@ -151,32 +165,48 @@ public class PowerWidget extends AppWidgetProvider {
public static class UpdateService extends Service {
@Autowired
Database database;
private Database database;
@Autowired
TaskService taskService;
private TaskService taskService;
public UpdateService() {
DependencyInjectionService.getInstance().inject(this);
}
@Override
public void onStart(Intent intent, int startId) {
ContextManager.setContext(this);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
if (intent != null){
if (intent != null && ACTION_MARK_COMPLETE.equals(intent.getAction())) {
long taskId = intent.getLongExtra(COMPLETED_TASK_ID, -1);
if (taskId > 0){
Task task = taskService.fetchById(taskId, Task.PROPERTIES);
if (task != null){
taskService.setComplete(task, true);
if (taskId > 0) {
Task task = taskService.fetchById(taskId, Task.ID, Task.COMPLETION_DATE);
if (task != null) {
taskService.setComplete(task, !task.isCompleted());
int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
Preferences.setLong(PREF_LAST_COMPLETED_ID +
appWidgetId, taskId);
Preferences.setInt(PREF_LAST_COMPLETED_POS +
appWidgetId, intent.getIntExtra(COMPLETED_TASK_POSITION, -1));
Preferences.setLong(PREF_LAST_COMPLETED_DATE +
appWidgetId, DateUtilities.now());
System.err.println("completed business. posn " +
intent.getIntExtra(COMPLETED_TASK_POSITION, 0) +
" app id: " + appWidgetId);
}
}
}
AppWidgetManager manager = AppWidgetManager.getInstance(this);
int scrollOffset = 0;
int[] appWidgetIds = null;
int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
if (intent != null){
if (intent != null && (ACTION_SCROLL_UP.equals(intent.getAction()) || ACTION_SCROLL_DOWN.equals(intent.getAction()))) {
scrollOffset = intent.getIntExtra(EXTRA_SCROLL_OFFSET, 0);
appWidgetIds = intent.getIntArrayExtra(APP_WIDGET_IDS);
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
@ -204,6 +234,8 @@ public class PowerWidget extends AppWidgetProvider {
public RemoteViews buildUpdate(Context context, int appWidgetId, int scrollOffset) {
DependencyInjectionService.getInstance().inject(this);
System.err.println("BUILD UPDATE " + DateUtilities.now());
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_power_44);
@ -292,28 +324,70 @@ public class PowerWidget extends AppWidgetProvider {
int sort = Preferences.getInt(SortSelectionActivity.PREF_SORT_SORT, 0);
String query = SortSelectionActivity.adjustQueryForFlagsAndSort(
filter.sqlQuery, flags, sort);
query = query.replace(Task.COMPLETION_DATE.eq(0).toString(), Criterion.or(Task.COMPLETION_DATE.eq(0),
Task.COMPLETION_DATE.gt(DateUtilities.now() - 60000L)).toString());
scrollOffset = Math.max(0, scrollOffset);
query = query.replaceAll("[lL][iI][mM][iI][tT] +[^ ]+", "") + " LIMIT " +
scrollOffset + "," + ROW_LIMIT;
System.err.println("PRE LOAD DATA " + DateUtilities.now());
database.openForReading();
cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE,
Task.DUE_DATE, Task.IMPORTANCE, Task.COMPLETION_DATE);
final Property<?>[] properties = new Property<?>[] { Task.ID, Task.TITLE,
Task.DUE_DATE, Task.IMPORTANCE, Task.COMPLETION_DATE };
cursor = taskService.fetchFiltered(query, null, properties);
// adjust bounds of scrolling
if (scrollOffset < 0){
scrollOffset = 0;
} else if (scrollOffset >= cursor.getCount()){
scrollOffset = cursor.getCount() - 1 ;
boolean canScrollDown = cursor.getCount() > 1;
if(importanceColors == null) {
importanceColors = Task.getImportanceColors(getResources());
System.err.println("loaded importance");
}
int[] importanceColors = Task.getImportanceColors(getResources());
// load last completed task
Task lastCompleted = null;
int lastCompletedPosition = 0;
System.err.println("last completed for " + appWidgetId + ": " +
new Date(Preferences.getLong(PREF_LAST_COMPLETED_DATE+appWidgetId, 0)));
if(DateUtilities.now() - Preferences.getLong(PREF_LAST_COMPLETED_DATE+appWidgetId, 0) < 120000L) {
lastCompleted = taskService.fetchById(Preferences.getLong(PREF_LAST_COMPLETED_ID+appWidgetId, -1L),
properties);
lastCompletedPosition = Preferences.getInt(PREF_LAST_COMPLETED_POS+appWidgetId, 0);
}
Task task = new Task();
for (int i = scrollOffset; i < cursor.getCount() && i < 10; i++) {
cursor.moveToPosition(i);
int position;
for (position = 0; position < cursor.getCount() && position < ROW_LIMIT; position++) {
if(lastCompleted != null && lastCompletedPosition == position + scrollOffset) {
task = lastCompleted;
} else {
cursor.moveToNext();
task.readFromCursor(cursor);
}
long taskId = task.getValue(Task.ID);
// importance
views.setInt(TASK_IMPORTANCE[position], "setBackgroundColor", importanceColors[task.getValue(Task.IMPORTANCE)]);
String textContent = "";
// check box
Intent markCompleteIntent = new Intent(context, PowerWidget.class);
markCompleteIntent.setAction(ACTION_MARK_COMPLETE);
markCompleteIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
markCompleteIntent.putExtra(COMPLETED_TASK_ID, taskId);
markCompleteIntent.putExtra(COMPLETED_TASK_POSITION, scrollOffset + position);
markCompleteIntent.setType(COMPLETED_TASK_ID + taskId);
PendingIntent pMarkCompleteIntent = PendingIntent.getBroadcast(context, 0, markCompleteIntent, 0);
views.setOnClickPendingIntent(TASK_CHECKBOX[position], pMarkCompleteIntent);
if(task.isCompleted()) {
views.setImageViewResource(TASK_CHECKBOX[position], R.drawable.btn_check_buttonless_on);
views.setInt(TASK_TITLE[position], "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG);
} else {
views.setImageViewResource(TASK_CHECKBOX[position], R.drawable.btn_check_buttonless_off);
views.setInt(TASK_TITLE[position], "setPaintFlags", 0);
}
// title
int titleColor = textColor;
int dueString = R.string.PPW_due;
if(task.isCompleted()) {
@ -323,78 +397,68 @@ public class PowerWidget extends AppWidgetProvider {
titleColor = overdueColor;
dueString = R.string.PPW_past_due;
}
textContent = task.getValue(Task.TITLE);
String dateValue = "";
if(dueString != 0 && task.hasDueDate()) {
dateValue = getString(dueString) + "\n" +
DateUtils.getRelativeTimeSpanString(task.getValue(Task.DUE_DATE));
}
long taskId = task.getValue(Task.ID);
String textContent = task.getValue(Task.TITLE);
views.setTextViewText(TASK_TITLE[position], textContent);
views.setTextColor(TASK_TITLE[position], titleColor);
Intent viewTaskIntent = new Intent(context, ShortcutActivity.class);
viewTaskIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
viewTaskIntent.putExtra(ShortcutActivity.TOKEN_SINGLE_TASK, taskId);
viewTaskIntent.setType(ShortcutActivity.TOKEN_SINGLE_TASK + taskId);
Log.d(LOG_TAG, "viewTaskIntent type: "+ShortcutActivity.TOKEN_SINGLE_TASK + taskId);
PendingIntent pEditTask = PendingIntent.getActivity(context, 0, viewTaskIntent, PendingIntent.FLAG_CANCEL_CURRENT);
views.setOnClickPendingIntent(TASK_TITLE[position], pEditTask);
Intent markCompleteIntent = new Intent(context, PowerWidget.class);
markCompleteIntent.setAction(ACTION_MARK_COMPLETE);
markCompleteIntent.putExtra(COMPLETED_TASK_ID, taskId);
markCompleteIntent.setType(COMPLETED_TASK_ID + taskId);
PendingIntent pMarkCompleteIntent = PendingIntent.getBroadcast(context, 0, markCompleteIntent, 0);
// due date
String dateValue = "";
if(dueString != 0 && task.hasDueDate()) {
dateValue = getString(dueString) + "\n" +
DateUtils.getRelativeTimeSpanString(task.getValue(Task.DUE_DATE));
}
views.setTextViewText(TASK_DUE[position], dateValue);
views.setTextColor(TASK_DUE[position], titleColor);
// set importance marker
views.setInt(TASK_IMPORTANCE[i], "setBackgroundColor", importanceColors[task.getValue(Task.IMPORTANCE)]);
// set click listener for checkbox
views.setOnClickPendingIntent(TASK_CHECKBOX[i], pMarkCompleteIntent);
// set task title
if(task.isCompleted())
views.setInt(TASK_TITLE[i], "setPaintFlags", Paint.STRIKE_THRU_TEXT_FLAG);
views.setTextViewText(TASK_TITLE[i], textContent);
views.setTextColor(TASK_TITLE[i], titleColor);
// set due date
views.setTextViewText(TASK_DUE[i], dateValue);
views.setTextColor(TASK_DUE[i], titleColor);
// set click listener for text content
views.setOnClickPendingIntent(TASK_TITLE[i], pEditTask);
views.setViewVisibility(TASK_IMPORTANCE[position], View.VISIBLE);
views.setViewVisibility(TASK_CHECKBOX[position], View.VISIBLE);
views.setViewVisibility(TASK_TITLE[position], View.VISIBLE);
views.setViewVisibility(TASK_DUE[position], View.VISIBLE);
}
for(; position < ROW_LIMIT; position++) {
views.setViewVisibility(TASK_IMPORTANCE[position], View.INVISIBLE);
views.setViewVisibility(TASK_CHECKBOX[position], View.INVISIBLE);
views.setViewVisibility(TASK_TITLE[position], View.INVISIBLE);
views.setViewVisibility(TASK_DUE[position], View.INVISIBLE);
}
// create intent to scroll up
Intent scrollUpIntent = new Intent(context, PowerWidget.class);
scrollUpIntent.setAction(ACTION_SCROLL_UP);
scrollUpIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
scrollUpIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset-1);
scrollUpIntent.setType(AppWidgetManager.EXTRA_APPWIDGET_ID + appWidgetId);
PendingIntent pScrollUpIntent = PendingIntent.getBroadcast(context, 0, scrollUpIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.scroll_up, pScrollUpIntent);
if (scrollOffset-1 < 0){
// show disabled up button
scrollUpIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset);
views.setImageViewResource(R.id.scroll_up, R.drawable.scroll_up_disabled);
} else {
scrollUpIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset-1);
views.setImageViewResource(R.id.scroll_up, R.drawable.scroll_up);
}
PendingIntent pScrollUpIntent = PendingIntent.getBroadcast(context, 0, scrollUpIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.scroll_up, pScrollUpIntent);
// create intent to scroll down
Intent scrollDownIntent = new Intent(context, PowerWidget.class);
scrollDownIntent.setAction(ACTION_SCROLL_DOWN);
scrollDownIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
scrollDownIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset+1);
scrollDownIntent.setType(AppWidgetManager.EXTRA_APPWIDGET_ID + appWidgetId);
PendingIntent pScrollDownIntent = PendingIntent.getBroadcast(context, 0, scrollDownIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.scroll_down, pScrollDownIntent);
if (scrollOffset+1 >= cursor.getCount()){
// show disabled down button
if (!canScrollDown){
scrollDownIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset);
views.setImageViewResource(R.id.scroll_down, R.drawable.scroll_down_disabled);
} else {
scrollDownIntent.putExtra(EXTRA_SCROLL_OFFSET, scrollOffset+1);
views.setImageViewResource(R.id.scroll_down, R.drawable.scroll_down);
}
PendingIntent pScrollDownIntent = PendingIntent.getBroadcast(context, 0, scrollDownIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.scroll_down, pScrollDownIntent);
} catch (Exception e) {
// can happen if database is not ready
Log.e("WIDGET-UPDATE", "Error updating widget", e);
@ -403,7 +467,7 @@ public class PowerWidget extends AppWidgetProvider {
cursor.close();
}
System.err.println("END UPDATE " + DateUtilities.now());
return views;
}

Loading…
Cancel
Save