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.example.michaelg.myapplication.Item.discreteseekbar.DiscreteSeekBar.java

public DiscreteSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setFocusable(true);//from w  ww.j  a va2  s .  c o  m
    setWillNotDraw(false);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    float density = context.getResources().getDisplayMetrics().density;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar, defStyleAttr,
            R.style.Widget_DiscreteSeekBar);

    int max = 100;
    int min = 0;
    int value = 0;
    mMirrorForRtl = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
    mAllowTrackClick = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);
    mIndicatorPopupEnabled = a.getBoolean(R.styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled,
            mIndicatorPopupEnabled);
    mTrackHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_trackHeight, (int) (1 * density));
    mScrubberHeight = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_scrubberHeight,
            (int) (4 * density));
    int thumbSize = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_thumbSize,
            (int) (density * ThumbDrawable.DEFAULT_SIZE_DP));
    int separation = a.getDimensionPixelSize(R.styleable.DiscreteSeekBar_dsb_indicatorSeparation,
            (int) (SEPARATION_DP * density));

    //Extra pixels for a minimum touch area of 32dp
    int touchBounds = (int) (density * 32);
    mAddedTouchBounds = Math.max(0, (touchBounds - thumbSize) / 2);

    int indexMax = R.styleable.DiscreteSeekBar_dsb_max;
    int indexMin = R.styleable.DiscreteSeekBar_dsb_min;
    int indexValue = R.styleable.DiscreteSeekBar_dsb_value;
    final TypedValue out = new TypedValue();
    //Not sure why, but we wanted to be able to use dimensions here...
    if (a.getValue(indexMax, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            max = a.getDimensionPixelSize(indexMax, max);
        } else {
            max = a.getInteger(indexMax, max);
        }
    }
    if (a.getValue(indexMin, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            min = a.getDimensionPixelSize(indexMin, min);
        } else {
            min = a.getInteger(indexMin, min);
        }
    }
    if (a.getValue(indexValue, out)) {
        if (out.type == TypedValue.TYPE_DIMENSION) {
            value = a.getDimensionPixelSize(indexValue, value);
        } else {
            value = a.getInteger(indexValue, value);
        }
    }

    mMin = min;
    mMax = Math.max(min + 1, max);
    mValue = Math.max(min, Math.min(max, value));
    updateKeyboardRange();

    mIndicatorFormatter = a.getString(R.styleable.DiscreteSeekBar_dsb_indicatorFormatter);

    ColorStateList trackColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_trackColor);
    ColorStateList progressColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_progressColor);
    ColorStateList rippleColor = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_rippleColor);
    boolean editMode = isInEditMode();
    if (editMode || rippleColor == null) {
        rippleColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.DKGRAY });
    }
    if (editMode || trackColor == null) {
        trackColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { Color.GRAY });
    }
    if (editMode || progressColor == null) {
        progressColor = new ColorStateList(new int[][] { new int[] {} }, new int[] { DEFAULT_THUMB_COLOR });
    }

    mRipple = SeekBarCompat.getRipple(rippleColor);
    if (isLollipopOrGreater) {
        SeekBarCompat.setBackground(this, mRipple);
    } else {
        mRipple.setCallback(this);
    }

    TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);
    mTrack = shapeDrawable;
    mTrack.setCallback(this);

    shapeDrawable = new TrackRectDrawable(progressColor);
    mScrubber = shapeDrawable;
    mScrubber.setCallback(this);

    mThumb = new ThumbDrawable(progressColor, thumbSize);
    mThumb.setCallback(this);
    mThumb.setBounds(0, 0, mThumb.getIntrinsicWidth(), mThumb.getIntrinsicHeight());

    if (!editMode) {
        mIndicator = new PopupIndicator(context, attrs, defStyleAttr, convertValueToMessage(mMax), thumbSize,
                thumbSize + mAddedTouchBounds + separation);
        mIndicator.setListener(mFloaterListener);
    }
    a.recycle();

    setNumericTransformer(new DefaultNumericTransformer());

}

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

private void setDefaultIconTintList() {
    TypedValue value = new TypedValue();
    if (mContext.getTheme().resolveAttribute(android.R.attr.textColorPrimary, value, true)) {
        ColorStateList baseColor = mContext.getResources().getColorStateList(value.resourceId);
        if (mContext.getTheme().resolveAttribute(R.attr.colorPrimary, value, true)) {
            int colorPrimary = value.data;
            int defaultColor = baseColor.getDefaultColor();
            mIconTintList = new ColorStateList(
                    new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
                    new int[] { baseColor.getColorForState(DISABLED_STATE_SET, defaultColor), colorPrimary,
                            defaultColor });
        }/*  w  w w .j  a  v a 2 s . co m*/
    }

    if (mIconTintList == null) {
        // Defaults
        boolean isLightTheme = mDefaultTheme == SublimeThemer.DefaultTheme.LIGHT;

        int defDisabled = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_disabled_material_dark);
        int defChecked = isLightTheme ? mContext.getResources().getColor(R.color.snv_primary_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_material_dark);
        int defEmptySet = isLightTheme
                ? mContext.getResources().getColor(R.color.snv_primary_text_default_material_light)
                : mContext.getResources().getColor(R.color.snv_primary_text_default_material_dark);
        mIconTintList = new ColorStateList(
                new int[][] { DISABLED_STATE_SET, CHECKED_STATE_SET, EMPTY_STATE_SET },
                new int[] { defDisabled, defChecked, defEmptySet });
    }
}

From source file:cc.metapro.openct.myclass.ClassActivity.java

private void showThemePicker() {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = getTheme();
    theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
    ColorPickerDialog dialog = ColorPickerDialog.newBuilder().setDialogTitle(R.string.select_theme)
            .setColorShape(ColorShape.CIRCLE).setAllowCustom(false).setAllowPresets(false)
            .setDialogType(ColorPickerDialog.TYPE_PRESETS).setShowAlphaSlider(false).setShowColorShades(false)
            .setPresets(getResources().getIntArray(R.array.theme_color))
            .setColor(ReferenceUtils.getThemeColor(this, R.attr.colorPrimary)).create();

    final int oldTheme = PrefHelper.getInt(this, R.string.pref_theme_activity, R.style.AppTheme);
    dialog.setColorPickerDialogListener(new ColorPickerDialogListener() {
        @Override//from  ww w. ja v a2s . co m
        public void onColorSelected(int i, @ColorInt int i1) {
            PrefHelper.putInt(ClassActivity.this, R.string.pref_theme_activity, getThemeByColor(i1));
        }

        @Override
        public void onDialogDismissed(int i) {
            int newTheme = PrefHelper.getInt(ClassActivity.this, R.string.pref_theme_activity,
                    R.style.AppTheme);
            if (oldTheme != newTheme) {
                finish();
                startActivity(getIntent());
            }
        }
    });
    dialog.show(getFragmentManager(), "color_picker");
}

From source file:com.axolotl.yanews.customize.SlidingTabLayout.java

/**
 * tabview. tab view/*from  ww  w  .j  ava 2s  .c om*/
 * {@link #setCustomTabView(int, int)}.
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context, null, 0);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTab_text_size_sp);
    if (mBold) {
        textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
    } else {
        textView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    }
    if (mChangeTextColor) {
        textView.setTextColor(mNormalColor);
    }
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (mBackgroundResource != 0) {
        textView.setBackgroundResource(mBackgroundResource);
    } 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);
            textView.setBackgroundResource(outValue.resourceId);
        }
    }

    //wtf
    //        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, 0, padding, 0);
    return textView;
}

From source file:com.development.jaba.view.SlidingTabLayout.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)}./*from ww w  . j a v a  2  s  .c  om*/
 */
protected TextView createDefaultTabView(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);

    // By default use the unselected title color.
    textView.setTextColor(mTitleColor);

    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);
    }

    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);

    return textView;
}

From source file:com.tapcentive.sdk.actions.TapMessageFragment.java

/**
 * Gets the display metrics.//from  ww  w .  j av a2 s .com
 * 
 * @return the display metrics
 */
private void getDisplayMetrics() {
    // determine the screen size used for the animation
    DisplayMetrics dimension = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dimension);
    TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
    int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
    int statusBarHeight = getResources()
            .getDimensionPixelSize(getResources().getIdentifier("status_bar_height", "dimen", "android"));

    usableHeight = dimension.heightPixels - (actionBarHeight + statusBarHeight);
}

From source file:android_network.hetnet.vpn_service.AdapterRule.java

public AdapterRule(Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;
    this.inflater = LayoutInflater.from(context);

    if (prefs.getBoolean("dark_theme", false))
        colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY),
                Color.blue(Color.DKGRAY));
    else/*from  ww  w .j a va2 s .  c o  m*/
        colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY),
                Color.blue(Color.LTGRAY));

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
    try {
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);

    iconSize = Util.dips2pixels(48, context);
}

From source file:eu.faircode.netguard.AdapterRule.java

public AdapterRule(Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;

    if (prefs.getBoolean("dark_theme", false))
        colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY),
                Color.blue(Color.DKGRAY));
    else/*from  ww  w .j av  a2 s. c  o  m*/
        colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY),
                Color.blue(Color.LTGRAY));

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);

    iconSize = Util.dips2pixels(48, context);
}

From source file:com.example.abner.dynamicfragment.view.CustomSlidingTabLayout.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)}.//from w  w w  .j  a v  a 2  s  . co  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(dTextColor);
    // mTextSize is sp
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    if (mNeedBold) {
        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);
    }

    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);
    if (mShouldExpand) {
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.width = 0;
        layoutParams.weight = 1;
        textView.setLayoutParams(layoutParams);
    }
    return textView;
}