1 /* 2 * Copyright (C) 2024 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 17 package com.android.launcher3.allapps; 18 19 import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PRIVATESPACE; 20 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP; 21 22 import android.content.Context; 23 import android.content.Intent; 24 import android.util.AttributeSet; 25 import android.view.View; 26 import android.widget.ImageButton; 27 28 import com.android.launcher3.logging.StatsLogManager; 29 import com.android.launcher3.model.data.AppInfo; 30 import com.android.launcher3.util.ApiWrapper; 31 import com.android.launcher3.views.ActivityContext; 32 33 public class PrivateSpaceSettingsButton extends ImageButton implements View.OnClickListener { 34 35 private final ActivityContext mActivityContext; 36 private final StatsLogManager mStatsLogManager; 37 private final Intent mPrivateSpaceSettingsIntent; 38 PrivateSpaceSettingsButton(Context context)39 public PrivateSpaceSettingsButton(Context context) { 40 this(context, null, 0); 41 } 42 PrivateSpaceSettingsButton(Context context, AttributeSet attrs)43 public PrivateSpaceSettingsButton(Context context, AttributeSet attrs) { 44 this(context, attrs, 0); 45 } 46 PrivateSpaceSettingsButton(Context context, AttributeSet attrs, int defStyleAttr)47 public PrivateSpaceSettingsButton(Context context, AttributeSet attrs, int defStyleAttr) { 48 super(context, attrs, defStyleAttr); 49 mActivityContext = ActivityContext.lookupContext(context); 50 mStatsLogManager = mActivityContext.getStatsLogManager(); 51 mPrivateSpaceSettingsIntent = 52 ApiWrapper.INSTANCE.get(context).getPrivateSpaceSettingsIntent(); 53 } 54 55 @Override onFinishInflate()56 protected void onFinishInflate() { 57 super.onFinishInflate(); 58 setOnClickListener(this); 59 } 60 61 @Override onClick(View view)62 public void onClick(View view) { 63 mStatsLogManager.logger().log(LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP); 64 AppInfo privateSpaceSettingsItemInfo = createPrivateSpaceSettingsAppInfo(); 65 view.setTag(privateSpaceSettingsItemInfo); 66 mActivityContext.startActivitySafely( 67 view, 68 mPrivateSpaceSettingsIntent, 69 privateSpaceSettingsItemInfo); 70 } 71 createPrivateSpaceSettingsAppInfo()72 AppInfo createPrivateSpaceSettingsAppInfo() { 73 AppInfo itemInfo = new AppInfo(); 74 itemInfo.id = CONTAINER_PRIVATESPACE; 75 if (mPrivateSpaceSettingsIntent != null) { 76 itemInfo.componentName = mPrivateSpaceSettingsIntent.getComponent(); 77 } 78 itemInfo.container = CONTAINER_PRIVATESPACE; 79 return itemInfo; 80 } 81 } 82