Fixed bug with tag widgets not launching tag view activity

pull/14/head
Sam Bosley 13 years ago
parent c8bf0dc866
commit 32b865d86f

@ -31,6 +31,7 @@ import android.graphics.BitmapFactory;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.NetworkInfo.State; import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -160,6 +161,8 @@ public class AndroidUtilities {
value.getClass()); value.getClass());
} }
// --- serialization
/** /**
* Rips apart a content value into two string arrays, keys and value * Rips apart a content value into two string arrays, keys and value
*/ */
@ -192,20 +195,36 @@ public class AndroidUtilities {
public static String contentValuesToSerializedString(ContentValues source) { public static String contentValuesToSerializedString(ContentValues source) {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
for(Entry<String, Object> entry : source.valueSet()) { for(Entry<String, Object> entry : source.valueSet()) {
result.append(entry.getKey().replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)).append( addSerialized(result, entry.getKey(), entry.getValue());
SERIALIZATION_SEPARATOR); }
Object value = entry.getValue(); return result.toString();
if(value instanceof Integer) }
result.append('i').append(value);
else if(value instanceof Double) /** add serialized helper */
result.append('d').append(value); private static void addSerialized(StringBuilder result,
else if(value instanceof Long) String key, Object value) {
result.append('l').append(value); result.append(key.replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)).append(
else if(value instanceof String) SERIALIZATION_SEPARATOR);
result.append('s').append(value.toString()); if(value instanceof Integer)
else result.append('i').append(value);
throw new UnsupportedOperationException(value.getClass().toString()); else if(value instanceof Double)
result.append(SERIALIZATION_SEPARATOR); result.append('d').append(value);
else if(value instanceof Long)
result.append('l').append(value);
else if(value instanceof String)
result.append('s').append(value.toString().replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE));
else
throw new UnsupportedOperationException(value.getClass().toString());
result.append(SERIALIZATION_SEPARATOR);
}
/**
* Serializes a {@link android.os.Bundle} into a string
*/
public static String bundleToSerializedString(Bundle source) {
StringBuilder result = new StringBuilder();
for(String key : source.keySet()) {
addSerialized(result, key, source.get(key));
} }
return result.toString(); return result.toString();
} }
@ -219,34 +238,80 @@ public class AndroidUtilities {
if(string == null) if(string == null)
return new ContentValues(); return new ContentValues();
String[] pairs = string.split("\\" + SERIALIZATION_SEPARATOR); //$NON-NLS-1$
ContentValues result = new ContentValues(); ContentValues result = new ContentValues();
for(int i = 0; i < pairs.length; i += 2) { fromSerialized(string, result, new SerializedPut<ContentValues>() {
String key = pairs[i].replaceAll(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR); public void put(ContentValues object, String key, char type, String value) throws NumberFormatException {
String value = pairs[i+1].substring(1); switch(type) {
try {
switch(pairs[i+1].charAt(0)) {
case 'i': case 'i':
result.put(key, Integer.parseInt(value)); object.put(key, Integer.parseInt(value));
break; break;
case 'd': case 'd':
result.put(key, Double.parseDouble(value)); object.put(key, Double.parseDouble(value));
break; break;
case 'l': case 'l':
result.put(key, Long.parseLong(value)); object.put(key, Long.parseLong(value));
break; break;
case 's': case 's':
result.put(key, value.replace(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR)); object.put(key, value.replace(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR));
break; break;
} }
}
});
return result;
}
/**
* Turn {@link android.os.Bundle} into a string
* @param string
* @return
*/
public static Bundle bundleFromSerializedString(String string) {
if(string == null)
return new Bundle();
Bundle result = new Bundle();
fromSerialized(string, result, new SerializedPut<Bundle>() {
public void put(Bundle object, String key, char type, String value) throws NumberFormatException {
switch(type) {
case 'i':
object.putInt(key, Integer.parseInt(value));
break;
case 'd':
object.putDouble(key, Double.parseDouble(value));
break;
case 'l':
object.putLong(key, Long.parseLong(value));
break;
case 's':
object.putString(key, value.replace(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR));
break;
}
}
});
return result;
}
public interface SerializedPut<T> {
public void put(T object, String key, char type, String value) throws NumberFormatException;
}
private static <T> void fromSerialized(String string, T object, SerializedPut<T> putter) {
String[] pairs = string.split("\\" + SERIALIZATION_SEPARATOR); //$NON-NLS-1$
for(int i = 0; i < pairs.length; i += 2) {
String key = pairs[i].replaceAll(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR);
String value = pairs[i+1].substring(1);
try {
putter.put(object, key, pairs[i+1].charAt(0), value);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// failed parse to number, try to put a string // failed parse to number
result.put(key, value); putter.put(object, key, 's', value);
} }
} }
return result;
} }
/** /**
* Turn ContentValues into a string * Turn ContentValues into a string
* @param string * @param string

@ -315,7 +315,12 @@
</receiver> </receiver>
<activity android:name="com.todoroo.astrid.actfm.TagViewActivity" <activity android:name="com.todoroo.astrid.actfm.TagViewActivity"
android:windowSoftInputMode="stateHidden" android:windowSoftInputMode="stateHidden"
android:theme="@style/Theme" /> android:theme="@style/Theme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="com.todoroo.astrid.actfm.EditPeopleExposer"> <receiver android:name="com.todoroo.astrid.actfm.EditPeopleExposer">
<intent-filter> <intent-filter>
<action android:name="com.todoroo.astrid.REQUEST_ACTIONS" /> <action android:name="com.todoroo.astrid.REQUEST_ACTIONS" />

@ -168,6 +168,10 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
if(savedInstanceState != null && savedInstanceState.containsKey(TAB_IN_PROGRESS)) { if(savedInstanceState != null && savedInstanceState.containsKey(TAB_IN_PROGRESS)) {
tabHost.setCurrentTab(savedInstanceState.getInt(TAB_IN_PROGRESS)); tabHost.setCurrentTab(savedInstanceState.getInt(TAB_IN_PROGRESS));
} }
System.err.println("hey my intent is " + getIntent().getExtras());
onNewIntent(getIntent());
} }
/* (non-Javadoc) /* (non-Javadoc)

@ -30,6 +30,7 @@ import android.graphics.PixelFormat;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -224,12 +225,17 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
parent.addView(getListBody(parent), 1); parent.addView(getListBody(parent), 1);
setContentView(parent); setContentView(parent);
System.err.println("is the database null? " + database + " and " + taskService);
if(database == null) if(database == null)
return; return;
database.openForWriting(); database.openForWriting();
System.err.println("i'm here, son!");
setUpUiComponents(); setUpUiComponents();
System.err.println("i'm here, son! # 2");
onNewIntent(getIntent()); onNewIntent(getIntent());
System.err.println("i'm here, son! # 3");
if(Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1) if(Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1)
upgradeService.showChangeLog(this, Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1)); upgradeService.showChangeLog(this, Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
@ -264,6 +270,8 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
Log.w("funky", "new intent - ", new Throwable());
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
String intentAction = intent.getAction(); String intentAction = intent.getAction();
if (Intent.ACTION_SEARCH.equals(intentAction)) { if (Intent.ACTION_SEARCH.equals(intentAction)) {
@ -279,6 +287,7 @@ public class TaskListActivity extends ListActivity implements OnScrollListener,
return; return;
} else if(extras != null && extras.containsKey(TOKEN_FILTER)) { } else if(extras != null && extras.containsKey(TOKEN_FILTER)) {
filter = extras.getParcelable(TOKEN_FILTER); filter = extras.getParcelable(TOKEN_FILTER);
System.err.println("/FILTER: " + filter.sqlQuery);
isInbox = true; isInbox = true;
} else { } else {
filter = CoreFilterExposer.buildInboxFilter(getResources()); filter = CoreFilterExposer.buildInboxFilter(getResources());

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
@ -204,14 +205,21 @@ public class TasksWidget extends AppWidgetProvider {
updateForScreenSize(views); updateForScreenSize(views);
Intent listIntent = new Intent(context, TaskListActivity.class); Intent listIntent = new Intent(context, TaskListActivity.class);
listIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); String customIntent = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET); + widgetId);
if(filter != null) { if(customIntent != null) {
listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter); listIntent.setComponent(ComponentName.unflattenFromString(customIntent));
listIntent.setType(filter.sqlQuery); String serializedExtras = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
+ widgetId);
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
listIntent.putExtras(extras);
} }
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
listIntent, 0); listIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
listIntent.setAction("L" + widgetId + filter.sqlQuery);
PendingIntent pendingIntent = PendingIntent.getActivity(context, widgetId,
listIntent, PendingIntent.FLAG_CANCEL_CURRENT);
views.setOnClickPendingIntent(R.id.taskbody, pendingIntent); views.setOnClickPendingIntent(R.id.taskbody, pendingIntent);
Intent editIntent = new Intent(context, TaskEditActivity.class); Intent editIntent = new Intent(context, TaskEditActivity.class);

@ -17,6 +17,7 @@ import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterCategory; import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
@ -26,7 +27,8 @@ abstract public class WidgetConfigActivity extends ExpandableListActivity {
static final String PREF_TITLE = "widget-title-"; static final String PREF_TITLE = "widget-title-";
static final String PREF_SQL = "widget-sql-"; static final String PREF_SQL = "widget-sql-";
static final String PREF_VALUES = "widget-values-"; static final String PREF_VALUES = "widget-values-";
static final String PREF_CUSTOM_INTENT = "widget-intent-";
static final String PREF_CUSTOM_EXTRAS = "widget-extras-";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
@ -161,6 +163,15 @@ abstract public class WidgetConfigActivity extends ExpandableListActivity {
Preferences.setString(WidgetConfigActivity.PREF_TITLE + mAppWidgetId, title); Preferences.setString(WidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(WidgetConfigActivity.PREF_SQL + mAppWidgetId, sql); Preferences.setString(WidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
Preferences.setString(WidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString); Preferences.setString(WidgetConfigActivity.PREF_VALUES + mAppWidgetId, contentValuesString);
if(filterListItem instanceof FilterWithCustomIntent) {
String flattenedName = ((FilterWithCustomIntent)filterListItem).customTaskList.flattenToString();
Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_INTENT + mAppWidgetId,
flattenedName);
String flattenedExtras = AndroidUtilities.bundleToSerializedString(((FilterWithCustomIntent)filterListItem).customExtras);
Preferences.setString(WidgetConfigActivity.PREF_CUSTOM_EXTRAS + mAppWidgetId,
flattenedExtras);
}
} }
} }

Loading…
Cancel
Save