shortcuttable filter

pull/14/head
Tim Su 14 years ago
parent 75d5cc5819
commit 2e08637958

@ -3,11 +3,12 @@
*/
package com.todoroo.astrid.gtasks;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.AbstractModel;
@ -58,13 +59,9 @@ public class GtasksFilterExposer extends BroadcastReceiver {
GtasksMetadata.LIST_ID.eq(list.getValue(GtasksList.REMOTE_ID)))).orderBy(
Order.asc(Functions.cast(GtasksMetadata.ORDER, "INTEGER"))), //$NON-NLS-1$
values);
Intent intent = new Intent(ContextManager.getContext(), GtasksListActivity.class);
intent.putExtra(GtasksListActivity.TOKEN_LIST_ID, list.getValue(GtasksList.REMOTE_ID));
intent.putExtra(GtasksListActivity.TOKEN_FILTER, filter);
intent.setType(list.getValue(GtasksList.REMOTE_ID));
PendingIntent pendingIntent = PendingIntent.getActivity(ContextManager.getContext(),
0, intent, 0);
filter.intent = pendingIntent;
filter.customTaskList = new ComponentName(ContextManager.getContext(), GtasksListActivity.class);
filter.customExtras = new Bundle();
filter.customExtras.putString(GtasksListActivity.TOKEN_LIST_ID, list.getValue(GtasksList.REMOTE_ID));
return filter;
}

@ -203,15 +203,13 @@ public class FilterListActivity extends ExpandableListActivity {
protected boolean onItemClicked(FilterListItem item) {
if(item instanceof Filter) {
Filter filter = (Filter)item;
Intent intent = new Intent(FilterListActivity.this, TaskListActivity.class);
intent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
if(filter instanceof FilterWithCustomIntent) {
try {
((FilterWithCustomIntent)filter).intent.send();
} catch (CanceledException e) {
// we won't do anything in this case
}
FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter);
intent.setComponent(customFilter.customTaskList);
intent.getExtras().putAll(customFilter.customExtras);
} else {
Intent intent = new Intent(FilterListActivity.this, TaskListActivity.class);
intent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
startActivity(intent);
}
AndroidUtilities.callApiMethod(5, this, "overridePendingTransition", //$NON-NLS-1$

@ -22,8 +22,7 @@ package com.todoroo.astrid.activity;
import java.util.Map.Entry;
import android.app.Activity;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
@ -64,7 +63,7 @@ public class ShortcutActivity extends Activity {
public static final String TOKEN_FILTER_VALUES_ITEM = "v4ntp_"; //$NON-NLS-1$
/** token for passing a PendingIntent to launch */
public static final String TOKEN_PENDING_INTENT = "pintent"; //$NON-NLS-1$
public static final String TOKEN_CUSTOM_CLASS = "class"; //$NON-NLS-1$
// --- implementation
@ -85,13 +84,10 @@ public class ShortcutActivity extends Activity {
private void launchTaskList(Intent intent) {
Bundle extras = intent.getExtras();
if(extras != null && extras.containsKey(TOKEN_PENDING_INTENT)) {
PendingIntent pending = extras.getParcelable(TOKEN_PENDING_INTENT);
try {
pending.send();
} catch (CanceledException e) {
// ignore it
}
Intent taskListIntent = new Intent(this, TaskListActivity.class);
if(extras != null && extras.containsKey(TOKEN_CUSTOM_CLASS)) {
taskListIntent.setComponent(ComponentName.unflattenFromString(extras.getString(TOKEN_CUSTOM_CLASS)));
} else if(extras != null && extras.containsKey(TOKEN_FILTER_SQL)) {
// launched from desktop shortcut, must create a fake filter
String title = extras.getString(TOKEN_FILTER_TITLE);
@ -123,19 +119,18 @@ public class ShortcutActivity extends Activity {
}
Filter filter = new Filter("", title, sql, values); //$NON-NLS-1$
Intent taskListIntent = new Intent(this, TaskListActivity.class);
taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
startActivity(taskListIntent);
} else if(extras != null && extras.containsKey(TOKEN_SINGLE_TASK)) {
Filter filter = new Filter("", getString(R.string.TLA_custom), //$NON-NLS-1$
new QueryTemplate().where(Task.ID.eq(extras.getLong(TOKEN_SINGLE_TASK, -1))), null);
Intent taskListIntent = new Intent(this, TaskListActivity.class);
taskListIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
taskListIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
startActivity(taskListIntent);
}
startActivity(taskListIntent);
finish();
}
@ -143,9 +138,11 @@ public class ShortcutActivity extends Activity {
Intent shortcutIntent = new Intent(ContextManager.getContext(),
ShortcutActivity.class);
if(filter instanceof FilterWithCustomIntent)
shortcutIntent.putExtra(ShortcutActivity.TOKEN_PENDING_INTENT,
((FilterWithCustomIntent)filter).intent);
if(filter instanceof FilterWithCustomIntent) {
FilterWithCustomIntent customFilter = ((FilterWithCustomIntent)filter);
shortcutIntent.getExtras().putAll(customFilter.customExtras);
shortcutIntent.putExtra(TOKEN_CUSTOM_CLASS, customFilter.customTaskList.flattenToString());
}
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE,

@ -1,8 +1,8 @@
package com.todoroo.astrid.api;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@ -10,7 +10,8 @@ import com.todoroo.andlib.sql.QueryTemplate;
public class FilterWithCustomIntent extends Filter {
public PendingIntent intent = null;
public ComponentName customTaskList = null;
public Bundle customExtras = null;
protected FilterWithCustomIntent() {
super();
@ -43,13 +44,15 @@ public class FilterWithCustomIntent extends Filter {
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(intent, 0);
dest.writeParcelable(customTaskList, 0);
dest.writeParcelable(customExtras, 0);
}
@Override
public void readFromParcel(Parcel source) {
super.readFromParcel(source);
intent = source.readParcelable(Intent.class.getClassLoader());
customTaskList = source.readParcelable(ComponentName.class.getClassLoader());
customExtras = source.readParcelable(Bundle.class.getClassLoader());
}
/**

Loading…
Cancel
Save