Commit 3b618e38 authored by Yusuke Iwaki's avatar Yusuke Iwaki Committed by GitHub

Merge pull request #126 from RocketChat/feature/burger-menu

Added a burger menu
parents 20b4436a 28d63853
......@@ -36,7 +36,7 @@
<activity
android:name=".activity.LoginActivity"
android:windowSoftInputMode="adjustResize"
android:configChanges="orientation|screenSize"/>
android:configChanges="orientation|screenSize" />
<service android:name=".service.RocketChatService" />
......
......@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.support.v7.widget.Toolbar;
import android.view.View;
......@@ -91,25 +92,47 @@ public class MainActivity extends AbstractAuthedActivity {
private void setupSidebar() {
SlidingPaneLayout pane = (SlidingPaneLayout) findViewById(R.id.sliding_pane);
if (pane != null) {
final SlidingPaneLayout subPane = (SlidingPaneLayout) findViewById(R.id.sub_sliding_pane);
pane.setPanelSlideListener(new SlidingPaneLayout.SimplePanelSlideListener() {
@Override
public void onPanelClosed(View panel) {
super.onPanelClosed(panel);
if (subPane != null) {
subPane.closePane();
}
}
});
if (pane == null) {
return;
}
Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
toolbar.setNavigationOnClickListener(view -> {
if (pane.isSlideable() && !pane.isOpen()) {
pane.openPane();
final SlidingPaneLayout subPane = (SlidingPaneLayout) findViewById(R.id.sub_sliding_pane);
pane.setPanelSlideListener(new SlidingPaneLayout.SimplePanelSlideListener() {
@Override
public void onPanelClosed(View panel) {
super.onPanelClosed(panel);
if (subPane != null) {
subPane.closePane();
}
});
}
}
});
final DrawerArrowDrawable drawerArrowDrawable = new DrawerArrowDrawable(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.activity_main_toolbar);
toolbar.setNavigationIcon(drawerArrowDrawable);
toolbar.setNavigationOnClickListener(view -> {
if (pane.isSlideable() && !pane.isOpen()) {
pane.openPane();
}
});
//ref: ActionBarDrawerToggle#setProgress
pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
drawerArrowDrawable.setProgress(slideOffset);
}
@Override
public void onPanelOpened(View panel) {
drawerArrowDrawable.setVerticalMirror(true);
}
@Override
public void onPanelClosed(View panel) {
drawerArrowDrawable.setVerticalMirror(false);
}
});
}
private boolean closeSidebarIfNeeded() {
......
package chat.rocket.android.fragment.chatroom;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.support.annotation.StringRes;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import chat.rocket.android.R;
import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.widget.RoomToolbar;
abstract class AbstractChatRoomFragment extends AbstractFragment {
protected Toolbar activityToolbar;
private RoomToolbar roomToolbar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
activityToolbar = (Toolbar) getActivity().findViewById(R.id.activity_main_toolbar);
roomToolbar = (RoomToolbar) getActivity().findViewById(R.id.activity_main_toolbar);
return super.onCreateView(inflater, container, savedInstanceState);
}
protected void setTitleText(@StringRes int stringResId) {
if (roomToolbar == null) {
return;
}
roomToolbar.setTitle(stringResId);
}
protected void setTitleText(CharSequence title) {
if (roomToolbar == null) {
return;
}
roomToolbar.setTitle(title);
}
protected void setTitleDrawableLeft(@DrawableRes int drawableResId) {
if (roomToolbar == null) {
return;
}
roomToolbar.setRoomIcon(drawableResId);
}
}
......@@ -13,13 +13,13 @@ public class HomeFragment extends AbstractChatRoomFragment {
@Override
protected void onSetupView() {
activityToolbar.setTitle(R.string.home_fragment_title);
setTitleText(R.string.home_fragment_title);
}
@Override
public void onResume() {
super.onResume();
activityToolbar.setNavigationIcon(null);
activityToolbar.setTitle(R.string.home_fragment_title);
setTitleDrawableLeft(0);
setTitleText(R.string.home_fragment_title);
}
}
......@@ -266,15 +266,15 @@ public class RoomFragment extends AbstractChatRoomFragment
String type = roomSubscription.getType();
if (RoomSubscription.TYPE_CHANNEL.equals(type)) {
activityToolbar.setNavigationIcon(R.drawable.ic_hashtag_gray_24dp);
setTitleDrawableLeft(R.drawable.ic_hashtag_gray_24dp);
} else if (RoomSubscription.TYPE_PRIVATE.equals(type)) {
activityToolbar.setNavigationIcon(R.drawable.ic_lock_gray_24dp);
setTitleDrawableLeft(R.drawable.ic_lock_gray_24dp);
} else if (RoomSubscription.TYPE_DIRECT_MESSAGE.equals(type)) {
activityToolbar.setNavigationIcon(R.drawable.ic_at_gray_24dp);
setTitleDrawableLeft(R.drawable.ic_at_gray_24dp);
} else {
activityToolbar.setNavigationIcon(null);
setTitleDrawableLeft(0);
}
activityToolbar.setTitle(roomSubscription.getName());
setTitleText(roomSubscription.getName());
}
private void onUpdateLoadMessageProcedure(LoadMessageProcedure procedure) {
......
......@@ -14,12 +14,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
<chat.rocket.android.widget.RoomToolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/white"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name" />
app:titleText="@string/app_name"
app:titleTextColor="@color/titleTextColor"
app:titleDrawablePadding="@dimen/margin_8" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
......
......@@ -15,19 +15,21 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
<chat.rocket.android.widget.RoomToolbar
android:id="@+id/activity_main_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:titleTextColor="@color/titleTextColor"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="@string/app_name" />
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"
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/button_menu"
android:background="@color/borderColor"/>
android:background="@color/borderColor" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
......
......@@ -8,14 +8,17 @@
<LinearLayout
android:id="@+id/user_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimaryDark"
android:elevation="2dp"
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/margin_16">
android:paddingBottom="@dimen/margin_8"
android:paddingTop="@dimen/margin_8"
android:paddingLeft="@dimen/margin_16"
android:paddingRight="@dimen/margin_16">
<ImageView
android:id="@+id/current_user_status"
......@@ -29,8 +32,8 @@
<ImageView
android:id="@+id/current_user_avatar"
android:layout_width="48dp"
android:layout_height="48dp" />
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView
android:id="@+id/current_user_name"
......
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.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
public class RoomToolbar extends Toolbar {
private TextView titleTextView;
public RoomToolbar(Context context) {
super(context);
initialize(context, null);
}
public RoomToolbar(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
}
public RoomToolbar(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.room_toolbar, this);
titleTextView = (TextView) findViewById(R.id.toolbar_title);
if (titleTextView == null) {
return;
}
TypedArray typedArray = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.RoomToolbar,
0, 0);
try {
titleTextView.setText(typedArray.getText(R.styleable.RoomToolbar_titleText));
titleTextView
.setTextColor(typedArray.getColor(R.styleable.RoomToolbar_titleTextColor, Color.BLACK));
titleTextView.setCompoundDrawablePadding(
typedArray.getLayoutDimension(R.styleable.RoomToolbar_titleDrawablePadding, 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 setRoomIcon(@DrawableRes int drawableResId) {
if (titleTextView == null) {
return;
}
Drawable drawable = drawableResId > 0
? VectorDrawableCompat.create(getResources(), drawableResId, null)
: null;
titleTextView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
}
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
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="RoomToolbar">
<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