aboutsummaryrefslogtreecommitdiff
path: root/car-lib/src/android/car/app/menu/CarUiEntry.java
blob: f14421b72b6af25f6038df0166b1290d4774605a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.car.app.menu;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

/**
 * A base class for a car ui entry which is used for loading and manipulating common car
 * app decor window (CarUi).
 *
 * A CarUi provider provides essential ui elements that a car app may want to use. The CarUi is
 * loaded by apps at runtime, similar to a shared library, but via reflection through a class that
 * extends {@link android.car.app.menu.CarUiEntry} from a separate apk
 * called CarUiProvider. Depending on the different platforms, the CarUiProvider may
 * be different and can be customized by different car makers. However, it is required that a
 * set of basic ui elements and functionalities exist in the CarUiProvider. This class defines
 * the set of must have functions in a CarUiProvider.
 */
public abstract class CarUiEntry {
    protected final Context mAppContext;
    protected final Context mUiLibContext;

    public CarUiEntry(Context uiLibContext, Context appContext) {
        mUiLibContext = uiLibContext.createConfigurationContext(
                appContext.getResources().getConfiguration());
        mAppContext = appContext;
    }

    /**
     * Return the content view.
     */
    abstract public View getContentView();

    /**
     * Set {@link android.car.app.menu.CarMenuCallbacks} from a car app for car menu interactions.
     */
    abstract public void setCarMenuCallbacks(CarMenuCallbacks callbacks);

    /**
     * Return the id of the main container in which app can render its own content.
     */
    abstract public int getFragmentContainerId();

    /**
     * Set the background bitmap.
     */
    abstract public void setBackground(Bitmap bitmap);

    /**
     * Replace the menu button with the given bitmap.
     */
    abstract public void setMenuButtonBitmap(Bitmap bitmap);

    /**
     * Hide the menu button.
     */
    abstract public void hideMenuButton();

    /**
     * Restore the menu button.
     */
    abstract public void restoreMenuDrawable();

    /**
     * Set the color of the car menu scrim.
     */
    abstract public void setScrimColor(int color);

    /**
     * Set the title of the car menu.
     */
    abstract public void setTitle(CharSequence title);

    /**
     * Close the car menu.
     */
    abstract public void closeDrawer();

    /**
     * Open the car menu.
     */
    abstract public void openDrawer();

    /**
     * Show the menu associated with the specified id, and set the car menu title.
     */
    abstract public void showMenu(String id, String title);

    /**
     * Set the car menu button color.
     */
    abstract public void setMenuButtonColor(int color);

    /**
     * Make the menu title visible.
     */
    abstract public void showTitle();

    /**
     * Hide the menu title.
     */
    abstract public void hideTitle();

    /**
     * Use the light car theme.
     */
    abstract public void setLightMode();

    /**
     * Use the dark car theme.
     */
    abstract public void setDarkMode();

    /**
     * Use automatic light/dark car theme based on ui mode.
     */
    abstract public void setAutoLightDarkMode();

    /**
     * Called when the activity's onRestoreInstanceState is called.
     */
    abstract public void onRestoreInstanceState(Bundle savedInstanceState);

    /**
     * Called when the activity's onSaveInstanceState is called.
     */
    abstract public void onSaveInstanceState(Bundle outState);

    /**
     * Show the search box and set the click listener for the search box.
     */
    abstract public void showSearchBox(View.OnClickListener listener);

    /**
     * Set the color of the search box.
     */
    abstract public void setSearchBoxColors(int backgroundColor, int searchLogoColor,
            int textColor, int hintTextColor);

    /**
     * Set the search box edit listener for monitoring input.
     */
    abstract public void setSearchBoxEditListener(SearchBoxEditListener listener);

    /**
     * Called when activity's onStart is called.
     */
    abstract public void onStart();

    /**
     * Called when activity's onResume is called.
     */
    abstract public void onResume();

    /**
     * Called when activity's onPause is called.
     */
    abstract public void onPause();

    /**
     * Called when activity's onStop is called.
     */
    abstract public void onStop();

    /**
     * Start input on the search box and show IME.
     * @param hint hint text to show in the search box.
     * @param searchBoxClickListener search box click listener.
     * @return The search box {@link android.widget.EditText}.
     */
    abstract public EditText startInput(String hint,
            View.OnClickListener searchBoxClickListener);

    /**
     * Set the view in the end of the search box as the search result is loading.
     */
    abstract public void setSearchBoxEndView(View view);

    /**
     * Returns the current user entered text in the search box.
     */
    abstract public CharSequence getSearchBoxText();

    /**
     * Called when input should be stopped.
     */
    abstract public void stopInput();

    /**
     * Show a toast message.
     * @param msg text to show
     * @param duration toast duration in millisecond.
     */
    abstract public void showToast(String msg, long duration);
}