'Back' bezel gesture to leave story list view. (#249)

This commit is contained in:
dosiecki 2014-02-28 15:35:08 -08:00
parent 952def6542
commit cf8adff271
8 changed files with 49 additions and 4 deletions

View file

@ -38,10 +38,9 @@ public abstract class ItemsList extends NbFragmentActivity implements ActionComp
protected ItemListFragment itemListFragment;
protected FragmentManager fragmentManager;
protected int currentState;
private Menu menu;
protected boolean stopLoading = false;
@Override
protected void onCreate(Bundle bundle) {
requestWindowFeature(Window.FEATURE_PROGRESS);
@ -54,7 +53,6 @@ public abstract class ItemsList extends NbFragmentActivity implements ActionComp
// our intel state is entirely determined by the state of the Main view
currentState = getIntent().getIntExtra(EXTRA_STATE, 0);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
protected void onResume() {

View file

@ -57,6 +57,7 @@ public class AllSharedStoriesItemListFragment extends ItemListFragment implement
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
contentResolver = getActivity().getContentResolver();
@ -109,6 +110,7 @@ public class AllSharedStoriesItemListFragment extends ItemListFragment implement
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), AllSharedStoriesReading.class);
i.putExtra(FeedReading.EXTRA_FEED_IDS, feedIds);
i.putExtra(FeedReading.EXTRA_POSITION, position);

View file

@ -54,6 +54,7 @@ public class AllStoriesItemListFragment extends ItemListFragment implements Load
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
@ -108,6 +109,7 @@ public class AllStoriesItemListFragment extends ItemListFragment implements Load
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), AllStoriesReading.class);
i.putExtra(FeedReading.EXTRA_FEED_IDS, feedIds);
i.putExtra(FeedReading.EXTRA_POSITION, position);

View file

@ -63,8 +63,9 @@ public class FeedItemListFragment extends ItemListFragment implements LoaderMana
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
ContentResolver contentResolver = getActivity().getContentResolver();
@ -127,6 +128,7 @@ public class FeedItemListFragment extends ItemListFragment implements LoaderMana
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), FeedReading.class);
i.putExtra(Reading.EXTRA_FEED, feedId);
i.putExtra(FeedReading.EXTRA_POSITION, position);

View file

@ -75,6 +75,7 @@ public class FolderItemListFragment extends ItemListFragment implements LoaderMa
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
@ -119,6 +120,7 @@ public class FolderItemListFragment extends ItemListFragment implements LoaderMa
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), FolderReading.class);
i.putExtra(FeedReading.EXTRA_FEED_IDS, feedIds);
i.putExtra(FeedReading.EXTRA_POSITION, position);

View file

@ -8,9 +8,13 @@ import android.support.v4.app.Fragment;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.ContextMenu;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AbsListView;
@ -145,4 +149,35 @@ public abstract class ItemListFragment extends Fragment implements OnScrollListe
return super.onContextItemSelected(item);
}
}
protected void setupBezelSwipeDetector(View v) {
final GestureDetector gestureDetector = new GestureDetector(getActivity(), new BezelSwipeDetector());
v.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}
/**
* A gesture detector that captures bezel swipes and finishes the activity,
* to simulate a 'back' gesture.
*
* NB: pretty much all Views still try to process on-tap events despite
* returning true, so be sure to check isFinishing() on all other
* tap handlers.
*/
class BezelSwipeDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if((e1.getX() < 75f) && // the gesture should start from the left bezel and
((e2.getX()-e1.getX()) > 90f) && // move horizontally to the right and
(Math.abs(e1.getY()-e2.getY()) < 40f) // have minimal vertical travel, so we don't capture scrolling gestures
) {
ItemListFragment.this.getActivity().finish();
return true;
}
return false;
}
}
}

View file

@ -46,6 +46,7 @@ public class SavedStoriesItemListFragment extends ItemListFragment implements Lo
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
ListView itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
@ -95,6 +96,7 @@ public class SavedStoriesItemListFragment extends ItemListFragment implements Lo
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), SavedStoriesReading.class);
i.putExtra(FeedReading.EXTRA_POSITION, position);
i.putExtra(Reading.EXTRA_DEFAULT_FEED_VIEW, defaultFeedView);

View file

@ -91,6 +91,7 @@ public class SocialFeedItemListFragment extends ItemListFragment implements Load
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_itemlist, null);
itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
setupBezelSwipeDetector(itemList);
itemList.setEmptyView(v.findViewById(R.id.empty_view));
itemList.setOnScrollListener(this);
@ -122,6 +123,7 @@ public class SocialFeedItemListFragment extends ItemListFragment implements Load
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (getActivity().isFinishing()) return;
Intent i = new Intent(getActivity(), SocialFeedReading.class);
i.putExtra(Reading.EXTRA_USERID, userId);
i.putExtra(Reading.EXTRA_USERNAME, username);