mirror of https://github.com/tasks/tasks
NavDrawer contents visible through status bar
parent
8e909a26ba
commit
48a4a4c32e
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc.
|
||||||
|
*
|
||||||
|
* 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 org.tasks.ui;
|
||||||
|
|
||||||
|
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.v4.view.ViewCompat;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import org.tasks.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the area above UI chrome
|
||||||
|
* (status and navigation bars, overlay action bars).
|
||||||
|
*/
|
||||||
|
public class ScrimInsetsFrameLayout extends FrameLayout {
|
||||||
|
private Drawable mInsetForeground;
|
||||||
|
|
||||||
|
private Rect mInsets;
|
||||||
|
private Rect mTempRect = new Rect();
|
||||||
|
private OnInsetsCallback mOnInsetsCallback;
|
||||||
|
|
||||||
|
public ScrimInsetsFrameLayout(Context context) {
|
||||||
|
super(context);
|
||||||
|
init(context, null, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
init(context, attrs, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
init(context, attrs, defStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
final TypedArray a = context.obtainStyledAttributes(attrs,
|
||||||
|
R.styleable.ScrimInsetsFrameLayout, defStyle, 0);
|
||||||
|
if (a == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
|
||||||
|
a.recycle();
|
||||||
|
|
||||||
|
setWillNotDraw(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean fitSystemWindows(Rect insets) {
|
||||||
|
mInsets = new Rect(insets);
|
||||||
|
setWillNotDraw(mInsetForeground == null);
|
||||||
|
ViewCompat.postInvalidateOnAnimation(this);
|
||||||
|
if (mOnInsetsCallback != null) {
|
||||||
|
mOnInsetsCallback.onInsetsChanged(insets);
|
||||||
|
}
|
||||||
|
return true; // consume insets
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows the calling container to specify a callback for custom processing when insets change (i.e. when
|
||||||
|
* {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements based on
|
||||||
|
* UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, remember to set
|
||||||
|
* clipToPadding to false.
|
||||||
|
*/
|
||||||
|
public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) {
|
||||||
|
mOnInsetsCallback = onInsetsCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static interface OnInsetsCallback {
|
||||||
|
public void onInsetsChanged(Rect insets);
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +1,57 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<org.tasks.ui.ScrimInsetsFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/scrim_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:fitsSystemWindows="true"
|
||||||
|
android:background="?attr/drawer_background"
|
||||||
<ListView
|
app:insetForeground="#4000">
|
||||||
android:id="@android:id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:background="?attr/drawer_background"
|
|
||||||
android:cacheColorHint="@android:color/transparent"
|
|
||||||
android:choiceMode="singleChoice"
|
|
||||||
android:divider="@android:color/transparent"
|
|
||||||
android:fitsSystemWindows="true"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:scrollingCache="false"
|
|
||||||
tools:context=".NavigationDrawerFragment" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:background="?attr/drawer_background"
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<View
|
<ListView
|
||||||
|
android:id="@android:id/list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1px"
|
android:layout_height="0dp"
|
||||||
android:background="?attr/asSeparatorBackground" />
|
android:layout_weight="1"
|
||||||
|
android:choiceMode="singleChoice"
|
||||||
|
android:divider="@android:color/transparent"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
tools:context=".NavigationDrawerFragment" />
|
||||||
|
|
||||||
<Button
|
<LinearLayout
|
||||||
android:id="@+id/settings_row"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="45dp"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="start|center_vertical"
|
android:layout_gravity="bottom"
|
||||||
android:drawableStart="?attr/ic_action_settings"
|
android:orientation="vertical">
|
||||||
android:drawableLeft="?attr/ic_action_settings"
|
|
||||||
android:drawablePadding="10dp"
|
<View
|
||||||
android:paddingLeft="10dp"
|
android:layout_width="match_parent"
|
||||||
android:paddingStart="10dp"
|
android:layout_height="1px"
|
||||||
android:textAppearance="@style/TextAppearance.FLA_Filter"
|
android:background="?attr/asSeparatorBackground" />
|
||||||
android:layout_gravity="start"
|
|
||||||
android:text="@string/TLA_menu_settings"
|
<Button
|
||||||
android:background="?attr/selectableItemBackground"/>
|
android:id="@+id/settings_row"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="45dp"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:drawableStart="?attr/ic_action_settings"
|
||||||
|
android:drawableLeft="?attr/ic_action_settings"
|
||||||
|
android:drawablePadding="10dp"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingStart="10dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.FLA_Filter"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:text="@string/TLA_menu_settings"
|
||||||
|
android:background="?attr/selectableItemBackground" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</org.tasks.ui.ScrimInsetsFrameLayout>
|
||||||
|
Loading…
Reference in New Issue