Search in sources :

Example 16 with TypedArray

use of android.content.res.TypedArray in project material-icon-lib by code-mc.

the class MaterialIconView method init.

private void init(Context context, AttributeSet attrs) {
    init();
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MaterialIconViewFormat);
    try {
        int type = array.getInt(R.styleable.MaterialIconViewFormat_materialIcon, 0);
        if (type >= 0)
            setIcon(type);
    } catch (Exception e) {
    }
    try {
        int color = array.getColor(R.styleable.MaterialIconViewFormat_materialIconColor, Color.BLACK);
        setColor(color);
    } catch (Exception e) {
    }
    try {
        int size = array.getDimensionPixelSize(R.styleable.MaterialIconViewFormat_materialIconSize, -1);
        if (size >= 0)
            setSizePx(size);
    } catch (Exception e) {
    }
    array.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint)

Example 17 with TypedArray

use of android.content.res.TypedArray in project UltimateAndroid by cymcsg.

the class CircularImageView method init.

/**
	 * Initializes paint objects and sets desired attributes.
	 * @param context Context
	 * @param attrs Attributes
	 * @param defStyle Default Style
	 */
private void init(Context context, AttributeSet attrs, int defStyle) {
    // Initialize paint objects
    paint = new Paint();
    paint.setAntiAlias(true);
    paintBorder = new Paint();
    paintBorder.setAntiAlias(true);
    paintBorder.setStyle(Paint.Style.STROKE);
    paintSelectorBorder = new Paint();
    paintSelectorBorder.setAntiAlias(true);
    // Enable software rendering on HoneyComb and up. (needed for shadow)
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    // Load the styled attributes and set their properties
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CircularImageView, defStyle, 0);
    // Check for extra features being enabled
    hasBorder = attributes.getBoolean(R.styleable.CircularImageView_civ_border, false);
    hasSelector = attributes.getBoolean(R.styleable.CircularImageView_civ_selector, false);
    shadowEnabled = attributes.getBoolean(R.styleable.CircularImageView_civ_shadow, SHADOW_ENABLED);
    // Set border properties, if enabled
    if (hasBorder) {
        int defaultBorderSize = (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
        setBorderWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_civ_borderWidth, defaultBorderSize));
        setBorderColor(attributes.getColor(R.styleable.CircularImageView_civ_borderColor, Color.WHITE));
    }
    // Set selector properties, if enabled
    if (hasSelector) {
        int defaultSelectorSize = (int) (2 * context.getResources().getDisplayMetrics().density + 0.5f);
        setSelectorColor(attributes.getColor(R.styleable.CircularImageView_civ_selectorColor, Color.TRANSPARENT));
        setSelectorStrokeWidth(attributes.getDimensionPixelOffset(R.styleable.CircularImageView_civ_selectorStrokeWidth, defaultSelectorSize));
        setSelectorStrokeColor(attributes.getColor(R.styleable.CircularImageView_civ_selectorStrokeColor, Color.BLUE));
    }
    // Set shadow properties, if enabled
    if (shadowEnabled) {
        shadowRadius = attributes.getFloat(R.styleable.CircularImageView_civ_shadowRadius, SHADOW_RADIUS);
        shadowDx = attributes.getFloat(R.styleable.CircularImageView_civ_shadowDx, SHADOW_DX);
        shadowDy = attributes.getFloat(R.styleable.CircularImageView_civ_shadowDy, SHADOW_DY);
        shadowColor = attributes.getColor(R.styleable.CircularImageView_civ_shadowColor, SHADOW_COLOR);
        setShadowEnabled(true);
    }
    // We no longer need our attributes TypedArray, give it back to cache
    attributes.recycle();
}
Also used : TypedArray(android.content.res.TypedArray) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 18 with TypedArray

use of android.content.res.TypedArray in project cw-omnibus by commonsguy.

the class ActionBarSherlockCompat method generateLayout.

private ViewGroup generateLayout() {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "[generateLayout]");
    // Apply data from current theme.
    TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
    if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) {
        throw new IllegalStateException("You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.");
    }
    if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) {
        requestFeature(Window.FEATURE_NO_TITLE);
    } else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) {
        // Don't allow an action bar if there is no title.
        requestFeature(Window.FEATURE_ACTION_BAR);
    }
    if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    }
    if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }
    a.recycle();
    int layoutResource;
    if (!hasFeature(Window.FEATURE_NO_TITLE)) {
        if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
            layoutResource = R.layout.abs__screen_action_bar_overlay;
        } else {
            layoutResource = R.layout.abs__screen_action_bar;
        }
    } else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) {
        layoutResource = R.layout.abs__screen_simple_overlay_action_mode;
    } else {
        layoutResource = R.layout.abs__screen_simple;
    }
    if (BuildConfig.DEBUG)
        Log.d(TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource));
    View in = mActivity.getLayoutInflater().inflate(layoutResource, null);
    mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    ViewGroup contentParent = (ViewGroup) mDecor.findViewById(R.id.abs__content);
    if (contentParent == null) {
        throw new RuntimeException("Couldn't find content container view");
    }
    //Make our new child the true content view (for fragments). VERY VOLATILE!
    mDecor.setId(View.NO_ID);
    contentParent.setId(android.R.id.content);
    if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) {
        IcsProgressBar progress = getCircularProgressBar(false);
        if (progress != null) {
            progress.setIndeterminate(true);
        }
    }
    return contentParent;
}
Also used : AndroidRuntimeException(android.util.AndroidRuntimeException) ViewGroup(android.view.ViewGroup) TypedArray(android.content.res.TypedArray) ActionBarContextView(com.actionbarsherlock.internal.widget.ActionBarContextView) ActionBarView(com.actionbarsherlock.internal.widget.ActionBarView) View(android.view.View) IcsProgressBar(com.actionbarsherlock.internal.widget.IcsProgressBar)

Example 19 with TypedArray

use of android.content.res.TypedArray in project cw-omnibus by commonsguy.

the class AbsActionBarView method onConfigurationChanged.

/*
     * Must be public so we can dispatch pre-2.2 via ActionBarImpl.
     */
@Override
public void onConfigurationChanged(Configuration newConfig) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        super.onConfigurationChanged(newConfig);
    } else if (mMenuView != null) {
        mMenuView.onConfigurationChanged(newConfig);
    }
    // Action bar can change size on configuration changes.
    // Reread the desired height from the theme-specified style.
    TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.SherlockActionBar, R.attr.actionBarStyle, 0);
    setContentHeight(a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0));
    a.recycle();
    if (mSplitWhenNarrow) {
        setSplitActionBar(getResources_getBoolean(getContext(), R.bool.abs__split_action_bar_is_narrow));
    }
    if (mActionMenuPresenter != null) {
        mActionMenuPresenter.onConfigurationChanged(newConfig);
    }
}
Also used : TypedArray(android.content.res.TypedArray)

Example 20 with TypedArray

use of android.content.res.TypedArray in project SimplifyReader by chentao0707.

the class SwipeBackLayout method attachToActivity.

public void attachToActivity(Activity activity) {
    mActivity = activity;
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();
    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}
Also used : ViewGroup(android.view.ViewGroup) TypedArray(android.content.res.TypedArray)

Aggregations

TypedArray (android.content.res.TypedArray)1991 Paint (android.graphics.Paint)190 TypedValue (android.util.TypedValue)185 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)162 Resources (android.content.res.Resources)118 View (android.view.View)116 Drawable (android.graphics.drawable.Drawable)114 XmlResourceParser (android.content.res.XmlResourceParser)80 Context (android.content.Context)78 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)62 ViewGroup (android.view.ViewGroup)59 Bundle (android.os.Bundle)48 LayoutInflater (android.view.LayoutInflater)42 Point (android.graphics.Point)41 ImageView (android.widget.ImageView)40