Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/BottomSheetContentController.java

Issue 2751583002: 🏡 Show correct BottomSheetContent toolbar when contents swapped (Closed)
Patch Set: [Home] Show correct BottomSheetContent toolbar when contents swapped Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.widget; 5 package org.chromium.chrome.browser.widget;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.Resources; 8 import android.content.res.Resources;
9 import android.support.design.internal.BottomNavigationItemView; 9 import android.support.design.internal.BottomNavigationItemView;
10 import android.support.design.internal.BottomNavigationMenuView; 10 import android.support.design.internal.BottomNavigationMenuView;
(...skipping 21 matching lines...) Expand all
32 /** 32 /**
33 * Displays and controls a {@link BottomNavigationView} fixed to the bottom of t he 33 * Displays and controls a {@link BottomNavigationView} fixed to the bottom of t he
34 * {@link BottomSheet}. Also manages {@link BottomSheetContent} displayed in the BottomSheet. 34 * {@link BottomSheet}. Also manages {@link BottomSheetContent} displayed in the BottomSheet.
35 */ 35 */
36 public class BottomSheetContentController extends BottomNavigationView 36 public class BottomSheetContentController extends BottomNavigationView
37 implements BottomSheetObserver, OnNavigationItemSelectedListener { 37 implements BottomSheetObserver, OnNavigationItemSelectedListener {
38 private BottomSheet mBottomSheet; 38 private BottomSheet mBottomSheet;
39 private TabModelSelector mTabModelSelector; 39 private TabModelSelector mTabModelSelector;
40 private float mDistanceBelowToolbarPx; 40 private float mDistanceBelowToolbarPx;
41 private int mSelectedItemId; 41 private int mSelectedItemId;
42 private boolean mDefaultContentInitialized;
42 43
43 private final Map<Integer, BottomSheetContent> mBottomSheetContents = new Ha shMap<>(); 44 private final Map<Integer, BottomSheetContent> mBottomSheetContents = new Ha shMap<>();
44 45
45 public BottomSheetContentController(Context context, AttributeSet atts) { 46 public BottomSheetContentController(Context context, AttributeSet atts) {
46 super(context, atts); 47 super(context, atts);
47 } 48 }
48 49
49 /** 50 /**
50 * Initializes the {@link BottomSheetContentController}. 51 * Initializes the {@link BottomSheetContentController}.
51 * @param bottomSheet The {@link BottomSheet} associated with this bottom na v. 52 * @param bottomSheet The {@link BottomSheet} associated with this bottom na v.
(...skipping 11 matching lines...) Expand all
63 + res.getDimensionPixelOffset(R.dimen.bottom_nav_space_from_tool bar); 64 + res.getDimensionPixelOffset(R.dimen.bottom_nav_space_from_tool bar);
64 65
65 setOnNavigationItemSelectedListener(this); 66 setOnNavigationItemSelectedListener(this);
66 disableShiftingMode(); 67 disableShiftingMode();
67 } 68 }
68 69
69 /** 70 /**
70 * Initialize the default {@link BottomSheetContent}. 71 * Initialize the default {@link BottomSheetContent}.
71 */ 72 */
72 public void initializeDefaultContent() { 73 public void initializeDefaultContent() {
73 mBottomSheet.showContent(getSheetContentForId(R.id.action_home)); 74 if (mDefaultContentInitialized) return;
74 mSelectedItemId = R.id.action_home; 75 showBottomSheetContent(R.id.action_home);
76 mDefaultContentInitialized = true;
75 } 77 }
76 78
77 @Override 79 @Override
78 public boolean onNavigationItemSelected(MenuItem item) { 80 public boolean onNavigationItemSelected(MenuItem item) {
79 if (mSelectedItemId == item.getItemId()) return false; 81 if (mSelectedItemId == item.getItemId()) return false;
80 82
81 showBottomSheetContent(item.getItemId()); 83 showBottomSheetContent(item.getItemId());
82 return true; 84 return true;
83 } 85 }
84 86
85 @Override 87 @Override
86 public void onTransitionPeekToHalf(float transitionFraction) { 88 public void onTransitionPeekToHalf(float transitionFraction) {
87 float offsetY = (mBottomSheet.getMinOffset() - mBottomSheet.getSheetOffs etFromBottom()) 89 float offsetY = (mBottomSheet.getMinOffset() - mBottomSheet.getSheetOffs etFromBottom())
88 + mDistanceBelowToolbarPx; 90 + mDistanceBelowToolbarPx;
89 setTranslationY((int) Math.max(offsetY, 0f)); 91 setTranslationY((int) Math.max(offsetY, 0f));
90 setVisibility(MathUtils.areFloatsEqual(transitionFraction, 0f) ? View.GO NE : View.VISIBLE); 92 setVisibility(MathUtils.areFloatsEqual(transitionFraction, 0f) ? View.GO NE : View.VISIBLE);
91 } 93 }
92 94
93 @Override 95 @Override
94 public void onSheetOpened() {} 96 public void onSheetOpened() {
Theresa 2017/03/14 17:12:33 A note for myself -- mTabModelSelector.getCurrentT
Theresa 2017/03/14 20:40:02 Done.
97 if (!mDefaultContentInitialized) initializeDefaultContent();
98 }
95 99
96 @Override 100 @Override
97 public void onSheetClosed() { 101 public void onSheetClosed() {
98 Iterator<Entry<Integer, BottomSheetContent>> contentIterator = 102 Iterator<Entry<Integer, BottomSheetContent>> contentIterator =
99 mBottomSheetContents.entrySet().iterator(); 103 mBottomSheetContents.entrySet().iterator();
100 while (contentIterator.hasNext()) { 104 while (contentIterator.hasNext()) {
101 Entry<Integer, BottomSheetContent> entry = contentIterator.next(); 105 Entry<Integer, BottomSheetContent> entry = contentIterator.next();
102 if (entry.getKey() == R.id.action_home) continue; 106 if (entry.getKey() == R.id.action_home) continue;
103 107
104 entry.getValue().destroy(); 108 entry.getValue().destroy();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // There are some bugs related to programatically selecting menu items t hat are fixed in 166 // There are some bugs related to programatically selecting menu items t hat are fixed in
163 // newer support library versions. 167 // newer support library versions.
164 // TODO(twellington): remove this after the support library is rolled. 168 // TODO(twellington): remove this after the support library is rolled.
165 if (mSelectedItemId != 0) getMenu().findItem(mSelectedItemId).setChecked (false); 169 if (mSelectedItemId != 0) getMenu().findItem(mSelectedItemId).setChecked (false);
166 mSelectedItemId = navItemId; 170 mSelectedItemId = navItemId;
167 getMenu().findItem(mSelectedItemId).setChecked(true); 171 getMenu().findItem(mSelectedItemId).setChecked(true);
168 172
169 mBottomSheet.showContent(getSheetContentForId(mSelectedItemId)); 173 mBottomSheet.showContent(getSheetContentForId(mSelectedItemId));
170 } 174 }
171 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698