Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

used SlidingPanel from Superuser app instead of my own implemention.

  • Loading branch information...
commit e8d145f3e00a3c2e6f7a8ca05f6cad0b76536dd6 1 parent 10c1db9
@mariotaku authored
View
46 res/layout-land/home_dual_pane.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<merge xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <LinearLayout
+ android:id="@+id/main_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
+ android:id="@+id/panel_anchor"
+ android:layout_width="@dimen/pane_left_width"
+ android:layout_height="match_parent"
+ android:layout_weight="0">
+
+ <org.mariotaku.twidere.view.ExtendedViewPager
+ android:id="@+id/main"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <FrameLayout
+ android:id="@+id/fragment_container_left"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+ </org.mariotaku.twidere.view.ExtendedFrameLayout>
+
+ <FrameLayout
+ android:id="@+id/fragment_container_right"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_weight="1"/>
+ </LinearLayout>
+
+ <ImageButton
+ android:id="@+id/button_compose"
+ android:layout_width="56dp"
+ android:layout_height="56dp"
+ android:layout_gravity="bottom|right"
+ android:contentDescription="@string/compose"
+ android:onClick="onClick"
+ android:src="@drawable/ic_menu_tweet"/>
+
+</merge>
View
2  res/layout/home.xml
@@ -2,7 +2,7 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<org.mariotaku.twidere.view.ExtendedViewPager
- android:id="@+id/pager"
+ android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
View
73 res/layout/home_dual_pane.xml
@@ -1,52 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
-<merge xmlns:android="http://schemas.android.com/apk/res/android">
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:twidere="http://schemas.android.com/apk/res/org.mariotaku.twidere">
- <FrameLayout
+ <org.mariotaku.twidere.view.SlidingPanel
android:id="@+id/main_container"
android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout
- android:id="@+id/left_pane_layer"
+ android:layout_height="match_parent"
+ twidere:anchor="@+id/panel_anchor"
+ twidere:button="@+id/panel_button"
+ twidere:content="@+id/fragment_container_right"
+ twidere:openOverlap="4dp"
+ twidere:closedLimit="@dimen/pane_closed_limit">
+
+ <Button
+ android:id="@+id/panel_button"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:baselineAligned="false"
- android:orientation="horizontal">
-
- <org.mariotaku.twidere.view.ExtendedFrameLayout
- android:id="@+id/left_pane_container"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="@integer/pane_left_content_weight">
-
- <FrameLayout
- android:id="@+id/main"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <org.mariotaku.twidere.view.ExtendedViewPager
- android:id="@+id/pager"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </FrameLayout>
-
- <FrameLayout
- android:id="@+id/left_pane"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </org.mariotaku.twidere.view.ExtendedFrameLayout>
+ android:layout_height="64dp"/>
+
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
+ android:id="@+id/panel_anchor"
+ android:layout_width="@dimen/pane_left_width"
+ android:layout_height="match_parent">
+
+ <org.mariotaku.twidere.view.ExtendedViewPager
+ android:id="@+id/main"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <FrameLayout
+ android:id="@+id/fragment_container_left"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
<View
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="@integer/pane_left_shadow_weight"/>
- </LinearLayout>
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+ </org.mariotaku.twidere.view.ExtendedFrameLayout>
- <org.mariotaku.twidere.view.SlidePane
- android:id="@+id/right_pane_layer"
+ <FrameLayout
+ android:id="@+id/fragment_container_right"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- </FrameLayout>
+ </org.mariotaku.twidere.view.SlidingPanel>
<ImageButton
android:id="@+id/button_compose"
View
4 res/layout/status.xml
@@ -9,7 +9,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
- <FrameLayout
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
android:id="@+id/status_container"
android:layout_width="match_parent"
android:layout_height="0dp"
@@ -30,4 +30,4 @@
android:layout_gravity="center"
android:visibility="gone"/>
-</FrameLayout>
+</FrameLayout>
View
6 res/values-large-land/dimens.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <dimen name="pane_left_width">420dp</dimen>
+
+</resources>
View
7 res/values-large/dimens.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <dimen name="pane_left_width">375dp</dimen>
+ <dimen name="pane_closed_limit">150dp</dimen>
+
+</resources>
View
8 res/values/attrs.xml
@@ -11,5 +11,13 @@
<attr name="tabTextStyle" format="reference"/>
<attr name="tabBackground" format="reference"/>
</declare-styleable>
+ <declare-styleable name="SlidingPanel">
+ <attr name="button" format="reference" />
+ <attr name="anchor" format="reference" />
+ <attr name="content" format="reference" />
+ <attr name="openOverlap" format="dimension" />
+ <attr name="closedLimit" format="dimension" />
+ </declare-styleable>
+
</resources>
View
2  res/values/dimens.xml
@@ -10,5 +10,7 @@
<dimen name="notification_large_icon_width">64dp</dimen>
<!-- The width of the big icons in notifications. -->
<dimen name="notification_large_icon_height">64dp</dimen>
+ <dimen name="pane_left_width">300dp</dimen>
+ <dimen name="pane_closed_limit">120dp</dimen>
</resources>
View
5 src/org/mariotaku/twidere/Constants.java
@@ -471,9 +471,8 @@
public static final String DIR_NAME_PROFILE_IMAGES = "profile_images";
public static final String DIR_NAME_CACHED_THUMBNAILS = "cached_thumbnails";
- public static final int PANE_LEFT = R.id.left_pane;
- public static final int PANE_LEFT_CONTAINER = R.id.left_pane_container;
- public static final int PANE_RIGHT = R.id.right_pane;
+ public static final int PANE_LEFT = R.id.fragment_container_left;
+ public static final int PANE_RIGHT = R.id.fragment_container_right;
public static final int PANE_RIGHT_CONTAINER = R.id.right_pane_container;
public static final int NOTIFICATION_ID_HOME_TIMELINE = 1;
View
32 src/org/mariotaku/twidere/activity/DualPaneActivity.java
@@ -22,7 +22,6 @@
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.Panes;
import org.mariotaku.twidere.view.ExtendedFrameLayout;
-import org.mariotaku.twidere.view.ExtendedFrameLayout.TouchInterceptor;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -41,30 +40,22 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
-import org.mariotaku.twidere.view.SlidePane;
@SuppressLint("Registered")
public class DualPaneActivity extends BaseActivity implements OnBackStackChangedListener {
private SharedPreferences mPreferences;
- private FrameLayout mLeftPaneContainer, mRightPaneContainer;
- private ViewGroup mLeftPaneLayer, mRightPaneLayer;
+ private FrameLayout mFragmentContainerLeft, mFragmentContainerRight;
private Fragment mDetailsFragment;
private boolean mDualPaneInPortrait, mDualPaneInLandscape;
public final void bringLeftPaneToFront() {
- if (mRightPaneLayer instanceof SlidePane) {
- ((SlidePane)mRightPaneLayer).close();
- }
}
public final void bringRightPaneToFront() {
- if (mRightPaneLayer instanceof SlidePane) {
- ((SlidePane)mRightPaneLayer).open();
- }
}
public Fragment getDetailsFragment() {
@@ -72,10 +63,7 @@ public Fragment getDetailsFragment() {
}
public final boolean isDualPaneMode() {
- if (!(findViewById(PANE_LEFT_CONTAINER) instanceof ViewGroup && findViewById(PANE_RIGHT_CONTAINER) instanceof ViewGroup))
- return false;
- final View main_container = findViewById(R.id.main_container);
- return main_container != null && main_container instanceof FrameLayout;
+ return findViewById(PANE_LEFT) instanceof ViewGroup && findViewById(PANE_RIGHT) instanceof ViewGroup;
}
@Override
@@ -104,9 +92,8 @@ public void onBackStackChanged() {
bringRightPaneToFront();
}
}
- mRightPaneContainer.setBackgroundResource(getPaneBackground());
if (main_view != null) {
- main_view.setVisibility(left_pane_used ? View.GONE : View.VISIBLE);
+ //main_view.setVisibility(left_pane_used ? View.GONE : View.VISIBLE);
}
}
}
@@ -115,13 +102,8 @@ public void onBackStackChanged() {
public void onContentChanged() {
super.onContentChanged();
if (isDualPaneMode()) {
- mLeftPaneContainer = (FrameLayout) findViewById(R.id.left_pane_container);
- mLeftPaneLayer = (ViewGroup) findViewById(R.id.left_pane_layer);
- mRightPaneContainer = (FrameLayout) findViewById(R.id.right_pane_container);
- mRightPaneLayer = (ViewGroup) findViewById(R.id.right_pane_layer);
- if (mRightPaneLayer instanceof SlidePane) {
- ((SlidePane)mRightPaneLayer).closeNoAnimation();
- }
+ mFragmentContainerLeft = (FrameLayout) findViewById(PANE_LEFT);
+ mFragmentContainerRight = (FrameLayout) findViewById(PANE_RIGHT);
}
}
@@ -146,8 +128,8 @@ public void onCreate(final Bundle savedInstanceState) {
break;
}
setContentView(layout);
- if (mRightPaneContainer != null) {
- mRightPaneContainer.setBackgroundResource(getPaneBackground());
+ if (mFragmentContainerRight != null) {
+ mFragmentContainerRight.setBackgroundResource(getPaneBackground());
}
getSupportFragmentManager().addOnBackStackChangedListener(this);
}
View
2  src/org/mariotaku/twidere/activity/HomeActivity.java
@@ -165,7 +165,7 @@ public void onClick(final View v) {
@Override
public void onContentChanged() {
super.onContentChanged();
- mViewPager = (ExtendedViewPager) findViewById(R.id.pager);
+ mViewPager = (ExtendedViewPager) findViewById(R.id.main);
mComposeButton = (ImageButton) findViewById(R.id.button_compose);
}
View
21 src/org/mariotaku/twidere/fragment/StatusFragment.java
@@ -65,6 +65,7 @@
import org.mariotaku.twidere.util.SynchronizedStateSavedList;
import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.view.ColorLabelRelativeLayout;
+import org.mariotaku.twidere.view.ExtendedFrameLayout;
import twitter4j.Relationship;
import twitter4j.Twitter;
@@ -96,8 +97,6 @@
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
-import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
@@ -155,7 +154,7 @@
private Gallery mGallery;
private View mStatusView;
private View mLoadImagesIndicator;
- private FrameLayout mStatusContainer;
+ private ExtendedFrameLayout mStatusContainer;
private ListView mListView;
private ParcelableStatus mStatus;
@@ -428,14 +427,15 @@ public boolean onMenuItemClick(final MenuItem item) {
}
};
- private final OnGlobalLayoutListener mOnGlobalLayoutListener = new OnGlobalLayoutListener() {
+ private final ExtendedFrameLayout.OnSizeChangedListener mOnSizeChangedListener = new ExtendedFrameLayout.OnSizeChangedListener() {
+
@Override
- public void onGlobalLayout() {
- // mMainContent.getViewTreeObserver().removeGlobalOnLayoutListener(this);
+ public void onSizeChanged(View view, int w, int h, int oldw, int oldh) {
if (getActivity() == null) return;
final float density = getResources().getDisplayMetrics().density;
- mStatusView.setMinimumHeight((int) (mStatusContainer.getHeight() - density * 2));
+ mStatusView.setMinimumHeight(h - (int) (density * 2));
}
+
};
public void displayStatus(final ParcelableStatus status) {
@@ -638,14 +638,11 @@ public void onClick(final View view) {
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.status, null, false);
mMainContent = view.findViewById(R.id.content);
- final ViewTreeObserver observer = mMainContent.getViewTreeObserver();
- if (observer.isAlive()) {
- observer.addOnGlobalLayoutListener(mOnGlobalLayoutListener);
- }
mStatusLoadProgress = (ProgressBar) view.findViewById(R.id.status_load_progress);
mMenuBar = (MenuBar) view.findViewById(R.id.menu_bar);
- mStatusContainer = (FrameLayout) view.findViewById(R.id.status_container);
+ mStatusContainer = (ExtendedFrameLayout) view.findViewById(R.id.status_container);
mStatusContainer.addView(super.onCreateView(inflater, container, savedInstanceState));
+ mStatusContainer.setOnSizeChangedListener(mOnSizeChangedListener);
mStatusView = inflater.inflate(R.layout.status_content, null, false);
mImagesPreviewContainer = mStatusView.findViewById(R.id.images_preview);
mLocationView = (TextView) mStatusView.findViewById(R.id.location_view);
View
24 src/org/mariotaku/twidere/util/ExtendedViewInterface.java
@@ -0,0 +1,24 @@
+package org.mariotaku.twidere.util;
+
+import android.view.MotionEvent;
+import android.view.View;
+
+public interface ExtendedViewInterface {
+
+ public void setOnSizeChangedListener(final OnSizeChangedListener listener);
+
+ public void setTouchInterceptor(final TouchInterceptor listener);
+
+ public static interface OnSizeChangedListener {
+ void onSizeChanged(View view, int w, int h, int oldw, int oldh);
+ }
+
+ public static interface TouchInterceptor {
+
+ boolean onInterceptTouchEvent(View view, MotionEvent event);
+
+ boolean onTouchEvent(View view, MotionEvent event);
+
+ }
+
+}
View
17 src/org/mariotaku/twidere/view/ExtendedFrameLayout.java
@@ -19,12 +19,15 @@
package org.mariotaku.twidere.view;
+import org.mariotaku.twidere.util.ExtendedViewInterface;
+
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;
+import android.view.View;
-public class ExtendedFrameLayout extends FrameLayout {
+public class ExtendedFrameLayout extends FrameLayout implements ExtendedViewInterface {
private TouchInterceptor mTouchInterceptor;
private OnSizeChangedListener mOnSizeChangedListener;
@@ -44,7 +47,7 @@ public ExtendedFrameLayout(final Context context, final AttributeSet attrs, fina
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onInterceptTouchEvent(event);
+ mTouchInterceptor.onInterceptTouchEvent(this, event);
}
return super.onInterceptTouchEvent(event);
}
@@ -52,7 +55,7 @@ public boolean onInterceptTouchEvent(final MotionEvent event) {
@Override
public boolean onTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onInterceptTouchEvent(event);
+ mTouchInterceptor.onTouchEvent(this, event);
}
return super.onTouchEvent(event);
}
@@ -73,12 +76,4 @@ protected void onSizeChanged(final int w, final int h, final int oldw, final int
}
}
- public interface OnSizeChangedListener {
- void onSizeChanged(FrameLayout view, int w, int h, int oldw, int oldh);
- }
-
- public interface TouchInterceptor {
- void onInterceptTouchEvent(MotionEvent event);
- }
-
}
View
79 src/org/mariotaku/twidere/view/ExtendedLinearLayout.java
@@ -0,0 +1,79 @@
+/*
+ * Twidere - Twitter client for Android
+ *
+ * Copyright (C) 2012 Mariotaku Lee <mariotaku.lee@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.mariotaku.twidere.view;
+
+import org.mariotaku.twidere.util.ExtendedViewInterface;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.widget.LinearLayout;
+import android.view.View;
+
+public class ExtendedLinearLayout extends LinearLayout implements ExtendedViewInterface {
+
+ private TouchInterceptor mTouchInterceptor;
+ private OnSizeChangedListener mOnSizeChangedListener;
+
+ public ExtendedLinearLayout(final Context context) {
+ super(context);
+ }
+
+ public ExtendedLinearLayout(final Context context, final AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public ExtendedLinearLayout(final Context context, final AttributeSet attrs, final int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(final MotionEvent event) {
+ if (mTouchInterceptor != null) {
+ mTouchInterceptor.onInterceptTouchEvent(this, event);
+ }
+ return super.onInterceptTouchEvent(event);
+ }
+
+ @Override
+ public boolean onTouchEvent(final MotionEvent event) {
+ if (mTouchInterceptor != null) {
+ mTouchInterceptor.onTouchEvent(this, event);
+ }
+ return super.onTouchEvent(event);
+ }
+
+ public void setOnSizeChangedListener(final OnSizeChangedListener listener) {
+ mOnSizeChangedListener = listener;
+ }
+
+ public void setTouchInterceptor(final TouchInterceptor listener) {
+ mTouchInterceptor = listener;
+ }
+
+ @Override
+ protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) {
+ super.onSizeChanged(w, h, oldw, oldh);
+ if (mOnSizeChangedListener != null) {
+ mOnSizeChangedListener.onSizeChanged(this, w, h, oldw, oldh);
+ }
+ }
+
+}
View
381 src/org/mariotaku/twidere/view/SlidePane.java
@@ -1,381 +0,0 @@
-/*
- * Twidere - Twitter client for Android
- *
- * Copyright (C) 2012 Mariotaku Lee <mariotaku.lee@gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.mariotaku.twidere.view;
-
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-
-import org.mariotaku.twidere.R;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Color;
-import android.util.AttributeSet;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.widget.FrameLayout;
-import android.widget.LinearLayout;
-import android.widget.Toast;
-import android.view.animation.TranslateAnimation;
-import android.view.animation.Animation;
-import android.widget.ImageView;
-import android.graphics.drawable.ColorDrawable;
-import android.view.animation.AlphaAnimation;
-
-public class SlidePane extends FrameLayout {
-
- private final LinearLayout mInternalLinearLayout;
- private final FrameLayout mInternalContentView;
- private final View mBlankView;
- private final ShadeLayer mShadeLayer;
-
- private int mBlankViewWidth, mContentWidth;
-
- private boolean mFirstCreate = true;
-
- private final boolean mShouldDisableScroll;
-
- public SlidePane(Context context) {
- this(context, null);
- }
-
- public SlidePane(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public SlidePane(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- mInternalLinearLayout = new InternalLinearLayout(this);
- setWillNotDraw(false);
- setClipChildren(false);
- final Resources res = getResources();
- mShouldDisableScroll = res.getBoolean(R.bool.should_disable_scroll);
- final LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(0, MATCH_PARENT, res.getInteger(R.integer.pane_right_shadow_weight));
- mInternalLinearLayout.addView(mBlankView = new BlankView(this), lp1);
- final LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(0, MATCH_PARENT, res.getInteger(R.integer.pane_right_content_weight));
- mInternalLinearLayout.addView(mInternalContentView = new InternalContentView(this), lp2);
- addView(mShadeLayer = new ShadeLayer(this));
- addView(mInternalLinearLayout);
- final FrameLayout v = new FrameLayout(context);
- v.setId(R.id.right_pane);
- addContent(v);
- }
-
- public void addContent(View view) {
- mInternalContentView.addView(view);
- }
-
- public void addContent(View view, FrameLayout.LayoutParams params) {
- mInternalContentView.addView(view, params);
- }
-
- static class ShadeLayer extends ImageView {
-
- final SlidePane parent;
-
- float alpha;
-
- ShadeLayer(SlidePane parent) {
- super(parent.getContext());
- this.parent = parent;
- setImageDrawable(new ColorDrawable(0x40000000));
- }
-//
-// public float getAlpha() {
-// return alpha;
-// }
-//
-// public void setAlpha(int alpha) {
-// this.alpha = (float) alpha / 0xFF;
-// super.setAlpha(alpha);
-// }
-//
-// public void setAlpha(float alpha) {
-// setAlpha((int)(alpha * 0xFF));
-// }
- }
-
- void abortAnimation() {
- final Animation scroll_anim = mInternalLinearLayout.getAnimation();
- if (scroll_anim != null) {
- scroll_anim.cancel();
- }
- }
-
- void animateContentTo(final int x) {
- if (shouldDisableScroll()) return;
- abortAnimation();
- final int scroll = getContentScrollX();
- final int move = x - scroll;
- if (move == 0) return;
- final long dur = 3000;
- final TranslateAnimation scroll_anim = new TranslateAnimation(0, move, 0, 0);
- scroll_anim.setDuration(dur);
- scroll_anim.setFillEnabled(true);
- scroll_anim.setFillAfter(true);
- scroll_anim.setFillBefore(true);
- scroll_anim.setAnimationListener(new ScrollAnimationListener(move));
- mInternalLinearLayout.startAnimation(scroll_anim);
- final int max = getMaxScrollWidth();
- final AlphaAnimation alpha_anim = new AlphaAnimation(((float)(max + scroll) / max), ((float)(max + x) / max));
- alpha_anim.setDuration(dur);
- mShadeLayer.startAnimation(alpha_anim);
- }
-
- class ScrollAnimationListener implements Animation.AnimationListener {
-
- final int move;
-
- ScrollAnimationListener(int move) {
- this.move = move;
- }
-
- public void onAnimationStart(Animation anim) {
- }
-
- public void onAnimationEnd(Animation anim) {
- mInternalLinearLayout.offsetLeftAndRight(move);
- }
-
- public void onAnimationRepeat(Animation anim) {
- }
-
- }
-
- public void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- if (mFirstCreate) {
- post(new CloseNoAnimationRunnable());
- mFirstCreate = false;
- }
- }
-
- static class InternalLinearLayout extends LinearLayout {
-
- private final SlidePane parent;
-
- InternalLinearLayout(SlidePane parent) {
- super(parent.getContext());
- this.parent = parent;
- }
-
- public void onScrollChanged(int l, int t, int oldl, int oldt) {
- super.onScrollChanged(l, t, oldl, oldt);
- if (parent.shouldDisableScroll()) {
- parent.setBackgroundColor(Color.TRANSPARENT);
- return;
- }
- final int max = parent.getMaxScrollWidth();
- final float percent = (float)(limit(l + max, 0, max)) / max;
- parent.setShadeAlpha((int)(percent * 0xFF));
- }
-
- }
-
- void setShadeAlpha(int alpha) {
- mShadeLayer.setAlpha(alpha);
- }
-
- class CloseNoAnimationRunnable implements Runnable {
-
- public void run() {
- closeNoAnimation();
- }
- }
-
- boolean shouldDisableScroll() {
- return mShouldDisableScroll;
- }
-
- void scrollContentTo(int x) {
- if (shouldDisableScroll()) return;
- mInternalLinearLayout.offsetLeftAndRight(x);
- }
-
- int getContentScrollX() {
- return mInternalLinearLayout.getLeft();
- //return mInternalLinearLayout.getScrollX();
- }
-
- int getMaxScrollWidth() {
- return mContentWidth - mBlankViewWidth;
- }
-
- void setBlankViewWidth(int width) {
- mBlankViewWidth = width;
- }
-
- void setContentWidth(int width) {
- mContentWidth = width;
- }
-
- void updateMainBackground() {
- if (shouldDisableScroll()) {
- setBackgroundColor(Color.TRANSPARENT);
- return;
- }
- final int sx = getScrollX();
- final int max = getMaxScrollWidth();
- final float percent = (float)(limit(sx + max, 0, max)) / max;
- setShadeAlpha((int)(percent * 0xFF));
- }
-
- static class BlankView extends View {
-
- private final SlidePane parent;
-
- public BlankView(SlidePane parent) {
- super(parent.getContext());
- this.parent = parent;
- setBackgroundResource(R.drawable.right_pane_shadow);
- }
-
- public void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- parent.setBlankViewWidth(w);
- }
-
- public boolean onTouchEvent(MotionEvent event) {
- final int action = event.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN: {
- parent.abortAnimation();
- parent.close();
- break;
- }
- }
- return super.onTouchEvent(event);
- }
- }
-
- static class InternalContentView extends FrameLayout {
-
- private final SlidePane parent;
- private final ViewConfiguration conf;
-
- private int mTotalMove;
- private Integer mTempDelta;
-
- InternalContentView(SlidePane parent) {
- super(parent.getContext());
- this.parent = parent;
- this.conf = ViewConfiguration.get(getContext());
- setWillNotDraw(false);
- setId(R.id.right_pane_container);
- }
-
- public void onSizeChanged(int w, int h, int oldw, int oldh) {
- super.onSizeChanged(w, h, oldw, oldh);
- parent.setContentWidth(w);
- parent.updateMainBackground();
- }
-
- public boolean onInterceptTouchEvent(MotionEvent event) {
- if (parent.shouldDisableScroll()) return false;
- final int action = event.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN: {
- parent.abortAnimation();
- mTempDelta = null;
- break;
- }
- case MotionEvent.ACTION_MOVE: {
- final int history_size = event.getHistorySize();
- if (history_size <= 0) break;
- final int delta = Math.round(event.getHistoricalX(0) - event.getX());
- if (delta != 0) mTempDelta = delta;
- mTotalMove += delta;
- if (Math.abs(mTotalMove) >= conf.getScaledTouchSlop()) return true;
- break;
- }
- case MotionEvent.ACTION_UP: {
- final int move = mTotalMove;
- mTotalMove = 0;
- if (Math.abs(move) >= conf.getScaledTouchSlop()) {
- return true;
- }
- break;
- }
- }
- return false;
- }
-
- public boolean onTouchEvent(MotionEvent event) {
- if (parent.shouldDisableScroll()) return false;
- final int max = parent.getMaxScrollWidth();
- final int action = event.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN: {
- parent.abortAnimation();
- break;
- }
- case MotionEvent.ACTION_MOVE: {
- final int history_size = event.getHistorySize();
- if (history_size <= 0) break;
- final int delta = Math.round(event.getX() - event.getHistoricalX(0));
- if (delta != 0) mTempDelta = delta;
- mTotalMove += delta;
- if (Math.abs(mTotalMove) < conf.getScaledTouchSlop()) return false;
- parent.scrollContentTo(delta);
- return true;
- }
- case MotionEvent.ACTION_UP: {
- final Integer delta = mTempDelta;
- final int move = mTotalMove;
- mTempDelta = null;
- mTotalMove = 0;
- if (delta != null && Math.abs(move) >= conf.getScaledTouchSlop()) {
- parent.animateContentTo(delta < 0 ? 0 : -max);
- return true;
- }
- break;
- }
- }
- return true;
- }
- }
-
-
- static int limit(int value, int min, int max) {
- if (value < min) return min;
- if (value > max) return max;
- return value;
- }
-
- public void close() {
- if (shouldDisableScroll()) return;
- animateContentTo(getMaxScrollWidth());
- }
-
- public void open() {
- if (shouldDisableScroll()) return;
- animateContentTo(0);
- }
-
- public void closeNoAnimation() {
- if (shouldDisableScroll()) return;
- scrollContentTo(getMaxScrollWidth());
- }
-
- public void openNoAnimation() {
- if (shouldDisableScroll()) return;
- scrollContentTo(0);
- }
-}
View
196 src/org/mariotaku/twidere/view/SlidingPanel.java
@@ -0,0 +1,196 @@
+package org.mariotaku.twidere.view;
+
+import org.mariotaku.twidere.R;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.AccelerateDecelerateInterpolator;
+import android.view.animation.Animation;
+import android.view.animation.TranslateAnimation;
+import android.view.animation.Animation.AnimationListener;
+import android.widget.Button;
+
+public class SlidingPanel extends ViewGroup {
+// private static final String TAG = "Su.SlidingPanel";
+
+ private final int mButtonId;
+ private View mButton;
+ private final int mAnchorId;
+ private View mAnchor;
+ private final int mContentId;
+ private View mContent;
+
+ private final int mOpenOverlap;
+ private final int mClosedLimit;
+
+ private boolean mAnimating = false;
+ private int mFillOffset = 0;
+
+ private boolean mExpanded = true;
+
+ private Toggler mToggler;
+
+ public SlidingPanel(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public SlidingPanel(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingPanel,
+ defStyle, 0);
+
+ final int buttonId = a.getResourceId(R.styleable.SlidingPanel_button, 0);
+ if (buttonId == 0) {
+ throw new IllegalArgumentException("The button attribute is required and must refer" +
+ " to a valid child");
+ }
+
+ final int anchorId = a.getResourceId(R.styleable.SlidingPanel_anchor, 0);
+ if (anchorId == buttonId) {
+ throw new IllegalArgumentException("The anchor attribute is required and must refer" +
+ " to a different child");
+ }
+
+ final int contentId = a.getResourceId(R.styleable.SlidingPanel_content, 0);
+ if (contentId == anchorId || contentId == buttonId) {
+ throw new IllegalArgumentException("The content attribute is required and must refer" +
+ " to a different child");
+ }
+
+ mOpenOverlap = a.getDimensionPixelSize(R.styleable.SlidingPanel_openOverlap, 0);
+ mClosedLimit = a.getDimensionPixelSize(R.styleable.SlidingPanel_closedLimit, 0);
+
+ a.recycle();
+
+ mButtonId = buttonId;
+ mAnchorId = anchorId;
+ mContentId = contentId;
+
+ mToggler = new Toggler();
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ mButton = findViewById(mButtonId);
+ ((Button)mButton).setText(">");
+ if (mButton == null) {
+ throw new IllegalArgumentException("The handle attribute must refer to a child");
+ }
+
+ mAnchor = findViewById(mAnchorId);
+ if (mAnchor == null) {
+ throw new IllegalArgumentException("The anchor attribute must refer to a child");
+ }
+
+ mContent = findViewById(mContentId);
+ if (mContent == null) {
+ throw new IllegalArgumentException("The content attribute must refer to a child");
+ }
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int width = View.resolveSize(0, widthMeasureSpec);
+ int height = View.resolveSize(0, heightMeasureSpec);
+
+ final View anchor = mAnchor;
+ measureChild(anchor, widthMeasureSpec, heightMeasureSpec);
+
+ final View button = mButton;
+ measureChild(button, MeasureSpec.makeMeasureSpec(anchor.getMeasuredWidth(),
+ MeasureSpec.EXACTLY),
+ heightMeasureSpec);
+ button.setOnClickListener(mToggler);
+
+ final View content = mContent;
+ int contentWidth = width - mClosedLimit;
+ content.measure(MeasureSpec.makeMeasureSpec(contentWidth, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
+
+ setMeasuredDimension(width, height);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ final View button = mButton;
+ button.layout(0, 0, button.getMeasuredWidth(), button.getMeasuredHeight());
+
+ final View anchor = mAnchor;
+ anchor.layout(0, button.getMeasuredHeight(), anchor.getMeasuredWidth(),
+ button.getMeasuredHeight() + anchor.getMeasuredHeight());
+
+ final View content = mContent;
+ int contentLeft;
+ if (mAnimating) {
+ contentLeft = content.getLeft();
+ } else if (mExpanded) {
+ contentLeft = mClosedLimit;
+ } else {
+ contentLeft = anchor.getRight() - mOpenOverlap;
+ }
+ content.layout(contentLeft, 0,
+ contentLeft + content.getMeasuredWidth(),
+ content.getMeasuredHeight());
+ }
+
+ public void toggle() {
+ final View content = mContent;
+
+ final View anchor = mAnchor;
+ final int offset = anchor.getMeasuredWidth() - mOpenOverlap - mClosedLimit;
+ TranslateAnimation anim;
+ if (mExpanded) {
+ anim = new TranslateAnimation(0, offset, 0, 0);
+ mFillOffset = offset;
+ } else {
+ anim = new TranslateAnimation(0, -offset, 0, 0);
+ mFillOffset = -offset;
+ }
+ mExpanded = !mExpanded;
+ anim.setFillEnabled(true);
+ anim.setFillBefore(true);
+ anim.setDuration(300);
+ anim.setInterpolator(new AccelerateDecelerateInterpolator());
+ anim.setAnimationListener(new AnimationFiller());
+ content.startAnimation(anim);
+ }
+
+ private class Toggler implements OnClickListener {
+
+ @Override
+ public void onClick(View v) {
+ if (!mAnimating) {
+ toggle();
+ }
+ }
+ }
+
+ private class AnimationFiller implements AnimationListener {
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ mAnimating = false;
+ final View content = mContent;
+ content.offsetLeftAndRight(mFillOffset);
+ final Button button = (Button) mButton;
+ if (mExpanded) {
+ button.setText(">");
+ } else {
+ button.setText("<");
+ }
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ }
+
+ @Override
+ public void onAnimationStart(Animation animation) {
+ mAnimating = true;
+ }
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.