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