Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

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

Prototype

TypedValue

Source Link

Usage

From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java

protected TextView createDefaultTextTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }/*from  w w  w . j  ava  2  s . c  om*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    //System.out.println("c " + titleColor);
    if (titleColor != null) {
        textView.setTextColor(titleColor);
    }

    return textView;
}

From source file:com.jaymullen.TrailJournal.EntryActivity.java

private void updateBottomBar() {
    int position = mPager.getCurrentItem();
    if (position == mCurrentPageSequence.size()) {
        mNextButton.setText(R.string.publish);
        mNextButton.setTextAppearance(this, R.style.TextAppearanceFinish);
        if (Utils.isOnline(this)) {
            mNextButton.setBackgroundResource(R.drawable.finish_background);
            mNextButton.setClickable(true);
        } else {/*from   w  w  w  . j  a va  2 s.  c  om*/
            mNextButton.setBackgroundResource(R.drawable.finish_no_connection_background);
            mNextButton.setClickable(false);
        }

        mSaveButton.setVisibility(View.VISIBLE);
        if (mIsPublished) {
            mNextButton.setText("Update");
        }
    } else {
        mNextButton.setText(mEditingAfterReview ? R.string.review : R.string.next);
        mNextButton.setBackgroundResource(R.drawable.selectable_item_background);
        TypedValue v = new TypedValue();
        getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, v, true);
        mNextButton.setTextAppearance(this, v.resourceId);
        mNextButton.setEnabled(position != mPagerAdapter.getCutOffPage());
        mNextButton.setClickable(true);

        mSaveButton.setVisibility(View.GONE);
    }

    mPrevButton.setVisibility(position <= 0 ? View.INVISIBLE : View.VISIBLE);
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

private void setDefaultItemBackground() {
    TypedValue value = new TypedValue();
    int colorControlHighlight = 0;
    if (mContext.getTheme().resolveAttribute(R.attr.colorControlHighlight, value, true)) {
        colorControlHighlight = value.data;
    } else {// w  ww.  j  a va  2  s  .  c  o  m
        colorControlHighlight = mDefaultTheme == DefaultTheme.LIGHT
                ? mContext.getResources().getColor(R.color.snv_ripple_material_light)
                : mContext.getResources().getColor(R.color.snv_ripple_material_dark);
    }

    StateListDrawable drawable = new StateListDrawable();
    LayerDrawable checked = new LayerDrawable(
            new Drawable[] { new ColorDrawable(colorControlHighlight), obtainSelectableItemBackground() });
    drawable.addState(CHECKED_STATE_SET, checked);
    drawable.addState(EMPTY_STATE_SET, obtainSelectableItemBackground());
    mItemBackground = drawable;
}

From source file:a.dev.mobile.thread.MainActivity.java

public int calculateDrawerWidth() {
    // Calculate ActionBar height
    TypedValue tv = new TypedValue();
    int actionBarHeight = 0;
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }//from  www .  ja v  a 2  s  .c o m
    Display display = getWindowManager().getDefaultDisplay();
    int width;

    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;

    } else {
        width = display.getWidth(); // deprecated

    }
    return width - actionBarHeight;
}

From source file:android.support.v7.widget.AppCompatDrawableManager.java

private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) {
    if (mDelegates != null && !mDelegates.isEmpty()) {
        if (mKnownDrawableIdTags != null) {
            final String cachedTagName = mKnownDrawableIdTags.get(resId);
            if (SKIP_DRAWABLE_TAG.equals(cachedTagName)
                    || (cachedTagName != null && mDelegates.get(cachedTagName) == null)) {
                // If we don't have a delegate for the drawable tag, or we've been set to
                // skip it, fail fast and return null
                if (DEBUG) {
                    Log.d(TAG, "[loadDrawableFromDelegates] Skipping drawable: "
                            + context.getResources().getResourceName(resId));
                }/* w w w .  ja v a  2  s .  c om*/
                return null;
            }
        } else {
            // Create an id cache as we'll need one later
            mKnownDrawableIdTags = new SparseArray<>();
        }

        if (mTypedValue == null) {
            mTypedValue = new TypedValue();
        }
        final TypedValue tv = mTypedValue;
        final Resources res = context.getResources();
        res.getValue(resId, tv, true);

        final long key = createCacheKey(tv);

        Drawable dr = getCachedDrawable(context, key);
        if (dr != null) {
            if (DEBUG) {
                Log.i(TAG, "[loadDrawableFromDelegates] Returning cached drawable: "
                        + context.getResources().getResourceName(resId));
            }
            // We have a cached drawable, return it!
            return dr;
        }

        if (tv.string != null && tv.string.toString().endsWith(".xml")) {
            // If the resource is an XML file, let's try and parse it
            try {
                final XmlPullParser parser = res.getXml(resId);
                final AttributeSet attrs = Xml.asAttributeSet(parser);
                int type;
                while ((type = parser.next()) != XmlPullParser.START_TAG
                        && type != XmlPullParser.END_DOCUMENT) {
                    // Empty loop
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException("No start tag found");
                }

                final String tagName = parser.getName();
                // Add the tag name to the cache
                mKnownDrawableIdTags.append(resId, tagName);

                // Now try and find a delegate for the tag name and inflate if found
                final InflateDelegate delegate = mDelegates.get(tagName);
                if (delegate != null) {
                    dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme());
                }
                if (dr != null) {
                    // Add it to the drawable cache
                    dr.setChangingConfigurations(tv.changingConfigurations);
                    if (addDrawableToCache(context, key, dr) && DEBUG) {
                        Log.i(TAG, "[loadDrawableFromDelegates] Saved drawable to cache: "
                                + context.getResources().getResourceName(resId));
                    }
                }
            } catch (Exception e) {
                Log.e(TAG, "Exception while inflating drawable", e);
            }
        }
        if (dr == null) {
            // If we reach here then the delegate inflation of the resource failed. Mark it as
            // bad so we skip the id next time
            mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG);
        }
        return dr;
    }

    return null;
}

From source file:com.example.administrator.smartbj.Drawer.MyNavigationView.java

private ColorStateList createDefaultColorStateList(int baseColorThemeAttr) {
    TypedValue value = new TypedValue();
    if (!getContext().getTheme().resolveAttribute(baseColorThemeAttr, value, true)) {
        return null;
    }//  ww w  .  j a  va 2 s .com
    ColorStateList baseColor = getResources().getColorStateList(value.resourceId);
    if (!getContext().getTheme().resolveAttribute(android.support.design.R.attr.colorPrimary, value, true)) {
        return null;
    }
    int colorPrimary = value.data;
    int defaultColor = baseColor.getDefaultColor();
    return new ColorStateList(new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
            new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                    defaultColor });
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = getContext();

    // Pull disabled alpha from theme.
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    mDisabledAlpha = outValue.getFloat();

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr,
            defStyleRes);/*from   ww  w . j  a v a2 s .  c om*/

    mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor);
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor);
    mTextColor[MINUTES] = mTextColor[HOURS];

    mPaint[HOURS] = new Paint();
    mPaint[HOURS].setAntiAlias(true);
    mPaint[HOURS].setTextAlign(Paint.Align.CENTER);

    mPaint[MINUTES] = new Paint();
    mPaint[MINUTES].setAntiAlias(true);
    mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);

    final ColorStateList selectorColors = a
            .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor);

    int selectorActivatedColor = Color.BLACK;
    if (selectorColors != null) {
        selectorActivatedColor = selectorColors
                .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0);
    }

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);

    mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
    mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);

    mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);

    mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor,
            ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner);

    mShowHours = true;
    mIs24HourMode = false;
    mAmOrPm = AM;

    // Set up accessibility components.
    mTouchHelper = new RadialPickerTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    initHoursAndMinutesText();
    initData();

    a.recycle();

    // Initial values
    final Calendar calendar = Calendar.getInstance(Locale.getDefault());
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);

    setCurrentHourInternal(currentHour, false, false);
    setCurrentMinuteInternal(currentMinute, false);

    setHapticFeedbackEnabled(true);
}

From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*w w w.  j  av  a 2  s  . c  o m*/
 */
protected ImageView createDefaultTabView(int resource) {
    ImageView imageView = new ImageView(getContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1));
    imageView.setImageResource(resource);
    if (tabViewBackgroundResId != NO_ID) {
        imageView.setBackgroundResource(tabViewBackgroundResId);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        imageView.setBackgroundResource(outValue.resourceId);
    }

    imageView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        imageView.setMinimumWidth(tabViewTextMinWidth);
    }

    return imageView;
}

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

private void resolveTheme() {
    FragmentActivity activity = getActivity();
    int theme = onProvideTheme();
    if (theme == -1) {
        // Look up the onboardingTheme in the activity's currently specified theme. If it
        // exists, wrap the theme with its value.
        int resId = R.attr.onboardingTheme;
        TypedValue typedValue = new TypedValue();
        boolean found = activity.getTheme().resolveAttribute(resId, typedValue, true);
        if (DEBUG)
            Log.v(TAG, "Found onboarding theme reference? " + found);
        if (found) {
            mThemeWrapper = new ContextThemeWrapper(activity, typedValue.resourceId);
        }// w  w  w.j  a  va  2  s.  com
    } else {
        mThemeWrapper = new ContextThemeWrapper(activity, theme);
    }
}