1 /* 2 * Copyright (C) 2023 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 package com.android.launcher3.allapps; 17 18 import android.content.Context; 19 import android.os.Bundle; 20 21 import androidx.annotation.NonNull; 22 23 public class SectionDecorationInfo { 24 25 public static final int ROUND_NOTHING = 0; 26 public static final int ROUND_TOP_LEFT = 1 << 1; 27 public static final int ROUND_TOP_RIGHT = 1 << 2; 28 public static final int ROUND_BOTTOM_LEFT = 1 << 3; 29 public static final int ROUND_BOTTOM_RIGHT = 1 << 4; 30 public static final int DECORATOR_ALPHA = 255; 31 32 protected boolean mShouldDecorateItemsTogether; 33 private SectionDecorationHandler mDecorationHandler; 34 protected boolean mIsTopRound; 35 protected boolean mIsBottomRound; 36 SectionDecorationInfo(Context context, int roundRegions, boolean decorateTogether)37 public SectionDecorationInfo(Context context, int roundRegions, boolean decorateTogether) { 38 mDecorationHandler = 39 new SectionDecorationHandler(context, DECORATOR_ALPHA, 40 isFlagEnabled(roundRegions, ROUND_TOP_LEFT), 41 isFlagEnabled(roundRegions, ROUND_TOP_RIGHT), 42 isFlagEnabled(roundRegions, ROUND_BOTTOM_LEFT), 43 isFlagEnabled(roundRegions, ROUND_BOTTOM_RIGHT)); 44 mShouldDecorateItemsTogether = decorateTogether; 45 mIsTopRound = isFlagEnabled(roundRegions, ROUND_TOP_LEFT) && 46 isFlagEnabled(roundRegions, ROUND_TOP_RIGHT); 47 mIsBottomRound = isFlagEnabled(roundRegions, ROUND_BOTTOM_LEFT) && 48 isFlagEnabled(roundRegions, ROUND_BOTTOM_RIGHT); 49 } 50 SectionDecorationInfo(Context context, @NonNull Bundle target, String targetLayoutType, @NonNull Bundle prevTarget, @NonNull Bundle nextTarget)51 public SectionDecorationInfo(Context context, @NonNull Bundle target, 52 String targetLayoutType, @NonNull Bundle prevTarget, @NonNull Bundle nextTarget) {} 53 getDecorationHandler()54 public SectionDecorationHandler getDecorationHandler() { 55 return mDecorationHandler; 56 } 57 isFlagEnabled(int canonicalFlag, int comparison)58 private boolean isFlagEnabled(int canonicalFlag, int comparison) { 59 return (canonicalFlag & comparison) != 0; 60 } 61 62 /** 63 * Returns whether multiple {@link SectionDecorationInfo}s with the same sectionId should 64 * be grouped together. 65 */ shouldDecorateItemsTogether()66 public boolean shouldDecorateItemsTogether() { 67 return mShouldDecorateItemsTogether; 68 } 69 isTopRound()70 public boolean isTopRound() { 71 return mIsTopRound; 72 } 73 isBottomRound()74 public boolean isBottomRound() { 75 return mIsBottomRound; 76 } 77 } 78