Skip to content

Commit

Permalink
Drop shadows. Woo.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeinstein10 committed Jul 19, 2012
1 parent 0d246de commit 52bcb09
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 1,549 deletions.
12 changes: 12 additions & 0 deletions library/res/drawable/header_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:top="35dp">
<shape android:shape="rectangle" >
<solid android:color="@color/holo_blue_bright" />

<size android:height="@dimen/menu_header_line" />
</shape>
</item>

</layer-list>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions library/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
-->

<resources>

<declare-styleable name="SlidingMenu">
<declare-styleable name="SlidingMenu">
<attr name="viewAbove" format="reference" />
<attr name="viewBehind" format="reference" />
<attr name="behindOffset" format="dimension" />
Expand All @@ -29,6 +29,8 @@
<enum name="margin" value="0" />
<enum name="fullscreen" value="1" />
</attr>
<attr name="shadowDrawable" format="reference" />
<attr name="shadowWidth" format="dimension" />
</declare-styleable>

</resources>
</resources>
6 changes: 6 additions & 0 deletions library/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="holo_blue_bright">#ff00ddff</color>

</resources>
8 changes: 8 additions & 0 deletions library/res/values/dimen.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="menu_item_padding">10dp</dimen>
<dimen name="menu_header_padding_top">8dp</dimen>
<dimen name="menu_header_line">3dp</dimen>
<dimen name="menu_icon_side">40dp</dimen>

</resources>
217 changes: 102 additions & 115 deletions library/src/com/slidingmenu/lib/CustomViewAbove.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,11 @@ public float getInterpolation(float t) {
private ItemInfo mWindow;
private ItemInfo mContent;

private int mCurItem; // Index of currently displayed page.
private int mRestoredCurItem = -1;
private Parcelable mRestoredAdapterState = null;
private ClassLoader mRestoredClassLoader = null;
private int mCurItem;
private Scroller mScroller;
private PagerObserver mObserver;

private int mPageMargin;
private Drawable mMarginDrawable;
private int mShadowWidth;
private Drawable mShadowDrawable;
private int mTopPageBounds;
private int mBottomPageBounds;

Expand Down Expand Up @@ -228,7 +224,7 @@ public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
super(context, attrs);
initCustomViewAbove(isAbove);
}

void initCustomViewAbove() {
initCustomViewAbove(false);
}
Expand Down Expand Up @@ -388,37 +384,37 @@ OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener
/**
* Set the margin between pages.
*
* @param marginPixels Distance between adjacent pages in pixels
* @see #getPageMargin()
* @see #setPageMarginDrawable(Drawable)
* @see #setPageMarginDrawable(int)
* @param shadowWidth Distance between adjacent pages in pixels
* @see #getShadowWidth()
* @see #setShadowDrawable(Drawable)
* @see #setShadowDrawable(int)
*/
public void setPageMargin(int marginPixels) {
final int oldMargin = mPageMargin;
mPageMargin = marginPixels;

final int width = getWidth();
recomputeScrollPosition(width, width, marginPixels, oldMargin);
public void setShadowWidth(int shadowWidth) {
final int oldWidth = mShadowWidth;
mShadowWidth = shadowWidth;

requestLayout();
// final int width = getWidth();
// recomputeScrollPosition(width, width, shadowWidth, oldWidth);
//
// requestLayout();
}

/**
* Return the margin between pages.
*
* @return The size of the margin in pixels
*/
public int getPageMargin() {
return mPageMargin;
public int getShadowWidth() {
return mShadowWidth;
}

/**
* Set a drawable that will be used to fill the margin between pages.
*
* @param d Drawable to display between pages
*/
public void setPageMarginDrawable(Drawable d) {
mMarginDrawable = d;
public void setShadowDrawable(Drawable d) {
mShadowDrawable = d;
if (d != null) refreshDrawableState();
setWillNotDraw(d == null);
invalidate();
Expand All @@ -429,19 +425,19 @@ public void setPageMarginDrawable(Drawable d) {
*
* @param resId Resource ID of a drawable to display between pages
*/
public void setPageMarginDrawable(int resId) {
setPageMarginDrawable(getContext().getResources().getDrawable(resId));
public void setShadowDrawable(int resId) {
setShadowDrawable(getContext().getResources().getDrawable(resId));
}


protected boolean verifyDrawable(Drawable who) {
return super.verifyDrawable(who) || who == mMarginDrawable;
return super.verifyDrawable(who) || who == mShadowDrawable;
}


protected void drawableStateChanged() {
super.drawableStateChanged();
final Drawable d = mMarginDrawable;
final Drawable d = mShadowDrawable;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
Expand Down Expand Up @@ -555,7 +551,7 @@ void smoothScrollTo(int x, int y, int velocity) {
if (velocity > 0) {
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
} else {
final float pageDelta = (float) Math.abs(dx) / (width + mPageMargin);
final float pageDelta = (float) Math.abs(dx) / (width + mShadowWidth);
duration = (int) ((pageDelta + 1) * 100);
// TODO set custom duration!
duration = MAX_SETTLE_DURATION;
Expand Down Expand Up @@ -661,75 +657,75 @@ void populate() {
* state, in which case it should implement a subclass of this which
* contains that state.
*/
// public static class SavedState extends BaseSavedState {
// int position;
// Parcelable adapterState;
// ClassLoader loader;
//
// public SavedState(Parcelable superState) {
// super(superState);
// }
//
//
// public void writeToParcel(Parcel out, int flags) {
// super.writeToParcel(out, flags);
// out.writeInt(position);
// out.writeParcelable(adapterState, flags);
// }
//
//
// public String toString() {
// return "FragmentPager.SavedState{"
// + Integer.toHexString(System.identityHashCode(this))
// + " position=" + position + "}";
// }
//
// public static final Parcelable.Creator<SavedState> CREATOR
// = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
//
// public SavedState createFromParcel(Parcel in, ClassLoader loader) {
// return new SavedState(in, loader);
// }
//
// public SavedState[] newArray(int size) {
// return new SavedState[size];
// }
// });
//
// SavedState(Parcel in, ClassLoader loader) {
// super(in);
// if (loader == null) {
// loader = getClass().getClassLoader();
// }
// position = in.readInt();
// adapterState = in.readParcelable(loader);
// this.loader = loader;
// }
// }
//
//
// public Parcelable onSaveInstanceState() {
// Parcelable superState = super.onSaveInstanceState();
// SavedState ss = new SavedState(superState);
// ss.position = mCurItem;
// return ss;
// }
//
//
// public void onRestoreInstanceState(Parcelable state) {
// if (!(state instanceof SavedState)) {
// super.onRestoreInstanceState(state);
// return;
// }
//
// SavedState ss = (SavedState)state;
// super.onRestoreInstanceState(ss.getSuperState());
//
// setCurrentItemInternal(ss.position, false, true);
// mRestoredCurItem = ss.position;
// mRestoredAdapterState = ss.adapterState;
// mRestoredClassLoader = ss.loader;
// }
// public static class SavedState extends BaseSavedState {
// int position;
// Parcelable adapterState;
// ClassLoader loader;
//
// public SavedState(Parcelable superState) {
// super(superState);
// }
//
//
// public void writeToParcel(Parcel out, int flags) {
// super.writeToParcel(out, flags);
// out.writeInt(position);
// out.writeParcelable(adapterState, flags);
// }
//
//
// public String toString() {
// return "FragmentPager.SavedState{"
// + Integer.toHexString(System.identityHashCode(this))
// + " position=" + position + "}";
// }
//
// public static final Parcelable.Creator<SavedState> CREATOR
// = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
//
// public SavedState createFromParcel(Parcel in, ClassLoader loader) {
// return new SavedState(in, loader);
// }
//
// public SavedState[] newArray(int size) {
// return new SavedState[size];
// }
// });
//
// SavedState(Parcel in, ClassLoader loader) {
// super(in);
// if (loader == null) {
// loader = getClass().getClassLoader();
// }
// position = in.readInt();
// adapterState = in.readParcelable(loader);
// this.loader = loader;
// }
// }
//
//
// public Parcelable onSaveInstanceState() {
// Parcelable superState = super.onSaveInstanceState();
// SavedState ss = new SavedState(superState);
// ss.position = mCurItem;
// return ss;
// }
//
//
// public void onRestoreInstanceState(Parcelable state) {
// if (!(state instanceof SavedState)) {
// super.onRestoreInstanceState(state);
// return;
// }
//
// SavedState ss = (SavedState)state;
// super.onRestoreInstanceState(ss.getSuperState());
//
// setCurrentItemInternal(ss.position, false, true);
// mRestoredCurItem = ss.position;
// mRestoredAdapterState = ss.adapterState;
// mRestoredClassLoader = ss.loader;
// }

protected void setMenu(View v) {
ItemInfo ii = new ItemInfo();
Expand Down Expand Up @@ -892,7 +888,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {

// Make sure scroll position is set correctly.
if (w != oldw) {
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
recomputeScrollPosition(w, oldw, mShadowWidth, mShadowWidth);
}
}

Expand Down Expand Up @@ -933,13 +929,10 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
int pos = infoForChild(child).position;
int childLeft = 0;
int childTop = 0;
childLeft = getChildLeft(pos);
Log.v(TAG, "Child#" + i + " left:" + childLeft +
" right:" + (childLeft + child.getMeasuredWidth()));
child.layout(childLeft, childTop,
childLeft + child.getMeasuredWidth(),
childTop + child.getMeasuredHeight());
Expand Down Expand Up @@ -978,7 +971,7 @@ public void computeScroll() {

private void pageScrolled(int xpos) {
// TODO
final int widthWithMargin = getChildWidth(mCurItem) + mPageMargin;
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
final int position = xpos / widthWithMargin;
final int offsetPixels = xpos % widthWithMargin;
final float offset = (float) offsetPixels / widthWithMargin;
Expand Down Expand Up @@ -1322,7 +1315,7 @@ public boolean onTouchEvent(MotionEvent ev) {
int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
velocityTracker, mActivePointerId);
mPopulatePending = true;
final int widthWithMargin = getChildWidth(mCurItem) + mPageMargin;
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
final int scrollX = getScrollX();
final int currentPage = scrollX / widthWithMargin;
final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
Expand Down Expand Up @@ -1382,6 +1375,7 @@ public void scrollTo(int x, int y) {
if (mCustomViewBehind2 != null && mEnabled) {
mCustomViewBehind2.scrollTo((int)(x*mScrollScale), y);
}
invalidate();
}

private int determineTargetPage(int currentPage, float pageOffset, int velocity, int deltaX) {
Expand All @@ -1396,19 +1390,12 @@ private int determineTargetPage(int currentPage, float pageOffset, int velocity,

protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

// Draw the margin drawable if needed.
if (mPageMargin > 0 && mMarginDrawable != null) {
final int scrollX = getDestScrollX();
final int width = getChildWidth(mCurItem);
final int offset = scrollX % (width + mPageMargin);
if (offset != 0) {
// Pages fit completely when settled; we only need to draw when in between
final int left = scrollX - offset + width;
mMarginDrawable.setBounds(left, mTopPageBounds, left + mPageMargin,
mBottomPageBounds);
mMarginDrawable.draw(canvas);
}
if (mShadowWidth > 0 && mShadowDrawable != null) {
final int left = this.getBehindWidth() - mShadowWidth;
mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
mBottomPageBounds);
mShadowDrawable.draw(canvas);
}
}

Expand Down
Loading

0 comments on commit 52bcb09

Please sign in to comment.