| /* |
| * Copyright (C) 2019 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.systemui.bubbles; |
| |
| import android.content.Context; |
| import android.util.AttributeSet; |
| import android.view.View; |
| import android.widget.FrameLayout; |
| import android.widget.ImageView; |
| |
| import com.android.systemui.R; |
| |
| /** |
| * Menu which allows users to take actions on bubbles, ex. screenshots. |
| */ |
| public class BubbleMenuView extends FrameLayout { |
| private FrameLayout mMenu; |
| private boolean mShowing = false; |
| |
| /** Delay before taking a screenshot once the button is tapped to allow the menu time to hide.*/ |
| public static final long SCREENSHOT_DELAY = 200; |
| |
| public BubbleMenuView(Context context, AttributeSet attrs) { |
| super(context, attrs); |
| } |
| |
| public BubbleMenuView(Context context) { |
| super(context); |
| } |
| |
| @Override |
| protected void onFinishInflate() { |
| super.onFinishInflate(); |
| mMenu = findViewById(R.id.bubble_menu_view); |
| ImageView icon = findViewById(com.android.internal.R.id.icon); |
| icon.setImageDrawable(mContext.getDrawable(com.android.internal.R.drawable.ic_screenshot)); |
| } |
| |
| /** |
| * Get the bubble menu view. |
| */ |
| public View getMenuView() { |
| return mMenu; |
| } |
| |
| /** |
| * Checks whether the bubble menu is currently displayed. |
| */ |
| public boolean isShowing() { |
| return mShowing; |
| } |
| |
| /** |
| * Show the bubble menu at the specified position on the screen. |
| */ |
| public void show(float x, float y) { |
| mShowing = true; |
| this.setVisibility(VISIBLE); |
| mMenu.setTranslationX(x); |
| mMenu.setTranslationY(y); |
| } |
| |
| /** |
| * Hide the bubble menu. |
| */ |
| public void hide() { |
| mShowing = false; |
| this.setVisibility(GONE); |
| } |
| } |