use of android.content.res.TypedArray in project android_frameworks_base by ParanoidAndroid.
the class PhoneWindowManager method addStartingWindow.
/** {@inheritDoc} */
@Override
public View addStartingWindow(IBinder appToken, String packageName, int theme, CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, int icon, int windowFlags) {
if (!SHOW_STARTING_ANIMATIONS) {
return null;
}
if (packageName == null) {
return null;
}
WindowManager wm = null;
View view = null;
try {
Context context = mContext;
if (DEBUG_STARTING_WINDOW)
Slog.d(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" + Integer.toHexString(theme));
try {
context = context.createPackageContext(packageName, 0);
if (theme != context.getThemeResId()) {
context.setTheme(theme);
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
Window win = PolicyManager.makeNewWindow(context);
final TypedArray ta = win.getWindowStyle();
if (ta.getBoolean(com.android.internal.R.styleable.Window_windowDisablePreview, false) || ta.getBoolean(com.android.internal.R.styleable.Window_windowShowWallpaper, false)) {
return null;
}
Resources r = context.getResources();
win.setTitle(r.getText(labelRes, nonLocalizedLabel));
win.setType(WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
// Force the window flags: this is a fake window, so it is not really
// touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
// flag because we do know that the next window will take input
// focus, so we want to get the IME window up on top of us right away.
win.setFlags(windowFlags | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, windowFlags | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
if (!compatInfo.supportsScreen()) {
win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
}
win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
final WindowManager.LayoutParams params = win.getAttributes();
params.token = appToken;
params.packageName = packageName;
params.windowAnimations = win.getWindowStyle().getResourceId(com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
params.setTitle("Starting " + packageName);
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
view = win.getDecorView();
if (win.isFloating()) {
// earlier.)
return null;
}
if (DEBUG_STARTING_WINDOW)
Slog.d(TAG, "Adding starting window for " + packageName + " / " + appToken + ": " + (view.getParent() != null ? view : null));
wm.addView(view, params);
// window manager... which we can tell by it having a parent.
return view.getParent() != null ? view : null;
} catch (WindowManager.BadTokenException e) {
// ignore
Log.w(TAG, appToken + " already running, starting window not displayed");
} catch (RuntimeException e) {
// don't crash if something else bad happens, for example a
// failure loading resources because we are loading from an app
// on external storage that has been unmounted.
Log.w(TAG, appToken + " failed creating starting window", e);
} finally {
if (view != null && view.getParent() == null) {
Log.w(TAG, "view not successfully added to wm, removing view");
wm.removeViewImmediate(view);
}
}
return null;
}
use of android.content.res.TypedArray in project android_frameworks_base by ParanoidAndroid.
the class AppWidgetServiceImpl method parseProviderInfoXml.
private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
Provider p = null;
ActivityInfo activityInfo = ri.activityInfo;
XmlResourceParser parser = null;
try {
parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(), AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
if (parser == null) {
Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " + "AppWidget provider '" + component + '\'');
return null;
}
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
// drain whitespace, comments, etc.
}
String nodeName = parser.getName();
if (!"appwidget-provider".equals(nodeName)) {
Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" + " AppWidget provider '" + component + '\'');
return null;
}
p = new Provider();
AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
info.provider = component;
p.uid = activityInfo.applicationInfo.uid;
Resources res = mContext.getPackageManager().getResourcesForApplicationAsUser(activityInfo.packageName, mUserId);
TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AppWidgetProviderInfo);
// These dimensions has to be resolved in the application's context.
// We simply send back the raw complex data, which will be
// converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
TypedValue value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
info.minWidth = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
info.minHeight = value != null ? value.data : 0;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
info.minResizeWidth = value != null ? value.data : info.minWidth;
value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
info.minResizeHeight = value != null ? value.data : info.minHeight;
info.updatePeriodMillis = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
info.initialLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialKeyguardLayout, 0);
String className = sa.getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
if (className != null) {
info.configure = new ComponentName(component.getPackageName(), className);
}
info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
info.icon = ri.getIconResource();
info.previewImage = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
info.autoAdvanceViewId = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
info.resizeMode = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, AppWidgetProviderInfo.RESIZE_NONE);
info.widgetCategory = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
sa.recycle();
} catch (Exception e) {
// Ok to catch Exception here, because anything going wrong because
// of what a client process passes to us should not be fatal for the
// system process.
Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
return null;
} finally {
if (parser != null)
parser.close();
}
return p;
}
use of android.content.res.TypedArray in project android_frameworks_base by ParanoidAndroid.
the class InputMethodManagerService method showInputMethodMenuInternal.
private void showInputMethodMenuInternal(boolean showSubtypes) {
if (DEBUG)
Slog.v(TAG, "Show switching menu");
final Context context = getUiContext();
final boolean isScreenLocked = isScreenLocked();
final String lastInputMethodId = mSettings.getSelectedInputMethod();
int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
if (DEBUG)
Slog.v(TAG, "Current IME: " + lastInputMethodId);
synchronized (mMethodMap) {
final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
if (immis == null || immis.size() == 0) {
return;
}
hideInputMethodMenuLocked();
final List<ImeSubtypeListItem> imList = mImListManager.getSortedInputMethodAndSubtypeList(showSubtypes, mInputShown, isScreenLocked);
if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
if (currentSubtype != null) {
final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
}
}
final int N = imList.size();
mIms = new InputMethodInfo[N];
mSubtypeIds = new int[N];
int checkedItem = 0;
for (int i = 0; i < N; ++i) {
final ImeSubtypeListItem item = imList.get(i);
mIms[i] = item.mImi;
mSubtypeIds[i] = item.mSubtypeId;
if (mIms[i].getId().equals(lastInputMethodId)) {
int subtypeId = mSubtypeIds[i];
if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
checkedItem = i;
}
}
}
final TypedArray a = context.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
mDialogBuilder = new AlertDialog.Builder(context).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
hideInputMethodMenu();
}
}).setIcon(a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogTitle));
a.recycle();
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerService.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
final Switch hardKeySwitch = ((Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch));
hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mWindowManagerService.setHardKeyboardEnabled(isChecked);
// Ensure that the input method dialog is dismissed when changing
// the hardware keyboard state.
hideInputMethodMenu();
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, com.android.internal.R.layout.simple_list_item_2_single_choice, imList, checkedItem);
mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, new AlertDialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
synchronized (mMethodMap) {
if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
return;
}
InputMethodInfo im = mIms[which];
int subtypeId = mSubtypeIds[which];
adapter.mCheckedItem = which;
adapter.notifyDataSetChanged();
hideInputMethodMenu();
if (im != null) {
if ((subtypeId < 0) || (subtypeId >= im.getSubtypeCount())) {
subtypeId = NOT_A_SUBTYPE_ID;
}
setInputMethodLocked(im.getId(), subtypeId);
}
}
}
});
if (showSubtypes && !isScreenLocked) {
mDialogBuilder.setPositiveButton(com.android.internal.R.string.configure_input_methods, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
showConfigureInputMethods();
}
});
}
mSwitchingDialog = mDialogBuilder.create();
mSwitchingDialog.setCanceledOnTouchOutside(true);
mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
mSwitchingDialog.show();
}
}
use of android.content.res.TypedArray in project android_frameworks_base by ParanoidAndroid.
the class InputManagerService method visitKeyboardLayoutsInPackage.
private void visitKeyboardLayoutsInPackage(PackageManager pm, ActivityInfo receiver, String keyboardName, KeyboardLayoutVisitor visitor) {
Bundle metaData = receiver.metaData;
if (metaData == null) {
return;
}
int configResId = metaData.getInt(InputManager.META_DATA_KEYBOARD_LAYOUTS);
if (configResId == 0) {
Log.w(TAG, "Missing meta-data '" + InputManager.META_DATA_KEYBOARD_LAYOUTS + "' on receiver " + receiver.packageName + "/" + receiver.name);
return;
}
CharSequence receiverLabel = receiver.loadLabel(pm);
String collection = receiverLabel != null ? receiverLabel.toString() : "";
try {
Resources resources = pm.getResourcesForApplication(receiver.applicationInfo);
XmlResourceParser parser = resources.getXml(configResId);
try {
XmlUtils.beginDocument(parser, "keyboard-layouts");
for (; ; ) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null) {
break;
}
if (element.equals("keyboard-layout")) {
TypedArray a = resources.obtainAttributes(parser, com.android.internal.R.styleable.KeyboardLayout);
try {
String name = a.getString(com.android.internal.R.styleable.KeyboardLayout_name);
String label = a.getString(com.android.internal.R.styleable.KeyboardLayout_label);
int keyboardLayoutResId = a.getResourceId(com.android.internal.R.styleable.KeyboardLayout_keyboardLayout, 0);
if (name == null || label == null || keyboardLayoutResId == 0) {
Log.w(TAG, "Missing required 'name', 'label' or 'keyboardLayout' " + "attributes in keyboard layout " + "resource from receiver " + receiver.packageName + "/" + receiver.name);
} else {
String descriptor = KeyboardLayoutDescriptor.format(receiver.packageName, receiver.name, name);
if (keyboardName == null || name.equals(keyboardName)) {
visitor.visitKeyboardLayout(resources, descriptor, label, collection, keyboardLayoutResId);
}
}
} finally {
a.recycle();
}
} else {
Log.w(TAG, "Skipping unrecognized element '" + element + "' in keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name);
}
}
} finally {
parser.close();
}
} catch (Exception ex) {
Log.w(TAG, "Could not parse keyboard layout resource from receiver " + receiver.packageName + "/" + receiver.name, ex);
}
}
use of android.content.res.TypedArray in project android_frameworks_base by ParanoidAndroid.
the class SimpleInflater method readItem.
public void readItem(AttributeSet attrs) {
TypedArray a = mContext.obtainStyledAttributes(attrs, com.android.internal.R.styleable.MenuItem);
// Inherit attributes from the group as default value
int itemId = a.getResourceId(R.styleable.MenuItem_android_id, 0);
final int category = a.getInt(R.styleable.MenuItem_android_menuCategory, 0);
final int order = a.getInt(R.styleable.MenuItem_android_orderInCategory, 0);
CharSequence itemTitle = a.getText(R.styleable.MenuItem_android_title);
CharSequence itemTitleCondensed = a.getText(R.styleable.MenuItem_android_titleCondensed);
int itemIconResId = a.getResourceId(R.styleable.MenuItem_android_icon, 0);
String itemAlphabeticShortcut = a.getString(R.styleable.MenuItem_android_alphabeticShortcut);
String itemNumericShortcut = a.getString(R.styleable.MenuItem_android_numericShortcut);
int itemCheckable = 0;
if (a.hasValue(R.styleable.MenuItem_android_checkable)) {
// Item has attribute checkable, use it
itemCheckable = a.getBoolean(R.styleable.MenuItem_android_checkable, false) ? 1 : 0;
}
boolean itemChecked = a.getBoolean(R.styleable.MenuItem_android_checked, false);
boolean itemVisible = a.getBoolean(R.styleable.MenuItem_android_visible, false);
boolean itemEnabled = a.getBoolean(R.styleable.MenuItem_android_enabled, false);
a.recycle();
}
Aggregations