Search in sources :

Example 16 with TypedValue

use of android.util.TypedValue in project Libraries-for-Android-Developers by eoecn.

the class ShareActionProvider method onCreateActionView.

/**
     * {@inheritDoc}
     */
@Override
public View onCreateActionView() {
    // Create the view and set its data model.
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    ActivityChooserView activityChooserView = new ActivityChooserView(mContext);
    activityChooserView.setActivityChooserModel(dataModel);
    // Lookup and set the expand action icon.
    TypedValue outTypedValue = new TypedValue();
    mContext.getTheme().resolveAttribute(R.attr.actionModeShareDrawable, outTypedValue, true);
    Drawable drawable = mContext.getResources().getDrawable(outTypedValue.resourceId);
    activityChooserView.setExpandActivityOverflowButtonDrawable(drawable);
    activityChooserView.setProvider(this);
    // Set content description.
    activityChooserView.setDefaultActionButtonContentDescription(R.string.abs__shareactionprovider_share_with_application);
    activityChooserView.setExpandActivityOverflowButtonContentDescription(R.string.abs__shareactionprovider_share_with);
    return activityChooserView;
}
Also used : Drawable(android.graphics.drawable.Drawable) TypedValue(android.util.TypedValue)

Example 17 with TypedValue

use of android.util.TypedValue in project Libraries-for-Android-Developers by eoecn.

the class SuggestionsAdapter method formatUrl.

private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }
    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null), 0, url.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
Also used : SpannableString(android.text.SpannableString) TextAppearanceSpan(android.text.style.TextAppearanceSpan) TypedValue(android.util.TypedValue)

Example 18 with TypedValue

use of android.util.TypedValue in project android_frameworks_base by ParanoidAndroid.

the class AnimatorInflater method loadAnimator.

/**
     * Creates a new animation whose parameters come from the specified context and
     * attributes set.
     *
     * @param context the application environment
     * @param attrs the set of attributes holding the animation parameters
     */
private static ValueAnimator loadAnimator(Context context, AttributeSet attrs, ValueAnimator anim) throws NotFoundException {
    TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Animator);
    long duration = a.getInt(com.android.internal.R.styleable.Animator_duration, 300);
    long startDelay = a.getInt(com.android.internal.R.styleable.Animator_startOffset, 0);
    int valueType = a.getInt(com.android.internal.R.styleable.Animator_valueType, VALUE_TYPE_FLOAT);
    if (anim == null) {
        anim = new ValueAnimator();
    }
    TypeEvaluator evaluator = null;
    int valueFromIndex = com.android.internal.R.styleable.Animator_valueFrom;
    int valueToIndex = com.android.internal.R.styleable.Animator_valueTo;
    boolean getFloats = (valueType == VALUE_TYPE_FLOAT);
    TypedValue tvFrom = a.peekValue(valueFromIndex);
    boolean hasFrom = (tvFrom != null);
    int fromType = hasFrom ? tvFrom.type : 0;
    TypedValue tvTo = a.peekValue(valueToIndex);
    boolean hasTo = (tvTo != null);
    int toType = hasTo ? tvTo.type : 0;
    if ((hasFrom && (fromType >= TypedValue.TYPE_FIRST_COLOR_INT) && (fromType <= TypedValue.TYPE_LAST_COLOR_INT)) || (hasTo && (toType >= TypedValue.TYPE_FIRST_COLOR_INT) && (toType <= TypedValue.TYPE_LAST_COLOR_INT))) {
        // special case for colors: ignore valueType and get ints
        getFloats = false;
        anim.setEvaluator(new ArgbEvaluator());
    }
    if (getFloats) {
        float valueFrom;
        float valueTo;
        if (hasFrom) {
            if (fromType == TypedValue.TYPE_DIMENSION) {
                valueFrom = a.getDimension(valueFromIndex, 0f);
            } else {
                valueFrom = a.getFloat(valueFromIndex, 0f);
            }
            if (hasTo) {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = a.getDimension(valueToIndex, 0f);
                } else {
                    valueTo = a.getFloat(valueToIndex, 0f);
                }
                anim.setFloatValues(valueFrom, valueTo);
            } else {
                anim.setFloatValues(valueFrom);
            }
        } else {
            if (toType == TypedValue.TYPE_DIMENSION) {
                valueTo = a.getDimension(valueToIndex, 0f);
            } else {
                valueTo = a.getFloat(valueToIndex, 0f);
            }
            anim.setFloatValues(valueTo);
        }
    } else {
        int valueFrom;
        int valueTo;
        if (hasFrom) {
            if (fromType == TypedValue.TYPE_DIMENSION) {
                valueFrom = (int) a.getDimension(valueFromIndex, 0f);
            } else if ((fromType >= TypedValue.TYPE_FIRST_COLOR_INT) && (fromType <= TypedValue.TYPE_LAST_COLOR_INT)) {
                valueFrom = a.getColor(valueFromIndex, 0);
            } else {
                valueFrom = a.getInt(valueFromIndex, 0);
            }
            if (hasTo) {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = (int) a.getDimension(valueToIndex, 0f);
                } else if ((toType >= TypedValue.TYPE_FIRST_COLOR_INT) && (toType <= TypedValue.TYPE_LAST_COLOR_INT)) {
                    valueTo = a.getColor(valueToIndex, 0);
                } else {
                    valueTo = a.getInt(valueToIndex, 0);
                }
                anim.setIntValues(valueFrom, valueTo);
            } else {
                anim.setIntValues(valueFrom);
            }
        } else {
            if (hasTo) {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = (int) a.getDimension(valueToIndex, 0f);
                } else if ((toType >= TypedValue.TYPE_FIRST_COLOR_INT) && (toType <= TypedValue.TYPE_LAST_COLOR_INT)) {
                    valueTo = a.getColor(valueToIndex, 0);
                } else {
                    valueTo = a.getInt(valueToIndex, 0);
                }
                anim.setIntValues(valueTo);
            }
        }
    }
    anim.setDuration(duration);
    anim.setStartDelay(startDelay);
    if (a.hasValue(com.android.internal.R.styleable.Animator_repeatCount)) {
        anim.setRepeatCount(a.getInt(com.android.internal.R.styleable.Animator_repeatCount, 0));
    }
    if (a.hasValue(com.android.internal.R.styleable.Animator_repeatMode)) {
        anim.setRepeatMode(a.getInt(com.android.internal.R.styleable.Animator_repeatMode, ValueAnimator.RESTART));
    }
    if (evaluator != null) {
        anim.setEvaluator(evaluator);
    }
    final int resID = a.getResourceId(com.android.internal.R.styleable.Animator_interpolator, 0);
    if (resID > 0) {
        anim.setInterpolator(AnimationUtils.loadInterpolator(context, resID));
    }
    a.recycle();
    return anim;
}
Also used : TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue)

Example 19 with TypedValue

use of android.util.TypedValue in project android_frameworks_base by ParanoidAndroid.

the class Activity method attach.

final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token, int ident, Application application, Intent intent, ActivityInfo info, CharSequence title, Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances, Configuration config) {
    attachBaseContext(context);
    mFragments.attachActivity(this, mContainer, null);
    boolean floating = (intent.getFlags() & Intent.FLAG_FLOATING_WINDOW) == Intent.FLAG_FLOATING_WINDOW;
    boolean history = (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY;
    if (intent != null && floating && !history) {
        TypedArray styleArray = context.obtainStyledAttributes(info.theme, com.android.internal.R.styleable.Window);
        TypedValue backgroundValue = styleArray.peekValue(com.android.internal.R.styleable.Window_windowBackground);
        // Apps that have no title don't need no title bar
        TypedValue outValue = new TypedValue();
        boolean result = styleArray.getValue(com.android.internal.R.styleable.Window_windowNoTitle, outValue);
        if (backgroundValue != null && backgroundValue.toString().contains("light")) {
            context.getTheme().applyStyle(com.android.internal.R.style.Theme_DeviceDefault_FloatingWindowLight, true);
        } else {
            context.getTheme().applyStyle(com.android.internal.R.style.Theme_DeviceDefault_FloatingWindow, true);
        }
        parent = null;
        // Create our new window
        mWindow = PolicyManager.makeNewWindow(this);
        mWindow.mIsFloatingWindow = true;
        mWindow.setCloseOnTouchOutsideIfNotSet(true);
        mWindow.setGravity(Gravity.CENTER);
        if (this instanceof LayerActivity || android.os.Process.myUid() == android.os.Process.SYSTEM_UID) {
            mWindow.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            WindowManager.LayoutParams params = mWindow.getAttributes();
            params.alpha = 1f;
            params.dimAmount = 0.25f;
            mWindow.setAttributes((android.view.WindowManager.LayoutParams) params);
        }
        // Scale it
        scaleFloatingWindow(context);
    } else {
        mWindow = PolicyManager.makeNewWindow(this);
    }
    mWindow.setCallback(this);
    mWindow.getLayoutInflater().setPrivateFactory(this);
    if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
        mWindow.setSoftInputMode(info.softInputMode);
    }
    if (info.uiOptions != 0) {
        mWindow.setUiOptions(info.uiOptions);
    }
    mUiThread = Thread.currentThread();
    mMainThread = aThread;
    mInstrumentation = instr;
    mToken = token;
    mIdent = ident;
    mApplication = application;
    mIntent = intent;
    mComponent = intent.getComponent();
    mActivityInfo = info;
    mTitle = title;
    mParent = parent;
    mEmbeddedID = id;
    mLastNonConfigurationInstances = lastNonConfigurationInstances;
    mWindow.setWindowManager((WindowManager) context.getSystemService(Context.WINDOW_SERVICE), mToken, mComponent.flattenToString(), (info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
    if (mParent != null) {
        mWindow.setContainer(mParent.getWindow());
    }
    mWindowManager = mWindow.getWindowManager();
    mCurrentConfig = config;
}
Also used : TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue) WindowManager(android.view.WindowManager)

Example 20 with TypedValue

use of android.util.TypedValue in project android_frameworks_base by ParanoidAndroid.

the class PackageParser method parseMetaData.

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();
    }
    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;
}
Also used : Bundle(android.os.Bundle) TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue)

Aggregations

TypedValue (android.util.TypedValue)836 TypedArray (android.content.res.TypedArray)185 Resources (android.content.res.Resources)92 ContextThemeWrapper (android.view.ContextThemeWrapper)52 Context (android.content.Context)49 Drawable (android.graphics.drawable.Drawable)49 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)46 TextView (android.widget.TextView)44 Paint (android.graphics.Paint)41 IOException (java.io.IOException)40 AttributeSet (android.util.AttributeSet)34 XmlResourceParser (android.content.res.XmlResourceParser)29 View (android.view.View)27 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)26 Point (android.graphics.Point)25 ColorStateList (android.content.res.ColorStateList)23 DisplayMetrics (android.util.DisplayMetrics)23 LinearLayout (android.widget.LinearLayout)20 SpannableString (android.text.SpannableString)19 Bundle (android.os.Bundle)18