Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added panelOffScreen option to keep sliding until the panel is locate…
…d off screen (above or below, depending on the gravity)
  • Loading branch information
Alberto Manzano Torregrosa authored and alberto.manzano committed May 20, 2016
commit a1a4e81f8f225f19f58dda4953adf2945099cbd5
103 changes: 103 additions & 0 deletions demo/res/layout/activity_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DemoActivity" >

<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp"
sothree:umanoParallaxOffset="100dp"
sothree:umanoDragView="@+id/dragView"
sothree:umanoOverlay="true"
sothree:umanoScrollableView="@+id/list"
sothree:panelOffScreen="true">

<!-- MAIN CONTENT -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_toolbar"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
sothree:theme="@style/ActionBar"
android:layout_width="match_parent"/>
<TextView
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:gravity="center"
android:text="Main Content"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:textSize="16sp" />
</FrameLayout>

<!-- SLIDING LAYOUT -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
android:id="@+id/dragView">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal">

<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="14sp"
android:gravity="center_vertical"
android:paddingLeft="10dp"/>

<Button
android:id="@+id/follow"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="14sp"
android:gravity="center_vertical|right"
android:paddingRight="10dp"
android:paddingLeft="10dp"/>

</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>

<!--<ScrollView-->
<!--android:id="@+id/sv"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="0dp"-->
<!--android:layout_weight="1"-->
<!-->-->
<!--<TextView-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--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."/>-->
<!--</ScrollView>-->
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.sothree.slidinguppanel;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand All @@ -15,10 +17,12 @@
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
Expand All @@ -43,6 +47,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
*/
private static final float DEFAULT_ANCHOR_POINT = 1.0f; // In relative %

/**
* Default position of the panel
*/
private static final boolean DEFAULT_PANEL_OFF_SCREEN = false;

/**
* Default initial state for the component
*/
Expand Down Expand Up @@ -107,6 +116,11 @@ public class SlidingUpPanelLayout extends ViewGroup {
*/
private int mPanelHeight = -1;

/**
* True if we want to slide the visible panel off screen; false by default
*/
private boolean mPanelOffScreen;

/**
* The size of the shadow in pixels.
*/
Expand Down Expand Up @@ -216,6 +230,8 @@ public enum PanelState {

private final ViewDragHelper mDragHelper;

private Context mContext;

/**
* Stores whether or not the pane was expanded the last time it was slideable.
* If expand/collapse operations are invoked this state is modified. Used by
Expand Down Expand Up @@ -270,6 +286,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs) {
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

mContext = context;

if (isInEditMode()) {
mShadowDrawable = null;
mDragHelper = null;
Expand Down Expand Up @@ -311,6 +329,8 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
if (interpolatorResId != -1) {
scrollerInterpolator = AnimationUtils.loadInterpolator(context, interpolatorResId);
}

mPanelOffScreen = ta.getBoolean(R.styleable.SlidingUpPanelLayout_panelOffScreen, DEFAULT_PANEL_OFF_SCREEN);
}

ta.recycle();
Expand Down Expand Up @@ -351,6 +371,13 @@ public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();

if (mPanelOffScreen) {
// Get scrollable view (always second child) and expand its size in order to put
// the panel above the screen
View slidingUpPanelLayout = getChildAt(1);
setExpandedPanelOffScreen(slidingUpPanelLayout);
}
if (mDragViewResId != -1) {
setDragView(findViewById(mDragViewResId));
}
Expand All @@ -359,6 +386,30 @@ protected void onFinishInflate() {
}
}

/**
* Expands the height of the SlidingUpPanelLayout by 'mPanelHeight' so that there's no
* empty space at the bottom when the view is expanded
*
* @param slidingUpPanelLayout (SlidingUpPanelLayout)
*/
@TargetApi(13)
public void setExpandedPanelOffScreen(View slidingUpPanelLayout) {
if (slidingUpPanelLayout != null) {
// Get screen dimensions
final Point size = new Point();
((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(size);
final int screenHeight = size.y;
final int screenWidth = size.x;

SlidingUpPanelLayout.LayoutParams params;
params = new SlidingUpPanelLayout.LayoutParams(screenWidth, screenHeight + mPanelHeight);

slidingUpPanelLayout.setLayoutParams(params);
} else {
Log.e(TAG, "slidingUpPanelLayout is null in setExpandedPanelOffScreen");
}
}

public void setGravity(int gravity) {
if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
throw new IllegalArgumentException("gravity must be set to either top or bottom");
Expand Down Expand Up @@ -788,14 +839,29 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

child.measure(childWidthSpec, childHeightSpec);

if (child == mSlideableView) {
if (mPanelOffScreen) {
// In order to place the panel off the screen,
// the sliding distance will be the height of the entire sliding view
// minus the panel height and the notification bar
mSlideRange = mSlideableView.getMeasuredHeight() - mPanelHeight - getNotificationBarHeight();
} else {
mSlideRange = mSlideableView.getMeasuredHeight() - mPanelHeight;
}
}

setMeasuredDimension(widthSize, heightSize);
}

// Returns the height of the notification bar
private int getNotificationBarHeight() {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
return getResources().getDimensionPixelSize(resourceId);
} else {
return 0;
}
}

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int paddingLeft = getPaddingLeft();
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<attr name="umanoOverlay" format="boolean"/>
<attr name="umanoClipPanel" format="boolean"/>
<attr name="umanoAnchorPoint" format="float" />
<attr name="panelOffScreen" format="boolean" />
<attr name="umanoInitialState" format="enum">
<enum name="expanded" value="0" />
<enum name="collapsed" value="1" />
Expand Down
4 changes: 2 additions & 2 deletions maven_push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ afterEvaluate { project ->
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
repository(url: sonatypeRepositoryUrl) {
authentication(userName: "", password: "")
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
Expand Down