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.NetworkInfo;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent;
@ -160,6 +161,8 @@ public class AndroidUtilities {
value.getClass());
}
// --- serialization
/**
* 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) {
StringBuilder result = new StringBuilder();
for(Entry<String, Object> entry : source.valueSet()) {
result.append(entry.getKey().replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)).append(
SERIALIZATION_SEPARATOR);
Object value = entry.getValue();
if(value instanceof Integer)
result.append('i').append(value);
else if(value instanceof Double)
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());
else
throw new UnsupportedOperationException(value.getClass().toString());
result.append(SERIALIZATION_SEPARATOR);
addSerialized(result, entry.getKey(), entry.getValue());
}
return result.toString();
}
/** add serialized helper */
private static void addSerialized(StringBuilder result,
String key, Object value) {
result.append(key.replace(SERIALIZATION_SEPARATOR, SEPARATOR_ESCAPE)).append(
SERIALIZATION_SEPARATOR);
if(value instanceof Integer)
result.append('i').append(value);
else if(value instanceof Double)
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();
}
@ -219,34 +238,80 @@ public class AndroidUtilities {
if(string == null)
return new ContentValues();
String[] pairs = string.split("\\" + SERIALIZATION_SEPARATOR); //$NON-NLS-1$
ContentValues result = new ContentValues();
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 {
switch(pairs[i+1].charAt(0)) {
fromSerialized(string, result, new SerializedPut<ContentValues>() {
public void put(ContentValues object, String key, char type, String value) throws NumberFormatException {
switch(type) {
case 'i':
result.put(key, Integer.parseInt(value));
object.put(key, Integer.parseInt(value));
break;
case 'd':
result.put(key, Double.parseDouble(value));
object.put(key, Double.parseDouble(value));
break;
case 'l':
result.put(key, Long.parseLong(value));
object.put(key, Long.parseLong(value));
break;
case 's':
result.put(key, value.replace(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR));
object.put(key, value.replace(SEPARATOR_ESCAPE, SERIALIZATION_SEPARATOR));
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) {
// failed parse to number, try to put a string
result.put(key, value);
// failed parse to number
putter.put(object, key, 's', value);
}
}
return result;
}
/**
* Turn ContentValues into a string
* @param string

@ -315,7 +315,12 @@
</receiver>
<activity android:name="com.todoroo.astrid.actfm.TagViewActivity"
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">
<intent-filter>
<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)) {
tabHost.setCurrentTab(savedInstanceState.getInt(TAB_IN_PROGRESS));
}
System.err.println("hey my intent is " + getIntent().getExtras());
onNewIntent(getIntent());
}
/* (non-Javadoc)

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

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.IBinder;
import android.util.DisplayMetrics;
import android.util.Log;
@ -204,14 +205,21 @@ public class TasksWidget extends AppWidgetProvider {
updateForScreenSize(views);
Intent listIntent = new Intent(context, TaskListActivity.class);
listIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
if(filter != null) {
listIntent.putExtra(TaskListActivity.TOKEN_FILTER, filter);
listIntent.setType(filter.sqlQuery);
String customIntent = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_INTENT
+ widgetId);
if(customIntent != null) {
listIntent.setComponent(ComponentName.unflattenFromString(customIntent));
String serializedExtras = Preferences.getStringValue(WidgetConfigActivity.PREF_CUSTOM_EXTRAS
+ widgetId);
Bundle extras = AndroidUtilities.bundleFromSerializedString(serializedExtras);
listIntent.putExtras(extras);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
listIntent, 0);
listIntent.putExtra(TaskListActivity.TOKEN_SOURCE, Constants.SOURCE_WIDGET);
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);
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.FilterCategory;
import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.service.StatisticsConstants;
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_SQL = "widget-sql-";
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;
@ -161,6 +163,15 @@ abstract public class WidgetConfigActivity extends ExpandableListActivity {
Preferences.setString(WidgetConfigActivity.PREF_TITLE + mAppWidgetId, title);
Preferences.setString(WidgetConfigActivity.PREF_SQL + mAppWidgetId, sql);
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