Skip to content

Commit a1a4e81

Browse files
Alberto Manzano Torregrosaalberto.manzano
authored andcommitted
Added panelOffScreen option to keep sliding until the panel is located off screen (above or below, depending on the gravity)
1 parent a592298 commit a1a4e81

File tree

4 files changed

+173
-3
lines changed

4 files changed

+173
-3
lines changed

demo/res/layout/activity_demo.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".DemoActivity" >
6+
7+
<com.sothree.slidinguppanel.SlidingUpPanelLayout
8+
xmlns:sothree="http://schemas.android.com/apk/res-auto"
9+
android:id="@+id/sliding_layout"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:gravity="bottom"
13+
sothree:umanoPanelHeight="68dp"
14+
sothree:umanoShadowHeight="4dp"
15+
sothree:umanoParallaxOffset="100dp"
16+
sothree:umanoDragView="@+id/dragView"
17+
sothree:umanoOverlay="true"
18+
sothree:umanoScrollableView="@+id/list"
19+
sothree:panelOffScreen="true">
20+
21+
<!-- MAIN CONTENT -->
22+
<FrameLayout
23+
android:layout_width="match_parent"
24+
android:layout_height="match_parent"
25+
android:orientation="vertical">
26+
<android.support.v7.widget.Toolbar
27+
xmlns:sothree="http://schemas.android.com/apk/res-auto"
28+
xmlns:android="http://schemas.android.com/apk/res/android"
29+
android:id="@+id/main_toolbar"
30+
android:layout_height="?attr/actionBarSize"
31+
android:background="?attr/colorPrimary"
32+
sothree:theme="@style/ActionBar"
33+
android:layout_width="match_parent"/>
34+
<TextView
35+
android:id="@+id/main"
36+
android:layout_width="match_parent"
37+
android:layout_height="match_parent"
38+
android:layout_marginTop="?attr/actionBarSize"
39+
android:gravity="center"
40+
android:text="Main Content"
41+
android:clickable="true"
42+
android:focusable="false"
43+
android:focusableInTouchMode="true"
44+
android:textSize="16sp" />
45+
</FrameLayout>
46+
47+
<!-- SLIDING LAYOUT -->
48+
<LinearLayout
49+
android:layout_width="match_parent"
50+
android:layout_height="match_parent"
51+
android:background="#ffffff"
52+
android:orientation="vertical"
53+
android:clickable="true"
54+
android:focusable="false"
55+
android:id="@+id/dragView">
56+
57+
<LinearLayout
58+
android:layout_width="match_parent"
59+
android:layout_height="68dp"
60+
android:orientation="horizontal">
61+
62+
<TextView
63+
android:id="@+id/name"
64+
android:layout_width="0dp"
65+
android:layout_height="match_parent"
66+
android:layout_weight="1"
67+
android:textSize="14sp"
68+
android:gravity="center_vertical"
69+
android:paddingLeft="10dp"/>
70+
71+
<Button
72+
android:id="@+id/follow"
73+
android:layout_width="wrap_content"
74+
android:layout_height="match_parent"
75+
android:textSize="14sp"
76+
android:gravity="center_vertical|right"
77+
android:paddingRight="10dp"
78+
android:paddingLeft="10dp"/>
79+
80+
</LinearLayout>
81+
82+
<ListView
83+
android:id="@+id/list"
84+
android:layout_width="match_parent"
85+
android:layout_height="0dp"
86+
android:layout_weight="1">
87+
</ListView>
88+
89+
<!--<ScrollView-->
90+
<!--android:id="@+id/sv"-->
91+
<!--android:layout_width="match_parent"-->
92+
<!--android:layout_height="0dp"-->
93+
<!--android:layout_weight="1"-->
94+
<!-->-->
95+
<!--<TextView-->
96+
<!--android:layout_width="match_parent"-->
97+
<!--android:layout_height="wrap_content"-->
98+
<!--android:text="The standard Lorem Ipsum passage, used since the 1500Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Section 1.10.32 of written by Cicero in 45 t perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?1914 translation by H. RackhamBut I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete accouof the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."/>-->
99+
<!--</ScrollView>-->
100+
</LinearLayout>
101+
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
102+
103+
</RelativeLayout>

library/src/main/java/com/sothree/slidinguppanel/SlidingUpPanelLayout.java

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.sothree.slidinguppanel;
22

33
import android.annotation.SuppressLint;
4+
import android.annotation.TargetApi;
45
import android.content.Context;
56
import android.content.res.TypedArray;
67
import android.graphics.Canvas;
78
import android.graphics.Paint;
89
import android.graphics.PixelFormat;
10+
import android.graphics.Point;
911
import android.graphics.Rect;
1012
import android.graphics.drawable.Drawable;
1113
import android.os.Build;
@@ -15,10 +17,12 @@
1517
import android.support.v4.view.MotionEventCompat;
1618
import android.support.v4.view.ViewCompat;
1719
import android.util.AttributeSet;
20+
import android.util.Log;
1821
import android.view.Gravity;
1922
import android.view.MotionEvent;
2023
import android.view.View;
2124
import android.view.ViewGroup;
25+
import android.view.WindowManager;
2226
import android.view.accessibility.AccessibilityEvent;
2327
import android.view.animation.AnimationUtils;
2428
import android.view.animation.Interpolator;
@@ -43,6 +47,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
4347
*/
4448
private static final float DEFAULT_ANCHOR_POINT = 1.0f; // In relative %
4549

50+
/**
51+
* Default position of the panel
52+
*/
53+
private static final boolean DEFAULT_PANEL_OFF_SCREEN = false;
54+
4655
/**
4756
* Default initial state for the component
4857
*/
@@ -107,6 +116,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
107116
*/
108117
private int mPanelHeight = -1;
109118

119+
/**
120+
* True if we want to slide the visible panel off screen; false by default
121+
*/
122+
private boolean mPanelOffScreen;
123+
110124
/**
111125
* The size of the shadow in pixels.
112126
*/
@@ -216,6 +230,8 @@ public enum PanelState {
216230

217231
private final ViewDragHelper mDragHelper;
218232

233+
private Context mContext;
234+
219235
/**
220236
* Stores whether or not the pane was expanded the last time it was slideable.
221237
* If expand/collapse operations are invoked this state is modified. Used by
@@ -270,6 +286,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs) {
270286
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
271287
super(context, attrs, defStyle);
272288

289+
mContext = context;
290+
273291
if (isInEditMode()) {
274292
mShadowDrawable = null;
275293
mDragHelper = null;
@@ -311,6 +329,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
311329
if (interpolatorResId != -1) {
312330
scrollerInterpolator = AnimationUtils.loadInterpolator(context, interpolatorResId);
313331
}
332+
333+
mPanelOffScreen = ta.getBoolean(R.styleable.SlidingUpPanelLayout_panelOffScreen, DEFAULT_PANEL_OFF_SCREEN);
314334
}
315335

316336
ta.recycle();
@@ -351,6 +371,13 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
351371
@Override
352372
protected void onFinishInflate() {
353373
super.onFinishInflate();
374+
375+
if (mPanelOffScreen) {
376+
// Get scrollable view (always second child) and expand its size in order to put
377+
// the panel above the screen
378+
View slidingUpPanelLayout = getChildAt(1);
379+
setExpandedPanelOffScreen(slidingUpPanelLayout);
380+
}
354381
if (mDragViewResId != -1) {
355382
setDragView(findViewById(mDragViewResId));
356383
}
@@ -359,6 +386,30 @@ protected void onFinishInflate() {
359386
}
360387
}
361388

389+
/**
390+
* Expands the height of the SlidingUpPanelLayout by 'mPanelHeight' so that there's no
391+
* empty space at the bottom when the view is expanded
392+
*
393+
* @param slidingUpPanelLayout (SlidingUpPanelLayout)
394+
*/
395+
@TargetApi(13)
396+
public void setExpandedPanelOffScreen(View slidingUpPanelLayout) {
397+
if (slidingUpPanelLayout != null) {
398+
// Get screen dimensions
399+
final Point size = new Point();
400+
((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);
401+
final int screenHeight = size.y;
402+
final int screenWidth = size.x;
403+
404+
SlidingUpPanelLayout.LayoutParams params;
405+
params = new SlidingUpPanelLayout.LayoutParams(screenWidth, screenHeight + mPanelHeight);
406+
407+
slidingUpPanelLayout.setLayoutParams(params);
408+
} else {
409+
Log.e(TAG, "slidingUpPanelLayout is null in setExpandedPanelOffScreen");
410+
}
411+
}
412+
362413
public void setGravity(int gravity) {
363414
if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
364415
throw new IllegalArgumentException("gravity must be set to either top or bottom");
@@ -788,14 +839,29 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
788839

789840
child.measure(childWidthSpec, childHeightSpec);
790841

791-
if (child == mSlideableView) {
842+
if (mPanelOffScreen) {
843+
// In order to place the panel off the screen,
844+
// the sliding distance will be the height of the entire sliding view
845+
// minus the panel height and the notification bar
846+
mSlideRange = mSlideableView.getMeasuredHeight() - mPanelHeight - getNotificationBarHeight();
847+
} else {
792848
mSlideRange = mSlideableView.getMeasuredHeight() - mPanelHeight;
793849
}
794850
}
795851

796852
setMeasuredDimension(widthSize, heightSize);
797853
}
798854

855+
// Returns the height of the notification bar
856+
private int getNotificationBarHeight() {
857+
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
858+
if (resourceId > 0) {
859+
return getResources().getDimensionPixelSize(resourceId);
860+
} else {
861+
return 0;
862+
}
863+
}
864+
799865
@Override
800866
protected void onLayout(boolean changed, int l, int t, int r, int b) {
801867
final int paddingLeft = getPaddingLeft();

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<attr name="umanoOverlay" format="boolean"/>
1313
<attr name="umanoClipPanel" format="boolean"/>
1414
<attr name="umanoAnchorPoint" format="float" />
15+
<attr name="panelOffScreen" format="boolean" />
1516
<attr name="umanoInitialState" format="enum">
1617
<enum name="expanded" value="0" />
1718
<enum name="collapsed" value="1" />

maven_push.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ afterEvaluate { project ->
4949
pom.artifactId = POM_ARTIFACT_ID
5050
pom.version = VERSION_NAME
5151

52-
repository(url: getReleaseRepositoryUrl()) {
53-
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
52+
repository(url: sonatypeRepositoryUrl) {
53+
authentication(userName: "", password: "")
5454
}
5555
snapshotRepository(url: getSnapshotRepositoryUrl()) {
5656
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())

0 commit comments

Comments
 (0)