Search in sources :

Example 1 with WorkModeSwitch

use of com.android.launcher3.allapps.WorkModeSwitch in project android_packages_apps_Launcher3 by crdroidandroid.

the class WorkTabTest method toggleWorks.

@Ignore("b/182844465")
@Test
public void toggleWorks() {
    mDevice.pressHome();
    waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
    executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
    waitForState("Launcher internal state didn't switch to All Apps", () -> ALL_APPS);
    getOnceNotNull("Apps view did not bind", launcher -> launcher.getAppsView().getWorkModeSwitch(), 60000);
    UserManager userManager = getFromLauncher(l -> l.getSystemService(UserManager.class));
    assertEquals(2, userManager.getUserProfiles().size());
    UserHandle workProfile = getFromLauncher(l -> {
        UserHandle myHandle = Process.myUserHandle();
        List<UserHandle> userProfiles = userManager.getUserProfiles();
        return userProfiles.get(0) == myHandle ? userProfiles.get(1) : userProfiles.get(0);
    });
    waitForLauncherCondition("work profile can't be turned off", l -> userManager.requestQuietModeEnabled(true, workProfile));
    assertTrue(userManager.isQuietModeEnabled(workProfile));
    executeOnLauncher(launcher -> {
        WorkModeSwitch wf = launcher.getAppsView().getWorkModeSwitch();
        ((AllAppsPagedView) launcher.getAppsView().getContentView()).snapToPageImmediately(AllAppsContainerView.AdapterHolder.WORK);
        wf.toggle();
    });
    waitForLauncherCondition("Work toggle did not work", l -> l.getSystemService(UserManager.class).isQuietModeEnabled(workProfile));
}
Also used : UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Objects(java.util.Objects) WorkModeSwitch(com.android.launcher3.allapps.WorkModeSwitch) AllAppsPagedView(com.android.launcher3.allapps.AllAppsPagedView) Ignore(org.junit.Ignore) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 2 with WorkModeSwitch

use of com.android.launcher3.allapps.WorkModeSwitch in project Neo-Launcher by NeoApplications.

the class AllAppsGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    switch(holder.getItemViewType()) {
        case VIEW_TYPE_ICON:
            AppInfo info = mApps.getAdapterItems().get(position).appInfo;
            BubbleTextView icon = (BubbleTextView) holder.itemView;
            icon.reset();
            icon.applyFromApplicationInfo(info);
            break;
        case VIEW_TYPE_EMPTY_SEARCH:
            TextView emptyViewText = (TextView) holder.itemView;
            emptyViewText.setText(mEmptySearchMessage);
            emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL);
            break;
        case VIEW_TYPE_SEARCH_MARKET:
            TextView searchView = (TextView) holder.itemView;
            if (mMarketSearchIntent != null) {
                searchView.setVisibility(View.VISIBLE);
            } else {
                searchView.setVisibility(View.GONE);
            }
            break;
        case VIEW_TYPE_ALL_APPS_DIVIDER:
            // nothing to do
            break;
        case VIEW_TYPE_WORK_TAB_FOOTER:
            WorkModeSwitch workModeToggle = holder.itemView.findViewById(R.id.work_mode_toggle);
            workModeToggle.refresh();
            TextView managedByLabel = holder.itemView.findViewById(R.id.managed_by_label);
            boolean anyProfileQuietModeEnabled = UserManagerCompat.getInstance(managedByLabel.getContext()).isAnyProfileQuietModeEnabled();
            managedByLabel.setText(anyProfileQuietModeEnabled ? R.string.work_mode_off_label : R.string.work_mode_on_label);
            break;
        case VIEW_TYPE_FOLDER:
            ViewGroup container = (ViewGroup) holder.itemView;
            FolderIcon folderIcon = mApps.getAdapterItems().get(position).folderItem.getFolderIcon(mLauncher, container);
            container.removeAllViews();
            container.addView(folderIcon);
            folderIcon.verifyHighRes();
            break;
        case VIEW_TYPE_SEARCH_SUGGESTION:
            int color = getDrawerTextColor();
            ViewGroup group = (ViewGroup) holder.itemView;
            TextView textView = group.findViewById(R.id.suggestion);
            String suggestion = mApps.getAdapterItems().get(position).suggestion;
            textView.setText(suggestion);
            textView.setTextColor(color);
            ((ImageView) group.findViewById(android.R.id.icon)).getDrawable().setTint(color);
            group.setOnClickListener(v -> {
                SearchProvider provider = getSearchProvider();
                if (provider instanceof WebSearchProvider) {
                    ((WebSearchProvider) provider).openResults(suggestion);
                }
            });
            break;
    }
    if (mBindViewCallback != null) {
        mBindViewCallback.onBindView(holder);
    }
}
Also used : WebSearchProvider(com.saggitt.omega.search.webproviders.WebSearchProvider) ViewGroup(android.view.ViewGroup) FolderIcon(com.android.launcher3.folder.FolderIcon) BubbleTextView(com.android.launcher3.BubbleTextView) TextView(android.widget.TextView) WebSearchProvider(com.saggitt.omega.search.webproviders.WebSearchProvider) SearchProvider(com.saggitt.omega.search.SearchProvider) BubbleTextView(com.android.launcher3.BubbleTextView) AppInfo(com.android.launcher3.AppInfo)

Example 3 with WorkModeSwitch

use of com.android.launcher3.allapps.WorkModeSwitch in project android_packages_apps_Trebuchet by LineageOS.

the class WorkTabTest method toggleWorks.

@Test
public void toggleWorks() {
    mDevice.pressHome();
    waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
    executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS));
    waitForState("Launcher internal state didn't switch to All Apps", () -> ALL_APPS);
    getOnceNotNull("Apps view did not bind", launcher -> launcher.getAppsView().getWorkModeSwitch(), 60000);
    UserManager userManager = getFromLauncher(l -> l.getSystemService(UserManager.class));
    assertEquals(2, userManager.getUserProfiles().size());
    UserHandle workProfile = getFromLauncher(l -> {
        UserHandle myHandle = Process.myUserHandle();
        List<UserHandle> userProfiles = userManager.getUserProfiles();
        return userProfiles.get(0) == myHandle ? userProfiles.get(1) : userProfiles.get(0);
    });
    waitForLauncherCondition("work profile can't be turned off", l -> userManager.requestQuietModeEnabled(true, workProfile));
    assertTrue(userManager.isQuietModeEnabled(workProfile));
    executeOnLauncher(launcher -> {
        WorkModeSwitch wf = launcher.getAppsView().getWorkModeSwitch();
        ((AllAppsPagedView) launcher.getAppsView().getContentView()).snapToPageImmediately(AllAppsContainerView.AdapterHolder.WORK);
        wf.toggle();
    });
    waitForLauncherCondition("Work toggle did not work", l -> l.getSystemService(UserManager.class).isQuietModeEnabled(workProfile));
}
Also used : UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) Objects(java.util.Objects) WorkModeSwitch(com.android.launcher3.allapps.WorkModeSwitch) AllAppsPagedView(com.android.launcher3.allapps.AllAppsPagedView) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

UserHandle (android.os.UserHandle)2 UserManager (android.os.UserManager)2 LargeTest (androidx.test.filters.LargeTest)2 AllAppsPagedView (com.android.launcher3.allapps.AllAppsPagedView)2 WorkModeSwitch (com.android.launcher3.allapps.WorkModeSwitch)2 Objects (java.util.Objects)2 Test (org.junit.Test)2 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 AppInfo (com.android.launcher3.AppInfo)1 BubbleTextView (com.android.launcher3.BubbleTextView)1 FolderIcon (com.android.launcher3.folder.FolderIcon)1 SearchProvider (com.saggitt.omega.search.SearchProvider)1 WebSearchProvider (com.saggitt.omega.search.webproviders.WebSearchProvider)1 Ignore (org.junit.Ignore)1