mirror of https://github.com/tasks/tasks
Set MinSdk to Ice Cream Sandwich
parent
06375cb0b7
commit
7590a075e6
@ -1,192 +0,0 @@
|
|||||||
package com.todoroo.astrid.widget;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.appwidget.AppWidgetManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.RemoteViews;
|
|
||||||
|
|
||||||
import com.todoroo.andlib.data.TodorooCursor;
|
|
||||||
import com.todoroo.astrid.actfm.TagViewFragment;
|
|
||||||
import com.todoroo.astrid.api.Filter;
|
|
||||||
import com.todoroo.astrid.api.FilterWithCustomIntent;
|
|
||||||
import com.todoroo.astrid.core.SortHelper;
|
|
||||||
import com.todoroo.astrid.dao.Database;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
import com.todoroo.astrid.service.TaskService;
|
|
||||||
import com.todoroo.astrid.subtasks.SubtasksHelper;
|
|
||||||
import com.todoroo.astrid.utility.Constants;
|
|
||||||
|
|
||||||
import org.tasks.R;
|
|
||||||
import org.tasks.injection.InjectingService;
|
|
||||||
import org.tasks.preferences.Preferences;
|
|
||||||
import org.tasks.widget.DueDateFormatter;
|
|
||||||
import org.tasks.widget.WidgetHelper;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class WidgetUpdateService extends InjectingService {
|
|
||||||
|
|
||||||
private static final int NUM_VISIBLE_TASKS = 25;
|
|
||||||
|
|
||||||
public static final String EXTRA_WIDGET_ID = "widget_id"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
@Inject Database database;
|
|
||||||
@Inject TaskService taskService;
|
|
||||||
@Inject WidgetHelper widgetHelper;
|
|
||||||
@Inject Preferences preferences;
|
|
||||||
@Inject SubtasksHelper subtasksHelper;
|
|
||||||
@Inject DueDateFormatter dueDateFormatter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart(final Intent intent, int startId) {
|
|
||||||
new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
startServiceInBackgroundThread(intent);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startServiceInBackgroundThread(Intent intent) {
|
|
||||||
ComponentName thisWidget = new ComponentName(this,
|
|
||||||
TasksWidget.class);
|
|
||||||
AppWidgetManager manager = AppWidgetManager.getInstance(this);
|
|
||||||
|
|
||||||
int extrasId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
|
||||||
if(intent != null) {
|
|
||||||
extrasId = intent.getIntExtra(EXTRA_WIDGET_ID, extrasId);
|
|
||||||
}
|
|
||||||
if(extrasId == AppWidgetManager.INVALID_APPWIDGET_ID) {
|
|
||||||
int[] ids;
|
|
||||||
try {
|
|
||||||
ids = manager.getAppWidgetIds(thisWidget);
|
|
||||||
for(int id : ids) {
|
|
||||||
RemoteViews updateViews = buildUpdate(this, id);
|
|
||||||
manager.updateAppWidget(id, updateViews);
|
|
||||||
}
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
// "System server dead" was sometimes thrown here by the OS. Abort if that happens
|
|
||||||
Timber.e(e, e.getMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RemoteViews updateViews = buildUpdate(this, extrasId);
|
|
||||||
manager.updateAppWidget(extrasId, updateViews);
|
|
||||||
}
|
|
||||||
|
|
||||||
stopSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
private RemoteViews buildUpdate(Context context, int widgetId) {
|
|
||||||
boolean darkTheme = preferences.useDarkWidgetTheme(widgetId);
|
|
||||||
/**
|
|
||||||
* The reason we use a bunch of different but almost identical layouts is that there is a bug with
|
|
||||||
* Android 2.1 (level 7) that doesn't allow setting backgrounds on remote views. I know it's lame,
|
|
||||||
* but I didn't see a better solution. Alternatively, we could disallow theming widgets on
|
|
||||||
* Android 2.1.
|
|
||||||
*/
|
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(), darkTheme
|
|
||||||
? R.layout.widget_initialized_dark
|
|
||||||
: R.layout.widget_initialized);
|
|
||||||
|
|
||||||
if (preferences.getBoolean(WidgetConfigActivity.PREF_HIDE_HEADER + widgetId, false)) {
|
|
||||||
views.setViewVisibility(R.id.widget_header, View.GONE);
|
|
||||||
}
|
|
||||||
if (preferences.getBoolean(WidgetConfigActivity.PREF_WIDGET_TRANSPARENT + widgetId, false)) {
|
|
||||||
views.setInt(R.id.widget_header, "setBackgroundColor", android.R.color.transparent);
|
|
||||||
views.setInt(R.id.taskbody, "setBackgroundColor", android.R.color.transparent);
|
|
||||||
}
|
|
||||||
|
|
||||||
int numberOfTasks = NUM_VISIBLE_TASKS;
|
|
||||||
|
|
||||||
TodorooCursor<Task> cursor = null;
|
|
||||||
Filter filter = null;
|
|
||||||
try {
|
|
||||||
filter = widgetHelper.getFilter(context, widgetId);
|
|
||||||
if (filter.isTagFilter()) {
|
|
||||||
((FilterWithCustomIntent) filter).customTaskList = new ComponentName(context, TagViewFragment.class); // In case legacy widget was created with subtasks fragment
|
|
||||||
}
|
|
||||||
views.setTextViewText(R.id.widget_title, filter.listingTitle);
|
|
||||||
views.removeAllViews(R.id.taskbody);
|
|
||||||
|
|
||||||
int sort = preferences.getSortMode();
|
|
||||||
String query = SortHelper.adjustQueryForFlagsAndSort(preferences,
|
|
||||||
filter.getSqlQuery(), sort).replaceAll("LIMIT \\d+", "") + " LIMIT " + numberOfTasks;
|
|
||||||
|
|
||||||
String tagName = preferences.getStringValue(WidgetConfigActivity.PREF_TITLE + widgetId);
|
|
||||||
boolean showDueDates = preferences.getBoolean(WidgetConfigActivity.PREF_SHOW_DUE_DATE + widgetId, false);
|
|
||||||
query = subtasksHelper.applySubtasksToWidgetFilter(filter, query, tagName, numberOfTasks);
|
|
||||||
|
|
||||||
database.openForReading();
|
|
||||||
cursor = taskService.fetchFiltered(query, null, Task.ID, Task.TITLE, Task.DUE_DATE, Task.COMPLETION_DATE);
|
|
||||||
int i;
|
|
||||||
Resources r = context.getResources();
|
|
||||||
for (i = 0; i < cursor.getCount() && i < numberOfTasks; i++) {
|
|
||||||
cursor.moveToPosition(i);
|
|
||||||
Task task = new Task(cursor);
|
|
||||||
String textContent = task.getTitle();
|
|
||||||
int textColor = r.getColor(darkTheme
|
|
||||||
? R.color.widget_text_color_dark
|
|
||||||
: R.color.widget_text_color_light);
|
|
||||||
if(task.isCompleted()) {
|
|
||||||
textColor = r.getColor(R.color.task_list_done);
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoteViews row = new RemoteViews(Constants.PACKAGE, R.layout.widget_row);
|
|
||||||
|
|
||||||
if (showDueDates) {
|
|
||||||
dueDateFormatter.formatDueDate(row, task, textColor);
|
|
||||||
} else if(task.hasDueDate() && task.isOverdue()) {
|
|
||||||
textColor = r.getColor(R.color.overdue);
|
|
||||||
}
|
|
||||||
|
|
||||||
row.setTextViewText(R.id.text, textContent);
|
|
||||||
row.setTextColor(R.id.text, textColor);
|
|
||||||
|
|
||||||
views.addView(R.id.taskbody, row);
|
|
||||||
|
|
||||||
RemoteViews separator = new RemoteViews(Constants.PACKAGE, R.layout.widget_separator);
|
|
||||||
boolean isLastRow = (i == cursor.getCount() - 1) || (i == numberOfTasks - 1);
|
|
||||||
if (!isLastRow) {
|
|
||||||
views.addView(R.id.taskbody, separator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (; i < numberOfTasks; i++) {
|
|
||||||
RemoteViews row = new RemoteViews(Constants.PACKAGE, R.layout.widget_row);
|
|
||||||
row.setViewVisibility(R.id.text, View.INVISIBLE);
|
|
||||||
views.addView(R.id.taskbody, row);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Timber.e(e, e.getMessage());
|
|
||||||
} finally {
|
|
||||||
if(cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PendingIntent pListIntent = widgetHelper.getListIntent(context, filter, widgetId);
|
|
||||||
if (pListIntent != null) {
|
|
||||||
views.setOnClickPendingIntent(R.id.taskbody, pListIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
PendingIntent pEditIntent = widgetHelper.getNewTaskIntent(context, filter, widgetId);
|
|
||||||
if (pEditIntent != null) {
|
|
||||||
views.setOnClickPendingIntent(R.id.widget_button, pEditIntent);
|
|
||||||
views.setOnClickPendingIntent(R.id.widget_title, pEditIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return views;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,12 @@
|
|||||||
package org.tasks.injection;
|
package org.tasks.injection;
|
||||||
|
|
||||||
import com.todoroo.astrid.widget.WidgetUpdateService;
|
|
||||||
|
|
||||||
import org.tasks.widget.ScrollableWidgetUpdateService;
|
import org.tasks.widget.ScrollableWidgetUpdateService;
|
||||||
|
|
||||||
import dagger.Module;
|
import dagger.Module;
|
||||||
|
|
||||||
@Module(addsTo = TasksModule.class,
|
@Module(addsTo = TasksModule.class,
|
||||||
injects = {
|
injects = {
|
||||||
ScrollableWidgetUpdateService.class,
|
ScrollableWidgetUpdateService.class
|
||||||
WidgetUpdateService.class
|
|
||||||
})
|
})
|
||||||
public class ServiceModule {
|
public class ServiceModule {
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package org.tasks.receivers;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import org.tasks.injection.InjectingBroadcastReceiver;
|
|
||||||
import org.tasks.scheduling.BackgroundScheduler;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class PackageReplacedReceiver extends InjectingBroadcastReceiver {
|
|
||||||
|
|
||||||
@Inject BackgroundScheduler backgroundScheduler;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
super.onReceive(context, intent);
|
|
||||||
|
|
||||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED) && context.getPackageName().equals(intent.getData().getSchemeSpecificPart())) {
|
|
||||||
Timber.d("onReceive(context, %s)", intent);
|
|
||||||
backgroundScheduler.scheduleEverything();
|
|
||||||
} else {
|
|
||||||
Timber.d("ignoring %s", intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/widget"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="@dimen/widget_margin"
|
|
||||||
android:background="@android:color/transparent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/widget_header"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="@color/primary">
|
|
||||||
|
|
||||||
<include layout="@layout/widget_toolbar"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/taskbody"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:background="@color/widget_body_light"
|
|
||||||
android:orientation="vertical">
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/widget"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="@dimen/widget_margin"
|
|
||||||
android:background="@android:color/transparent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/widget_header"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="@color/widget_header_dark">
|
|
||||||
|
|
||||||
<include layout="@layout/widget_toolbar"/>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/widget_header_separator"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="1px"
|
|
||||||
android:background="@android:color/white"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/taskbody"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:background="@color/widget_body_dark"
|
|
||||||
android:orientation="vertical">
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
** Copyright (c) 2012 Todoroo Inc
|
|
||||||
**
|
|
||||||
** See the file "LICENSE" for the full license governing this code.
|
|
||||||
-->
|
|
||||||
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="1px"
|
|
||||||
android:layout_marginLeft="5dip"
|
|
||||||
android:layout_marginRight="5dip"
|
|
||||||
android:background="#ddbababa" >
|
|
||||||
</ImageView>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
<style name="TaskListView" parent="ListView" />
|
|
||||||
|
|
||||||
</resources>
|
|
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<bool name="at_most_honeycomb">false</bool>
|
|
||||||
<bool name="at_least_honeycomb_mr1">true</bool>
|
|
||||||
</resources>
|
|
@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<style name="edit_text_style">
|
|
||||||
<item name="android:textCursorDrawable">@null</item>
|
|
||||||
</style>
|
|
||||||
</resources>
|
|
@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
<dimen name="widget_margin">0dp</dimen>
|
|
||||||
</resources>
|
|
@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
<style name="TextBoxText">
|
|
||||||
<item name="android:textColor">?attr/asTextColor</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
|
@ -1,8 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<bool name="two_pane_layout">false</bool>
|
<bool name="two_pane_layout">false</bool>
|
||||||
<bool name="at_most_honeycomb">true</bool>
|
|
||||||
<bool name="at_least_honeycomb_mr1">false</bool>
|
|
||||||
<bool name="sync_enabled">false</bool>
|
<bool name="sync_enabled">false</bool>
|
||||||
<bool name="location_enabled">false</bool>
|
<bool name="location_enabled">false</bool>
|
||||||
<bool name="google_play_store_available">false</bool>
|
<bool name="google_play_store_available">false</bool>
|
||||||
|
Loading…
Reference in New Issue