From 9facd4457f9b328674af0eaae8a8cd019dfcbc72 Mon Sep 17 00:00:00 2001 From: seven332 Date: Wed, 12 Apr 2017 23:29:56 +0800 Subject: [PATCH] Add StatusBarView --- .gitignore | 1 + app/build.gradle | 2 +- .../hippo/ehviewer/activity/EhvActivity.java | 34 ++----- .../changehandler/ChangeHandlerAnimators.java | 8 +- .../changehandler/DialogChangeHandler.java | 7 +- .../base/ChangeHandlerUtils.java | 37 +++++++ .../scene/analytics/AnalyticsView.java | 2 +- .../scene/favourites/FavouritesView.java | 4 +- .../scene/gallerylist/GalleryListView.java | 4 +- .../ehviewer/scene/warning/WarningView.java | 2 +- .../java/com/hippo/ehviewer/view/EhvView.java | 33 ++----- .../hippo/ehviewer/view/GalleryInfoView.java | 2 +- .../com/hippo/ehviewer/view/MixbarView.java | 6 +- .../com/hippo/ehviewer/view/SheetView.java | 4 +- .../hippo/ehviewer/view/StatusBarView.java | 96 +++++++++++++++++++ .../ehviewer/view/StatusBarViewImpl.java | 34 +++++++ .../com/hippo/ehviewer/view/ToolbarView.java | 12 +-- .../ehviewer/widget/ControllerContainer.java | 63 ------------ .../ehviewer/widget/EhvDrawerContent.java | 74 +++++++++++--- .../hippo/ehviewer/widget/EhvLeftDrawer.java | 20 ++-- app/src/main/res/layout/activity_ehv.xml | 9 +- app/src/main/res/layout/controller_mixbar.xml | 2 +- .../main/res/layout/controller_status_bar.xml | 36 +++++++ .../main/res/layout/controller_toolbar.xml | 2 +- 24 files changed, 320 insertions(+), 174 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/changehandler/base/ChangeHandlerUtils.java create mode 100644 app/src/main/java/com/hippo/ehviewer/view/StatusBarView.java create mode 100644 app/src/main/java/com/hippo/ehviewer/view/StatusBarViewImpl.java delete mode 100644 app/src/main/java/com/hippo/ehviewer/widget/ControllerContainer.java create mode 100644 app/src/main/res/layout/controller_status_bar.xml diff --git a/.gitignore b/.gitignore index 09b993d0..053e1609 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ /build /captures .externalNativeBuild +src diff --git a/app/build.gradle b/app/build.gradle index cb3bbf00..9d1c5391 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/main/java/com/hippo/ehviewer/activity/EhvActivity.java b/app/src/main/java/com/hippo/ehviewer/activity/EhvActivity.java index 5cfd68fc..25502673 100644 --- a/app/src/main/java/com/hippo/ehviewer/activity/EhvActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/activity/EhvActivity.java @@ -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. */ diff --git a/app/src/main/java/com/hippo/ehviewer/changehandler/ChangeHandlerAnimators.java b/app/src/main/java/com/hippo/ehviewer/changehandler/ChangeHandlerAnimators.java index 145fead5..55e3447d 100644 --- a/app/src/main/java/com/hippo/ehviewer/changehandler/ChangeHandlerAnimators.java +++ b/app/src/main/java/com/hippo/ehviewer/changehandler/ChangeHandlerAnimators.java @@ -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; } diff --git a/app/src/main/java/com/hippo/ehviewer/changehandler/DialogChangeHandler.java b/app/src/main/java/com/hippo/ehviewer/changehandler/DialogChangeHandler.java index 0ca89289..c478781c 100644 --- a/app/src/main/java/com/hippo/ehviewer/changehandler/DialogChangeHandler.java +++ b/app/src/main/java/com/hippo/ehviewer/changehandler/DialogChangeHandler.java @@ -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); - } } diff --git a/app/src/main/java/com/hippo/ehviewer/changehandler/base/ChangeHandlerUtils.java b/app/src/main/java/com/hippo/ehviewer/changehandler/base/ChangeHandlerUtils.java new file mode 100644 index 00000000..8349a5ec --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/changehandler/base/ChangeHandlerUtils.java @@ -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 { + + } + + + + +} diff --git a/app/src/main/java/com/hippo/ehviewer/scene/analytics/AnalyticsView.java b/app/src/main/java/com/hippo/ehviewer/scene/analytics/AnalyticsView.java index 24e91bf5..a3cfc72b 100644 --- a/app/src/main/java/com/hippo/ehviewer/scene/analytics/AnalyticsView.java +++ b/app/src/main/java/com/hippo/ehviewer/scene/analytics/AnalyticsView.java @@ -55,7 +55,7 @@ public class AnalyticsView extends MessageSheetView } @Override - protected int getStatusBarColor() { + public int getStatusBarColor() { return ContextCompat.getColor(getEhvActivity(), R.color.indigo_700); } diff --git a/app/src/main/java/com/hippo/ehviewer/scene/favourites/FavouritesView.java b/app/src/main/java/com/hippo/ehviewer/scene/favourites/FavouritesView.java index fe9f5aee..1fab9204 100644 --- a/app/src/main/java/com/hippo/ehviewer/scene/favourites/FavouritesView.java +++ b/app/src/main/java/com/hippo/ehviewer/scene/favourites/FavouritesView.java @@ -34,8 +34,8 @@ public class FavouritesView extends GalleryInfoView } @Override - protected int getStatusBarColor() { + public int getStatusBarColor() { return ContextCompat.getColor(getEhvActivity(), R.color.red_700); } diff --git a/app/src/main/java/com/hippo/ehviewer/view/EhvView.java b/app/src/main/java/com/hippo/ehviewer/view/EhvView.java index 53be70fc..797a6ecd 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/EhvView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/EhvView.java @@ -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

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

extends ControllerVi //getApplication().getRefWatcher().watch(this); } - /** - * Gets status bar color. - *

- * Override it to change status bar color. - *

- * Default: colorPrimaryDark - */ - @ColorInt - protected int getStatusBarColor() { - return ResourcesUtils.getAttrColor(getEhvActivity(), R.attr.colorPrimaryDark); - } - /** * Whether show left drawer. *

diff --git a/app/src/main/java/com/hippo/ehviewer/view/GalleryInfoView.java b/app/src/main/java/com/hippo/ehviewer/view/GalleryInfoView.java index cef655ad..f2320847 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/GalleryInfoView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/GalleryInfoView.java @@ -47,7 +47,7 @@ public abstract class GalleryInfoView

@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; diff --git a/app/src/main/java/com/hippo/ehviewer/view/MixbarView.java b/app/src/main/java/com/hippo/ehviewer/view/MixbarView.java index ac5f8511..dbe017a1 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/MixbarView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/MixbarView.java @@ -32,17 +32,17 @@ import com.hippo.ehviewer.widget.Mixbar; /** * {@code MixbarView} shows a Mixbar at top. */ -public abstract class MixbarView

extends EhvView

{ +public abstract class MixbarView

extends StatusBarView

{ 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); diff --git a/app/src/main/java/com/hippo/ehviewer/view/SheetView.java b/app/src/main/java/com/hippo/ehviewer/view/SheetView.java index e0c585ad..ecd0fd8b 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/SheetView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/SheetView.java @@ -38,7 +38,7 @@ import com.hippo.ehviewer.widget.IndicatingScrollView; /** * {@code SheetView} shows a header, a message and two buttons. */ -public abstract class SheetView

extends EhvView

{ +public abstract class SheetView

extends StatusBarView

{ private View header; private CrossFadeTextView title; @@ -50,7 +50,7 @@ public abstract class SheetView

extends EhvView

@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); diff --git a/app/src/main/java/com/hippo/ehviewer/view/StatusBarView.java b/app/src/main/java/com/hippo/ehviewer/view/StatusBarView.java new file mode 100644 index 00000000..0ac338de --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/view/StatusBarView.java @@ -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

extends EhvView

+ 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); + } +} diff --git a/app/src/main/java/com/hippo/ehviewer/view/StatusBarViewImpl.java b/app/src/main/java/com/hippo/ehviewer/view/StatusBarViewImpl.java new file mode 100644 index 00000000..1c078a05 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/view/StatusBarViewImpl.java @@ -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(); +} diff --git a/app/src/main/java/com/hippo/ehviewer/view/ToolbarView.java b/app/src/main/java/com/hippo/ehviewer/view/ToolbarView.java index 67c1f4ac..25054f72 100644 --- a/app/src/main/java/com/hippo/ehviewer/view/ToolbarView.java +++ b/app/src/main/java/com/hippo/ehviewer/view/ToolbarView.java @@ -39,7 +39,7 @@ import java.lang.annotation.RetentionPolicy; /** * {@code ToolbarView} shows a Toolbar at top. */ -public abstract class ToolbarView

extends EhvView

{ +public abstract class ToolbarView

extends StatusBarView

{ private static final String LOG_TAG = ToolbarView.class.getSimpleName(); @@ -54,11 +54,10 @@ public abstract class ToolbarView

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

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

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. diff --git a/app/src/main/java/com/hippo/ehviewer/widget/ControllerContainer.java b/app/src/main/java/com/hippo/ehviewer/widget/ControllerContainer.java deleted file mode 100644 index 172f1d31..00000000 --- a/app/src/main/java/com/hippo/ehviewer/widget/ControllerContainer.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/widget/EhvDrawerContent.java b/app/src/main/java/com/hippo/ehviewer/widget/EhvDrawerContent.java index 70ea2eb8..442881ec 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/EhvDrawerContent.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/EhvDrawerContent.java @@ -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 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 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); } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/EhvLeftDrawer.java b/app/src/main/java/com/hippo/ehviewer/widget/EhvLeftDrawer.java index f84934fc..9d35b3bc 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/EhvLeftDrawer.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/EhvLeftDrawer.java @@ -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; } /** diff --git a/app/src/main/res/layout/activity_ehv.xml b/app/src/main/res/layout/activity_ehv.xml index 840f523e..23761097 100644 --- a/app/src/main/res/layout/activity_ehv.xml +++ b/app/src/main/res/layout/activity_ehv.xml @@ -30,14 +30,7 @@ - - - - + android:layout_height="match_parent"/> diff --git a/app/src/main/res/layout/controller_status_bar.xml b/app/src/main/res/layout/controller_status_bar.xml new file mode 100644 index 00000000..900ebc0f --- /dev/null +++ b/app/src/main/res/layout/controller_status_bar.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/controller_toolbar.xml b/app/src/main/res/layout/controller_toolbar.xml index 34f4cd29..293a3a77 100644 --- a/app/src/main/res/layout/controller_toolbar.xml +++ b/app/src/main/res/layout/controller_toolbar.xml @@ -28,7 +28,7 @@ android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>