• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.launcher3.allapps;
17 
18 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_ON_WORK_APPS_TAP;
19 import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
20 
21 import android.content.Context;
22 import android.content.res.Configuration;
23 import android.util.AttributeSet;
24 import android.view.View;
25 import android.widget.Button;
26 import android.widget.LinearLayout;
27 
28 import com.android.launcher3.Launcher;
29 import com.android.launcher3.R;
30 import com.android.launcher3.Utilities;
31 
32 /**
33  * Work profile toggle switch shown at the bottom of AllApps work tab
34  */
35 public class WorkPausedCard extends LinearLayout implements View.OnClickListener {
36 
37     private final Launcher mLauncher;
38     private Button mBtn;
39 
WorkPausedCard(Context context)40     public WorkPausedCard(Context context) {
41         this(context, null, 0);
42     }
43 
WorkPausedCard(Context context, AttributeSet attrs)44     public WorkPausedCard(Context context, AttributeSet attrs) {
45         this(context, attrs, 0);
46     }
47 
WorkPausedCard(Context context, AttributeSet attrs, int defStyleAttr)48     public WorkPausedCard(Context context, AttributeSet attrs, int defStyleAttr) {
49         super(context, attrs, defStyleAttr);
50         mLauncher = Launcher.getLauncher(getContext());
51     }
52 
53 
54     @Override
onFinishInflate()55     protected void onFinishInflate() {
56         super.onFinishInflate();
57         mBtn = findViewById(R.id.enable_work_apps);
58         mBtn.setOnClickListener(this);
59     }
60 
61     @Override
onClick(View view)62     public void onClick(View view) {
63         if (Utilities.ATLEAST_P) {
64             setEnabled(false);
65             mLauncher.getStatsLogManager().logger().log(LAUNCHER_TURN_ON_WORK_APPS_TAP);
66             UI_HELPER_EXECUTOR.post(() -> WorkModeSwitch.setWorkProfileEnabled(getContext(), true));
67         }
68     }
69 
70     @Override
onLayout(boolean changed, int l, int t, int r, int b)71     protected void onLayout(boolean changed, int l, int t, int r, int b) {
72         int orientation = getResources().getConfiguration().orientation;
73         getLayoutParams().height = orientation == Configuration.ORIENTATION_PORTRAIT
74                 ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
75         super.onLayout(changed, l, t, r, b);
76     }
77 }
78