|
@@ -1,361 +0,0 @@
|
1
|
|
-package com.reactnativenavigation.views;
|
2
|
|
-
|
3
|
|
-public class RnnToolBar {
|
4
|
|
-
|
5
|
|
-// private List<_Screen> mScreens;
|
6
|
|
-// private AsyncTask mDrawerIconTask;
|
7
|
|
-// private AsyncTask mSetupToolbarTask;
|
8
|
|
-// private Drawable mBackground;
|
9
|
|
-// private Drawable mDrawerIcon;
|
10
|
|
-// private DrawerLayout mDrawerLayout;
|
11
|
|
-// private ActionBarDrawerToggle mDrawerToggle;
|
12
|
|
-// private ArrayList<View> mMenuItems;
|
13
|
|
-//
|
14
|
|
-// public RnnToolBar(Context context) {
|
15
|
|
-// super(context);
|
16
|
|
-// init();
|
17
|
|
-// }
|
18
|
|
-//
|
19
|
|
-// private void init() {
|
20
|
|
-// mMenuItems = new ArrayList<>();
|
21
|
|
-// mBackground = getBackground();
|
22
|
|
-// }
|
23
|
|
-//
|
24
|
|
-// public void setScreens(List<_Screen> screens) {
|
25
|
|
-// mScreens = screens;
|
26
|
|
-// }
|
27
|
|
-//
|
28
|
|
-// public void handleOnCreateOptionsMenuAsync() {
|
29
|
|
-//// if (mScreens != null) {
|
30
|
|
-//// setupToolbarButtonsAsync(null, mScreens.get(0));
|
31
|
|
-//// }
|
32
|
|
-// }
|
33
|
|
-//
|
34
|
|
-// public ActionBarDrawerToggle setupDrawer(DrawerLayout drawerLayout, _Screen drawerScreen, _Screen screen) {
|
35
|
|
-// if (drawerLayout == null || drawerScreen == null) {
|
36
|
|
-// return null;
|
37
|
|
-// }
|
38
|
|
-//
|
39
|
|
-// mDrawerLayout = drawerLayout;
|
40
|
|
-// mDrawerToggle = new ActionBarDrawerToggle(
|
41
|
|
-// ContextProvider.getActivityContext(),
|
42
|
|
-// mDrawerLayout,
|
43
|
|
-// this,
|
44
|
|
-// R.string.drawer_open,
|
45
|
|
-// R.string.drawer_close
|
46
|
|
-// );
|
47
|
|
-// mDrawerLayout.setDrawerListener(mDrawerToggle);
|
48
|
|
-// setupDrawerIconAsync(drawerScreen.tabIcon, screen);
|
49
|
|
-//
|
50
|
|
-// return mDrawerToggle;
|
51
|
|
-// }
|
52
|
|
-//
|
53
|
|
-// public void setDrawerIcon(Drawable tabIcon) {
|
54
|
|
-// mDrawerIcon = tabIcon;
|
55
|
|
-// }
|
56
|
|
-//
|
57
|
|
-// public void showDrawer(boolean animated) {
|
58
|
|
-// if (mDrawerLayout == null) {
|
59
|
|
-// return;
|
60
|
|
-// }
|
61
|
|
-//
|
62
|
|
-// mDrawerLayout.openDrawer(Gravity.LEFT);
|
63
|
|
-// }
|
64
|
|
-//
|
65
|
|
-// public void hideDrawer(boolean animated) {
|
66
|
|
-// if (mDrawerLayout == null) {
|
67
|
|
-// return;
|
68
|
|
-// }
|
69
|
|
-//
|
70
|
|
-// mDrawerLayout.closeDrawer(Gravity.LEFT);
|
71
|
|
-// }
|
72
|
|
-//
|
73
|
|
-// public void toggleDrawer(boolean animated) {
|
74
|
|
-// if (mDrawerLayout == null) {
|
75
|
|
-// return;
|
76
|
|
-// }
|
77
|
|
-//
|
78
|
|
-// boolean visible = mDrawerLayout.isDrawerOpen(Gravity.LEFT);
|
79
|
|
-// if (visible) {
|
80
|
|
-// hideDrawer(animated);
|
81
|
|
-// } else {
|
82
|
|
-// showDrawer(animated);
|
83
|
|
-// }
|
84
|
|
-// }
|
85
|
|
-//
|
86
|
|
-// public void setupDrawerIconAsync(String drawerIconSource, _Screen screen) {
|
87
|
|
-// if (mDrawerIconTask == null) {
|
88
|
|
-// mDrawerIconTask = new SetupDrawerIconTask(this, drawerIconSource, screen).execute();
|
89
|
|
-// }
|
90
|
|
-// }
|
91
|
|
-//
|
92
|
|
-// public void setupToolbarButtonsAsync(_Screen newScreen) {
|
93
|
|
-// if (newScreen != null) {
|
94
|
|
-// this.setupToolbarButtonsAsync(null, newScreen);
|
95
|
|
-// }
|
96
|
|
-// }
|
97
|
|
-//
|
98
|
|
-//
|
99
|
|
-// public void setupToolbarButtonsAsync(_Screen oldScreen, _Screen newScreen) {
|
100
|
|
-// if (mSetupToolbarTask == null) {
|
101
|
|
-// mSetupToolbarTask = new SetupToolbarButtonsTask(this, oldScreen, newScreen).execute();
|
102
|
|
-// }
|
103
|
|
-// }
|
104
|
|
-//
|
105
|
|
-// public void showToolbar(boolean animated) {
|
106
|
|
-// ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
|
107
|
|
-// if (actionBar != null) {
|
108
|
|
-// actionBar.setShowHideAnimationEnabled(animated);
|
109
|
|
-// // We hide the ToolBar's parent (AppBarLayout) since this animates the shadow added by AppBar as well
|
110
|
|
-// ((View) getParent()).setVisibility(VISIBLE);
|
111
|
|
-// }
|
112
|
|
-// }
|
113
|
|
-//
|
114
|
|
-// public void hideToolbar(boolean animated) {
|
115
|
|
-// ActionBar actionBar = ((AppCompatActivity) getContext()).getSupportActionBar();
|
116
|
|
-// if (actionBar != null) {
|
117
|
|
-// actionBar.setShowHideAnimationEnabled(animated);
|
118
|
|
-// // We hide the ToolBar's parent (AppBarLayout) since this animates the shadow added by AppBar as well
|
119
|
|
-// ((View) getParent()).setVisibility(GONE);
|
120
|
|
-// }
|
121
|
|
-// }
|
122
|
|
-//
|
123
|
|
-// private void showToolbar() {
|
124
|
|
-// showToolbar(false);
|
125
|
|
-// }
|
126
|
|
-//
|
127
|
|
-// private void hideToolbar() {
|
128
|
|
-// hideToolbar(false);
|
129
|
|
-// }
|
130
|
|
-//
|
131
|
|
-// public void setNavUpButton() {
|
132
|
|
-// setNavUpButton(null);
|
133
|
|
-// }
|
134
|
|
-//
|
135
|
|
-// @SuppressWarnings({"ConstantConditions"})
|
136
|
|
-// public void setNavUpButton(_Screen screen) {
|
137
|
|
-// BaseReactActivity context = ContextProvider.getActivityContext();
|
138
|
|
-// if (context == null) {
|
139
|
|
-// return;
|
140
|
|
-// }
|
141
|
|
-//
|
142
|
|
-// ActionBar actionBar = context.getSupportActionBar();
|
143
|
|
-// if (actionBar == null) {
|
144
|
|
-// return;
|
145
|
|
-// }
|
146
|
|
-//
|
147
|
|
-// boolean isBack = screen != null;
|
148
|
|
-// boolean hasDrawer = mDrawerToggle != null;
|
149
|
|
-//
|
150
|
|
-// Drawable navIcon = null;
|
151
|
|
-// DrawerArrowDrawable navArrow = null;
|
152
|
|
-// if (hasDrawer && mDrawerIcon == null) {
|
153
|
|
-// navArrow = (DrawerArrowDrawable) this.getNavigationIcon();
|
154
|
|
-// } else {
|
155
|
|
-// if (isBack && !screen.backButtonHidden) {
|
156
|
|
-// navArrow = new DrawerArrowDrawable(context);
|
157
|
|
-// } else if (hasDrawer) {
|
158
|
|
-// navIcon = mDrawerIcon;
|
159
|
|
-// }
|
160
|
|
-// }
|
161
|
|
-//
|
162
|
|
-// if (navArrow != null) {
|
163
|
|
-// navArrow.setProgress(isBack ? 1.0f : 0.0f);
|
164
|
|
-// if (screen != null && screen.navBarButtonColor != null) {
|
165
|
|
-// navArrow.setColor(screen.navBarButtonColor);
|
166
|
|
-// } else {
|
167
|
|
-// navArrow.setColor(Color.BLACK);
|
168
|
|
-// }
|
169
|
|
-// navIcon = navArrow;
|
170
|
|
-// }
|
171
|
|
-//
|
172
|
|
-// actionBar.setHomeAsUpIndicator(navIcon);
|
173
|
|
-// actionBar.setDisplayHomeAsUpEnabled(navIcon != null);
|
174
|
|
-// }
|
175
|
|
-//
|
176
|
|
-// /**
|
177
|
|
-// * Update the ToolBar from screen. This function sets any properties that are defined
|
178
|
|
-// * in the screen.
|
179
|
|
-// *
|
180
|
|
-// * @param screen The currently displayed screen
|
181
|
|
-// */
|
182
|
|
-// @UiThread
|
183
|
|
-// public void update(@NonNull _Screen screen) {
|
184
|
|
-// ((AppCompatActivity) getContext()).setSupportActionBar(this);
|
185
|
|
-// setTitle(screen.title);
|
186
|
|
-// setStyle(screen);
|
187
|
|
-// }
|
188
|
|
-//
|
189
|
|
-// public void updateAndSetButtons(_Screen screen) {
|
190
|
|
-// update(screen);
|
191
|
|
-// setupToolbarButtonsAsync(screen);
|
192
|
|
-// }
|
193
|
|
-//
|
194
|
|
-// private static class SetupDrawerIconTask extends AsyncTask<Void, Void, Drawable> {
|
195
|
|
-// private final WeakReference<RnnToolBar> mToolbarWR;
|
196
|
|
-// private final String mDrawerIconSource;
|
197
|
|
-// private final Integer mTintColor;
|
198
|
|
-//
|
199
|
|
-// public SetupDrawerIconTask(RnnToolBar toolBar, String drawerIconSource, _Screen screen) {
|
200
|
|
-// mToolbarWR = new WeakReference<>(toolBar);
|
201
|
|
-// mDrawerIconSource = drawerIconSource;
|
202
|
|
-// mTintColor = screen.navBarButtonColor;
|
203
|
|
-// }
|
204
|
|
-//
|
205
|
|
-// @Override
|
206
|
|
-// protected Drawable doInBackground(Void... params) {
|
207
|
|
-// Context context = ContextProvider.getActivityContext();
|
208
|
|
-// if (context == null || mDrawerIconSource == null) {
|
209
|
|
-// return null;
|
210
|
|
-// }
|
211
|
|
-//
|
212
|
|
-// return ImageLoader.loadImage(mDrawerIconSource);
|
213
|
|
-// }
|
214
|
|
-//
|
215
|
|
-// @Override
|
216
|
|
-// protected void onPostExecute(Drawable drawerIcon) {
|
217
|
|
-// RnnToolBar toolBar = mToolbarWR.get();
|
218
|
|
-// if (drawerIcon != null) {
|
219
|
|
-// if (mTintColor != null) {
|
220
|
|
-// ImageUtils.tint(drawerIcon, mTintColor);
|
221
|
|
-// }
|
222
|
|
-// toolBar.setDrawerIcon(drawerIcon);
|
223
|
|
-// }
|
224
|
|
-//
|
225
|
|
-// toolBar.setNavUpButton();
|
226
|
|
-// mToolbarWR.clear();
|
227
|
|
-// }
|
228
|
|
-// }
|
229
|
|
-//
|
230
|
|
-// private static class SetupToolbarButtonsTask extends AsyncTask<Void, Void, Map<String, Drawable>> {
|
231
|
|
-// private final List<_Button> mOldButtons;
|
232
|
|
-// private final List<_Button> mNewButtons;
|
233
|
|
-// private final WeakReference<RnnToolBar> mToolbarWR;
|
234
|
|
-// @ColorInt
|
235
|
|
-// private final Integer mTintColor;
|
236
|
|
-// private final int mIconDimensions;
|
237
|
|
-//
|
238
|
|
-// public SetupToolbarButtonsTask(RnnToolBar toolBar, _Screen oldScreen, _Screen newScreen) {
|
239
|
|
-// mToolbarWR = new WeakReference<>(toolBar);
|
240
|
|
-// mOldButtons = oldScreen == null ? null : oldScreen.getButtons();
|
241
|
|
-// mNewButtons = newScreen.getButtons();
|
242
|
|
-// mTintColor = newScreen.navBarButtonColor;
|
243
|
|
-// mIconDimensions = (int) ImageUtils.convertDpToPixel(48, toolBar.getContext());
|
244
|
|
-// }
|
245
|
|
-//
|
246
|
|
-// @Override
|
247
|
|
-// protected Map<String, Drawable> doInBackground(Void... params) {
|
248
|
|
-// Context context = ContextProvider.getActivityContext();
|
249
|
|
-// if (context == null) {
|
250
|
|
-// return null;
|
251
|
|
-// }
|
252
|
|
-//
|
253
|
|
-// Map<String, Drawable> icons = new HashMap<>();
|
254
|
|
-// for (_Button button : mNewButtons) {
|
255
|
|
-// if (button.hasIcon()) {
|
256
|
|
-// icons.put(button.id, button.getIcon(context, mIconDimensions));
|
257
|
|
-// }
|
258
|
|
-// }
|
259
|
|
-// return icons;
|
260
|
|
-// }
|
261
|
|
-//
|
262
|
|
-// @Override
|
263
|
|
-// protected void onPostExecute(Map<String, Drawable> icons) {
|
264
|
|
-// final Context context = ContextProvider.getActivityContext();
|
265
|
|
-// if (context == null) {
|
266
|
|
-// return;
|
267
|
|
-// }
|
268
|
|
-//
|
269
|
|
-// Menu menu = ((BaseReactActivity) context).getMenu();
|
270
|
|
-// if (menu == null) {
|
271
|
|
-// RnnToolBar toolBar = mToolbarWR.get();
|
272
|
|
-// if (toolBar != null) {
|
273
|
|
-// toolBar.mSetupToolbarTask = null;
|
274
|
|
-// }
|
275
|
|
-// mToolbarWR.clear();
|
276
|
|
-// return;
|
277
|
|
-// }
|
278
|
|
-//
|
279
|
|
-// // Remove prev screen buttons
|
280
|
|
-// if (mOldButtons == null) {
|
281
|
|
-// menu.clear();
|
282
|
|
-// } else {
|
283
|
|
-// for (_Button btn : mOldButtons) {
|
284
|
|
-// menu.removeItem(btn.getItemId());
|
285
|
|
-// }
|
286
|
|
-// }
|
287
|
|
-//
|
288
|
|
-// // Add new screen buttons
|
289
|
|
-// final List<String> textButtons = new ArrayList<>();
|
290
|
|
-// final int size = mNewButtons.size();
|
291
|
|
-// for (int i = 0; i < size; i++) {
|
292
|
|
-// _Button button = mNewButtons.get(i);
|
293
|
|
-// MenuItem item = menu.add(Menu.NONE, button.getItemId(), size - i - 1, button.title);
|
294
|
|
-// item.setShowAsAction(getMenuItemShowAction(button.showAsAction));
|
295
|
|
-//
|
296
|
|
-// // Set button tabIcon
|
297
|
|
-// if (button.hasIcon()) {
|
298
|
|
-// Drawable tabIcon = icons.get(button.id);
|
299
|
|
-// if (mTintColor != null) {
|
300
|
|
-// ImageUtils.tint(tabIcon, mTintColor);
|
301
|
|
-// }
|
302
|
|
-// item.setIcon(tabIcon);
|
303
|
|
-// } else {
|
304
|
|
-// textButtons.add(button.title);
|
305
|
|
-// }
|
306
|
|
-//
|
307
|
|
-// // Disable button if needed
|
308
|
|
-// if (button.disabled) {
|
309
|
|
-// item.setEnabled(false);
|
310
|
|
-// }
|
311
|
|
-// }
|
312
|
|
-//
|
313
|
|
-// final RnnToolBar toolBar = mToolbarWR.get();
|
314
|
|
-// if (toolBar != null) {
|
315
|
|
-// // Tint overflow tabIcon which appears when there's not enough space in Toolbar for icons
|
316
|
|
-// if (mTintColor != null) {
|
317
|
|
-// ImageUtils.tint(toolBar.getOverflowIcon(), mTintColor);
|
318
|
|
-// }
|
319
|
|
-//
|
320
|
|
-// // Tint text buttons
|
321
|
|
-// if (textButtons.size() > 0 && mTintColor != null) {
|
322
|
|
-// final View decorView = ((Activity) context).getWindow().getDecorView();
|
323
|
|
-// decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
324
|
|
-// @Override
|
325
|
|
-// public void onGlobalLayout() {
|
326
|
|
-// decorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
327
|
|
-//
|
328
|
|
-// // Find TextViews
|
329
|
|
-// for (String text : textButtons) {
|
330
|
|
-// decorView.findViewsWithText(toolBar.mMenuItems, text, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
|
331
|
|
-// }
|
332
|
|
-//
|
333
|
|
-// // Set text color
|
334
|
|
-// for (View button : toolBar.mMenuItems) {
|
335
|
|
-// ((TextView) button).setTextColor(mTintColor);
|
336
|
|
-// }
|
337
|
|
-//
|
338
|
|
-// toolBar.mMenuItems.clear();
|
339
|
|
-// }
|
340
|
|
-// });
|
341
|
|
-// }
|
342
|
|
-//
|
343
|
|
-// toolBar.mSetupToolbarTask = null;
|
344
|
|
-// mToolbarWR.clear();
|
345
|
|
-// }
|
346
|
|
-// }
|
347
|
|
-//
|
348
|
|
-// private int getMenuItemShowAction(String action) {
|
349
|
|
-// switch (action) {
|
350
|
|
-// case "never":
|
351
|
|
-// return MenuItem.SHOW_AS_ACTION_NEVER;
|
352
|
|
-// case "always":
|
353
|
|
-// return MenuItem.SHOW_AS_ACTION_ALWAYS;
|
354
|
|
-// case "withText":
|
355
|
|
-// return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
|
356
|
|
-// default:
|
357
|
|
-// return MenuItem.SHOW_AS_ACTION_IF_ROOM;
|
358
|
|
-// }
|
359
|
|
-// }
|
360
|
|
-// }
|
361
|
|
-}
|