1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { Action } from './Action'; 17import { ActionBarColorMode, ActionBarMode, ActionBarSelectionMode } from './ActionBarMode'; 18 19// ActionBarProp 20export class ActionBarProp { 21 public static NORMAL_BACKGROUND_COLOR: Resource = $r('app.color.default_background_color'); 22 public static TRANSPARENT_BACKGROUND_COLOR: Resource = $r('app.color.transparent'); 23 public static NORMAL_TEXT_COLOR: Resource = $r('sys.color.ohos_id_color_titlebar_text'); 24 public static NORMAL_SUBTITLE_TEXT_COLOR: Resource = $r('sys.color.ohos_id_color_titlebar_subtitle_text'); 25 public static ICON_COLOR: Resource = $r('sys.color.ohos_id_color_primary'); 26 public static TRANSPARENT_TEXT_COLOR: Resource = $r('app.color.title_text_color_on_transparent_bg'); 27 public static TRANSPARENT_SUBTITLE_TEXT_COLOR: Resource = $r('app.color.subtitle_text_color_on_transparent_bg'); 28 public static HEAD_TITLE_TEXT_SIZE: Resource = $r('sys.float.ohos_id_text_size_headline6'); 29 public static HEAD_TITLE_ONE_LINE_TEXT_SIZE: Resource = $r('sys.float.ohos_id_text_size_headline7'); 30 public static TITLE_TEXT_SIZE: Resource = $r('sys.float.ohos_id_text_size_headline8'); 31 public static TITLE_FONT_WEIGHT = 500; 32 public static SUBTITLE_TEXT_SIZE: Resource = $r('sys.float.ohos_id_text_size_body2'); 33 public static MEDIUM_FONT: Resource = $r('app.string.id_text_font_family_medium'); 34 public static REGULAR_FONT: Resource = $r('app.string.id_text_font_family_regular'); 35 public static SINGLE_UNSELECT_TITLE: Resource = $r('app.string.title_select_photos'); 36 public static SINGLE_SELECT_ALBUM_TITLE: Resource = $r('app.string.title_select_album'); 37 public static SINGLE_TAB_ALBUM_TITLE: Resource = $r('app.string.tab_albums'); 38 public static MULTI_UNSELECT_TITLE: Resource = $r('app.string.title_none_selected'); 39 public static PHOTO_BROWSER_ACTIONBAR_ALPHA = 0.95; 40 private hasTabBar = false; 41 private leftAction = Action.NONE; 42 private isHeadTitle = false; 43 private title: Resource | string = null; 44 private subTitle: Resource | string = null; 45 private menuList: Action[] = []; 46 private backgroundColorResource: Resource = ActionBarProp.NORMAL_BACKGROUND_COLOR; 47 private alpha = 1; 48 private selectionMode: ActionBarSelectionMode = ActionBarSelectionMode.MULTI; 49 private colorMode: ActionBarColorMode = ActionBarColorMode.NORMAL; 50 private mode: ActionBarMode = ActionBarMode.STANDARD_MODE; 51 private maxSelectCount = 0; 52 private isNeedTitle: boolean = true; 53 54 constructor() { 55 } 56 57 public static getCountDetailSelectedTitle(count: number): Resource { 58 return $r('app.plural.count_details_selected', count, count); 59 } 60 61 /** 62 * External selection quantity display 63 * @param count The selected quantity, same as the current count above 64 * @param maxSelectCount Maximum number of options 65 */ 66 public static getCountDetailExternalSelectedTitle(count: number, maxSelectCount: number): Resource { 67 return $r('app.string.count_details_external_selected', count, maxSelectCount); 68 } 69 70 public setHasTabBar(hasTabBar: boolean): ActionBarProp { 71 this.hasTabBar = hasTabBar; 72 return this; 73 } 74 75 public getHasTabBar(): boolean { 76 return this.hasTabBar; 77 } 78 79 public setLeftAction(leftAction: Action): ActionBarProp { 80 this.leftAction = leftAction; 81 return this; 82 } 83 84 public getLeftAction(): Action { 85 return this.leftAction; 86 } 87 88 public setIsHeadTitle(isHeadTitle: boolean): ActionBarProp { 89 this.isHeadTitle = isHeadTitle; 90 return this; 91 } 92 93 public getIsHeadTitle(): boolean { 94 return this.isHeadTitle; 95 } 96 97 public setTitle(title: Resource | string): ActionBarProp { 98 this.title = title; 99 return this; 100 } 101 102 public getTitle(): Resource | string { 103 return this.title; 104 } 105 106 public setSubTitle(subTitle: Resource | string): ActionBarProp { 107 this.subTitle = subTitle; 108 return this; 109 } 110 111 public getSubTitle(): Resource | string { 112 return this.subTitle; 113 } 114 115 public setMenuList(menuList: Action[]): ActionBarProp { 116 this.menuList = menuList; 117 return this; 118 } 119 120 public getMenuList(): Action[] { 121 return this.menuList; 122 } 123 124 public setBackgroundColor(backgroundColorResource: Resource): ActionBarProp { 125 this.backgroundColorResource = backgroundColorResource; 126 return this; 127 } 128 129 public getBackgroundColor(): Resource { 130 return this.colorMode == ActionBarColorMode.TRANSPARENT 131 ? ActionBarProp.TRANSPARENT_BACKGROUND_COLOR : this.backgroundColorResource; 132 } 133 134 public setAlpha(alpha: number): ActionBarProp { 135 this.alpha = alpha; 136 return this; 137 } 138 139 public getAlpha(): number { 140 return this.alpha; 141 } 142 143 public setMode(mode: ActionBarMode): ActionBarProp { 144 this.mode = mode; 145 return this; 146 } 147 148 public getMode(): ActionBarMode { 149 return this.mode; 150 } 151 152 public setColorMode(colorMode: ActionBarColorMode): ActionBarProp { 153 this.colorMode = colorMode; 154 return this; 155 } 156 157 public getColorMode(): ActionBarColorMode { 158 return this.colorMode; 159 } 160 161 public setSelectionMode(selectionMode: ActionBarSelectionMode): ActionBarProp { 162 this.selectionMode = selectionMode; 163 return this; 164 } 165 166 public getSelectionMode(): ActionBarSelectionMode { 167 return this.selectionMode; 168 } 169 170 public setMaxSelectCount(maxSelectCount: number): ActionBarProp { 171 this.maxSelectCount = maxSelectCount; 172 return this; 173 } 174 175 public getMaxSelectCount(): number { 176 return this.maxSelectCount; 177 } 178 179 public setIsNeedTitle(isNeedTitle: boolean): ActionBarProp { 180 this.isNeedTitle = isNeedTitle; 181 return this; 182 } 183 184 public getIsNeedTitle(): boolean { 185 return this.isNeedTitle; 186 } 187}