Commit 03668ace authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewerNew: avatar resizing, movement trajectory improved, paddings corrected.

parent 2b05d0b6
...@@ -34,11 +34,18 @@ import static java.lang.Math.sqrt; ...@@ -34,11 +34,18 @@ import static java.lang.Math.sqrt;
public class ContactViewerNew extends ManagedActivity implements ObservableScrollViewCallbacks { public class ContactViewerNew extends ManagedActivity implements ObservableScrollViewCallbacks {
private int toolbarHeight; private int toolbarHeight;
private View actionBarView; private View avatarView;
private int paddingLeft; private View titleView;
private int paddingLeftMin;
private int paddingRight; private int paddingRight;
private int actionBarSize; private int actionBarSize;
private int radius; private int toolbarHeightDelta;
private int avatarLargeSize;
private int avatarNormalSize;
private int avatarRadius;
private View contactNamePanel;
private int contactTitlePaddingBottomBig;
private int contactTitlePaddingBottomSmall;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -56,16 +63,24 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol ...@@ -56,16 +63,24 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
accountActionBarColors = getResources().getIntArray(R.array.account_action_bar); accountActionBarColors = getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = getResources().getIntArray(R.array.account_status_bar); accountStatusBarColors = getResources().getIntArray(R.array.account_status_bar);
actionBarView = findViewById(R.id.title); titleView = findViewById(R.id.title);
avatarView = findViewById(R.id.avatar);
contactNamePanel = findViewById(R.id.contact_name_panel);
paddingLeft = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_left); paddingLeftMin = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_left);
paddingRight = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_right); paddingRight = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_right);
avatarLargeSize = getResources().getDimensionPixelSize(R.dimen.avatar_large_size);
avatarNormalSize = getResources().getDimensionPixelSize(R.dimen.avatar_normal_size);
avatarRadius = getResources().getDimensionPixelSize(R.dimen.avatar_radius);
TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme, new int[] {R.attr.colorPrimary}); contactTitlePaddingBottomBig = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_bottom_big);
contactTitlePaddingBottomSmall = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_bottom_small);
TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme, new int[]{R.attr.colorPrimary});
AbstractContact bestContact = RosterManager.getInstance().getBestContact(getAccount(getIntent()), getUser(getIntent())); AbstractContact bestContact = RosterManager.getInstance().getBestContact(getAccount(getIntent()), getUser(getIntent()));
ContactTitleInflater.updateTitle(actionBarView, this, bestContact); ContactTitleInflater.updateTitle(titleView, this, bestContact);
int colorLevel = AccountManager.getInstance().getColorLevel(bestContact.getAccount()); int colorLevel = AccountManager.getInstance().getColorLevel(bestContact.getAccount());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
...@@ -75,7 +90,7 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol ...@@ -75,7 +90,7 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
window.setStatusBarColor(accountStatusBarColors[colorLevel]); window.setStatusBarColor(accountStatusBarColors[colorLevel]);
} }
actionBarView.setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel])); titleView.setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
toolbarHeight = getResources().getDimensionPixelSize(R.dimen.toolbar_height); toolbarHeight = getResources().getDimensionPixelSize(R.dimen.toolbar_height);
...@@ -95,7 +110,7 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol ...@@ -95,7 +110,7 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
super.onResume(); super.onResume();
actionBarSize = getActionBarSize(); actionBarSize = getActionBarSize();
radius = toolbarHeight - actionBarSize; toolbarHeightDelta = toolbarHeight - actionBarSize;
} }
protected int getActionBarSize() { protected int getActionBarSize() {
...@@ -122,22 +137,65 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol ...@@ -122,22 +137,65 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
} }
private void updateFlexibleSpaceText(final int scrollY) { private void updateFlexibleSpaceText(final int scrollY) {
if (scrollY <= radius) { setLeftPadding(scrollY);
int newPadding = (int) round(sqrt(pow(radius, 2) - pow(scrollY - radius, 2))); setTopPadding(scrollY);
setAvatarSize(scrollY);
setHeight(scrollY);
}
if (newPadding > radius) { private void setTopPadding(int scrollY) {
newPadding = radius; int paddingDelta = contactTitlePaddingBottomBig - contactTitlePaddingBottomSmall;
} int paddingBottom = contactTitlePaddingBottomBig - scrollY * paddingDelta / toolbarHeightDelta;
if (scrollY <= 0) {
paddingBottom = contactTitlePaddingBottomBig;
}
if (scrollY >= toolbarHeightDelta) {
paddingBottom = contactTitlePaddingBottomSmall;
}
contactNamePanel.setPadding(0, 0, 0, paddingBottom);
}
private void setAvatarSize(int scrollY) {
int newAvatarSize = avatarLargeSize - (scrollY / 2);
if (newAvatarSize < avatarNormalSize) {
newAvatarSize = avatarNormalSize;
}
actionBarView.setPadding(paddingLeft + newPadding, 0, paddingRight, 0); if (avatarView.getWidth() != newAvatarSize) {
avatarView.getLayoutParams().width = newAvatarSize;
avatarView.getLayoutParams().height = newAvatarSize;
} }
}
private void setHeight(int scrollY) {
int newHeight = toolbarHeight - scrollY; int newHeight = toolbarHeight - scrollY;
if (newHeight < actionBarSize) { if (newHeight < actionBarSize) {
newHeight = actionBarSize; newHeight = actionBarSize;
} }
actionBarView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, newHeight)); titleView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
}
private void setLeftPadding(int scrollY) {
int paddingLeft = (int) round(sqrt(pow(avatarRadius, 2) - pow(scrollY - avatarRadius, 2)));
if (scrollY < 0) {
paddingLeft = paddingLeftMin;
}
if (scrollY > avatarRadius) {
paddingLeft = avatarRadius;
}
if (paddingLeft < paddingLeftMin) {
paddingLeft = paddingLeftMin;
}
titleView.setPadding(paddingLeft, 0, paddingRight, 0);
} }
public static Intent createIntent(Context context, String account, String user) { public static Intent createIntent(Context context, String account, String user) {
......
...@@ -30,11 +30,79 @@ ...@@ -30,11 +30,79 @@
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView> </com.github.ksoichiro.android.observablescrollview.ObservableScrollView>
<include layout="@layout/contact_title" <FrameLayout
android:layout_height="@dimen/toolbar_height" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/title" android:id="@+id/title"
/> android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@color/green_500"
android:elevation="8dp"
>
<LinearLayout
android:id="@+id/contact_name_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:paddingBottom="10dp"
>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/avatar"
android:layout_width="@dimen/avatar_large_size"
android:layout_height="@dimen/avatar_large_size"
android:src="@drawable/ic_avatar_1"
android:layout_gravity="center_vertical"
/>
<LinearLayout
android:id="@+id/name_holder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_vertical"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@color/primary_text_default_material_dark"
android:text="Lorem Ipsum"
android:layout_marginLeft="6dp"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="@+id/status_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:singleLine="true"
android:textColor="@color/grey_200"
android:text="Lorem ipsum dolor sit amet"
android:layout_marginTop="3dp"
android:layout_marginLeft="6dp"
/>
</LinearLayout>
<ImageView
android:id="@+id/status_mode"
android:src="@drawable/ic_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/contact_viewer_toolbar" android:id="@+id/contact_viewer_toolbar"
...@@ -42,6 +110,8 @@ ...@@ -42,6 +110,8 @@
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="@null"
android:elevation="8dp"
/> />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_gravity="bottom" android:layout_gravity="bottom"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="toolbar_height">108dp</dimen> <dimen name="toolbar_height">138dp</dimen>
<dimen name="contact_title_padding_left">10dp</dimen> <dimen name="contact_title_padding_left">10dp</dimen>
<dimen name="contact_title_padding_right">10dp</dimen> <dimen name="contact_title_padding_right">10dp</dimen>
<dimen name="contact_title_padding_bottom">10dp</dimen>
<dimen name="contact_title_padding_bottom_small">2dp</dimen>
<dimen name="contact_title_padding_bottom_big">10dp</dimen>
<dimen name="avatar_large_size">72dp</dimen>
<dimen name="avatar_normal_size">48dp</dimen>
<dimen name="avatar_radius">56dp</dimen>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment