Task timer should add to your activity stream

pull/14/head
Andrew Shaw 13 years ago
parent 2c9e4126bc
commit 554690d3bb

@ -21,7 +21,6 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateUtils;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
@ -58,10 +57,10 @@ import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.SyncV2Service.SyncResultCallback;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerStoppedListener;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerActionListener;
import com.todoroo.astrid.utility.Flags;
public class EditNoteActivity extends LinearLayout implements TimerStoppedListener {
public class EditNoteActivity extends LinearLayout implements TimerActionListener {
@ -84,7 +83,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private View commentButton;
private int commentItems = 10;
private ImageButton pictureButton;
private Bitmap picture = null;
private Bitmap pendingCommentPicture = null;
private final Fragment fragment;
private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>();
@ -97,7 +96,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public EditNoteActivity(Fragment fragment, View parent, long t) {
super(fragment.getActivity());
Log.d("EditnoteActivity", "Contructor being called");
this.fragment = fragment;
DependencyInjectionService.getInstance().inject(this);
@ -143,7 +141,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
private void setUpInterface() {
timerView = commentsBar.findViewById(R.id.timer_container);
timerView = commentsBar.findViewById(R.id.timer_button);
commentButton = commentsBar.findViewById(R.id.commentButton);
commentField = (EditText) commentsBar.findViewById(R.id.commentField);
commentField.setOnEditorActionListener(new OnEditorActionListener() {
@ -196,8 +194,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
final ClearImageCallback clearImage = new ClearImageCallback() {
@Override
public void clearImage() {
Log.e("Errrr EditNOtes activity", "Picture clear image called");
picture = null;
pendingCommentPicture = null;
pictureButton.setImageResource(R.drawable.camera_button);
}
};
@ -205,7 +202,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
pictureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (picture != null)
if (pendingCommentPicture != null)
ActFmCameraModule.showPictureLauncher(fragment, clearImage);
else
ActFmCameraModule.showPictureLauncher(fragment, null);
@ -224,9 +221,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
loadingText = new TextView(getContext());
for (UpdatesChangedListener l : listeners) {
l.updatesChanged();
}
}
private void setUpListAdapter() {
@ -277,7 +271,6 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
this.addView(notesView);
}
if ( items.size() > commentItems) {
Button loadMore = new Button(getContext());
loadMore.setText(R.string.TEA_load_more);
@ -303,6 +296,9 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
}
for (UpdatesChangedListener l : listeners) {
l.updatesChanged();
}
}
@ -347,7 +343,7 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
// picture
final AsyncImageView commentPictureView = (AsyncImageView)view.findViewById(R.id.comment_picture); {
if(TextUtils.isEmpty(item.commentPicture))
if(TextUtils.isEmpty(item.commentPicture) || item.commentPicture.equals("null")) //$NON-NLS-1$
commentPictureView.setVisibility(View.GONE);
else {
commentPictureView.setVisibility(View.VISIBLE);
@ -398,11 +394,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
}
private void addComment() {
addComment(commentField.getText().toString(), "task_comment"); //$NON-NLS-1$
addComment(commentField.getText().toString(), "task_comment", true); //$NON-NLS-1$
}
private void addComment(String message, String actionCode) {
private void addComment(String message, String actionCode, boolean usePicture) {
Update update = new Update();
update.setValue(Update.MESSAGE, message);
update.setValue(Update.ACTION_CODE, actionCode);
@ -410,30 +406,28 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.CREATION_DATE, DateUtilities.now());
Log.d("Add comment", "The picture is: " + picture);
if (picture != null) {
if (usePicture && pendingCommentPicture != null) {
update.setValue(Update.PICTURE, Update.PICTURE_LOADING);
}
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
updateDao.createNew(update);
final long updateId = update.getId();
final Bitmap tempPicture = picture;
final Bitmap tempPicture = usePicture ? pendingCommentPicture : null;
new Thread() {
@Override
public void run() {
actFmSyncService.pushUpdate(updateId, tempPicture);
Log.d("Run thread", "The picture is: " + picture);
}
}.start();
commentField.setText(""); //$NON-NLS-1$
setUpListAdapter();
picture = null;
pendingCommentPicture = usePicture ? null : pendingCommentPicture;
pictureButton.setImageResource(R.drawable.camera_button);
StatisticsService.reportEvent(StatisticsConstants.ACTFM_TASK_COMMENT);
setUpListAdapter();
for (UpdatesChangedListener l : listeners) {
l.commentAdded();
}
@ -463,11 +457,13 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
public static NoteOrUpdate fromMetadata(Metadata m) {
if(!m.containsNonNullValue(NoteMetadata.THUMBNAIL))
m.setValue(NoteMetadata.THUMBNAIL, ""); //$NON-NLS-1$
if(!m.containsNonNullValue(NoteMetadata.COMMENT_PICTURE))
m.setValue(NoteMetadata.COMMENT_PICTURE, ""); //$NON-NLS-1$
return new NoteOrUpdate(m.getValue(NoteMetadata.THUMBNAIL),
m.getValue(NoteMetadata.TITLE),
m.getValue(NoteMetadata.BODY),
m.getValue(NoteMetadata.COMMENTPICTURE),
m.getValue(NoteMetadata.COMMENT_PICTURE),
m.getValue(Metadata.CREATION_DATE));
}
@ -479,8 +475,10 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
String message = u.getValue(Update.MESSAGE);
if(u.getValue(Update.ACTION_CODE).equals("task_comment"))
description = message;
else if(!TextUtils.isEmpty(message))
else if(!TextUtils.isEmpty(message) && !TextUtils.isEmpty(description))
description += " " + message;
else
description = message;
String commentPicture = u.getValue(Update.PICTURE);
return new NoteOrUpdate(user.optString("picture"),
@ -506,19 +504,22 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
}
@Override
public void timerStarted(Task task) {
// TODO Auto-generated method stub
addComment(getContext().getString(R.string.TEA_timer_comment_started) + " " + DateUtilities.getTimeString(getContext(), new Date()), "task_started"); //$NON-NLS-1$
public void timerStarted(Task t) {
addComment(String.format("%s %s", //$NON-NLS-1$
getContext().getString(R.string.TEA_timer_comment_started),
DateUtilities.getTimeString(getContext(), new Date())),
"task_started", //$NON-NLS-1$
false);
}
@Override
public void timerStopped(Task task) {
// TODO Auto-generated method stub
String elapsedTime = DateUtils.formatElapsedTime(task.getValue(Task.ELAPSED_SECONDS));
addComment(getContext().getString(R.string.TEA_timer_comment_stopped) + " " +
DateUtilities.getTimeString(getContext(), new Date()) + "\n" + getContext().getString(R.string.TEA_timer_comment_spent) + " " + elapsedTime, "task_stopped"); //$NON-NLS-1$
public void timerStopped(Task t) {
String elapsedTime = DateUtils.formatElapsedTime(t.getValue(Task.ELAPSED_SECONDS));
addComment(String.format("%s %s\n%s %s", //$NON-NLS-1$
getContext().getString(R.string.TEA_timer_comment_stopped),
DateUtilities.getTimeString(getContext(), new Date()),
getContext().getString(R.string.TEA_timer_comment_spent),
elapsedTime), "task_stopped", false); //$NON-NLS-1$
}
/*
@ -526,13 +527,11 @@ public class EditNoteActivity extends LinearLayout implements TimerStoppedListen
*/
public boolean activityResult(int requestCode, int resultCode, Intent data) {
Log.d("Activity result", "Called on camera for request code: " + requestCode);
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
picture = bitmap;
pictureButton.setImageBitmap(picture);
Log.d("Picture", "Picture = " + picture);
pendingCommentPicture = bitmap;
pictureButton.setImageBitmap(pendingCommentPicture);
}
};

@ -24,7 +24,7 @@ public class NoteMetadata {
public static final StringProperty THUMBNAIL = Metadata.VALUE3;
/** note external id (use for your own purposes) */
public static final StringProperty COMMENTPICTURE = Metadata.VALUE6;
public static final StringProperty COMMENT_PICTURE = Metadata.VALUE6;
/** note external provider (use for your own purposes) */
public static final StringProperty EXT_PROVIDER = Metadata.VALUE4;

@ -7,8 +7,8 @@ import android.app.Activity;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageButton;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DateUtilities;
@ -17,21 +17,18 @@ import com.todoroo.astrid.helper.TaskEditControlSet;
public class TimerActionControlSet extends TaskEditControlSet {
private final Button timerButton;
private final ImageButton timerButton;
private final Chronometer chronometer;
private final View timerContainer;
private boolean timerActive;
private final Activity activity;
private Task task;
private final List<TimerStoppedListener> listeners = new LinkedList<TimerStoppedListener>();
private final List<TimerActionListener> listeners = new LinkedList<TimerActionListener>();
public TimerActionControlSet(Activity activity, View parent) {
super(activity, -1);
this.activity = activity;
timerButton = (Button) parent.findViewById(R.id.timer_button);
timerContainer = (View) parent.findViewById(R.id.timer_container);
timerContainer.setOnClickListener(timerListener);
timerButton = (ImageButton) parent.findViewById(R.id.timer_button);
timerButton.setOnClickListener(timerListener);
chronometer = new Chronometer(activity);
}
@ -59,14 +56,14 @@ public class TimerActionControlSet extends TaskEditControlSet {
@Override
public void onClick(View v) {
if (timerActive) {
TimerPlugin.updateTimer(activity, task, false);
// TimerPlugin.updateTimer(activity, task, false);
for(TimerStoppedListener listener : listeners)
for(TimerActionListener listener : listeners)
listener.timerStopped(task);
chronometer.stop();
} else {
TimerPlugin.updateTimer(activity, task, true);
for(TimerStoppedListener listener : listeners)
// TimerPlugin.updateTimer(activity, task, true);
for(TimerActionListener listener : listeners)
listener.timerStarted(task);
chronometer.start();
}
@ -100,16 +97,16 @@ public class TimerActionControlSet extends TaskEditControlSet {
}
}
public interface TimerStoppedListener {
public interface TimerActionListener {
public void timerStopped(Task task);
public void timerStarted(Task task);
}
public void addListener(TimerStoppedListener listener) {
public void addListener(TimerActionListener listener) {
this.listeners.add(listener);
}
public void removeListener(TimerStoppedListener listener) {
public void removeListener(TimerActionListener listener) {
if (listeners.contains(listener))
listeners.remove(listener);
}

@ -7,7 +7,7 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property.IntegerProperty;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerStoppedListener;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerActionListener;
import com.todoroo.astrid.ui.PopupControlSet;
import com.todoroo.astrid.ui.TimeDurationControlSet;
@ -17,7 +17,7 @@ import com.todoroo.astrid.ui.TimeDurationControlSet;
* @author Tim Su <tim@todoroo.com>
*
*/
public class TimerControlSet extends PopupControlSet implements TimerStoppedListener {
public class TimerControlSet extends PopupControlSet implements TimerActionListener {
TaskEditControlSet estimated, elapsed;

@ -39,9 +39,9 @@
android:id="@+id/completeBox"
android:layout_width="45dip"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dip"
android:button="@drawable/btn_check" />
android:layout_marginLeft="12dip" />
<!-- assignee photo -->

@ -9,10 +9,10 @@
<ScrollView
android:id="@+id/edit_scroll"
style="@style/Content_EditScroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
style="@style/Content_EditScroll" >
android:layout_weight="100" >
<LinearLayout
android:layout_width="fill_parent"
@ -22,11 +22,11 @@
<LinearLayout
android:id="@+id/title_controls"
style="@style/EditRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dip"
android:gravity="center_vertical"
style="@style/EditRow"
android:orientation="horizontal"
android:paddingRight="6dip" >
@ -36,6 +36,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" >
<ImageButton
android:id="@+id/cancel"
android:layout_width="wrap_content"
@ -43,6 +44,7 @@
android:layout_marginRight="10dip"
android:background="@android:color/transparent"
android:src="@android:drawable/ic_menu_close_clear_cancel" />
<ImageButton
android:id="@+id/save"
android:layout_width="wrap_content"
@ -54,20 +56,20 @@
<LinearLayout
android:id="@+id/basic_controls"
style="@style/EditRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="3dip"
android:layout_marginTop="10dip"
style="@style/EditRow"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/more_header"
style="@style/EditRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
style="@style/EditRow"
android:visibility="gone" >
-
@ -79,16 +81,15 @@
android:gravity="center"
android:text="@string/TEA_more"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/more_container"
style="@style/EditRow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dip"
android:layout_marginBottom="0dip"
style="@style/EditRow"
android:orientation="vertical"
android:visibility="gone" >
@ -109,7 +110,6 @@
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
@ -118,10 +118,10 @@
<LinearLayout
android:id="@+id/updatesFooter"
style="@style/Content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Content"
android:minHeight="47dip"
android:orientation="horizontal"
android:padding="3dip" >
@ -135,11 +135,11 @@
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="#00000000"
android:paddingBottom="2dip"
android:paddingLeft="7dip"
android:paddingRight="7dip"
android:scaleType="centerInside"
android:background="#00000000"
android:src="@drawable/camera_button" />
<!-- Quick Add Task -->
@ -148,47 +148,39 @@
android:id="@+id/commentField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="1dip"
android:layout_marginLeft="1dip"
android:paddingLeft="10dip"
android:layout_marginRight="1dip"
android:layout_weight="100"
android:autoText="true"
android:background="@drawable/footer_comment_edittext"
android:capitalize="sentences"
android:hint="@string/TVA_add_comment"
android:paddingLeft="10dip"
android:textSize="16sp" />
<!-- Extended Add Button -->
<LinearLayout
android:id="@+id/timer_container"
<ImageButton
android:id="@+id/timer_button"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_marginLeft="3dip"
android:orientation="vertical"
android:layout_weight="1">
<Button
android:id="@+id/timer_button"
android:layout_width="30dip"
android:layout_height="25dip"
android:layout_marginTop="7dip"
android:layout_marginTop="3dip"
android:padding="7dip"
android:scaleType="fitCenter"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
</LinearLayout>
<ImageButton
android:id="@+id/commentButton"
android:layout_width="35dip"
android:layout_height="35dip"
android:layout_width="39dip"
android:layout_height="39dip"
android:layout_gravity="top"
android:layout_marginRight="3dip"
android:layout_weight="1"
android:background="@drawable/footer_button"
android:background="?attr/asAddButtonImg"
android:scaleType="center"
android:visibility="gone"
android:src="@drawable/ic_footer_add" />
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

@ -56,6 +56,7 @@
android:paddingTop="5dip"
astrid:defaultSrc="@drawable/icn_default_person_image"
android:scaleType="fitCenter"
android:layout_marginLeft="50dip"
android:visibility="gone" />
<!-- activity date -->

@ -34,6 +34,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.speech.RecognizerIntent;
import android.support.v4.app.Fragment;
import android.support.v4.app.SupportActivity;
@ -212,6 +213,16 @@ public final class TaskEditActivity extends Fragment implements
private TaskEditViewPager mAdapter;
private TabPageIndicator mIndicator;
private final Runnable refreshActivity = new Runnable()
{
@Override
public void run()
{
//Change state here
setPagerHeightForPosition(TAB_VIEW_UPDATES);
}
};
private final List<TaskEditControlSet> controls = Collections.synchronizedList(new ArrayList<TaskEditControlSet>());
// --- other instance variables
@ -377,11 +388,6 @@ public final class TaskEditActivity extends Fragment implements
mAdapter = new TaskEditViewPager(getActivity());
mAdapter.parent = this;
editNotes = new EditNoteActivity(this, getView(),
idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mPager = (ViewPager) getView().findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
@ -393,7 +399,9 @@ public final class TaskEditActivity extends Fragment implements
if (editNotes.numberOfComments() == 0) {
setCurrentTab(TAB_VIEW_MORE);
} else {
setPagerHeightForPosition(TAB_VIEW_UPDATES);
Handler refreshHandler = new Handler();
refreshHandler.postDelayed(refreshActivity, 1000);
}
editNotes.addListener(this);
}
@ -1155,6 +1163,7 @@ public final class TaskEditActivity extends Fragment implements
private void setPagerHeightForPosition(int position) {
int height = 0;
View view = (position == TAB_VIEW_MORE) ? moreControls : editNotes;
if (view == null || mPager == null) return;
int desiredWidth = MeasureSpec.makeMeasureSpec(view.getWidth(),
MeasureSpec.AT_MOST);

@ -122,8 +122,8 @@ import com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough;
import com.todoroo.astrid.widget.TasksWidget;
/**
* Primary activity for the Bente application. Shows a list of upcoming
* tasks and a user's coaches.
* Primary activity for the Bente application. Shows a list of upcoming tasks
* and a user's coaches.
*
* @author Tim Su <tim@todoroo.com>
*
@ -171,26 +171,33 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
// --- instance variables
@Autowired ExceptionService exceptionService;
@Autowired
ExceptionService exceptionService;
@Autowired protected TaskService taskService;
@Autowired
protected TaskService taskService;
@Autowired MetadataService metadataService;
@Autowired
MetadataService metadataService;
@Autowired Database database;
@Autowired
Database database;
@Autowired AddOnService addOnService;
@Autowired
AddOnService addOnService;
@Autowired UpgradeService upgradeService;
@Autowired
UpgradeService upgradeService;
@Autowired protected SyncV2Service syncService;
@Autowired
protected SyncV2Service syncService;
@Autowired TagDataService tagDataService;
@Autowired
TagDataService tagDataService;
private final TaskContextActionExposer[] contextItemExposers = new TaskContextActionExposer[] {
new ReminderDebugContextActions.MakeNotification(),
new ReminderDebugContextActions.WhenReminder(),
};
new ReminderDebugContextActions.WhenReminder(), };
protected TaskAdapter taskAdapter = null;
protected DetailReceiver detailReceiver = new DetailReceiver();
@ -218,16 +225,19 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
OnTaskListItemClickedListener mListener;
private boolean mDualFragments = false;
/* ======================================================================
/*
* ======================================================================
* ======================================================= initialization
* ====================================================================== */
* ======================================================================
*/
static {
AstridDependencyInjector.initialize();
}
/** Container Activity must implement this interface and we ensure
* that it does during the onAttach() callback
/**
* Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback
*/
public interface OnTaskListItemClickedListener {
public void onTaskListItemClicked(long taskId);
@ -236,7 +246,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
@Override
public void onAttach(SupportActivity activity) {
super.onAttach(activity);
// Check that the container activity has implemented the callback interface
// Check that the container activity has implemented the callback
// interface
try {
mListener = (OnTaskListItemClickedListener) activity;
} catch (ClassCastException e) {
@ -252,9 +263,11 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
*/
protected View getListBody(ViewGroup root) {
if (AndroidUtilities.getSdkVersion() > 3)
return getActivity().getLayoutInflater().inflate(R.layout.task_list_body_standard, root, false);
return getActivity().getLayoutInflater().inflate(
R.layout.task_list_body_standard, root, false);
else
return getActivity().getLayoutInflater().inflate(R.layout.task_list_body_api3, root, false);
return getActivity().getLayoutInflater().inflate(
R.layout.task_list_body_api3, root, false);
}
/** Called when loading up the activity */
@ -275,9 +288,12 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
database.openForWriting();
}
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
/*
* (non-Javadoc)
*
* @see
* android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,
* android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -298,8 +314,10 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
setUpUiComponents();
onNewIntent(getActivity().getIntent());
Fragment filterlistFrame = getFragmentManager().findFragmentByTag(FilterListActivity.TAG_FILTERLIST_FRAGMENT);
mDualFragments = (filterlistFrame != null) && filterlistFrame.isInLayout();
Fragment filterlistFrame = getFragmentManager().findFragmentByTag(
FilterListActivity.TAG_FILTERLIST_FRAGMENT);
mDualFragments = (filterlistFrame != null)
&& filterlistFrame.isInLayout();
if (mDualFragments) {
// In dual-pane mode, the list view highlights the selected item.
@ -308,10 +326,12 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
if (Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1)
upgradeService.showChangeLog(getActivity(), Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
if (getActivity().getIntent().hasExtra(TOKEN_SOURCE)) {
switch(getActivity().getIntent().getIntExtra(TOKEN_SOURCE, Constants.SOURCE_DEFAULT)) {
switch (getActivity().getIntent().getIntExtra(TOKEN_SOURCE,
Constants.SOURCE_DEFAULT)) {
case Constants.SOURCE_NOTIFICATION:
StatisticsService.reportEvent(StatisticsConstants.LAUNCH_FROM_NOTIFICATION);
break;
@ -347,8 +367,10 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
String intentAction = intent.getAction();
if (Intent.ACTION_SEARCH.equals(intentAction)) {
String query = intent.getStringExtra(SearchManager.QUERY).trim();
Filter searchFilter = new Filter(null, getString(R.string.FLA_search_filter, query),
new QueryTemplate().where(Functions.upper(Task.TITLE).like("%" + //$NON-NLS-1$
Filter searchFilter = new Filter(null, getString(
R.string.FLA_search_filter, query),
new QueryTemplate().where(Functions.upper(Task.TITLE).like(
"%" + //$NON-NLS-1$
query.toUpperCase() + "%")), //$NON-NLS-1$
null);
intent = new Intent(getActivity(), TaskListWrapperActivity.class);
@ -356,7 +378,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
startActivity(intent);
getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(), R.anim.slide_right_in, R.anim.slide_right_out);
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
return;
} else if (extras != null && extras.containsKey(TOKEN_FILTER)) {
@ -396,7 +419,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
MenuItem item;
if (!(this instanceof DraggableTaskListActivity)) {
item = menu.add(Menu.NONE, MENU_SORT_ID, Menu.NONE, R.string.TLA_menu_sort);
item = menu.add(Menu.NONE, MENU_SORT_ID, Menu.NONE,
R.string.TLA_menu_sort);
item.setIcon(android.R.drawable.ic_menu_sort_by_size);
if (((AstridWrapperActivity) getActivity()).isMultipleFragments())
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
@ -419,10 +443,12 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
item.setIcon(android.R.drawable.ic_menu_preferences);
// ask about plug-ins
Intent queryIntent = new Intent(AstridApiConstants.ACTION_TASK_LIST_MENU);
Intent queryIntent = new Intent(
AstridApiConstants.ACTION_TASK_LIST_MENU);
PackageManager pm = getActivity().getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(queryIntent, 0);
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(
queryIntent, 0);
int length = resolveInfoList.size();
for (int i = 0; i < length; i++) {
ResolveInfo resolveInfo = resolveInfoList.get(i);
@ -449,7 +475,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
View selected = getListView().getSelectedView();
// hot-key to set task priority - 1-4 or ALT + Q-R
if(!filterOn && event.getUnicodeChar() >= '1' && event.getUnicodeChar() <= '4' && selected != null) {
if (!filterOn && event.getUnicodeChar() >= '1'
&& event.getUnicodeChar() <= '4' && selected != null) {
int importance = event.getNumber() - '1';
Task task = ((ViewHolder) selected.getTag()).task;
task.setValue(Task.IMPORTANCE, importance);
@ -459,10 +486,12 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
// filter
else if (!filterOn && event.getUnicodeChar() != 0) {
getListView().setTextFilterEnabled(true);
getListView().setFilterText(Character.toString((char)event.getUnicodeChar()));
getListView().setFilterText(
Character.toString((char) event.getUnicodeChar()));
}
// turn off filter if nothing is selected
else if(filterOn && TextUtils.isEmpty(getListView().getTextFilter())) {
else if (filterOn
&& TextUtils.isEmpty(getListView().getTextFilter())) {
getListView().setTextFilterEnabled(false);
}
@ -477,8 +506,10 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
* When user presses enter, quick-add the task
*/
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_NULL && !TextUtils.isEmpty(quickAddBox.getText().toString().trim())) {
public boolean onEditorAction(TextView view, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_NULL
&& !TextUtils.isEmpty(quickAddBox.getText().toString().trim())) {
quickAddTask(quickAddBox.getText().toString(), true);
return true;
}
@ -486,8 +517,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
});
quickAddButton = ((ImageButton)getView().findViewById(R.id.quickAddButton));
quickAddButton = ((ImageButton) getView().findViewById(
R.id.quickAddButton));
// set listener for quick add button
quickAddButton.setOnClickListener(new OnClickListener() {
@ -500,18 +531,21 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
});
// prepare and set listener for voice add button
voiceAddButton = (ImageButton) getView().findViewById(R.id.voiceAddButton);
voiceAddButton = (ImageButton) getView().findViewById(
R.id.voiceAddButton);
int prompt = R.string.voice_edit_title_prompt;
if (Preferences.getBoolean(R.string.p_voiceInputCreatesTask, false))
prompt = R.string.voice_create_prompt;
voiceInputAssistant = new VoiceInputAssistant(getActivity(),voiceAddButton,quickAddBox);
voiceInputAssistant = new VoiceInputAssistant(getActivity(),
voiceAddButton, quickAddBox);
voiceInputAssistant.configureMicrophoneButton(prompt);
// set listener for extended addbutton
quickAddButton.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Task task = quickAddTask(quickAddBox.getText().toString(), false);
Task task = quickAddTask(quickAddBox.getText().toString(),
false);
if (task == null)
return true;
@ -528,10 +562,10 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
});
// gestures / animation
try {
GestureService.registerGestureDetector(getActivity(), R.id.gestures, R.raw.gestures, this);
GestureService.registerGestureDetector(getActivity(),
R.id.gestures, R.raw.gestures, this);
} catch (VerifyError e) {
// failed check, no gestures :P
}
@ -542,13 +576,16 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
// dithering
getActivity().getWindow().setFormat(PixelFormat.RGBA_8888);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
getActivity().getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DITHER);
syncResultCallback = new ProgressBarSyncResultCallback(getActivity(),
R.id.progressBar, new Runnable() {
@Override
public void run() {
ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
ContextManager.getContext().sendBroadcast(
new Intent(
AstridApiConstants.BROADCAST_EVENT_REFRESH));
}
});
}
@ -562,7 +599,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
public void transitionForTaskEdit() {
AndroidUtilities.callOverridePendingTransition(getActivity(), R.anim.slide_left_in, R.anim.slide_left_out);
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_left_in, R.anim.slide_left_out);
}
private void setUpBackgroundJobs() {
@ -588,9 +626,11 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}, BACKGROUND_REFRESH_INTERVAL, BACKGROUND_REFRESH_INTERVAL);
}
/* ======================================================================
/*
* ======================================================================
* ============================================================ lifecycle
* ====================================================================== */
* ======================================================================
*/
@Override
public void onStart() {
@ -608,9 +648,9 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
super.onResume();
StatisticsService.sessionStart(getActivity());
if (addOnService.hasPowerPack() &&
Preferences.getBoolean(R.string.p_voiceInputEnabled, true) &&
voiceInputAssistant.isVoiceInputAvailable()) {
if (addOnService.hasPowerPack()
&& Preferences.getBoolean(R.string.p_voiceInputEnabled, true)
&& voiceInputAssistant.isVoiceInputAvailable()) {
voiceAddButton.setVisibility(View.VISIBLE);
} else {
voiceAddButton.setVisibility(View.GONE);
@ -624,26 +664,34 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
new IntentFilter(AstridApiConstants.BROADCAST_SEND_ACTIONS));
getActivity().registerReceiver(refreshReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));
getActivity().registerReceiver(syncActionReceiver,
getActivity().registerReceiver(
syncActionReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS));
setUpBackgroundJobs();
if (!Preferences.getBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, false)) {
Preferences.setBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, true);
Intent showWelcomeLogin = new Intent(getActivity(), WelcomeWalkthrough.class);
if (!Preferences.getBoolean(
WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN, false)) {
Preferences.setBoolean(WelcomeWalkthrough.KEY_SHOWED_WELCOME_LOGIN,
true);
Intent showWelcomeLogin = new Intent(getActivity(),
WelcomeWalkthrough.class);
showWelcomeLogin.putExtra(ActFmLoginActivity.SHOW_TOAST, false);
startActivity(showWelcomeLogin);
return;
}
if (!Preferences.getBoolean(R.string.p_showed_add_task_help, false)) {
HelpInfoPopover.showPopover(getActivity(), quickAddBox, R.string.help_popover_add_task, null);
HelpInfoPopover.showPopover(getActivity(), quickAddBox,
R.string.help_popover_add_task, null);
Preferences.setBoolean(R.string.p_showed_add_task_help, true);
} else if (!Preferences.getBoolean(R.string.p_showed_tap_task_help, false)) {
} else if (!Preferences.getBoolean(R.string.p_showed_tap_task_help,
false)) {
showTaskEditHelpPopover();
} else if (Preferences.isSet(getString(R.string.p_showed_lists_help)) &&
!Preferences.getBoolean(R.string.p_showed_lists_help, false)) {
//HelpInfoPopover.showPopover(getActivity(), getView().findViewById(R.id.back), R.string.help_popover_lists, null);
} else if (Preferences.isSet(getString(R.string.p_showed_lists_help))
&& !Preferences.getBoolean(R.string.p_showed_lists_help, false)) {
// HelpInfoPopover.showPopover(getActivity(),
// getView().findViewById(R.id.back), R.string.help_popover_lists,
// null);
Preferences.setBoolean(R.string.p_showed_lists_help, true);
}
@ -673,7 +721,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
protected class RefreshReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent == null || !AstridApiConstants.BROADCAST_EVENT_REFRESH.equals(intent.getAction()))
if (intent == null
|| !AstridApiConstants.BROADCAST_EVENT_REFRESH.equals(intent.getAction()))
return;
getActivity().runOnUiThread(new Runnable() {
@ -685,7 +734,6 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
}
/**
* Called by the RefreshReceiver when the task list receives a refresh
* broadcast. Subclasses should override this.
@ -704,7 +752,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
protected class SyncActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent == null || !AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS.equals(intent.getAction()))
if (intent == null
|| !AstridApiConstants.BROADCAST_SEND_SYNC_ACTIONS.equals(intent.getAction()))
return;
try {
@ -713,7 +762,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
syncActions.add(syncAction);
} catch (Exception e) {
exceptionService.reportError("receive-sync-action-" + //$NON-NLS-1$
intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON), e);
intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON),
e);
}
}
}
@ -734,17 +784,20 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
if (AstridApiConstants.BROADCAST_SEND_DECORATIONS.equals(intent.getAction())) {
TaskDecoration deco = extras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.decorationManager.addNew(taskId, addOn, deco, null);
taskAdapter.decorationManager.addNew(taskId, addOn, deco,
null);
} else if (AstridApiConstants.BROADCAST_SEND_DETAILS.equals(intent.getAction())) {
String detail = extras.getString(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.addDetails(taskId, detail);
} else if (AstridApiConstants.BROADCAST_SEND_ACTIONS.equals(intent.getAction())) {
TaskAction action = extras.getParcelable(AstridApiConstants.EXTRAS_RESPONSE);
taskAdapter.taskActionManager.addNew(taskId, addOn, action, null);
taskAdapter.taskActionManager.addNew(taskId, addOn, action,
null);
}
} catch (Exception e) {
exceptionService.reportError("receive-detail-" + //$NON-NLS-1$
intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON), e);
intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON),
e);
}
}
}
@ -761,35 +814,44 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// handle the result of voice recognition, put it into the textfield
if (voiceInputAssistant.handleActivityResult(requestCode, resultCode, data)) {
// if user wants, create the task directly (with defaultvalues) after saying it
if (voiceInputAssistant.handleActivityResult(requestCode, resultCode,
data)) {
// if user wants, create the task directly (with defaultvalues)
// after saying it
Flags.set(Flags.TLA_RESUMED_FROM_VOICE_ADD);
if (Preferences.getBoolean(R.string.p_voiceInputCreatesTask, false))
quickAddTask(quickAddBox.getText().toString(), true);
super.onActivityResult(requestCode, resultCode, data);
// the rest of onActivityResult is totally unrelated to voicerecognition, so bail out
// the rest of onActivityResult is totally unrelated to
// voicerecognition, so bail out
return;
}
if(requestCode == ACTIVITY_SETTINGS && resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
if (requestCode == ACTIVITY_SETTINGS
&& resultCode == EditPreferences.RESULT_CODE_THEME_CHANGED) {
getActivity().finish();
if (overrideFinishAnim) {
AndroidUtilities.callOverridePendingTransition(getActivity(), R.anim.slide_right_in, R.anim.slide_right_out);
AndroidUtilities.callOverridePendingTransition(getActivity(),
R.anim.slide_right_in, R.anim.slide_right_out);
}
getActivity().startActivity(getActivity().getIntent());
}
super.onActivityResult(requestCode, resultCode, data);
if (!Preferences.getBoolean(R.string.p_showed_add_task_help, false)) {
HelpInfoPopover.showPopover(getActivity(), quickAddBox, R.string.help_popover_add_task, null);
HelpInfoPopover.showPopover(getActivity(), quickAddBox,
R.string.help_popover_add_task, null);
Preferences.setBoolean(R.string.p_showed_add_task_help, true);
}
if (resultCode != Activity.RESULT_CANCELED) {
if (data != null && data.hasExtra(TaskEditActivity.TOKEN_TASK_WAS_ASSIGNED) && data.getBooleanExtra(TaskEditActivity.TOKEN_TASK_WAS_ASSIGNED, false) && !isFilter) {
if (data != null
&& data.hasExtra(TaskEditActivity.TOKEN_TASK_WAS_ASSIGNED)
&& data.getBooleanExtra(
TaskEditActivity.TOKEN_TASK_WAS_ASSIGNED, false)
&& !isFilter) {
String assignedTo = data.getStringExtra(TaskEditActivity.TOKEN_ASSIGNED_TO);
switchToAssignedFilter(assignedTo);
} else {
@ -806,7 +868,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
public void onClick(DialogInterface dialog, int which) {
Filter assignedFilter = CustomFilterExposer.getAssignedByMeFilter(getResources());
Intent intent = new Intent(getActivity(), TaskListWrapperActivity.class);
Intent intent = new Intent(getActivity(),
TaskListWrapperActivity.class);
intent.putExtra(TaskListActivity.TOKEN_FILTER, assignedFilter);
intent.putExtra(TaskListActivity.TOKEN_OVERRIDE_ANIM, true);
startActivityForResult(intent, 0);
@ -814,19 +877,20 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
};
DialogUtilities.okCancelCustomDialog(getActivity(),
getString(R.string.actfm_view_task_title), getString(R.string.actfm_view_task_text, assignedEmail),
R.string.actfm_view_task_ok, R.string.actfm_view_task_cancel, 0,
okListener, null);
getString(R.string.actfm_view_task_title),
getString(R.string.actfm_view_task_text, assignedEmail),
R.string.actfm_view_task_ok, R.string.actfm_view_task_cancel,
0, okListener, null);
}
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// do nothing
}
/**
* Detect when user is flinging the task, disable task adapter loading
* when this occurs to save resources and time.
* Detect when user is flinging the task, disable task adapter loading when
* this occurs to save resources and time.
*/
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
@ -846,12 +910,15 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
}
/* ======================================================================
/*
* ======================================================================
* =================================================== managing list view
* ====================================================================== */
* ======================================================================
*/
/**
* Load or re-load action items and update views
*
* @param requery
*/
public void loadTaskListContent(boolean requery) {
@ -870,26 +937,30 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
getActivity().startManagingCursor(taskCursor);
if(oldListItemSelected != ListView.INVALID_POSITION &&
oldListItemSelected < taskCursor.getCount())
if (oldListItemSelected != ListView.INVALID_POSITION
&& oldListItemSelected < taskCursor.getCount())
getListView().setSelection(oldListItemSelected);
// also load sync actions
syncActions.clear();
Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_REQUEST_SYNC_ACTIONS);
getActivity().sendOrderedBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ);
Intent broadcastIntent = new Intent(
AstridApiConstants.BROADCAST_REQUEST_SYNC_ACTIONS);
getActivity().sendOrderedBroadcast(broadcastIntent,
AstridApiConstants.PERMISSION_READ);
}
/**
* Fill in the Task List with current items
* @param withCustomId force task with given custom id to be part of list
*
* @param withCustomId
* force task with given custom id to be part of list
*/
protected void setUpTaskList() {
if (filter == null)
return;
sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort(filter.sqlQuery,
sortFlags, sortSort));
sqlQueryTemplate.set(SortHelper.adjustQueryForFlagsAndSort(
filter.sqlQuery, sortFlags, sortSort));
// perform query
TodorooCursor<Task> currentCursor = taskService.fetchFiltered(
@ -898,7 +969,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
// set up list adapters
taskAdapter = new TaskAdapter(this, R.layout.task_adapter_row,
currentCursor, sqlQueryTemplate, false, new OnCompletedTaskListener() {
currentCursor, sqlQueryTemplate, false,
new OnCompletedTaskListener() {
@Override
public void onCompletedTask(Task item, boolean newState) {
if (newState == true)
@ -913,8 +985,9 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
/**
* Select a custom task id in the list. If it doesn't exist, create
* a new custom filter
* Select a custom task id in the list. If it doesn't exist, create a new
* custom filter
*
* @param withCustomId
*/
@SuppressWarnings("nls")
@ -932,12 +1005,14 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
// create a custom cursor
if (!sqlQueryTemplate.get().contains("WHERE"))
sqlQueryTemplate.set(sqlQueryTemplate.get() + " WHERE " + TaskCriteria.byId(withCustomId));
sqlQueryTemplate.set(sqlQueryTemplate.get() + " WHERE "
+ TaskCriteria.byId(withCustomId));
else
sqlQueryTemplate.set(sqlQueryTemplate.get().replace("WHERE ", "WHERE " +
TaskCriteria.byId(withCustomId) + " OR "));
sqlQueryTemplate.set(sqlQueryTemplate.get().replace("WHERE ",
"WHERE " + TaskCriteria.byId(withCustomId) + " OR "));
currentCursor = taskService.fetchFiltered(sqlQueryTemplate.get(), null, TaskAdapter.PROPERTIES);
currentCursor = taskService.fetchFiltered(sqlQueryTemplate.get(), null,
TaskAdapter.PROPERTIES);
getListView().setFilterText("");
getActivity().startManagingCursor(currentCursor);
@ -961,25 +1036,35 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
private void showTaskEditHelpPopover() {
if (!Preferences.getBoolean(R.string.p_showed_tap_task_help, false)) {
Preferences.setBoolean(R.string.p_showed_tap_task_help, true);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(quickAddBox.getWindowToken(), 0);
getListView().postDelayed(new Runnable() {
public void run() {
if (taskAdapter.getCount() > 0) {
final View view = getListView().getChildAt(getListView().getChildCount() - 1);
final View view = getListView().getChildAt(
getListView().getChildCount() - 1);
if (view != null) {
OnDismissListener onDismiss = new OnDismissListener() {
@Override
public void onDismiss() {
if (!Preferences.isSet(getString(R.string.p_showed_lists_help))) {
Preferences.setBoolean(R.string.p_showed_lists_help, false);
} else if (!Preferences.getBoolean(R.string.p_showed_lists_help, false)) {
Preferences.setBoolean(R.string.p_showed_lists_help, true);
//HelpInfoPopover.showPopover(getActivity(), getView().findViewById(R.id.back), R.string.help_popover_lists, null);
Preferences.setBoolean(
R.string.p_showed_lists_help,
false);
} else if (!Preferences.getBoolean(
R.string.p_showed_lists_help, false)) {
Preferences.setBoolean(
R.string.p_showed_lists_help,
true);
// HelpInfoPopover.showPopover(getActivity(),
// getView().findViewById(R.id.back),
// R.string.help_popover_lists, null);
}
}
};
HelpInfoPopover.showPopover(getActivity(), view, R.string.help_popover_tap_task, onDismiss);
HelpInfoPopover.showPopover(getActivity(), view,
R.string.help_popover_tap_task, onDismiss);
}
}
}
@ -988,13 +1073,17 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
}
/* ======================================================================
/*
* ======================================================================
* ============================================================== actions
* ====================================================================== */
* ======================================================================
*/
/**
* A task was completed from the task adapter
* @param item task that was completed
*
* @param item
* task that was completed
*/
protected void onTaskCompleted(Task item) {
if (isFilter)
@ -1005,6 +1094,7 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
/**
* Quick-add a new task
*
* @param title
* @return
*/
@ -1013,18 +1103,21 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
try {
if (title != null)
title = title.trim();
Task task = createWithValues(filter.valuesForNewTasks,
title, taskService, metadataService);
Task task = createWithValues(filter.valuesForNewTasks, title,
taskService, metadataService);
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null &&
!Preferences.getStringValue(R.string.gcal_p_default).equals("-1");
boolean gcalCreateEventEnabled = Preferences.getStringValue(R.string.gcal_p_default) != null
&& !Preferences.getStringValue(R.string.gcal_p_default).equals(
"-1");
if (title.length() > 0 && gcalCreateEventEnabled) {
Uri calendarUri = GCalHelper.createTaskEvent(task, getActivity().getContentResolver(), new ContentValues());
Uri calendarUri = GCalHelper.createTaskEvent(task,
getActivity().getContentResolver(), new ContentValues());
task.setValue(Task.CALENDAR_URI, calendarUri.toString());
taskService.save(task);
}
TextView quickAdd = (TextView)getView().findViewById(R.id.quickAddText);
TextView quickAdd = (TextView) getView().findViewById(
R.id.quickAddText);
quickAdd.setText(""); //$NON-NLS-1$
if (selectNewTask) {
@ -1035,21 +1128,23 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
StatisticsService.reportEvent(StatisticsConstants.TASK_CREATED_TASKLIST);
return task;
} catch (Exception e) {
exceptionService.displayAndReportError(getActivity(), "quick-add-task", e);
exceptionService.displayAndReportError(getActivity(),
"quick-add-task", e);
return new Task();
}
}
/**
* Create task from the given content values, saving it.
*
* @param values
* @param title
* @param taskService
* @param metadataService
* @return
*/
public static Task createWithValues(ContentValues values, String title, TaskService taskService,
MetadataService metadataService) {
public static Task createWithValues(ContentValues values, String title,
TaskService taskService, MetadataService metadataService) {
Task task = new Task();
if (title != null)
task.setValue(Task.TITLE, title);
@ -1111,16 +1206,18 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
Object label = contextItemExposers[i].getLabel(task);
if (label != null) {
if (label instanceof Integer)
menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i, Menu.NONE, (Integer)label);
menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i,
Menu.NONE, (Integer) label);
else
menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i, Menu.NONE, (String)label);
menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i,
Menu.NONE, (String) label);
}
}
long taskId = task.getId();
for (ContextMenuItem item : contextMenuExtensionLoader.getList()) {
android.view.MenuItem menuItem = menu.add(id, CONTEXT_MENU_BROADCAST_INTENT_ID, Menu.NONE,
item.title);
android.view.MenuItem menuItem = menu.add(id,
CONTEXT_MENU_BROADCAST_INTENT_ID, Menu.NONE, item.title);
item.intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
menuItem.setIntent(item.intent);
}
@ -1133,30 +1230,31 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
/** Show a dialog box and delete the task specified */
private void deleteTask(final Task task) {
new AlertDialog.Builder(getActivity()).setTitle(R.string.DLG_confirm_title)
.setMessage(R.string.DLG_delete_this_task_question).setIcon(
new AlertDialog.Builder(getActivity()).setTitle(
R.string.DLG_confirm_title).setMessage(
R.string.DLG_delete_this_task_question).setIcon(
android.R.drawable.ic_dialog_alert).setPositiveButton(
android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
taskService.delete(task);
loadTaskListContent(true);
}
}).setNegativeButton(android.R.string.cancel, null)
.show();
}).setNegativeButton(android.R.string.cancel, null).show();
}
/**
* Intent object with custom label returned by toString.
*
* @author joshuagross <joshua.gross@gmail.com>
*/
protected static class IntentWithLabel extends Intent {
private final String label;
public IntentWithLabel(Intent in, String labelIn) {
super(in);
label = labelIn;
}
@Override
public String toString() {
return label;
@ -1166,7 +1264,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
private static final String PREF_LAST_AUTO_SYNC = "taskListLastAutoSync"; //$NON-NLS-1$
protected void initiateAutomaticSync() {
if (filter == null || filter.title == null || !filter.title.equals(getString(R.string.BFE_Active)))
if (filter == null || filter.title == null
|| !filter.title.equals(getString(R.string.BFE_Active)))
return;
long lastAutoSync = Preferences.getLong(PREF_LAST_AUTO_SYNC, 0);
@ -1204,9 +1303,11 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
intent.setClassName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);
if(MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name) &&
!MilkUtilities.INSTANCE.isLoggedIn())
String category = MetadataHelper.resolveActivityCategoryName(
resolveInfo, pm);
if (MilkPreferences.class.getName().equals(
resolveInfo.activityInfo.name)
&& !MilkUtilities.INSTANCE.isLoggedIn())
continue;
if (category.equals(desiredCategory)) {
@ -1242,13 +1343,15 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
if (actions[which] instanceof SyncAction) {
try {
((SyncAction) actions[which]).intent.send();
Toast.makeText(getActivity(), R.string.SyP_progress_toast,
Toast.makeText(getActivity(),
R.string.SyP_progress_toast,
Toast.LENGTH_LONG).show();
} catch (CanceledException e) {
//
}
} else {
((SyncV2Provider)actions[which]).synchronizeActiveTasks(true, syncResultCallback);
((SyncV2Provider) actions[which]).synchronizeActiveTasks(
true, syncResultCallback);
}
}
};
@ -1257,13 +1360,15 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
}
/**
* Show menu of sync options. This is shown when you're not logged into any services, or logged into
* more than one.
* Show menu of sync options. This is shown when you're not logged into any
* services, or logged into more than one.
*
* @param <TYPE>
* @param items
* @param listener
*/
private <TYPE> void showSyncOptionMenu(TYPE[] items, DialogInterface.OnClickListener listener) {
private <TYPE> void showSyncOptionMenu(TYPE[] items,
DialogInterface.OnClickListener listener) {
if (items.length == 1) {
listener.onClick(null, 0);
return;
@ -1273,14 +1378,16 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
android.R.layout.simple_spinner_dropdown_item, items);
// show a menu of available options
new AlertDialog.Builder(getActivity())
.setTitle(R.string.SyP_label)
.setAdapter(adapter, listener)
.show().setOwnerActivity(getActivity());
new AlertDialog.Builder(getActivity()).setTitle(R.string.SyP_label).setAdapter(
adapter, listener).show().setOwnerActivity(getActivity());
}
/* (non-Javadoc)
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
/*
* (non-Javadoc)
*
* @see
* android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView
* , android.view.View, int, long)
*/
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
@ -1314,8 +1421,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
return true;
case MENU_SORT_ID:
StatisticsService.reportEvent(StatisticsConstants.TLA_MENU_SORT);
AlertDialog dialog = SortSelectionActivity.createDialog(getActivity(),
this, sortFlags, sortSort);
AlertDialog dialog = SortSelectionActivity.createDialog(
getActivity(), this, sortFlags, sortSort);
dialog.show();
return true;
case MENU_SYNC_ID:
@ -1329,7 +1436,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
return true;
case MENU_ADDON_INTENT_ID:
intent = item.getIntent();
AndroidUtilities.startExternalIntent(getActivity(), intent, ACTIVITY_MENU_EXTERNAL);
AndroidUtilities.startExternalIntent(getActivity(), intent,
ACTIVITY_MENU_EXTERNAL);
return true;
// --- context menu items
@ -1435,7 +1543,8 @@ public class TaskListActivity extends ListFragment implements OnScrollListener,
editor.putInt(SortHelper.PREF_SORT_FLAGS, flags);
editor.putInt(SortHelper.PREF_SORT_SORT, sort);
editor.commit();
ContextManager.getContext().startService(new Intent(ContextManager.getContext(),
ContextManager.getContext().startService(
new Intent(ContextManager.getContext(),
TasksWidget.WidgetUpdateService.class));
}

Loading…
Cancel
Save