use of android.view.InflateException in project android_frameworks_base by ResurrectionRemix.
the class TransitionInflater method createCustom.
private Object createCustom(AttributeSet attrs, Class expectedType, String tag) {
String className = attrs.getAttributeValue(null, "class");
if (className == null) {
throw new InflateException(tag + " tag must have a 'class' attribute");
}
try {
synchronized (sConstructors) {
Constructor constructor = sConstructors.get(className);
if (constructor == null) {
Class c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
if (c != null) {
constructor = c.getConstructor(sConstructorSignature);
constructor.setAccessible(true);
sConstructors.put(className, constructor);
}
}
return constructor.newInstance(mContext, attrs);
}
} catch (InstantiationException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (ClassNotFoundException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (InvocationTargetException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (NoSuchMethodException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (IllegalAccessException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
}
}
use of android.view.InflateException in project android_frameworks_base by ResurrectionRemix.
the class Transition method parseMatchOrder.
private static int[] parseMatchOrder(String matchOrderString) {
StringTokenizer st = new StringTokenizer(matchOrderString, ",");
int[] matches = new int[st.countTokens()];
int index = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
if (MATCH_ID_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_ID;
} else if (MATCH_INSTANCE_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_INSTANCE;
} else if (MATCH_NAME_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_NAME;
} else if (MATCH_VIEW_NAME_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_NAME;
} else if (MATCH_ITEM_ID_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_ITEM_ID;
} else if (token.isEmpty()) {
int[] smallerMatches = new int[matches.length - 1];
System.arraycopy(matches, 0, smallerMatches, 0, index);
matches = smallerMatches;
index--;
} else {
throw new InflateException("Unknown match type in matchOrder: '" + token + "'");
}
index++;
}
return matches;
}
use of android.view.InflateException in project discreet-app-rate by PomepuyN.
the class AppRate method showAppRate.
@SuppressLint("NewApi")
private void showAppRate() {
if (view != 0) {
mainView = new FrameLayout(activity);
try {
activity.getLayoutInflater().inflate(view, mainView);
} catch (InflateException e) {
mainView = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.app_rate, null);
view = 0;
} catch (Resources.NotFoundException e) {
mainView = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.app_rate, null);
view = 0;
}
} else {
mainView = (ViewGroup) activity.getLayoutInflater().inflate(R.layout.app_rate, null);
}
View close = (View) mainView.findViewById(R.id.dar_close);
TextView rateElement = (TextView) mainView.findViewById(R.id.dar_rate_element);
ViewGroup container = (ViewGroup) mainView.findViewById(R.id.dar_container);
if (container != null) {
if (fromTop) {
if (container.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) container.getLayoutParams();
lp.gravity = Gravity.TOP;
container.setLayoutParams(lp);
} else if (container.getParent() instanceof RelativeLayout) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) container.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
container.setLayoutParams(lp);
}
} else {
if (container.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) container.getLayoutParams();
lp.gravity = Gravity.BOTTOM;
container.setLayoutParams(lp);
} else if (container.getParent() instanceof RelativeLayout) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) container.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
container.setLayoutParams(lp);
}
}
}
if (rateElement != null) {
rateElement.setText(text);
final String packageName = this.packageName;
rateElement.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activity.startActivity(intent);
hideAllViews(mainView);
editor.putBoolean(KEY_CLICKED, true);
commitEditor();
if (onShowListener != null)
onShowListener.onRateAppClicked();
}
});
}
if (close != null) {
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideAllViews(mainView);
if (onShowListener != null)
onShowListener.onRateAppDismissed();
}
});
}
if (view == 0) {
if (theme == AppRateTheme.LIGHT) {
PorterDuff.Mode mMode = PorterDuff.Mode.SRC_ATOP;
Drawable d = activity.getResources().getDrawable(R.drawable.ic_action_remove);
d.setColorFilter(Color.BLACK, mMode);
((ImageView) close).setImageDrawable(d);
rateElement.setTextColor(Color.BLACK);
container.setBackgroundColor(0X88ffffff);
if (Build.VERSION.SDK_INT >= 16) {
close.setBackground(activity.getResources().getDrawable(R.drawable.selectable_button_light));
} else {
close.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.selectable_button_light));
}
} else {
Drawable d = activity.getResources().getDrawable(R.drawable.ic_action_remove);
d.clearColorFilter();
((ImageView) close).setImageDrawable(d);
container.setBackgroundColor(0Xaa000000);
if (Build.VERSION.SDK_INT >= 16) {
close.setBackground(activity.getResources().getDrawable(R.drawable.selectable_button_dark));
} else {
close.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.selectable_button_dark));
}
}
}
// Manage translucent themes
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && container != null) {
Window win = activity.getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
if (fromTop) {
boolean isTranslucent = Utils.hasFlag(winParams.flags, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
int translucentLolliPop = activity.getWindow().getDecorView().getSystemUiVisibility();
boolean isTranslucentLolliPop = (translucentLolliPop == View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
if (isTranslucent || isTranslucentLolliPop) {
if (debug)
LogD("Activity is translucent");
if (container.getParent() instanceof FrameLayout) {
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) container.getLayoutParams();
lp.topMargin = Utils.getActionStatusBarHeight(activity);
container.setLayoutParams(lp);
} else if (container.getParent() instanceof RelativeLayout) {
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) container.getLayoutParams();
lp.topMargin = Utils.getActionStatusBarHeight(activity);
container.setLayoutParams(lp);
}
}
} else {
boolean isTranslucent = Utils.hasFlag(winParams.flags, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (isTranslucent) {
if (debug)
LogD("Activity is translucent");
Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int orientation = display.getRotation();
ViewGroup.MarginLayoutParams lp = null;
if (container.getParent() instanceof FrameLayout) {
lp = (FrameLayout.LayoutParams) container.getLayoutParams();
} else if (container.getParent() instanceof RelativeLayout) {
lp = (RelativeLayout.LayoutParams) container.getLayoutParams();
}
if (lp != null) {
switch(orientation) {
case Surface.ROTATION_0:
case Surface.ROTATION_180:
lp.bottomMargin = Utils.getSoftbuttonsbarHeight(activity);
container.setLayoutParams(lp);
break;
case Surface.ROTATION_90:
case Surface.ROTATION_270:
lp.rightMargin = Utils.getSoftbuttonsbarWidth(activity);
container.setLayoutParams(lp);
break;
}
}
}
}
}
if (delay > 0) {
activity.getWindow().getDecorView().postDelayed(new Runnable() {
@Override
public void run() {
displayViews(mainView);
}
}, delay);
} else {
displayViews(mainView);
}
}
use of android.view.InflateException in project HoloEverywhere by Prototik.
the class SupportMenuInflater method inflate.
/**
* Inflate a menu hierarchy from the specified XML resource. Throws
* {@link InflateException} if there is an error.
*
* @param menuRes Resource ID for an XML layout resource to load (e.g.,
* <code>R.menu.main_activity</code>)
* @param menu The Menu to inflate into. The items and submenus will be
* added to this Menu.
*/
@Override
public void inflate(int menuRes, Menu menu) {
// If we're not dealing with a SupportMenu instance, let super handle
if (!(menu instanceof SupportMenu)) {
super.inflate(menuRes, menu);
return;
}
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, menu);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null)
parser.close();
}
}
use of android.view.InflateException in project HoloEverywhere by Prototik.
the class LayoutInflater method _createView.
public View _createView(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
Constructor<? extends View> constructor = sConstructorMap.get(name);
Class<? extends View> clazz = null;
try {
if (constructor == null) {
clazz = mContext.getClassLoader().loadClass(prefix != null ? prefix + name : name).asSubclass(View.class);
if (mFilter != null && clazz != null) {
boolean allowed = mFilter.onLoadClass(clazz);
if (!allowed) {
failNotAllowed(name, prefix, attrs);
}
}
constructor = clazz.getConstructor(sConstructorSignature);
sConstructorMap.put(name, constructor);
} else {
if (mFilter != null) {
Boolean allowedState = mFilterMap.get(name);
if (allowedState == null) {
clazz = mContext.getClassLoader().loadClass(prefix != null ? prefix + name : name).asSubclass(View.class);
boolean allowed = clazz != null && mFilter.onLoadClass(clazz);
mFilterMap.put(name, allowed);
if (!allowed) {
failNotAllowed(name, prefix, attrs);
}
} else if (allowedState.equals(Boolean.FALSE)) {
failNotAllowed(name, prefix, attrs);
}
}
}
Object[] args = mConstructorArgs;
args[1] = attrs;
final View view = constructor.newInstance(args);
if (view instanceof ViewStub) {
final ViewStub viewStub = (ViewStub) view;
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
viewStub.setLayoutInflater(this);
}
}
return view;
} catch (NoSuchMethodException e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (prefix != null ? prefix + name : name));
ie.initCause(e);
throw ie;
} catch (ClassCastException e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Class is not a View " + (prefix != null ? prefix + name : name));
ie.initCause(e);
throw ie;
} catch (ClassNotFoundException e) {
throw e;
} catch (Exception e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (clazz == null ? "<unknown>" : clazz.getName()));
ie.initCause(e);
throw ie;
}
}
Aggregations