AI2 Component  (Version nb184)
IceCreamSandwichThemeHelper.java
Go to the documentation of this file.
1 // -*- mode: java; c-basic-offset: 2; -*-
2 // Copyright 2018-2020 MIT, All rights reserved
3 // Released under the Apache License, Version 2.0
4 // http://www.apache.org/licenses/LICENSE-2.0
5 
6 package com.google.appinventor.components.runtime.util.theme;
7 
8 import android.graphics.Color;
9 import android.text.Html;
10 import android.view.Window;
11 import androidx.appcompat.app.ActionBar;
16 
17 public class IceCreamSandwichThemeHelper implements ThemeHelper {
18 
19  private final AppInventorCompatActivity activity;
20 
22  this.activity = activity;
23  }
24 
25  @Override
26  public void requestActionBar() {
27  activity.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
28  }
29 
30  @Override
31  public boolean setActionBarVisible(boolean visible) {
32  ActionBar actionBar = activity.getSupportActionBar();
33  if (actionBar == null) {
34  if (activity instanceof Form) {
35  ((Form) activity).dispatchErrorOccurredEvent((Form) activity, "ActionBar", ErrorMessages.ERROR_ACTIONBAR_NOT_SUPPORTED);
36  }
37  return false;
38  } else if (visible) {
39  actionBar.show();
40  } else {
41  actionBar.hide();
42  }
43  return true;
44  }
45 
46  @Override
47  public boolean hasActionBar() {
48  return activity.getSupportActionBar() != null;
49  }
50 
51  @Override
52  public void setTitle(String title) {
53  ActionBar actionBar = activity.getSupportActionBar();
54  if (actionBar != null) {
55  actionBar.setTitle(title);
56  }
57  }
58 
59  @Override
60  public void setActionBarAnimation(boolean enabled) {
61  ActionBar actionBar = activity.getSupportActionBar();
62  if (actionBar != null) {
63  actionBar.setShowHideAnimationEnabled(enabled);
64  }
65  }
66 
67  @Override
68  public void setTitle(String title, boolean black) {
69  ActionBar actionBar = activity.getSupportActionBar();
70  if (actionBar != null) {
71  if (black) {
72  actionBar.setTitle(Html.fromHtml("<font color=\"black\">" + title + "</font>"));
73  ImageViewUtil.setMenuButtonColor(activity, Color.BLACK);
74  } else {
75  actionBar.setTitle(title);
76  ImageViewUtil.setMenuButtonColor(activity, Color.WHITE);
77  }
78  }
79  }
80 }
com.google.appinventor.components.runtime.util.ErrorMessages
Definition: ErrorMessages.java:17
com.google.appinventor.components.runtime.util
-*- mode: java; c-basic-offset: 2; -*-
Definition: AccountChooser.java:7
com.google.appinventor.components.runtime.util.ImageViewUtil.setMenuButtonColor
static void setMenuButtonColor(Activity activity, int color)
Definition: ImageViewUtil.java:28
com.google.appinventor.components
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.requestActionBar
void requestActionBar()
Definition: IceCreamSandwichThemeHelper.java:26
com.google.appinventor.components.runtime.util.ErrorMessages.ERROR_ACTIONBAR_NOT_SUPPORTED
static final int ERROR_ACTIONBAR_NOT_SUPPORTED
Definition: ErrorMessages.java:119
com.google.appinventor.components.runtime.util.theme.ThemeHelper
Definition: ThemeHelper.java:8
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.setActionBarAnimation
void setActionBarAnimation(boolean enabled)
Definition: IceCreamSandwichThemeHelper.java:60
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.setActionBarVisible
boolean setActionBarVisible(boolean visible)
Definition: IceCreamSandwichThemeHelper.java:31
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.IceCreamSandwichThemeHelper
IceCreamSandwichThemeHelper(AppInventorCompatActivity activity)
Definition: IceCreamSandwichThemeHelper.java:21
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper
Definition: IceCreamSandwichThemeHelper.java:17
com.google.appinventor.components.runtime.util.ImageViewUtil
Definition: ImageViewUtil.java:19
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.setTitle
void setTitle(String title)
Definition: IceCreamSandwichThemeHelper.java:52
com.google.appinventor.components.runtime
Copyright 2009-2011 Google, All Rights reserved.
Definition: AccelerometerSensor.java:8
com.google.appinventor.components.runtime.AppInventorCompatActivity.getSupportActionBar
ActionBar getSupportActionBar()
Definition: AppInventorCompatActivity.java:207
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.hasActionBar
boolean hasActionBar()
Definition: IceCreamSandwichThemeHelper.java:47
com.google.appinventor.components.runtime.util.theme.IceCreamSandwichThemeHelper.setTitle
void setTitle(String title, boolean black)
Definition: IceCreamSandwichThemeHelper.java:68
com.google.appinventor.components.runtime.AppInventorCompatActivity
Definition: AppInventorCompatActivity.java:40
com.google
com
com.google.appinventor.components.runtime.Form
Definition: Form.java:126
com.google.appinventor