OSDN Git Service

a321cc69088453698c92e89bae83ef845e933160
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / util / FABWrapper.java
1 /* Copyright 2019 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.content.Context;
19 import android.support.design.widget.FloatingActionButton;
20 import android.support.v4.content.ContextCompat;
21 import android.view.View;
22 import android.widget.ImageView;
23
24 import com.farmerbb.taskbar.BuildConfig;
25 import com.farmerbb.taskbar.R;
26
27 public class FABWrapper {
28     public View view;
29
30     public FABWrapper(Context context) {
31         view = !context.getPackageName().equals(BuildConfig.ANDROIDX86_APPLICATION_ID)
32                 ? new ImageView(context)
33                 : new FloatingActionButton(context);
34
35         if(view instanceof ImageView) {
36             view.setBackground(ContextCompat.getDrawable(context, R.drawable.tb_circle));
37
38             int padding = context.getResources().getDimensionPixelSize(R.dimen.tb_fake_fab_padding);
39             view.setPadding(padding, padding, padding, padding);
40         }
41     }
42
43     public void setImageResource(int resource) {
44         if(view instanceof FloatingActionButton)
45             ((FloatingActionButton) view).setImageResource(resource);
46         else if(view instanceof ImageView)
47             ((ImageView) view).setImageResource(resource);
48     }
49
50     public void show() {
51         if(view instanceof FloatingActionButton)
52             ((FloatingActionButton) view).show();
53         else if(view instanceof ImageView)
54             view.setVisibility(View.VISIBLE);
55     }
56
57     public void hide() {
58         if(view instanceof FloatingActionButton)
59             ((FloatingActionButton) view).hide();
60         else if(view instanceof ImageView)
61             view.setVisibility(View.GONE);
62     }
63 }