Mostly working task edit popover

pull/14/head
Sam Bosley 13 years ago committed by Andrew Shaw
parent d5b704badf
commit 537beaa062

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/task_edit_dialog_background_white"
android:padding="10dip"
android:layout_below="@+id/gdi_arrow_up"/>
<ImageView
android:id="@+id/gdi_arrow_up"
android:layout_width="27dip"
android:layout_height="27dip"
android:scaleType="fitCenter"
android:layout_marginBottom="-8dip"
android:background="#ff0000"/>
<ImageView
android:id="@+id/gdi_arrow_down"
android:layout_width="27dip"
android:layout_height="27dip"
android:scaleType="fitCenter"
android:layout_marginBottom="-8dip"
android:layout_below="@android:id/list"
android:src="@drawable/list_arrow_down" />
</RelativeLayout>

@ -145,11 +145,8 @@ public class AstridWrapperActivity extends FragmentActivity
if (fragmentLayout != LAYOUT_SINGLE) { if (fragmentLayout != LAYOUT_SINGLE) {
TaskEditActivity editActivity = getTaskEditFragment(); TaskEditActivity editActivity = getTaskEditFragment();
findViewById(R.id.taskedit_fragment_container).setVisibility(View.VISIBLE); if (fragmentLayout == LAYOUT_TRIPLE)
findViewById(R.id.taskedit_fragment_container).setVisibility(View.VISIBLE);
if(fragmentLayout == LAYOUT_DOUBLE) {
findViewById(R.id.filterlist_fragment_container).setVisibility(View.GONE);
}
if(editActivity == null) { if(editActivity == null) {
editActivity = new TaskEditActivity(); editActivity = new TaskEditActivity();
@ -157,6 +154,13 @@ public class AstridWrapperActivity extends FragmentActivity
transaction.add(R.id.taskedit_fragment_container, editActivity, TaskEditActivity.TAG_TASKEDIT_FRAGMENT); transaction.add(R.id.taskedit_fragment_container, editActivity, TaskEditActivity.TAG_TASKEDIT_FRAGMENT);
transaction.addToBackStack(null); transaction.addToBackStack(null);
transaction.commit(); transaction.commit();
runOnUiThread(new Runnable() {
@Override
public void run() {
// Force the transaction to occur so that we can be guaranteed of the fragment existing if we try to present it
getSupportFragmentManager().executePendingTransactions();
}
});
} }
editActivity.save(true); editActivity.save(true);

@ -4,8 +4,11 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ActionBar; import android.support.v4.app.ActionBar;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.PopupWindow.OnDismissListener; import android.widget.PopupWindow.OnDismissListener;
import android.widget.TextView; import android.widget.TextView;
@ -16,7 +19,7 @@ import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.ui.ListDropdownPopover; import com.todoroo.astrid.ui.FragmentPopover;
public class TaskListWrapperActivity extends AstridWrapperActivity { public class TaskListWrapperActivity extends AstridWrapperActivity {
@ -24,13 +27,14 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
private View listsNav; private View listsNav;
private TextView lists; private TextView lists;
private ListDropdownPopover popover; private FragmentPopover listsPopover;
private FragmentPopover editPopover;
private final OnClickListener popupMenuClickListener = new OnClickListener() { private final OnClickListener popupMenuClickListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setListsDropdownSelected(true); setListsDropdownSelected(true);
popover.show(v); listsPopover.show(v);
} }
}; };
/** /**
@ -70,6 +74,7 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
fragmentLayout = LAYOUT_TRIPLE; fragmentLayout = LAYOUT_TRIPLE;
} else { } else {
fragmentLayout = LAYOUT_DOUBLE; fragmentLayout = LAYOUT_DOUBLE;
createEditPopover();
} }
setupFragment(FilterListActivity.TAG_FILTERLIST_FRAGMENT, setupFragment(FilterListActivity.TAG_FILTERLIST_FRAGMENT,
@ -78,14 +83,14 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
fragmentLayout = LAYOUT_SINGLE; fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener); listsNav.setOnClickListener(popupMenuClickListener);
createPopover(); createListsPopover();
setupPopoverWithFilterList((FilterListActivity) setupFragment(FilterListActivity.TAG_FILTERLIST_FRAGMENT, 0, FilterListActivity.class)); setupPopoverWithFilterList((FilterListActivity) setupFragment(FilterListActivity.TAG_FILTERLIST_FRAGMENT, 0, FilterListActivity.class));
} }
} }
private void createPopover() { private void createListsPopover() {
popover = new ListDropdownPopover(TaskListWrapperActivity.this); listsPopover = new FragmentPopover(this, R.layout.list_dropdown_popover);
popover.setOnDismissListener(new OnDismissListener() { listsPopover.setOnDismissListener(new OnDismissListener() {
@Override @Override
public void onDismiss() { public void onDismiss() {
setListsDropdownSelected(false); setListsDropdownSelected(false);
@ -93,22 +98,52 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
}); });
} }
private void createEditPopover() {
editPopover = new FragmentPopover(this, R.layout.taskedit_popover);
editPopover.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss() {
TaskEditActivity tea = getTaskEditFragment();
if (tea != null)
tea.save(false);
}
});
}
private void setupPopoverWithFragment(FragmentPopover popover, Fragment frag, LayoutParams params) {
if (popover != null) {
View view = frag.getView();
if (view != null) {
FrameLayout parent = (FrameLayout) view.getParent();
if (parent != null)
parent.removeView(view);
if (params == null)
popover.setContent(view);
else
popover.setContent(view, params);
}
}
}
public void setupPopoverWithFilterList(FilterListActivity fla) { public void setupPopoverWithFilterList(FilterListActivity fla) {
if (popover != null) { setupPopoverWithFragment(listsPopover, fla, null);
View view = fla.getView(); }
if (view != null) {
FrameLayout parent = (FrameLayout) view.getParent(); @Override
if (parent != null) public void onTaskListItemClicked(long taskId) {
parent.removeView(view); super.onTaskListItemClicked(taskId);
popover.setContent(view); if (fragmentLayout == LAYOUT_DOUBLE && getTaskEditFragment() != null) {
} DisplayMetrics metrics = getResources().getDisplayMetrics();
setupPopoverWithFragment(editPopover, getTaskEditFragment(), new LayoutParams((int) (400 * metrics.density), (int) (600 * metrics.density)));
editPopover.show(listsNav);
} }
} }
@Override @Override
public boolean onFilterItemClicked(FilterListItem item) { public boolean onFilterItemClicked(FilterListItem item) {
if (popover != null) if (listsPopover != null)
popover.dismiss(); listsPopover.dismiss();
return super.onFilterItemClicked(item); return super.onFilterItemClicked(item);
} }
@ -132,8 +167,10 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
@Override @Override
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
if (popover != null) if (listsPopover != null)
popover.dismiss(); listsPopover.dismiss();
if (editPopover != null)
editPopover.dismiss();
} }
public void setSelectedItem(Filter item) { public void setSelectedItem(Filter item) {

@ -10,16 +10,17 @@ import android.graphics.Rect;
import android.view.View; import android.view.View;
import android.view.View.MeasureSpec; import android.view.View.MeasureSpec;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import com.timsu.astrid.R; import com.timsu.astrid.R;
public class ListDropdownPopover extends QuickActionWidget { public class FragmentPopover extends QuickActionWidget {
public ListDropdownPopover(Context context) { public FragmentPopover(Context context, int layout) {
super(context); super(context);
setContentView(R.layout.list_dropdown_popover); setContentView(layout);
setFocusable(true); setFocusable(true);
setTouchable(true); setTouchable(true);
@ -30,6 +31,11 @@ public class ListDropdownPopover extends QuickActionWidget {
contentContainer.addView(content); contentContainer.addView(content);
} }
public void setContent(View content, LayoutParams params) {
FrameLayout contentContainer = (FrameLayout) getContentView().findViewById(R.id.content);
contentContainer.addView(content, params);
}
@Override @Override
protected void populateQuickActions(List<QuickAction> quickActions) { protected void populateQuickActions(List<QuickAction> quickActions) {
// Do nothing // Do nothing
Loading…
Cancel
Save