Added Quick Action bar to replace astrid's previous task edit button bar

pull/14/head
Melissa Yu 14 years ago committed by Tim Su
parent 8af6d11051
commit 14d1a3bb1b

@ -47,5 +47,10 @@
<type>2</type> <type>2</type>
<locationURI>_android_astridApi_98e6a2cf/src</locationURI> <locationURI>_android_astridApi_98e6a2cf/src</locationURI>
</link> </link>
<link>
<name>astridApi_src</name>
<type>2</type>
<locationURI>_android_astridApi_98e6a2cf/src</locationURI>
</link>
</linkedResources> </linkedResources>
</projectDescription> </projectDescription>

@ -56,8 +56,7 @@
android:minSdkVersion="3" /> android:minSdkVersion="3" />
<supports-screens /> <supports-screens />
<application android:icon="@drawable/icon" android:debuggable="true" android:label="@string/app_name"> <application android:icon="@drawable/icon" android:label="@string/app_name">
<!-- ====================================================== Activities = --> <!-- ====================================================== Activities = -->
<!-- Activity that displays task list --> <!-- Activity that displays task list -->

@ -7,6 +7,9 @@ import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
@ -45,8 +48,10 @@ public class TimerActionExposer extends BroadcastReceiver {
label = context.getString(R.string.TAE_stopTimer); label = context.getString(R.string.TAE_stopTimer);
Intent newIntent = new Intent(TIMER_ACTION); Intent newIntent = new Intent(TIMER_ACTION);
newIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId); newIntent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
Drawable timer = context.getResources().getDrawable(R.drawable.tango_clock);
Bitmap icon = ((BitmapDrawable)timer).getBitmap();
TaskAction action = new TaskAction(label, TaskAction action = new TaskAction(label,
PendingIntent.getBroadcast(context, (int)taskId, newIntent, 0)); PendingIntent.getBroadcast(context, (int)taskId, newIntent, 0), icon);
// transmit // transmit
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_ACTIONS); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_SEND_ACTIONS);

@ -12,7 +12,7 @@
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
</style> </style>
<style name="Theme" parent="android:Theme"> <style name="Theme" parent="@style/Theme.GreenDroid">
<item name="android:windowBackground">@null</item> <item name="android:windowBackground">@null</item>
</style> </style>

@ -1,5 +1,10 @@
package com.todoroo.astrid.adapter; package com.todoroo.astrid.adapter;
import greendroid.widget.QuickAction;
import greendroid.widget.QuickActionBar;
import greendroid.widget.QuickActionWidget;
import greendroid.widget.QuickActionWidget.OnQuickActionClickListener;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
@ -15,26 +20,27 @@ import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.Html; import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.Html.ImageGetter; import android.text.Html.ImageGetter;
import android.text.Html.TagHandler; import android.text.Html.TagHandler;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener; import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
import android.widget.Filterable; import android.widget.Filterable;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
@ -114,6 +120,10 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
// the task that's expanded // the task that's expanded
private long expanded = -1; private long expanded = -1;
// actions for QuickActionBar/mel
private QuickActionWidget mBar;
//private View mBarAnchor;
// --- task detail and decoration soft caches // --- task detail and decoration soft caches
public final ExtendedDetailManager extendedDetailManager; public final ExtendedDetailManager extendedDetailManager;
@ -734,55 +744,100 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
return broadcastIntent; return broadcastIntent;
} }
@Override //quickactionbar
protected void draw(final ViewHolder viewHolder, final long taskId, Collection<TaskAction> actions) { //private QuickActionWidget mBar;
if(actions == null || viewHolder.task.getId() != taskId)
return;
// hack because we know we have > 1 button @Override
if(actions.size() == 0) public synchronized void addNew(long taskId, String addOn, final TaskAction item) {
return; // TODO Auto-generated method stub
addIfNotExists(taskId, addOn, item);
if(mBar != null) {
ListView listView = activity.getListView();
ViewHolder myHolder = null;
// update view if it is visible
int length = listView.getChildCount();
for(int i = 0; i < length; i++) {
ViewHolder viewHolder = (ViewHolder) listView.getChildAt(i).getTag();
if(viewHolder == null || viewHolder.task.getId() != taskId)
continue;
myHolder = viewHolder;
break;
}
for(int i = viewHolder.actions.getChildCount(); i < actions.size() + 1; i++) { if(myHolder != null) {
Button editButton = new Button(activity); final ViewHolder viewHolder = myHolder;
editButton.setLayoutParams(params); activity.runOnUiThread(new Runnable() {
viewHolder.actions.addView(editButton); @Override
public void run() {
Drawable drawable = new BitmapDrawable(activity.getResources(), item.icon);
mBar.addQuickAction(new QuickAction(drawable, item.text));
mBar.setOnQuickActionClickListener(new QuickActionListener(item, viewHolder));
mBar.show(viewHolder.view);
}
});
}
} }
for(int i = actions.size() + 1; i < viewHolder.actions.getChildCount(); i++) {
viewHolder.actions.getChildAt(i).setVisibility(View.GONE);
} }
int i = 0; @Override
Button button = (Button) viewHolder.actions.getChildAt(i++); public Collection<TaskAction> get(long taskId) {
return super.get(taskId);
}
button.setText(R.string.TAd_actionEditTask);
button.setVisibility(View.VISIBLE);
button.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View arg0) { protected void draw(final ViewHolder viewHolder, final long taskId, Collection<TaskAction> actions) {
Intent intent = new Intent(activity, TaskEditActivity.class); // do not draw!
intent.putExtra(TaskEditActivity.TOKEN_ID, taskId);
activity.startActivityForResult(intent, TaskListActivity.ACTIVITY_EDIT_TASK);
} }
});
/*
//preparing quickActionBar
private void prepareQuickActionBar(ViewHolder viewHolder, Collection<TaskAction> actions){
mBar = new QuickActionBar(viewHolder.view.getContext());
QuickAction editAction = new QuickAction(viewHolder.view.getContext(), R.drawable.tango_edit, " Edit ");
mBar.addQuickAction(editAction);
for(TaskAction action : actions) { for(TaskAction action : actions) {
button = (Button) viewHolder.actions.getChildAt(i++);
button.setText(action.text); mBar.addQuickAction(new QuickAction(viewHolder.view.getContext(), R.drawable.tango_clock, action.text));
button.setVisibility(View.VISIBLE); mBar.setOnQuickActionClickListener(new quickActionListener(action, viewHolder));
button.setOnClickListener(new ActionClickListener(action, viewHolder));
} }
reset(viewHolder, taskId);
} }
*/
/*
protected synchronized void showQuickActionBar(ViewHolder viewHolder, long taskId, Collection<TaskAction> actions) {
if(mBar != null){
mBar.dismiss();
}
if(expanded != taskId) {
//viewHolder.actions.setVisibility(View.GONE);
return;
}
//display quickactionbar
else {
prepareQuickActionBar(viewHolder, actions);
mBar.show(viewHolder.view);
}
//viewHolder.actions.setVisibility(View.VISIBLE);
}
*/
@Override @Override
protected void reset(ViewHolder viewHolder, long taskId) { protected void reset(ViewHolder viewHolder, long taskId) {
if(expanded != taskId) { if(expanded != taskId) {
viewHolder.actions.setVisibility(View.GONE); mBar.dismiss();
//viewHolder.actions.setVisibility(View.GONE);
return; return;
} }
viewHolder.actions.setVisibility(View.VISIBLE); //display quickactionbar
/*
else{
prepareQuickActionBar(viewHolder);
mBar.show(viewHolder.view);
}
*/
//viewHolder.actions.setVisibility(View.VISIBLE);
} }
} }
@ -794,6 +849,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
public void notifyDataSetChanged() { public void notifyDataSetChanged() {
super.notifyDataSetChanged(); super.notifyDataSetChanged();
fontSize = Preferences.getIntegerFromString(R.string.p_fontSize, 20); fontSize = Preferences.getIntegerFromString(R.string.p_fontSize, 20);
} }
protected final View.OnClickListener completeBoxListener = new View.OnClickListener() { protected final View.OnClickListener completeBoxListener = new View.OnClickListener() {
@ -808,6 +864,7 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
}; };
/*
private final class ActionClickListener implements View.OnClickListener { private final class ActionClickListener implements View.OnClickListener {
private final TaskAction action; private final TaskAction action;
private final ViewHolder viewHolder; private final ViewHolder viewHolder;
@ -830,9 +887,66 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
taskActionManager.request(viewHolder); taskActionManager.request(viewHolder);
} }
}; };
*/
private final class QuickActionListener implements OnQuickActionClickListener {
private final TaskAction action;
private final ViewHolder viewHolder;
public QuickActionListener(TaskAction action, ViewHolder viewHolder) {
this.action = action;
this.viewHolder = viewHolder;
}
public void onQuickActionClicked(QuickActionWidget widget, int position){
mBar.dismiss();
mBar = null;
if(position == 0){
Intent intent = new Intent(activity, TaskEditActivity.class);
intent.putExtra(TaskEditActivity.TOKEN_ID, viewHolder.task.getId());
activity.startActivityForResult(intent, TaskListActivity.ACTIVITY_EDIT_TASK);
}
else{
flushSpecific(viewHolder.task.getId());
try {
action.intent.send();
} catch (Exception e) {
exceptionService.displayAndReportError(activity,
"Error launching action", e); //$NON-NLS-1$
}
decorationManager.request(viewHolder);
extendedDetailManager.request(viewHolder);
taskActionManager.request(viewHolder);
}
clearSelection();
notifyDataSetChanged();
}
}
private class TaskRowListener implements OnCreateContextMenuListener, OnClickListener { private class TaskRowListener implements OnCreateContextMenuListener, OnClickListener {
//prep quick action bar
private void prepareQuickActionBar(ViewHolder viewHolder, Collection<TaskAction> collection){
mBar = new QuickActionBar(viewHolder.view.getContext());
QuickAction editAction = new QuickAction(activity, R.drawable.tango_edit, " Edit ");
mBar.addQuickAction(editAction);
if(collection != null) {
for(TaskAction item : collection) {
Drawable drawable = new BitmapDrawable(activity.getResources(), item.icon);
mBar.addQuickAction(new QuickAction(drawable, item.text));
mBar.setOnQuickActionClickListener(new QuickActionListener(item, viewHolder));
}
}
}
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
// this is all a big sham. it's actually handled in Task List // this is all a big sham. it's actually handled in Task List
@ -847,11 +961,16 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
return; return;
long taskId = viewHolder.task.getId(); long taskId = viewHolder.task.getId();
if(expanded == taskId) {
expanded = -1; Collection<TaskAction> actions = taskActionManager.get(taskId);
} else { prepareQuickActionBar(viewHolder, actions);
expanded = taskId; //mBarAnchor = v;
} System.err.println("view is ID " + v.getId());
if(actions != null)
mBar.show(v);
System.err.println("! Request for " + taskId);
taskActionManager.request(viewHolder);
notifyDataSetChanged(); notifyDataSetChanged();
} }

@ -134,6 +134,8 @@ abstract public class TaskAdapterAddOnManager<TYPE> {
* @return * @return
*/ */
protected Collection<TYPE> get(long taskId) { protected Collection<TYPE> get(long taskId) {
if(cache.get(taskId) == null)
return null;
return cache.get(taskId).values(); return cache.get(taskId).values();
} }

Loading…
Cancel
Save