1 /* 2 * Copyright (C) 2020 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.screenshot; 18 19 import android.annotation.ColorInt; 20 import android.app.PendingIntent; 21 import android.content.Context; 22 import android.graphics.drawable.Icon; 23 import android.util.AttributeSet; 24 import android.util.Log; 25 import android.widget.FrameLayout; 26 import android.widget.ImageView; 27 import android.widget.TextView; 28 29 import com.android.systemui.R; 30 31 /** 32 * View for a chip with an icon and text. 33 */ 34 public class ScreenshotActionChip extends FrameLayout { 35 36 private static final String TAG = "ScreenshotActionChip"; 37 38 private ImageView mIcon; 39 private TextView mText; 40 private @ColorInt int mIconColor; 41 ScreenshotActionChip(Context context)42 public ScreenshotActionChip(Context context) { 43 this(context, null); 44 } 45 ScreenshotActionChip(Context context, AttributeSet attrs)46 public ScreenshotActionChip(Context context, AttributeSet attrs) { 47 this(context, attrs, 0); 48 } 49 ScreenshotActionChip(Context context, AttributeSet attrs, int defStyleAttr)50 public ScreenshotActionChip(Context context, AttributeSet attrs, int defStyleAttr) { 51 this(context, attrs, defStyleAttr, 0); 52 } 53 ScreenshotActionChip( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)54 public ScreenshotActionChip( 55 Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 56 super(context, attrs, defStyleAttr, defStyleRes); 57 58 mIconColor = context.getColor(R.color.global_screenshot_button_icon); 59 } 60 61 @Override onFinishInflate()62 protected void onFinishInflate() { 63 mIcon = findViewById(R.id.screenshot_action_chip_icon); 64 mText = findViewById(R.id.screenshot_action_chip_text); 65 } 66 setIcon(Icon icon, boolean tint)67 void setIcon(Icon icon, boolean tint) { 68 mIcon.setImageIcon(icon); 69 if (!tint) { 70 mIcon.setImageTintList(null); 71 } 72 } 73 setText(CharSequence text)74 void setText(CharSequence text) { 75 mText.setText(text); 76 } 77 setPendingIntent(PendingIntent intent, Runnable finisher)78 void setPendingIntent(PendingIntent intent, Runnable finisher) { 79 setOnClickListener(v -> { 80 try { 81 intent.send(); 82 finisher.run(); 83 } catch (PendingIntent.CanceledException e) { 84 Log.e(TAG, "Intent cancelled", e); 85 } 86 }); 87 } 88 } 89