OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.snackbar; | 5 package org.chromium.chrome.browser.snackbar; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
10 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
11 import android.app.Activity; | 11 import android.app.Activity; |
12 import android.graphics.Rect; | 12 import android.graphics.Rect; |
13 import android.graphics.drawable.Drawable; | 13 import android.graphics.drawable.Drawable; |
14 import android.graphics.drawable.GradientDrawable; | 14 import android.graphics.drawable.GradientDrawable; |
15 import android.os.Build; | |
15 import android.support.annotation.Nullable; | 16 import android.support.annotation.Nullable; |
16 import android.view.Gravity; | 17 import android.view.Gravity; |
17 import android.view.LayoutInflater; | 18 import android.view.LayoutInflater; |
19 import android.view.PointerIcon; | |
18 import android.view.SurfaceView; | 20 import android.view.SurfaceView; |
19 import android.view.View; | 21 import android.view.View; |
20 import android.view.View.OnClickListener; | 22 import android.view.View.OnClickListener; |
21 import android.view.View.OnLayoutChangeListener; | 23 import android.view.View.OnLayoutChangeListener; |
22 import android.view.ViewGroup; | 24 import android.view.ViewGroup; |
23 import android.view.animation.DecelerateInterpolator; | 25 import android.view.animation.DecelerateInterpolator; |
24 import android.widget.FrameLayout; | 26 import android.widget.FrameLayout; |
25 import android.widget.ImageView; | 27 import android.widget.ImageView; |
26 import android.widget.TextView; | 28 import android.widget.TextView; |
27 | 29 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 mParent = mOriginalParent; | 88 mParent = mOriginalParent; |
87 mView = (ViewGroup) LayoutInflater.from(activity).inflate( | 89 mView = (ViewGroup) LayoutInflater.from(activity).inflate( |
88 R.layout.snackbar, mParent, false); | 90 R.layout.snackbar, mParent, false); |
89 mAnimationDuration = mView.getResources() | 91 mAnimationDuration = mView.getResources() |
90 .getInteger(android.R.integer.config_mediumAnimTime); | 92 .getInteger(android.R.integer.config_mediumAnimTime); |
91 mMessageView = (TemplatePreservingTextView) mView.findViewById(R.id.snac kbar_message); | 93 mMessageView = (TemplatePreservingTextView) mView.findViewById(R.id.snac kbar_message); |
92 mActionButtonView = (TextView) mView.findViewById(R.id.snackbar_button); | 94 mActionButtonView = (TextView) mView.findViewById(R.id.snackbar_button); |
93 mActionButtonView.setOnClickListener(listener); | 95 mActionButtonView.setOnClickListener(listener); |
94 mProfileImageView = (ImageView) mView.findViewById(R.id.snackbar_profile _image); | 96 mProfileImageView = (ImageView) mView.findViewById(R.id.snackbar_profile _image); |
95 | 97 |
98 setPointerIcons(); | |
99 | |
96 updateInternal(snackbar, false); | 100 updateInternal(snackbar, false); |
97 } | 101 } |
98 | 102 |
99 void show() { | 103 void show() { |
100 addToParent(); | 104 addToParent(); |
101 mView.addOnLayoutChangeListener(new OnLayoutChangeListener() { | 105 mView.addOnLayoutChangeListener(new OnLayoutChangeListener() { |
102 @Override | 106 @Override |
103 public void onLayoutChange(View v, int left, int top, int right, int bottom, | 107 public void onLayoutChange(View v, int left, int top, int right, int bottom, |
104 int oldLeft, int oldTop, int oldRight, int oldBottom) { | 108 int oldLeft, int oldTop, int oldRight, int oldBottom) { |
105 mView.removeOnLayoutChangeListener(this); | 109 mView.removeOnLayoutChangeListener(this); |
(...skipping 29 matching lines...) Expand all Loading... | |
135 } | 139 } |
136 | 140 |
137 /** | 141 /** |
138 * Adjusts the position of the snackbar on top of the soft keyboard, if any. | 142 * Adjusts the position of the snackbar on top of the soft keyboard, if any. |
139 */ | 143 */ |
140 void adjustViewPosition() { | 144 void adjustViewPosition() { |
141 mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); | 145 mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); |
142 // Only update if the visible frame has changed, otherwise there will be a layout loop. | 146 // Only update if the visible frame has changed, otherwise there will be a layout loop. |
143 if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { | 147 if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { |
144 mPreviousVisibleRect.set(mCurrentVisibleRect); | 148 mPreviousVisibleRect.set(mCurrentVisibleRect); |
145 | |
146 int keyboardHeight = mParent.getHeight() - mCurrentVisibleRect.botto m | |
Jinsuk Kim
2017/07/17 04:45:19
Why is it okay not to take the keyboard height int
jaebaek
2017/07/18 07:48:21
Initially, layout_height of mParent was "match_par
| |
147 + mCurrentVisibleRect.top; | |
148 FrameLayout.LayoutParams lp = getLayoutParams(); | |
149 lp.bottomMargin = keyboardHeight; | |
150 if (mIsTablet) { | 149 if (mIsTablet) { |
150 FrameLayout.LayoutParams lp = getLayoutParams(); | |
151 int margin = mParent.getResources() | 151 int margin = mParent.getResources() |
152 .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); | 152 .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); |
153 int width = mParent.getResources() | 153 int width = mParent.getResources() |
154 .getDimensionPixelSize(R.dimen.snackbar_width_tablet); | 154 .getDimensionPixelSize(R.dimen.snackbar_width_tablet); |
155 lp.width = Math.min(width, mParent.getWidth() - 2 * margin); | 155 lp.width = Math.min(width, mParent.getWidth() - 2 * margin); |
156 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; | 156 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
157 mView.setLayoutParams(lp); | |
157 } | 158 } |
158 mView.setLayoutParams(lp); | |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 /** | 162 /** |
163 * @see SnackbarManager#overrideParent(ViewGroup) | 163 * @see SnackbarManager#overrideParent(ViewGroup) |
164 */ | 164 */ |
165 void overrideParent(ViewGroup overridingParent) { | 165 void overrideParent(ViewGroup overridingParent) { |
166 mParent.removeOnLayoutChangeListener(mLayoutListener); | 166 mParent.removeOnLayoutChangeListener(mLayoutListener); |
167 mParent = overridingParent == null ? mOriginalParent : overridingParent; | 167 mParent = overridingParent == null ? mOriginalParent : overridingParent; |
168 if (isShowing()) { | 168 if (isShowing()) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 if (view.getText().toString().equals(text)) return; | 279 if (view.getText().toString().equals(text)) return; |
280 view.animate().cancel(); | 280 view.animate().cancel(); |
281 if (animate) { | 281 if (animate) { |
282 view.setAlpha(0.0f); | 282 view.setAlpha(0.0f); |
283 view.setText(text); | 283 view.setText(text); |
284 view.animate().alpha(1.f).setDuration(mAnimationDuration).setListene r(null); | 284 view.animate().alpha(1.f).setDuration(mAnimationDuration).setListene r(null); |
285 } else { | 285 } else { |
286 view.setText(text); | 286 view.setText(text); |
287 } | 287 } |
288 } | 288 } |
289 | |
290 private void setPointerIcons() { | |
291 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
292 setPointerIcon(mMessageView, PointerIcon.TYPE_TEXT); | |
293 setPointerIcon(mActionButtonView, PointerIcon.TYPE_HAND); | |
294 } | |
295 } | |
296 | |
297 private void setPointerIcon(View view, int type) { | |
Jinsuk Kim
2017/07/17 04:45:19
static?
jaebaek
2017/07/18 07:48:21
Done.
| |
298 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
299 PointerIcon icon = PointerIcon.getSystemIcon(view.getContext(), type ); | |
300 view.setPointerIcon(icon); | |
301 } | |
302 } | |
289 } | 303 } |
OLD | NEW |