CarUiEntry.java revision 5d8b90468dead2f59ec7007af3d67cc587ac5c1a
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 */
16package android.car.app.menu;
17
18import android.content.Context;
19import android.graphics.Bitmap;
20import android.os.Bundle;
21import android.view.View;
22import 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 */
36public abstract class CarUiEntry {
37    protected final Context mAppContext;
38    protected final Context mUiLibContext;
39
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     */
49    abstract public View getContentView();
50
51    /**
52     * Set {@link android.car.app.menu.CarMenuCallbacks} from a car app for car menu interactions.
53     */
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     */
59    abstract public int getFragmentContainerId();
60
61    /**
62     * Set the background bitmap.
63     */
64    abstract public void setBackground(Bitmap bitmap);
65
66    /**
67     * Replace the menu button with the given bitmap.
68     */
69    abstract public void setMenuButtonBitmap(Bitmap bitmap);
70
71    /**
72     * Hide the menu button.
73     */
74    abstract public void hideMenuButton();
75
76    /**
77     * Restore the menu button.
78     */
79    abstract public void restoreMenuDrawable();
80
81    /**
82     * Set the color of the car menu scrim.
83     */
84    abstract public void setScrimColor(int color);
85
86    /**
87     * Set the title of the car menu.
88     */
89    abstract public void setTitle(CharSequence title);
90
91    /**
92     * Close the car menu.
93     */
94    abstract public void closeDrawer();
95
96    /**
97     * Open the car menu.
98     */
99    abstract public void openDrawer();
100
101    /**
102     * Show the menu associated with the specified id, and set the car menu title.
103     */
104    abstract public void showMenu(String id, String title);
105
106    /**
107     * Set the car menu button color.
108     */
109    abstract public void setMenuButtonColor(int color);
110
111    /**
112     * Make the menu title visible.
113     */
114    abstract public void showTitle();
115
116    /**
117     * Hide the menu title.
118     */
119    abstract public void hideTitle();
120
121    /**
122     * Use the light car theme.
123     */
124    abstract public void setLightMode();
125
126    /**
127     * Use the dark car theme.
128     */
129    abstract public void setDarkMode();
130
131    /**
132     * Use automatic light/dark car theme based on ui mode.
133     */
134    abstract public void setAutoLightDarkMode();
135
136    /**
137     * Called when the activity's onRestoreInstanceState is called.
138     */
139    abstract public void onRestoreInstanceState(Bundle savedInstanceState);
140
141    /**
142     * Called when the activity's onSaveInstanceState is called.
143     */
144    abstract public void onSaveInstanceState(Bundle outState);
145
146    /**
147     * Show the search box and set the click listener for the search box.
148     */
149    abstract public void showSearchBox(View.OnClickListener listener);
150
151    /**
152     * Set the color of the search box.
153     */
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     */
160    abstract public void setSearchBoxEditListener(SearchBoxEditListener listener);
161
162    /**
163     * Called when activity's onStart is called.
164     */
165    abstract public void onStart();
166
167    /**
168     * Called when activity's onResume is called.
169     */
170    abstract public void onResume();
171
172    /**
173     * Called when activity's onPause is called.
174     */
175    abstract public void onPause();
176
177    /**
178     * Called when activity's onStop is called.
179     */
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     */
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     */
194    abstract public void setSearchBoxEndView(View view);
195
196    /**
197     * Returns the current user entered text in the search box.
198     */
199    abstract public CharSequence getSearchBoxText();
200
201    /**
202     * Called when input should be stopped.
203     */
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     */
211    abstract public void showToast(String msg, long duration);
212}
213