Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6b65956a authored by Brandon Dayauon's avatar Brandon Dayauon Committed by Android (Google) Code Review
Browse files

Merge "Make PrivateSpaceSettingsButton instead of having just the imageView." into main

parents 97157614 736527a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@
        android:gravity="center_vertical"
        android:layout_alignParentEnd="true"
        android:animateLayoutChanges="false">
        <ImageButton
        <com.android.launcher3.allapps.PrivateSpaceSettingsButton
            android:id="@+id/ps_settings_button"
            android:layout_width="@dimen/ps_header_image_height"
            android:layout_height="@dimen/ps_header_image_height"
+2 −33
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static com.android.launcher3.anim.AnimatorListeners.forEndCallback;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_LOCK_ANIMATION_BEGIN;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_LOCK_ANIMATION_END;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_LOCK_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_UNLOCK_ANIMATION_BEGIN;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_UNLOCK_ANIMATION_END;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_UNLOCK_TAP;
@@ -52,7 +51,6 @@ import android.os.UserHandle;
import android.os.UserManager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
@@ -229,30 +227,6 @@ public class PrivateProfileManager extends UserProfileManager {
        resetPrivateSpaceDecorator(updatedState);
    }

    /**
     * Opens the Private Space Settings Page.
     *
     * @param view the view that was clicked to open the settings page and which will be the same
     *             view to animate back. Otherwise if there is no view, simply start the activity.
     */
    public void openPrivateSpaceSettings(View view) {
        if (mPrivateSpaceSettingsAvailable) {
            Context context = mAllApps.getContext();
            Intent intent = ApiWrapper.INSTANCE.get(context).getPrivateSpaceSettingsIntent();
            if (view == null) {
                context.startActivity(intent);
                return;
            }
            ActivityContext activityContext = ActivityContext.lookupContext(context);
            AppInfo itemInfo = new AppInfo();
            itemInfo.id = CONTAINER_PRIVATESPACE;
            itemInfo.componentName = intent.getComponent();
            itemInfo.container = CONTAINER_PRIVATESPACE;
            view.setTag(itemInfo);
            activityContext.startActivitySafely(view, intent, itemInfo);
        }
    }

    /** Returns whether or not Private Space Settings Page is available. */
    public boolean isPrivateSpaceSettingsAvailable() {
        return mPrivateSpaceSettingsAvailable;
@@ -385,7 +359,7 @@ public class PrivateProfileManager extends UserProfileManager {
        updateHeaderOnClickListener(mPSHeader);

        //Add image and action for private space settings button
        ImageButton settingsButton = mPSHeader.findViewById(R.id.ps_settings_button);
        PrivateSpaceSettingsButton settingsButton = mPSHeader.findViewById(R.id.ps_settings_button);
        assert settingsButton != null;
        updatePrivateSpaceSettingsButton(settingsButton);

@@ -439,15 +413,10 @@ public class PrivateProfileManager extends UserProfileManager {
        setQuietMode(lock);
    }

    private void updatePrivateSpaceSettingsButton(ImageButton settingsButton) {
    private void updatePrivateSpaceSettingsButton(PrivateSpaceSettingsButton settingsButton) {
        if (getCurrentState() == STATE_ENABLED
                && isPrivateSpaceSettingsAvailable()) {
            settingsButton.setVisibility(VISIBLE);
            settingsButton.setOnClickListener(
                    view -> {
                        logEvents(LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP);
                        openPrivateSpaceSettings(view);
                    });
        } else {
            settingsButton.setVisibility(GONE);
        }
+81 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.allapps;

import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PRIVATESPACE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;

import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.util.ApiWrapper;
import com.android.launcher3.views.ActivityContext;

public class PrivateSpaceSettingsButton extends ImageButton implements View.OnClickListener {

    private final ActivityContext mActivityContext;
    private final StatsLogManager mStatsLogManager;
    private final Intent mPrivateSpaceSettingsIntent;

    public PrivateSpaceSettingsButton(Context context) {
        this(context, null, 0);
    }

    public PrivateSpaceSettingsButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public PrivateSpaceSettingsButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mActivityContext = ActivityContext.lookupContext(context);
        mStatsLogManager = mActivityContext.getStatsLogManager();
        mPrivateSpaceSettingsIntent =
                ApiWrapper.INSTANCE.get(context).getPrivateSpaceSettingsIntent();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        mStatsLogManager.logger().log(LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP);
        AppInfo privateSpaceSettingsItemInfo = createPrivateSpaceSettingsAppInfo();
        view.setTag(privateSpaceSettingsItemInfo);
        mActivityContext.startActivitySafely(
                view,
                mPrivateSpaceSettingsIntent,
                privateSpaceSettingsItemInfo);
    }

    AppInfo createPrivateSpaceSettingsAppInfo() {
        AppInfo itemInfo = new AppInfo();
        itemInfo.id = CONTAINER_PRIVATESPACE;
        if (mPrivateSpaceSettingsIntent != null) {
            itemInfo.componentName = mPrivateSpaceSettingsIntent.getComponent();
        }
        itemInfo.container = CONTAINER_PRIVATESPACE;
        return itemInfo;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ public class PrivateProfileManagerTest {
        ArgumentCaptor<Intent> acIntent = ArgumentCaptor.forClass(Intent.class);
        mPrivateProfileManager.setPrivateSpaceSettingsAvailable(true);

        mPrivateProfileManager.openPrivateSpaceSettings(null);
        mContext.startActivity(expectedIntent);

        Mockito.verify(mContext).startActivity(acIntent.capture());
        assertEquals("Intent Action is different",
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.allapps;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;

import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PRIVATESPACE;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;

import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.util.ActivityContextWrapper;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;

@RunWith(AndroidJUnit4.class)
public class PrivateSpaceSettingsButtonTest {

    private PrivateSpaceSettingsButton mVut;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        Context context = new ActivityContextWrapper(getApplicationContext());
        mVut = new PrivateSpaceSettingsButton(context);
    }

    @Test
    public void privateSpaceSettingsAppInfo_hasCorrectIdAndContainer() {
        AppInfo appInfo = mVut.createPrivateSpaceSettingsAppInfo();

        assertThat(appInfo.id).isEqualTo(CONTAINER_PRIVATESPACE);
        assertThat(appInfo.container).isEqualTo(CONTAINER_PRIVATESPACE);
    }
}