[SuwLib] Improve wrong theme error message

am: 9958648

* commit '99586481628659cd2982a0248bc0d09a6ec4590e':
  [SuwLib] Improve wrong theme error message
This commit is contained in:
Maurice Lam 2016-03-18 17:54:50 +00:00 committed by android-build-merger
commit 5111c67feb
4 changed files with 46 additions and 3 deletions

View file

@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.util.AttributeSet;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -121,7 +122,12 @@ public class GlifLayout extends TemplateLayout {
if (template == 0) {
template = R.layout.suw_glif_template;
}
return super.onInflateTemplate(inflater, template);
try {
return super.onInflateTemplate(inflater, template);
} catch (InflateException e) {
throw new InflateException("Unable to inflate layout. Are you using "
+ "@style/SuwThemeGlif (or its descendant) as your theme?", e);
}
}
@Override

View file

@ -25,7 +25,6 @@ import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Parcel;
@ -34,6 +33,7 @@ import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -167,7 +167,12 @@ public class SetupWizardLayout extends TemplateLayout {
if (template == 0) {
template = R.layout.suw_template;
}
return super.onInflateTemplate(inflater, template);
try {
return super.onInflateTemplate(inflater, template);
} catch (InflateException e) {
throw new InflateException("Unable to inflate layout. Are you using "
+ "@style/SuwThemeMaterial (or its descendant) as your theme?", e);
}
}
@Override

View file

@ -23,6 +23,7 @@ import android.os.Build;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.ContextThemeWrapper;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
@ -98,6 +99,21 @@ public class GlifLayoutTest extends InstrumentationTestCase {
}
}
@SmallTest
public void testWrongTheme() {
// Test the error message when using the wrong theme
mContext = new ContextThemeWrapper(getInstrumentation().getContext(),
android.R.style.Theme);
try {
new GlifLayout(mContext);
fail("Should have thrown InflateException");
} catch (InflateException e) {
assertEquals("Exception message should mention correct theme to use",
"Unable to inflate layout. Are you using @style/SuwThemeGlif "
+ "(or its descendant) as your theme?", e.getMessage());
}
}
private void assertDefaultTemplateInflated(GlifLayout layout) {
View title = layout.findViewById(R.id.suw_layout_title);
assertNotNull("@id/suw_layout_title should not be null", title);

View file

@ -22,6 +22,7 @@ import android.graphics.drawable.ColorDrawable;
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.ContextThemeWrapper;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
@ -143,6 +144,21 @@ public class SetupWizardLayoutTest extends InstrumentationTestCase {
assertFalse("Progress bar should not be shown", layout.isProgressBarShown());
}
@SmallTest
public void testWrongTheme() {
// Test the error message when using the wrong theme
mContext = new ContextThemeWrapper(getInstrumentation().getContext(),
android.R.style.Theme);
try {
new SetupWizardLayout(mContext);
fail("Should have thrown InflateException");
} catch (InflateException e) {
assertEquals("Exception message should mention correct theme to use",
"Unable to inflate layout. Are you using @style/SuwThemeMaterial "
+ "(or its descendant) as your theme?", e.getMessage());
}
}
private void assertDefaultTemplateInflated(SetupWizardLayout layout) {
View decorView = layout.findViewById(R.id.suw_layout_decor);
View navbar = layout.findViewById(R.id.suw_layout_navigation_bar);