OSDN Git Service

Fix secondary display toast placement on Android 11
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / util / ToastFrameworkImpl.java
1 /* Copyright 2017 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.util;
17
18 import android.annotation.SuppressLint;
19 import android.content.Context;
20 import android.view.Gravity;
21 import android.widget.Toast;
22
23 import com.farmerbb.taskbar.R;
24
25 class ToastFrameworkImpl implements ToastInterface {
26     private Toast toast;
27
28     @SuppressLint("ShowToast")
29     ToastFrameworkImpl(Context context, String message, int length) {
30         int offset = context.getResources().getDimensionPixelSize(R.dimen.tb_toast_y_offset);
31         if(U.getCurrentApiVersion() > 29.0 && U.isDesktopModeActive(context)) {
32             offset = offset + U.getNavbarHeight(context);
33         }
34
35         toast = Toast.makeText(context, message, length);
36         toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, offset);
37     }
38
39     @Override
40     public void show() {
41         toast.show();
42     }
43
44     @Override
45     public void cancel() {
46         toast.cancel();
47     }
48 }