Fix for AST-148: filter shortcuts that are two words cause crash

pull/14/head
Tim Su 14 years ago
parent 28b44894cd
commit be1ef4decc

@ -23,8 +23,8 @@ import android.text.InputType;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.widget.TextView;
import com.todoroo.andlib.service.Autowired;
@ -193,7 +193,7 @@ public class AndroidUtilities {
if(string == null)
return null;
String[] pairs = string.split(" ");
String[] pairs = string.split("=");
ContentValues result = new ContentValues();
for(String item : pairs) {
String[] keyValue = item.split("=");

@ -15,19 +15,19 @@ import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.TextView.OnEditorActionListener;
import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R;
@ -251,7 +251,6 @@ public class FilterListActivity extends ExpandableListActivity {
if(item instanceof Filter) {
Filter filter = (Filter) item;
info.targetView.setTag(filter);
menuItem = menu.add(0, CONTEXT_MENU_SHORTCUT, 0, R.string.FLA_context_shortcut);
menuItem.setIntent(ShortcutActivity.createIntent(filter));
}
@ -295,13 +294,9 @@ public class FilterListActivity extends ExpandableListActivity {
bitmap.getWidth(), bitmap.getHeight()), null);
Intent createShortcutIntent = new Intent();
createShortcutIntent.putExtra(
Intent.EXTRA_SHORTCUT_INTENT,
shortcutIntent);
createShortcutIntent.putExtra(
Intent.EXTRA_SHORTCUT_NAME, label);
createShortcutIntent.putExtra(
Intent.EXTRA_SHORTCUT_ICON, bitmap);
createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
createShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //$NON-NLS-1$
sendBroadcast(createShortcutIntent);
@ -331,49 +326,9 @@ public class FilterListActivity extends ExpandableListActivity {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)item.getMenuInfo();
final Intent shortcutIntent = item.getIntent();
final Filter filter = (Filter)info.targetView.getTag();
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setPadding(10, 0, 10, 0);
final EditText editText = new EditText(this);
if(filter.listingTitle == null)
filter.listingTitle = ""; //$NON-NLS-1$
editText.setText(filter.listingTitle.
replaceAll("\\(\\d+\\)$", "").trim()); //$NON-NLS-1$ //$NON-NLS-2$
frameLayout.addView(editText, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
final Runnable createShortcut = new Runnable() {
@Override
public void run() {
String label = editText.getText().toString();
createShortcut(filter, shortcutIntent, label);
}
};
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL) {
createShortcut.run();
return true;
}
return false;
}
});
new AlertDialog.Builder(this)
.setTitle(R.string.FLA_shortcut_dialog_title)
.setMessage(R.string.FLA_shortcut_dialog)
.setView(frameLayout)
.setIcon(android.R.drawable.ic_dialog_info)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
createShortcut.run();
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
FilterListItem filter = ((FilterAdapter.ViewHolder)info.targetView.getTag()).item;
if(filter instanceof Filter)
showCreateShortcutDialog(shortcutIntent, (Filter)filter);
return true;
}
@ -388,4 +343,49 @@ public class FilterListActivity extends ExpandableListActivity {
return false;
}
private void showCreateShortcutDialog(final Intent shortcutIntent,
final Filter filter) {
FrameLayout frameLayout = new FrameLayout(this);
frameLayout.setPadding(10, 0, 10, 0);
final EditText editText = new EditText(this);
if(filter.listingTitle == null)
filter.listingTitle = ""; //$NON-NLS-1$
editText.setText(filter.listingTitle.
replaceAll("\\(\\d+\\)$", "").trim()); //$NON-NLS-1$ //$NON-NLS-2$
frameLayout.addView(editText, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
final Runnable createShortcut = new Runnable() {
@Override
public void run() {
String label = editText.getText().toString();
createShortcut(filter, shortcutIntent, label);
}
};
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL) {
createShortcut.run();
return true;
}
return false;
}
});
new AlertDialog.Builder(this)
.setTitle(R.string.FLA_shortcut_dialog_title)
.setMessage(R.string.FLA_shortcut_dialog)
.setView(frameLayout)
.setIcon(android.R.drawable.ic_dialog_info)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
createShortcut.run();
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
}

@ -19,6 +19,8 @@
*/
package com.todoroo.astrid.activity;
import java.util.Map.Entry;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
@ -46,14 +48,13 @@ public class ShortcutActivity extends Activity {
/** token for passing a {@link Filter}'s sql through extras */
public static final String TOKEN_FILTER_SQL = "sql"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras */
/** token for passing a {@link Filter}'s values for new tasks through extras as string */
@Deprecated
public static final String TOKEN_FILTER_VALUES = "v4nt"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras (keys) */
public static final String TOKEN_FILTER_VALUES_KEYS = "v4ntk"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras as exploded ContentValues */
public static final String TOKEN_FILTER_VALUES_ITEM = "v4ntp_"; //$NON-NLS-1$
/** token for passing a {@link Filter}'s values for new tasks through extras (values) */
public static final String TOKEN_FILTER_VALUES_VALUES = "v4ntv"; //$NON-NLS-1$
// --- implementation
@ -81,6 +82,28 @@ public class ShortcutActivity extends Activity {
ContentValues values = null;
if(extras.containsKey(TOKEN_FILTER_VALUES))
values = AndroidUtilities.contentValuesFromString(extras.getString(TOKEN_FILTER_VALUES));
else {
values = new ContentValues();
for(String key : extras.keySet()) {
if(!key.startsWith(TOKEN_FILTER_VALUES_ITEM))
continue;
Object value = extras.get(key);
key = key.substring(TOKEN_FILTER_VALUES_ITEM.length());
// assume one of the big 4...
if(value instanceof String)
values.put(key, (String) value);
else if(value instanceof Integer)
values.put(key, (Integer) value);
else if(value instanceof Double)
values.put(key, (Double) value);
else if(value instanceof Long)
values.put(key, (Long) value);
else
throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
}
}
Filter filter = new Filter("", title, new QueryTemplate(), values); //$NON-NLS-1$
filter.sqlQuery = sql;
@ -95,12 +118,26 @@ public class ShortcutActivity extends Activity {
public static Intent createIntent(Filter filter) {
Intent shortcutIntent = new Intent(ContextManager.getContext(),
ShortcutActivity.class);
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.setAction(Intent.ACTION_VIEW);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_TITLE, filter.title);
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_SQL, filter.sqlQuery);
if(filter.valuesForNewTasks != null) {
shortcutIntent.putExtra(ShortcutActivity.TOKEN_FILTER_VALUES,
filter.valuesForNewTasks.toString());
for(Entry<String, Object> item : filter.valuesForNewTasks.valueSet()) {
String key = TOKEN_FILTER_VALUES_ITEM + item.getKey();
Object value = item.getValue();
// assume one of the big 4...
if(value instanceof String)
shortcutIntent.putExtra(key, (String) value);
else if(value instanceof Integer)
shortcutIntent.putExtra(key, (Integer) value);
else if(value instanceof Double)
shortcutIntent.putExtra(key, (Double) value);
else if(value instanceof Long)
shortcutIntent.putExtra(key, (Long) value);
else
throw new IllegalStateException("Unsupported bundle type " + value.getClass()); //$NON-NLS-1$
}
}
return shortcutIntent;
}

@ -95,7 +95,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
return convertView;
}
private static class ViewHolder {
public static class ViewHolder {
public FilterListItem item;
public ImageView expander;
public ImageView icon;
@ -132,11 +132,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
Object item = getChild(groupPosition, childPosition);
if(!(item instanceof FilterListItem))
return convertView;
viewHolder.item = (FilterListItem) item;
viewHolder.item = (FilterListItem) getChild(groupPosition, childPosition);
populateView(viewHolder, true, false);
return convertView;
@ -162,11 +158,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
ViewGroup parent) {
convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
Object groupItem = getGroup(groupPosition);
if(!(groupItem instanceof FilterListItem))
return convertView;
viewHolder.item = (FilterListItem) groupItem;
viewHolder.item = (FilterListItem) getGroup(groupPosition);
populateView(viewHolder, false, isExpanded);
return convertView;
}

Loading…
Cancel
Save