Chromium Code Reviews| 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 setPointerIcon(mMessageView, PointerIcon.TYPE_TEXT); | |
| 99 setPointerIcon(mActionButtonView, PointerIcon.TYPE_HAND); | |
| 100 | |
| 96 updateInternal(snackbar, false); | 101 updateInternal(snackbar, false); |
| 97 } | 102 } |
| 98 | 103 |
| 99 void show() { | 104 void show() { |
| 100 addToParent(); | 105 addToParent(); |
| 101 mView.addOnLayoutChangeListener(new OnLayoutChangeListener() { | 106 mView.addOnLayoutChangeListener(new OnLayoutChangeListener() { |
| 102 @Override | 107 @Override |
| 103 public void onLayoutChange(View v, int left, int top, int right, int bottom, | 108 public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 104 int oldLeft, int oldTop, int oldRight, int oldBottom) { | 109 int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 105 mView.removeOnLayoutChangeListener(this); | 110 mView.removeOnLayoutChangeListener(this); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 135 } | 140 } |
| 136 | 141 |
| 137 /** | 142 /** |
| 138 * Adjusts the position of the snackbar on top of the soft keyboard, if any. | 143 * Adjusts the position of the snackbar on top of the soft keyboard, if any. |
| 139 */ | 144 */ |
| 140 void adjustViewPosition() { | 145 void adjustViewPosition() { |
| 141 mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); | 146 mParent.getWindowVisibleDisplayFrame(mCurrentVisibleRect); |
| 142 // Only update if the visible frame has changed, otherwise there will be a layout loop. | 147 // Only update if the visible frame has changed, otherwise there will be a layout loop. |
| 143 if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { | 148 if (!mCurrentVisibleRect.equals(mPreviousVisibleRect)) { |
| 144 mPreviousVisibleRect.set(mCurrentVisibleRect); | 149 mPreviousVisibleRect.set(mCurrentVisibleRect); |
| 145 | |
| 146 int keyboardHeight = mParent.getHeight() - mCurrentVisibleRect.botto m | |
| 147 + mCurrentVisibleRect.top; | |
| 148 FrameLayout.LayoutParams lp = getLayoutParams(); | |
|
Ted C
2017/07/18 16:41:18
this change will prevent snackbars from appearing
jaebaek
2017/07/19 01:18:53
Yes, it is intentional. When we set the height of
| |
| 149 lp.bottomMargin = keyboardHeight; | |
| 150 if (mIsTablet) { | 150 if (mIsTablet) { |
| 151 FrameLayout.LayoutParams lp = getLayoutParams(); | |
| 151 int margin = mParent.getResources() | 152 int margin = mParent.getResources() |
| 152 .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); | 153 .getDimensionPixelSize(R.dimen.snackbar_margin_tablet); |
| 153 int width = mParent.getResources() | 154 int width = mParent.getResources() |
| 154 .getDimensionPixelSize(R.dimen.snackbar_width_tablet); | 155 .getDimensionPixelSize(R.dimen.snackbar_width_tablet); |
| 155 lp.width = Math.min(width, mParent.getWidth() - 2 * margin); | 156 lp.width = Math.min(width, mParent.getWidth() - 2 * margin); |
| 156 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; | 157 lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; |
| 158 mView.setLayoutParams(lp); | |
| 157 } | 159 } |
| 158 mView.setLayoutParams(lp); | |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 | 162 |
| 162 /** | 163 /** |
| 163 * @see SnackbarManager#overrideParent(ViewGroup) | 164 * @see SnackbarManager#overrideParent(ViewGroup) |
| 164 */ | 165 */ |
| 165 void overrideParent(ViewGroup overridingParent) { | 166 void overrideParent(ViewGroup overridingParent) { |
| 166 mParent.removeOnLayoutChangeListener(mLayoutListener); | 167 mParent.removeOnLayoutChangeListener(mLayoutListener); |
| 167 mParent = overridingParent == null ? mOriginalParent : overridingParent; | 168 mParent = overridingParent == null ? mOriginalParent : overridingParent; |
| 168 if (isShowing()) { | 169 if (isShowing()) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 if (view.getText().toString().equals(text)) return; | 280 if (view.getText().toString().equals(text)) return; |
| 280 view.animate().cancel(); | 281 view.animate().cancel(); |
| 281 if (animate) { | 282 if (animate) { |
| 282 view.setAlpha(0.0f); | 283 view.setAlpha(0.0f); |
| 283 view.setText(text); | 284 view.setText(text); |
| 284 view.animate().alpha(1.f).setDuration(mAnimationDuration).setListene r(null); | 285 view.animate().alpha(1.f).setDuration(mAnimationDuration).setListene r(null); |
| 285 } else { | 286 } else { |
| 286 view.setText(text); | 287 view.setText(text); |
| 287 } | 288 } |
| 288 } | 289 } |
| 290 | |
| 291 private static void setPointerIcon(View view, int type) { | |
| 292 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |
| 293 PointerIcon icon = PointerIcon.getSystemIcon(view.getContext(), type ); | |
| 294 view.setPointerIcon(icon); | |
| 295 } | |
| 296 } | |
| 289 } | 297 } |
| OLD | NEW |