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

Commit 807e8611 authored by Colin Cross's avatar Colin Cross
Browse files

Use if instead of switch for resources

Converting to Soong will move some code from directly compiled
into the app to compiled into an Android library and then
shared between the app and the tests.  This will cause resource
IDs in the library to become non-final, which means they can
no longer be used in case statements.  Convert affect case
statements to if blocks.

Test: m RunSettingsRoboTests
Change-Id: I25742a374f06d3fa4decbfc0d223a350acc50881
parent 90cb5628
Loading
Loading
Loading
Loading
+16 −21
Original line number Diff line number Diff line
@@ -197,8 +197,7 @@ public class ToggleAccessibilityServicePreferenceFragment

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.permission_enable_allow_button:
        if (view.getId() == R.id.permission_enable_allow_button) {
            if (isFullDiskEncrypted()) {
                String title = createConfirmCredentialReasonMessage();
                Intent intent = ConfirmDeviceCredentialActivity.createIntent(title, null);
@@ -207,17 +206,13 @@ public class ToggleAccessibilityServicePreferenceFragment
            } else {
                handleConfirmServiceEnabled(true);
            }
                break;
            case R.id.permission_enable_deny_button:
        } else if (view.getId() == R.id.permission_enable_deny_button) {
            handleConfirmServiceEnabled(false);
                break;
            case R.id.permission_disable_stop_button:
        } else if (view.getId() == R.id.permission_disable_stop_button) {
            handleConfirmServiceEnabled(false);
                break;
            case R.id.permission_disable_cancel_button:
        } else if (view.getId() == R.id.permission_disable_cancel_button) {
            handleConfirmServiceEnabled(true);
                break;
            default:
        } else {
            throw new IllegalArgumentException();
        }
        mDialog.dismiss();
+45 −55
Original line number Diff line number Diff line
@@ -690,22 +690,18 @@ public class ManageApplications extends InstrumentedFragment
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int menuId = item.getItemId();
        switch (item.getItemId()) {
            case R.id.sort_order_alpha:
            case R.id.sort_order_size:
        int i = item.getItemId();
        if (i == R.id.sort_order_alpha || i == R.id.sort_order_size) {
            if (mApplications != null) {
                mApplications.rebuild(menuId);
            }
                break;
            case R.id.show_system:
            case R.id.hide_system:
        } else if (i == R.id.show_system || i == R.id.hide_system) {
            mShowSystem = !mShowSystem;
            mApplications.rebuild();
                break;
            case R.id.reset_app_preferences:
        } else if (i == R.id.reset_app_preferences) {
            mResetAppsHelper.buildResetDialog();
            return true;
            case R.id.advanced:
        } else if (i == R.id.advanced) {
            if (mListType == LIST_TYPE_NOTIFICATION) {
                new SubSettingLauncher(getContext())
                        .setDestination(ConfigureNotificationSettings.class.getName())
@@ -719,8 +715,7 @@ public class ManageApplications extends InstrumentedFragment
                startActivityForResult(intent, ADVANCED_SETTINGS);
            }
            return true;
            default:
                // Handle the home button
        } else {// Handle the home button
            return false;
        }
        updateOptionsMenu();
@@ -1133,8 +1128,7 @@ public class ManageApplications extends InstrumentedFragment
                            ApplicationsState.FILTER_DOWNLOADED_AND_LAUNCHER);
                }
            }
            switch (mLastSortMode) {
                case R.id.sort_order_size:
            if (mLastSortMode == R.id.sort_order_size) {
                switch (mWhichSize) {
                    case SIZE_INTERNAL:
                        comparatorObj = ApplicationsState.INTERNAL_SIZE_COMPARATOR;
@@ -1146,16 +1140,12 @@ public class ManageApplications extends InstrumentedFragment
                        comparatorObj = ApplicationsState.SIZE_COMPARATOR;
                        break;
                }
                    break;
                case R.id.sort_order_recent_notification:
            } else if (mLastSortMode == R.id.sort_order_recent_notification) {
                comparatorObj = AppStateNotificationBridge.RECENT_NOTIFICATION_COMPARATOR;
                    break;
                case R.id.sort_order_frequent_notification:
            } else if (mLastSortMode == R.id.sort_order_frequent_notification) {
                comparatorObj = AppStateNotificationBridge.FREQUENCY_NOTIFICATION_COMPARATOR;
                    break;
                default:
            } else {
                comparatorObj = ApplicationsState.ALPHA_COMPARATOR;
                    break;
            }

            filterObj = new CompoundFilter(filterObj, ApplicationsState.FILTER_NOT_HIDE);
+129 −154
Original line number Diff line number Diff line
@@ -424,14 +424,14 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
    public boolean onOptionsItemSelected(MenuItem item) {
        final Context context = getActivity();
        final Bundle args = new Bundle();
        switch (item.getItemId()) {
            case R.id.storage_rename:
        int i = item.getItemId();
        if (i == R.id.storage_rename) {
            RenameFragment.show(this, mVolume);
            return true;
            case R.id.storage_mount:
        } else if (i == R.id.storage_mount) {
            new MountTask(context, mVolume).execute();
            return true;
            case R.id.storage_unmount:
        } else if (i == R.id.storage_unmount) {
            args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
            new SubSettingLauncher(context)
                    .setDestination(PrivateVolumeUnmount.class.getCanonicalName())
@@ -440,7 +440,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
                    .setArguments(args)
                    .launch();
            return true;
            case R.id.storage_format:
        } else if (i == R.id.storage_format) {
            args.putString(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
            new SubSettingLauncher(context)
                    .setDestination(PrivateVolumeFormat.class.getCanonicalName())
@@ -449,12 +449,12 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
                    .setArguments(args)
                    .launch();
            return true;
            case R.id.storage_migrate:
        } else if (i == R.id.storage_migrate) {
            final Intent intent = new Intent(context, StorageWizardMigrateConfirm.class);
            intent.putExtra(VolumeInfo.EXTRA_VOLUME_ID, mVolume.getId());
            startActivity(intent);
            return true;
            case R.id.storage_free:
        } else if (i == R.id.storage_free) {
            final Intent deletion_helper_intent =
                    new Intent(StorageManager.ACTION_MANAGE_STORAGE);
            startActivity(deletion_helper_intent);
@@ -476,8 +476,7 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
            itemTitleId = 0;
        }
        Intent intent = null;
        switch (itemTitleId) {
            case R.string.storage_detail_apps: {
        if (itemTitleId == R.string.storage_detail_apps) {
            Bundle args = new Bundle();
            args.putString(ManageApplications.EXTRA_CLASSNAME,
                    StorageUseActivity.class.getName());
@@ -492,41 +491,28 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
                    .setTitleRes(R.string.apps_storage)
                    .setSourceMetricsCategory(getMetricsCategory())
                    .toIntent();

            } break;
            case R.string.storage_detail_images: {
        } else if (itemTitleId == R.string.storage_detail_images) {
            intent = getIntentForStorage(AUTHORITY_MEDIA, "images_root");
            } break;
            case R.string.storage_detail_videos: {
        } else if (itemTitleId == R.string.storage_detail_videos) {
            intent = getIntentForStorage(AUTHORITY_MEDIA, "videos_root");
            } break;
            case R.string.storage_detail_audio: {
        } else if (itemTitleId == R.string.storage_detail_audio) {
            intent = getIntentForStorage(AUTHORITY_MEDIA, "audio_root");
            } break;
            case R.string.storage_detail_system: {
        } else if (itemTitleId == R.string.storage_detail_system) {
            SystemInfoFragment.show(this);
            return true;

            }
            case R.string.storage_detail_other: {
        } else if (itemTitleId == R.string.storage_detail_other) {
            OtherInfoFragment.show(this, mStorageManager.getBestVolumeDescription(mVolume),
                    mSharedVolume, userId);
            return true;

            }
            case R.string.storage_detail_cached: {
        } else if (itemTitleId == R.string.storage_detail_cached) {
            ConfirmClearCacheFragment.show(this);
            return true;

            }
            case R.string.storage_menu_explore: {
        } else if (itemTitleId == R.string.storage_menu_explore) {
            intent = mSharedVolume.buildBrowseIntent();
            } break;
            case 0: {
        } else if (itemTitleId == 0) {
            UserInfoFragment.show(this, pref.getTitle(), pref.getSummary());
            return true;
        }
        }

        if (intent != null) {
            intent.putExtra(Intent.EXTRA_USER_ID, userId);
@@ -569,36 +555,32 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
            } catch (NumberFormatException e) {
                itemTitleId = 0;
            }
            switch (itemTitleId) {
                case R.string.storage_detail_system: {
            // Cannot display 'Other' until all known items are accounted for.
            if (itemTitleId == R.string.storage_detail_system) {
                updatePreference(item, mSystemSize);
                accountedSize += mSystemSize;
                if (LOGV) Log.v(TAG, "mSystemSize: " + mSystemSize
                        + " accountedSize: " + accountedSize);
                } break;
                case R.string.storage_detail_apps: {
            } else if (itemTitleId == R.string.storage_detail_apps) {
                updatePreference(item, details.appsSize.get(userId));
                accountedSize += details.appsSize.get(userId);
                if (LOGV) Log.v(TAG, "appsSize: " + details.appsSize.get(userId)
                        + " accountedSize: " + accountedSize);
                } break;
                case R.string.storage_detail_images: {
            } else if (itemTitleId == R.string.storage_detail_images) {
                final long imagesSize = totalValues(details, userId,
                        Environment.DIRECTORY_DCIM, Environment.DIRECTORY_PICTURES);
                updatePreference(item, imagesSize);
                accountedSize += imagesSize;
                if (LOGV) Log.v(TAG, "imagesSize: " + imagesSize
                        + " accountedSize: " + accountedSize);
                } break;
                case R.string.storage_detail_videos: {
            } else if (itemTitleId == R.string.storage_detail_videos) {
                final long videosSize = totalValues(details, userId,
                        Environment.DIRECTORY_MOVIES);
                updatePreference(item, videosSize);
                accountedSize += videosSize;
                if (LOGV) Log.v(TAG, "videosSize: " + videosSize
                        + " accountedSize: " + accountedSize);
                } break;
                case R.string.storage_detail_audio: {
            } else if (itemTitleId == R.string.storage_detail_audio) {
                final long audioSize = totalValues(details, userId,
                        Environment.DIRECTORY_MUSIC,
                        Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS,
@@ -607,37 +589,30 @@ public class PrivateVolumeSettings extends SettingsPreferenceFragment {
                accountedSize += audioSize;
                if (LOGV) Log.v(TAG, "audioSize: " + audioSize
                        + " accountedSize: " + accountedSize);
                } break;
                case R.string.storage_detail_other: {
            } else if (itemTitleId == R.string.storage_detail_other) {
                final long downloadsSize = totalValues(details, userId,
                        Environment.DIRECTORY_DOWNLOADS);
                final long miscSize = details.miscSize.get(userId);
                totalDownloadsSize += downloadsSize;
                totalMiscSize += miscSize;
                accountedSize += miscSize + downloadsSize;

                if (LOGV)
                    Log.v(TAG, "miscSize for " + userId + ": " + miscSize + "(total: "
                            + totalMiscSize + ") \ndownloadsSize: " + downloadsSize + "(total: "
                            + totalDownloadsSize + ") accountedSize: " + accountedSize);

                    // Cannot display 'Other' until all known items are accounted for.
                otherItem = item;
                } break;
                case R.string.storage_detail_cached: {
            } else if (itemTitleId == R.string.storage_detail_cached) {
                updatePreference(item, details.cacheSize);
                accountedSize += details.cacheSize;
                if (LOGV)
                    Log.v(TAG, "cacheSize: " + details.cacheSize + " accountedSize: "
                            + accountedSize);
                } break;
                case 0: {
            } else if (itemTitleId == 0) {
                final long userSize = details.usersSize.get(userId);
                updatePreference(item, userSize);
                accountedSize += userSize;
                if (LOGV) Log.v(TAG, "userSize: " + userSize
                        + " accountedSize: " + accountedSize);
                } break;
            }
        }
        if (otherItem != null) {
+4 −6
Original line number Diff line number Diff line
@@ -105,13 +105,11 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
                @Override
                public int getSpanSize(int position) {
                    final int viewType = mContextualCards.get(position).getViewType();
                    switch (viewType) {
                        case ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH:
                        case SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH:
                    if (viewType == ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH
                            || viewType == SliceContextualCardRenderer.VIEW_TYPE_HALF_WIDTH) {
                        return HALF_WIDTH;
                        default:
                            return FULL_WIDTH;
                    }
                    return FULL_WIDTH;
                }
            });
        }
+17 −25
Original line number Diff line number Diff line
@@ -84,14 +84,12 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life

    @Override
    public RecyclerView.ViewHolder createViewHolder(View view, @LayoutRes int viewType) {
        switch (viewType) {
            case VIEW_TYPE_DEFERRED_SETUP:
        if (viewType == VIEW_TYPE_DEFERRED_SETUP) {
            return mDeferredSetupCardHelper.createViewHolder(view);
            case VIEW_TYPE_HALF_WIDTH:
        } else if (viewType == VIEW_TYPE_HALF_WIDTH) {
            return mHalfCardHelper.createViewHolder(view);
            default:
                return mFullCardHelper.createViewHolder(view);
        }
        return mFullCardHelper.createViewHolder(view);
    }

    @Override
@@ -132,14 +130,11 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life
                return;
            }

            switch (holder.getItemViewType()) {
                case VIEW_TYPE_DEFERRED_SETUP:
            if (holder.getItemViewType() == VIEW_TYPE_DEFERRED_SETUP) {
                mDeferredSetupCardHelper.bindView(holder, card, slice);
                    break;
                case VIEW_TYPE_HALF_WIDTH:
            } else if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
                mHalfCardHelper.bindView(holder, card, slice);
                    break;
                default:
            } else {
                mFullCardHelper.bindView(holder, card, slice);
            }
            if (swipeBackground != null) {
@@ -147,14 +142,11 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life
            }
        });

        switch (holder.getItemViewType()) {
            case VIEW_TYPE_DEFERRED_SETUP:
                // Deferred setup is never dismissible.
                break;
            case VIEW_TYPE_HALF_WIDTH:
        if (holder.getItemViewType()
                == VIEW_TYPE_DEFERRED_SETUP) {// Deferred setup is never dismissible.
        } else if (holder.getItemViewType() == VIEW_TYPE_HALF_WIDTH) {
            initDismissalActions(holder, card);
                break;
            default:
        } else {
            initDismissalActions(holder, card);
        }

Loading