mirror of
https://github.com/seven332/EhViewer
synced 2026-11-26 17:18:06 +08:00
Add StatusBarView
This commit is contained in:
1 parent
4756f938e9
commit
9facd4457f
24 files changed
+320
-174
No files matched your search
@@ -6,3 +6,4 @@
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
src
|
||||
+1
-1
@@ -101,7 +101,7 @@ dependencies {
|
||||
compile 'com.github.seven332.easyrecyclerview:easyrecyclerview-rxjava:1.2.1'
|
||||
compile 'com.github.seven332.easyrecyclerview:recyclerview-addons:1.2.1'
|
||||
compile 'com.github.seven332:refreshlayout:0.2.1'
|
||||
compile 'com.github.seven332:drawerlayout:0.2.1'
|
||||
compile 'com.github.seven332:drawerlayout:0.2.2'
|
||||
compile 'me.zhanghai.android.materialprogressbar:library:1.3.0'
|
||||
|
||||
// Utilities
|
||||
|
||||
@@ -23,6 +23,7 @@ package com.hippo.ehviewer.activity;
|
||||
import static com.bluelinelabs.conductor.RouterTransaction.with;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@@ -54,7 +55,6 @@ import com.hippo.ehviewer.controller.EhvController;
|
||||
import com.hippo.ehviewer.util.OpenSupplier;
|
||||
import com.hippo.ehviewer.util.Supplier;
|
||||
import com.hippo.ehviewer.view.EhvView;
|
||||
import com.hippo.ehviewer.widget.ControllerContainer;
|
||||
import com.hippo.ehviewer.widget.EhvLeftDrawer;
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,12 @@ public class EhvActivity extends ControllerActivity {
|
||||
setContentView(R.layout.activity_ehv);
|
||||
coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.draw_layout);
|
||||
|
||||
// Don't let DrawerLayout draw status bar background
|
||||
drawerLayout.setStatusBarColor(Color.TRANSPARENT);
|
||||
|
||||
EhvLeftDrawer leftDrawer = (EhvLeftDrawer) findViewById(R.id.left_drawer);
|
||||
// Navigation onItemClickListener
|
||||
navigationView = leftDrawer.getNavigationView();
|
||||
navigationView.setNavigationItemSelectedListener(item -> {
|
||||
int id = item.getItemId();
|
||||
@@ -150,6 +155,7 @@ public class EhvActivity extends ControllerActivity {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// Night mode button
|
||||
Button button = leftDrawer.getBottomButton();
|
||||
button.setText(EhvApp.isNightTheme(button.getContext())
|
||||
? R.string.let_there_be_light
|
||||
@@ -165,9 +171,7 @@ public class EhvActivity extends ControllerActivity {
|
||||
@NonNull
|
||||
@Override
|
||||
protected ViewGroup getControllerContainer() {
|
||||
ControllerContainer container = (ControllerContainer) findViewById(R.id.controller_container);
|
||||
container.setDrawLayout(drawerLayout);
|
||||
return container;
|
||||
return (ViewGroup) findViewById(R.id.drawer_content);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -285,28 +289,6 @@ public class EhvActivity extends ControllerActivity {
|
||||
return (EhvApp) getApplicationContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets DrawerLayout status bar color.
|
||||
* Returns {@code 0} if can't get it.
|
||||
*/
|
||||
public int getStatusBarColor() {
|
||||
if (drawerLayout != null) {
|
||||
return drawerLayout.getStatusBarColor();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets DrawerLayout status bar color.
|
||||
* Ignores it if can't sets it.
|
||||
*/
|
||||
public void setStatusBarColor(int color) {
|
||||
if (drawerLayout != null) {
|
||||
drawerLayout.setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes and locks left drawer.
|
||||
*/
|
||||
|
||||
@@ -48,7 +48,7 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.activity.EhvActivity;
|
||||
import com.hippo.ehviewer.drawable.ScaleDrawable;
|
||||
import com.hippo.ehviewer.view.EhvView;
|
||||
import com.hippo.ehviewer.widget.ControllerContainer;
|
||||
import com.hippo.ehviewer.widget.EhvDrawerContent;
|
||||
import com.hippo.ehviewer.widget.Overlay;
|
||||
import com.hippo.yorozuya.android.AnimationUtils;
|
||||
import com.transitionseverywhere.ArcMotion;
|
||||
@@ -98,12 +98,12 @@ public final class ChangeHandlerAnimators {
|
||||
public static Animator recolorStatusBar(
|
||||
@NonNull ViewGroup container, @Nullable View from, @Nullable View to) {
|
||||
if (!SUPPORT_COLOR_BAR
|
||||
|| !(container instanceof ControllerContainer)
|
||||
|| !(container instanceof EhvDrawerContent)
|
||||
|| from == null || to == null) {
|
||||
return null;
|
||||
}
|
||||
ControllerContainer controllerContainer = (ControllerContainer) container;
|
||||
DrawerLayout drawerLayout = controllerContainer.getDrawLayout();
|
||||
EhvDrawerContent drawerContent = (EhvDrawerContent) container;
|
||||
DrawerLayout drawerLayout = drawerContent.getDrawerLayout();
|
||||
if (drawerLayout == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,16 +20,13 @@ package com.hippo.ehviewer.changehandler;
|
||||
* Created by Hippo on 2/20/2017.
|
||||
*/
|
||||
|
||||
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler;
|
||||
import com.hippo.conductor.dialog.SimpleDialogChangeHandler;
|
||||
import com.hippo.ehviewer.controller.DialogController;
|
||||
|
||||
/**
|
||||
* {@code DialogChangeHandler} is for {@link DialogController}.
|
||||
* It keeps from view on push and show no animations or transitions.
|
||||
*/
|
||||
public class DialogChangeHandler extends SimpleSwapChangeHandler {
|
||||
public class DialogChangeHandler extends SimpleDialogChangeHandler {
|
||||
|
||||
public DialogChangeHandler() {
|
||||
super(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
* 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 com.hippo.ehviewer.changehandler.base;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 4/9/2017.
|
||||
*/
|
||||
|
||||
final class ChangeHandlerUtils {
|
||||
private ChangeHandlerUtils() {}
|
||||
|
||||
public interface StatusBarColor {
|
||||
int getStatusBarColor();
|
||||
}
|
||||
|
||||
public static class DialogStatusBarColor {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class AnalyticsView extends MessageSheetView<AnalyticsContract.Presenter>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getStatusBarColor() {
|
||||
public int getStatusBarColor() {
|
||||
return ContextCompat.getColor(getEhvActivity(), R.color.indigo_700);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public class FavouritesView extends GalleryInfoView<FavouritesContract.Presenter
|
||||
private EhvPreferences preferences;
|
||||
|
||||
@Override
|
||||
protected View createContentView(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = super.createContentView(inflater, parent);
|
||||
protected View onCreateToolbarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = super.onCreateToolbarContent(inflater, parent);
|
||||
|
||||
preferences = getEhvApp().getPreferences();
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ public class GalleryListView extends GalleryInfoView<GalleryListContract.Present
|
||||
private EhvPreferences preferences;
|
||||
|
||||
@Override
|
||||
protected View createContentView(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = super.createContentView(inflater, parent);
|
||||
protected View onCreateToolbarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = super.onCreateToolbarContent(inflater, parent);
|
||||
|
||||
preferences = getEhvApp().getPreferences();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class WarningView extends MessageSheetView<WarningContract.Presenter>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getStatusBarColor() {
|
||||
public int getStatusBarColor() {
|
||||
return ContextCompat.getColor(getEhvActivity(), R.color.red_700);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,19 +20,14 @@ package com.hippo.ehviewer.view;
|
||||
* Created by Hippo on 2/19/2017.
|
||||
*/
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import com.hippo.ehviewer.EhvApp;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.activity.EhvActivity;
|
||||
import com.hippo.ehviewer.controller.EhvController;
|
||||
import com.hippo.ehviewer.presenter.PresenterInterface;
|
||||
import com.hippo.yorozuya.android.ResourcesUtils;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import rx.Scheduler;
|
||||
import rx.Subscription;
|
||||
@@ -85,17 +80,17 @@ public abstract class EhvView<P extends PresenterInterface> extends ControllerVi
|
||||
|
||||
EhvActivity activity = getEhvActivity();
|
||||
|
||||
int statusBarColor = getStatusBarColor();
|
||||
activity.setStatusBarColor(statusBarColor);
|
||||
//int statusBarColor = getStatusBarColor();
|
||||
//activity.setStatusBarColor(statusBarColor);
|
||||
// Store controller status bar color in content view
|
||||
// Make RecolorStatusBarTransitionChangeHandler work
|
||||
getView().setTag(R.id.controller_status_bar_color, statusBarColor);
|
||||
// getView().setTag(R.id.controller_status_bar_color, statusBarColor);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
ActivityManager.TaskDescription taskDescription =
|
||||
new ActivityManager.TaskDescription(null, null, statusBarColor);
|
||||
activity.setTaskDescription(taskDescription);
|
||||
}
|
||||
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
// ActivityManager.TaskDescription taskDescription =
|
||||
// new ActivityManager.TaskDescription(null, null, statusBarColor);
|
||||
// activity.setTaskDescription(taskDescription);
|
||||
//}
|
||||
|
||||
if (whetherShowLeftDrawer()) {
|
||||
activity.unlockLeftDrawer();
|
||||
@@ -120,18 +115,6 @@ public abstract class EhvView<P extends PresenterInterface> extends ControllerVi
|
||||
//getApplication().getRefWatcher().watch(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status bar color.
|
||||
* <p>
|
||||
* Override it to change status bar color.
|
||||
* <p>
|
||||
* Default: colorPrimaryDark
|
||||
*/
|
||||
@ColorInt
|
||||
protected int getStatusBarColor() {
|
||||
return ResourcesUtils.getAttrColor(getEhvActivity(), R.attr.colorPrimaryDark);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether show left drawer.
|
||||
* <p>
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class GalleryInfoView<P extends GalleryInfoContract.Presenter>
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
protected View createContentView(LayoutInflater inflater, ViewGroup parent) {
|
||||
protected View onCreateToolbarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.controller_gallery_info_list, parent, false);
|
||||
layout = (ContentLayout) view;
|
||||
|
||||
|
||||
@@ -32,17 +32,17 @@ import com.hippo.ehviewer.widget.Mixbar;
|
||||
/**
|
||||
* {@code MixbarView} shows a Mixbar at top.
|
||||
*/
|
||||
public abstract class MixbarView<P extends PresenterInterface> extends EhvView<P> {
|
||||
public abstract class MixbarView<P extends PresenterInterface> extends StatusBarView<P> {
|
||||
|
||||
private Mixbar mixbar;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected final View onCreateView(LayoutInflater inflater, ViewGroup parent) {
|
||||
protected final View onCreateStatusBarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.controller_mixbar, parent, false);
|
||||
|
||||
mixbar = (Mixbar) view.findViewById(R.id.mixbar);
|
||||
ViewGroup container = (ViewGroup) view.findViewById(R.id.content_container);
|
||||
ViewGroup container = (ViewGroup) view.findViewById(R.id.mixbar_content_container);
|
||||
|
||||
View contentView = createContentView(inflater, container);
|
||||
container.addView(contentView);
|
||||
|
||||
@@ -38,7 +38,7 @@ import com.hippo.ehviewer.widget.IndicatingScrollView;
|
||||
/**
|
||||
* {@code SheetView} shows a header, a message and two buttons.
|
||||
*/
|
||||
public abstract class SheetView<P extends PresenterInterface> extends EhvView<P> {
|
||||
public abstract class SheetView<P extends PresenterInterface> extends StatusBarView<P> {
|
||||
|
||||
private View header;
|
||||
private CrossFadeTextView title;
|
||||
@@ -50,7 +50,7 @@ public abstract class SheetView<P extends PresenterInterface> extends EhvView<P>
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected final View onCreateView(LayoutInflater inflater, ViewGroup parent) {
|
||||
protected final View onCreateStatusBarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.controller_sheet, parent, false);
|
||||
|
||||
header = view.findViewById(R.id.header);
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
* 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 com.hippo.ehviewer.view;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 4/12/2017.
|
||||
*/
|
||||
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.presenter.PresenterInterface;
|
||||
import com.hippo.ehviewer.widget.EhvDrawerContent;
|
||||
import com.hippo.yorozuya.android.ResourcesUtils;
|
||||
|
||||
/**
|
||||
* A view with a status bar on the top.
|
||||
*/
|
||||
public abstract class StatusBarView<P extends PresenterInterface> extends EhvView<P>
|
||||
implements StatusBarViewImpl, EhvDrawerContent.OnGetWindowPaddingTopListener {
|
||||
|
||||
private View statusBar;
|
||||
private EhvDrawerContent drawerContent;
|
||||
|
||||
@CallSuper
|
||||
@NonNull
|
||||
@Override
|
||||
protected View onCreateView(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.controller_status_bar, parent, false);
|
||||
|
||||
statusBar = view.findViewById(R.id.status_bar);
|
||||
drawerContent = (EhvDrawerContent) parent;
|
||||
// Sets status bar height
|
||||
drawerContent.addOnGetWindowPaddingTopListener(this);
|
||||
// Sets status bar color
|
||||
statusBar.setBackgroundColor(getStatusBarColor());
|
||||
|
||||
// Sets content
|
||||
ViewGroup container = (ViewGroup) view.findViewById(R.id.status_bar_content_container);
|
||||
View content = onCreateStatusBarContent(inflater, container);
|
||||
container.addView(content);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGetWindowPaddingTop(int top) {
|
||||
ViewGroup.LayoutParams lp = statusBar.getLayoutParams();
|
||||
lp.height = top;
|
||||
statusBar.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetach() {
|
||||
super.onDetach();
|
||||
drawerContent.removeOnGetWindowPaddingTopListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the content for {@link StatusBarView}.
|
||||
*/
|
||||
@NonNull
|
||||
protected abstract View onCreateStatusBarContent(LayoutInflater inflater, ViewGroup parent);
|
||||
|
||||
@Override
|
||||
public void setStatusBarColor(int color) {
|
||||
if (statusBar != null) {
|
||||
statusBar.setBackgroundColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default status bar color for this view.
|
||||
*/
|
||||
@Override
|
||||
public int getStatusBarColor() {
|
||||
return ResourcesUtils.getAttrColor(getEhvActivity(), R.attr.colorPrimaryDark);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
* 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 com.hippo.ehviewer.view;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 4/9/2017.
|
||||
*/
|
||||
|
||||
public interface StatusBarViewImpl {
|
||||
|
||||
/**
|
||||
* Sets the status bar color.
|
||||
*/
|
||||
void setStatusBarColor(int color);
|
||||
|
||||
/**
|
||||
* Gets the status bar color.
|
||||
*/
|
||||
int getStatusBarColor();
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
/**
|
||||
* {@code ToolbarView} shows a Toolbar at top.
|
||||
*/
|
||||
public abstract class ToolbarView<P extends PresenterInterface> extends EhvView<P> {
|
||||
public abstract class ToolbarView<P extends PresenterInterface> extends StatusBarView<P> {
|
||||
|
||||
private static final String LOG_TAG = ToolbarView.class.getSimpleName();
|
||||
|
||||
@@ -54,11 +54,10 @@ public abstract class ToolbarView<P extends PresenterInterface> extends EhvView<
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected View onCreateView(LayoutInflater inflater, ViewGroup parent) {
|
||||
protected View onCreateStatusBarContent(LayoutInflater inflater, ViewGroup parent) {
|
||||
View view = inflater.inflate(R.layout.controller_toolbar, parent, false);
|
||||
|
||||
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
ViewGroup container = (ViewGroup) view.findViewById(R.id.content_container);
|
||||
|
||||
DrawerArrowDrawable drawable = new DrawerArrowDrawable(getEhvActivity());
|
||||
drawable.setDirection(DrawerArrowDrawable.ARROW_DIRECTION_LEFT);
|
||||
@@ -74,8 +73,9 @@ public abstract class ToolbarView<P extends PresenterInterface> extends EhvView<
|
||||
break;
|
||||
}
|
||||
|
||||
View contentView = createContentView(inflater, container);
|
||||
container.addView(contentView);
|
||||
ViewGroup container = (ViewGroup) view.findViewById(R.id.toolbar_content_container);
|
||||
View content = onCreateToolbarContent(inflater, container);
|
||||
container.addView(content);
|
||||
|
||||
if (view instanceof ToolbarLayout) {
|
||||
((ToolbarLayout) view).setDrawerArrowDrawable(drawable);
|
||||
@@ -89,7 +89,7 @@ public abstract class ToolbarView<P extends PresenterInterface> extends EhvView<
|
||||
/**
|
||||
* Creates content view for this {@code ToolbarView}.
|
||||
*/
|
||||
protected abstract View createContentView(LayoutInflater inflater, ViewGroup parent);
|
||||
protected abstract View onCreateToolbarContent(LayoutInflater inflater, ViewGroup parent);
|
||||
|
||||
/**
|
||||
* {@link #NAVIGATION_TYPE_RETURN}: arrow, back.
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 2017 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
|
||||
* 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 com.hippo.ehviewer.widget;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2/6/2017.
|
||||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import com.bluelinelabs.conductor.ChangeHandlerFrameLayout;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
|
||||
/**
|
||||
* {@code ControllerContainer} is a container for controllers.
|
||||
*/
|
||||
public class ControllerContainer extends ChangeHandlerFrameLayout {
|
||||
|
||||
@Nullable
|
||||
private DrawerLayout drawerLayout;
|
||||
|
||||
public ControllerContainer(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ControllerContainer(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ControllerContainer(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets DrawerLayout of the Activity.
|
||||
*/
|
||||
@Nullable
|
||||
public DrawerLayout getDrawLayout() {
|
||||
return drawerLayout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets DrawerLayout of the Activity.
|
||||
*/
|
||||
public void setDrawLayout(DrawerLayout drawLayout) {
|
||||
this.drawerLayout = drawLayout;
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,21 @@ package com.hippo.ehviewer.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
import android.view.ViewParent;
|
||||
import com.bluelinelabs.conductor.ChangeHandlerFrameLayout;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.drawerlayout.DrawerLayoutChild;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Content for {@link com.hippo.drawerlayout.DrawerLayout}.
|
||||
*/
|
||||
public class EhvDrawerContent extends FrameLayout implements DrawerLayoutChild {
|
||||
public class EhvDrawerContent extends ChangeHandlerFrameLayout implements DrawerLayoutChild {
|
||||
|
||||
private int layoutPaddingTop;
|
||||
private int layoutPaddingBottom;
|
||||
private List<OnGetWindowPaddingTopListener> listeners = new ArrayList<>();
|
||||
private int windowPaddingTop;
|
||||
private int windowPaddingBottom;
|
||||
|
||||
public EhvDrawerContent(Context context) {
|
||||
super(context);
|
||||
@@ -45,19 +50,64 @@ public class EhvDrawerContent extends FrameLayout implements DrawerLayoutChild {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
layoutPaddingTop = top;
|
||||
layoutPaddingBottom = bottom;
|
||||
/**
|
||||
* Gets it's parent, {@link DrawerLayout}.
|
||||
*/
|
||||
public DrawerLayout getDrawerLayout() {
|
||||
ViewParent parent = getParent();
|
||||
if (parent instanceof DrawerLayout) {
|
||||
return (DrawerLayout) parent;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
return layoutPaddingTop;
|
||||
public void onGetWindowPadding(int top, int bottom) {
|
||||
windowPaddingTop = top;
|
||||
windowPaddingBottom = bottom;
|
||||
|
||||
// Callback
|
||||
List<OnGetWindowPaddingTopListener> copy = new ArrayList<>(listeners);
|
||||
for (OnGetWindowPaddingTopListener l : copy) {
|
||||
l.onGetWindowPaddingTop(top);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return layoutPaddingBottom;
|
||||
public int getAdditionalTopMargin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAdditionalBottomMargin() {
|
||||
return windowPaddingBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link OnGetWindowPaddingTopListener}.
|
||||
* The {@link OnGetWindowPaddingTopListener#onGetWindowPaddingTop(int)} will be called at once.
|
||||
*/
|
||||
public void addOnGetWindowPaddingTopListener(OnGetWindowPaddingTopListener listener) {
|
||||
if (listener != null) {
|
||||
listener.onGetWindowPaddingTop(windowPaddingTop);
|
||||
listeners.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a {@link OnGetWindowPaddingTopListener}.
|
||||
*/
|
||||
public void removeOnGetWindowPaddingTopListener(OnGetWindowPaddingTopListener listener) {
|
||||
if (listener != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback to get window padding top.
|
||||
*/
|
||||
public interface OnGetWindowPaddingTopListener {
|
||||
void onGetWindowPaddingTop(int top);
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,8 @@ public class EhvLeftDrawer extends LinearLayout implements DrawerLayoutChild {
|
||||
private static final int SCRIM_COLOR = 0x44000000;
|
||||
private static final boolean DRAW_SCRIM = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
|
||||
private int layoutPaddingTop;
|
||||
private int layoutPaddingBottom;
|
||||
private int windowPaddingTop;
|
||||
private int windowPaddingBottom;
|
||||
private Paint paint;
|
||||
|
||||
private NavigationView navigationView;
|
||||
@@ -92,29 +92,29 @@ public class EhvLeftDrawer extends LinearLayout implements DrawerLayoutChild {
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
if (DRAW_SCRIM && layoutPaddingTop > 0) {
|
||||
if (DRAW_SCRIM && windowPaddingTop > 0) {
|
||||
if (paint == null) {
|
||||
paint = new Paint();
|
||||
paint.setColor(SCRIM_COLOR);
|
||||
}
|
||||
canvas.drawRect(0, 0, getWidth(), layoutPaddingTop, paint);
|
||||
canvas.drawRect(0, 0, getWidth(), windowPaddingTop, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFitPadding(int top, int bottom) {
|
||||
layoutPaddingTop = top;
|
||||
layoutPaddingBottom = bottom;
|
||||
public void onGetWindowPadding(int top, int bottom) {
|
||||
windowPaddingTop = top;
|
||||
windowPaddingBottom = bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingTop() {
|
||||
public int getAdditionalTopMargin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutPaddingBottom() {
|
||||
return layoutPaddingBottom;
|
||||
public int getAdditionalBottomMargin() {
|
||||
return windowPaddingBottom;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,14 +30,7 @@
|
||||
<com.hippo.ehviewer.widget.EhvDrawerContent
|
||||
android:id="@+id/drawer_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.hippo.ehviewer.widget.ControllerContainer
|
||||
android:id="@+id/controller_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</com.hippo.ehviewer.widget.EhvDrawerContent>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<com.hippo.ehviewer.widget.EhvLeftDrawer
|
||||
android:id="@+id/left_drawer"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</com.hippo.ehviewer.widget.Mixbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_container"
|
||||
android:id="@+id/mixbar_content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2017 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
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- Sets height programmatically -->
|
||||
<View
|
||||
android:id="@+id/status_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/status_bar_content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -28,7 +28,7 @@
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_container"
|
||||
android:id="@+id/toolbar_content_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
Reference in new issue
Block a user