1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Updated Navigation Drawer in MainActivity to comply with latest material design guidelines.

This commit is contained in:
Christophe Beyls 2016-01-01 20:51:50 +01:00
parent 24b6364a96
commit 14f38d5e6e
10 changed files with 250 additions and 128 deletions

View file

@ -27,7 +27,7 @@
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar.WindowDrawsSystemBarBackgrounds">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View file

@ -81,7 +81,7 @@ public class MainActivity extends AppCompatActivity {
private final int iconResId; private final int iconResId;
private final boolean keep; private final boolean keep;
private Section(Class<? extends Fragment> fragmentClass, int titleResId, int iconResId, boolean keep) { Section(Class<? extends Fragment> fragmentClass, int titleResId, int iconResId, boolean keep) {
this.fragmentClassName = fragmentClass.getName(); this.fragmentClassName = fragmentClass.getName();
this.titleResId = titleResId; this.titleResId = titleResId;
this.iconResId = iconResId; this.iconResId = iconResId;
@ -176,7 +176,9 @@ public class MainActivity extends AppCompatActivity {
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity()).setTitle(R.string.download_reminder_title).setMessage(R.string.download_reminder_message) return new AlertDialog.Builder(getActivity())
.setTitle(R.string.download_reminder_title)
.setMessage(R.string.download_reminder_message)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
@ -184,7 +186,8 @@ public class MainActivity extends AppCompatActivity {
((MainActivity) getActivity()).startDownloadSchedule(); ((MainActivity) getActivity()).startDownloadSchedule();
} }
}).setNegativeButton(android.R.string.cancel, null).create(); }).setNegativeButton(android.R.string.cancel, null)
.create();
} }
} }
@ -204,17 +207,9 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onDrawerOpened(View drawerView) { public void onDrawerOpened(View drawerView) {
updateActionBar();
supportInvalidateOptionsMenu();
// Make keypad navigation easier // Make keypad navigation easier
mainMenu.requestFocus(); mainMenu.requestFocus();
} }
@Override
public void onDrawerClosed(View drawerView) {
updateActionBar();
supportInvalidateOptionsMenu();
}
}; };
drawerToggle.setDrawerIndicatorEnabled(true); drawerToggle.setDrawerIndicatorEnabled(true);
drawerLayout.setDrawerListener(drawerToggle); drawerLayout.setDrawerListener(drawerToggle);
@ -262,11 +257,7 @@ public class MainActivity extends AppCompatActivity {
} }
private void updateActionBar() { private void updateActionBar() {
if (drawerLayout.isDrawerOpen(mainMenu)) { getSupportActionBar().setTitle(currentSection.getTitleResId());
getSupportActionBar().setTitle(null);
} else {
getSupportActionBar().setTitle(currentSection.getTitleResId());
}
} }
private void updateLastUpdateTime() { private void updateLastUpdateTime() {
@ -278,10 +269,6 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
if (drawerLayout.isDrawerOpen(mainMenu)) {
updateActionBar();
}
drawerToggle.syncState(); drawerToggle.syncState();
} }
@ -369,22 +356,6 @@ public class MainActivity extends AppCompatActivity {
return true; return true;
} }
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Hide & disable primary (contextual) action items when the main menu is opened
if (drawerLayout.isDrawerOpen(mainMenu)) {
final int size = menu.size();
for (int i = 0; i < size; ++i) {
MenuItem item = menu.getItem(i);
if ((item.getOrder() & 0xFFFF0000) == 0) {
item.setVisible(false).setEnabled(false);
}
}
}
return super.onPrepareOptionsMenu(menu);
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Will close the drawer if the home button is pressed // Will close the drawer if the home button is pressed
@ -535,6 +506,7 @@ public class MainActivity extends AppCompatActivity {
ft.commit(); ft.commit();
currentSection = section; currentSection = section;
updateActionBar();
menuAdapter.notifyDataSetChanged(); menuAdapter.notifyDataSetChanged();
} }

View file

@ -0,0 +1,116 @@
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package be.digitalia.fosdem.widgets;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.WindowInsetsCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import be.digitalia.fosdem.R;
public class ScrimInsetsFrameLayout extends FrameLayout {
private Drawable mInsetForeground;
private Rect mInsets;
private Rect mTempRect = new Rect();
public ScrimInsetsFrameLayout(Context context) {
this(context, null);
}
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
final TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
R.style.Widget_Design_ScrimInsetsFrameLayout);
mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
a.recycle();
setWillNotDraw(true); // No need to draw until the insets are adjusted
ViewCompat.setOnApplyWindowInsetsListener(this,
new android.support.v4.view.OnApplyWindowInsetsListener() {
@Override
public WindowInsetsCompat onApplyWindowInsets(View v,
WindowInsetsCompat insets) {
if (null == mInsets) {
mInsets = new Rect();
}
mInsets.set(insets.getSystemWindowInsetLeft(),
insets.getSystemWindowInsetTop(),
insets.getSystemWindowInsetRight(),
insets.getSystemWindowInsetBottom());
setWillNotDraw(mInsets.isEmpty() || mInsetForeground == null);
ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
return insets.consumeSystemWindowInsets();
}
});
}
@Override
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
int width = getWidth();
int height = getHeight();
if (mInsets != null && mInsetForeground != null) {
int sc = canvas.save();
canvas.translate(getScrollX(), getScrollY());
// Top
mTempRect.set(0, 0, width, mInsets.top);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Bottom
mTempRect.set(0, height - mInsets.bottom, width, height);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Left
mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
// Right
mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
mInsetForeground.setBounds(mTempRect);
mInsetForeground.draw(canvas);
canvas.restoreToCount(sc);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mInsetForeground != null) {
mInsetForeground.setCallback(this);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (mInsetForeground != null) {
mInsetForeground.setCallback(null);
}
}
}

View file

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<be.digitalia.fosdem.widgets.ScrimInsetsFrameLayout
android:id="@+id/main_menu"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/main_menu_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/main_menu_background"
android:fitsSystemWindows="true">
<ScrollView
android:id="@+id/main_menu_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/main_menu_footer_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/main_menu_header_height"
android:padding="@dimen/main_menu_padding"
android:scaleType="center"
android:src="@drawable/fosdem_title"/>
<be.digitalia.fosdem.widgets.AdapterLinearLayout
android:id="@+id/sections"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
style="@style/SeparatorLine"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/settings"
style="@style/MainMenuItem"
android:text="@string/settings"/>
<TextView
android:id="@+id/about"
style="@style/MainMenuItem"
android:text="@string/about"/>
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/last_update"
style="@style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="@dimen/main_menu_footer_height"
android:layout_gravity="bottom"
android:background="@color/main_menu_footer_background"
android:ellipsize="end"
android:gravity="center"
android:lines="1"
android:padding="4dp"
tools:text="DB last updated: 1 jan. 2015 13:37:00"/>
</be.digitalia.fosdem.widgets.ScrimInsetsFrameLayout>

View file

@ -1,105 +1,53 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.DrawerLayout
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"> xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<LinearLayout <!-- Main content view -->
<FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical">
<android.support.v7.widget.Toolbar <LinearLayout
android:id="@+id/toolbar"
style="@style/Toolbar.Fosdem"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/> android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.DrawerLayout <android.support.v7.widget.Toolbar
android:id="@+id/drawer_layout" android:id="@+id/toolbar"
android:layout_width="match_parent" style="@style/Toolbar.Fosdem"
android:layout_height="0dp" android:layout_width="match_parent"
android:layout_weight="1"> android:layout_height="?attr/actionBarSize"/>
<!-- Main content view -->
<FrameLayout <FrameLayout
android:id="@+id/content" android:id="@+id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="0dp"
android:layout_weight="1"/>
<!-- Left drawer --> </LinearLayout>
<LinearLayout <ProgressBar
android:id="@+id/main_menu" android:id="@+id/progress"
android:layout_width="260dp" style="?android:attr/progressBarStyleHorizontal"
android:layout_height="match_parent" android:layout_width="match_parent"
android:layout_gravity="left" android:layout_height="wrap_content"
android:background="@color/main_menu_background" android:layout_alignParentTop="true"
android:orientation="vertical"> android:layout_marginTop="-7dp"
android:max="100"
android:visibility="gone"
tools:visibility="visible"/>
<ScrollView </FrameLayout>
android:id="@+id/main_menu_scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout <!-- Navigation drawer -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView <include layout="@layout/include_navigation_drawer"/>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/main_menu_padding"
android:scaleType="center"
android:src="@drawable/fosdem_title"/>
<be.digitalia.fosdem.widgets.AdapterLinearLayout </android.support.v4.widget.DrawerLayout>
android:id="@+id/sections"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
style="@style/SeparatorLine"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/settings"
style="@style/MainMenuItem"
android:text="@string/settings"/>
<TextView
android:id="@+id/about"
style="@style/MainMenuItem"
android:text="@string/about"/>
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/last_update"
style="@style/TextAppearance.AppCompat.Caption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#10000000"
android:gravity="center"
android:padding="4dp"
tools:text="DB last updated: 1 jan. 2015 13:37:00"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="-7dp"
android:max="100"
android:visibility="gone"/>
</FrameLayout>

View file

@ -5,6 +5,11 @@
<style name="AppTheme" parent="Base.AppTheme"/> <style name="AppTheme" parent="Base.AppTheme"/>
<style name="AppTheme.NoActionBar.WindowDrawsSystemBarBackgrounds">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<!-- Styles --> <!-- Styles -->
<style name="FloatingActionButton" parent="FloatingActionButtonBase"> <style name="FloatingActionButton" parent="FloatingActionButtonBase">

View file

@ -12,4 +12,8 @@
<attr name="distributeEvenly" format="boolean"/> <attr name="distributeEvenly" format="boolean"/>
</declare-styleable> </declare-styleable>
<declare-styleable name="ScrimInsetsFrameLayout">
<attr name="insetForeground" format="color|reference"/>
</declare-styleable>
</resources> </resources>

View file

@ -5,7 +5,8 @@
<color name="color_primary_dark">#76005e</color> <color name="color_primary_dark">#76005e</color>
<color name="color_accent">#3479c4</color> <color name="color_accent">#3479c4</color>
<color name="fosdem_blue_translucent">#663479c4</color> <color name="fosdem_blue_translucent">#663479c4</color>
<color name="main_menu_background">#fffafafa</color> <color name="main_menu_background">#fafafa</color>
<color name="main_menu_footer_background">#eaeaea</color>
<color name="translucent_grey">#0c000000</color> <color name="translucent_grey">#0c000000</color>
<color name="schedule_time_background">#29000000</color> <color name="schedule_time_background">#29000000</color>
<color name="schedule_time_foreground">#000</color> <color name="schedule_time_foreground">#000</color>

View file

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<dimen name="main_menu_width">260dp</dimen>
<dimen name="main_menu_header_height">128dp</dimen>
<dimen name="main_menu_padding">16dp</dimen> <dimen name="main_menu_padding">16dp</dimen>
<dimen name="main_menu_drawable_padding">32dp</dimen> <dimen name="main_menu_drawable_padding">32dp</dimen>
<dimen name="main_menu_item_height">48dp</dimen> <dimen name="main_menu_item_height">48dp</dimen>
<dimen name="main_menu_footer_height">32dp</dimen>
<dimen name="list_item_padding">8dp</dimen> <dimen name="list_item_padding">8dp</dimen>
<dimen name="list_item_title_text_size">18sp</dimen> <dimen name="list_item_title_text_size">18sp</dimen>
<dimen name="list_item_medium_text_size">16sp</dimen> <dimen name="list_item_medium_text_size">16sp</dimen>

View file

@ -25,6 +25,8 @@
<item name="windowActionModeOverlay">true</item> <item name="windowActionModeOverlay">true</item>
</style> </style>
<style name="AppTheme.NoActionBar.WindowDrawsSystemBarBackgrounds"/>
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"> <style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">@color/color_primary</item> <item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item> <item name="colorPrimaryDark">@color/color_primary_dark</item>
@ -34,7 +36,7 @@
<style name="Toolbar.Fosdem" parent="Widget.AppCompat.Toolbar"> <style name="Toolbar.Fosdem" parent="Widget.AppCompat.Toolbar">
<item name="android:background">?attr/colorPrimary</item> <item name="android:background">?attr/colorPrimary</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item> <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> <item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style> </style>
<style name="ProgressBar.Fosdem" parent="android:Widget.ProgressBar.Horizontal"> <style name="ProgressBar.Fosdem" parent="android:Widget.ProgressBar.Horizontal">
@ -58,6 +60,10 @@
<!-- Styles --> <!-- Styles -->
<style name="Widget.Design.ScrimInsetsFrameLayout" parent="">
<item name="insetForeground">#4000</item>
</style>
<style name="MainMenuItem" parent="TextAppearance.AppCompat.Body2"> <style name="MainMenuItem" parent="TextAppearance.AppCompat.Body2">
<item name="android:background">@drawable/menu_item_background</item> <item name="android:background">@drawable/menu_item_background</item>
<item name="android:focusable">true</item> <item name="android:focusable">true</item>