|
49 | 49 | import com.zebra.ai_multibarcodes_capture.helpers.LocaleHelper; |
50 | 50 | import com.zebra.ai_multibarcodes_capture.helpers.LogUtils; |
51 | 51 | import com.zebra.ai_multibarcodes_capture.helpers.PreferencesHelper; |
| 52 | +import com.zebra.ai_multibarcodes_capture.helpers.ThemeHelpers; |
52 | 53 | import com.zebra.ai_multibarcodes_capture.java.CameraXLivePreviewActivity; |
53 | 54 | import com.zebra.ai_multibarcodes_capture.managedconfig.ManagedConfigurationReceiver; |
54 | 55 | import com.zebra.ai_multibarcodes_capture.sessionmanagement.SessionViewerActivity; |
@@ -136,13 +137,14 @@ protected void onCreate(Bundle savedInstanceState) { |
136 | 137 | super.onCreate(savedInstanceState); |
137 | 138 |
|
138 | 139 | // Apply theme before setting content view |
139 | | - applyTheme(); |
| 140 | + ThemeHelpers.applyTheme(this); |
| 141 | + |
140 | 142 |
|
141 | 143 | binding = ActivityEntryChoiceBinding.inflate(getLayoutInflater()); |
142 | 144 | setContentView(binding.getRoot()); |
143 | 145 |
|
144 | 146 | // Configure system bar colors |
145 | | - configureSystemBars(); |
| 147 | + ThemeHelpers.configureSystemBars(this, R.id.cl_entry_choice_activity); |
146 | 148 |
|
147 | 149 | // Initializing the AI Vision SDK |
148 | 150 | try { |
@@ -357,85 +359,6 @@ public void onClick(View view) { |
357 | 359 | } |
358 | 360 |
|
359 | 361 |
|
360 | | - |
361 | | - private void configureSystemBars() { |
362 | | - Window window = getWindow(); |
363 | | - |
364 | | - // 1. Set the Navigation Bar Background Color to Black |
365 | | - window.setNavigationBarColor(Color.BLACK); |
366 | | - |
367 | | - // 2. Control the Navigation Bar Icon Color (Light/White) |
368 | | - // Ensure the system bars are drawn over the app's content |
369 | | - WindowCompat.setDecorFitsSystemWindows(window, false); |
370 | | - |
371 | | - // Use the compatibility controller for managing bar appearance |
372 | | - WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, window.getDecorView()); |
373 | | - |
374 | | - // Request light navigation bar icons (white) |
375 | | - // Setting this to 'false' tells the system to use light icons on a dark background. |
376 | | - controller.setAppearanceLightNavigationBars(false); |
377 | | - |
378 | | - // Force status bar color |
379 | | - View rootLayout = findViewById(R.id.cl_entry_choice_activity); |
380 | | - |
381 | | - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { // Android 15+ |
382 | | - |
383 | | - // 1. Set Navigation Bar background color using the WindowInsetsListener on decorView |
384 | | - window.getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { |
385 | | - @Override |
386 | | - public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) { |
387 | | - // Set the background color to the view (decorView) - BLACK for navigation bar |
388 | | - view.setBackgroundColor(Color.BLACK); |
389 | | - return insets; |
390 | | - } |
391 | | - }); |
392 | | - |
393 | | - // 2. Handle Status Bar color and Root Layout padding using ViewCompat |
394 | | - ViewCompat.setOnApplyWindowInsetsListener(rootLayout, (v, windowInsets) -> { |
395 | | - // Get the system bar insets (status bar and navigation bar area) |
396 | | - // Use getInsets(WindowInsetsCompat.Type.systemBars()) |
397 | | - // equivalent to the Kotlin line |
398 | | - androidx.core.graphics.Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); |
399 | | - int statusBarHeight = insets.top; |
400 | | - |
401 | | - // Below code is for adding padding top and bottom (setting margins on the rootLayout) |
402 | | - ViewGroup.LayoutParams lp = v.getLayoutParams(); |
403 | | - if (lp instanceof ViewGroup.MarginLayoutParams) { |
404 | | - ViewGroup.MarginLayoutParams marginLp = (ViewGroup.MarginLayoutParams) lp; |
405 | | - |
406 | | - // The Kotlin updateLayoutParams<MarginLayoutParams> block is equivalent to this: |
407 | | - marginLp.topMargin = insets.top; |
408 | | - marginLp.bottomMargin = insets.bottom; |
409 | | - v.setLayoutParams(marginLp); // Apply the updated layout params |
410 | | - } |
411 | | - |
412 | | - |
413 | | - // 3. Create and add a separate Status Bar View |
414 | | - View statusBarView = new View(getApplicationContext()); |
415 | | - |
416 | | - // Below code is for setting color and height to notification bar |
417 | | - // Height is the status bar height |
418 | | - statusBarView.setLayoutParams(new ViewGroup.LayoutParams( |
419 | | - ViewGroup.LayoutParams.MATCH_PARENT, |
420 | | - statusBarHeight |
421 | | - )); |
422 | | - |
423 | | - // Set the status bar color using ContextCompat |
424 | | - statusBarView.setBackgroundColor(androidx.appcompat.R.attr.colorPrimary); |
425 | | - |
426 | | - // Add the view to the activity's content view group |
427 | | - addContentView(statusBarView, statusBarView.getLayoutParams()); |
428 | | - |
429 | | - // Consume the insets so they aren't passed down further |
430 | | - return WindowInsetsCompat.CONSUMED; |
431 | | - }); |
432 | | - |
433 | | - } else { |
434 | | - // For Android 14 and below |
435 | | - window.setStatusBarColor(androidx.appcompat.R.attr.colorPrimary); |
436 | | - } |
437 | | - } |
438 | | - |
439 | 362 | private void updateCards() |
440 | 363 | { |
441 | 364 | if (eProcessingMode == EProcessingMode.FILE) { |
@@ -487,7 +410,7 @@ protected void onResume() { |
487 | 410 | super.onResume(); |
488 | 411 |
|
489 | 412 | // Re-apply system bar appearance to ensure it persists |
490 | | - configureSystemBars(); |
| 413 | + ThemeHelpers.configureSystemBars(this, R.id.cl_entry_choice_activity); |
491 | 414 |
|
492 | 415 | checkCameraPermission(); |
493 | 416 |
|
@@ -640,17 +563,6 @@ public void onRequestPermissionsResult(int requestCode, |
640 | 563 | } |
641 | 564 | } |
642 | 565 |
|
643 | | - private void applyTheme() { |
644 | | - SharedPreferences sharedPreferences = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); |
645 | | - String theme = sharedPreferences.getString(SHARED_PREFERENCES_THEME, SHARED_PREFERENCES_THEME_DEFAULT); |
646 | | - |
647 | | - if ("modern".equals(theme)) { |
648 | | - setTheme(R.style.Base_Theme_AIMultiBarcodes_Capture_Modern); |
649 | | - } else { |
650 | | - setTheme(R.style.Base_Theme_AIMultiBarcodes_Capture_Legacy); |
651 | | - } |
652 | | - } |
653 | | - |
654 | 566 | @Override |
655 | 567 | protected void attachBaseContext(Context newBase) { |
656 | 568 | String languageCode = LocaleHelper.getCurrentLanguageCode(newBase); |
|
0 commit comments