mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 19:38:52 +01:00
Remove slidingmenu
This commit is contained in:
@@ -12,6 +12,7 @@ import com.moez.QKSMS.ui.MainActivity;
|
||||
import com.moez.QKSMS.ui.base.QKActivity;
|
||||
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
|
||||
import com.moez.QKSMS.ui.dialog.QKDialog;
|
||||
import com.moez.QKSMS.ui.messagelist.MessageListActivity;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -30,7 +31,7 @@ public class DialogHelper {
|
||||
showDeleteConversationsDialog(context, threadIds);
|
||||
}
|
||||
|
||||
public static void showDeleteConversationsDialog(final MainActivity context, final Set<Long> threadIds) {
|
||||
public static void showDeleteConversationsDialog(final QKActivity context, final Set<Long> threadIds) {
|
||||
new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null);
|
||||
|
||||
Set<Long> threads = new HashSet<>(threadIds); // Make a copy so the list isn't reset when multi-select is disabled
|
||||
@@ -43,7 +44,9 @@ public class DialogHelper {
|
||||
Conversation.ConversationQueryHandler handler = new Conversation.ConversationQueryHandler(context.getContentResolver());
|
||||
Conversation.startDelete(handler, 0, false, threads);
|
||||
Conversation.asyncDeleteObsoleteThreads(handler, 0);
|
||||
context.showMenu();
|
||||
if (context instanceof MessageListActivity) {
|
||||
context.onBackPressed();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
|
||||
@@ -32,7 +32,6 @@ public enum QKPreference {
|
||||
AVATAR_RECEIVED("pref_key_avatar_received", true),
|
||||
|
||||
MESSAGE_COUNT("pref_key_message_count", false),
|
||||
SLIDING_TAB("pref_key_sliding_tab", false),
|
||||
TIMESTAMPS_24H("pref_key_24h", false),
|
||||
|
||||
// General
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -32,9 +31,7 @@ import com.moez.QKSMS.common.DonationManager;
|
||||
import com.moez.QKSMS.common.LiveViewManager;
|
||||
import com.moez.QKSMS.common.QKRateSnack;
|
||||
import com.moez.QKSMS.common.google.DraftCache;
|
||||
import com.moez.QKSMS.common.utils.KeyboardUtils;
|
||||
import com.moez.QKSMS.common.utils.MessageUtils;
|
||||
import com.moez.QKSMS.common.utils.Units;
|
||||
import com.moez.QKSMS.data.Conversation;
|
||||
import com.moez.QKSMS.enums.QKPreference;
|
||||
import com.moez.QKSMS.receiver.IconColorReceiver;
|
||||
@@ -50,7 +47,6 @@ import com.moez.QKSMS.ui.messagelist.MessageListFragment;
|
||||
import com.moez.QKSMS.ui.popup.QKReplyActivity;
|
||||
import com.moez.QKSMS.ui.search.SearchActivity;
|
||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||
import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu;
|
||||
import com.moez.QKSMS.ui.welcome.WelcomeActivity;
|
||||
import org.ligi.snackengage.SnackEngage;
|
||||
import org.ligi.snackengage.snacks.BaseSnack;
|
||||
@@ -58,7 +54,7 @@ import org.ligi.snackengage.snacks.BaseSnack;
|
||||
import java.util.Collection;
|
||||
|
||||
|
||||
public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuListener {
|
||||
public class MainActivity extends QKActivity {
|
||||
private final String TAG = "MainActivity";
|
||||
|
||||
public final static String EXTRA_THREAD_ID = "thread_id";
|
||||
@@ -74,7 +70,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
public static final String MMS_SETUP_DONT_ASK_AGAIN = "mmsSetupDontAskAgain";
|
||||
|
||||
@Bind(R.id.root) View mRoot;
|
||||
@Bind(R.id.sliding_menu) SlidingMenu mSlidingMenu;
|
||||
|
||||
private ConversationListFragment mConversationList;
|
||||
private ContentFragment mContent;
|
||||
@@ -92,25 +87,18 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
super.onCreate(savedInstanceState);
|
||||
launchWelcomeActivity();
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
setContentView(R.layout.activity_fragment);
|
||||
setTitle(R.string.title_conversation_list);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false));
|
||||
mSlidingMenu.setListener(this);
|
||||
mSlidingMenu.setContent();
|
||||
mSlidingMenu.setMenu();
|
||||
mSlidingMenu.showContent(false);
|
||||
mSlidingMenu.showMenu(false);
|
||||
|
||||
FragmentManager fm = getFragmentManager();
|
||||
|
||||
mConversationList = (ConversationListFragment) fm.findFragmentById(R.id.menu_frame);
|
||||
mConversationList = (ConversationListFragment) fm.findFragmentById(R.id.content_frame);
|
||||
if (mConversationList == null) {
|
||||
mConversationList = new ConversationListFragment();
|
||||
}
|
||||
FragmentTransaction menuTransaction = fm.beginTransaction();
|
||||
menuTransaction.replace(R.id.menu_frame, mConversationList);
|
||||
menuTransaction.replace(R.id.content_frame, mConversationList);
|
||||
menuTransaction.commit();
|
||||
|
||||
onNewIntent(getIntent());
|
||||
@@ -178,39 +166,13 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
startActivityForResult(welcomeIntent, WelcomeActivity.WELCOME_REQUEST_CODE);
|
||||
}
|
||||
|
||||
public void showMenu() {
|
||||
mSlidingMenu.showMenu();
|
||||
}
|
||||
|
||||
public SlidingMenu getSlidingMenu() {
|
||||
return mSlidingMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configured the sliding menu view to peek the content or not.
|
||||
*
|
||||
* @param slidingTabEnabled true to peek the content
|
||||
*/
|
||||
public void setSlidingTabEnabled(boolean slidingTabEnabled) {
|
||||
if (slidingTabEnabled) {
|
||||
mSlidingMenu.setBehindOffset(Units.dpToPx(this, 48));
|
||||
} else {
|
||||
mSlidingMenu.setBehindOffset(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
menu.clear();
|
||||
|
||||
if (mSlidingMenu.isMenuShowing() || mContent == null) {
|
||||
showBackButton(false);
|
||||
mConversationList.inflateToolbar(menu, inflater, this);
|
||||
} else {
|
||||
showBackButton(true);
|
||||
mContent.inflateToolbar(menu, inflater, this);
|
||||
}
|
||||
showBackButton(false);
|
||||
mConversationList.inflateToolbar(menu, inflater, this);
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
@@ -283,15 +245,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (!mSlidingMenu.isMenuShowing()) {
|
||||
mSlidingMenu.showMenu();
|
||||
return true;
|
||||
if (mConversationList.isShowingBlocked()) {
|
||||
mConversationList.setShowingBlocked(false);
|
||||
} else {
|
||||
if (mConversationList.isShowingBlocked()) {
|
||||
mConversationList.setShowingBlocked(false);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,9 +259,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
sThreadShowing = 0;
|
||||
if (!mSlidingMenu.isMenuShowing()) {
|
||||
mContent.onContentClosed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -324,10 +278,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (!mSlidingMenu.isMenuShowing()) {
|
||||
mContent.onContentOpened();
|
||||
}
|
||||
|
||||
if (mContent != null && mContent instanceof MessageListFragment) {
|
||||
sThreadShowing = ((MessageListFragment) mContent).getThreadId();
|
||||
QKReplyActivity.dismiss(sThreadShowing);
|
||||
@@ -373,84 +323,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL
|
||||
}
|
||||
}
|
||||
|
||||
public void switchContent(ContentFragment fragment, boolean animate) {
|
||||
// Make sure that the activity isn't destroyed before making fragment transactions.
|
||||
if (fragment != null && !mIsDestroyed) {
|
||||
KeyboardUtils.hide(this);
|
||||
|
||||
mContent = fragment;
|
||||
FragmentManager m = getFragmentManager();
|
||||
|
||||
// Only do a replace if it is a different fragment.
|
||||
if (fragment != m.findFragmentById(R.id.content_frame)) {
|
||||
getFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.content_frame, (Fragment) fragment)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
mSlidingMenu.showContent(animate);
|
||||
invalidateOptionsMenu();
|
||||
|
||||
} else {
|
||||
Log.w(TAG, "Null fragment, can't switch content");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen() {
|
||||
invalidateOptionsMenu();
|
||||
sThreadShowing = 0;
|
||||
|
||||
// Notify the content that it is being closed, since the menu (i.e. conversation list) is being opened.
|
||||
if (mContent != null) mContent.onContentClosing();
|
||||
|
||||
// Hide the soft keyboard
|
||||
KeyboardUtils.hide(this, getCurrentFocus());
|
||||
|
||||
showBackButton(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
invalidateOptionsMenu();
|
||||
|
||||
// Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed.
|
||||
if (mContent != null) {
|
||||
mContent.onContentOpening();
|
||||
}
|
||||
|
||||
if (mContent != null && mContent instanceof MessageListFragment) {
|
||||
sThreadShowing = ((MessageListFragment) mContent).getThreadId();
|
||||
} else {
|
||||
sThreadShowing = 0;
|
||||
}
|
||||
|
||||
// Hide the soft keyboard
|
||||
KeyboardUtils.hide(this, getCurrentFocus());
|
||||
|
||||
showBackButton(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpened() {
|
||||
// When the menu (i.e. the conversation list) has been opened, the content has been opened.
|
||||
// So notify the content fragment.
|
||||
if (mContent != null) mContent.onContentClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed() {
|
||||
// When the menu (i.e. the conversation list) has been closed, the content has been opened.
|
||||
// So notify the content fragment.
|
||||
if (mContent != null && ((Fragment) mContent).isAdded()) mContent.onContentOpened();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanging(float percentOpen) {
|
||||
if (mContent != null) mContent.onMenuChanging(percentOpen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and show the proper delete thread dialog. The UI is slightly different
|
||||
* depending on whether there are locked messages in the thread(s) and whether we're
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.moez.QKSMS.common.utils.PhoneNumberUtils;
|
||||
import com.moez.QKSMS.interfaces.ActivityLauncher;
|
||||
import com.moez.QKSMS.interfaces.RecipientProvider;
|
||||
import com.moez.QKSMS.mmssms.Utils;
|
||||
import com.moez.QKSMS.ui.MainActivity;
|
||||
import com.moez.QKSMS.ui.base.QKFragment;
|
||||
import com.moez.QKSMS.ui.messagelist.MessageListActivity;
|
||||
import com.moez.QKSMS.ui.view.AutoCompleteContactView;
|
||||
@@ -59,10 +58,10 @@ public class ComposeFragment extends QKFragment implements ActivityLauncher, Rec
|
||||
@Override
|
||||
public void onSend(String[] recipients, String body) {
|
||||
long threadId = Utils.getOrCreateThreadId(mContext, recipients[0]);
|
||||
if (recipients.length == 1) {
|
||||
if (threadId != 0) {
|
||||
MessageListActivity.launch(mContext, threadId, -1, null, true);
|
||||
} else {
|
||||
((MainActivity) mContext).showMenu();
|
||||
mContext.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -964,9 +964,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
||||
conv.clearThreadId();
|
||||
conv.setDraftState(false);
|
||||
}
|
||||
// The last message in this converation was just deleted. Send the user
|
||||
// to the conversation list.
|
||||
((MainActivity) mContext).showMenu();
|
||||
mContext.onBackPressed();
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
@@ -1009,7 +1007,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
|
||||
Conversation.init(mContext);
|
||||
|
||||
// Go back to the conversation list
|
||||
((MainActivity) mContext).showMenu();
|
||||
mContext.onBackPressed();
|
||||
} else if (token == DELETE_MESSAGE_TOKEN) {
|
||||
// Check to see if we just deleted the last message
|
||||
startMsgListQuery(MESSAGE_LIST_QUERY_AFTER_DELETE_TOKEN);
|
||||
|
||||
@@ -99,7 +99,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
||||
public static final String FONT_SIZE = "pref_key_font_size";
|
||||
public static final String FONT_WEIGHT = "pref_key_font_weight";
|
||||
public static final String MESSAGE_COUNT = "pref_key_message_count";
|
||||
public static final String SLIDING_TAB = "pref_key_sliding_tab";
|
||||
public static final String PROXIMITY_CALLING = "pref_key_prox_sensor_calling";
|
||||
public static final String DELIVERY_REPORTS = "pref_key_delivery";
|
||||
public static final String DELIVERY_TOAST = "pref_key_delivery_toast";
|
||||
|
||||
@@ -1,866 +0,0 @@
|
||||
package com.moez.QKSMS.ui.view.slidingmenu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.v4.view.KeyEventCompat;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v4.view.VelocityTrackerCompat;
|
||||
import android.support.v4.view.ViewConfigurationCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.FloatMath;
|
||||
import android.util.Log;
|
||||
import android.view.FocusFinder;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.SoundEffectConstants;
|
||||
import android.view.VelocityTracker;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Scroller;
|
||||
|
||||
public class CustomViewAbove extends ViewGroup {
|
||||
|
||||
private static final String TAG = "CustomViewAbove";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final boolean USE_CACHE = false;
|
||||
|
||||
private static final int MAX_SETTLE_DURATION = 350; // ms
|
||||
private static final int MIN_DISTANCE_FOR_FLING = 25; // dips
|
||||
|
||||
private static final Interpolator sInterpolator = t -> (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f;
|
||||
|
||||
private View mContent;
|
||||
|
||||
private int mCurItem;
|
||||
private Scroller mScroller;
|
||||
|
||||
private boolean mScrollingCacheEnabled;
|
||||
|
||||
private boolean mScrolling;
|
||||
|
||||
private boolean mIsBeingDragged;
|
||||
private boolean mIsUnableToDrag;
|
||||
private int mTouchSlop;
|
||||
private float mInitialMotionX;
|
||||
/**
|
||||
* Position of the last motion event.
|
||||
*/
|
||||
private float mLastMotionX;
|
||||
private float mLastMotionY;
|
||||
/**
|
||||
* ID of the active pointer. This is used to retain consistency during
|
||||
* drags/flings if multiple pointers are used.
|
||||
*/
|
||||
protected int mActivePointerId = INVALID_POINTER;
|
||||
/**
|
||||
* Sentinel value for no current active pointer.
|
||||
* Used by {@link #mActivePointerId}.
|
||||
*/
|
||||
private static final int INVALID_POINTER = -1;
|
||||
|
||||
/**
|
||||
* Determines speed during touch scrolling
|
||||
*/
|
||||
protected VelocityTracker mVelocityTracker;
|
||||
private int mMinimumVelocity;
|
||||
protected int mMaximumVelocity;
|
||||
private int mFlingDistance;
|
||||
|
||||
private CustomViewBehind mViewBehind;
|
||||
|
||||
private OnPageChangeListener mOnPageChangeListener;
|
||||
private OnPageChangeListener mInternalPageChangeListener;
|
||||
|
||||
private SlidingMenu.SlidingMenuListener mListener;
|
||||
|
||||
/**
|
||||
* Callback interface for responding to changing state of the selected page.
|
||||
*/
|
||||
public interface OnPageChangeListener {
|
||||
|
||||
/**
|
||||
* This method will be invoked when the current page is scrolled, either as part
|
||||
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
|
||||
*
|
||||
* @param position Position index of the first page currently being displayed.
|
||||
* Page position+1 will be visible if positionOffset is nonzero.
|
||||
* @param positionOffset Value from [0, 1) indicating the offset from the page at position.
|
||||
* @param positionOffsetPixels Value in pixels indicating the offset from position.
|
||||
*/
|
||||
void onPageScrolled(int position, float positionOffset, int positionOffsetPixels);
|
||||
|
||||
/**
|
||||
* This method will be invoked when a new page becomes selected. Animation is not
|
||||
* necessarily complete.
|
||||
*
|
||||
* @param position Position index of the new selected page.
|
||||
*/
|
||||
void onPageSelected(int position, boolean anim);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple implementation of the {@link OnPageChangeListener} interface with stub
|
||||
* implementations of each method. Extend this if you do not intend to override
|
||||
* every method of {@link OnPageChangeListener}.
|
||||
*/
|
||||
public static class SimpleOnPageChangeListener implements OnPageChangeListener {
|
||||
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
// This space for rent
|
||||
}
|
||||
|
||||
public void onPageSelected(int position, boolean anim) {
|
||||
// This space for rent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CustomViewAbove(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CustomViewAbove(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initCustomViewAbove();
|
||||
}
|
||||
|
||||
void initCustomViewAbove() {
|
||||
setWillNotDraw(false);
|
||||
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
|
||||
setFocusable(true);
|
||||
final Context context = getContext();
|
||||
mScroller = new Scroller(context, sInterpolator);
|
||||
final ViewConfiguration configuration = ViewConfiguration.get(context);
|
||||
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
|
||||
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
|
||||
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
|
||||
setInternalPageChangeListener(new SimpleOnPageChangeListener() {
|
||||
public void onPageSelected(int position, boolean anim) {
|
||||
if (mViewBehind != null) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
case 2:
|
||||
mViewBehind.setChildrenEnabled(true);
|
||||
break;
|
||||
case 1:
|
||||
mViewBehind.setChildrenEnabled(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final float density = context.getResources().getDisplayMetrics().density;
|
||||
mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently selected page. If the CustomViewPager has already been through its first
|
||||
* layout there will be a smooth animated transition between the current item and the
|
||||
* specified item.
|
||||
*
|
||||
* @param item Item index to select
|
||||
*/
|
||||
public void setCurrentItem(int item) {
|
||||
setCurrentItem(item, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently selected page.
|
||||
*
|
||||
* @param item Item index to select
|
||||
* @param smoothScroll True to smoothly scroll to the new item, false to transition immediately
|
||||
*/
|
||||
public void setCurrentItem(int item, boolean smoothScroll) {
|
||||
setCurrentItem(item, smoothScroll, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently selected page.
|
||||
*
|
||||
* @param item Item index to select
|
||||
* @param smoothScroll True to smoothly scroll to the new item, false to transition immediately
|
||||
* @param notify True if the open and close listeners should be notified.
|
||||
*/
|
||||
public void setCurrentItem(int item, boolean smoothScroll, boolean notify) {
|
||||
setCurrentItemInternal(item, smoothScroll, false, 0, notify);
|
||||
}
|
||||
|
||||
public int getCurrentItem() {
|
||||
return mCurItem;
|
||||
}
|
||||
|
||||
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always) {
|
||||
setCurrentItemInternal(item, smoothScroll, always, 0);
|
||||
}
|
||||
|
||||
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
|
||||
setCurrentItemInternal(item, smoothScroll, always, velocity, false);
|
||||
}
|
||||
|
||||
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity, boolean notify) {
|
||||
if (!always && mCurItem == item) {
|
||||
setScrollingCacheEnabled(false);
|
||||
|
||||
if (notify) {
|
||||
// Notify the listeners here, because the client has switched content.
|
||||
if (isMenuOpen()) {
|
||||
if (mListener != null)
|
||||
mListener.onOpened();
|
||||
} else {
|
||||
if (mListener != null)
|
||||
mListener.onClosed();
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
item = mViewBehind.getMenuPage(item);
|
||||
|
||||
final boolean dispatchSelected = mCurItem != item;
|
||||
mCurItem = item;
|
||||
final int destX = getDestScrollX(mCurItem);
|
||||
if (dispatchSelected && mOnPageChangeListener != null) {
|
||||
mOnPageChangeListener.onPageSelected(item, smoothScroll);
|
||||
}
|
||||
if (dispatchSelected && mInternalPageChangeListener != null) {
|
||||
mInternalPageChangeListener.onPageSelected(item, smoothScroll);
|
||||
}
|
||||
if (smoothScroll) {
|
||||
smoothScrollTo(destX, 0, velocity);
|
||||
} else {
|
||||
completeScroll();
|
||||
scrollTo(destX, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a listener that will be invoked whenever the page changes or is incrementally
|
||||
* scrolled. See {@link OnPageChangeListener}.
|
||||
*
|
||||
* @param listener Listener to set
|
||||
*/
|
||||
public void setOnPageChangeListener(OnPageChangeListener listener) {
|
||||
mOnPageChangeListener = listener;
|
||||
}
|
||||
|
||||
public void setListener(SlidingMenu.SlidingMenuListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a separate OnPageChangeListener for internal use by the support library.
|
||||
*
|
||||
* @param listener Listener to set
|
||||
* @return The old listener that was set, if any.
|
||||
*/
|
||||
OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener) {
|
||||
OnPageChangeListener oldListener = mInternalPageChangeListener;
|
||||
mInternalPageChangeListener = listener;
|
||||
return oldListener;
|
||||
}
|
||||
|
||||
// We want the duration of the page snap animation to be influenced by the distance that
|
||||
// the screen has to travel, however, we don't want this duration to be effected in a
|
||||
// purely linear fashion. Instead, we use this method to moderate the effect that the distance
|
||||
// of travel has on the overall snap duration.
|
||||
float distanceInfluenceForSnapDuration(float f) {
|
||||
f -= 0.5f; // center the values about 0.
|
||||
f *= 0.3f * Math.PI / 2.0f;
|
||||
return FloatMath.sin(f);
|
||||
}
|
||||
|
||||
public int getDestScrollX(int page) {
|
||||
switch (page) {
|
||||
case 0:
|
||||
case 2:
|
||||
return mViewBehind.getMenuLeft(mContent, page);
|
||||
case 1:
|
||||
return mContent.getLeft();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getLeftBound() {
|
||||
return mViewBehind.getAbsLeftBound(mContent);
|
||||
}
|
||||
|
||||
private int getRightBound() {
|
||||
return mViewBehind.getAbsRightBound(mContent);
|
||||
}
|
||||
|
||||
public boolean isMenuOpen() {
|
||||
return mCurItem == 0 || mCurItem == 2;
|
||||
}
|
||||
|
||||
public int getBehindWidth() {
|
||||
if (mViewBehind == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return mViewBehind.getBehindWidth();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link View#scrollBy}, but scroll smoothly instead of immediately.
|
||||
*
|
||||
* @param x the number of pixels to scroll by on the X axis
|
||||
* @param y the number of pixels to scroll by on the Y axis
|
||||
* @param velocity the velocity associated with a fling, if applicable. (0 otherwise)
|
||||
*/
|
||||
void smoothScrollTo(int x, int y, int velocity) {
|
||||
if (getChildCount() == 0) {
|
||||
// Nothing to do.
|
||||
setScrollingCacheEnabled(false);
|
||||
return;
|
||||
}
|
||||
int sx = getScrollX();
|
||||
int sy = getScrollY();
|
||||
int dx = x - sx;
|
||||
int dy = y - sy;
|
||||
if (dx == 0 && dy == 0) {
|
||||
completeScroll();
|
||||
if (isMenuOpen()) {
|
||||
if (mListener != null)
|
||||
mListener.onOpened();
|
||||
} else {
|
||||
if (mListener != null)
|
||||
mListener.onClosed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setScrollingCacheEnabled(true);
|
||||
mScrolling = true;
|
||||
|
||||
final int width = getBehindWidth();
|
||||
final int halfWidth = width / 2;
|
||||
final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width);
|
||||
final float distance = halfWidth + halfWidth *
|
||||
distanceInfluenceForSnapDuration(distanceRatio);
|
||||
|
||||
int duration = 0;
|
||||
velocity = Math.abs(velocity);
|
||||
if (velocity > 0) {
|
||||
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
|
||||
} else {
|
||||
duration = MAX_SETTLE_DURATION;
|
||||
}
|
||||
duration = Math.min(duration, MAX_SETTLE_DURATION);
|
||||
|
||||
mScroller.startScroll(sx, sy, dx, dy, duration);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setContent(View v) {
|
||||
if (mContent != null)
|
||||
this.removeView(mContent);
|
||||
mContent = v;
|
||||
addView(mContent);
|
||||
}
|
||||
|
||||
public View getContent() {
|
||||
return mContent;
|
||||
}
|
||||
|
||||
public void setCustomViewBehind(CustomViewBehind cvb) {
|
||||
mViewBehind = cvb;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
|
||||
int width = getDefaultSize(0, widthMeasureSpec);
|
||||
int height = getDefaultSize(0, heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
|
||||
final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width);
|
||||
final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
|
||||
mContent.measure(contentWidth, contentHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
// Make sure scroll position is set correctly.
|
||||
if (w != oldw) {
|
||||
// [ChrisJ] - This fixes the onConfiguration change for orientation issue..
|
||||
// maybe worth having a look why the recomputeScroll pos is screwing up?
|
||||
completeScroll();
|
||||
scrollTo(getDestScrollX(mCurItem), getScrollY());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int width = r - l;
|
||||
final int height = b - t;
|
||||
mContent.layout(0, 0, width, height);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void computeScroll() {
|
||||
if (!mScroller.isFinished()) {
|
||||
if (mScroller.computeScrollOffset()) {
|
||||
int oldX = getScrollX();
|
||||
int oldY = getScrollY();
|
||||
int x = mScroller.getCurrX();
|
||||
int y = mScroller.getCurrY();
|
||||
|
||||
if (oldX != x || oldY != y) {
|
||||
scrollTo(x, y);
|
||||
pageScrolled(x);
|
||||
}
|
||||
|
||||
// Keep on drawing until the animation has finished.
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Done with scroll, clean up state.
|
||||
completeScroll();
|
||||
}
|
||||
|
||||
private void pageScrolled(int xpos) {
|
||||
final int widthWithMargin = getWidth();
|
||||
final int position = xpos / widthWithMargin;
|
||||
final int offsetPixels = xpos % widthWithMargin;
|
||||
final float offset = (float) offsetPixels / widthWithMargin;
|
||||
|
||||
onPageScrolled(position, offset, offsetPixels);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be invoked when the current page is scrolled, either as part
|
||||
* of a programmatically initiated smooth scroll or a user initiated touch scroll.
|
||||
* If you override this method you must call through to the superclass implementation
|
||||
* (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
|
||||
* returns.
|
||||
*
|
||||
* @param position Position index of the first page currently being displayed.
|
||||
* Page position+1 will be visible if positionOffset is nonzero.
|
||||
* @param offset Value from [0, 1) indicating the offset from the page at position.
|
||||
* @param offsetPixels Value in pixels indicating the offset from position.
|
||||
*/
|
||||
protected void onPageScrolled(int position, float offset, int offsetPixels) {
|
||||
if (mOnPageChangeListener != null) {
|
||||
mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
|
||||
}
|
||||
if (mInternalPageChangeListener != null) {
|
||||
mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
|
||||
}
|
||||
}
|
||||
|
||||
private void completeScroll() {
|
||||
boolean needPopulate = mScrolling;
|
||||
if (needPopulate) {
|
||||
// Done with scroll, no longer want to cache view drawing.
|
||||
setScrollingCacheEnabled(false);
|
||||
mScroller.abortAnimation();
|
||||
int oldX = getScrollX();
|
||||
int oldY = getScrollY();
|
||||
int x = mScroller.getCurrX();
|
||||
int y = mScroller.getCurrY();
|
||||
if (oldX != x || oldY != y) {
|
||||
scrollTo(x, y);
|
||||
}
|
||||
if (isMenuOpen()) {
|
||||
if (mListener != null)
|
||||
mListener.onOpened();
|
||||
} else {
|
||||
if (mListener != null)
|
||||
mListener.onClosed();
|
||||
}
|
||||
}
|
||||
mScrolling = false;
|
||||
}
|
||||
|
||||
private boolean thisTouchAllowed(MotionEvent ev) {
|
||||
return !isMenuOpen();
|
||||
}
|
||||
|
||||
private boolean thisSlideAllowed(float dx) {
|
||||
boolean allowed;
|
||||
if (isMenuOpen()) {
|
||||
allowed = mViewBehind.menuOpenSlideAllowed(dx);
|
||||
} else {
|
||||
allowed = mViewBehind.menuClosedSlideAllowed(dx);
|
||||
}
|
||||
if (DEBUG)
|
||||
Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx);
|
||||
return allowed;
|
||||
}
|
||||
|
||||
private int getPointerIndex(MotionEvent ev, int id) {
|
||||
int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id);
|
||||
if (activePointerIndex == -1)
|
||||
mActivePointerId = INVALID_POINTER;
|
||||
return activePointerIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the user has tapped DOWN, and so tapping UP means that the drawer should open.
|
||||
*/
|
||||
private boolean mQuickReturn = false;
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
|
||||
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
|
||||
|
||||
if (DEBUG)
|
||||
if (action == MotionEvent.ACTION_DOWN)
|
||||
Log.v(TAG, "Received ACTION_DOWN");
|
||||
|
||||
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP
|
||||
|| (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
|
||||
endDrag();
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
determineDrag(ev);
|
||||
break;
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
int index = MotionEventCompat.getActionIndex(ev);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
|
||||
if (mActivePointerId == INVALID_POINTER)
|
||||
break;
|
||||
mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
|
||||
mLastMotionY = MotionEventCompat.getY(ev, index);
|
||||
if (thisTouchAllowed(ev)) {
|
||||
mIsBeingDragged = false;
|
||||
mIsUnableToDrag = false;
|
||||
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) {
|
||||
mQuickReturn = true;
|
||||
}
|
||||
} else {
|
||||
mIsUnableToDrag = true;
|
||||
}
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_UP:
|
||||
onSecondaryPointerUp(ev);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!mIsBeingDragged) {
|
||||
if (mVelocityTracker == null) {
|
||||
mVelocityTracker = VelocityTracker.obtain();
|
||||
}
|
||||
mVelocityTracker.addMovement(ev);
|
||||
}
|
||||
return mIsBeingDragged || mQuickReturn;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
|
||||
if (!mIsBeingDragged && !thisTouchAllowed(ev))
|
||||
return false;
|
||||
|
||||
final int action = ev.getAction();
|
||||
|
||||
if (mVelocityTracker == null) {
|
||||
mVelocityTracker = VelocityTracker.obtain();
|
||||
}
|
||||
mVelocityTracker.addMovement(ev);
|
||||
|
||||
switch (action & MotionEventCompat.ACTION_MASK) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
/*
|
||||
* If being flinged and user touches, stop the fling. isFinished
|
||||
* will be false if being flinged.
|
||||
*/
|
||||
completeScroll();
|
||||
|
||||
// Remember where the motion event started
|
||||
int index = MotionEventCompat.getActionIndex(ev);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
|
||||
mLastMotionX = mInitialMotionX = ev.getX();
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (!mIsBeingDragged) {
|
||||
determineDrag(ev);
|
||||
if (mIsUnableToDrag)
|
||||
return false;
|
||||
}
|
||||
if (mIsBeingDragged) {
|
||||
// Scroll to follow the motion event
|
||||
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
|
||||
if (mActivePointerId == INVALID_POINTER)
|
||||
break;
|
||||
final float x = MotionEventCompat.getX(ev, activePointerIndex);
|
||||
final float deltaX = mLastMotionX - x;
|
||||
mLastMotionX = x;
|
||||
float oldScrollX = getScrollX();
|
||||
float scrollX = oldScrollX + deltaX;
|
||||
final float leftBound = getLeftBound();
|
||||
final float rightBound = getRightBound();
|
||||
if (scrollX < leftBound) {
|
||||
scrollX = leftBound;
|
||||
} else if (scrollX > rightBound) {
|
||||
scrollX = rightBound;
|
||||
}
|
||||
// Don't lose the rounded component
|
||||
mLastMotionX += scrollX - (int) scrollX;
|
||||
scrollTo((int) scrollX, getScrollY());
|
||||
pageScrolled((int) scrollX);
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (mIsBeingDragged) {
|
||||
final VelocityTracker velocityTracker = mVelocityTracker;
|
||||
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
|
||||
int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
|
||||
velocityTracker, mActivePointerId);
|
||||
final int scrollX = getScrollX();
|
||||
final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth();
|
||||
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
|
||||
if (mActivePointerId != INVALID_POINTER) {
|
||||
final float x = MotionEventCompat.getX(ev, activePointerIndex);
|
||||
final int totalDelta = (int) (x - mInitialMotionX);
|
||||
int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta);
|
||||
setCurrentItemInternal(nextPage, true, true, initialVelocity);
|
||||
} else {
|
||||
setCurrentItemInternal(mCurItem, true, true, initialVelocity);
|
||||
}
|
||||
mActivePointerId = INVALID_POINTER;
|
||||
endDrag();
|
||||
} else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) {
|
||||
// close the menu
|
||||
setCurrentItem(1);
|
||||
endDrag();
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
if (mIsBeingDragged) {
|
||||
setCurrentItemInternal(mCurItem, true, true);
|
||||
mActivePointerId = INVALID_POINTER;
|
||||
endDrag();
|
||||
}
|
||||
break;
|
||||
case MotionEventCompat.ACTION_POINTER_DOWN: {
|
||||
final int indexx = MotionEventCompat.getActionIndex(ev);
|
||||
mLastMotionX = MotionEventCompat.getX(ev, indexx);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, indexx);
|
||||
break;
|
||||
}
|
||||
case MotionEventCompat.ACTION_POINTER_UP:
|
||||
onSecondaryPointerUp(ev);
|
||||
int pointerIndex = getPointerIndex(ev, mActivePointerId);
|
||||
if (mActivePointerId == INVALID_POINTER)
|
||||
break;
|
||||
mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void determineDrag(MotionEvent ev) {
|
||||
final int activePointerId = mActivePointerId;
|
||||
final int pointerIndex = getPointerIndex(ev, activePointerId);
|
||||
if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER)
|
||||
return;
|
||||
final float x = MotionEventCompat.getX(ev, pointerIndex);
|
||||
final float dx = x - mLastMotionX;
|
||||
final float xDiff = Math.abs(dx);
|
||||
final float y = MotionEventCompat.getY(ev, pointerIndex);
|
||||
final float dy = y - mLastMotionY;
|
||||
final float yDiff = Math.abs(dy);
|
||||
if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) {
|
||||
startDrag();
|
||||
mLastMotionX = x;
|
||||
mLastMotionY = y;
|
||||
setScrollingCacheEnabled(true);
|
||||
// TODO add back in touch slop check
|
||||
} else if (xDiff > mTouchSlop) {
|
||||
mIsUnableToDrag = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
float percentOpen = getPercentOpen();
|
||||
mScrollX = x;
|
||||
mViewBehind.scrollBehindTo(mContent, x, y);
|
||||
((SlidingMenu) getParent()).manageLayers(percentOpen);
|
||||
if (mListener != null) {
|
||||
mListener.onChanging(percentOpen);
|
||||
}
|
||||
}
|
||||
|
||||
private int determineTargetPage(float pageOffset, int velocity, int deltaX) {
|
||||
int targetPage = mCurItem;
|
||||
if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) {
|
||||
if (velocity > 0 && deltaX > 0) {
|
||||
targetPage -= 1;
|
||||
} else if (velocity < 0 && deltaX < 0) {
|
||||
targetPage += 1;
|
||||
}
|
||||
} else {
|
||||
targetPage = Math.round(mCurItem + pageOffset);
|
||||
}
|
||||
return targetPage;
|
||||
}
|
||||
|
||||
protected float getPercentOpen() {
|
||||
return Math.abs(mScrollX - mContent.getLeft()) / getBehindWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
// Draw the margin drawable if needed.
|
||||
mViewBehind.drawShadow(mContent, canvas);
|
||||
}
|
||||
|
||||
// variables for drawing
|
||||
private float mScrollX = 0.0f;
|
||||
|
||||
private void onSecondaryPointerUp(MotionEvent ev) {
|
||||
if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called");
|
||||
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
|
||||
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
|
||||
if (pointerId == mActivePointerId) {
|
||||
// This was our active pointer going up. Choose a new
|
||||
// active pointer and adjust accordingly.
|
||||
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
|
||||
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
|
||||
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
|
||||
if (mVelocityTracker != null) {
|
||||
mVelocityTracker.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startDrag() {
|
||||
mIsBeingDragged = true;
|
||||
mQuickReturn = false;
|
||||
}
|
||||
|
||||
private void endDrag() {
|
||||
mQuickReturn = false;
|
||||
mIsBeingDragged = false;
|
||||
mIsUnableToDrag = false;
|
||||
mActivePointerId = INVALID_POINTER;
|
||||
|
||||
if (mVelocityTracker != null) {
|
||||
mVelocityTracker.recycle();
|
||||
mVelocityTracker = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void setScrollingCacheEnabled(boolean enabled) {
|
||||
if (mScrollingCacheEnabled != enabled) {
|
||||
mScrollingCacheEnabled = enabled;
|
||||
if (USE_CACHE) {
|
||||
final int size = getChildCount();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
final View child = getChildAt(i);
|
||||
if (child.getVisibility() != GONE) {
|
||||
child.setDrawingCacheEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Let the focused view and/or our descendants get the key first
|
||||
return super.dispatchKeyEvent(event) || executeKeyEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* You can call this function yourself to have the scroll view perform
|
||||
* scrolling from a key event, just as if the event had been dispatched to
|
||||
* it by the view hierarchy.
|
||||
*
|
||||
* @param event The key event to execute.
|
||||
* @return Return true if the event was handled, else false.
|
||||
*/
|
||||
public boolean executeKeyEvent(KeyEvent event) {
|
||||
boolean handled = false;
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
switch (event.getKeyCode()) {
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
handled = arrowScroll(FOCUS_LEFT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
handled = arrowScroll(FOCUS_RIGHT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_TAB:
|
||||
// The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
|
||||
// before Android 3.0. Ignore the tab key on those devices.
|
||||
if (KeyEventCompat.hasNoModifiers(event)) {
|
||||
handled = arrowScroll(FOCUS_FORWARD);
|
||||
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
|
||||
handled = arrowScroll(FOCUS_BACKWARD);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
public boolean arrowScroll(int direction) {
|
||||
View currentFocused = findFocus();
|
||||
if (currentFocused == this) currentFocused = null;
|
||||
|
||||
boolean handled = false;
|
||||
|
||||
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
|
||||
direction);
|
||||
if (nextFocused != null && nextFocused != currentFocused) {
|
||||
if (direction == View.FOCUS_LEFT) {
|
||||
handled = nextFocused.requestFocus();
|
||||
} else if (direction == View.FOCUS_RIGHT) {
|
||||
// If there is nothing to the right, or this is causing us to
|
||||
// jump to the left, then what we really want to do is page right.
|
||||
if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
|
||||
handled = pageRight();
|
||||
} else {
|
||||
handled = nextFocused.requestFocus();
|
||||
}
|
||||
}
|
||||
} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
|
||||
// Trying to move left and nothing there; try to page.
|
||||
handled = pageLeft();
|
||||
} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
|
||||
// Trying to move right and nothing there; try to page.
|
||||
handled = pageRight();
|
||||
}
|
||||
if (handled) {
|
||||
playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
boolean pageLeft() {
|
||||
if (mCurItem > 0) {
|
||||
setCurrentItem(mCurItem - 1, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean pageRight() {
|
||||
if (mCurItem < 1) {
|
||||
setCurrentItem(mCurItem + 1, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
package com.moez.QKSMS.ui.view.slidingmenu;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.moez.QKSMS.common.utils.Units;
|
||||
|
||||
public class CustomViewBehind extends ViewGroup {
|
||||
private static final String TAG = "CustomViewBehind";
|
||||
|
||||
private View mContent;
|
||||
private int mWidthOffset;
|
||||
private boolean mChildrenEnabled;
|
||||
|
||||
private float mScrollScale;
|
||||
private Drawable mShadowDrawable;
|
||||
private int mShadowWidth;
|
||||
|
||||
public CustomViewBehind(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public CustomViewBehind(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
mShadowWidth = Units.dpToPx(getContext(), 8);
|
||||
}
|
||||
|
||||
public void setWidthOffset(int i) {
|
||||
mWidthOffset = i;
|
||||
requestLayout();
|
||||
}
|
||||
|
||||
public int getBehindWidth() {
|
||||
return mContent.getWidth();
|
||||
}
|
||||
|
||||
public void setContent(View v) {
|
||||
if (mContent != null) {
|
||||
removeView(mContent);
|
||||
}
|
||||
mContent = v;
|
||||
addView(mContent);
|
||||
}
|
||||
|
||||
public View getContent() {
|
||||
return mContent;
|
||||
}
|
||||
|
||||
public void setChildrenEnabled(boolean enabled) {
|
||||
mChildrenEnabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent e) {
|
||||
return !mChildrenEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent e) {
|
||||
return !mChildrenEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
final int width = r - l;
|
||||
final int height = b - t;
|
||||
mContent.layout(0, 0, width - mWidthOffset, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int width = getDefaultSize(0, widthMeasureSpec);
|
||||
int height = getDefaultSize(0, heightMeasureSpec);
|
||||
setMeasuredDimension(width, height);
|
||||
final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width - mWidthOffset);
|
||||
final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height);
|
||||
mContent.measure(contentWidth, contentHeight);
|
||||
}
|
||||
|
||||
public void setScrollScale(float scrollScale) {
|
||||
mScrollScale = scrollScale;
|
||||
}
|
||||
|
||||
public void setShadowDrawable(Drawable shadow) {
|
||||
mShadowDrawable = shadow;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getMenuPage(int page) {
|
||||
page = (page > 1) ? 2 : ((page < 1) ? 0 : page);
|
||||
if (page > 1) {
|
||||
return 0;
|
||||
} else {
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollBehindTo(View content, int x, int y) {
|
||||
int vis = View.VISIBLE;
|
||||
if (x >= content.getLeft()) vis = View.INVISIBLE;
|
||||
scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y);
|
||||
setVisibility(vis);
|
||||
}
|
||||
|
||||
public int getMenuLeft(View content, int page) {
|
||||
switch (page) {
|
||||
case 0:
|
||||
return content.getLeft() - getBehindWidth();
|
||||
case 2:
|
||||
return content.getLeft();
|
||||
}
|
||||
return content.getLeft();
|
||||
}
|
||||
|
||||
public int getAbsLeftBound(View content) {
|
||||
return content.getLeft() - getBehindWidth();
|
||||
}
|
||||
|
||||
public int getAbsRightBound(View content) {
|
||||
return content.getLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether x is on a menu.
|
||||
*
|
||||
* @param content content
|
||||
* @param x the position of the touch
|
||||
*/
|
||||
public boolean menuTouchInQuickReturn(View content, float x) {
|
||||
return x >= content.getLeft();
|
||||
}
|
||||
|
||||
public boolean menuClosedSlideAllowed(float dx) {
|
||||
return dx > 0;
|
||||
}
|
||||
|
||||
public boolean menuOpenSlideAllowed(float dx) {
|
||||
return dx < 0;
|
||||
}
|
||||
|
||||
public void drawShadow(View content, Canvas canvas) {
|
||||
if (mShadowDrawable == null || mShadowWidth <= 0) return;
|
||||
int left = content.getLeft() - mShadowWidth;
|
||||
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
|
||||
mShadowDrawable.draw(canvas);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
package com.moez.QKSMS.ui.view.slidingmenu;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.RelativeLayout;
|
||||
import com.moez.QKSMS.R;
|
||||
import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener;
|
||||
|
||||
/**
|
||||
* Stripped down version of Jeremy Feinstein's SlidingMenu library
|
||||
*/
|
||||
public class SlidingMenu extends RelativeLayout {
|
||||
private static final String TAG = "SlidingMenu";
|
||||
|
||||
private boolean mActionbarOverlay = false;
|
||||
|
||||
private CustomViewAbove mViewAbove;
|
||||
private CustomViewBehind mViewBehind;
|
||||
|
||||
private SlidingMenuListener mListener;
|
||||
|
||||
public interface SlidingMenuListener {
|
||||
void onOpen();
|
||||
|
||||
void onOpened();
|
||||
|
||||
void onClose();
|
||||
|
||||
void onClosed();
|
||||
|
||||
void onChanging(float percentOpen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new SlidingMenu.
|
||||
*
|
||||
* @param context the associated Context
|
||||
*/
|
||||
public SlidingMenu(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new SlidingMenu.
|
||||
*
|
||||
* @param context the associated Context
|
||||
* @param attrs the attrs
|
||||
*/
|
||||
public SlidingMenu(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new SlidingMenu.
|
||||
*
|
||||
* @param context the associated Context
|
||||
* @param attrs the attrs
|
||||
* @param defStyle the def style
|
||||
*/
|
||||
public SlidingMenu(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
mViewBehind = new CustomViewBehind(context);
|
||||
addView(mViewBehind, behindParams);
|
||||
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
mViewAbove = new CustomViewAbove(context);
|
||||
addView(mViewAbove, aboveParams);
|
||||
mViewBehind.setScrollScale(0.5f);
|
||||
mViewBehind.setShadowDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shadow_slidingmenu));
|
||||
mViewAbove.setCustomViewBehind(mViewBehind);
|
||||
mViewAbove.setOnPageChangeListener(new OnPageChangeListener() {
|
||||
public static final int POSITION_OPEN = 0;
|
||||
public static final int POSITION_CLOSE = 1;
|
||||
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
}
|
||||
|
||||
public void onPageSelected(int position, boolean anim) {
|
||||
if (position == POSITION_OPEN && mListener != null && anim) {
|
||||
mListener.onOpen();
|
||||
} else if (position == POSITION_OPEN && mListener != null) {
|
||||
mListener.onOpened();
|
||||
} else if (position == POSITION_CLOSE && mListener != null && anim) {
|
||||
mListener.onClose();
|
||||
} else if (position == POSITION_CLOSE && mListener != null) {
|
||||
mListener.onClosed();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the above view content from a layout resource. The resource will be inflated, adding all top-level views
|
||||
* to the above view.
|
||||
*/
|
||||
public void setContent() {
|
||||
mViewAbove.setContent(LayoutInflater.from(getContext()).inflate(R.layout.content_frame, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current content.
|
||||
*
|
||||
* @return the current content
|
||||
*/
|
||||
public View getContent() {
|
||||
return mViewAbove.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the behind view (menu) content from a layout resource. The resource will be inflated, adding all top-level views
|
||||
* to the behind view.
|
||||
*/
|
||||
public void setMenu() {
|
||||
mViewBehind.setContent(LayoutInflater.from(getContext()).inflate(R.layout.menu_frame, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the main menu.
|
||||
*
|
||||
* @return the main menu
|
||||
*/
|
||||
public View getMenu() {
|
||||
return mViewBehind.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu and shows the menu view.
|
||||
*/
|
||||
public void showMenu() {
|
||||
showMenu(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu and shows the menu view.
|
||||
*
|
||||
* @param animate true to animate the transition, false to ignore animation
|
||||
*/
|
||||
public void showMenu(boolean animate) {
|
||||
mViewAbove.setCurrentItem(0, animate, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the menu and shows the above view.
|
||||
*/
|
||||
public void showContent() {
|
||||
showContent(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the menu and shows the above view.
|
||||
*
|
||||
* @param animate true to animate the transition, false to ignore animation
|
||||
*/
|
||||
public void showContent(boolean animate) {
|
||||
mViewAbove.setCurrentItem(1, animate, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
|
||||
*/
|
||||
public void toggle() {
|
||||
toggle(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the SlidingMenu. If it is open, it will be closed, and vice versa.
|
||||
*
|
||||
* @param animate true to animate the transition, false to ignore animation
|
||||
*/
|
||||
public void toggle(boolean animate) {
|
||||
if (isMenuShowing()) {
|
||||
showContent(animate);
|
||||
} else {
|
||||
showMenu(animate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is the behind view showing.
|
||||
*
|
||||
* @return Whether or not the behind view is showing
|
||||
*/
|
||||
public boolean isMenuShowing() {
|
||||
return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the behind offset.
|
||||
*
|
||||
* @param i The margin, in pixels, on the right of the screen that the behind view scrolls to.
|
||||
*/
|
||||
public void setBehindOffset(int i) {
|
||||
mViewBehind.setWidthOffset(i);
|
||||
}
|
||||
|
||||
public void setListener(SlidingMenuListener listener) {
|
||||
mListener = listener;
|
||||
mViewAbove.setListener(listener);
|
||||
}
|
||||
|
||||
public static class SavedState extends BaseSavedState {
|
||||
|
||||
private final int mItem;
|
||||
|
||||
public SavedState(Parcelable superState, int item) {
|
||||
super(superState);
|
||||
mItem = item;
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
mItem = in.readInt();
|
||||
}
|
||||
|
||||
public int getItem() {
|
||||
return mItem;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.AbsSavedState#writeToParcel(android.os.Parcel, int)
|
||||
*/
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeInt(mItem);
|
||||
}
|
||||
|
||||
public static final Creator<SavedState> CREATOR =
|
||||
new Creator<SavedState>() {
|
||||
public SavedState createFromParcel(Parcel in) {
|
||||
return new SavedState(in);
|
||||
}
|
||||
|
||||
public SavedState[] newArray(int size) {
|
||||
return new SavedState[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View#onSaveInstanceState()
|
||||
*/
|
||||
@Override
|
||||
protected Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState ss = new SavedState(superState, mViewAbove.getCurrentItem());
|
||||
return ss;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View#onRestoreInstanceState(android.os.Parcelable)
|
||||
*/
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState ss = (SavedState) state;
|
||||
super.onRestoreInstanceState(ss.getSuperState());
|
||||
mViewAbove.setCurrentItem(ss.getItem());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect)
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected boolean fitSystemWindows(Rect insets) {
|
||||
int leftPadding = insets.left;
|
||||
int rightPadding = insets.right;
|
||||
int topPadding = insets.top;
|
||||
int bottomPadding = insets.bottom;
|
||||
if (!mActionbarOverlay) {
|
||||
setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void manageLayers(float percentOpen) {
|
||||
if (Build.VERSION.SDK_INT < 11) return;
|
||||
|
||||
boolean layer = percentOpen > 0.0f && percentOpen < 1.0f;
|
||||
final int layerType = layer ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE;
|
||||
|
||||
if (layerType != getContent().getLayerType()) {
|
||||
getHandler().post(() -> {
|
||||
getContent().setLayerType(layerType, null);
|
||||
getMenu().setLayerType(layerType, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user