From b5306d6d25edb80657a343fbe9772a667513b9ca Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 5 Dec 2016 15:20:57 +0800 Subject: [PATCH] improved account switch indicator --- .../twidere/view/ProfileImageView.java | 22 +++++++++ .../fragment/AccountsDashboardFragment.kt | 13 +++++- .../layout/adapter_item_dashboard_account.xml | 13 +++--- .../layout/header_drawer_account_selector.xml | 46 +++++++++++++++---- .../drawable/ic_indicator_arrow_next-mdpi.svg | 13 ++++++ .../drawable/ic_indicator_arrow_prev-mdpi.svg | 13 ++++++ 6 files changed, 103 insertions(+), 17 deletions(-) create mode 100644 twidere/src/main/svg/drawable/ic_indicator_arrow_next-mdpi.svg create mode 100644 twidere/src/main/svg/drawable/ic_indicator_arrow_prev-mdpi.svg diff --git a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileImageView.java b/twidere/src/main/java/org/mariotaku/twidere/view/ProfileImageView.java index ced082070..647402d36 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/view/ProfileImageView.java +++ b/twidere/src/main/java/org/mariotaku/twidere/view/ProfileImageView.java @@ -21,6 +21,7 @@ package org.mariotaku.twidere.view; import android.content.Context; import android.util.AttributeSet; +import android.view.ViewGroup; /** * Created by mariotaku on 15/6/6. @@ -37,4 +38,25 @@ public class ProfileImageView extends ShapedImageView { public ProfileImageView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); } + + @Override + protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { + final int width = MeasureSpec.getSize(widthMeasureSpec), height = MeasureSpec.getSize(heightMeasureSpec); + final ViewGroup.LayoutParams lp = getLayoutParams(); + if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) { + super.onMeasure(makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY), makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY)); + } else if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT && lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) { + super.onMeasure(makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY), makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY)); + } else { + if (width > height) { + super.onMeasure(makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY), makeSpec(heightMeasureSpec, MeasureSpec.EXACTLY)); + } else { + super.onMeasure(makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY), makeSpec(widthMeasureSpec, MeasureSpec.EXACTLY)); + } + } + } + + private static int makeSpec(int spec, int mode) { + return MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(spec), mode); + } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt index 9eebfdb92..e0a6b1149 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt @@ -85,6 +85,8 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks. --> - - + diff --git a/twidere/src/main/res/layout/header_drawer_account_selector.xml b/twidere/src/main/res/layout/header_drawer_account_selector.xml index 0511057f0..f5252e87f 100644 --- a/twidere/src/main/res/layout/header_drawer_account_selector.xml +++ b/twidere/src/main/res/layout/header_drawer_account_selector.xml @@ -52,8 +52,6 @@ android:layout_height="wrap_content" android:focusable="false" android:paddingBottom="@dimen/element_spacing_normal" - android:paddingLeft="@dimen/element_spacing_large" - android:paddingRight="@dimen/element_spacing_large" android:paddingTop="@dimen/element_spacing_normal"> + + + + diff --git a/twidere/src/main/svg/drawable/ic_indicator_arrow_next-mdpi.svg b/twidere/src/main/svg/drawable/ic_indicator_arrow_next-mdpi.svg new file mode 100644 index 000000000..93d0d4190 --- /dev/null +++ b/twidere/src/main/svg/drawable/ic_indicator_arrow_next-mdpi.svg @@ -0,0 +1,13 @@ + + + + ic_indicator_arrow_next + Created with Sketch. + + + + + + + + \ No newline at end of file diff --git a/twidere/src/main/svg/drawable/ic_indicator_arrow_prev-mdpi.svg b/twidere/src/main/svg/drawable/ic_indicator_arrow_prev-mdpi.svg new file mode 100644 index 000000000..7ab279094 --- /dev/null +++ b/twidere/src/main/svg/drawable/ic_indicator_arrow_prev-mdpi.svg @@ -0,0 +1,13 @@ + + + + ic_indicator_arrow_prev + Created with Sketch. + + + + + + + + \ No newline at end of file