1 /* 2 * Copyright (C) 2019 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.settingslib.widget; 18 19 import android.graphics.drawable.Drawable; 20 import android.view.View; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 25 /** 26 * AppEntityInfo is responsible for storing app information shown in {@link R.xml.app_view.xml}. 27 */ 28 public class AppEntityInfo { 29 30 private final Drawable mIcon; 31 private final CharSequence mTitle; 32 private final CharSequence mSummary; 33 private final View.OnClickListener mClickListener; 34 35 /** 36 * Gets the drawable for the icon of app entity. 37 * 38 * @return the drawable for the icon of app entity. 39 */ getIcon()40 public Drawable getIcon() { 41 return mIcon; 42 } 43 44 /** 45 * Gets the text for the title of app enitity. 46 * 47 * @return the text for the title of app enitity. 48 */ getTitle()49 public CharSequence getTitle() { 50 return mTitle; 51 } 52 53 /** 54 * Gets the text for the summary of app enitity. 55 * 56 * @return the text for the summary of app enitity. 57 */ getSummary()58 public CharSequence getSummary() { 59 return mSummary; 60 } 61 62 /** 63 * Gets the click listener for the app entity view. 64 * 65 * @return click listener for the app entity view. 66 */ getClickListener()67 public View.OnClickListener getClickListener() { 68 return mClickListener; 69 } 70 AppEntityInfo(Builder builder)71 private AppEntityInfo(Builder builder) { 72 mIcon = builder.mIcon; 73 mTitle = builder.mTitle; 74 mSummary = builder.mSummary; 75 mClickListener = builder.mClickListener; 76 } 77 78 /** 79 * Builder class for {@link AppEntityInfo} 80 */ 81 public static class Builder { 82 83 private Drawable mIcon; 84 private CharSequence mTitle; 85 private CharSequence mSummary; 86 private View.OnClickListener mClickListener; 87 88 /** 89 * Creates an instance of a {@link AppEntityInfo} based on the current builder settings. 90 * 91 * @return The {@link AppEntityInfo}. 92 */ build()93 public AppEntityInfo build() { 94 return new AppEntityInfo(this); 95 } 96 97 /** 98 * Sets the drawable for the icon. 99 */ setIcon(@onNull Drawable icon)100 public Builder setIcon(@NonNull Drawable icon) { 101 mIcon = icon; 102 return this; 103 } 104 105 /** 106 * Sets the text for the title. 107 */ setTitle(@ullable CharSequence title)108 public Builder setTitle(@Nullable CharSequence title) { 109 mTitle = title; 110 return this; 111 } 112 113 /** 114 * Sets the text for the summary. 115 */ setSummary(@ullable CharSequence summary)116 public Builder setSummary(@Nullable CharSequence summary) { 117 mSummary = summary; 118 return this; 119 } 120 121 /** 122 * Sets the click listener for app entity view. 123 */ setOnClickListener(@ullable View.OnClickListener clickListener)124 public Builder setOnClickListener(@Nullable View.OnClickListener clickListener) { 125 mClickListener = clickListener; 126 return this; 127 } 128 } 129 } 130