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.util.Log; 24 import android.view.View; 25 import android.widget.Button; 26 import android.widget.LinearLayout; 27 import android.widget.TextView; 28 29 import com.android.launcher3.R; 30 import com.android.launcher3.model.StringCache; 31 import com.android.launcher3.views.ActivityContext; 32 33 /** 34 * Work profile toggle switch shown at the bottom of AllApps work tab 35 */ 36 public class WorkPausedCard extends LinearLayout implements View.OnClickListener { 37 38 private static final String TAG = "WorkPausedCard"; 39 private final ActivityContext mActivityContext; 40 private Button mBtn; 41 WorkPausedCard(Context context)42 public WorkPausedCard(Context context) { 43 this(context, null, 0); 44 } 45 WorkPausedCard(Context context, AttributeSet attrs)46 public WorkPausedCard(Context context, AttributeSet attrs) { 47 this(context, attrs, 0); 48 } 49 WorkPausedCard(Context context, AttributeSet attrs, int defStyleAttr)50 public WorkPausedCard(Context context, AttributeSet attrs, int defStyleAttr) { 51 super(context, attrs, defStyleAttr); 52 mActivityContext = ActivityContext.lookupContext(getContext()); 53 } 54 55 @Override onFinishInflate()56 protected void onFinishInflate() { 57 super.onFinishInflate(); 58 mBtn = findViewById(R.id.enable_work_apps); 59 mBtn.setOnClickListener(this); 60 61 updateStringFromCache(); 62 } 63 updateStringFromCache()64 public void updateStringFromCache() { 65 StringCache cache = mActivityContext.getStringCache(); 66 if (cache != null) { 67 setWorkProfilePausedResources(cache); 68 } 69 } 70 setWorkProfilePausedResources(StringCache cache)71 private void setWorkProfilePausedResources(StringCache cache) { 72 TextView title = findViewById(R.id.work_apps_paused_title); 73 title.setText(cache.workProfilePausedTitle); 74 75 TextView body = findViewById(R.id.work_apps_paused_content); 76 body.setText(cache.workProfilePausedDescription); 77 78 TextView button = findViewById(R.id.enable_work_apps); 79 button.setText(cache.workProfileEnableButton); 80 } 81 82 @Override onClick(View view)83 public void onClick(View view) { 84 Log.d(TAG, "WorkPausedCard clicked."); 85 mActivityContext.getAppsView().getWorkManager().setWorkProfileEnabled(true); 86 mActivityContext.getStatsLogManager().logger().log(LAUNCHER_TURN_ON_WORK_APPS_TAP); 87 } 88 89 @Override onLayout(boolean changed, int l, int t, int r, int b)90 protected void onLayout(boolean changed, int l, int t, int r, int b) { 91 int orientation = getResources().getConfiguration().orientation; 92 getLayoutParams().height = orientation == Configuration.ORIENTATION_PORTRAIT 93 ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT; 94 super.onLayout(changed, l, t, r, b); 95 } 96 } 97