Skip to content

Commit 52bcb09

Browse files
author
jfeinstein10
committed
Drop shadows. Woo.
1 parent 0d246de commit 52bcb09

12 files changed

+173
-1549
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
3+
4+
<item android:top="35dp">
5+
<shape android:shape="rectangle" >
6+
<solid android:color="@color/holo_blue_bright" />
7+
8+
<size android:height="@dimen/menu_header_line" />
9+
</shape>
10+
</item>
11+
12+
</layer-list>
Loading

library/res/values/attrs.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
15-
-->
15+
-->
1616

1717
<resources>
1818

19-
<declare-styleable name="SlidingMenu">
19+
<declare-styleable name="SlidingMenu">
2020
<attr name="viewAbove" format="reference" />
2121
<attr name="viewBehind" format="reference" />
2222
<attr name="behindOffset" format="dimension" />
@@ -29,6 +29,8 @@
2929
<enum name="margin" value="0" />
3030
<enum name="fullscreen" value="1" />
3131
</attr>
32+
<attr name="shadowDrawable" format="reference" />
33+
<attr name="shadowWidth" format="dimension" />
3234
</declare-styleable>
3335

34-
</resources>
36+
</resources>

library/res/values/colors.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<color name="holo_blue_bright">#ff00ddff</color>
5+
6+
</resources>

library/res/values/dimen.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="menu_item_padding">10dp</dimen>
4+
<dimen name="menu_header_padding_top">8dp</dimen>
5+
<dimen name="menu_header_line">3dp</dimen>
6+
<dimen name="menu_icon_side">40dp</dimen>
7+
8+
</resources>

library/src/com/slidingmenu/lib/CustomViewAbove.java

Lines changed: 102 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,11 @@ public float getInterpolation(float t) {
7373
private ItemInfo mWindow;
7474
private ItemInfo mContent;
7575

76-
private int mCurItem; // Index of currently displayed page.
77-
private int mRestoredCurItem = -1;
78-
private Parcelable mRestoredAdapterState = null;
79-
private ClassLoader mRestoredClassLoader = null;
76+
private int mCurItem;
8077
private Scroller mScroller;
81-
private PagerObserver mObserver;
8278

83-
private int mPageMargin;
84-
private Drawable mMarginDrawable;
79+
private int mShadowWidth;
80+
private Drawable mShadowDrawable;
8581
private int mTopPageBounds;
8682
private int mBottomPageBounds;
8783

@@ -228,7 +224,7 @@ public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
228224
super(context, attrs);
229225
initCustomViewAbove(isAbove);
230226
}
231-
227+
232228
void initCustomViewAbove() {
233229
initCustomViewAbove(false);
234230
}
@@ -388,37 +384,37 @@ OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener
388384
/**
389385
* Set the margin between pages.
390386
*
391-
* @param marginPixels Distance between adjacent pages in pixels
392-
* @see #getPageMargin()
393-
* @see #setPageMarginDrawable(Drawable)
394-
* @see #setPageMarginDrawable(int)
387+
* @param shadowWidth Distance between adjacent pages in pixels
388+
* @see #getShadowWidth()
389+
* @see #setShadowDrawable(Drawable)
390+
* @see #setShadowDrawable(int)
395391
*/
396-
public void setPageMargin(int marginPixels) {
397-
final int oldMargin = mPageMargin;
398-
mPageMargin = marginPixels;
399-
400-
final int width = getWidth();
401-
recomputeScrollPosition(width, width, marginPixels, oldMargin);
392+
public void setShadowWidth(int shadowWidth) {
393+
final int oldWidth = mShadowWidth;
394+
mShadowWidth = shadowWidth;
402395

403-
requestLayout();
396+
// final int width = getWidth();
397+
// recomputeScrollPosition(width, width, shadowWidth, oldWidth);
398+
//
399+
// requestLayout();
404400
}
405401

406402
/**
407403
* Return the margin between pages.
408404
*
409405
* @return The size of the margin in pixels
410406
*/
411-
public int getPageMargin() {
412-
return mPageMargin;
407+
public int getShadowWidth() {
408+
return mShadowWidth;
413409
}
414410

415411
/**
416412
* Set a drawable that will be used to fill the margin between pages.
417413
*
418414
* @param d Drawable to display between pages
419415
*/
420-
public void setPageMarginDrawable(Drawable d) {
421-
mMarginDrawable = d;
416+
public void setShadowDrawable(Drawable d) {
417+
mShadowDrawable = d;
422418
if (d != null) refreshDrawableState();
423419
setWillNotDraw(d == null);
424420
invalidate();
@@ -429,19 +425,19 @@ public void setPageMarginDrawable(Drawable d) {
429425
*
430426
* @param resId Resource ID of a drawable to display between pages
431427
*/
432-
public void setPageMarginDrawable(int resId) {
433-
setPageMarginDrawable(getContext().getResources().getDrawable(resId));
428+
public void setShadowDrawable(int resId) {
429+
setShadowDrawable(getContext().getResources().getDrawable(resId));
434430
}
435431

436432

437433
protected boolean verifyDrawable(Drawable who) {
438-
return super.verifyDrawable(who) || who == mMarginDrawable;
434+
return super.verifyDrawable(who) || who == mShadowDrawable;
439435
}
440436

441437

442438
protected void drawableStateChanged() {
443439
super.drawableStateChanged();
444-
final Drawable d = mMarginDrawable;
440+
final Drawable d = mShadowDrawable;
445441
if (d != null && d.isStateful()) {
446442
d.setState(getDrawableState());
447443
}
@@ -555,7 +551,7 @@ void smoothScrollTo(int x, int y, int velocity) {
555551
if (velocity > 0) {
556552
duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
557553
} else {
558-
final float pageDelta = (float) Math.abs(dx) / (width + mPageMargin);
554+
final float pageDelta = (float) Math.abs(dx) / (width + mShadowWidth);
559555
duration = (int) ((pageDelta + 1) * 100);
560556
// TODO set custom duration!
561557
duration = MAX_SETTLE_DURATION;
@@ -661,75 +657,75 @@ void populate() {
661657
* state, in which case it should implement a subclass of this which
662658
* contains that state.
663659
*/
664-
// public static class SavedState extends BaseSavedState {
665-
// int position;
666-
// Parcelable adapterState;
667-
// ClassLoader loader;
668-
//
669-
// public SavedState(Parcelable superState) {
670-
// super(superState);
671-
// }
672-
//
673-
//
674-
// public void writeToParcel(Parcel out, int flags) {
675-
// super.writeToParcel(out, flags);
676-
// out.writeInt(position);
677-
// out.writeParcelable(adapterState, flags);
678-
// }
679-
//
680-
//
681-
// public String toString() {
682-
// return "FragmentPager.SavedState{"
683-
// + Integer.toHexString(System.identityHashCode(this))
684-
// + " position=" + position + "}";
685-
// }
686-
//
687-
// public static final Parcelable.Creator<SavedState> CREATOR
688-
// = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
689-
//
690-
// public SavedState createFromParcel(Parcel in, ClassLoader loader) {
691-
// return new SavedState(in, loader);
692-
// }
693-
//
694-
// public SavedState[] newArray(int size) {
695-
// return new SavedState[size];
696-
// }
697-
// });
698-
//
699-
// SavedState(Parcel in, ClassLoader loader) {
700-
// super(in);
701-
// if (loader == null) {
702-
// loader = getClass().getClassLoader();
703-
// }
704-
// position = in.readInt();
705-
// adapterState = in.readParcelable(loader);
706-
// this.loader = loader;
707-
// }
708-
// }
709-
//
710-
//
711-
// public Parcelable onSaveInstanceState() {
712-
// Parcelable superState = super.onSaveInstanceState();
713-
// SavedState ss = new SavedState(superState);
714-
// ss.position = mCurItem;
715-
// return ss;
716-
// }
717-
//
718-
//
719-
// public void onRestoreInstanceState(Parcelable state) {
720-
// if (!(state instanceof SavedState)) {
721-
// super.onRestoreInstanceState(state);
722-
// return;
723-
// }
724-
//
725-
// SavedState ss = (SavedState)state;
726-
// super.onRestoreInstanceState(ss.getSuperState());
727-
//
728-
// setCurrentItemInternal(ss.position, false, true);
729-
// mRestoredCurItem = ss.position;
730-
// mRestoredAdapterState = ss.adapterState;
731-
// mRestoredClassLoader = ss.loader;
732-
// }
660+
// public static class SavedState extends BaseSavedState {
661+
// int position;
662+
// Parcelable adapterState;
663+
// ClassLoader loader;
664+
//
665+
// public SavedState(Parcelable superState) {
666+
// super(superState);
667+
// }
668+
//
669+
//
670+
// public void writeToParcel(Parcel out, int flags) {
671+
// super.writeToParcel(out, flags);
672+
// out.writeInt(position);
673+
// out.writeParcelable(adapterState, flags);
674+
// }
675+
//
676+
//
677+
// public String toString() {
678+
// return "FragmentPager.SavedState{"
679+
// + Integer.toHexString(System.identityHashCode(this))
680+
// + " position=" + position + "}";
681+
// }
682+
//
683+
// public static final Parcelable.Creator<SavedState> CREATOR
684+
// = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
685+
//
686+
// public SavedState createFromParcel(Parcel in, ClassLoader loader) {
687+
// return new SavedState(in, loader);
688+
// }
689+
//
690+
// public SavedState[] newArray(int size) {
691+
// return new SavedState[size];
692+
// }
693+
// });
694+
//
695+
// SavedState(Parcel in, ClassLoader loader) {
696+
// super(in);
697+
// if (loader == null) {
698+
// loader = getClass().getClassLoader();
699+
// }
700+
// position = in.readInt();
701+
// adapterState = in.readParcelable(loader);
702+
// this.loader = loader;
703+
// }
704+
// }
705+
//
706+
//
707+
// public Parcelable onSaveInstanceState() {
708+
// Parcelable superState = super.onSaveInstanceState();
709+
// SavedState ss = new SavedState(superState);
710+
// ss.position = mCurItem;
711+
// return ss;
712+
// }
713+
//
714+
//
715+
// public void onRestoreInstanceState(Parcelable state) {
716+
// if (!(state instanceof SavedState)) {
717+
// super.onRestoreInstanceState(state);
718+
// return;
719+
// }
720+
//
721+
// SavedState ss = (SavedState)state;
722+
// super.onRestoreInstanceState(ss.getSuperState());
723+
//
724+
// setCurrentItemInternal(ss.position, false, true);
725+
// mRestoredCurItem = ss.position;
726+
// mRestoredAdapterState = ss.adapterState;
727+
// mRestoredClassLoader = ss.loader;
728+
// }
733729

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

893889
// Make sure scroll position is set correctly.
894890
if (w != oldw) {
895-
recomputeScrollPosition(w, oldw, mPageMargin, mPageMargin);
891+
recomputeScrollPosition(w, oldw, mShadowWidth, mShadowWidth);
896892
}
897893
}
898894

@@ -933,13 +929,10 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
933929
for (int i = 0; i < count; i++) {
934930
final View child = getChildAt(i);
935931
if (child.getVisibility() != GONE) {
936-
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
937932
int pos = infoForChild(child).position;
938933
int childLeft = 0;
939934
int childTop = 0;
940935
childLeft = getChildLeft(pos);
941-
Log.v(TAG, "Child#" + i + " left:" + childLeft +
942-
" right:" + (childLeft + child.getMeasuredWidth()));
943936
child.layout(childLeft, childTop,
944937
childLeft + child.getMeasuredWidth(),
945938
childTop + child.getMeasuredHeight());
@@ -978,7 +971,7 @@ public void computeScroll() {
978971

979972
private void pageScrolled(int xpos) {
980973
// TODO
981-
final int widthWithMargin = getChildWidth(mCurItem) + mPageMargin;
974+
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
982975
final int position = xpos / widthWithMargin;
983976
final int offsetPixels = xpos % widthWithMargin;
984977
final float offset = (float) offsetPixels / widthWithMargin;
@@ -1322,7 +1315,7 @@ public boolean onTouchEvent(MotionEvent ev) {
13221315
int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
13231316
velocityTracker, mActivePointerId);
13241317
mPopulatePending = true;
1325-
final int widthWithMargin = getChildWidth(mCurItem) + mPageMargin;
1318+
final int widthWithMargin = getChildWidth(mCurItem) + mShadowWidth;
13261319
final int scrollX = getScrollX();
13271320
final int currentPage = scrollX / widthWithMargin;
13281321
final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
@@ -1382,6 +1375,7 @@ public void scrollTo(int x, int y) {
13821375
if (mCustomViewBehind2 != null && mEnabled) {
13831376
mCustomViewBehind2.scrollTo((int)(x*mScrollScale), y);
13841377
}
1378+
invalidate();
13851379
}
13861380

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

13971391
protected void onDraw(Canvas canvas) {
13981392
super.onDraw(canvas);
1399-
14001393
// Draw the margin drawable if needed.
1401-
if (mPageMargin > 0 && mMarginDrawable != null) {
1402-
final int scrollX = getDestScrollX();
1403-
final int width = getChildWidth(mCurItem);
1404-
final int offset = scrollX % (width + mPageMargin);
1405-
if (offset != 0) {
1406-
// Pages fit completely when settled; we only need to draw when in between
1407-
final int left = scrollX - offset + width;
1408-
mMarginDrawable.setBounds(left, mTopPageBounds, left + mPageMargin,
1409-
mBottomPageBounds);
1410-
mMarginDrawable.draw(canvas);
1411-
}
1394+
if (mShadowWidth > 0 && mShadowDrawable != null) {
1395+
final int left = this.getBehindWidth() - mShadowWidth;
1396+
mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
1397+
mBottomPageBounds);
1398+
mShadowDrawable.draw(canvas);
14121399
}
14131400
}
14141401

0 commit comments

Comments
 (0)