Search in sources :

Example 71 with TypedArray

use of android.content.res.TypedArray in project platform_frameworks_base by android.

the class InputMethodManagerService method showInputMethodMenu.

private void showInputMethodMenu(boolean showAuxSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
    final Context context = mContext;
    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 = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, 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 Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
        mDialogBuilder = new AlertDialog.Builder(settingsContext);
        mDialogBuilder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        });
        final Context dialogContext = mDialogBuilder.getContext();
        final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
        a.recycle();
        mDialogBuilder.setIcon(dialogIcon);
        final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
        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(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
        hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSettings.setShowImeWithHardKeyboard(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
        final OnClickListener choiceListener = new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    final 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);
                    }
                }
            }
        };
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
        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");
        updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
        mSwitchingDialog.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodInfo(android.view.inputmethod.InputMethodInfo) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) OnCancelListener(android.content.DialogInterface.OnCancelListener) IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Drawable(android.graphics.drawable.Drawable) View(android.view.View) TextView(android.widget.TextView) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem) ContextThemeWrapper(android.view.ContextThemeWrapper) Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Example 72 with TypedArray

use of android.content.res.TypedArray in project platform_frameworks_base by android.

the class ShortcutParser method parseShortcutAttributes.

private static ShortcutInfo parseShortcutAttributes(ShortcutService service, AttributeSet attrs, String packageName, ComponentName activity, @UserIdInt int userId, int rank) {
    final TypedArray sa = service.mContext.getResources().obtainAttributes(attrs, R.styleable.Shortcut);
    try {
        if (sa.getType(R.styleable.Shortcut_shortcutId) != TypedValue.TYPE_STRING) {
            Log.w(TAG, "android:shortcutId must be string literal. activity=" + activity);
            return null;
        }
        final String id = sa.getNonResourceString(R.styleable.Shortcut_shortcutId);
        final boolean enabled = sa.getBoolean(R.styleable.Shortcut_enabled, true);
        final int iconResId = sa.getResourceId(R.styleable.Shortcut_icon, 0);
        final int titleResId = sa.getResourceId(R.styleable.Shortcut_shortcutShortLabel, 0);
        final int textResId = sa.getResourceId(R.styleable.Shortcut_shortcutLongLabel, 0);
        final int disabledMessageResId = sa.getResourceId(R.styleable.Shortcut_shortcutDisabledMessage, 0);
        if (TextUtils.isEmpty(id)) {
            Log.w(TAG, "android:shortcutId must be provided. activity=" + activity);
            return null;
        }
        if (titleResId == 0) {
            Log.w(TAG, "android:shortcutShortLabel must be provided. activity=" + activity);
            return null;
        }
        return createShortcutFromManifest(service, userId, id, packageName, activity, titleResId, textResId, disabledMessageResId, rank, iconResId, enabled);
    } finally {
        sa.recycle();
    }
}
Also used : TypedArray(android.content.res.TypedArray)

Example 73 with TypedArray

use of android.content.res.TypedArray in project platform_frameworks_base by android.

the class Keyboard method parseKeyboardAttributes.

private void parseKeyboardAttributes(Resources res, XmlResourceParser parser) {
    TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), com.android.internal.R.styleable.Keyboard);
    mDefaultWidth = getDimensionOrFraction(a, com.android.internal.R.styleable.Keyboard_keyWidth, mDisplayWidth, mDisplayWidth / 10);
    mDefaultHeight = getDimensionOrFraction(a, com.android.internal.R.styleable.Keyboard_keyHeight, mDisplayHeight, 50);
    mDefaultHorizontalGap = getDimensionOrFraction(a, com.android.internal.R.styleable.Keyboard_horizontalGap, mDisplayWidth, 0);
    mDefaultVerticalGap = getDimensionOrFraction(a, com.android.internal.R.styleable.Keyboard_verticalGap, mDisplayHeight, 0);
    mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
    // Square it for comparison
    mProximityThreshold = mProximityThreshold * mProximityThreshold;
    a.recycle();
}
Also used : TypedArray(android.content.res.TypedArray)

Example 74 with TypedArray

use of android.content.res.TypedArray in project platform_frameworks_base by android.

the class TransitionInflater method getTargetIds.

private void getTargetIds(XmlPullParser parser, AttributeSet attrs, Transition transition) throws XmlPullParserException, IOException {
    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();
    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 (name.equals("target")) {
            TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TransitionTarget);
            int id = a.getResourceId(R.styleable.TransitionTarget_targetId, 0);
            String transitionName;
            if (id != 0) {
                transition.addTarget(id);
            } else if ((id = a.getResourceId(R.styleable.TransitionTarget_excludeId, 0)) != 0) {
                transition.excludeTarget(id, true);
            } else if ((transitionName = a.getString(R.styleable.TransitionTarget_targetName)) != null) {
                transition.addTarget(transitionName);
            } else if ((transitionName = a.getString(R.styleable.TransitionTarget_excludeName)) != null) {
                transition.excludeTarget(transitionName, true);
            } else {
                String className = a.getString(R.styleable.TransitionTarget_excludeClass);
                try {
                    if (className != null) {
                        Class clazz = Class.forName(className);
                        transition.excludeTarget(clazz, true);
                    } else if ((className = a.getString(R.styleable.TransitionTarget_targetClass)) != null) {
                        Class clazz = Class.forName(className);
                        transition.addTarget(clazz);
                    }
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("Could not create " + className, e);
                }
            }
        } else {
            throw new RuntimeException("Unknown scene name: " + parser.getName());
        }
    }
}
Also used : TypedArray(android.content.res.TypedArray)

Example 75 with TypedArray

use of android.content.res.TypedArray in project platform_frameworks_base by android.

the class SuggestionSpan method initStyle.

private void initStyle(Context context) {
    if (context == null) {
        mMisspelledUnderlineThickness = 0;
        mEasyCorrectUnderlineThickness = 0;
        mAutoCorrectionUnderlineThickness = 0;
        mMisspelledUnderlineColor = Color.BLACK;
        mEasyCorrectUnderlineColor = Color.BLACK;
        mAutoCorrectionUnderlineColor = Color.BLACK;
        return;
    }
    int defStyleAttr = com.android.internal.R.attr.textAppearanceMisspelledSuggestion;
    TypedArray typedArray = context.obtainStyledAttributes(null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mMisspelledUnderlineThickness = typedArray.getDimension(com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mMisspelledUnderlineColor = typedArray.getColor(com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
    defStyleAttr = com.android.internal.R.attr.textAppearanceEasyCorrectSuggestion;
    typedArray = context.obtainStyledAttributes(null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mEasyCorrectUnderlineThickness = typedArray.getDimension(com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mEasyCorrectUnderlineColor = typedArray.getColor(com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
    defStyleAttr = com.android.internal.R.attr.textAppearanceAutoCorrectionSuggestion;
    typedArray = context.obtainStyledAttributes(null, com.android.internal.R.styleable.SuggestionSpan, defStyleAttr, 0);
    mAutoCorrectionUnderlineThickness = typedArray.getDimension(com.android.internal.R.styleable.SuggestionSpan_textUnderlineThickness, 0);
    mAutoCorrectionUnderlineColor = typedArray.getColor(com.android.internal.R.styleable.SuggestionSpan_textUnderlineColor, Color.BLACK);
}
Also used : TypedArray(android.content.res.TypedArray) TextPaint(android.text.TextPaint)

Aggregations

TypedArray (android.content.res.TypedArray)2031 Paint (android.graphics.Paint)193 TypedValue (android.util.TypedValue)190 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)162 Drawable (android.graphics.drawable.Drawable)119 Resources (android.content.res.Resources)118 View (android.view.View)117 Context (android.content.Context)80 XmlResourceParser (android.content.res.XmlResourceParser)80 ColorStateList (android.content.res.ColorStateList)78 AttributeSet (android.util.AttributeSet)78 IOException (java.io.IOException)77 SuppressLint (android.annotation.SuppressLint)66 TextPaint (android.text.TextPaint)63 TextView (android.widget.TextView)63 ViewGroup (android.view.ViewGroup)59 Bundle (android.os.Bundle)48 Point (android.graphics.Point)43 LayoutInflater (android.view.LayoutInflater)42 ImageView (android.widget.ImageView)40