- * 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 Locale.
- */
- @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);
- }
-
-}
diff --git a/astrid/src/main/java/com/todoroo/astrid/locale/LocaleReceiver.java b/astrid/src/main/java/com/todoroo/astrid/locale/LocaleReceiver.java
deleted file mode 100644
index 1c8d270f7..000000000
--- a/astrid/src/main/java/com/todoroo/astrid/locale/LocaleReceiver.java
+++ /dev/null
@@ -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