1 /* 2 * Copyright (C) 2015 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 android.car.app.menu; 17 18 import android.content.Context; 19 import android.graphics.Bitmap; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.widget.EditText; 23 24 /** 25 * A base class for a car ui entry which is used for loading and manipulating common car 26 * app decor window (CarUi). 27 * 28 * A CarUi provider provides essential ui elements that a car app may want to use. The CarUi is 29 * loaded by apps at runtime, similar to a shared library, but via reflection through a class that 30 * extends {@link android.car.app.menu.CarUiEntry} from a separate apk 31 * called CarUiProvider. Depending on the different platforms, the CarUiProvider may 32 * be different and can be customized by different car makers. However, it is required that a 33 * set of basic ui elements and functionalities exist in the CarUiProvider. This class defines 34 * the set of must have functions in a CarUiProvider. 35 */ 36 public abstract class CarUiEntry { 37 protected final Context mAppContext; 38 protected final Context mUiLibContext; 39 CarUiEntry(Context uiLibContext, Context appContext)40 public CarUiEntry(Context uiLibContext, Context appContext) { 41 mUiLibContext = uiLibContext.createConfigurationContext( 42 appContext.getResources().getConfiguration()); 43 mAppContext = appContext; 44 } 45 46 /** 47 * Return the content view. 48 */ getContentView()49 abstract public View getContentView(); 50 51 /** 52 * Set {@link android.car.app.menu.CarMenuCallbacks} from a car app for car menu interactions. 53 */ setCarMenuCallbacks(CarMenuCallbacks callbacks)54 abstract public void setCarMenuCallbacks(CarMenuCallbacks callbacks); 55 56 /** 57 * Return the id of the main container in which app can render its own content. 58 */ getFragmentContainerId()59 abstract public int getFragmentContainerId(); 60 61 /** 62 * Set the background bitmap. 63 */ setBackground(Bitmap bitmap)64 abstract public void setBackground(Bitmap bitmap); 65 66 /** 67 * Replace the menu button with the given bitmap. 68 */ setMenuButtonBitmap(Bitmap bitmap)69 abstract public void setMenuButtonBitmap(Bitmap bitmap); 70 71 /** 72 * Hide the menu button. 73 */ hideMenuButton()74 abstract public void hideMenuButton(); 75 76 /** 77 * Restore the menu button. 78 */ restoreMenuDrawable()79 abstract public void restoreMenuDrawable(); 80 81 /** 82 * Set the color of the car menu scrim. 83 */ setScrimColor(int color)84 abstract public void setScrimColor(int color); 85 86 /** 87 * Set the title of the car menu. 88 */ setTitle(CharSequence title)89 abstract public void setTitle(CharSequence title); 90 91 /** 92 * Close the car menu. 93 */ closeDrawer()94 abstract public void closeDrawer(); 95 96 /** 97 * Open the car menu. 98 */ openDrawer()99 abstract public void openDrawer(); 100 101 /** 102 * Show the menu associated with the specified id, and set the car menu title. 103 */ showMenu(String id, String title)104 abstract public void showMenu(String id, String title); 105 106 /** 107 * Set the car menu button color. 108 */ setMenuButtonColor(int color)109 abstract public void setMenuButtonColor(int color); 110 111 /** 112 * Make the menu title visible. 113 */ showTitle()114 abstract public void showTitle(); 115 116 /** 117 * Hide the menu title. 118 */ hideTitle()119 abstract public void hideTitle(); 120 121 /** 122 * Use the light car theme. 123 */ setLightMode()124 abstract public void setLightMode(); 125 126 /** 127 * Use the dark car theme. 128 */ setDarkMode()129 abstract public void setDarkMode(); 130 131 /** 132 * Use automatic light/dark car theme based on ui mode. 133 */ setAutoLightDarkMode()134 abstract public void setAutoLightDarkMode(); 135 136 /** 137 * Called when the activity's onRestoreInstanceState is called. 138 */ onRestoreInstanceState(Bundle savedInstanceState)139 abstract public void onRestoreInstanceState(Bundle savedInstanceState); 140 141 /** 142 * Called when the activity's onSaveInstanceState is called. 143 */ onSaveInstanceState(Bundle outState)144 abstract public void onSaveInstanceState(Bundle outState); 145 146 /** 147 * Show the search box and set the click listener for the search box. 148 */ showSearchBox(View.OnClickListener listener)149 abstract public void showSearchBox(View.OnClickListener listener); 150 151 /** 152 * Set the color of the search box. 153 */ setSearchBoxColors(int backgroundColor, int searchLogoColor, int textColor, int hintTextColor)154 abstract public void setSearchBoxColors(int backgroundColor, int searchLogoColor, 155 int textColor, int hintTextColor); 156 157 /** 158 * Set the search box edit listener for monitoring input. 159 */ setSearchBoxEditListener(SearchBoxEditListener listener)160 abstract public void setSearchBoxEditListener(SearchBoxEditListener listener); 161 162 /** 163 * Called when activity's onStart is called. 164 */ onStart()165 abstract public void onStart(); 166 167 /** 168 * Called when activity's onResume is called. 169 */ onResume()170 abstract public void onResume(); 171 172 /** 173 * Called when activity's onPause is called. 174 */ onPause()175 abstract public void onPause(); 176 177 /** 178 * Called when activity's onStop is called. 179 */ onStop()180 abstract public void onStop(); 181 182 /** 183 * Start input on the search box and show IME. 184 * @param hint hint text to show in the search box. 185 * @param searchBoxClickListener search box click listener. 186 * @return The search box {@link android.widget.EditText}. 187 */ startInput(String hint, View.OnClickListener searchBoxClickListener)188 abstract public EditText startInput(String hint, 189 View.OnClickListener searchBoxClickListener); 190 191 /** 192 * Set the view in the end of the search box as the search result is loading. 193 */ setSearchBoxEndView(View view)194 abstract public void setSearchBoxEndView(View view); 195 196 /** 197 * Returns the current user entered text in the search box. 198 */ getSearchBoxText()199 abstract public CharSequence getSearchBoxText(); 200 201 /** 202 * Called when input should be stopped. 203 */ stopInput()204 abstract public void stopInput(); 205 206 /** 207 * Show a toast message. 208 * @param msg text to show 209 * @param duration toast duration in millisecond. 210 */ showToast(String msg, long duration)211 abstract public void showToast(String msg, long duration); 212 } 213