Example usage for android.util TypedValue TYPE_INT_BOOLEAN

List of usage examples for android.util TypedValue TYPE_INT_BOOLEAN

Introduction

In this page you can find the example usage for android.util TypedValue TYPE_INT_BOOLEAN.

Prototype

int TYPE_INT_BOOLEAN

To view the source code for android.util TypedValue TYPE_INT_BOOLEAN.

Click Source Link

Document

The data field holds 0 or 1 that was originally specified as "false" or "true".

Usage

From source file:com.android.settingslib.RestrictedSwitchPreference.java

public RestrictedSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    setWidgetLayoutResource(R.layout.restricted_switch_widget);
    mHelper = new RestrictedPreferenceHelper(context, this, attrs);
    if (attrs != null) {
        final TypedArray attributes = context.obtainStyledAttributes(attrs,
                R.styleable.RestrictedSwitchPreference);
        final TypedValue useAdditionalSummary = attributes
                .peekValue(R.styleable.RestrictedSwitchPreference_useAdditionalSummary);
        if (useAdditionalSummary != null) {
            mUseAdditionalSummary = (useAdditionalSummary.type == TypedValue.TYPE_INT_BOOLEAN
                    && useAdditionalSummary.data != 0);
        }// ww  w .  ja va 2s. com

        final TypedValue restrictedSwitchSummary = attributes
                .peekValue(R.styleable.RestrictedSwitchPreference_restrictedSwitchSummary);
        CharSequence data = null;
        if (restrictedSwitchSummary != null && restrictedSwitchSummary.type == TypedValue.TYPE_STRING) {
            if (restrictedSwitchSummary.resourceId != 0) {
                data = context.getString(restrictedSwitchSummary.resourceId);
            } else {
                data = restrictedSwitchSummary.string;
            }
        }
        mRestrictedSwitchSummary = data == null ? null : data.toString();
    }
    if (mRestrictedSwitchSummary == null) {
        mRestrictedSwitchSummary = context.getString(R.string.disabled_by_admin);
    }
    if (mUseAdditionalSummary) {
        setLayoutResource(R.layout.restricted_switch_preference);
        useAdminDisabledSummary(false);
    }
}

From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java

private static boolean isGuidedStepTheme(Context context) {
    int resId = android.support.v17.leanback.R.attr.guidedStepThemeFlag;
    TypedValue typedValue = new TypedValue();
    boolean found = context.getTheme().resolveAttribute(resId, typedValue, true);
    if (DEBUG)//  w  w  w.j a v  a 2  s .co  m
        Log.v(TAG, "Found guided step theme flag? " + found);
    return found && typedValue.type == TypedValue.TYPE_INT_BOOLEAN && typedValue.data != 0;
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

private static boolean isGuidedStepTheme(Context context) {
    int resId = R.attr.guidedStepThemeFlag;
    TypedValue typedValue = new TypedValue();
    boolean found = context.getTheme().resolveAttribute(resId, typedValue, true);
    if (DEBUG)//ww  w.jav a 2 s .co  m
        Log.v(TAG, "Found guided step theme flag? " + found);
    return found && typedValue.type == TypedValue.TYPE_INT_BOOLEAN && typedValue.data != 0;
}

From source file:android.content.pm.PackageParser.java

private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data,
        String[] outError) throws XmlPullParserException, IOException {

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData);

    if (data == null) {
        data = new Bundle();
    }/*from   w w w  .  ja  v  a 2  s. c  o  m*/

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name,
            0);
    if (name == null) {
        outError[0] = "<meta-data> requires an android:name attribute";
        sa.recycle();
        return null;
    }

    name = name.intern();

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource);
    if (v != null && v.resourceId != 0) {
        //Slog.i(TAG, "Meta data ref " + name + ": " + v);
        data.putInt(name, v.resourceId);
    } else {
        v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value);
        //Slog.i(TAG, "Meta data " + name + ": " + v);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                data.putString(name, cs != null ? cs.toString().intern() : null);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                data.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) {
                data.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                data.putFloat(name, v.getFloat());
            } else {
                if (!RIGID_PARSER) {
                    Slog.w(TAG,
                            "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: "
                                    + parser.getName() + " at " + mArchiveSourcePath + " "
                                    + parser.getPositionDescription());
                } else {
                    outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types";
                    data = null;
                }
            }
        } else {
            outError[0] = "<meta-data> requires an android:value or android:resource attribute";
            data = null;
        }
    }

    sa.recycle();

    XmlUtils.skipCurrentTag(parser);

    return data;
}