forked from upstream-mirrors/quik
Stripped out a lot of unneeded code from SlidingMenu
This commit is contained in:
@@ -110,7 +110,15 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
setTitle(R.string.title_conversation_list);
|
setTitle(R.string.title_conversation_list);
|
||||||
|
|
||||||
mSlidingMenu = (SlidingMenu) findViewById(R.id.sliding_menu);
|
mSlidingMenu = (SlidingMenu) findViewById(R.id.sliding_menu);
|
||||||
setupSlidingMenu();
|
setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false));
|
||||||
|
mSlidingMenu.setOnOpenListener(this);
|
||||||
|
mSlidingMenu.setOnCloseListener(this);
|
||||||
|
mSlidingMenu.setOnOpenedListener(this);
|
||||||
|
mSlidingMenu.setOnClosedListener(this);
|
||||||
|
mSlidingMenu.setContent();
|
||||||
|
mSlidingMenu.setMenu();
|
||||||
|
mSlidingMenu.showContent(false);
|
||||||
|
mSlidingMenu.showMenu(false);
|
||||||
|
|
||||||
setupFragments(savedInstanceState);
|
setupFragments(savedInstanceState);
|
||||||
onNewIntent(getIntent());
|
onNewIntent(getIntent());
|
||||||
@@ -219,30 +227,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
startActivityForResult(welcomeIntent, WelcomeActivity.WELCOME_REQUEST_CODE);
|
startActivityForResult(welcomeIntent, WelcomeActivity.WELCOME_REQUEST_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlidingMenu getSlidingMenu() {
|
|
||||||
return mSlidingMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showMenu() {
|
public void showMenu() {
|
||||||
mSlidingMenu.showMenu();
|
mSlidingMenu.showMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSlidingMenu() {
|
|
||||||
setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false));
|
|
||||||
mSlidingMenu.setBehindScrollScale(0.5f);
|
|
||||||
mSlidingMenu.setFadeDegree(0.5f);
|
|
||||||
mSlidingMenu.setOnOpenListener(this);
|
|
||||||
mSlidingMenu.setOnCloseListener(this);
|
|
||||||
mSlidingMenu.setOnOpenedListener(this);
|
|
||||||
mSlidingMenu.setOnClosedListener(this);
|
|
||||||
mSlidingMenu.setShadowDrawable(R.drawable.shadow_slidingmenu);
|
|
||||||
mSlidingMenu.setShadowWidthRes(R.dimen.shadow_width);
|
|
||||||
mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
|
|
||||||
mSlidingMenu.setContent(R.layout.content_frame);
|
|
||||||
mSlidingMenu.setMenu(R.layout.menu_frame);
|
|
||||||
mSlidingMenu.showMenu(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configured the sliding menu view to peek the content or not.
|
* Configured the sliding menu view to peek the content or not.
|
||||||
*
|
*
|
||||||
@@ -250,11 +238,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
*/
|
*/
|
||||||
public void setSlidingTabEnabled(boolean slidingTabEnabled) {
|
public void setSlidingTabEnabled(boolean slidingTabEnabled) {
|
||||||
if (slidingTabEnabled) {
|
if (slidingTabEnabled) {
|
||||||
mSlidingMenu.setShadowDrawable(R.drawable.shadow_slidingmenu);
|
|
||||||
mSlidingMenu.setShadowWidth(Units.dpToPx(this, 8));
|
|
||||||
mSlidingMenu.setBehindOffset(Units.dpToPx(this, 48));
|
mSlidingMenu.setBehindOffset(Units.dpToPx(this, 48));
|
||||||
} else {
|
} else {
|
||||||
mSlidingMenu.setShadowWidth(0);
|
|
||||||
mSlidingMenu.setBehindOffset(0);
|
mSlidingMenu.setBehindOffset(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,10 +260,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
return super.onPrepareOptionsMenu(menu);
|
return super.onPrepareOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Fragment getConversationList() {
|
|
||||||
return mConversationList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Fragment getContent() {
|
public Fragment getContent() {
|
||||||
return (Fragment) mContent;
|
return (Fragment) mContent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ package com.moez.QKSMS.ui.view.slidingmenu;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v4.view.KeyEventCompat;
|
import android.support.v4.view.KeyEventCompat;
|
||||||
import android.support.v4.view.MotionEventCompat;
|
import android.support.v4.view.MotionEventCompat;
|
||||||
import android.support.v4.view.VelocityTrackerCompat;
|
import android.support.v4.view.VelocityTrackerCompat;
|
||||||
import android.support.v4.view.ViewCompat;
|
|
||||||
import android.support.v4.view.ViewConfigurationCompat;
|
import android.support.v4.view.ViewConfigurationCompat;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.FloatMath;
|
import android.util.FloatMath;
|
||||||
@@ -23,9 +21,6 @@ import android.view.ViewGroup;
|
|||||||
import android.view.animation.Interpolator;
|
import android.view.animation.Interpolator;
|
||||||
import android.widget.Scroller;
|
import android.widget.Scroller;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CustomViewAbove extends ViewGroup {
|
public class CustomViewAbove extends ViewGroup {
|
||||||
|
|
||||||
private static final String TAG = "CustomViewAbove";
|
private static final String TAG = "CustomViewAbove";
|
||||||
@@ -36,13 +31,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
private static final int MAX_SETTLE_DURATION = 350; // ms
|
private static final int MAX_SETTLE_DURATION = 350; // ms
|
||||||
private static final int MIN_DISTANCE_FOR_FLING = 25; // dips
|
private static final int MIN_DISTANCE_FOR_FLING = 25; // dips
|
||||||
|
|
||||||
private static final Interpolator sInterpolator = new Interpolator() {
|
private static final Interpolator sInterpolator = t -> (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f;
|
||||||
// See [1] for explanation for the 0.63 * t.
|
|
||||||
// http://www.wolframalpha.com/input/?i=graph+1%2B%28t-1%29%5E5%2C+1%2B%28t*0.63-1%29%5E5+from+t+%3D+0+to+1
|
|
||||||
public float getInterpolation(float t) {
|
|
||||||
return (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View mContent;
|
private View mContent;
|
||||||
|
|
||||||
@@ -82,21 +71,13 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
private int mFlingDistance;
|
private int mFlingDistance;
|
||||||
|
|
||||||
private CustomViewBehind mViewBehind;
|
private CustomViewBehind mViewBehind;
|
||||||
// private int mMode;
|
|
||||||
private boolean mEnabled = true;
|
|
||||||
|
|
||||||
private OnPageChangeListener mOnPageChangeListener;
|
private OnPageChangeListener mOnPageChangeListener;
|
||||||
private OnPageChangeListener mInternalPageChangeListener;
|
private OnPageChangeListener mInternalPageChangeListener;
|
||||||
|
|
||||||
// private OnCloseListener mCloseListener;
|
|
||||||
// private OnOpenListener mOpenListener;
|
|
||||||
private SlidingMenu.OnClosedListener mClosedListener;
|
private SlidingMenu.OnClosedListener mClosedListener;
|
||||||
private SlidingMenu.OnOpenedListener mOpenedListener;
|
private SlidingMenu.OnOpenedListener mOpenedListener;
|
||||||
|
|
||||||
private List<View> mIgnoredViews = new ArrayList<>();
|
|
||||||
|
|
||||||
// private int mScrollState = SCROLL_STATE_IDLE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback interface for responding to changing state of the selected page.
|
* Callback interface for responding to changing state of the selected page.
|
||||||
*/
|
*/
|
||||||
@@ -111,7 +92,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
* @param positionOffset Value from [0, 1) indicating the offset from the page at position.
|
* @param positionOffset Value from [0, 1) indicating the offset from the page at position.
|
||||||
* @param positionOffsetPixels Value in pixels indicating the offset from position.
|
* @param positionOffsetPixels Value in pixels indicating the offset from position.
|
||||||
*/
|
*/
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels);
|
void onPageScrolled(int position, float positionOffset, int positionOffsetPixels);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be invoked when a new page becomes selected. Animation is not
|
* This method will be invoked when a new page becomes selected. Animation is not
|
||||||
@@ -119,7 +100,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
*
|
*
|
||||||
* @param position Position index of the new selected page.
|
* @param position Position index of the new selected page.
|
||||||
*/
|
*/
|
||||||
public void onPageSelected(int position, boolean anim);
|
void onPageSelected(int position, boolean anim);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,10 +119,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
// This space for rent
|
// This space for rent
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPageScrollStateChanged(int state) {
|
|
||||||
// This space for rent
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomViewAbove(Context context) {
|
public CustomViewAbove(Context context) {
|
||||||
@@ -227,8 +204,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
setCurrentItemInternal(item, smoothScroll, always, velocity, false);
|
setCurrentItemInternal(item, smoothScroll, always, velocity, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity,
|
void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity, boolean notify) {
|
||||||
boolean notify) {
|
|
||||||
if (!always && mCurItem == item) {
|
if (!always && mCurItem == item) {
|
||||||
setScrollingCacheEnabled(false);
|
setScrollingCacheEnabled(false);
|
||||||
|
|
||||||
@@ -275,15 +251,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
mOnPageChangeListener = listener;
|
mOnPageChangeListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public void setOnOpenListener(OnOpenListener l) {
|
|
||||||
mOpenListener = l;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOnCloseListener(OnCloseListener l) {
|
|
||||||
mCloseListener = l;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public void setOnOpenedListener(SlidingMenu.OnOpenedListener l) {
|
public void setOnOpenedListener(SlidingMenu.OnOpenedListener l) {
|
||||||
mOpenedListener = l;
|
mOpenedListener = l;
|
||||||
}
|
}
|
||||||
@@ -304,20 +271,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
return oldListener;
|
return oldListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIgnoredView(View v) {
|
|
||||||
if (!mIgnoredViews.contains(v)) {
|
|
||||||
mIgnoredViews.add(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeIgnoredView(View v) {
|
|
||||||
mIgnoredViews.remove(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearIgnoredViews() {
|
|
||||||
mIgnoredViews.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want the duration of the page snap animation to be influenced by the distance that
|
// 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
|
// 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
|
// purely linear fashion. Instead, we use this method to moderate the effect that the distance
|
||||||
@@ -325,7 +278,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
float distanceInfluenceForSnapDuration(float f) {
|
float distanceInfluenceForSnapDuration(float f) {
|
||||||
f -= 0.5f; // center the values about 0.
|
f -= 0.5f; // center the values about 0.
|
||||||
f *= 0.3f * Math.PI / 2.0f;
|
f *= 0.3f * Math.PI / 2.0f;
|
||||||
return (float) FloatMath.sin(f);
|
return FloatMath.sin(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDestScrollX(int page) {
|
public int getDestScrollX(int page) {
|
||||||
@@ -347,23 +300,10 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
return mViewBehind.getAbsRightBound(mContent);
|
return mViewBehind.getAbsRightBound(mContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getContentLeft() {
|
|
||||||
return mContent.getLeft() + mContent.getPaddingLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isMenuOpen() {
|
public boolean isMenuOpen() {
|
||||||
return mCurItem == 0 || mCurItem == 2;
|
return mCurItem == 0 || mCurItem == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInIgnoredView(MotionEvent ev) {
|
|
||||||
Rect rect = new Rect();
|
|
||||||
for (View v : mIgnoredViews) {
|
|
||||||
v.getHitRect(rect);
|
|
||||||
if (rect.contains((int) ev.getX(), (int) ev.getY())) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBehindWidth() {
|
public int getBehindWidth() {
|
||||||
if (mViewBehind == null) {
|
if (mViewBehind == null) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -372,35 +312,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChildWidth(int i) {
|
|
||||||
switch (i) {
|
|
||||||
case 0:
|
|
||||||
return getBehindWidth();
|
|
||||||
case 1:
|
|
||||||
return mContent.getWidth();
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSlidingEnabled() {
|
|
||||||
return mEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSlidingEnabled(boolean b) {
|
|
||||||
mEnabled = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
void smoothScrollTo(int x, int y) {
|
|
||||||
smoothScrollTo(x, y, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like {@link View#scrollBy}, but scroll smoothly instead of immediately.
|
* Like {@link View#scrollBy}, but scroll smoothly instead of immediately.
|
||||||
*
|
*
|
||||||
@@ -444,8 +355,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
if (velocity > 0) {
|
if (velocity > 0) {
|
||||||
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
|
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
|
||||||
} else {
|
} else {
|
||||||
final float pageDelta = (float) Math.abs(dx) / width;
|
|
||||||
duration = (int) ((pageDelta + 1) * 100);
|
|
||||||
duration = MAX_SETTLE_DURATION;
|
duration = MAX_SETTLE_DURATION;
|
||||||
}
|
}
|
||||||
duration = Math.min(duration, MAX_SETTLE_DURATION);
|
duration = Math.min(duration, MAX_SETTLE_DURATION);
|
||||||
@@ -487,8 +396,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
// Make sure scroll position is set correctly.
|
// Make sure scroll position is set correctly.
|
||||||
if (w != oldw) {
|
if (w != oldw) {
|
||||||
// [ChrisJ] - This fixes the onConfiguration change for orientation issue..
|
// [ChrisJ] - This fixes the onConfiguration change for orientation issue..
|
||||||
// maybe worth having a look why the recomputeScroll pos is screwing
|
// maybe worth having a look why the recomputeScroll pos is screwing up?
|
||||||
// up?
|
|
||||||
completeScroll();
|
completeScroll();
|
||||||
scrollTo(getDestScrollX(mCurItem), getScrollY());
|
scrollTo(getDestScrollX(mCurItem), getScrollY());
|
||||||
}
|
}
|
||||||
@@ -501,13 +409,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
mContent.layout(0, 0, width, height);
|
mContent.layout(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAboveOffset(int i) {
|
|
||||||
// RelativeLayout.LayoutParams params = ((RelativeLayout.LayoutParams)mContent.getLayoutParams());
|
|
||||||
// params.setMargins(i, params.topMargin, params.rightMargin, params.bottomMargin);
|
|
||||||
mContent.setPadding(i, mContent.getPaddingTop(),
|
|
||||||
mContent.getPaddingRight(), mContent.getPaddingBottom());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void computeScroll() {
|
public void computeScroll() {
|
||||||
@@ -587,35 +488,12 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
mScrolling = false;
|
mScrolling = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN;
|
|
||||||
|
|
||||||
public void setTouchMode(int i) {
|
|
||||||
mTouchMode = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTouchMode() {
|
|
||||||
return mTouchMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean thisTouchAllowed(MotionEvent ev) {
|
private boolean thisTouchAllowed(MotionEvent ev) {
|
||||||
int x = (int) (ev.getX() + mScrollX);
|
return !isMenuOpen();
|
||||||
if (isMenuOpen()) {
|
|
||||||
return mViewBehind.menuOpenTouchAllowed(mContent, mCurItem, x);
|
|
||||||
} else {
|
|
||||||
switch (mTouchMode) {
|
|
||||||
case SlidingMenu.TOUCHMODE_FULLSCREEN:
|
|
||||||
return !isInIgnoredView(ev);
|
|
||||||
case SlidingMenu.TOUCHMODE_NONE:
|
|
||||||
return false;
|
|
||||||
case SlidingMenu.TOUCHMODE_MARGIN:
|
|
||||||
return mViewBehind.marginTouchAllowed(mContent, x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean thisSlideAllowed(float dx) {
|
private boolean thisSlideAllowed(float dx) {
|
||||||
boolean allowed = false;
|
boolean allowed;
|
||||||
if (isMenuOpen()) {
|
if (isMenuOpen()) {
|
||||||
allowed = mViewBehind.menuOpenSlideAllowed(dx);
|
allowed = mViewBehind.menuOpenSlideAllowed(dx);
|
||||||
} else {
|
} else {
|
||||||
@@ -641,9 +519,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
|
|
||||||
if (!mEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
|
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
@@ -695,15 +570,9 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent ev) {
|
public boolean onTouchEvent(MotionEvent ev) {
|
||||||
|
|
||||||
if (!mEnabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!mIsBeingDragged && !thisTouchAllowed(ev))
|
if (!mIsBeingDragged && !thisTouchAllowed(ev))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if (!mIsBeingDragged && !mQuickReturn)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
final int action = ev.getAction();
|
final int action = ev.getAction();
|
||||||
|
|
||||||
if (mVelocityTracker == null) {
|
if (mVelocityTracker == null) {
|
||||||
@@ -841,7 +710,7 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
targetPage += 1;
|
targetPage += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
targetPage = (int) Math.round(mCurItem + pageOffset);
|
targetPage = Math.round(mCurItem + pageOffset);
|
||||||
}
|
}
|
||||||
return targetPage;
|
return targetPage;
|
||||||
}
|
}
|
||||||
@@ -855,8 +724,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
super.dispatchDraw(canvas);
|
super.dispatchDraw(canvas);
|
||||||
// Draw the margin drawable if needed.
|
// Draw the margin drawable if needed.
|
||||||
mViewBehind.drawShadow(mContent, canvas);
|
mViewBehind.drawShadow(mContent, canvas);
|
||||||
mViewBehind.drawFade(mContent, canvas, getPercentOpen());
|
|
||||||
mViewBehind.drawSelector(mContent, canvas, getPercentOpen());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// variables for drawing
|
// variables for drawing
|
||||||
@@ -910,38 +777,6 @@ public class CustomViewAbove extends ViewGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests scrollability within child views of v given a delta of dx.
|
|
||||||
*
|
|
||||||
* @param v View to test for horizontal scrollability
|
|
||||||
* @param checkV Whether the view v passed should itself be checked for scrollability (true),
|
|
||||||
* or just its children (false).
|
|
||||||
* @param dx Delta scrolled in pixels
|
|
||||||
* @param x X coordinate of the active touch point
|
|
||||||
* @param y Y coordinate of the active touch point
|
|
||||||
* @return true if child views of v can be scrolled by delta of dx.
|
|
||||||
*/
|
|
||||||
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
|
|
||||||
if (v instanceof ViewGroup) {
|
|
||||||
final ViewGroup group = (ViewGroup) v;
|
|
||||||
final int scrollX = v.getScrollX();
|
|
||||||
final int scrollY = v.getScrollY();
|
|
||||||
final int count = group.getChildCount();
|
|
||||||
// Count backwards - let topmost views consume scroll distance first.
|
|
||||||
for (int i = count - 1; i >= 0; i--) {
|
|
||||||
final View child = group.getChildAt(i);
|
|
||||||
if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
|
|
||||||
y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
|
|
||||||
canScroll(child, true, dx, x + scrollX - child.getLeft(),
|
|
||||||
y + scrollY - child.getTop())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return checkV && ViewCompat.canScrollHorizontally(v, -dx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
|
|||||||
@@ -1,32 +1,19 @@
|
|||||||
package com.moez.QKSMS.ui.view.slidingmenu;
|
package com.moez.QKSMS.ui.view.slidingmenu;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.TypedValue;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.common.utils.Units;
|
||||||
|
|
||||||
public class CustomViewBehind extends ViewGroup {
|
public class CustomViewBehind extends ViewGroup {
|
||||||
|
|
||||||
private static final String TAG = "CustomViewBehind";
|
private static final String TAG = "CustomViewBehind";
|
||||||
|
|
||||||
private static final int MARGIN_THRESHOLD = 48; // dips
|
|
||||||
private int mTouchMode = SlidingMenu.TOUCHMODE_MARGIN;
|
|
||||||
|
|
||||||
private CustomViewAbove mViewAbove;
|
|
||||||
|
|
||||||
private View mContent;
|
private View mContent;
|
||||||
private View mSecondaryContent;
|
|
||||||
private int mMarginThreshold;
|
|
||||||
private int mWidthOffset;
|
private int mWidthOffset;
|
||||||
private SlidingMenu.CanvasTransformer mTransformer;
|
|
||||||
private boolean mChildrenEnabled;
|
private boolean mChildrenEnabled;
|
||||||
|
|
||||||
public CustomViewBehind(Context context) {
|
public CustomViewBehind(Context context) {
|
||||||
@@ -35,16 +22,7 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
|
|
||||||
public CustomViewBehind(Context context, AttributeSet attrs) {
|
public CustomViewBehind(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mMarginThreshold = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
mShadowWidth = Units.dpToPx(getContext(), 8);
|
||||||
MARGIN_THRESHOLD, getResources().getDisplayMetrics());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCustomViewAbove(CustomViewAbove customViewAbove) {
|
|
||||||
mViewAbove = customViewAbove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCanvasTransformer(SlidingMenu.CanvasTransformer t) {
|
|
||||||
mTransformer = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWidthOffset(int i) {
|
public void setWidthOffset(int i) {
|
||||||
@@ -52,21 +30,14 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
requestLayout();
|
requestLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMarginThreshold(int marginThreshold) {
|
|
||||||
mMarginThreshold = marginThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMarginThreshold() {
|
|
||||||
return mMarginThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getBehindWidth() {
|
public int getBehindWidth() {
|
||||||
return mContent.getWidth();
|
return mContent.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContent(View v) {
|
public void setContent(View v) {
|
||||||
if (mContent != null)
|
if (mContent != null) {
|
||||||
removeView(mContent);
|
removeView(mContent);
|
||||||
|
}
|
||||||
mContent = v;
|
mContent = v;
|
||||||
addView(mContent);
|
addView(mContent);
|
||||||
}
|
}
|
||||||
@@ -82,8 +53,6 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
@Override
|
@Override
|
||||||
public void scrollTo(int x, int y) {
|
public void scrollTo(int x, int y) {
|
||||||
super.scrollTo(x, y);
|
super.scrollTo(x, y);
|
||||||
if (mTransformer != null)
|
|
||||||
invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,13 +67,7 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void dispatchDraw(Canvas canvas) {
|
protected void dispatchDraw(Canvas canvas) {
|
||||||
if (mTransformer != null) {
|
super.dispatchDraw(canvas);
|
||||||
canvas.save();
|
|
||||||
mTransformer.transformCanvas(canvas, mViewAbove.getPercentOpen());
|
|
||||||
super.dispatchDraw(canvas);
|
|
||||||
canvas.restore();
|
|
||||||
} else
|
|
||||||
super.dispatchDraw(canvas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,63 +87,23 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
mContent.measure(contentWidth, contentHeight);
|
mContent.measure(contentWidth, contentHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines the location of the menu(s): left only, right only, or on both left and right.
|
|
||||||
*/
|
|
||||||
private int mMode;
|
|
||||||
private boolean mFadeEnabled;
|
|
||||||
private final Paint mFadePaint = new Paint();
|
|
||||||
private float mScrollScale;
|
private float mScrollScale;
|
||||||
private Drawable mShadowDrawable;
|
private Drawable mShadowDrawable;
|
||||||
private int mShadowWidth;
|
private int mShadowWidth;
|
||||||
private float mFadeDegree;
|
|
||||||
|
|
||||||
public void setMode(int mode) {
|
|
||||||
if (mode == SlidingMenu.LEFT || mode == SlidingMenu.RIGHT) {
|
|
||||||
if (mContent != null)
|
|
||||||
mContent.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
mMode = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMode() {
|
|
||||||
return mMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setScrollScale(float scrollScale) {
|
public void setScrollScale(float scrollScale) {
|
||||||
mScrollScale = scrollScale;
|
mScrollScale = scrollScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScrollScale() {
|
|
||||||
return mScrollScale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShadowDrawable(Drawable shadow) {
|
public void setShadowDrawable(Drawable shadow) {
|
||||||
mShadowDrawable = shadow;
|
mShadowDrawable = shadow;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShadowWidth(int width) {
|
|
||||||
mShadowWidth = width;
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFadeEnabled(boolean b) {
|
|
||||||
mFadeEnabled = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFadeDegree(float degree) {
|
|
||||||
if (degree > 1.0f || degree < 0.0f)
|
|
||||||
throw new IllegalStateException("The BehindFadeDegree must be between 0.0f and 1.0f");
|
|
||||||
mFadeDegree = degree;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMenuPage(int page) {
|
public int getMenuPage(int page) {
|
||||||
page = (page > 1) ? 2 : ((page < 1) ? 0 : page);
|
page = (page > 1) ? 2 : ((page < 1) ? 0 : page);
|
||||||
if (mMode == SlidingMenu.LEFT && page > 1) {
|
if (page > 1) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (mMode == SlidingMenu.RIGHT && page < 1) {
|
|
||||||
return 2;
|
|
||||||
} else {
|
} else {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
@@ -188,96 +111,27 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
|
|
||||||
public void scrollBehindTo(View content, int x, int y) {
|
public void scrollBehindTo(View content, int x, int y) {
|
||||||
int vis = View.VISIBLE;
|
int vis = View.VISIBLE;
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
if (x >= content.getLeft()) vis = View.INVISIBLE;
|
||||||
if (x >= content.getLeft()) vis = View.INVISIBLE;
|
scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y);
|
||||||
scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y);
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
if (x <= content.getLeft()) vis = View.INVISIBLE;
|
|
||||||
scrollTo((int) (getBehindWidth() - getWidth() +
|
|
||||||
(x - getBehindWidth()) * mScrollScale), y);
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
mContent.setVisibility(x >= content.getLeft() ? View.INVISIBLE : View.VISIBLE);
|
|
||||||
vis = x == 0 ? View.INVISIBLE : View.VISIBLE;
|
|
||||||
if (x <= content.getLeft()) {
|
|
||||||
scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y);
|
|
||||||
} else {
|
|
||||||
scrollTo((int) (getBehindWidth() - getWidth() +
|
|
||||||
(x - getBehindWidth()) * mScrollScale), y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setVisibility(vis);
|
setVisibility(vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMenuLeft(View content, int page) {
|
public int getMenuLeft(View content, int page) {
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
switch (page) {
|
||||||
switch (page) {
|
case 0:
|
||||||
case 0:
|
return content.getLeft() - getBehindWidth();
|
||||||
return content.getLeft() - getBehindWidth();
|
case 2:
|
||||||
case 2:
|
return content.getLeft();
|
||||||
return content.getLeft();
|
|
||||||
}
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
switch (page) {
|
|
||||||
case 0:
|
|
||||||
return content.getLeft();
|
|
||||||
case 2:
|
|
||||||
return content.getLeft() + getBehindWidth();
|
|
||||||
}
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
switch (page) {
|
|
||||||
case 0:
|
|
||||||
return content.getLeft() - getBehindWidth();
|
|
||||||
case 2:
|
|
||||||
return content.getLeft() + getBehindWidth();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return content.getLeft();
|
return content.getLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAbsLeftBound(View content) {
|
public int getAbsLeftBound(View content) {
|
||||||
if (mMode == SlidingMenu.LEFT || mMode == SlidingMenu.LEFT_RIGHT) {
|
return content.getLeft() - getBehindWidth();
|
||||||
return content.getLeft() - getBehindWidth();
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
return content.getLeft();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAbsRightBound(View content) {
|
public int getAbsRightBound(View content) {
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
return content.getLeft();
|
||||||
return content.getLeft();
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
return content.getLeft() + getBehindWidth();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean marginTouchAllowed(View content, int x) {
|
|
||||||
int left = content.getLeft();
|
|
||||||
int right = content.getRight();
|
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
|
||||||
return (x >= left && x <= mMarginThreshold + left);
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
return (x <= right && x >= right - mMarginThreshold);
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
return (x >= left && x <= mMarginThreshold + left) ||
|
|
||||||
(x <= right && x >= right - mMarginThreshold);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTouchMode(int i) {
|
|
||||||
mTouchMode = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean menuOpenTouchAllowed(View content, int currPage, float x) {
|
|
||||||
switch (mTouchMode) {
|
|
||||||
case SlidingMenu.TOUCHMODE_FULLSCREEN:
|
|
||||||
return true;
|
|
||||||
case SlidingMenu.TOUCHMODE_MARGIN:
|
|
||||||
return menuTouchInQuickReturn(content, currPage, x);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -288,125 +142,22 @@ public class CustomViewBehind extends ViewGroup {
|
|||||||
* @param x the position of the touch
|
* @param x the position of the touch
|
||||||
*/
|
*/
|
||||||
public boolean menuTouchInQuickReturn(View content, int currPage, float x) {
|
public boolean menuTouchInQuickReturn(View content, int currPage, float x) {
|
||||||
if (mMode == SlidingMenu.LEFT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 0)) {
|
return x >= content.getLeft();
|
||||||
return x >= content.getLeft();
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT || (mMode == SlidingMenu.LEFT_RIGHT && currPage == 2)) {
|
|
||||||
return x <= content.getRight();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean menuClosedSlideAllowed(float dx) {
|
public boolean menuClosedSlideAllowed(float dx) {
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
return dx > 0;
|
||||||
return dx > 0;
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
return dx < 0;
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean menuOpenSlideAllowed(float dx) {
|
public boolean menuOpenSlideAllowed(float dx) {
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
return dx < 0;
|
||||||
return dx < 0;
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
return dx > 0;
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawShadow(View content, Canvas canvas) {
|
public void drawShadow(View content, Canvas canvas) {
|
||||||
if (mShadowDrawable == null || mShadowWidth <= 0) return;
|
if (mShadowDrawable == null || mShadowWidth <= 0) return;
|
||||||
int left = 0;
|
int left = content.getLeft() - mShadowWidth;
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
|
||||||
left = content.getLeft() - mShadowWidth;
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
left = content.getRight();
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
left = content.getLeft() - mShadowWidth;
|
|
||||||
}
|
|
||||||
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
|
mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight());
|
||||||
mShadowDrawable.draw(canvas);
|
mShadowDrawable.draw(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawFade(View content, Canvas canvas, float openPercent) {
|
|
||||||
if (!mFadeEnabled) return;
|
|
||||||
final int alpha = (int) (mFadeDegree * 255 * Math.abs(1 - openPercent));
|
|
||||||
mFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
|
|
||||||
int left = 0;
|
|
||||||
int right = 0;
|
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
|
||||||
left = content.getLeft() - getBehindWidth();
|
|
||||||
right = content.getLeft();
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
left = content.getRight();
|
|
||||||
right = content.getRight() + getBehindWidth();
|
|
||||||
} else if (mMode == SlidingMenu.LEFT_RIGHT) {
|
|
||||||
left = content.getLeft() - getBehindWidth();
|
|
||||||
right = content.getLeft();
|
|
||||||
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
|
|
||||||
left = content.getRight();
|
|
||||||
right = content.getRight() + getBehindWidth();
|
|
||||||
}
|
|
||||||
canvas.drawRect(left, 0, right, getHeight(), mFadePaint);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean mSelectorEnabled = true;
|
|
||||||
private Bitmap mSelectorDrawable;
|
|
||||||
private View mSelectedView;
|
|
||||||
|
|
||||||
public void drawSelector(View content, Canvas canvas, float openPercent) {
|
|
||||||
if (!mSelectorEnabled) return;
|
|
||||||
if (mSelectorDrawable != null && mSelectedView != null) {
|
|
||||||
String tag = (String) mSelectedView.getTag(R.id.selected_view);
|
|
||||||
if (tag.equals(TAG + "SelectedView")) {
|
|
||||||
canvas.save();
|
|
||||||
int left, right, offset;
|
|
||||||
offset = (int) (mSelectorDrawable.getWidth() * openPercent);
|
|
||||||
if (mMode == SlidingMenu.LEFT) {
|
|
||||||
right = content.getLeft();
|
|
||||||
left = right - offset;
|
|
||||||
canvas.clipRect(left, 0, right, getHeight());
|
|
||||||
canvas.drawBitmap(mSelectorDrawable, left, getSelectorTop(), null);
|
|
||||||
} else if (mMode == SlidingMenu.RIGHT) {
|
|
||||||
left = content.getRight();
|
|
||||||
right = left + offset;
|
|
||||||
canvas.clipRect(left, 0, right, getHeight());
|
|
||||||
canvas.drawBitmap(mSelectorDrawable, right - mSelectorDrawable.getWidth(), getSelectorTop(), null);
|
|
||||||
}
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectorEnabled(boolean b) {
|
|
||||||
mSelectorEnabled = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectedView(View v) {
|
|
||||||
if (mSelectedView != null) {
|
|
||||||
mSelectedView.setTag(R.id.selected_view, null);
|
|
||||||
mSelectedView = null;
|
|
||||||
}
|
|
||||||
if (v != null && v.getParent() != null) {
|
|
||||||
mSelectedView = v;
|
|
||||||
mSelectedView.setTag(R.id.selected_view, TAG + "SelectedView");
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getSelectorTop() {
|
|
||||||
int y = mSelectedView.getTop();
|
|
||||||
y += (mSelectedView.getHeight() - mSelectorDrawable.getHeight()) / 2;
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelectorBitmap(Bitmap b) {
|
|
||||||
mSelectorDrawable = b;
|
|
||||||
refreshDrawableState();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +1,29 @@
|
|||||||
package com.moez.QKSMS.ui.view.slidingmenu;
|
package com.moez.QKSMS.ui.view.slidingmenu;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Point;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Display;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
|
import com.moez.QKSMS.common.utils.Units;
|
||||||
import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener;
|
import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stripped down version of Jeremy Feinstein's SlidingMenu library
|
* Stripped down version of Jeremy Feinstein's SlidingMenu library
|
||||||
*/
|
*/
|
||||||
public class SlidingMenu extends RelativeLayout {
|
public class SlidingMenu extends RelativeLayout {
|
||||||
|
|
||||||
private static final String TAG = "SlidingMenu";
|
private static final String TAG = "SlidingMenu";
|
||||||
|
|
||||||
public static final int SLIDING_WINDOW = 0;
|
|
||||||
public static final int SLIDING_CONTENT = 1;
|
|
||||||
private boolean mActionbarOverlay = false;
|
private boolean mActionbarOverlay = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
|
|
||||||
* gesture on the screen's margin
|
|
||||||
*/
|
|
||||||
public static final int TOUCHMODE_MARGIN = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setTouchModeAbove(). Allows the SlidingMenu to be opened with a swipe
|
|
||||||
* gesture anywhere on the screen
|
|
||||||
*/
|
|
||||||
public static final int TOUCHMODE_FULLSCREEN = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setTouchModeAbove(). Denies the SlidingMenu to be opened with a swipe
|
|
||||||
* gesture
|
|
||||||
*/
|
|
||||||
public static final int TOUCHMODE_NONE = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setMode(). Puts the menu to the left of the content.
|
|
||||||
*/
|
|
||||||
public static final int LEFT = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setMode(). Puts the menu to the right of the content.
|
|
||||||
*/
|
|
||||||
public static final int RIGHT = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant value for use with setMode(). Puts menus to the left and right of the content.
|
|
||||||
*/
|
|
||||||
public static final int LEFT_RIGHT = 2;
|
|
||||||
|
|
||||||
private CustomViewAbove mViewAbove;
|
private CustomViewAbove mViewAbove;
|
||||||
|
|
||||||
private CustomViewBehind mViewBehind;
|
private CustomViewBehind mViewBehind;
|
||||||
|
|
||||||
private OnOpenListener mOpenListener;
|
private OnOpenListener mOpenListener;
|
||||||
@@ -95,7 +45,7 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
/**
|
/**
|
||||||
* On open.
|
* On open.
|
||||||
*/
|
*/
|
||||||
public void onOpen();
|
void onOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,7 +64,7 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
/**
|
/**
|
||||||
* On opened.
|
* On opened.
|
||||||
*/
|
*/
|
||||||
public void onOpened();
|
void onOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,7 +83,7 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
/**
|
/**
|
||||||
* On close.
|
* On close.
|
||||||
*/
|
*/
|
||||||
public void onClose();
|
void onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,21 +102,7 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
/**
|
/**
|
||||||
* On closed.
|
* On closed.
|
||||||
*/
|
*/
|
||||||
public void onClosed();
|
void onClosed();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Interface CanvasTransformer.
|
|
||||||
*/
|
|
||||||
public interface CanvasTransformer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform canvas.
|
|
||||||
*
|
|
||||||
* @param canvas the canvas
|
|
||||||
* @param percentOpen the percent open
|
|
||||||
*/
|
|
||||||
public void transformCanvas(Canvas canvas, float percentOpen);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,17 +114,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new SlidingMenu and attach to Activity.
|
|
||||||
*
|
|
||||||
* @param activity the activity to attach slidingmenu
|
|
||||||
* @param slideStyle the slidingmenu style
|
|
||||||
*/
|
|
||||||
public SlidingMenu(Activity activity, int slideStyle) {
|
|
||||||
this(activity, null);
|
|
||||||
this.attachToActivity(activity, slideStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new SlidingMenu.
|
* Instantiates a new SlidingMenu.
|
||||||
*
|
*
|
||||||
@@ -215,15 +140,14 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||||
mViewAbove = new CustomViewAbove(context);
|
mViewAbove = new CustomViewAbove(context);
|
||||||
addView(mViewAbove, aboveParams);
|
addView(mViewAbove, aboveParams);
|
||||||
// register the CustomViewBehind with the CustomViewAbove
|
mViewBehind.setScrollScale(0.5f);
|
||||||
|
mViewBehind.setShadowDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shadow_slidingmenu));
|
||||||
mViewAbove.setCustomViewBehind(mViewBehind);
|
mViewAbove.setCustomViewBehind(mViewBehind);
|
||||||
mViewBehind.setCustomViewAbove(mViewAbove);
|
|
||||||
mViewAbove.setOnPageChangeListener(new OnPageChangeListener() {
|
mViewAbove.setOnPageChangeListener(new OnPageChangeListener() {
|
||||||
public static final int POSITION_OPEN = 0;
|
public static final int POSITION_OPEN = 0;
|
||||||
public static final int POSITION_CLOSE = 1;
|
public static final int POSITION_CLOSE = 1;
|
||||||
|
|
||||||
public void onPageScrolled(int position, float positionOffset,
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
int positionOffsetPixels) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPageSelected(int position, boolean anim) {
|
public void onPageSelected(int position, boolean anim) {
|
||||||
@@ -239,112 +163,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// now style everything!
|
|
||||||
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingMenu);
|
|
||||||
// set the above and behind views if defined in xml
|
|
||||||
int mode = ta.getInt(R.styleable.SlidingMenu_mode, LEFT);
|
|
||||||
setMode(mode);
|
|
||||||
int viewAbove = ta.getResourceId(R.styleable.SlidingMenu_viewAbove, -1);
|
|
||||||
if (viewAbove != -1) {
|
|
||||||
setContent(viewAbove);
|
|
||||||
} else {
|
|
||||||
setContent(new FrameLayout(context));
|
|
||||||
}
|
|
||||||
int viewBehind = ta.getResourceId(R.styleable.SlidingMenu_viewBehind, -1);
|
|
||||||
if (viewBehind != -1) {
|
|
||||||
setMenu(viewBehind);
|
|
||||||
} else {
|
|
||||||
setMenu(new FrameLayout(context));
|
|
||||||
}
|
|
||||||
int touchModeAbove = ta.getInt(R.styleable.SlidingMenu_touchModeAbove, TOUCHMODE_MARGIN);
|
|
||||||
setTouchModeAbove(touchModeAbove);
|
|
||||||
int touchModeBehind = ta.getInt(R.styleable.SlidingMenu_touchModeBehind, TOUCHMODE_MARGIN);
|
|
||||||
setTouchModeBehind(touchModeBehind);
|
|
||||||
|
|
||||||
int offsetBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindOffset, -1);
|
|
||||||
int widthBehind = (int) ta.getDimension(R.styleable.SlidingMenu_behindWidth, -1);
|
|
||||||
if (offsetBehind != -1 && widthBehind != -1)
|
|
||||||
throw new IllegalStateException("Cannot set both behindOffset and behindWidth for a SlidingMenu");
|
|
||||||
else if (offsetBehind != -1)
|
|
||||||
setBehindOffset(offsetBehind);
|
|
||||||
else if (widthBehind != -1)
|
|
||||||
setBehindWidth(widthBehind);
|
|
||||||
else
|
|
||||||
setBehindOffset(0);
|
|
||||||
float scrollOffsetBehind = ta.getFloat(R.styleable.SlidingMenu_behindScrollScale, 0.33f);
|
|
||||||
setBehindScrollScale(scrollOffsetBehind);
|
|
||||||
int shadowRes = ta.getResourceId(R.styleable.SlidingMenu_shadowDrawable, -1);
|
|
||||||
if (shadowRes != -1) {
|
|
||||||
setShadowDrawable(shadowRes);
|
|
||||||
}
|
|
||||||
int shadowWidth = (int) ta.getDimension(R.styleable.SlidingMenu_shadowWidth, 0);
|
|
||||||
setShadowWidth(shadowWidth);
|
|
||||||
boolean fadeEnabled = ta.getBoolean(R.styleable.SlidingMenu_fadeEnabled, true);
|
|
||||||
setFadeEnabled(fadeEnabled);
|
|
||||||
float fadeDeg = ta.getFloat(R.styleable.SlidingMenu_fadeDegree, 0.33f);
|
|
||||||
setFadeDegree(fadeDeg);
|
|
||||||
boolean selectorEnabled = ta.getBoolean(R.styleable.SlidingMenu_selectorEnabled, false);
|
|
||||||
setSelectorEnabled(selectorEnabled);
|
|
||||||
int selectorRes = ta.getResourceId(R.styleable.SlidingMenu_selectorDrawable, -1);
|
|
||||||
if (selectorRes != -1)
|
|
||||||
setSelectorDrawable(selectorRes);
|
|
||||||
ta.recycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches the SlidingMenu to an entire Activity
|
|
||||||
*
|
|
||||||
* @param activity the Activity
|
|
||||||
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
|
|
||||||
*/
|
|
||||||
public void attachToActivity(Activity activity, int slideStyle) {
|
|
||||||
attachToActivity(activity, slideStyle, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attaches the SlidingMenu to an entire Activity
|
|
||||||
*
|
|
||||||
* @param activity the Activity
|
|
||||||
* @param slideStyle either SLIDING_CONTENT or SLIDING_WINDOW
|
|
||||||
* @param actionbarOverlay whether or not the ActionBar is overlaid
|
|
||||||
*/
|
|
||||||
public void attachToActivity(Activity activity, int slideStyle, boolean actionbarOverlay) {
|
|
||||||
if (slideStyle != SLIDING_WINDOW && slideStyle != SLIDING_CONTENT)
|
|
||||||
throw new IllegalArgumentException("slideStyle must be either SLIDING_WINDOW or SLIDING_CONTENT");
|
|
||||||
|
|
||||||
if (getParent() != null)
|
|
||||||
throw new IllegalStateException("This SlidingMenu appears to already be attached");
|
|
||||||
|
|
||||||
// get the window background
|
|
||||||
TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowBackground});
|
|
||||||
int background = a.getResourceId(0, 0);
|
|
||||||
a.recycle();
|
|
||||||
|
|
||||||
switch (slideStyle) {
|
|
||||||
case SLIDING_WINDOW:
|
|
||||||
mActionbarOverlay = false;
|
|
||||||
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
|
|
||||||
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
|
|
||||||
// save ActionBar themes that have transparent assets
|
|
||||||
decorChild.setBackgroundResource(background);
|
|
||||||
decor.removeView(decorChild);
|
|
||||||
decor.addView(this);
|
|
||||||
setContent(decorChild);
|
|
||||||
break;
|
|
||||||
case SLIDING_CONTENT:
|
|
||||||
mActionbarOverlay = actionbarOverlay;
|
|
||||||
// take the above view out of
|
|
||||||
ViewGroup contentParent = (ViewGroup) activity.findViewById(android.R.id.content);
|
|
||||||
contentParent.addView(LayoutInflater.from(getContext()).inflate(R.layout.toolbar, contentParent, false));
|
|
||||||
View content = contentParent.getChildAt(0);
|
|
||||||
contentParent.removeView(content);
|
|
||||||
contentParent.addView(this);
|
|
||||||
setContent(content);
|
|
||||||
// save people from having transparent backgrounds
|
|
||||||
if (content.getBackground() == null)
|
|
||||||
content.setBackgroundResource(background);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -353,18 +171,8 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
*
|
*
|
||||||
* @param res the new content
|
* @param res the new content
|
||||||
*/
|
*/
|
||||||
public void setContent(int res) {
|
public void setContent() {
|
||||||
setContent(LayoutInflater.from(getContext()).inflate(res, null));
|
mViewAbove.setContent(LayoutInflater.from(getContext()).inflate(R.layout.content_frame, null));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the above view content to the given View.
|
|
||||||
*
|
|
||||||
* @param view The desired content to display.
|
|
||||||
*/
|
|
||||||
public void setContent(View view) {
|
|
||||||
mViewAbove.setContent(view);
|
|
||||||
showContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,17 +190,8 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
*
|
*
|
||||||
* @param res the new content
|
* @param res the new content
|
||||||
*/
|
*/
|
||||||
public void setMenu(int res) {
|
public void setMenu() {
|
||||||
setMenu(LayoutInflater.from(getContext()).inflate(res, null));
|
mViewBehind.setContent(LayoutInflater.from(getContext()).inflate(R.layout.menu_frame, null));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the behind view (menu) content to the given View.
|
|
||||||
*
|
|
||||||
* @param view The desired content to display.
|
|
||||||
*/
|
|
||||||
public void setMenu(View v) {
|
|
||||||
mViewBehind.setContent(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -404,65 +203,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
return mViewBehind.getContent();
|
return mViewBehind.getContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the sliding enabled.
|
|
||||||
*
|
|
||||||
* @param b true to enable sliding, false to disable it.
|
|
||||||
*/
|
|
||||||
public void setSlidingEnabled(boolean b) {
|
|
||||||
mViewAbove.setSlidingEnabled(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if is sliding enabled.
|
|
||||||
*
|
|
||||||
* @return true, if is sliding enabled
|
|
||||||
*/
|
|
||||||
public boolean isSlidingEnabled() {
|
|
||||||
return mViewAbove.isSlidingEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets which side the SlidingMenu should appear on.
|
|
||||||
*
|
|
||||||
* @param mode must be either SlidingMenu.LEFT or SlidingMenu.RIGHT
|
|
||||||
*/
|
|
||||||
public void setMode(int mode) {
|
|
||||||
if (mode != LEFT && mode != RIGHT && mode != LEFT_RIGHT) {
|
|
||||||
throw new IllegalStateException("SlidingMenu mode must be LEFT, RIGHT, or LEFT_RIGHT");
|
|
||||||
}
|
|
||||||
mViewBehind.setMode(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the current side that the SlidingMenu is on.
|
|
||||||
*
|
|
||||||
* @return the current mode, either SlidingMenu.LEFT or SlidingMenu.RIGHT
|
|
||||||
*/
|
|
||||||
public int getMode() {
|
|
||||||
return mViewBehind.getMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether or not the SlidingMenu is in static mode (i.e. nothing is moving and everything is showing)
|
|
||||||
*
|
|
||||||
* @param b true to set static mode, false to disable static mode.
|
|
||||||
*/
|
|
||||||
public void setStatic(boolean b) {
|
|
||||||
if (b) {
|
|
||||||
setSlidingEnabled(false);
|
|
||||||
mViewAbove.setCustomViewBehind(null);
|
|
||||||
mViewAbove.setCurrentItem(1);
|
|
||||||
// mViewBehind.setCurrentItem(0);
|
|
||||||
} else {
|
|
||||||
mViewAbove.setCurrentItem(1);
|
|
||||||
// mViewBehind.setCurrentItem(1);
|
|
||||||
mViewAbove.setCustomViewBehind(mViewBehind);
|
|
||||||
setSlidingEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the menu and shows the menu view.
|
* Opens the menu and shows the menu view.
|
||||||
*/
|
*/
|
||||||
@@ -476,7 +216,7 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
* @param animate true to animate the transition, false to ignore animation
|
* @param animate true to animate the transition, false to ignore animation
|
||||||
*/
|
*/
|
||||||
public void showMenu(boolean animate) {
|
public void showMenu(boolean animate) {
|
||||||
mViewAbove.setCurrentItem(0, animate);
|
mViewAbove.setCurrentItem(0, animate, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -524,15 +264,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2;
|
return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the behind offset.
|
|
||||||
*
|
|
||||||
* @return The margin on the right of the screen that the behind view scrolls to
|
|
||||||
*/
|
|
||||||
public int getBehindOffset() {
|
|
||||||
return ((LayoutParams) mViewBehind.getLayoutParams()).rightMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the behind offset.
|
* Sets the behind offset.
|
||||||
*
|
*
|
||||||
@@ -547,282 +278,12 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
mViewBehind.setWidthOffset(i);
|
mViewBehind.setWidthOffset(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the behind offset.
|
|
||||||
*
|
|
||||||
* @param resID The dimension resource id to be set as the behind offset.
|
|
||||||
* The menu, when open, will leave this width margin on the right of the screen.
|
|
||||||
*/
|
|
||||||
public void setBehindOffsetRes(int resID) {
|
|
||||||
int i = (int) getContext().getResources().getDimension(resID);
|
|
||||||
setBehindOffset(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the above offset.
|
|
||||||
*
|
|
||||||
* @param i the new above offset, in pixels
|
|
||||||
*/
|
|
||||||
public void setAboveOffset(int i) {
|
|
||||||
mViewAbove.setAboveOffset(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the above offset.
|
|
||||||
*
|
|
||||||
* @param resID The dimension resource id to be set as the above offset.
|
|
||||||
*/
|
|
||||||
public void setAboveOffsetRes(int resID) {
|
|
||||||
int i = (int) getContext().getResources().getDimension(resID);
|
|
||||||
setAboveOffset(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the behind width.
|
|
||||||
*
|
|
||||||
* @param i The width the Sliding Menu will open to, in pixels
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public void setBehindWidth(int i) {
|
|
||||||
int width;
|
|
||||||
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
|
|
||||||
.getDefaultDisplay();
|
|
||||||
try {
|
|
||||||
Class<?> cls = Display.class;
|
|
||||||
Class<?>[] parameterTypes = {Point.class};
|
|
||||||
Point parameter = new Point();
|
|
||||||
Method method = cls.getMethod("getSize", parameterTypes);
|
|
||||||
method.invoke(display, parameter);
|
|
||||||
width = parameter.x;
|
|
||||||
} catch (Exception e) {
|
|
||||||
width = display.getWidth();
|
|
||||||
}
|
|
||||||
setBehindOffset(width - i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the behind width.
|
|
||||||
*
|
|
||||||
* @param res The dimension resource id to be set as the behind width offset.
|
|
||||||
* The menu, when open, will open this wide.
|
|
||||||
*/
|
|
||||||
public void setBehindWidthRes(int res) {
|
|
||||||
int i = (int) getContext().getResources().getDimension(res);
|
|
||||||
setBehindWidth(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the behind scroll scale.
|
|
||||||
*
|
|
||||||
* @return The scale of the parallax scroll
|
|
||||||
*/
|
|
||||||
public float getBehindScrollScale() {
|
|
||||||
return mViewBehind.getScrollScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the touch mode margin threshold
|
|
||||||
*
|
|
||||||
* @return the touch mode margin threshold
|
|
||||||
*/
|
|
||||||
public int getTouchmodeMarginThreshold() {
|
|
||||||
return mViewBehind.getMarginThreshold();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the touch mode margin threshold
|
|
||||||
*
|
|
||||||
* @param touchmodeMarginThreshold
|
|
||||||
*/
|
|
||||||
public void setTouchmodeMarginThreshold(int touchmodeMarginThreshold) {
|
|
||||||
mViewBehind.setMarginThreshold(touchmodeMarginThreshold);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the behind scroll scale.
|
|
||||||
*
|
|
||||||
* @param f The scale of the parallax scroll (i.e. 1.0f scrolls 1 pixel for every
|
|
||||||
* 1 pixel that the above view scrolls and 0.0f scrolls 0 pixels)
|
|
||||||
*/
|
|
||||||
public void setBehindScrollScale(float f) {
|
|
||||||
if (f < 0 && f > 1)
|
|
||||||
throw new IllegalStateException("ScrollScale must be between 0 and 1");
|
|
||||||
mViewBehind.setScrollScale(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the behind canvas transformer.
|
|
||||||
*
|
|
||||||
* @param t the new behind canvas transformer
|
|
||||||
*/
|
|
||||||
public void setBehindCanvasTransformer(CanvasTransformer t) {
|
|
||||||
mViewBehind.setCanvasTransformer(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the touch mode above.
|
|
||||||
*
|
|
||||||
* @return the touch mode above
|
|
||||||
*/
|
|
||||||
public int getTouchModeAbove() {
|
|
||||||
return mViewAbove.getTouchMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls whether the SlidingMenu can be opened with a swipe gesture.
|
|
||||||
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
|
|
||||||
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
|
|
||||||
*
|
|
||||||
* @param i the new touch mode
|
|
||||||
*/
|
|
||||||
public void setTouchModeAbove(int i) {
|
|
||||||
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
|
|
||||||
&& i != TOUCHMODE_NONE) {
|
|
||||||
throw new IllegalStateException("TouchMode must be set to either" +
|
|
||||||
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
|
|
||||||
}
|
|
||||||
mViewAbove.setTouchMode(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controls whether the SlidingMenu can be opened with a swipe gesture.
|
|
||||||
* Options are {@link #TOUCHMODE_MARGIN TOUCHMODE_MARGIN}, {@link #TOUCHMODE_FULLSCREEN TOUCHMODE_FULLSCREEN},
|
|
||||||
* or {@link #TOUCHMODE_NONE TOUCHMODE_NONE}
|
|
||||||
*
|
|
||||||
* @param i the new touch mode
|
|
||||||
*/
|
|
||||||
public void setTouchModeBehind(int i) {
|
|
||||||
if (i != TOUCHMODE_FULLSCREEN && i != TOUCHMODE_MARGIN
|
|
||||||
&& i != TOUCHMODE_NONE) {
|
|
||||||
throw new IllegalStateException("TouchMode must be set to either" +
|
|
||||||
"TOUCHMODE_FULLSCREEN or TOUCHMODE_MARGIN or TOUCHMODE_NONE.");
|
|
||||||
}
|
|
||||||
mViewBehind.setTouchMode(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the shadow drawable.
|
|
||||||
*
|
|
||||||
* @param resId the resource ID of the new shadow drawable
|
|
||||||
*/
|
|
||||||
public void setShadowDrawable(int resId) {
|
|
||||||
setShadowDrawable(ContextCompat.getDrawable(getContext(), resId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the shadow drawable.
|
|
||||||
*
|
|
||||||
* @param d the new shadow drawable
|
|
||||||
*/
|
|
||||||
public void setShadowDrawable(Drawable d) {
|
|
||||||
mViewBehind.setShadowDrawable(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the shadow width.
|
|
||||||
*
|
|
||||||
* @param resId The dimension resource id to be set as the shadow width.
|
|
||||||
*/
|
|
||||||
public void setShadowWidthRes(int resId) {
|
|
||||||
setShadowWidth((int) getResources().getDimension(resId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the shadow width.
|
|
||||||
*
|
|
||||||
* @param pixels the new shadow width, in pixels
|
|
||||||
*/
|
|
||||||
public void setShadowWidth(int pixels) {
|
|
||||||
mViewBehind.setShadowWidth(pixels);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables or disables the SlidingMenu's fade in and out
|
|
||||||
*
|
|
||||||
* @param b true to enable fade, false to disable it
|
|
||||||
*/
|
|
||||||
public void setFadeEnabled(boolean b) {
|
|
||||||
mViewBehind.setFadeEnabled(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets how much the SlidingMenu fades in and out. Fade must be enabled, see
|
|
||||||
* {@link #setFadeEnabled(boolean) setFadeEnabled(boolean)}
|
|
||||||
*
|
|
||||||
* @param f the new fade degree, between 0.0f and 1.0f
|
|
||||||
*/
|
|
||||||
public void setFadeDegree(float f) {
|
|
||||||
mViewBehind.setFadeDegree(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables or disables whether the selector is drawn
|
|
||||||
*
|
|
||||||
* @param b true to draw the selector, false to not draw the selector
|
|
||||||
*/
|
|
||||||
public void setSelectorEnabled(boolean b) {
|
|
||||||
mViewBehind.setSelectorEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the selected view. The selector will be drawn here
|
|
||||||
*
|
|
||||||
* @param v the new selected view
|
|
||||||
*/
|
|
||||||
public void setSelectedView(View v) {
|
|
||||||
mViewBehind.setSelectedView(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the selector drawable.
|
|
||||||
*
|
|
||||||
* @param res a resource ID for the selector drawable
|
|
||||||
*/
|
|
||||||
public void setSelectorDrawable(int res) {
|
|
||||||
mViewBehind.setSelectorBitmap(BitmapFactory.decodeResource(getResources(), res));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the selector drawable.
|
|
||||||
*
|
|
||||||
* @param b the new selector bitmap
|
|
||||||
*/
|
|
||||||
public void setSelectorBitmap(Bitmap b) {
|
|
||||||
mViewBehind.setSelectorBitmap(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a View ignored by the Touch Down event when mode is Fullscreen
|
|
||||||
*
|
|
||||||
* @param v a view to be ignored
|
|
||||||
*/
|
|
||||||
public void addIgnoredView(View v) {
|
|
||||||
mViewAbove.addIgnoredView(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a View ignored by the Touch Down event when mode is Fullscreen
|
|
||||||
*
|
|
||||||
* @param v a view not wanted to be ignored anymore
|
|
||||||
*/
|
|
||||||
public void removeIgnoredView(View v) {
|
|
||||||
mViewAbove.removeIgnoredView(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the list of Views ignored by the Touch Down event when mode is Fullscreen
|
|
||||||
*/
|
|
||||||
public void clearIgnoredViews() {
|
|
||||||
mViewAbove.clearIgnoredViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened
|
* Sets the OnOpenListener. {@link OnOpenListener#onOpen() OnOpenListener.onOpen()} will be called when the SlidingMenu is opened
|
||||||
*
|
*
|
||||||
* @param listener the new OnOpenListener
|
* @param listener the new OnOpenListener
|
||||||
*/
|
*/
|
||||||
public void setOnOpenListener(OnOpenListener listener) {
|
public void setOnOpenListener(OnOpenListener listener) {
|
||||||
//mViewAbove.setOnOpenListener(listener);
|
|
||||||
mOpenListener = listener;
|
mOpenListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -833,7 +294,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
* @param listener the new setOnCloseListener
|
* @param listener the new setOnCloseListener
|
||||||
*/
|
*/
|
||||||
public void setOnCloseListener(OnCloseListener listener) {
|
public void setOnCloseListener(OnCloseListener listener) {
|
||||||
//mViewAbove.setOnCloseListener(listener);
|
|
||||||
mCloseListener = listener;
|
mCloseListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -932,7 +392,6 @@ public class SlidingMenu extends RelativeLayout {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
||||||
public void manageLayers(float percentOpen) {
|
public void manageLayers(float percentOpen) {
|
||||||
if (Build.VERSION.SDK_INT < 11) return;
|
if (Build.VERSION.SDK_INT < 11) return;
|
||||||
|
|
||||||
|
|||||||
@@ -66,32 +66,4 @@
|
|||||||
<declare-styleable name="AvatarView">
|
<declare-styleable name="AvatarView">
|
||||||
<attr name="initialSize" format="dimension" />
|
<attr name="initialSize" format="dimension" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="SlidingMenu">
|
|
||||||
<attr name="mode">
|
|
||||||
<enum name="left" value="0" />
|
|
||||||
<enum name="right" value="1" />
|
|
||||||
</attr>
|
|
||||||
<attr name="viewAbove" format="reference" />
|
|
||||||
<attr name="viewBehind" format="reference" />
|
|
||||||
<attr name="behindOffset" format="dimension" />
|
|
||||||
<attr name="behindWidth" format="dimension" />
|
|
||||||
<attr name="behindScrollScale" format="float" />
|
|
||||||
<attr name="touchModeAbove">
|
|
||||||
<enum name="margin" value="0" />
|
|
||||||
<enum name="fullscreen" value="1" />
|
|
||||||
<enum name="none" value="2" />
|
|
||||||
</attr>
|
|
||||||
<attr name="touchModeBehind">
|
|
||||||
<enum name="margin" value="0" />
|
|
||||||
<enum name="fullscreen" value="1" />
|
|
||||||
<enum name="none" value="2" />
|
|
||||||
</attr>
|
|
||||||
<attr name="shadowDrawable" format="reference" />
|
|
||||||
<attr name="shadowWidth" format="dimension" />
|
|
||||||
<attr name="fadeEnabled" format="boolean" />
|
|
||||||
<attr name="fadeDegree" format="float" />
|
|
||||||
<attr name="selectorEnabled" format="boolean" />
|
|
||||||
<attr name="selectorDrawable" format="reference" />
|
|
||||||
</declare-styleable>
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user