improved account switch indicator

This commit is contained in:
Mariotaku Lee 2016-12-05 15:20:57 +08:00
parent 25a80edb05
commit b5306d6d25
6 changed files with 103 additions and 17 deletions

View File

@ -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);
}
}

View File

@ -85,6 +85,8 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
private var accountsAdapter: AccountSelectorAdapter? = null
private val hasNextAccountIndicator by lazy { accountsHeader.hasNextAccountIndicator }
private val hasPrevAccountIndicator by lazy { accountsHeader.hasPrevAccountIndicator }
private val accountsSelector by lazy { accountsHeader.otherAccountsList }
private val navigationView by lazy { view as NavigationView }
private val accountsHeader by lazy { navigationView.getHeaderView(0) }
@ -112,6 +114,15 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
layoutManager.orientation = LinearLayoutManager.HORIZONTAL
layoutManager.stackFromEnd = true
accountsSelector.adapter = accountsAdapter
accountsSelector.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
val adapter = accountsAdapter ?: return
val pagePosition = position + positionOffset
hasPrevAccountIndicator.alpha = TwidereMathUtils.clamp(pagePosition, 0f, 1f)
hasNextAccountIndicator.alpha = TwidereMathUtils.clamp(adapter.count - (pagePosition
+ 1 / adapter.getPageWidth(position)), 0f, 1f)
}
})
accountsSelector.setPageTransformer(false, AccountsSelectorTransformer)
val menuInflater = SupportMenuInflater(context)
menuInflater.inflate(R.menu.action_dashboard_timeline_toggle, accountDashboardMenu.menu)
@ -776,4 +787,4 @@ class AccountsDashboardFragment : BaseSupportFragment(), LoaderCallbacks<Account
}
}
}

View File

@ -17,22 +17,23 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<org.mariotaku.twidere.view.SquareFrameLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="@dimen/element_spacing_msmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/element_spacing_small"
tools:layout_height="48dp">
<org.mariotaku.twidere.view.ProfileImageView
android:id="@android:id/icon"
style="?profileImageStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:sivBorder="true"
app:sivBorderWidth="1.5dp"
tools:src="@mipmap/ic_launcher"/>
</org.mariotaku.twidere.view.SquareFrameLayout>
</FrameLayout>

View File

@ -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">
<org.mariotaku.twidere.view.ProfileImageView
@ -62,6 +60,8 @@
android:layout_width="@dimen/icon_size_profile_image_dashboard_current"
android:layout_height="@dimen/icon_size_profile_image_dashboard_current"
android:layout_marginBottom="@dimen/element_spacing_mlarge"
android:layout_marginLeft="@dimen/element_spacing_large"
android:layout_marginStart="@dimen/element_spacing_large"
android:layout_marginTop="@dimen/element_spacing_mlarge"
android:focusable="false"
app:sivBorder="true"
@ -73,24 +73,50 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/profileImage"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/profileImage"
android:layout_marginBottom="@dimen/element_spacing_large"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/profileImage"
android:layout_toRightOf="@id/profileImage"
android:layout_toEndOf="@+id/hasPrevAccountIndicator"
android:layout_toLeftOf="@+id/hasNextAccountIndicator"
android:layout_toRightOf="@+id/hasPrevAccountIndicator"
android:layout_toStartOf="@+id/hasNextAccountIndicator"
android:focusable="false"
tools:listitem="@layout/adapter_item_dashboard_account"
tools:paddingStart="@dimen/element_spacing_large"
tools:visibility="visible"/>
<ImageButton
android:id="@+id/hasNextAccountIndicator"
android:layout_width="@dimen/element_spacing_large"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/otherAccountsList"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/otherAccountsList"
android:background="?selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_indicator_arrow_next"/>
<ImageButton
android:id="@+id/hasPrevAccountIndicator"
android:layout_width="@dimen/element_spacing_large"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/otherAccountsList"
android:layout_alignTop="@+id/otherAccountsList"
android:layout_toEndOf="@id/profileImage"
android:layout_toRightOf="@id/profileImage"
android:background="?selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_indicator_arrow_prev"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@id/profileImage"
android:layout_marginEnd="@dimen/element_spacing_large"
android:layout_marginLeft="@dimen/element_spacing_large"
android:layout_marginRight="@dimen/element_spacing_large"
android:layout_marginStart="@dimen/element_spacing_large"
android:baselineAligned="false"
android:focusable="false"
android:gravity="center_vertical"
@ -108,7 +134,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:singleLine="true"
android:maxLines="1"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@android:color/white"
android:textStyle="bold"
@ -119,7 +145,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:singleLine="true"
android:maxLines="1"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="@color/material_grey"
tools:text="\@username"/>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="12px" height="24px" viewBox="0 0 12 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 41.2 (35397) - http://www.bohemiancoding.com/sketch -->
<title>ic_indicator_arrow_next</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Miscellaneous" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="ic_indicator_arrow_next">
<polygon id="Shape" fill="#FFFFFF" points="3.99999991 6 2.58999991 7.41 7.16999991 12 2.58999991 16.59 3.99999991 18 9.99999991 12"></polygon>
<polygon id="Shape" points="0 0 24 0 24 24 0 24"></polygon>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 752 B

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="12px" height="24px" viewBox="0 0 12 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 41.2 (35397) - http://www.bohemiancoding.com/sketch -->
<title>ic_indicator_arrow_prev</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Miscellaneous" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="ic_indicator_arrow_prev">
<polygon id="Shape" fill="#FFFFFF" points="9.41 7.41 8 6 2 12 8 18 9.41 16.59 4.83 12"></polygon>
<polygon id="Shape" points="0 0 24 0 24 24 0 24"></polygon>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 707 B