Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

for sync.

  • Loading branch information...
commit d3de0c3f6a90f05fada038356ec59ba073d7ada3 1 parent e8d145f
@mariotaku authored
View
38 res/layout-land/base_dual_pane.xml
@@ -0,0 +1,38 @@
+<?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"
+ android:orientation="horizontal">
+
+ <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">
+
+ <FrameLayout
+ 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>
+
+</merge>
View
3  res/layout-land/home_dual_pane.xml
@@ -4,7 +4,8 @@
<LinearLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
<org.mariotaku.twidere.view.ExtendedFrameLayout
android:id="@+id/panel_anchor"
View
4 res/layout/base.xml
@@ -2,8 +2,8 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
- android:id="@+id/content"
+ android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
-</merge>
+</merge>
View
53 res/layout/base_dual_pane.xml
@@ -1,48 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/main_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
+<merge xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:twidere="http://schemas.android.com/apk/res/org.mariotaku.twidere">
- <LinearLayout
- android:id="@+id/left_pane_layer"
+ <org.mariotaku.twidere.view.SlidingPanel
+ android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:baselineAligned="false"
- android:orientation="horizontal">
+ twidere:anchor="@+id/panel_anchor"
+ twidere:content="@+id/fragment_container_right"
+ twidere:closedLimit="@dimen/pane_closed_limit">
<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">
+ android:id="@+id/panel_anchor"
+ android:layout_width="@dimen/pane_left_width"
+ android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main"
android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <FrameLayout
- android:id="@+id/content"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
- </FrameLayout>
+ android:layout_height="match_parent"/>
<FrameLayout
- android:id="@+id/left_pane"
+ android:id="@+id/fragment_container_left"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- </org.mariotaku.twidere.view.ExtendedFrameLayout>
- <View
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="@integer/pane_left_shadow_weight"/>
- </LinearLayout>
+ <View
+ 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"
- android:layout_width="match_parent"
- android:layout_height="match_parent"/>
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
+ android:id="@+id/fragment_container_right"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+ </org.mariotaku.twidere.view.SlidingPanel>
-</FrameLayout>
+</merge>
View
9 res/layout/home_dual_pane.xml
@@ -7,16 +7,9 @@
android:layout_width="match_parent"
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="64dp"/>
-
<org.mariotaku.twidere.view.ExtendedFrameLayout
android:id="@+id/panel_anchor"
android:layout_width="@dimen/pane_left_width"
@@ -37,7 +30,7 @@
android:layout_height="match_parent"/>
</org.mariotaku.twidere.view.ExtendedFrameLayout>
- <FrameLayout
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
android:id="@+id/fragment_container_right"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
View
84 res/layout/search_dual_pane.xml
@@ -1,59 +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_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">
-
- <android.support.v4.view.PagerTabStrip
- android:id="@+id/pager_tab"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="top"/>
-
- </org.mariotaku.twidere.view.ExtendedViewPager>
- </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="match_parent"
+ twidere:anchor="@+id/panel_anchor"
+ twidere:content="@+id/fragment_container_right"
+ twidere:closedLimit="@dimen/pane_closed_limit">
+
+ <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">
+
+ <android.support.v4.view.PagerTabStrip
+ android:id="@+id/pager_tab"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="top"/>
+
+ </org.mariotaku.twidere.view.ExtendedViewPager>
+
+ <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"
+ <org.mariotaku.twidere.view.ExtendedFrameLayout
+ android:id="@+id/fragment_container_right"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
- </FrameLayout>
+ </org.mariotaku.twidere.view.SlidingPanel>
</merge>
View
8 res/values/attrs.xml
@@ -12,11 +12,9 @@
<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" />
+ <attr name="anchor" format="reference"/>
+ <attr name="content" format="reference"/>
+ <attr name="closedLimit" format="dimension"/>
</declare-styleable>
View
74 src/org/mariotaku/twidere/activity/DualPaneActivity.java
@@ -40,22 +40,66 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
+import org.mariotaku.twidere.util.ExtendedViewGroupInterface;
+import org.mariotaku.twidere.view.SlidingPanel;
@SuppressLint("Registered")
public class DualPaneActivity extends BaseActivity implements OnBackStackChangedListener {
private SharedPreferences mPreferences;
- private FrameLayout mFragmentContainerLeft, mFragmentContainerRight;
+ private SlidingPanel mSlidingPanel;
+ private FrameLayout mFragmentContainerLeft;
+ private ExtendedFrameLayout mPanelAnchor, mFragmentContainerRight;
private Fragment mDetailsFragment;
private boolean mDualPaneInPortrait, mDualPaneInLandscape;
- public final void bringLeftPaneToFront() {
+ private ExtendedViewGroupInterface.TouchInterceptor mTouchInterceptorRight = new ExtendedFrameLayout.TouchInterceptor() {
+
+ public boolean onInterceptTouchEvent(ViewGroup view, MotionEvent event) {
+ final int action = event.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN: {
+ showRightPane();
+ break;
+ }
+ }
+ return false;
+ }
+
+ public boolean onTouchEvent(ViewGroup view, MotionEvent event) {
+ return true;
+ }
+
+ };
+
+ private ExtendedViewGroupInterface.TouchInterceptor mTouchInterceptorLeft = new ExtendedFrameLayout.TouchInterceptor() {
+
+ public boolean onInterceptTouchEvent(ViewGroup view, MotionEvent event) {
+ final int action = event.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN: {
+ showLeftPane();
+ break;
+ }
+ }
+ return false;
+ }
+
+ public boolean onTouchEvent(ViewGroup view, MotionEvent event) {
+ return false;
+ }
+
+ };
+
+ public final void showLeftPane() {
+ mSlidingPanel.close();
}
- public final void bringRightPaneToFront() {
+ public final void showRightPane() {
+ mSlidingPanel.open();
}
public Fragment getDetailsFragment() {
@@ -81,19 +125,19 @@ public void onBackStackChanged() {
if (entry == null) return;
final Fragment fragment = BackStackEntryTrojan.getFragmentInBackStackRecord(entry);
if (fragment instanceof Panes.Right) {
- bringRightPaneToFront();
+ showRightPane();
} else if (fragment instanceof Panes.Left) {
- bringLeftPaneToFront();
+ showLeftPane();
}
} else {
if (fm.findFragmentById(R.id.content) != null || left_pane_used) {
- bringLeftPaneToFront();
+ showLeftPane();
} else if (right_pane_used) {
- bringRightPaneToFront();
+ showRightPane();
}
}
if (main_view != null) {
- //main_view.setVisibility(left_pane_used ? View.GONE : View.VISIBLE);
+ main_view.setVisibility(left_pane_used ? View.GONE : View.VISIBLE);
}
}
}
@@ -102,8 +146,10 @@ public void onBackStackChanged() {
public void onContentChanged() {
super.onContentChanged();
if (isDualPaneMode()) {
+ mSlidingPanel = (SlidingPanel) findViewById(R.id.main_container);
mFragmentContainerLeft = (FrameLayout) findViewById(PANE_LEFT);
- mFragmentContainerRight = (FrameLayout) findViewById(PANE_RIGHT);
+ mFragmentContainerRight = (ExtendedFrameLayout) findViewById(PANE_RIGHT);
+ mPanelAnchor = (ExtendedFrameLayout) findViewById(R.id.panel_anchor);
}
}
@@ -128,9 +174,9 @@ public void onCreate(final Bundle savedInstanceState) {
break;
}
setContentView(layout);
- if (mFragmentContainerRight != null) {
- mFragmentContainerRight.setBackgroundResource(getPaneBackground());
- }
+ mFragmentContainerRight.setBackgroundResource(getPaneBackground());
+ mFragmentContainerRight.setTouchInterceptor(mTouchInterceptorRight);
+ mPanelAnchor.setTouchInterceptor(mTouchInterceptorLeft);
getSupportFragmentManager().addOnBackStackChangedListener(this);
}
@@ -138,12 +184,12 @@ public final void showAtPane(final int pane, final Fragment fragment, final bool
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
switch (pane) {
case PANE_LEFT: {
- bringLeftPaneToFront();
+ showLeftPane();
ft.replace(PANE_LEFT, fragment);
break;
}
case PANE_RIGHT: {
- bringRightPaneToFront();
+ showRightPane();
ft.replace(PANE_RIGHT, fragment);
break;
}
View
2  src/org/mariotaku/twidere/activity/HomeActivity.java
@@ -133,7 +133,7 @@ public void onBackStackChanged() {
setPagingEnabled(!left_pane_used);
final int count = fm.getBackStackEntryCount();
if (count == 0) {
- bringLeftPaneToFront();
+ showLeftPane();
}
}
View
4 src/org/mariotaku/twidere/activity/SearchActivity.java
@@ -69,14 +69,14 @@ public void onBackStackChanged() {
mActionBar.setDisplayHomeAsUpEnabled(count > 0);
}
if (count == 0) {
- bringLeftPaneToFront();
+ showLeftPane();
}
}
@Override
public void onContentChanged() {
super.onContentChanged();
- mViewPager = (ExtendedViewPager) findViewById(R.id.pager);
+ mViewPager = (ExtendedViewPager) findViewById(R.id.main);
mPagerTab = (PagerTabStrip) findViewById(R.id.pager_tab);
}
View
2  src/org/mariotaku/twidere/activity/SettingsActivity.java
@@ -65,7 +65,7 @@ public void onCreate(final Bundle savedInstanceState) {
mPreferences.registerOnSharedPreferenceChangeListener(this);
mFragment = new InternalSettingsFragment();
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- ft.replace(R.id.content, mFragment);
+ ft.replace(R.id.main, mFragment);
ft.commit();
}
View
18 src/org/mariotaku/twidere/util/ExtendedViewGroupInterface.java
@@ -0,0 +1,18 @@
+package org.mariotaku.twidere.util;
+
+import android.view.MotionEvent;
+import android.view.ViewGroup;
+
+public interface ExtendedViewGroupInterface extends ExtendedViewInterface {
+
+ public void setTouchInterceptor(final TouchInterceptor listener);
+
+ public static interface TouchInterceptor {
+
+ boolean onInterceptTouchEvent(ViewGroup view, MotionEvent event);
+
+ boolean onTouchEvent(ViewGroup view, MotionEvent event);
+
+ }
+
+}
View
10 src/org/mariotaku/twidere/util/ExtendedViewInterface.java
@@ -7,18 +7,8 @@
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
6 src/org/mariotaku/twidere/util/Utils.java
@@ -1840,7 +1840,7 @@ public static void openDirectMessagesConversation(final Activity activity, final
final Fragment details_fragment = dual_pane_activity.getDetailsFragment();
if (details_fragment instanceof DirectMessagesConversationFragment && details_fragment.isAdded()) {
((DirectMessagesConversationFragment) details_fragment).showConversation(account_id, conversation_id);
- dual_pane_activity.bringRightPaneToFront();
+ dual_pane_activity.showRightPane();
} else {
final Fragment fragment = new DirectMessagesConversationFragment();
final Bundle args = new Bundle();
@@ -1913,7 +1913,7 @@ public static void openStatus(final Activity activity, final ParcelableStatus st
final Fragment details_fragment = dual_pane_activity.getDetailsFragment();
if (details_fragment instanceof StatusFragment && details_fragment.isAdded()) {
((StatusFragment) details_fragment).displayStatus(status);
- dual_pane_activity.bringRightPaneToFront();
+ dual_pane_activity.showRightPane();
} else {
final Fragment fragment = new StatusFragment();
final Bundle args = new Bundle(bundle);
@@ -2306,7 +2306,7 @@ public static void openUserProfile(final Activity activity, final ParcelableUser
final Fragment details_fragment = dual_pane_activity.getDetailsFragment();
if (details_fragment instanceof UserProfileFragment && details_fragment.isAdded()) {
((UserProfileFragment) details_fragment).displayUser(user);
- dual_pane_activity.bringRightPaneToFront();
+ dual_pane_activity.showRightPane();
} else {
final Fragment fragment = new UserProfileFragment();
final Bundle args = new Bundle(bundle);
View
10 src/org/mariotaku/twidere/view/ExtendedFrameLayout.java
@@ -19,7 +19,7 @@
package org.mariotaku.twidere.view;
-import org.mariotaku.twidere.util.ExtendedViewInterface;
+import org.mariotaku.twidere.util.ExtendedViewGroupInterface;
import android.content.Context;
import android.util.AttributeSet;
@@ -27,7 +27,7 @@
import android.widget.FrameLayout;
import android.view.View;
-public class ExtendedFrameLayout extends FrameLayout implements ExtendedViewInterface {
+public final class ExtendedFrameLayout extends FrameLayout implements ExtendedViewGroupInterface {
private TouchInterceptor mTouchInterceptor;
private OnSizeChangedListener mOnSizeChangedListener;
@@ -47,7 +47,8 @@ public ExtendedFrameLayout(final Context context, final AttributeSet attrs, fina
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onInterceptTouchEvent(this, event);
+ final boolean ret = mTouchInterceptor.onInterceptTouchEvent(this, event);
+ if (ret) return true;
}
return super.onInterceptTouchEvent(event);
}
@@ -55,7 +56,8 @@ public boolean onInterceptTouchEvent(final MotionEvent event) {
@Override
public boolean onTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onTouchEvent(this, event);
+ final boolean ret = mTouchInterceptor.onTouchEvent(this, event);
+ if (ret) return true;
}
return super.onTouchEvent(event);
}
View
11 src/org/mariotaku/twidere/view/ExtendedLinearLayout.java
@@ -19,7 +19,7 @@
package org.mariotaku.twidere.view;
-import org.mariotaku.twidere.util.ExtendedViewInterface;
+import org.mariotaku.twidere.util.ExtendedViewGroupInterface;
import android.content.Context;
import android.util.AttributeSet;
@@ -27,7 +27,7 @@
import android.widget.LinearLayout;
import android.view.View;
-public class ExtendedLinearLayout extends LinearLayout implements ExtendedViewInterface {
+public final class ExtendedLinearLayout extends LinearLayout implements ExtendedViewGroupInterface {
private TouchInterceptor mTouchInterceptor;
private OnSizeChangedListener mOnSizeChangedListener;
@@ -47,7 +47,8 @@ public ExtendedLinearLayout(final Context context, final AttributeSet attrs, fin
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onInterceptTouchEvent(this, event);
+ final boolean ret = mTouchInterceptor.onInterceptTouchEvent(this, event);
+ if (ret) return true;
}
return super.onInterceptTouchEvent(event);
}
@@ -55,10 +56,12 @@ public boolean onInterceptTouchEvent(final MotionEvent event) {
@Override
public boolean onTouchEvent(final MotionEvent event) {
if (mTouchInterceptor != null) {
- mTouchInterceptor.onTouchEvent(this, event);
+ final boolean ret = mTouchInterceptor.onTouchEvent(this, event);
+ if (ret) return true;
}
return super.onTouchEvent(event);
}
+
public void setOnSizeChangedListener(final OnSizeChangedListener listener) {
mOnSizeChangedListener = listener;
View
83 src/org/mariotaku/twidere/view/SlidingPanel.java
@@ -11,19 +11,14 @@
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;
@@ -31,8 +26,6 @@
private boolean mExpanded = true;
- private Toggler mToggler;
-
public SlidingPanel(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -42,44 +35,29 @@ public SlidingPanel(Context context, AttributeSet attrs, int 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) {
+ if (anchorId == 0) {
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) {
+ if (contentId == anchorId || contentId == 0) {
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");
@@ -98,13 +76,7 @@ protected void onMeasure(int widthMeasureSpec, int 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),
@@ -115,32 +87,44 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@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());
+ anchor.layout(0, 0, anchor.getMeasuredWidth(),
+ getMeasuredHeight());
final View content = mContent;
- int contentLeft;
+ final int contentLeft;
if (mAnimating) {
contentLeft = content.getLeft();
} else if (mExpanded) {
contentLeft = mClosedLimit;
} else {
- contentLeft = anchor.getRight() - mOpenOverlap;
+ contentLeft = anchor.getRight();
}
content.layout(contentLeft, 0,
contentLeft + content.getMeasuredWidth(),
content.getMeasuredHeight());
}
+
+ public void open() {
+ if (mExpanded) return;
+ toggle();
+ }
+ public void close() {
+ if (!mExpanded) return;
+ toggle();
+ }
+
+ public boolean isOpened() {
+ return mExpanded;
+ }
+
public void toggle() {
+ if (mAnimating) return;
final View content = mContent;
final View anchor = mAnchor;
- final int offset = anchor.getMeasuredWidth() - mOpenOverlap - mClosedLimit;
+ final int offset = anchor.getMeasuredWidth() - mClosedLimit;
TranslateAnimation anim;
if (mExpanded) {
anim = new TranslateAnimation(0, offset, 0, 0);
@@ -152,35 +136,18 @@ public void toggle() {
mExpanded = !mExpanded;
anim.setFillEnabled(true);
anim.setFillBefore(true);
- anim.setDuration(300);
+ anim.setDuration(200);
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) {
+ mContent.offsetLeftAndRight(mFillOffset);
mAnimating = false;
- final View content = mContent;
- content.offsetLeftAndRight(mFillOffset);
- final Button button = (Button) mButton;
- if (mExpanded) {
- button.setText(">");
- } else {
- button.setText("<");
- }
}
@Override
Please sign in to comment.
Something went wrong with that request. Please try again.