Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-17964] Add custom error message for wrong theme used. #9396

Merged
merged 14 commits into from
May 19, 2018
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public abstract class TiBaseActivity extends AppCompatActivity
{
private static final String TAG = "TiBaseActivity";

private final String customToolbarExceptionMessage = "Trying to use Toolbar as ActionBar without disabling the default ActionBar in the used theme.\n" +
"Set 'windowActionBar' to false in your theme in order to do that. The following bundled themes:\n" +
"[Theme.Titanium, Theme.AppCompat.Translucent.NoTitleBar, Theme.AppCompat.NoTitleBar] are with\n" +
"disabled default ActionBar. You could use one of them.";

private static OrientationChangedListener orientationChangedListener = null;
private OrientationEventListener orientationListener;

Expand Down Expand Up @@ -752,7 +757,13 @@ public void onOrientationChanged(int orientation) {

private void setCustomActionBar() {
if (activityProxy.hasProperty(TiC.PROPERTY_SUPPORT_TOOLBAR)) {
this.setSupportActionBar(((Toolbar) ((TiToolbarProxy) activityProxy.getProperty(TiC.PROPERTY_SUPPORT_TOOLBAR)).getToolbarInstance()));
try {
this.setSupportActionBar(((Toolbar) ((TiToolbarProxy) activityProxy.getProperty(TiC.PROPERTY_SUPPORT_TOOLBAR)).getToolbarInstance()));
} catch (RuntimeException e) {
Log.e(TAG, customToolbarExceptionMessage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the error message will only be used once, it's best to just define it here

Log.e(TAG, "Attempting to use Toolbar as ActionBar without disabling the default ActionBar in the current theme.\n" +
           "You must set 'windowActionBar' to false in your current theme. Or use one of the following themes:\n" +
           "[Theme.Titanium, Theme.AppCompat.Translucent.NoTitleBar, Theme.AppCompat.NoTitleBar]\n" +
           "Which have ActionBar disabled by default.");

I have also re-worded it 👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do a list of theme instead of []? :-)

TiApplication.terminateActivityStack();
finish();
}
}
}

Expand Down