diff --git a/Clover/app/src/main/java/org/floens/chan/ui/controller/SplitNavigationController.java b/Clover/app/src/main/java/org/floens/chan/ui/controller/SplitNavigationController.java index 934edece..4ee4dcf1 100644 --- a/Clover/app/src/main/java/org/floens/chan/ui/controller/SplitNavigationController.java +++ b/Clover/app/src/main/java/org/floens/chan/ui/controller/SplitNavigationController.java @@ -18,24 +18,21 @@ package org.floens.chan.ui.controller; import android.content.Context; -import android.content.res.Configuration; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; -import android.widget.LinearLayout; import org.floens.chan.R; import org.floens.chan.controller.Controller; import org.floens.chan.controller.ControllerTransition; import org.floens.chan.controller.transition.PopControllerTransition; import org.floens.chan.controller.transition.PushControllerTransition; -import org.floens.chan.utils.AndroidUtils; +import org.floens.chan.ui.layout.SplitNavigationControllerLayout; -import static org.floens.chan.utils.AndroidUtils.dp; import static org.floens.chan.utils.AndroidUtils.getAttrColor; -public class SplitNavigationController extends Controller implements AndroidUtils.OnMeasuredCallback { +public class SplitNavigationController extends Controller { public Controller leftController; public Controller rightController; @@ -57,22 +54,22 @@ public class SplitNavigationController extends Controller implements AndroidUtil splitNavigationController = this; - LinearLayout wrap = new LinearLayout(context); - view = wrap; + SplitNavigationControllerLayout container = new SplitNavigationControllerLayout(context); + view = container; leftControllerView = new FrameLayout(context); - wrap.addView(leftControllerView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT)); dividerView = new View(context); dividerView.setBackgroundColor(getAttrColor(context, R.attr.divider_split_color)); - wrap.addView(dividerView, new LinearLayout.LayoutParams(dp(1), LinearLayout.LayoutParams.MATCH_PARENT)); rightControllerView = new FrameLayout(context); - wrap.addView(rightControllerView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); - setRightController(null); + container.setLeftView(leftControllerView); + container.setRightView(rightControllerView); + container.setDivider(dividerView); + container.build(); - AndroidUtils.waitForMeasure(view, this); + setRightController(null); } public void setEmptyView(ViewGroup emptyView) { @@ -182,23 +179,4 @@ public class SplitNavigationController extends Controller implements AndroidUtil (leftController != null && leftController.dispatchKeyEvent(event)) || super.dispatchKeyEvent(event); } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - AndroidUtils.waitForMeasure(view, this); - } - - @Override - public boolean onMeasured(View view) { - int width = Math.max(dp(300), (int) (view.getWidth() * 0.35)); - if (leftControllerView.getWidth() != width) { - leftControllerView.getLayoutParams().width = width; - leftControllerView.requestLayout(); - return true; - } else { - return false; - } - } } diff --git a/Clover/app/src/main/java/org/floens/chan/ui/layout/SplitNavigationControllerLayout.java b/Clover/app/src/main/java/org/floens/chan/ui/layout/SplitNavigationControllerLayout.java new file mode 100644 index 00000000..f5f0bd1c --- /dev/null +++ b/Clover/app/src/main/java/org/floens/chan/ui/layout/SplitNavigationControllerLayout.java @@ -0,0 +1,94 @@ +/* + * Clover - 4chan browser https://github.com/Floens/Clover/ + * Copyright (C) 2014 Floens + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.floens.chan.ui.layout; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import static org.floens.chan.utils.AndroidUtils.dp; + +public class SplitNavigationControllerLayout extends LinearLayout { + private final int dividerWidth; + private final int minimumLeftWidth; + private final double ratio; + + private ViewGroup leftView; + private ViewGroup rightView; + private View divider; + + public SplitNavigationControllerLayout(Context context) { + this(context, null); + } + + public SplitNavigationControllerLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public SplitNavigationControllerLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + setOrientation(LinearLayout.HORIZONTAL); + + dividerWidth = dp(1); + minimumLeftWidth = dp(300); + ratio = 0.35; + } + + public void setLeftView(ViewGroup leftView) { + this.leftView = leftView; + } + + public void setRightView(ViewGroup rightView) { + this.rightView = rightView; + } + + public void setDivider(View divider) { + this.divider = divider; + } + + public void build() { + addView(leftView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT)); + addView(divider, new LinearLayout.LayoutParams(dividerWidth, LinearLayout.LayoutParams.MATCH_PARENT)); + addView(rightView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT)); + } + + @Override + protected void measureChildren(int widthMeasureSpec, int heightMeasureSpec) { + super.measureChildren(widthMeasureSpec, heightMeasureSpec); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int widthSize = MeasureSpec.getSize(widthMeasureSpec); + + if (widthMode == MeasureSpec.UNSPECIFIED) { + throw new IllegalArgumentException(); + } + + int leftWidth = Math.max(minimumLeftWidth, (int) (widthSize * ratio)); + int rightWidth = widthSize - dividerWidth - leftWidth; + leftView.getLayoutParams().width = leftWidth; + rightView.getLayoutParams().width = rightWidth; + + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } +}