Adjust DrawerLayout for KK

This commit is contained in:
seven332 committed 2015-05-22 21:45:48 +08:00
1 parent 17625f9f97
commit 27abd5f5e0
7 files changed
+1891 -211

No files matched your search

@@ -21,12 +21,10 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import com.hippo.vectorold.content.VectorContext;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.ui.scene.GalleryListScene;
@@ -34,16 +32,18 @@ import com.hippo.ehviewer.ui.scene.SettingsHeaderScene;
import com.hippo.ehviewer.ui.scene.SignInScene;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.widget.DrawerLeftPanel;
import com.hippo.ehviewer.widget.StatusBarLayout;
import com.hippo.ehviewer.widget.FitStageLayout;
import com.hippo.scene.Announcer;
import com.hippo.scene.SimpleCurtain;
import com.hippo.scene.StageActivity;
import com.hippo.scene.StageLayout;
import com.hippo.util.Messenger;
import com.hippo.vectorold.content.VectorContext;
import com.hippo.widget.DrawerLayout;
import com.hippo.widget.DrawerListView;
public final class ContentActivity extends StageActivity
implements StatusBarLayout.OnGetFitPaddingBottomListener,
implements FitStageLayout.OnFitPaddingBottomListener,
DrawerLeftPanel.Helper {
public static final int DRAWER_LIST_NONE = -1;
@@ -57,8 +57,7 @@ public final class ContentActivity extends StageActivity
private Resources mResources;
private DrawerLayout mDrawerLayout;
private StatusBarLayout mStatusBarLayout;
private StageLayout mContentLayout;
private FitStageLayout mFitStageLayout;
private DrawerLeftPanel mDrawerLeftPanel;
private DrawerListView mDrawerListView;
@@ -110,12 +109,11 @@ public final class ContentActivity extends StageActivity
mResources = getResources();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mStatusBarLayout = (StatusBarLayout) mDrawerLayout.getChildAt(0);
mContentLayout = (StageLayout) mStatusBarLayout.findViewById(R.id.stage);
mFitStageLayout = (FitStageLayout) mDrawerLayout.getChildAt(0);
mDrawerLeftPanel = (DrawerLeftPanel) mDrawerLayout.getChildAt(1);
mDrawerListView = mDrawerLeftPanel.getDrawerListView();
mStatusBarLayout.setOnGetFitPaddingBottomListener(this);
mFitStageLayout.setOnFitPaddingBottomListener(this);
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
@@ -149,7 +147,7 @@ public final class ContentActivity extends StageActivity
@Override
public @NonNull StageLayout getStageLayout() {
return mContentLayout;
return mFitStageLayout;
}
@Override
@@ -181,8 +179,8 @@ public final class ContentActivity extends StageActivity
}
@Override
public void onGetFitPaddingBottom(int b) {
setFitPaddingBottom(b);
public void onFitPaddingBottom(int bottom) {
setFitPaddingBottom(bottom);
}
@Override
@@ -17,11 +17,9 @@ package com.hippo.ehviewer.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
@@ -37,8 +35,9 @@ import com.hippo.ehviewer.util.Config;
import com.hippo.util.FrescoUtils;
import com.hippo.util.Messenger;
import com.hippo.widget.DrawerListView;
import com.hippo.widget.FitPaddingImpl;
public class DrawerLeftPanel extends LinearLayout {
public class DrawerLeftPanel extends LinearLayout implements FitPaddingImpl{
private static final String STATE_KEY_SUPER = "super";
private static final String STATE_KEY_DRAWER_LIST_VIEW = "drawer_list_view";
@@ -206,43 +205,35 @@ public class DrawerLeftPanel extends LinearLayout {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@SuppressWarnings("deprecation")
@Override
protected boolean fitSystemWindows(@NonNull Rect insets) {
int fitPaddingTop = insets.top;
int fitPaddingBottom = insets.bottom;
if (mFitPaddingTop != fitPaddingTop) {
mFitPaddingTop = fitPaddingTop;
public void onFitPadding(int left, int top, int right, int bottom) {
if (mFitPaddingTop != top) {
mFitPaddingTop = top;
ViewGroup.LayoutParams lp;
lp = mKKStatusBarBg.getLayoutParams();
lp.height = fitPaddingTop;
lp.height = top;
mKKStatusBarBg.setLayoutParams(lp);
lp = mSuperUserPanel.getLayoutParams();
lp.height = mSuperUserPanelHeight + fitPaddingTop;
lp.height = mSuperUserPanelHeight + top;
mSuperUserPanel.setLayoutParams(lp);
mUserPanel.setPadding(mUserPanel.getPaddingLeft(),
mUserPanelOriginalPaddingTop + fitPaddingTop,
mUserPanelOriginalPaddingTop + top,
mUserPanel.getPaddingRight(),
mUserPanel.getPaddingBottom());
}
if (mFitPaddingBottom != fitPaddingBottom) {
mFitPaddingBottom = fitPaddingBottom;
if (mFitPaddingBottom != bottom) {
mFitPaddingBottom = bottom;
mDrawerListView.setPadding(mDrawerListView.getPaddingLeft(),
mDrawerListView.getPaddingTop(),
mDrawerListView.getPaddingRight(),
mDrawerListViewOriginalPaddingBottom + fitPaddingBottom);
mDrawerListViewOriginalPaddingBottom + bottom);
}
insets.set(insets.left, 0, insets.right, 0);
return super.fitSystemWindows(insets);
}
public interface Helper {
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* 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
* 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 com.hippo.ehviewer.widget;
import android.content.Context;
import android.util.AttributeSet;
import com.hippo.scene.StageLayout;
import com.hippo.widget.FitPaddingImpl;
public class FitStageLayout extends StageLayout implements FitPaddingImpl {
private OnFitPaddingBottomListener mOnFitPaddingBottomListener;
public FitStageLayout(Context context) {
super(context);
}
public FitStageLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FitStageLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setOnFitPaddingBottomListener(OnFitPaddingBottomListener listener) {
mOnFitPaddingBottomListener = listener;
}
@Override
public void onFitPadding(int left, int top, int right, int bottom) {
setPadding(0, top, 0, 0);
if (mOnFitPaddingBottomListener != null) {
mOnFitPaddingBottomListener.onFitPaddingBottom(bottom);
}
}
public interface OnFitPaddingBottomListener {
void onFitPaddingBottom(int bottom);
}
}
@@ -1,163 +0,0 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* 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
* 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 com.hippo.ehviewer.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import com.hippo.ehviewer.R;
import com.hippo.util.Log;
public class StatusBarLayout extends ViewGroup {
private int mFitPaddingTop = -1;
private OnGetFitPaddingBottomListener mOnGetFitPaddingBottomListener;
private Paint mPaint;
private int mStatusBarColor = Color.BLACK;
public StatusBarLayout(Context context) {
super(context);
init(context, null);
}
public StatusBarLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public StatusBarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(Context context, AttributeSet attrs) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mPaint = new Paint();
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StatusBarLayout);
int color = a.getColor(R.styleable.StatusBarLayout_statusBarColor, Color.BLACK);
mPaint.setColor(color);
setWillNotDraw(Color.alpha(color) == 0);
a.recycle();
} else {
setWillNotDraw(false);
}
}
}
public void setStatusBarColor(int color) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (mStatusBarColor != color) {
mStatusBarColor = color;
mPaint.setColor(color);
setWillNotDraw(Color.alpha(color) == 0);
invalidate();
}
}
}
@Override
protected void onDraw(Canvas canvas) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (mFitPaddingTop > 0) {
canvas.drawRect(0, 0, getWidth(), mFitPaddingTop, mPaint);
}
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int count = getChildCount();
int maxHeight = 0;
int maxWidth = 0;
// Find out how big everyone wants to be
measureChildren(widthMeasureSpec, heightMeasureSpec);
// Find rightmost and bottom-most child
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
if (child.getVisibility() != GONE) {
int childRight;
int childBottom;
childRight = child.getMeasuredWidth();
childBottom = child.getMeasuredHeight();
maxWidth = Math.max(maxWidth, childRight);
maxHeight = Math.max(maxHeight, childBottom);
}
}
// Account for padding too
maxWidth += getPaddingLeft() + getPaddingRight();
maxHeight += getPaddingTop() + getPaddingBottom();
// Check against minimum height and width
maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, 0),
resolveSizeAndState(maxHeight, heightMeasureSpec, 0));
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int size = getChildCount();
for (int i = 0; i < size; i++) {
View child = getChildAt(i);
if (child.getVisibility() == View.GONE) {
continue;
}
child.layout(paddingLeft, paddingTop, paddingLeft + child.getMeasuredWidth(), paddingTop + child.getMeasuredHeight());
}
}
public void setOnGetFitPaddingBottomListener(OnGetFitPaddingBottomListener listener) {
mOnGetFitPaddingBottomListener = listener;
}
@SuppressWarnings("deprecation")
@Override
protected boolean fitSystemWindows(@NonNull Rect insets) {
mFitPaddingTop = insets.top;
if (mOnGetFitPaddingBottomListener != null) {
mOnGetFitPaddingBottomListener.onGetFitPaddingBottom(insets.bottom);
}
insets.set(insets.left, insets.top, insets.right, 0);
return super.fitSystemWindows(insets);
}
public interface OnGetFitPaddingBottomListener {
void onGetFitPaddingBottom(int b);
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2015 Hippo Seven
*
* 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
* 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 com.hippo.widget;
public interface FitPaddingImpl {
void onFitPadding(int left, int top, int right, int bottom);
}