| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.bubbles; |
| 18 |
|
| 19 |
import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
| 20 |
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK; |
| 21 |
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT; |
| 22 |
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 23 |
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| 24 |
|
| 25 |
import static com.android.wm.shell.bubbles.BubbleDebugConfig.DEBUG_BUBBLE_EXPANDED_VIEW; |
| 26 |
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES; |
| 27 |
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; |
| 28 |
import static com.android.wm.shell.bubbles.BubblePositioner.MAX_HEIGHT; |
| 29 |
|
| 30 |
import android.annotation.NonNull; |
| 31 |
import android.annotation.SuppressLint; |
| 32 |
import android.app.ActivityOptions; |
| 33 |
import android.app.ActivityTaskManager; |
| 34 |
import android.app.PendingIntent; |
| 35 |
import android.content.ComponentName; |
| 36 |
import android.content.Context; |
| 37 |
import android.content.Intent; |
| 38 |
import android.content.res.Resources; |
| 39 |
import android.content.res.TypedArray; |
| 40 |
import android.graphics.Bitmap; |
| 41 |
import android.graphics.Color; |
| 42 |
import android.graphics.CornerPathEffect; |
| 43 |
import android.graphics.Outline; |
| 44 |
import android.graphics.Paint; |
| 45 |
import android.graphics.Picture; |
| 46 |
import android.graphics.PointF; |
| 47 |
import android.graphics.Rect; |
| 48 |
import android.graphics.drawable.ShapeDrawable; |
| 49 |
import android.os.RemoteException; |
| 50 |
import android.util.AttributeSet; |
| 51 |
import android.util.FloatProperty; |
| 52 |
import android.util.IntProperty; |
| 53 |
import android.util.Log; |
| 54 |
import android.util.TypedValue; |
| 55 |
import android.view.LayoutInflater; |
| 56 |
import android.view.SurfaceControl; |
| 57 |
import android.view.View; |
| 58 |
import android.view.ViewGroup; |
| 59 |
import android.view.ViewOutlineProvider; |
| 60 |
import android.view.accessibility.AccessibilityNodeInfo; |
| 61 |
import android.widget.FrameLayout; |
| 62 |
import android.widget.LinearLayout; |
| 63 |
|
| 64 |
import androidx.annotation.Nullable; |
| 65 |
|
| 66 |
import com.android.internal.annotations.VisibleForTesting; |
| 67 |
import com.android.internal.policy.ScreenDecorationsUtils; |
| 68 |
import com.android.wm.shell.R; |
| 69 |
import com.android.wm.shell.TaskView; |
| 70 |
import com.android.wm.shell.common.AlphaOptimizedButton; |
| 71 |
import com.android.wm.shell.common.TriangleShape; |
| 72 |
|
| 73 |
import java.io.PrintWriter; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public class BubbleExpandedView extends LinearLayout { |
| 79 |
private static final String TAG = TAG_WITH_CLASS_NAME ? "BubbleExpandedView" : TAG_BUBBLES; |
| 80 |
|
| 81 |
|
| 82 |
public static final IntProperty<BubbleExpandedView> BOTTOM_CLIP_PROPERTY = |
| 83 |
new IntProperty<BubbleExpandedView>("bottomClip") { |
| 84 |
@Override |
| 85 |
public void setValue(BubbleExpandedView expandedView, int value) { |
| 86 |
expandedView.setBottomClip(value); |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
public Integer get(BubbleExpandedView expandedView) { |
| 91 |
return expandedView.mBottomClip; |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
public static final FloatProperty<BubbleExpandedView> CONTENT_ALPHA = |
| 97 |
new FloatProperty<BubbleExpandedView>("contentAlpha") { |
| 98 |
@Override |
| 99 |
public void setValue(BubbleExpandedView expandedView, float value) { |
| 100 |
expandedView.setContentAlpha(value); |
| 101 |
} |
| 102 |
|
| 103 |
@Override |
| 104 |
public Float get(BubbleExpandedView expandedView) { |
| 105 |
return expandedView.getContentAlpha(); |
| 106 |
} |
| 107 |
}; |
| 108 |
|
| 109 |
|
| 110 |
public static final FloatProperty<BubbleExpandedView> BACKGROUND_ALPHA = |
| 111 |
new FloatProperty<BubbleExpandedView>("backgroundAlpha") { |
| 112 |
@Override |
| 113 |
public void setValue(BubbleExpandedView expandedView, float value) { |
| 114 |
expandedView.setBackgroundAlpha(value); |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public Float get(BubbleExpandedView expandedView) { |
| 119 |
return expandedView.getAlpha(); |
| 120 |
} |
| 121 |
}; |
| 122 |
|
| 123 |
|
| 124 |
public static final FloatProperty<BubbleExpandedView> MANAGE_BUTTON_ALPHA = |
| 125 |
new FloatProperty<BubbleExpandedView>("manageButtonAlpha") { |
| 126 |
@Override |
| 127 |
public void setValue(BubbleExpandedView expandedView, float value) { |
| 128 |
expandedView.mManageButton.setAlpha(value); |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public Float get(BubbleExpandedView expandedView) { |
| 133 |
return expandedView.mManageButton.getAlpha(); |
| 134 |
} |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
private View mPointerView; |
| 139 |
@Nullable private int[] mExpandedViewContainerLocation; |
| 140 |
|
| 141 |
private AlphaOptimizedButton mManageButton; |
| 142 |
private TaskView mTaskView; |
| 143 |
private BubbleOverflowContainerView mOverflowView; |
| 144 |
|
| 145 |
private int mTaskId = INVALID_TASK_ID; |
| 146 |
|
| 147 |
private boolean mImeVisible; |
| 148 |
private boolean mNeedsNewHeight; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
private boolean mIsContentVisible = false; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
private boolean mIsAnimating = false; |
| 162 |
|
| 163 |
private int mPointerWidth; |
| 164 |
private int mPointerHeight; |
| 165 |
private float mPointerRadius; |
| 166 |
private float mPointerOverlap; |
| 167 |
private final PointF mPointerPos = new PointF(); |
| 168 |
private CornerPathEffect mPointerEffect; |
| 169 |
private ShapeDrawable mCurrentPointer; |
| 170 |
private ShapeDrawable mTopPointer; |
| 171 |
private ShapeDrawable mLeftPointer; |
| 172 |
private ShapeDrawable mRightPointer; |
| 173 |
private float mCornerRadius = 0f; |
| 174 |
private int mBackgroundColorFloating; |
| 175 |
private boolean mUsingMaxHeight; |
| 176 |
private int mTopClip = 0; |
| 177 |
private int mBottomClip = 0; |
| 178 |
@Nullable private Bubble mBubble; |
| 179 |
private PendingIntent mPendingIntent; |
| 180 |
|
| 181 |
private boolean mIsOverflow; |
| 182 |
private boolean mIsClipping; |
| 183 |
|
| 184 |
private BubbleController mController; |
| 185 |
private BubbleStackView mStackView; |
| 186 |
private BubblePositioner mPositioner; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
private final FrameLayout mExpandedViewContainer = new FrameLayout(getContext()); |
| 193 |
|
| 194 |
private final TaskView.Listener mTaskViewListener = new TaskView.Listener() { |
| 195 |
private boolean mInitialized = false; |
| 196 |
private boolean mDestroyed = false; |
| 197 |
|
| 198 |
@Override |
| 199 |
public void onInitialized() { |
| 200 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 201 |
Log.d(TAG, "onInitialized: destroyed=" + mDestroyed |
| 202 |
+ " initialized=" + mInitialized |
| 203 |
+ " bubble=" + getBubbleKey()); |
| 204 |
} |
| 205 |
|
| 206 |
if (mDestroyed || mInitialized) { |
| 207 |
return; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
ActivityOptions options = ActivityOptions.makeCustomAnimation(getContext(), |
| 212 |
0 , 0 ); |
| 213 |
|
| 214 |
Rect launchBounds = new Rect(); |
| 215 |
mTaskView.getBoundsOnScreen(launchBounds); |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
post(() -> { |
| 220 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 221 |
Log.d(TAG, "onInitialized: calling startActivity, bubble=" |
| 222 |
+ getBubbleKey()); |
| 223 |
} |
| 224 |
try { |
| 225 |
options.setTaskAlwaysOnTop(true); |
| 226 |
options.setLaunchedFromBubble(true); |
| 227 |
|
| 228 |
Intent fillInIntent = new Intent(); |
| 229 |
|
| 230 |
fillInIntent.addFlags(FLAG_ACTIVITY_NEW_DOCUMENT); |
| 231 |
fillInIntent.addFlags(FLAG_ACTIVITY_MULTIPLE_TASK); |
| 232 |
|
| 233 |
if (mBubble.isAppBubble()) { |
| 234 |
PendingIntent pi = PendingIntent.getActivity(mContext, 0, |
| 235 |
mBubble.getAppBubbleIntent(), |
| 236 |
PendingIntent.FLAG_MUTABLE, |
| 237 |
null); |
| 238 |
mTaskView.startActivity(pi, fillInIntent, options, launchBounds); |
| 239 |
} else if (!mIsOverflow && mBubble.hasMetadataShortcutId()) { |
| 240 |
options.setApplyActivityFlagsForBubbles(true); |
| 241 |
mTaskView.startShortcutActivity(mBubble.getShortcutInfo(), |
| 242 |
options, launchBounds); |
| 243 |
} else { |
| 244 |
if (mBubble != null) { |
| 245 |
mBubble.setIntentActive(); |
| 246 |
} |
| 247 |
mTaskView.startActivity(mPendingIntent, fillInIntent, options, |
| 248 |
launchBounds); |
| 249 |
} |
| 250 |
} catch (RuntimeException e) { |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
Log.w(TAG, "Exception while displaying bubble: " + getBubbleKey() |
| 255 |
+ ", " + e.getMessage() + "; removing bubble"); |
| 256 |
mController.removeBubble(getBubbleKey(), Bubbles.DISMISS_INVALID_INTENT); |
| 257 |
} |
| 258 |
}); |
| 259 |
mInitialized = true; |
| 260 |
} |
| 261 |
|
| 262 |
@Override |
| 263 |
public void onReleased() { |
| 264 |
mDestroyed = true; |
| 265 |
} |
| 266 |
|
| 267 |
@Override |
| 268 |
public void onTaskCreated(int taskId, ComponentName name) { |
| 269 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 270 |
Log.d(TAG, "onTaskCreated: taskId=" + taskId |
| 271 |
+ " bubble=" + getBubbleKey()); |
| 272 |
} |
| 273 |
|
| 274 |
mTaskId = taskId; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
setContentVisibility(true); |
| 279 |
} |
| 280 |
|
| 281 |
@Override |
| 282 |
public void onTaskVisibilityChanged(int taskId, boolean visible) { |
| 283 |
setContentVisibility(visible); |
| 284 |
} |
| 285 |
|
| 286 |
@Override |
| 287 |
public void onTaskRemovalStarted(int taskId) { |
| 288 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 289 |
Log.d(TAG, "onTaskRemovalStarted: taskId=" + taskId |
| 290 |
+ " bubble=" + getBubbleKey()); |
| 291 |
} |
| 292 |
if (mBubble != null) { |
| 293 |
|
| 294 |
post(() -> mController.removeBubble( |
| 295 |
mBubble.getKey(), Bubbles.DISMISS_TASK_FINISHED)); |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
@Override |
| 300 |
public void onBackPressedOnTaskRoot(int taskId) { |
| 301 |
if (mTaskId == taskId && mStackView.isExpanded()) { |
| 302 |
mStackView.onBackPressed(); |
| 303 |
} |
| 304 |
} |
| 305 |
}; |
| 306 |
|
| 307 |
public BubbleExpandedView(Context context) { |
| 308 |
this(context, null); |
| 309 |
} |
| 310 |
|
| 311 |
public BubbleExpandedView(Context context, AttributeSet attrs) { |
| 312 |
this(context, attrs, 0); |
| 313 |
} |
| 314 |
|
| 315 |
public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr) { |
| 316 |
this(context, attrs, defStyleAttr, 0); |
| 317 |
} |
| 318 |
|
| 319 |
public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, |
| 320 |
int defStyleRes) { |
| 321 |
super(context, attrs, defStyleAttr, defStyleRes); |
| 322 |
} |
| 323 |
|
| 324 |
@SuppressLint("ClickableViewAccessibility") |
| 325 |
@Override |
| 326 |
protected void onFinishInflate() { |
| 327 |
super.onFinishInflate(); |
| 328 |
mManageButton = (AlphaOptimizedButton) LayoutInflater.from(getContext()).inflate( |
| 329 |
R.layout.bubble_manage_button, this , false ); |
| 330 |
updateDimensions(); |
| 331 |
mPointerView = findViewById(R.id.pointer_view); |
| 332 |
mCurrentPointer = mTopPointer; |
| 333 |
mPointerView.setVisibility(INVISIBLE); |
| 334 |
|
| 335 |
|
| 336 |
setContentVisibility(false); |
| 337 |
|
| 338 |
mExpandedViewContainer.setOutlineProvider(new ViewOutlineProvider() { |
| 339 |
@Override |
| 340 |
public void getOutline(View view, Outline outline) { |
| 341 |
Rect clip = new Rect(0, mTopClip, view.getWidth(), view.getHeight() - mBottomClip); |
| 342 |
outline.setRoundRect(clip, mCornerRadius); |
| 343 |
} |
| 344 |
}); |
| 345 |
mExpandedViewContainer.setClipToOutline(true); |
| 346 |
mExpandedViewContainer.setLayoutParams( |
| 347 |
new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)); |
| 348 |
addView(mExpandedViewContainer); |
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
bringChildToFront(mManageButton); |
| 357 |
|
| 358 |
applyThemeAttrs(); |
| 359 |
|
| 360 |
setClipToPadding(false); |
| 361 |
setOnTouchListener((view, motionEvent) -> { |
| 362 |
if (mTaskView == null) { |
| 363 |
return false; |
| 364 |
} |
| 365 |
|
| 366 |
final Rect avBounds = new Rect(); |
| 367 |
mTaskView.getBoundsOnScreen(avBounds); |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
if (motionEvent.getRawY() >= avBounds.top |
| 374 |
&& motionEvent.getRawY() <= avBounds.bottom |
| 375 |
&& (motionEvent.getRawX() < avBounds.left |
| 376 |
|| motionEvent.getRawX() > avBounds.right)) { |
| 377 |
return true; |
| 378 |
} |
| 379 |
|
| 380 |
return false; |
| 381 |
}); |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
setLayoutDirection(LAYOUT_DIRECTION_LOCALE); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
void initialize(BubbleController controller, BubbleStackView stackView, boolean isOverflow) { |
| 393 |
mController = controller; |
| 394 |
mStackView = stackView; |
| 395 |
mIsOverflow = isOverflow; |
| 396 |
mPositioner = mController.getPositioner(); |
| 397 |
|
| 398 |
if (mIsOverflow) { |
| 399 |
mOverflowView = (BubbleOverflowContainerView) LayoutInflater.from(getContext()).inflate( |
| 400 |
R.layout.bubble_overflow_container, null ); |
| 401 |
mOverflowView.setBubbleController(mController); |
| 402 |
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT); |
| 403 |
mExpandedViewContainer.addView(mOverflowView, lp); |
| 404 |
mExpandedViewContainer.setLayoutParams( |
| 405 |
new LinearLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); |
| 406 |
bringChildToFront(mOverflowView); |
| 407 |
mManageButton.setVisibility(GONE); |
| 408 |
} else { |
| 409 |
mTaskView = new TaskView(mContext, mController.getTaskOrganizer(), |
| 410 |
mController.getTaskViewTransitions(), mController.getSyncTransactionQueue()); |
| 411 |
mTaskView.setListener(mController.getMainExecutor(), mTaskViewListener); |
| 412 |
mExpandedViewContainer.addView(mTaskView); |
| 413 |
bringChildToFront(mTaskView); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
void updateDimensions() { |
| 418 |
Resources res = getResources(); |
| 419 |
updateFontSize(); |
| 420 |
|
| 421 |
mPointerWidth = res.getDimensionPixelSize(R.dimen.bubble_pointer_width); |
| 422 |
mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height); |
| 423 |
mPointerRadius = getResources().getDimensionPixelSize(R.dimen.bubble_pointer_radius); |
| 424 |
mPointerEffect = new CornerPathEffect(mPointerRadius); |
| 425 |
mPointerOverlap = getResources().getDimensionPixelSize(R.dimen.bubble_pointer_overlap); |
| 426 |
mTopPointer = new ShapeDrawable(TriangleShape.create( |
| 427 |
mPointerWidth, mPointerHeight, true )); |
| 428 |
mLeftPointer = new ShapeDrawable(TriangleShape.createHorizontal( |
| 429 |
mPointerWidth, mPointerHeight, true )); |
| 430 |
mRightPointer = new ShapeDrawable(TriangleShape.createHorizontal( |
| 431 |
mPointerWidth, mPointerHeight, false )); |
| 432 |
if (mPointerView != null) { |
| 433 |
updatePointerView(); |
| 434 |
} |
| 435 |
|
| 436 |
if (mManageButton != null) { |
| 437 |
int visibility = mManageButton.getVisibility(); |
| 438 |
removeView(mManageButton); |
| 439 |
mManageButton = (AlphaOptimizedButton) LayoutInflater.from(getContext()).inflate( |
| 440 |
R.layout.bubble_manage_button, this , false ); |
| 441 |
addView(mManageButton); |
| 442 |
mManageButton.setVisibility(visibility); |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
void updateFontSize() { |
| 447 |
final float fontSize = mContext.getResources() |
| 448 |
.getDimensionPixelSize(com.android.internal.R.dimen.text_size_body_2_material); |
| 449 |
if (mManageButton != null) { |
| 450 |
mManageButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
| 451 |
} |
| 452 |
if (mOverflowView != null) { |
| 453 |
mOverflowView.updateFontSize(); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
void applyThemeAttrs() { |
| 458 |
final TypedArray ta = mContext.obtainStyledAttributes(new int[]{ |
| 459 |
android.R.attr.dialogCornerRadius, |
| 460 |
android.R.attr.colorBackgroundFloating}); |
| 461 |
boolean supportsRoundedCorners = ScreenDecorationsUtils.supportsRoundedCornersOnWindows( |
| 462 |
mContext.getResources()); |
| 463 |
mCornerRadius = supportsRoundedCorners ? ta.getDimensionPixelSize(0, 0) : 0; |
| 464 |
mBackgroundColorFloating = ta.getColor(1, Color.WHITE); |
| 465 |
mExpandedViewContainer.setBackgroundColor(mBackgroundColorFloating); |
| 466 |
ta.recycle(); |
| 467 |
|
| 468 |
if (mTaskView != null) { |
| 469 |
mTaskView.setCornerRadius(mCornerRadius); |
| 470 |
} |
| 471 |
updatePointerView(); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
private void updatePointerView() { |
| 476 |
LayoutParams lp = (LayoutParams) mPointerView.getLayoutParams(); |
| 477 |
if (mCurrentPointer == mLeftPointer || mCurrentPointer == mRightPointer) { |
| 478 |
lp.width = mPointerHeight; |
| 479 |
lp.height = mPointerWidth; |
| 480 |
} else { |
| 481 |
lp.width = mPointerWidth; |
| 482 |
lp.height = mPointerHeight; |
| 483 |
} |
| 484 |
mCurrentPointer.setTint(mBackgroundColorFloating); |
| 485 |
|
| 486 |
Paint arrowPaint = mCurrentPointer.getPaint(); |
| 487 |
arrowPaint.setColor(mBackgroundColorFloating); |
| 488 |
arrowPaint.setPathEffect(mPointerEffect); |
| 489 |
mPointerView.setLayoutParams(lp); |
| 490 |
mPointerView.setBackground(mCurrentPointer); |
| 491 |
} |
| 492 |
|
| 493 |
@VisibleForTesting |
| 494 |
public String getBubbleKey() { |
| 495 |
return mBubble != null ? mBubble.getKey() : mIsOverflow ? BubbleOverflow.KEY : null; |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
public void setSurfaceZOrderedOnTop(boolean onTop) { |
| 504 |
if (mTaskView == null) { |
| 505 |
return; |
| 506 |
} |
| 507 |
mTaskView.setZOrderedOnTop(onTop, true ); |
| 508 |
} |
| 509 |
|
| 510 |
void setImeVisible(boolean visible) { |
| 511 |
mImeVisible = visible; |
| 512 |
if (!mImeVisible && mNeedsNewHeight) { |
| 513 |
updateHeight(); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
@Nullable |
| 519 |
SurfaceControl.ScreenshotHardwareBuffer snapshotActivitySurface() { |
| 520 |
if (mIsOverflow) { |
| 521 |
|
| 522 |
|
| 523 |
Picture p = new Picture(); |
| 524 |
mOverflowView.draw( |
| 525 |
p.beginRecording(mOverflowView.getWidth(), mOverflowView.getHeight())); |
| 526 |
p.endRecording(); |
| 527 |
Bitmap snapshot = Bitmap.createBitmap(p); |
| 528 |
return new SurfaceControl.ScreenshotHardwareBuffer( |
| 529 |
snapshot.getHardwareBuffer(), |
| 530 |
snapshot.getColorSpace(), |
| 531 |
false , |
| 532 |
false ); |
| 533 |
} |
| 534 |
if (mTaskView == null || mTaskView.getSurfaceControl() == null) { |
| 535 |
return null; |
| 536 |
} |
| 537 |
return SurfaceControl.captureLayers( |
| 538 |
mTaskView.getSurfaceControl(), |
| 539 |
new Rect(0, 0, mTaskView.getWidth(), mTaskView.getHeight()), |
| 540 |
1 ); |
| 541 |
} |
| 542 |
|
| 543 |
int[] getTaskViewLocationOnScreen() { |
| 544 |
if (mIsOverflow) { |
| 545 |
|
| 546 |
|
| 547 |
return mOverflowView.getLocationOnScreen(); |
| 548 |
} |
| 549 |
if (mTaskView != null) { |
| 550 |
return mTaskView.getLocationOnScreen(); |
| 551 |
} else { |
| 552 |
return new int[]{0, 0}; |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
void setManageClickListener(OnClickListener manageClickListener) { |
| 558 |
mManageButton.setOnClickListener(manageClickListener); |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
void updateObscuredTouchableRegion() { |
| 568 |
if (mTaskView != null) { |
| 569 |
mTaskView.onLocationChanged(); |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
@Override |
| 574 |
protected void onDetachedFromWindow() { |
| 575 |
super.onDetachedFromWindow(); |
| 576 |
mImeVisible = false; |
| 577 |
mNeedsNewHeight = false; |
| 578 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 579 |
Log.d(TAG, "onDetachedFromWindow: bubble=" + getBubbleKey()); |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
public void setAnimating(boolean animating) { |
| 589 |
mIsAnimating = animating; |
| 590 |
|
| 591 |
|
| 592 |
if (!animating) { |
| 593 |
setContentVisibility(mIsContentVisible); |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
public float getContentAlpha() { |
| 604 |
if (mIsOverflow) { |
| 605 |
return mOverflowView.getAlpha(); |
| 606 |
} |
| 607 |
if (mTaskView != null) { |
| 608 |
return mTaskView.getAlpha(); |
| 609 |
} |
| 610 |
return 1f; |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
public void setContentAlpha(float alpha) { |
| 620 |
if (mIsOverflow) { |
| 621 |
mOverflowView.setAlpha(alpha); |
| 622 |
} else if (mTaskView != null) { |
| 623 |
mTaskView.setAlpha(alpha); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
public void setBackgroundAlpha(float alpha) { |
| 631 |
mPointerView.setAlpha(alpha); |
| 632 |
setAlpha(alpha); |
| 633 |
} |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
public void setContentTranslationY(float translationY) { |
| 640 |
mExpandedViewContainer.setTranslationY(translationY); |
| 641 |
|
| 642 |
|
| 643 |
if (translationY <= 0 && (isShowingLeftPointer() || isShowingRightPointer())) { |
| 644 |
|
| 645 |
|
| 646 |
float detachPoint = |
| 647 |
mExpandedViewContainer.getBottom() - mBottomClip - mCornerRadius + translationY; |
| 648 |
float pointerBottom = mPointerPos.y + mPointerHeight; |
| 649 |
|
| 650 |
float horizontalShift = 0; |
| 651 |
if (pointerBottom > detachPoint) { |
| 652 |
horizontalShift = pointerBottom - detachPoint; |
| 653 |
} |
| 654 |
if (isShowingLeftPointer()) { |
| 655 |
|
| 656 |
movePointerBy(horizontalShift, 0); |
| 657 |
} else { |
| 658 |
|
| 659 |
movePointerBy(-horizontalShift, 0); |
| 660 |
} |
| 661 |
|
| 662 |
mPointerView.setVisibility( |
| 663 |
horizontalShift > mPointerWidth ? View.INVISIBLE : View.VISIBLE); |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
public void setManageButtonAlpha(float alpha) { |
| 671 |
mManageButton.setAlpha(alpha); |
| 672 |
} |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
public void setManageButtonTranslationY(float translationY) { |
| 678 |
mManageButton.setTranslationY(translationY); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
public void setTopClip(int clip) { |
| 685 |
mTopClip = clip; |
| 686 |
onContainerClipUpdate(); |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
public void setBottomClip(int clip) { |
| 693 |
mBottomClip = clip; |
| 694 |
onContainerClipUpdate(); |
| 695 |
} |
| 696 |
|
| 697 |
private void onContainerClipUpdate() { |
| 698 |
if (mTopClip == 0 && mBottomClip == 0) { |
| 699 |
if (mIsClipping) { |
| 700 |
mIsClipping = false; |
| 701 |
if (mTaskView != null) { |
| 702 |
mTaskView.setClipBounds(null); |
| 703 |
mTaskView.setEnableSurfaceClipping(false); |
| 704 |
} |
| 705 |
mExpandedViewContainer.invalidateOutline(); |
| 706 |
} |
| 707 |
} else { |
| 708 |
if (!mIsClipping) { |
| 709 |
mIsClipping = true; |
| 710 |
if (mTaskView != null) { |
| 711 |
mTaskView.setEnableSurfaceClipping(true); |
| 712 |
} |
| 713 |
} |
| 714 |
mExpandedViewContainer.invalidateOutline(); |
| 715 |
if (mTaskView != null) { |
| 716 |
mTaskView.setClipBounds(new Rect(0, mTopClip, mTaskView.getWidth(), |
| 717 |
mTaskView.getHeight() - mBottomClip)); |
| 718 |
} |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
public void movePointerBy(float x, float y) { |
| 726 |
mPointerView.setTranslationX(mPointerPos.x + x); |
| 727 |
mPointerView.setTranslationY(mPointerPos.y + y); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
public void setContentVisibility(boolean visibility) { |
| 739 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 740 |
Log.d(TAG, "setContentVisibility: visibility=" + visibility |
| 741 |
+ " bubble=" + getBubbleKey()); |
| 742 |
} |
| 743 |
mIsContentVisible = visibility; |
| 744 |
if (mTaskView != null && !mIsAnimating) { |
| 745 |
mTaskView.setAlpha(visibility ? 1f : 0f); |
| 746 |
mPointerView.setAlpha(visibility ? 1f : 0f); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 750 |
@Nullable |
| 751 |
TaskView getTaskView() { |
| 752 |
return mTaskView; |
| 753 |
} |
| 754 |
|
| 755 |
@VisibleForTesting |
| 756 |
public BubbleOverflowContainerView getOverflow() { |
| 757 |
return mOverflowView; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
public int getContentHeight() { |
| 768 |
if (mIsOverflow) { |
| 769 |
return mOverflowView.getHeight() - mTopClip - mBottomClip; |
| 770 |
} |
| 771 |
if (mTaskView != null) { |
| 772 |
return mTaskView.getHeight() - mTopClip - mBottomClip; |
| 773 |
} |
| 774 |
return 0; |
| 775 |
} |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
public int getContentBottomOnScreen() { |
| 783 |
Rect out = new Rect(); |
| 784 |
if (mIsOverflow) { |
| 785 |
mOverflowView.getBoundsOnScreen(out); |
| 786 |
} |
| 787 |
if (mTaskView != null) { |
| 788 |
mTaskView.getBoundsOnScreen(out); |
| 789 |
} |
| 790 |
return out.bottom; |
| 791 |
} |
| 792 |
|
| 793 |
int getTaskId() { |
| 794 |
return mTaskId; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
void update(Bubble bubble) { |
| 801 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 802 |
Log.d(TAG, "update: bubble=" + bubble); |
| 803 |
} |
| 804 |
if (mStackView == null) { |
| 805 |
Log.w(TAG, "Stack is null for bubble: " + bubble); |
| 806 |
return; |
| 807 |
} |
| 808 |
boolean isNew = mBubble == null || didBackingContentChange(bubble); |
| 809 |
if (isNew || bubble != null && bubble.getKey().equals(mBubble.getKey())) { |
| 810 |
mBubble = bubble; |
| 811 |
mManageButton.setContentDescription(getResources().getString( |
| 812 |
R.string.bubbles_settings_button_description, bubble.getAppName())); |
| 813 |
mManageButton.setAccessibilityDelegate( |
| 814 |
new AccessibilityDelegate() { |
| 815 |
@Override |
| 816 |
public void onInitializeAccessibilityNodeInfo(View host, |
| 817 |
AccessibilityNodeInfo info) { |
| 818 |
super.onInitializeAccessibilityNodeInfo(host, info); |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
mStackView.setupLocalMenu(info); |
| 823 |
} |
| 824 |
}); |
| 825 |
|
| 826 |
if (isNew) { |
| 827 |
mPendingIntent = mBubble.getBubbleIntent(); |
| 828 |
if ((mPendingIntent != null || mBubble.hasMetadataShortcutId()) |
| 829 |
&& mTaskView != null) { |
| 830 |
setContentVisibility(false); |
| 831 |
mTaskView.setVisibility(VISIBLE); |
| 832 |
} |
| 833 |
} |
| 834 |
applyThemeAttrs(); |
| 835 |
} else { |
| 836 |
Log.w(TAG, "Trying to update entry with different key, new bubble: " |
| 837 |
+ bubble.getKey() + " old bubble: " + bubble.getKey()); |
| 838 |
} |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
private boolean didBackingContentChange(Bubble newBubble) { |
| 853 |
boolean prevWasIntentBased = mBubble != null && mPendingIntent != null; |
| 854 |
boolean newIsIntentBased = newBubble.getBubbleIntent() != null; |
| 855 |
return prevWasIntentBased != newIsIntentBased; |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
public boolean isUsingMaxHeight() { |
| 862 |
return mUsingMaxHeight; |
| 863 |
} |
| 864 |
|
| 865 |
void updateHeight() { |
| 866 |
if (mExpandedViewContainerLocation == null) { |
| 867 |
return; |
| 868 |
} |
| 869 |
|
| 870 |
if ((mBubble != null && mTaskView != null) || mIsOverflow) { |
| 871 |
float desiredHeight = mPositioner.getExpandedViewHeight(mBubble); |
| 872 |
int maxHeight = mPositioner.getMaxExpandedViewHeight(mIsOverflow); |
| 873 |
float height = desiredHeight == MAX_HEIGHT |
| 874 |
? maxHeight |
| 875 |
: Math.min(desiredHeight, maxHeight); |
| 876 |
mUsingMaxHeight = height == maxHeight; |
| 877 |
FrameLayout.LayoutParams lp = mIsOverflow |
| 878 |
? (FrameLayout.LayoutParams) mOverflowView.getLayoutParams() |
| 879 |
: (FrameLayout.LayoutParams) mTaskView.getLayoutParams(); |
| 880 |
mNeedsNewHeight = lp.height != height; |
| 881 |
if (!mImeVisible) { |
| 882 |
|
| 883 |
|
| 884 |
lp.height = (int) height; |
| 885 |
if (mIsOverflow) { |
| 886 |
mOverflowView.setLayoutParams(lp); |
| 887 |
} else { |
| 888 |
mTaskView.setLayoutParams(lp); |
| 889 |
} |
| 890 |
mNeedsNewHeight = false; |
| 891 |
} |
| 892 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 893 |
Log.d(TAG, "updateHeight: bubble=" + getBubbleKey() |
| 894 |
+ " height=" + height |
| 895 |
+ " mNeedsNewHeight=" + mNeedsNewHeight); |
| 896 |
} |
| 897 |
} |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
public void updateView(int[] containerLocationOnScreen) { |
| 908 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 909 |
Log.d(TAG, "updateView: bubble=" |
| 910 |
+ getBubbleKey()); |
| 911 |
} |
| 912 |
mExpandedViewContainerLocation = containerLocationOnScreen; |
| 913 |
updateHeight(); |
| 914 |
if (mTaskView != null |
| 915 |
&& mTaskView.getVisibility() == VISIBLE |
| 916 |
&& mTaskView.isAttachedToWindow()) { |
| 917 |
mTaskView.onLocationChanged(); |
| 918 |
} |
| 919 |
if (mIsOverflow) { |
| 920 |
post(() -> { |
| 921 |
mOverflowView.show(); |
| 922 |
}); |
| 923 |
} |
| 924 |
} |
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
public void setPointerPosition(float bubblePosition, boolean onLeft, boolean animate) { |
| 941 |
final boolean isRtl = mContext.getResources().getConfiguration().getLayoutDirection() |
| 942 |
== LAYOUT_DIRECTION_RTL; |
| 943 |
|
| 944 |
final boolean showVertically = mPositioner.showBubblesVertically(); |
| 945 |
final float paddingLeft = (showVertically && onLeft) |
| 946 |
? mPointerHeight - mPointerOverlap |
| 947 |
: 0; |
| 948 |
final float paddingRight = (showVertically && !onLeft) |
| 949 |
? mPointerHeight - mPointerOverlap |
| 950 |
: 0; |
| 951 |
final float paddingTop = showVertically |
| 952 |
? 0 |
| 953 |
: mPointerHeight - mPointerOverlap; |
| 954 |
setPadding((int) paddingLeft, (int) paddingTop, (int) paddingRight, 0); |
| 955 |
|
| 956 |
|
| 957 |
float pointerPosition = mPositioner.getPointerPosition(bubblePosition); |
| 958 |
final float bubbleCenter = mPositioner.showBubblesVertically() |
| 959 |
? pointerPosition - mPositioner.getExpandedViewY(mBubble, bubblePosition) |
| 960 |
: pointerPosition; |
| 961 |
|
| 962 |
post(() -> { |
| 963 |
mCurrentPointer = showVertically ? onLeft ? mLeftPointer : mRightPointer : mTopPointer; |
| 964 |
updatePointerView(); |
| 965 |
if (showVertically) { |
| 966 |
mPointerPos.y = bubbleCenter - (mPointerWidth / 2f); |
| 967 |
if (!isRtl) { |
| 968 |
mPointerPos.x = onLeft |
| 969 |
? -mPointerHeight + mPointerOverlap |
| 970 |
: getWidth() - mPaddingRight - mPointerOverlap; |
| 971 |
} else { |
| 972 |
mPointerPos.x = onLeft |
| 973 |
? -(getWidth() - mPaddingLeft - mPointerOverlap) |
| 974 |
: mPointerHeight - mPointerOverlap; |
| 975 |
} |
| 976 |
} else { |
| 977 |
mPointerPos.y = mPointerOverlap; |
| 978 |
if (!isRtl) { |
| 979 |
mPointerPos.x = bubbleCenter - (mPointerWidth / 2f); |
| 980 |
} else { |
| 981 |
mPointerPos.x = -(getWidth() - mPaddingLeft - bubbleCenter) |
| 982 |
+ (mPointerWidth / 2f); |
| 983 |
} |
| 984 |
} |
| 985 |
if (animate) { |
| 986 |
mPointerView.animate().translationX(mPointerPos.x).translationY( |
| 987 |
mPointerPos.y).start(); |
| 988 |
} else { |
| 989 |
mPointerView.setTranslationY(mPointerPos.y); |
| 990 |
mPointerView.setTranslationX(mPointerPos.x); |
| 991 |
mPointerView.setVisibility(VISIBLE); |
| 992 |
} |
| 993 |
}); |
| 994 |
} |
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
public boolean isShowingLeftPointer() { |
| 1000 |
return mCurrentPointer == mLeftPointer; |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
public boolean isShowingRightPointer() { |
| 1007 |
return mCurrentPointer == mRightPointer; |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
public int getPointerWidth() { |
| 1014 |
return mPointerWidth; |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
public void getManageButtonBoundsOnScreen(Rect rect) { |
| 1022 |
mManageButton.getBoundsOnScreen(rect); |
| 1023 |
} |
| 1024 |
|
| 1025 |
public int getManageButtonMargin() { |
| 1026 |
return ((LinearLayout.LayoutParams) mManageButton.getLayoutParams()).getMarginStart(); |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
public void cleanUpExpandedState() { |
| 1035 |
if (DEBUG_BUBBLE_EXPANDED_VIEW) { |
| 1036 |
Log.d(TAG, "cleanUpExpandedState: bubble=" + getBubbleKey() + " task=" + mTaskId); |
| 1037 |
} |
| 1038 |
if (getTaskId() != INVALID_TASK_ID) { |
| 1039 |
try { |
| 1040 |
ActivityTaskManager.getService().removeTask(getTaskId()); |
| 1041 |
} catch (RemoteException e) { |
| 1042 |
Log.w(TAG, e.getMessage()); |
| 1043 |
} |
| 1044 |
} |
| 1045 |
if (mTaskView != null) { |
| 1046 |
mTaskView.release(); |
| 1047 |
removeView(mTaskView); |
| 1048 |
mTaskView = null; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
public void dump(@NonNull PrintWriter pw) { |
| 1056 |
pw.print("BubbleExpandedView"); |
| 1057 |
pw.print(" taskId: "); pw.println(mTaskId); |
| 1058 |
pw.print(" stackView: "); pw.println(mStackView); |
| 1059 |
} |
| 1060 |
} |