1 /* 2 * Copyright (C) 2021 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.providers.media.photopicker.util; 18 19 import android.annotation.IntDef; 20 21 import java.lang.annotation.Retention; 22 import java.lang.annotation.RetentionPolicy; 23 24 /** 25 * Utility class for various layout modes that PhotoPicker supports. 26 */ 27 public class LayoutModeUtils { 28 29 public static final Mode MODE_PHOTOS_TAB = Mode.of(Mode.MODE_PHOTOS_TAB); 30 public static final Mode MODE_ALBUMS_TAB = Mode.of(Mode.MODE_ALBUMS_TAB); 31 public static final Mode MODE_ALBUM_PHOTOS_TAB = Mode.of(Mode.MODE_ALBUM_PHOTOS_TAB); 32 public static final Mode MODE_PREVIEW = Mode.of(Mode.MODE_PREVIEW); 33 34 35 public static class Mode { 36 public boolean isPhotosTabOrAlbumsTab; 37 public boolean isPreview; 38 @IntDef(prefix = { "MODE_" }, value = { 39 MODE_PHOTOS_TAB, 40 MODE_ALBUMS_TAB, 41 MODE_ALBUM_PHOTOS_TAB, 42 MODE_PREVIEW, 43 }) 44 @Retention(RetentionPolicy.SOURCE) 45 public @interface ModeType {} 46 47 public static final int MODE_PHOTOS_TAB = 1; 48 public static final int MODE_ALBUMS_TAB = 2; 49 public static final int MODE_ALBUM_PHOTOS_TAB = 3; 50 public static final int MODE_PREVIEW = 4; 51 of(@ode.ModeType int modeType)52 public static Mode of(@Mode.ModeType int modeType) { 53 Mode mode = new Mode(); 54 switch(modeType) { 55 case MODE_PHOTOS_TAB: 56 case MODE_ALBUMS_TAB: 57 mode.isPhotosTabOrAlbumsTab = true; 58 mode.isPreview = false; 59 break; 60 case MODE_ALBUM_PHOTOS_TAB: 61 mode.isPhotosTabOrAlbumsTab = false; 62 mode.isPreview = false; 63 break; 64 case MODE_PREVIEW: 65 mode.isPhotosTabOrAlbumsTab = false; 66 mode.isPreview = true; 67 break; 68 default: 69 } 70 return mode; 71 } 72 } 73 } 74