mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Make the K9Activity GestureDetector more generic so that it can be used by both MessageList and MessageView.
Make the mTopView a ToggleScrollView. The only consumer is currently the MessageView, which uses a ToggleScrollView anyway. This should make it easier to reuse the anti-scrolling features in ToggleScrollView for ListView later on.
This commit is contained in:
parent
c89743635c
commit
edd78ea10c
@ -14,15 +14,15 @@ import android.view.View;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ScrollView;
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.helper.DateFormatter;
|
||||
import com.fsck.k9.view.ToggleScrollView;
|
||||
|
||||
|
||||
public class K9Activity extends Activity {
|
||||
private GestureDetector gestureDetector;
|
||||
|
||||
protected ScrollView mTopView;
|
||||
protected ToggleScrollView mTopView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@ -86,12 +86,26 @@ public class K9Activity extends Activity {
|
||||
public java.text.DateFormat getDateFormat() {
|
||||
return mDateFormat;
|
||||
}
|
||||
protected void onNext() {
|
||||
|
||||
}
|
||||
protected void onPrevious() {
|
||||
/**
|
||||
* Called when a swipe from right to left is handled by {@link MyGestureDetector}. See
|
||||
* {@link android.view.GestureDetector.OnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)}
|
||||
* for more information on the {@link MotionEvent}s being passed.
|
||||
* @param e1 First down motion event that started the fling.
|
||||
* @param e2 The move motion event that triggered the current onFling.
|
||||
*/
|
||||
protected void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a swipe from left to right is handled by {@link MyGestureDetector}. See
|
||||
* {@link android.view.GestureDetector.OnGestureListener#onFling(android.view.MotionEvent, android.view.MotionEvent, float, float)}
|
||||
* for more information on the {@link MotionEvent}s being passed.
|
||||
* @param e1 First down motion event that started the fling.
|
||||
* @param e2 The move motion event that triggered the current onFling.
|
||||
*/
|
||||
protected void onSwipeLeftToRight(final MotionEvent e1, final MotionEvent e2) {
|
||||
}
|
||||
|
||||
protected Animation inFromRightAnimation() {
|
||||
return slideAnimation(0.0f, +1.0f);
|
||||
@ -150,9 +164,9 @@ public class K9Activity extends Activity {
|
||||
return false;
|
||||
// right to left swipe
|
||||
if (e1.getX() - e2.getX() > min_distance && Math.abs(velocityX) > min_velocity) {
|
||||
onNext();
|
||||
onSwipeRightToLeft(e1, e2);
|
||||
} else if (e2.getX() - e1.getX() > min_distance && Math.abs(velocityX) > min_velocity) {
|
||||
onPrevious();
|
||||
onSwipeLeftToRight(e1, e2);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing
|
||||
|
@ -1660,22 +1660,25 @@ public class MessageList
|
||||
}
|
||||
}
|
||||
|
||||
class MyGestureDetector extends SimpleOnGestureListener {
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||
if (e2 == null || e1 == null)
|
||||
return true;
|
||||
protected void onSwipeRightToLeft(final MotionEvent e1, final MotionEvent e2) {
|
||||
// Handle right-to-left as an un-select
|
||||
handleSwipe(e1, false);
|
||||
}
|
||||
|
||||
float deltaX = e2.getX() - e1.getX(),
|
||||
deltaY = e2.getY() - e1.getY();
|
||||
|
||||
boolean movedAcross = (Math.abs(deltaX) > Math.abs(deltaY * 4));
|
||||
boolean steadyHand = (Math.abs(deltaX / deltaY) > 2);
|
||||
|
||||
if (movedAcross && steadyHand) {
|
||||
boolean selected = (deltaX > 0);
|
||||
int position = mListView.pointToPosition((int)e1.getX(), (int)e1.getY());
|
||||
@Override
|
||||
protected void onSwipeLeftToRight(final MotionEvent e1, final MotionEvent e2) {
|
||||
// Handle left-to-right as a select.
|
||||
handleSwipe(e1, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a select or unselect swipe event
|
||||
* @param downMotion Event that started the swipe
|
||||
* @param selected true if this was an attempt to select (i.e. left to right).
|
||||
*/
|
||||
private void handleSwipe(final MotionEvent downMotion, final boolean selected) {
|
||||
int position = mListView.pointToPosition((int) downMotion.getX(), (int) downMotion.getY());
|
||||
if (position != AdapterView.INVALID_POSITION) {
|
||||
MessageInfoHolder msgInfoHolder = (MessageInfoHolder) mAdapter.getItem(position);
|
||||
|
||||
@ -1688,10 +1691,6 @@ public class MessageList
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
|
@ -82,7 +82,6 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
private View mArchive;
|
||||
private View mMove;
|
||||
private View mSpam;
|
||||
private ToggleScrollView mToggleScrollView;
|
||||
private Account mAccount;
|
||||
private MessageReference mMessageReference;
|
||||
private ArrayList<MessageReference> mMessageReferences;
|
||||
@ -132,14 +131,14 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if (ev.getAction() == MotionEvent.ACTION_UP) {
|
||||
// Text selection is finished. Allow scrolling again.
|
||||
mToggleScrollView.setScrolling(true);
|
||||
mTopView.setScrolling(true);
|
||||
} else if (K9.zoomControlsEnabled()) {
|
||||
// If we have system zoom controls enabled, disable scrolling so the screen isn't wiggling around while
|
||||
// trying to zoom.
|
||||
if (ev.getAction() == MotionEvent.ACTION_POINTER_2_DOWN) {
|
||||
mToggleScrollView.setScrolling(false);
|
||||
mTopView.setScrolling(false);
|
||||
} else if (ev.getAction() == MotionEvent.ACTION_POINTER_2_UP) {
|
||||
mToggleScrollView.setScrolling(true);
|
||||
mTopView.setScrolling(true);
|
||||
}
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
@ -187,7 +186,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
* Selecting text started via shift key. Disable scrolling as
|
||||
* this causes problems when selecting text.
|
||||
*/
|
||||
mToggleScrollView.setScrolling(false);
|
||||
mTopView.setScrolling(false);
|
||||
break;
|
||||
}
|
||||
case KeyEvent.KEYCODE_DEL: {
|
||||
@ -379,7 +378,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setContentView(R.layout.message_view);
|
||||
|
||||
mTopView = mToggleScrollView = (ToggleScrollView) findViewById(R.id.top_view);
|
||||
mTopView = (ToggleScrollView) findViewById(R.id.top_view);
|
||||
mMessageView = (SingleMessageView) findViewById(R.id.message_view);
|
||||
|
||||
//set a callback for the attachment view. With this callback the attachmentview
|
||||
@ -871,7 +870,22 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a right-to-left swipe as "move to next message."
|
||||
*/
|
||||
@Override
|
||||
protected void onSwipeRightToLeft(MotionEvent e1, MotionEvent e2) {
|
||||
onNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a left-to-right swipe as "move to previous message."
|
||||
*/
|
||||
@Override
|
||||
protected void onSwipeLeftToRight(MotionEvent e1, MotionEvent e2) {
|
||||
onPrevious();
|
||||
}
|
||||
|
||||
protected void onNext() {
|
||||
if (mNextMessage == null) {
|
||||
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
|
||||
@ -886,7 +900,6 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
mNext.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrevious() {
|
||||
if (mPreviousMessage == null) {
|
||||
Toast.makeText(this, getString(R.string.end_of_folder), Toast.LENGTH_SHORT).show();
|
||||
@ -1019,7 +1032,7 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
});
|
||||
break;
|
||||
case R.id.select_text:
|
||||
mToggleScrollView.setScrolling(false);
|
||||
mTopView.setScrolling(false);
|
||||
mMessageView.beginSelectingText();
|
||||
break;
|
||||
default:
|
||||
|
@ -240,7 +240,6 @@ public class AccountSetupBasics extends K9Activity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNext() {
|
||||
String email = mEmailView.getText().toString();
|
||||
String[] emailParts = splitEmail(email);
|
||||
|
@ -385,7 +385,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNext() {
|
||||
try {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
|
@ -79,7 +79,6 @@ public class AccountSetupNames extends K9Activity implements OnClickListener {
|
||||
Utility.setCompoundDrawablesAlpha(mDoneButton, mDoneButton.isEnabled() ? 255 : 128);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNext() {
|
||||
if (Utility.requiredFieldValid(mDescription)) {
|
||||
mAccount.setDescription(mDescription.getText().toString());
|
||||
|
@ -285,7 +285,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNext() {
|
||||
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||
URI uri;
|
||||
|
Loading…
Reference in New Issue
Block a user