Remove Astrid Locale plugin

pull/46/head
Alex Baker 11 years ago
parent 5b5cec9f78
commit 6c97d5c501

Binary file not shown.

@ -517,21 +517,6 @@
<activity android:name="com.todoroo.astrid.files.FileExplore"/> <activity android:name="com.todoroo.astrid.files.FileExplore"/>
<!-- locale -->
<activity android:name="com.todoroo.astrid.locale.LocaleEditAlerts"
android:label="@string/locale_edit_alerts_title"
android:icon="@drawable/icon_32"
android:exported="true">
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
</intent-filter>
</activity>
<receiver android:name="com.todoroo.astrid.locale.LocaleReceiver">
<intent-filter>
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
</intent-filter>
</receiver>
<!-- notes --> <!-- notes -->
<receiver android:name="com.todoroo.astrid.notes.NotesDetailExposer"> <receiver android:name="com.todoroo.astrid.notes.NotesDetailExposer">
<intent-filter> <intent-filter>

@ -1,341 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.Spinner;
import org.tasks.R;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.activity.AddOnActivity;
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.core.PluginServices;
import com.todoroo.astrid.service.StatisticsConstants;
import com.twofortyfouram.SharedResources;
/**
* Activity to edit alerts from Locale
*
* @author Tim Su <tim@todoroo.com>
*
*/
public final class LocaleEditAlerts extends ListActivity {
// --- locale constants
/** key name for filter title in bundle */
public static final String KEY_FILTER_TITLE = "title";
/** key name for filter SQL in bundle */
public static final String KEY_SQL = "sql";
/** key name for filter content-values in bundle */
public static final String KEY_VALUES = "val";
/** key name for interval (integer, # of seconds) */
public static final String KEY_INTERVAL = "interval";
// --- activity constants
/**
* Indices for interval setting
*/
public static final int INTERVAL_ONE_HOUR = 0;
public static final int INTERVAL_SIX_HOURS = 1;
public static final int INTERVAL_TWELVE_HOURS = 2;
public static final int INTERVAL_ONE_DAY = 3;
public static final int INTERVAL_THREE_DAYS = 4;
public static final int INTERVAL_ONE_WEEK = 5;
/**
* Intervals in seconds
*/
public static final int[] INTERVALS = new int[] {
3600, 6 * 3600, 12 * 3600, 24 * 3600, 3 * 24 * 3600, 7 * 24 * 3600
};
/**
* Menu ID of the save item.
*/
private static final int MENU_SAVE = 1;
/**
* Menu ID of the don't save item.
*/
private static final int MENU_DONT_SAVE = 2;
// --- implementation
FilterAdapter adapter = null;
Spinner interval = null;
/**
* Flag boolean that can only be set to true via the "Don't Save" menu item in {@link #onMenuItemSelected(int, MenuItem)}. If
* true, then this {@code Activity} should return {@link Activity#RESULT_CANCELED} in {@link #finish()}.
* <p>
* There is no need to save/restore this field's state when the {@code Activity} is paused.
*/
private boolean isCancelled = false;
private boolean isRemoved = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme);
super.onCreate(savedInstanceState);
setContentView(R.layout.locale_edit_alerts);
ContextManager.setContext(this);
/*
* Locale guarantees that the breadcrumb string will be present, but checking for null anyway makes your Activity more
* robust and re-usable
*/
final String breadcrumbString = getIntent().getStringExtra(com.twofortyfouram.Intent.EXTRA_STRING_BREADCRUMB);
if (breadcrumbString != null) {
setTitle(String.format("%s%s%s", breadcrumbString, com.twofortyfouram.Intent.BREADCRUMB_SEPARATOR, //$NON-NLS-1$
getString(R.string.locale_edit_alerts_title)));
}
/*
* Load the Locale background frame from Locale
*/
// ((LinearLayout) findViewById(R.id.frame)).setBackgroundDrawable(
// SharedResources.getDrawableResource(getPackageManager(),
// SharedResources.DRAWABLE_LOCALE_BORDER));
// set up UI components
interval = (Spinner) findViewById(R.id.intervalSpinner);
interval.setSelection(INTERVAL_ONE_DAY);
String selectionToMatch = null;
try {
/*
* if savedInstanceState == null, then we are entering the Activity directly from Locale and we need to check whether the
* Intent has forwarded a Bundle extra (e.g. whether we editing an old setting or creating a new one)
*/
if (savedInstanceState == null)
{
final Bundle forwardedBundle = getIntent().getBundleExtra(com.twofortyfouram.Intent.EXTRA_BUNDLE);
/*
* the forwardedBundle would be null if this was a new setting
*/
if (forwardedBundle != null)
{
final int intervalValue = forwardedBundle.getInt(KEY_INTERVAL, INTERVALS[interval.getSelectedItemPosition()]);
for(int i = 0; i < INTERVALS.length; i++) {
if(intervalValue == INTERVALS[i]) {
interval.setSelection(i);
break;
}
}
selectionToMatch = forwardedBundle.getString(KEY_SQL);
}
}
} catch (Exception e) {
selectionToMatch = null;
Log.e("astrid-locale", "Error loading bundle", e); //$NON-NLS-1$ //$NON-NLS-2$
}
// if we match a selection, make it selected
final String finalSelection = selectionToMatch;
adapter = new FilterAdapter(this, getListView(), R.layout.filter_adapter_row, true) {
@Override
public void onReceiveFilter(FilterListItem item) {
if(adapter.getSelection() != null || finalSelection == null) {
return;
}
if(item instanceof Filter) {
if(finalSelection.equals(((Filter)item).getSqlQuery())) {
adapter.setSelection(item);
}
} else if(item instanceof FilterCategory) {
Filter[] filters = ((FilterCategory)item).children;
if(filters == null) {
return;
}
for(Filter filter : filters) {
if (finalSelection.equals(filter.getSqlQuery())) {
adapter.setSelection(filter);
break;
}
}
}
}
};
adapter.filterStyle = R.style.TextAppearance_LEA_Filter;
adapter.headerStyle = R.style.TextAppearance_LEA_Header;
setListAdapter(adapter);
// check for plugin
if(!PluginServices.getAddOnService().hasLocalePlugin()) {
isRemoved = true;
new AlertDialog.Builder(this)
.setTitle(R.string.DLG_information_title)
.setMessage(R.string.locale_plugin_required)
.setCancelable(false)
.setPositiveButton(android.R.string.ok,
AddOnActivity.createAddOnClicker(LocaleEditAlerts.this, true))
.show();
}
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
Filter item = adapter.getItem(position);
adapter.setSelection(item);
}
/**
* Called when the {@code Activity} is being terminated. This method determines the state of the {@code Activity} and what
* sort of result should be returned to <i>Locale</i>.
*/
@Override
public void finish()
{
if(isRemoved) {
setResult(com.twofortyfouram.Intent.RESULT_REMOVE);
} else if (isCancelled) {
setResult(RESULT_CANCELED);
} else
{
final FilterListItem selected = adapter.getSelection();
final int intervalIndex = interval.getSelectedItemPosition();
if (selected == null)
{
/*
* If nothing is selected, return as if user had canceled
*/
setResult(RESULT_CANCELED);
}
else
{
/*
* This is the return Intent, into which we'll put all the required extras
*/
final Intent returnIntent = new Intent();
/*
* This extra is the data to ourselves: either for the Activity or the BroadcastReceiver. Note that anything
* placed in this bundle must be available to Locale's class loader. So storing String, int, and other basic
* objects will work just fine. You cannot store an object that only exists in your project, as Locale will be
* unable to serialize it.
*/
final Bundle storeAndForwardExtras = new Bundle();
Filter filterItem = (Filter) selected;
storeAndForwardExtras.putString(KEY_FILTER_TITLE, filterItem.title);
storeAndForwardExtras.putString(KEY_SQL, filterItem.getSqlQuery());
if(filterItem.valuesForNewTasks != null) {
storeAndForwardExtras.putString(KEY_VALUES, AndroidUtilities.contentValuesToSerializedString(filterItem.valuesForNewTasks));
}
storeAndForwardExtras.putInt(KEY_INTERVAL, INTERVALS[intervalIndex]);
returnIntent.putExtra(com.twofortyfouram.Intent.EXTRA_BUNDLE, storeAndForwardExtras);
/*
* This is the blurb concisely describing what your setting's state is. This is simply used for display in the UI.
*/
if (filterItem.title != null && filterItem.title.length() > com.twofortyfouram.Intent.MAXIMUM_BLURB_LENGTH) {
returnIntent.putExtra(com.twofortyfouram.Intent.EXTRA_STRING_BLURB, filterItem.title.substring(0, com.twofortyfouram.Intent.MAXIMUM_BLURB_LENGTH));
} else {
returnIntent.putExtra(com.twofortyfouram.Intent.EXTRA_STRING_BLURB, filterItem.title);
}
setResult(RESULT_OK, returnIntent);
}
}
super.finish();
}
// --- boring stuff
@Override
protected void onResume() {
super.onResume();
adapter.registerRecevier();
}
@Override
protected void onPause() {
super.onPause();
adapter.unregisterRecevier();
}
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onStop() {
super.onStop();
}
/**
* {@inheritDoc}
*/
@Override
public boolean onCreateOptionsMenu(final Menu menu)
{
super.onCreateOptionsMenu(menu);
final PackageManager manager = getPackageManager();
/*
* We are dynamically loading resources from Locale's APK. This will only work if Locale is actually installed
*/
menu.add(0, MENU_DONT_SAVE, 0, SharedResources.getTextResource(manager, SharedResources.STRING_MENU_DONTSAVE))
.setIcon(SharedResources.getDrawableResource(manager, SharedResources.DRAWABLE_MENU_DONTSAVE)).getItemId();
menu.add(0, MENU_SAVE, 0, SharedResources.getTextResource(manager, SharedResources.STRING_MENU_SAVE))
.setIcon(SharedResources.getDrawableResource(manager, SharedResources.DRAWABLE_MENU_SAVE)).getItemId();
return true;
}
/**
* {@inheritDoc}
*/
@Override
public boolean onMenuItemSelected(final int featureId, final MenuItem item)
{
switch (item.getItemId())
{
case MENU_SAVE:
{
finish();
return true;
}
case MENU_DONT_SAVE:
{
isCancelled = true;
finish();
return true;
}
}
return super.onOptionsItemSelected(item);
}
}

@ -1,117 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.locale;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import org.tasks.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.Notifications;
import com.todoroo.astrid.utility.Constants;
/**
* Receiver is activated when Locale conditions are triggered
*
* @author timsu
*
*/
public class LocaleReceiver extends BroadcastReceiver {
/**
* Create a preference key for storing / retrieving last interval time
* @param filterTitle
* @param interval
* @return
*/
private String makePreferenceKey(String filterTitle, int interval) {
return "LOCALE:" + filterTitle + interval; //$NON-NLS-1$
}
@Override
/** Called when the system is started up */
public void onReceive(Context context, Intent intent) {
ContextManager.setContext(context);
try {
if (com.twofortyfouram.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
if(!PluginServices.getAddOnService().hasLocalePlugin()) {
return;
}
final Bundle forwardedBundle = intent.getBundleExtra(com.twofortyfouram.Intent.EXTRA_BUNDLE);
final String title = forwardedBundle.getString(LocaleEditAlerts.KEY_FILTER_TITLE);
final String sql = forwardedBundle.getString(LocaleEditAlerts.KEY_SQL);
final String values = forwardedBundle.getString(LocaleEditAlerts.KEY_VALUES);
final int interval = forwardedBundle.getInt(LocaleEditAlerts.KEY_INTERVAL, 24*3600);
if(TextUtils.isEmpty(title) || TextUtils.isEmpty(sql) ||
sql.contains("--") || sql.contains(";") || interval == 0) {
return;
}
// check if we've already made a notification recently
String preferenceKey = makePreferenceKey(title, interval);
long lastNotifyTime = Preferences.getLong(preferenceKey, 0);
if(DateUtilities.now() - lastNotifyTime < interval * 1000L) {
Log.i("astrid-locale-rx", title + ": Too soon, need " + (interval
- (DateUtilities.now() - lastNotifyTime)/1000) + " more seconds");
return;
}
// find out if we have active tasks with this tag
DependencyInjectionService.getInstance().inject(this);
Filter filter = new Filter(title, title, sql, null);
TodorooCursor<Task> cursor = PluginServices.getTaskService().fetchFiltered(
sql, null, Task.ID);
try {
if(cursor.getCount() == 0) {
return;
}
if(values != null) {
filter.valuesForNewTasks = AndroidUtilities.contentValuesFromSerializedString(values);
}
Resources r = context.getResources();
String reminder = r.getString(R.string.locale_notification).
replace("$NUM", r.getQuantityString(R.plurals.Ntasks,
cursor.getCount(), cursor.getCount())).
replace("$FILTER", title);
// show a reminder
String notificationTitle = r.getString(R.string.locale_edit_alerts_title);
Intent notifyIntent = ShortcutActivity.createIntent(filter);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Notifications.showNotification(Constants.NOTIFICATION_LOCALE,
notifyIntent, 0, notificationTitle, reminder, 1);
Preferences.setLong(preferenceKey, DateUtilities.now());
} finally {
cursor.close();
}
}
} catch (Exception e) {
Log.i("astrid-locale-rx", "Error receiving intent", e);
}
}
}

@ -5,13 +5,8 @@
*/ */
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.util.ArrayList;
import android.content.Context; import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import org.tasks.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
@ -32,24 +27,11 @@ public class AddOnService {
/** Astrid Power Pack package */ /** Astrid Power Pack package */
public static final String POWER_PACK_PACKAGE = "com.todoroo.astrid.ppack"; public static final String POWER_PACK_PACKAGE = "com.todoroo.astrid.ppack";
/** Astrid Locale package */
public static final String LOCALE_PACKAGE = "com.todoroo.astrid.locale";
/** Checks whether power pack should be enabled */ /** Checks whether power pack should be enabled */
public boolean hasPowerPack() { public boolean hasPowerPack() {
return true; return true;
} }
/** Checks whether locale plugin should be enabled */
public boolean hasLocalePlugin() {
if (Preferences.getBoolean(PREF_OEM, false)) {
return true;
} else if(isInstalled(LOCALE_PACKAGE, true)) {
return true;
}
return false;
}
/** /**
* Record that a version was an OEM install * Record that a version was an OEM install
*/ */
@ -132,19 +114,7 @@ public class AddOnService {
* @return available add-ons * @return available add-ons
*/ */
public AddOn[] getAddOns() { public AddOn[] getAddOns() {
Resources r = ContextManager.getContext().getResources(); return new AddOn[0];
// temporary temporary
ArrayList<AddOn> list = new ArrayList<AddOn>(3);
if(Constants.MARKET_STRATEGY.includesLocalePlugin()) {
list.add(new AddOn(false, true, r.getString(R.string.AOA_locale_title), null,
r.getString(R.string.AOA_locale_description),
LOCALE_PACKAGE,
((BitmapDrawable) r.getDrawable(R.drawable.icon_locale)).getBitmap()));
}
return list.toArray(new AddOn[list.size()]);
} }
} }

@ -20,13 +20,6 @@ public abstract class MarketStrategy {
abstract public String strategyId(); abstract public String strategyId();
/**
* @return if this market has locale plugin
*/
public boolean includesLocalePlugin() {
return true;
}
public int[] excludedSettings() { public int[] excludedSettings() {
return null; return null;
} }
@ -98,11 +91,6 @@ public abstract class MarketStrategy {
packageName)); packageName));
} }
@Override
public boolean includesLocalePlugin() {
return false;
}
/** /**
* @return true if the device is a kindle fire and needs special treatment * @return true if the device is a kindle fire and needs special treatment
*/ */
@ -136,11 +124,6 @@ public abstract class MarketStrategy {
packageName)); packageName));
} }
@Override
public boolean includesLocalePlugin() {
return false;
}
@Override @Override
public boolean allowIdeasTab() { public boolean allowIdeasTab() {
return false; return false;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

@ -1,63 +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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/Content">
<!-- At runtime, we'll load the Locale background frame -->
<LinearLayout
android:id="@+id/frame"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10px"
android:gravity="center"
android:text="@string/locale_edit_intro"
style="@style/TextAppearance" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:layout_margin="10px"
android:background="@drawable/locale_border">
<com.todoroo.astrid.ui.ErrorCatchingListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="@android:color/black"
android:cacheColorHint="@android:color/black"/>
</FrameLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="@string/locale_interval_label"
style="@style/TextAppearance" />
<Spinner android:id="@+id/intervalSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dip"
android:entries="@array/locale_interval" />
</LinearLayout>
</LinearLayout>

@ -663,9 +663,6 @@
<!-- Add-on Activity - when list is empty --> <!-- Add-on Activity - when list is empty -->
<string name="AOA_no_addons">Empty List!</string> <string name="AOA_no_addons">Empty List!</string>
<string name="AOA_locale_title">Tasks Locale Plugin</string>
<string name="AOA_locale_description">Allows Tasks to make use of the Locale application to send you notifications based on filter conditions. Requires Locale.</string>
<!-- ====================================================== TasksWidget == --> <!-- ====================================================== TasksWidget == -->
<!-- Widget text when loading tasks --> <!-- Widget text when loading tasks -->

@ -1,34 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Resources for built-in locale plug-in --> <!-- Locale Notification text -->
<!-- Locale Alert Editing Window Title -->
<string name="locale_edit_alerts_title">Tasks Filter Alert</string>
<!-- Locale Window Help -->
<string name="locale_edit_intro">Tasks will send you a reminder
when you have any tasks in the following filter:</string>
<!-- Locale Window Filter Picker UI -->
<!-- Locale Window Interval Label -->
<string name="locale_interval_label">Limit notifications to:</string>
<!-- Locale Window Interval Values -->
<string-array name="locale_interval">
<item>once an hour</item>
<item>once every six hours</item>
<item>once every twelve hours</item>
<item>once a day</item>
<item>once every three days</item>
<item>once a week</item>
</string-array>
<!-- Locale Notification text -->
<string name="locale_notification">You have $NUM matching: $FILTER</string> <string name="locale_notification">You have $NUM matching: $FILTER</string>
<!-- Locale Plugin was not found, it is required -->
<string name="locale_plugin_required">Please install the Tasks Locale plugin!</string>
</resources> </resources>

@ -1,31 +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.
-->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Resources for built-in locale plug-in -->
<style name="TextAppearance.Locale_Label">
<item name="android:textSize">16sp</item>
<item name="android:textColor">@android:color/black</item>
</style>
<!-- Locale filter list styles -->
<style name="TextAppearance.LEA_Filter">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="TextAppearance.LEA_Header" parent="TextAppearance.LEA_Filter">
<item name="android:textSize">13sp</item>
<item name="android:textColor">#ffdddddd</item>
</style>
<style name="TextAppearance.LEA_Category" parent="TextAppearance.LEA_Filter">
<item name="android:textSize">13sp</item>
<item name="android:textStyle">bold|italic</item>
</style>
</resources>
Loading…
Cancel
Save