1 /*
2  * Copyright (C) 2022 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.clipboardoverlay;
18 
19 import android.content.Context;
20 import android.widget.Toast;
21 
22 import com.android.systemui.res.R;
23 
24 import javax.inject.Inject;
25 
26 /**
27  * Utility class for showing a simple clipboard toast on copy.
28  */
29 class ClipboardToast extends Toast.Callback {
30     private final Context mContext;
31     private Toast mCopiedToast;
32 
33     @Inject
ClipboardToast(Context context)34     ClipboardToast(Context context) {
35         mContext = context;
36     }
37 
showCopiedToast()38     void showCopiedToast() {
39         if (mCopiedToast != null) {
40             mCopiedToast.cancel();
41         }
42         mCopiedToast = Toast.makeText(mContext,
43                 R.string.clipboard_overlay_text_copied, Toast.LENGTH_SHORT);
44         mCopiedToast.addCallback(this);
45         mCopiedToast.show();
46     }
47 
isShowing()48     boolean isShowing() {
49         return mCopiedToast != null;
50     }
51 
52     @Override // Toast.Callback
onToastHidden()53     public void onToastHidden() {
54         super.onToastHidden();
55         mCopiedToast = null;
56     }
57 }
58