use of android.view.InflateException in project Transitions-Everywhere by andkulikov.
the class TransitionInflater method createTransitionFromXml.
//
// Transition loading
//
@Nullable
private Transition createTransitionFromXml(@NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Transition parent) throws XmlPullParserException, IOException {
Transition transition = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
TransitionSet transitionSet = (parent instanceof TransitionSet) ? (TransitionSet) parent : null;
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if ("fade".equals(name)) {
transition = new Fade(mContext, attrs);
} else if ("changeBounds".equals(name)) {
transition = new ChangeBounds(mContext, attrs);
} else if ("slide".equals(name)) {
transition = new Slide(mContext, attrs);
} else if ("explode".equals(name)) {
transition = new Explode(mContext, attrs);
} else if ("changeImageTransform".equals(name)) {
transition = new ChangeImageTransform(mContext, attrs);
} else if ("changeTransform".equals(name)) {
transition = new ChangeTransform(mContext, attrs);
} else if ("changeClipBounds".equals(name)) {
transition = new ChangeClipBounds(mContext, attrs);
} else if ("autoTransition".equals(name)) {
transition = new AutoTransition(mContext, attrs);
} else if ("recolor".equals(name)) {
transition = new Recolor(mContext, attrs);
} else if ("changeScroll".equals(name)) {
transition = new ChangeScroll(mContext, attrs);
} else if ("transitionSet".equals(name)) {
transition = new TransitionSet(mContext, attrs);
} else if ("scale".equals(name)) {
transition = new Scale(mContext, attrs);
} else if ("translation".equals(name)) {
transition = new TranslationTransition(mContext, attrs);
} else if ("transition".equals(name)) {
transition = (Transition) createCustom(attrs, Transition.class, "transition");
} else if ("targets".equals(name) && parent != null) {
getTargetIds(parser, attrs, parent);
} else if ("arcMotion".equals(name) && parent != null) {
parent.setPathMotion(new ArcMotion(mContext, attrs));
} else if ("pathMotion".equals(name) && parent != null) {
parent.setPathMotion((PathMotion) createCustom(attrs, PathMotion.class, "pathMotion"));
} else if ("patternPathMotion".equals(name) && parent != null) {
parent.setPathMotion(new PatternPathMotion(mContext, attrs));
} else {
throw new RuntimeException("Unknown scene name: " + parser.getName());
}
if (transition != null) {
if (!parser.isEmptyElementTag()) {
createTransitionFromXml(parser, attrs, transition);
}
if (transitionSet != null) {
transitionSet.addTransition(transition);
transition = null;
} else if (parent != null) {
throw new InflateException("Could not add transition to another transition.");
}
}
}
return transition;
}
use of android.view.InflateException in project focus-android by mozilla-mobile.
the class GeckoViewPrompt method onDateTimePrompt.
@Override
public void onDateTimePrompt(final GeckoSession session, final String title, final int type, final String value, final String min, final String max, final TextCallback callback) {
final Activity activity = mActivity;
if (activity == null) {
callback.dismiss();
return;
}
final String format;
if (type == DATETIME_TYPE_DATE) {
format = "yyyy-MM-dd";
} else if (type == DATETIME_TYPE_MONTH) {
format = "yyyy-MM";
} else if (type == DATETIME_TYPE_WEEK) {
format = "yyyy-'W'ww";
} else if (type == DATETIME_TYPE_TIME) {
format = "HH:mm";
} else if (type == DATETIME_TYPE_DATETIME_LOCAL) {
format = "yyyy-MM-dd'T'HH:mm";
} else {
throw new UnsupportedOperationException();
}
final SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.ROOT);
final Date minDate = parseDate(formatter, min, /* defaultToNow */
false);
final Date maxDate = parseDate(formatter, max, /* defaultToNow */
false);
final Date date = parseDate(formatter, value, /* defaultToNow */
true);
final Calendar cal = formatter.getCalendar();
cal.setTime(date);
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final LayoutInflater inflater = LayoutInflater.from(builder.getContext());
final DatePicker datePicker;
if (type == DATETIME_TYPE_DATE || type == DATETIME_TYPE_MONTH || type == DATETIME_TYPE_WEEK || type == DATETIME_TYPE_DATETIME_LOCAL) {
final int resId = builder.getContext().getResources().getIdentifier("date_picker_dialog", "layout", "android");
DatePicker picker = null;
if (resId != 0) {
try {
picker = (DatePicker) inflater.inflate(resId, /* root */
null);
} catch (final ClassCastException | InflateException e) {
}
}
if (picker == null) {
picker = new DatePicker(builder.getContext());
}
picker.init(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), /* listener */
null);
if (minDate != null) {
picker.setMinDate(minDate.getTime());
}
if (maxDate != null) {
picker.setMaxDate(maxDate.getTime());
}
datePicker = picker;
} else {
datePicker = null;
}
final TimePicker timePicker;
if (type == DATETIME_TYPE_TIME || type == DATETIME_TYPE_DATETIME_LOCAL) {
final int resId = builder.getContext().getResources().getIdentifier("time_picker_dialog", "layout", "android");
TimePicker picker = null;
if (resId != 0) {
try {
picker = (TimePicker) inflater.inflate(resId, /* root */
null);
} catch (final ClassCastException | InflateException e) {
}
}
if (picker == null) {
picker = new TimePicker(builder.getContext());
}
setTimePickerTime(picker, cal);
picker.setIs24HourView(DateFormat.is24HourFormat(builder.getContext()));
timePicker = picker;
} else {
timePicker = null;
}
final LinearLayout container = addStandardLayout(builder, title, /* msg */
null);
container.setPadding(/* left */
0, /* top */
0, /* right */
0, /* bottom */
0);
if (datePicker != null) {
container.addView(datePicker);
}
if (timePicker != null) {
container.addView(timePicker);
}
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (which == DialogInterface.BUTTON_NEUTRAL) {
// Clear
callback.confirm("");
return;
}
if (datePicker != null) {
cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
}
if (timePicker != null) {
setCalendarTime(cal, timePicker);
}
callback.confirm(formatter.format(cal.getTime()));
}
};
builder.setNegativeButton(android.R.string.cancel, /* listener */
null).setNeutralButton(R.string.gv_prompt_clear, listener).setPositiveButton(android.R.string.ok, listener);
createStandardDialog(builder, callback).show();
}
use of android.view.InflateException in project MDM-Android-Agent by wso2-attic.
the class MenuInflater 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.
*/
public void inflate(int menuRes, Menu menu) {
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 Phonograph by kabouzeid.
the class ChangelogDialog method onCreateDialog.
@SuppressLint("InflateParams")
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final View customView;
try {
customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_web_view, null);
} catch (InflateException e) {
e.printStackTrace();
return new MaterialDialog.Builder(getActivity()).title(android.R.string.dialog_alert_title).content("This device doesn't support web view, which is necessary to view the change log. It is missing a system component.").positiveText(android.R.string.ok).build();
}
MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.changelog).customView(customView, false).positiveText(android.R.string.ok).showListener(dialog1 -> {
if (getActivity() != null)
setChangelogRead(getActivity());
}).build();
final WebView webView = customView.findViewById(R.id.web_view);
try {
// Load from phonograph-changelog.html in the assets folder
StringBuilder buf = new StringBuilder();
InputStream json = getActivity().getAssets().open("phonograph-changelog.html");
BufferedReader in = new BufferedReader(new InputStreamReader(json, "UTF-8"));
String str;
while ((str = in.readLine()) != null) buf.append(str);
in.close();
// Inject color values for WebView body background and links
final String backgroundColor = colorToCSS(ATHUtil.resolveColor(getActivity(), R.attr.md_background_color, Color.parseColor(ThemeSingleton.get().darkTheme ? "#424242" : "#ffffff")));
final String contentColor = colorToCSS(Color.parseColor(ThemeSingleton.get().darkTheme ? "#ffffff" : "#000000"));
final String changeLog = buf.toString().replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor)).replace("{link-color}", colorToCSS(ThemeSingleton.get().positiveColor.getDefaultColor())).replace("{link-color-active}", colorToCSS(ColorUtil.lightenColor(ThemeSingleton.get().positiveColor.getDefaultColor())));
webView.loadData(changeLog, "text/html", "UTF-8");
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
return dialog;
}
use of android.view.InflateException in project android_packages_apps_Snap by LineageOS.
the class PreferenceInflater method inflate.
private CameraPreference inflate(XmlPullParser parser) {
AttributeSet attrs = Xml.asAttributeSet(parser);
ArrayList<CameraPreference> list = new ArrayList<CameraPreference>();
Object[] args = new Object[] { mContext, attrs };
try {
for (int type = parser.next(); type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
if (type != XmlPullParser.START_TAG)
continue;
CameraPreference pref = newPreference(parser.getName(), args);
int depth = parser.getDepth();
if (depth > list.size()) {
list.add(pref);
} else {
list.set(depth - 1, pref);
}
if (depth > 1) {
((PreferenceGroup) list.get(depth - 2)).addChild(pref);
}
}
if (list.size() == 0) {
throw new InflateException("No root element found");
}
return list.get(0);
} catch (XmlPullParserException e) {
throw new InflateException(e);
} catch (IOException e) {
throw new InflateException(parser.getPositionDescription(), e);
}
}
Aggregations