Commit 23ea6c57 authored by Tiago Cunha's avatar Tiago Cunha

Changing to custom toolbar

parent 7dfd882e
......@@ -34,9 +34,9 @@
android:name=".activity.AddServerActivity"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".activity.ServerConfigActivity"
android:name=".activity.LoginActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|screenSize"/>
android:configChanges="orientation|screenSize" />
<service android:name=".service.RocketChatService" />
......
package chat.rocket.android.fragment.chatroom;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import chat.rocket.android.R;
import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.widget.CustomToolbar;
abstract class AbstractChatRoomFragment extends AbstractFragment {
private static final String TABLET = "tablet";
private TextView toolbarTitle;
private CustomToolbar customToolbar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
toolbarTitle = (TextView) getActivity().findViewById(R.id.toolbar_title);
customToolbar = (CustomToolbar) getActivity().findViewById(R.id.activity_main_toolbar);
return super.onCreateView(inflater, container, savedInstanceState);
}
protected void setTitleText(@StringRes int stringResId) {
if (toolbarTitle == null) {
if (customToolbar == null) {
return;
}
toolbarTitle.setText(stringResId);
customToolbar.setTitle(stringResId);
}
protected void setTitleText(CharSequence title) {
if (toolbarTitle == null) {
if (customToolbar == null) {
return;
}
toolbarTitle.setText(title);
customToolbar.setTitle(title);
}
protected void setTitleDrawableLeft(@DrawableRes int drawableResId) {
if (toolbarTitle == null) {
if (customToolbar == null) {
return;
}
Drawable drawable = drawableResId > 0
? VectorDrawableCompat.create(getResources(), drawableResId, null)
: null;
if (drawable != null && TABLET.equals(toolbarTitle.getTag())) {
DrawableCompat.setTint(drawable, Color.WHITE);
}
toolbarTitle.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
customToolbar.setTitleDrawableLeft(drawableResId);
}
}
......@@ -14,23 +14,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
<chat.rocket.android.widget.CustomToolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:drawablePadding="@dimen/margin_8"
android:tag="tablet"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
</android.support.v7.widget.Toolbar>
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:mode="tablet"
app:titleText="@string/app_name"
app:titleDrawablePadding="@dimen/margin_8" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
......
......@@ -15,24 +15,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
<chat.rocket.android.widget.CustomToolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="@color/titleTextColor"
android:drawablePadding="@dimen/margin_8"
android:tag="phone"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
</android.support.v7.widget.Toolbar>
app:mode="phone"
app:titleText="@string/app_name"
app:titleTextColor="@color/titleTextColor"
app:titleDrawablePadding="@dimen/margin_8"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
<View
android:layout_width="match_parent"
......
package chat.rocket.android.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
public class CustomToolbar extends Toolbar {
private static final String TABLET = "tablet";
private TextView titleTextView;
private int mode;
public CustomToolbar(Context context) {
super(context);
initialize(context, null);
}
public CustomToolbar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
}
public CustomToolbar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context, attrs);
}
private void initialize(Context context, @Nullable AttributeSet attrs) {
View.inflate(context, R.layout.custom_toolbar, this);
titleTextView = (TextView) findViewById(R.id.toolbar_title);
if (titleTextView == null) {
return;
}
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CustomToolbar,
0, 0);
try {
titleTextView.setText(typedArray.getText(R.styleable.CustomToolbar_titleText));
titleTextView
.setTextColor(typedArray.getColor(R.styleable.CustomToolbar_titleTextColor, Color.BLACK));
titleTextView.setCompoundDrawablePadding(
typedArray.getLayoutDimension(R.styleable.CustomToolbar_titleDrawablePadding, 0));
mode = typedArray.getInt(R.styleable.CustomToolbar_mode, 0);
} finally {
typedArray.recycle();
}
}
@Override
public void setTitle(@StringRes int resId) {
if (titleTextView != null) {
titleTextView.setText(resId);
return;
}
super.setTitle(resId);
}
@Override
public void setTitle(CharSequence title) {
if (titleTextView != null) {
titleTextView.setText(title);
return;
}
super.setTitle(title);
}
public void setTitleDrawableLeft(@DrawableRes int drawableResId) {
if (titleTextView == null) {
return;
}
Drawable drawable = drawableResId > 0
? VectorDrawableCompat.create(getResources(), drawableResId, null)
: null;
if (drawable != null && mode == 1) {
DrawableCompat.setTint(drawable, Color.WHITE);
}
titleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
}
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
</merge>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomToolbar">
<attr name="mode" format="enum">
<enum name="phone" value="0" />
<enum name="tablet" value="1" />
</attr>
<attr name="titleText" format="string" />
<attr name="titleTextColor" format="color" />
<attr name="titleDrawablePadding" format="dimension" />
</declare-styleable>
</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