Commit 9bda59c9 authored by Grigory Fedorov's avatar Grigory Fedorov

ContactViewerNew: new variant of expandable toolbar with transparent toolbar and fake panel.

parent ad8c887b
......@@ -3,46 +3,79 @@ package com.xabber.android.ui;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks;
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import com.github.ksoichiro.android.observablescrollview.ScrollUtils;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.intent.AccountIntentBuilder;
import com.xabber.android.data.intent.EntityIntentBuilder;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.helper.ContactTitleActionBarInflater;
import com.xabber.android.ui.helper.ContactTitleInflater;
import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.androiddev.R;
import static java.lang.Math.pow;
import static java.lang.Math.round;
import static java.lang.Math.sqrt;
public class ContactViewerNew extends ManagedActivity implements ObservableScrollViewCallbacks {
private Toolbar toolbar;
private int toolbarHeight;
private View actionBarView;
private int paddingLeft;
private int paddingRight;
private int actionBarSize;
private int radius;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact_viewer);
setSupportActionBar((Toolbar) findViewById(R.id.contact_viewer_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
setContentView(R.layout.activity_contact_viewer);
int[] accountActionBarColors;
int[] accountStatusBarColors;
setSupportActionBar((Toolbar) findViewById(R.id.contact_viewer_toolbar));
accountActionBarColors = getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = getResources().getIntArray(R.array.account_status_bar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
actionBarView = findViewById(R.id.title);
paddingLeft = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_left);
paddingRight = getResources().getDimensionPixelSize(R.dimen.contact_title_padding_right);
ContactTitleActionBarInflater contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setUpActionBarView();
contactTitleActionBarInflater.update(RosterManager.getInstance().getBestContact(getAccount(getIntent()), getUser(getIntent())));
TypedArray a = getTheme().obtainStyledAttributes(R.style.Theme, new int[] {R.attr.colorPrimary});
AbstractContact bestContact = RosterManager.getInstance().getBestContact(getAccount(getIntent()), getUser(getIntent()));
toolbar = (Toolbar)findViewById(R.id.contact_viewer_toolbar);
ContactTitleInflater.updateTitle(actionBarView, this, bestContact);
int colorLevel = AccountManager.getInstance().getColorLevel(bestContact.getAccount());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
actionBarView.setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
toolbarHeight = getResources().getDimensionPixelSize(R.dimen.toolbar_height);
......@@ -57,6 +90,14 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
});
}
@Override
protected void onResume() {
super.onResume();
actionBarSize = getActionBarSize();
radius = toolbarHeight - actionBarSize;
}
protected int getActionBarSize() {
TypedValue typedValue = new TypedValue();
int[] textSizeAttr = new int[]{R.attr.actionBarSize};
......@@ -81,14 +122,22 @@ public class ContactViewerNew extends ManagedActivity implements ObservableScrol
}
private void updateFlexibleSpaceText(final int scrollY) {
int actionBarSize = getActionBarSize();
if (scrollY <= radius) {
int newPadding = (int) round(sqrt(pow(radius, 2) - pow(scrollY - radius, 2)));
if (newPadding > radius) {
newPadding = radius;
}
actionBarView.setPadding(paddingLeft + newPadding, 0, paddingRight, 0);
}
int newHeight = toolbarHeight - scrollY;
if (newHeight < actionBarSize) {
newHeight = actionBarSize;
}
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
actionBarView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, newHeight));
}
public static Intent createIntent(Context context, String account, String user) {
......
......@@ -30,10 +30,16 @@
</com.github.ksoichiro.android.observablescrollview.ObservableScrollView>
<include layout="@layout/contact_title"
android:layout_height="@dimen/toolbar_height"
android:layout_width="match_parent"
android:id="@+id/title"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/contact_viewer_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:layout_height="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal"
android:background="@color/green_500"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/avatar"
android:layout_width="48dip"
android:layout_height="48dip"
android:src="@drawable/ic_avatar_1"
android:layout_gravity="bottom"
android:layout_gravity="center_vertical"
/>
<LinearLayout
......@@ -22,7 +29,7 @@
android:layout_width="0dp"
android:layout_height="48dip"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_gravity="center_vertical"
android:layout_weight="1"
>
<TextView
......@@ -76,3 +83,4 @@
/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="toolbar_height">96dp</dimen>
<dimen name="toolbar_height">108dp</dimen>
<dimen name="contact_title_padding_left">10dp</dimen>
<dimen name="contact_title_padding_right">10dp</dimen>
<dimen name="contact_title_padding_bottom">10dp</dimen>
</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