Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
| 17 | package com.android.systemui.bubbles; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | import android.widget.FrameLayout; |
| 23 | import android.widget.ImageView; |
| 24 | |
| 25 | import com.android.systemui.R; |
| 26 | |
| 27 | /** |
| 28 | * Menu which allows users to take actions on bubbles, ex. screenshots. |
| 29 | */ |
| 30 | public class BubbleMenuView extends FrameLayout { |
| 31 | private FrameLayout mMenu; |
| 32 | private boolean mShowing = false; |
| 33 | |
Aran Ink | 141a815 | 2019-12-12 13:31:23 -0500 | [diff] [blame] | 34 | /** Delay before taking a screenshot once the button is tapped to allow the menu time to hide.*/ |
| 35 | public static final long SCREENSHOT_DELAY = 200; |
| 36 | |
Aran Ink | aa4dfa7 | 2019-11-18 16:49:07 -0500 | [diff] [blame] | 37 | public BubbleMenuView(Context context, AttributeSet attrs) { |
| 38 | super(context, attrs); |
| 39 | } |
| 40 | |
| 41 | public BubbleMenuView(Context context) { |
| 42 | super(context); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | protected void onFinishInflate() { |
| 47 | super.onFinishInflate(); |
| 48 | mMenu = findViewById(R.id.bubble_menu_view); |
| 49 | ImageView icon = findViewById(com.android.internal.R.id.icon); |
| 50 | icon.setImageDrawable(mContext.getDrawable(com.android.internal.R.drawable.ic_screenshot)); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the bubble menu view. |
| 55 | */ |
| 56 | public View getMenuView() { |
| 57 | return mMenu; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Checks whether the bubble menu is currently displayed. |
| 62 | */ |
| 63 | public boolean isShowing() { |
| 64 | return mShowing; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Show the bubble menu at the specified position on the screen. |
| 69 | */ |
| 70 | public void show(float x, float y) { |
| 71 | mShowing = true; |
| 72 | this.setVisibility(VISIBLE); |
| 73 | mMenu.setTranslationX(x); |
| 74 | mMenu.setTranslationY(y); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Hide the bubble menu. |
| 79 | */ |
| 80 | public void hide() { |
| 81 | mShowing = false; |
| 82 | this.setVisibility(GONE); |
| 83 | } |
| 84 | } |