Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 18 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ObjectAnimator; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.res.Resources; |
| 24 | import android.content.res.TypedArray; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 26 | import android.graphics.Canvas; |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 27 | import android.graphics.Color; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 28 | import android.graphics.Paint; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 29 | import android.graphics.PorterDuff; |
| 30 | import android.graphics.PorterDuffXfermode; |
| 31 | import android.graphics.Rect; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 32 | import android.graphics.drawable.Drawable; |
| 33 | import android.util.AttributeSet; |
| 34 | import android.util.DisplayMetrics; |
Svetoslav Ganov | 55d225d | 2012-05-22 15:19:14 -0700 | [diff] [blame] | 35 | import android.view.FocusFinder; |
| 36 | import android.view.MotionEvent; |
| 37 | import android.view.View; |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 38 | import android.view.animation.AccelerateInterpolator; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 39 | import android.widget.FrameLayout; |
| 40 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 41 | public class Cling extends FrameLayout implements Insettable, View.OnLongClickListener { |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 42 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 43 | static final String FIRST_RUN_CLING_DISMISSED_KEY = "cling_gel.first_run.dismissed"; |
| 44 | static final String WORKSPACE_CLING_DISMISSED_KEY = "cling_gel.workspace.dismissed"; |
| 45 | static final String FOLDER_CLING_DISMISSED_KEY = "cling_gel.folder.dismissed"; |
| 46 | |
| 47 | private static String FIRST_RUN_PORTRAIT = "first_run_portrait"; |
| 48 | private static String FIRST_RUN_LANDSCAPE = "first_run_landscape"; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 49 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 50 | private static String WORKSPACE_PORTRAIT = "workspace_portrait"; |
| 51 | private static String WORKSPACE_LANDSCAPE = "workspace_landscape"; |
Andrew Flynn | 2f5f945 | 2012-05-12 17:00:35 -0700 | [diff] [blame] | 52 | private static String WORKSPACE_LARGE = "workspace_large"; |
| 53 | private static String WORKSPACE_CUSTOM = "workspace_custom"; |
| 54 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 55 | private static String FOLDER_PORTRAIT = "folder_portrait"; |
| 56 | private static String FOLDER_LANDSCAPE = "folder_landscape"; |
Winson Chung | d016015 | 2011-11-15 15:04:42 -0800 | [diff] [blame] | 57 | private static String FOLDER_LARGE = "folder_large"; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 58 | |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 59 | private static float FIRST_RUN_CIRCLE_BUFFER_DPS = 60; |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 60 | private static float WORKSPACE_INNER_CIRCLE_RADIUS_DPS = 50; |
| 61 | private static float WORKSPACE_OUTER_CIRCLE_RADIUS_DPS = 60; |
| 62 | private static float WORKSPACE_CIRCLE_Y_OFFSET_DPS = 30; |
| 63 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 64 | private Launcher mLauncher; |
| 65 | private boolean mIsInitialized; |
| 66 | private String mDrawIdentifier; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 67 | private Drawable mBackground; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 68 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 69 | private Paint mErasePaint; |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 70 | private Paint mBubblePaint; |
| 71 | private Paint mDotPaint; |
| 72 | |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 73 | private View mScrimView; |
| 74 | private int mBackgroundColor; |
| 75 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 76 | private final Rect mInsets = new Rect(); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 77 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 78 | public Cling(Context context) { |
| 79 | this(context, null, 0); |
| 80 | } |
| 81 | |
| 82 | public Cling(Context context, AttributeSet attrs) { |
| 83 | this(context, attrs, 0); |
| 84 | } |
| 85 | |
| 86 | public Cling(Context context, AttributeSet attrs, int defStyle) { |
| 87 | super(context, attrs, defStyle); |
| 88 | |
| 89 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Cling, defStyle, 0); |
| 90 | mDrawIdentifier = a.getString(R.styleable.Cling_drawIdentifier); |
| 91 | a.recycle(); |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 92 | |
| 93 | setClickable(true); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 94 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 97 | void init(Launcher l, View scrim) { |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 98 | if (!mIsInitialized) { |
| 99 | mLauncher = l; |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 100 | mScrimView = scrim; |
| 101 | mBackgroundColor = 0xdd000000; |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 102 | setOnLongClickListener(this); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 103 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 104 | mErasePaint = new Paint(); |
| 105 | mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); |
| 106 | mErasePaint.setColor(0xFFFFFF); |
| 107 | mErasePaint.setAlpha(0); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 108 | mErasePaint.setAntiAlias(true); |
| 109 | |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 110 | int circleColor = getResources().getColor( |
| 111 | R.color.first_run_cling_circle_background_color); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 112 | mBubblePaint = new Paint(); |
Winson Chung | e6eabff | 2013-09-24 11:01:23 -0700 | [diff] [blame] | 113 | mBubblePaint.setColor(circleColor); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 114 | mBubblePaint.setAntiAlias(true); |
| 115 | |
| 116 | mDotPaint = new Paint(); |
| 117 | mDotPaint.setColor(0x72BBED); |
| 118 | mDotPaint.setAntiAlias(true); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 119 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 120 | mIsInitialized = true; |
| 121 | } |
| 122 | } |
| 123 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 124 | void show(boolean animate, int duration) { |
| 125 | setVisibility(View.VISIBLE); |
| 126 | setLayerType(View.LAYER_TYPE_HARDWARE, null); |
| 127 | if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || |
| 128 | mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || |
| 129 | mDrawIdentifier.equals(WORKSPACE_LARGE) || |
| 130 | mDrawIdentifier.equals(WORKSPACE_CUSTOM)) { |
| 131 | View content = getContent(); |
| 132 | content.setAlpha(0f); |
| 133 | content.animate() |
| 134 | .alpha(1f) |
| 135 | .setDuration(duration) |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 136 | .setListener(null) |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 137 | .start(); |
| 138 | setAlpha(1f); |
| 139 | } else { |
| 140 | if (animate) { |
| 141 | buildLayer(); |
| 142 | setAlpha(0f); |
| 143 | animate() |
| 144 | .alpha(1f) |
| 145 | .setInterpolator(new AccelerateInterpolator()) |
| 146 | .setDuration(duration) |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 147 | .setListener(null) |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 148 | .start(); |
| 149 | } else { |
| 150 | setAlpha(1f); |
| 151 | } |
| 152 | } |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 153 | |
| 154 | // Show the scrim if necessary |
| 155 | if (mScrimView != null) { |
| 156 | mScrimView.setVisibility(View.VISIBLE); |
| 157 | mScrimView.setAlpha(0f); |
| 158 | mScrimView.animate() |
| 159 | .alpha(1f) |
| 160 | .setDuration(duration) |
| 161 | .setListener(null) |
| 162 | .start(); |
| 163 | } |
| 164 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 165 | setFocusableInTouchMode(true); |
| 166 | post(new Runnable() { |
| 167 | public void run() { |
| 168 | setFocusable(true); |
| 169 | requestFocus(); |
| 170 | } |
| 171 | }); |
| 172 | } |
| 173 | |
| 174 | void hide(final int duration, final Runnable postCb) { |
| 175 | if (mDrawIdentifier.equals(FIRST_RUN_PORTRAIT) || |
| 176 | mDrawIdentifier.equals(FIRST_RUN_LANDSCAPE)) { |
| 177 | View content = getContent(); |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 178 | content.animate() |
| 179 | .alpha(0f) |
| 180 | .setDuration(duration) |
| 181 | .setListener(new AnimatorListenerAdapter() { |
| 182 | public void onAnimationEnd(Animator animation) { |
| 183 | // We are about to trigger the workspace cling, so don't do anything else |
| 184 | setVisibility(View.GONE); |
| 185 | postCb.run(); |
| 186 | }; |
| 187 | }) |
| 188 | .start(); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 189 | } else { |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 190 | animate() |
| 191 | .alpha(0f) |
| 192 | .setDuration(duration) |
| 193 | .setListener(new AnimatorListenerAdapter() { |
| 194 | public void onAnimationEnd(Animator animation) { |
| 195 | // We are about to trigger the workspace cling, so don't do anything else |
| 196 | setVisibility(View.GONE); |
| 197 | postCb.run(); |
| 198 | }; |
| 199 | }) |
| 200 | .start(); |
| 201 | } |
| 202 | |
| 203 | // Show the scrim if necessary |
| 204 | if (mScrimView != null) { |
| 205 | mScrimView.animate() |
| 206 | .alpha(0f) |
| 207 | .setDuration(duration) |
| 208 | .setListener(new AnimatorListenerAdapter() { |
| 209 | public void onAnimationEnd(Animator animation) { |
| 210 | mScrimView.setVisibility(View.GONE); |
| 211 | }; |
| 212 | }) |
| 213 | .start(); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 217 | void cleanup() { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 218 | mBackground = null; |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 219 | mIsInitialized = false; |
| 220 | } |
| 221 | |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 222 | void bringScrimToFront() { |
| 223 | if (mScrimView != null) { |
| 224 | mScrimView.bringToFront(); |
| 225 | } |
| 226 | } |
| 227 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 228 | @Override |
| 229 | public void setInsets(Rect insets) { |
| 230 | mInsets.set(insets); |
| 231 | setPadding(insets.left, insets.top, insets.right, insets.bottom); |
Michael Jurka | 974c386 | 2012-05-22 22:00:31 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 234 | View getContent() { |
| 235 | return findViewById(R.id.content); |
| 236 | } |
| 237 | |
| 238 | String getDrawIdentifier() { |
| 239 | return mDrawIdentifier; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | @Override |
Svetoslav Ganov | 55d225d | 2012-05-22 15:19:14 -0700 | [diff] [blame] | 243 | public View focusSearch(int direction) { |
Michael Jurka | 9bc8eba | 2012-05-21 20:36:44 -0700 | [diff] [blame] | 244 | return this.focusSearch(this, direction); |
Svetoslav Ganov | 55d225d | 2012-05-22 15:19:14 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public View focusSearch(View focused, int direction) { |
| 249 | return FocusFinder.getInstance().findNextFocus(this, focused, direction); |
| 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public boolean onHoverEvent(MotionEvent event) { |
| 254 | return (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) |
| 255 | || mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) |
| 256 | || mDrawIdentifier.equals(WORKSPACE_LARGE) |
Svetoslav Ganov | 55d225d | 2012-05-22 15:19:14 -0700 | [diff] [blame] | 257 | || mDrawIdentifier.equals(WORKSPACE_CUSTOM)); |
| 258 | } |
| 259 | |
| 260 | @Override |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 261 | public boolean onTouchEvent(android.view.MotionEvent event) { |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 262 | if (mDrawIdentifier.equals(FOLDER_PORTRAIT) || |
Winson Chung | d016015 | 2011-11-15 15:04:42 -0800 | [diff] [blame] | 263 | mDrawIdentifier.equals(FOLDER_LANDSCAPE) || |
| 264 | mDrawIdentifier.equals(FOLDER_LARGE)) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 265 | Folder f = mLauncher.getWorkspace().getOpenFolder(); |
| 266 | if (f != null) { |
| 267 | Rect r = new Rect(); |
| 268 | f.getHitRect(r); |
| 269 | if (r.contains((int) event.getX(), (int) event.getY())) { |
| 270 | return false; |
| 271 | } |
| 272 | } |
| 273 | } |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 274 | return super.onTouchEvent(event); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | @Override |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 278 | public boolean onLongClick(View v) { |
| 279 | if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || |
| 280 | mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || |
| 281 | mDrawIdentifier.equals(WORKSPACE_LARGE)) { |
| 282 | mLauncher.dismissWorkspaceCling(null); |
| 283 | return true; |
| 284 | } |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | @Override |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 289 | protected void dispatchDraw(Canvas canvas) { |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 290 | if (mIsInitialized) { |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 291 | canvas.save(); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 292 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 293 | // Get the background override if there is one |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 294 | if (mBackground == null) { |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 295 | if (mDrawIdentifier.equals(WORKSPACE_CUSTOM)) { |
Andrew Flynn | a743d35 | 2012-05-18 13:38:52 -0700 | [diff] [blame] | 296 | mBackground = getResources().getDrawable(R.drawable.bg_cling5); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 299 | // Draw the background |
| 300 | Bitmap eraseBg = null; |
| 301 | Canvas eraseCanvas = null; |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 302 | if (mScrimView != null) { |
| 303 | // Skip drawing the background |
| 304 | mScrimView.setBackgroundColor(mBackgroundColor); |
| 305 | } else if (mBackground != null) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 306 | mBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 307 | mBackground.draw(canvas); |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 308 | } else if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || |
| 309 | mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || |
| 310 | mDrawIdentifier.equals(WORKSPACE_LARGE)) { |
| 311 | // Initialize the draw buffer (to allow punching through) |
| 312 | eraseBg = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), |
| 313 | Bitmap.Config.ARGB_8888); |
| 314 | eraseCanvas = new Canvas(eraseBg); |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 315 | eraseCanvas.drawColor(mBackgroundColor); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 316 | } else { |
Winson Chung | fa54513 | 2013-09-26 17:45:32 -0700 | [diff] [blame] | 317 | canvas.drawColor(mBackgroundColor); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 318 | } |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 319 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 320 | // Draw everything else |
| 321 | DisplayMetrics metrics = new DisplayMetrics(); |
| 322 | mLauncher.getWindowManager().getDefaultDisplay().getMetrics(metrics); |
| 323 | float alpha = getAlpha(); |
| 324 | View content = getContent(); |
| 325 | if (content != null) { |
| 326 | alpha *= content.getAlpha(); |
| 327 | } |
| 328 | if (mDrawIdentifier.equals(FIRST_RUN_PORTRAIT) || |
| 329 | mDrawIdentifier.equals(FIRST_RUN_LANDSCAPE)) { |
| 330 | // Draw the white circle |
| 331 | View bubbleContent = findViewById(R.id.bubble_content); |
| 332 | Rect bubbleRect = new Rect(); |
| 333 | bubbleContent.getGlobalVisibleRect(bubbleRect); |
| 334 | mBubblePaint.setAlpha((int) (255 * alpha)); |
| 335 | float buffer = DynamicGrid.pxFromDp(FIRST_RUN_CIRCLE_BUFFER_DPS, metrics); |
| 336 | canvas.drawCircle(metrics.widthPixels / 2, |
| 337 | bubbleRect.centerY(), |
| 338 | (bubbleContent.getMeasuredWidth() + buffer) / 2, |
| 339 | mBubblePaint); |
| 340 | } else if (mDrawIdentifier.equals(WORKSPACE_PORTRAIT) || |
| 341 | mDrawIdentifier.equals(WORKSPACE_LANDSCAPE) || |
| 342 | mDrawIdentifier.equals(WORKSPACE_LARGE)) { |
| 343 | int offset = DynamicGrid.pxFromDp(WORKSPACE_CIRCLE_Y_OFFSET_DPS, metrics); |
| 344 | mErasePaint.setAlpha((int) (128)); |
| 345 | eraseCanvas.drawCircle(metrics.widthPixels / 2, |
| 346 | metrics.heightPixels / 2 - offset, |
| 347 | DynamicGrid.pxFromDp(WORKSPACE_OUTER_CIRCLE_RADIUS_DPS, metrics), |
| 348 | mErasePaint); |
| 349 | mErasePaint.setAlpha(0); |
| 350 | eraseCanvas.drawCircle(metrics.widthPixels / 2, |
| 351 | metrics.heightPixels / 2 - offset, |
| 352 | DynamicGrid.pxFromDp(WORKSPACE_INNER_CIRCLE_RADIUS_DPS, metrics), |
| 353 | mErasePaint); |
| 354 | canvas.drawBitmap(eraseBg, 0, 0, null); |
| 355 | eraseCanvas.setBitmap(null); |
| 356 | eraseBg = null; |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 357 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 358 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 359 | |
Winson Chung | af40f20 | 2013-09-18 18:26:31 -0700 | [diff] [blame] | 360 | canvas.restore(); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 361 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 362 | |
| 363 | // Draw the rest of the cling |
| 364 | super.dispatchDraw(canvas); |
Winson Chung | 82f5553 | 2011-08-09 14:14:23 -0700 | [diff] [blame] | 365 | }; |
| 366 | } |