Add ability to add shortcut from list settings page

pull/14/head
Sam Bosley 13 years ago
parent 99b057243a
commit b70f7fd1a3

@ -37,6 +37,9 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.FilterListFragment;
import com.todoroo.astrid.activity.ShortcutActivity;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
@ -60,6 +63,7 @@ public class TagSettingsActivity extends FragmentActivity {
private static final String MEMBERS_IN_PROGRESS = "members"; //$NON-NLS-1$
private TagData tagData;
private Filter filter; // Used for creating shortcuts, only initialized if necessary
@Autowired TagDataService tagDataService;
@ -173,6 +177,20 @@ public class TagSettingsActivity extends FragmentActivity {
}
});
if (isNewTag) {
findViewById(R.id.create_shortcut_container).setVisibility(View.GONE);
} else {
findViewById(R.id.create_shortcut).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (filter == null) {
filter = TagFilterExposer.filterFromTagData(TagSettingsActivity.this, tagData);
}
FilterListFragment.showCreateShortcutDialog(TagSettingsActivity.this, ShortcutActivity.createIntent(filter), filter);
}
});
}
refreshSettingsPage();
}

@ -138,46 +138,80 @@
android:layout_marginTop="10dip"
android:hint="@string/actfm_TVA_tag_description_hint" />
</RelativeLayout>
<!-- Footer -->
<LinearLayout
android:id="@+id/listSettingsMore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="vertical"
android:visibility="gone">
<View
android:id="@+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@android:drawable/divider_horizontal_dark" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
style="@style/TextAppearance.GEN_EditLabel"
android:text="@string/actfm_TVA_tag_owner_label" />
<TextView
android:id="@+id/tag_owner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:textSize="20sp"/>
<CheckBox
android:id="@+id/tag_silenced"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:paddingLeft="45dip"
style="@style/TextAppearance"
android:text="@string/actfm_TVA_silence_label" />
</LinearLayout>
android:layout_marginTop="10dip"
android:layout_below="@id/tag_description"
style="@style/TEA_Separator" />
<!-- Footer -->
<LinearLayout
android:id="@+id/listSettingsMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/divider"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
style="@style/TextAppearance.GEN_EditLabel"
android:text="@string/actfm_TVA_tag_owner_label" />
<TextView
android:id="@+id/tag_owner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:textSize="20sp"/>
<CheckBox
android:id="@+id/tag_silenced"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:paddingLeft="45dip"
style="@style/TextAppearance"
android:text="@string/actfm_TVA_silence_label" />
</LinearLayout>
<LinearLayout
android:id="@+id/create_shortcut_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/divider"
android:layout_alignParentRight="true"
android:gravity="right"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
style="@style/TextAppearance.GEN_EditLabel"
android:text="@string/FLA_shortcut_dialog_title" />
<ImageButton
android:id="@+id/create_shortcut"
android:layout_width="75dip"
android:maxWidth="50dip"
android:layout_height="50dip"
android:maxHeight="50dip"
android:background="@android:color/transparent"
android:src="@android:drawable/ic_media_ff"
android:scaleType="fitCenter"/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

@ -322,7 +322,7 @@ public class FilterListFragment extends ListFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
showCreateShortcutDialog(ShortcutActivity.createIntent(filter), filter);
showCreateShortcutDialog(getActivity(), ShortcutActivity.createIntent(filter), filter);
} else {
startActivityForResult(intents[which - 1], REQUEST_CUSTOM_INTENT);
}
@ -390,19 +390,19 @@ public class FilterListFragment extends ListFragment {
* @param shortcutIntent
* @param label
*/
private void createShortcut(Filter filter, Intent shortcutIntent, String label) {
private static void createShortcut(Activity activity, Filter filter, Intent shortcutIntent, String label) {
if(label.length() == 0)
return;
Bitmap emblem = filter.listingIcon;
if(emblem == null)
emblem = ((BitmapDrawable) getResources().getDrawable(
emblem = ((BitmapDrawable) activity.getResources().getDrawable(
R.drawable.gl_list)).getBitmap();
// create icon by superimposing astrid w/ icon
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
Bitmap bitmap = ((BitmapDrawable) activity.getResources().getDrawable(
R.drawable.icon_blank)).getBitmap();
bitmap = bitmap.copy(bitmap.getConfig(), true);
Canvas canvas = new Canvas(bitmap);
@ -417,9 +417,9 @@ public class FilterListFragment extends ListFragment {
createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
createShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //$NON-NLS-1$
getActivity().sendBroadcast(createShortcutIntent);
Toast.makeText(getActivity(),
getString(R.string.FLA_toast_onCreateShortcut, label), Toast.LENGTH_LONG).show();
activity.sendBroadcast(createShortcutIntent);
Toast.makeText(activity,
activity.getString(R.string.FLA_toast_onCreateShortcut, label), Toast.LENGTH_LONG).show();
}
@Override
@ -452,7 +452,7 @@ public class FilterListFragment extends ListFragment {
final Intent shortcutIntent = item.getIntent();
FilterListItem filter = ((FilterAdapter.ViewHolder)info.targetView.getTag()).item;
if(filter instanceof Filter)
showCreateShortcutDialog(shortcutIntent, (Filter)filter);
showCreateShortcutDialog(getActivity(), shortcutIntent, (Filter)filter);
return true;
}
@ -470,11 +470,11 @@ public class FilterListFragment extends ListFragment {
return false;
}
private void showCreateShortcutDialog(final Intent shortcutIntent,
public static void showCreateShortcutDialog(final Activity activity, final Intent shortcutIntent,
final Filter filter) {
FrameLayout frameLayout = new FrameLayout(getActivity());
FrameLayout frameLayout = new FrameLayout(activity);
frameLayout.setPadding(10, 0, 10, 0);
final EditText editText = new EditText(getActivity());
final EditText editText = new EditText(activity);
if(filter.listingTitle == null)
filter.listingTitle = ""; //$NON-NLS-1$
editText.setText(filter.listingTitle.
@ -487,7 +487,7 @@ public class FilterListFragment extends ListFragment {
@Override
public void run() {
String label = editText.getText().toString();
createShortcut(filter, shortcutIntent, label);
createShortcut(activity, filter, shortcutIntent, label);
}
};
editText.setOnEditorActionListener(new OnEditorActionListener() {
@ -501,7 +501,7 @@ public class FilterListFragment extends ListFragment {
}
});
new AlertDialog.Builder(getActivity())
new AlertDialog.Builder(activity)
.setTitle(R.string.FLA_shortcut_dialog_title)
.setMessage(R.string.FLA_shortcut_dialog)
.setView(frameLayout)
@ -512,7 +512,7 @@ public class FilterListFragment extends ListFragment {
}
})
.setNegativeButton(android.R.string.cancel, null)
.show().setOwnerActivity(getActivity());
.show().setOwnerActivity(activity);
}
public void clear() {

Loading…
Cancel
Save