Example usage for android.content.res Resources getDisplayMetrics

List of usage examples for android.content.res Resources getDisplayMetrics

Introduction

In this page you can find the example usage for android.content.res Resources getDisplayMetrics.

Prototype

public DisplayMetrics getDisplayMetrics() 

Source Link

Document

Return the current display metrics that are in effect for this resource object.

Usage

From source file:de.schildbach.wallet.ui.ReportIssueDialogFragment.java

private static void appendDeviceInfo(final Appendable report, final Context context) throws IOException {
    final Resources res = context.getResources();
    final android.content.res.Configuration config = res.getConfiguration();
    final ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context
            .getSystemService(Context.DEVICE_POLICY_SERVICE);

    report.append("Device Model: " + Build.MODEL + "\n");
    report.append("Android Version: " + Build.VERSION.RELEASE + "\n");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        report.append("Android security patch level: ").append(Build.VERSION.SECURITY_PATCH).append("\n");
    report.append("ABIs: ")
            .append(Joiner.on(", ").skipNulls()
                    .join(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? supportedAbisLollipop()
                            : supportedAbisKitKat()))
            .append("\n");
    report.append("Board: " + Build.BOARD + "\n");
    report.append("Brand: " + Build.BRAND + "\n");
    report.append("Device: " + Build.DEVICE + "\n");
    report.append("Display: " + Build.DISPLAY + "\n");
    report.append("Finger Print: " + Build.FINGERPRINT + "\n");
    report.append("Host: " + Build.HOST + "\n");
    report.append("ID: " + Build.ID + "\n");
    report.append("Product: " + Build.PRODUCT + "\n");
    report.append("Tags: " + Build.TAGS + "\n");
    report.append("Time: " + Build.TIME + "\n");
    report.append("Type: " + Build.TYPE + "\n");
    report.append("User: " + Build.USER + "\n");
    report.append("Configuration: " + config + "\n");
    report.append("Screen Layout: size "
            + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) + " long "
            + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_LONG_MASK) + "\n");
    report.append("Display Metrics: " + res.getDisplayMetrics() + "\n");
    report.append(/*from w w  w . ja va 2 s . c o m*/
            "Memory Class: " + activityManager.getMemoryClass() + "/" + activityManager.getLargeMemoryClass()
                    + (activityManager.isLowRamDevice() ? " (low RAM device)" : "") + "\n");
    report.append("Storage Encryption Status: " + devicePolicyManager.getStorageEncryptionStatus() + "\n");
    report.append("Bluetooth MAC: " + bluetoothMac() + "\n");
    report.append("Runtime: ").append(System.getProperty("java.vm.name")).append(" ")
            .append(System.getProperty("java.vm.version")).append("\n");
}

From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java

/**
 * Construct a new Switch with a default style determined by the given theme attribute,
 * overriding specific style attributes as requested.
 *
 * @param context      The Context that will determine this widget's theming.
 * @param attrs        Specification of attributes that should deviate from the default styling.
 * @param defStyleAttr An attribute in the current theme that contains a
 *                     reference to a style resource that supplies default values for
 *                     the view. Can be 0 to not look for defaults.
 *//*from w  w  w  .  ja va2 s .  c  om*/
@SuppressLint("PrivateResource")
public IconSwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    Resources res = getResources();
    mTextPaint.density = res.getDisplayMetrics().density;

    TintTypedArray a;
    a = TintTypedArray.obtainStyledAttributes(context, attrs,
            android.support.v7.appcompat.R.styleable.SwitchCompat, defStyleAttr, 0);
    mThumbDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_android_thumb);
    if (mThumbDrawable != null) {
        mThumbDrawable.setCallback(this);
    }
    mTrackDrawable = a.getDrawable(android.support.v7.appcompat.R.styleable.SwitchCompat_track);
    if (mTrackDrawable != null) {
        mTrackDrawable.setCallback(this);
    }
    mTextOn = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOn);
    mTextOff = a.getText(android.support.v7.appcompat.R.styleable.SwitchCompat_android_textOff);
    mShowText = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_showText, true);
    mThumbTextPadding = a
            .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_thumbTextPadding, 0);
    /*mSwitchMinWidth = a.getDimensionPixelSize(
        android.support.v7.appcompat.R.styleable.SwitchCompat_switchMinWidth, 0);*/
    mSwitchPadding = a
            .getDimensionPixelSize(android.support.v7.appcompat.R.styleable.SwitchCompat_switchPadding, 0);
    mSplitTrack = a.getBoolean(android.support.v7.appcompat.R.styleable.SwitchCompat_splitTrack, false);

    final int appearance = a
            .getResourceId(android.support.v7.appcompat.R.styleable.SwitchCompat_switchTextAppearance, 0);
    if (appearance != 0) {
        setSwitchTextAppearance(context, appearance);
    }

    mDrawableManager = AppCompatDrawableManager.get();

    a.recycle();

    a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.IconSwitchCompat, defStyleAttr, 0);

    mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.IconSwitchCompat_minWidth, 0);

    Drawable icon = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawable);
    Drawable iconChecked = a.getDrawable(R.styleable.IconSwitchCompat_iconDrawableChecked);

    DrawableCompat.setTintList(icon, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor));

    DrawableCompat.setTintList(iconChecked, a.getColorStateList(R.styleable.IconSwitchCompat_iconColor));

    mIconDrawable = new StateListDrawable();
    ((StateListDrawable) mIconDrawable).addState(CHECKED_STATE_SET, iconChecked);
    ((StateListDrawable) mIconDrawable).addState(new int[] {}, icon);

    if (mIconDrawable != null) {
        mIconDrawable.setCallback(this);
    }

    /*if (mThumbDrawable != null) {
    DrawableCompat.setTintList(mThumbDrawable,
            a.getColorStateList(R.styleable.IconSwitchCompat_thumbColor));
    }
            
    if (mTrackDrawable != null) {
    DrawableCompat.setTintList(mTrackDrawable,
            a.getColorStateList(R.styleable.IconSwitchCompat_trackColor));
    }*/

    a.recycle();

    ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());
}

From source file:com.ruesga.rview.widget.ActivityStatsChart.java

public ActivityStatsChart(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final Resources r = getResources();
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

    int color = Color.DKGRAY;
    int textColor = Color.WHITE;

    Resources.Theme theme = context.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.ActivityStatsChart, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.ActivityStatsChart_charLineColor:
            color = a.getColor(attr, color);
            break;

        case R.styleable.ActivityStatsChart_charLineTextColor:
            textColor = a.getColor(attr, textColor);
            break;
        }//from  ww w.  j a v a2  s .c  om
    }
    a.recycle();

    mLinePaint = new Paint();
    mLinePaint.setStyle(Paint.Style.STROKE);
    mLinePaint.setColor(color);
    mLinePaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1.5f, r.getDisplayMetrics()));

    mAreaPaint = new Paint(mLinePaint);
    mAreaPaint.setStyle(Paint.Style.FILL);
    mAreaPaint.setAlpha(180);

    mGridLinesPaint = new Paint();
    mGridLinesPaint.setStyle(Paint.Style.STROKE);
    mGridLinesPaint.setColor(textColor);
    mGridLinesPaint.setStrokeWidth(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0.5f, r.getDisplayMetrics()));
    mGridLinesPaint.setAlpha(90);
    mGridLinesPaint.setPathEffect(new DashPathEffect(new float[] { 10, 10 }, 0));

    mTicksPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG);
    mTicksPaint.setColor(textColor);
    mTicksPaint.setTextAlign(Paint.Align.RIGHT);
    mTicksPaint.setAlpha(180);
    mTicksPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 8f, r.getDisplayMetrics()));

    // Ensure we have a background. Otherwise it will not draw anything
    if (getBackground() == null) {
        setBackgroundColor(Color.TRANSPARENT);
    }
}

From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java

private void generateImageFunction(HashMap args) {
    if (args.containsKey("fileName")) {
        Object fileName = args.get("fileName");
        if (fileName instanceof String) {
            this.fileName = (String) fileName;
            Log.i(PROXY_NAME, "fileName: " + this.fileName);
        }//from   w ww.  j av  a  2s .c  om
    } else
        return;

    if (args.containsKey("view")) {
        Object viewObject = args.get("view");
        if (viewObject instanceof TiViewProxy) {
            TiViewProxy viewProxy = (TiViewProxy) viewObject;
            this.view = viewProxy.getOrCreateView();
            if (this.view == null) {
                Log.e(PROXY_NAME, "NO VIEW was created!!");
                return;
            }
            Log.i(PROXY_NAME, "view: " + this.view.toString());
        }
    } else
        return;

    TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true);
    Log.i(PROXY_NAME, "file full path: " + file.nativePath());
    try {
        final int PDF_WIDTH = 612;
        final int PDF_HEIGHT = 792;
        Resources appResources = app.getResources();
        OutputStream outputStream = file.getOutputStream();
        int viewWidth = 1600;
        int viewHeight = 1;

        WebView view = (WebView) this.view.getNativeView();

        if (TiApplication.isUIThread()) {

            viewWidth = view.capturePicture().getWidth();
            viewHeight = view.capturePicture().getHeight();

            if (viewWidth <= 0) {
                viewWidth = 1300;
            }

            if (viewHeight <= 0) {
                viewHeight = 2300;
            }

        } else {
            Log.e(PROXY_NAME, "NO UI THREAD");
        }

        Log.i(PROXY_NAME, "viewWidth: " + viewWidth);
        Log.i(PROXY_NAME, "viewHeight: " + viewHeight);

        Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
        float density = appResources.getDisplayMetrics().density;

        Canvas canvas = new Canvas(viewBitmap);
        Matrix matrix = new Matrix();

        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null) {
            bgDrawable.draw(canvas);
        } else {
            canvas.drawColor(Color.WHITE);
        }
        view.draw(canvas);

        float scaleFactorWidth = 1 / ((float) viewWidth / (float) PDF_WIDTH);
        float scaleFactorHeight = 1 / ((float) viewHeight / (float) PDF_HEIGHT);

        Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth);
        Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight);

        matrix.setScale(scaleFactorWidth, scaleFactorWidth);

        Bitmap imageBitmap = Bitmap.createBitmap(PDF_WIDTH, PDF_HEIGHT, Bitmap.Config.ARGB_8888);
        Canvas imageCanvas = new Canvas(imageBitmap);
        imageCanvas.drawBitmap(viewBitmap, matrix, null);
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

        sendCompleteEvent();

    } catch (Exception exception) {
        Log.e(PROXY_NAME, "Error: " + exception.toString());
        sendErrorEvent(exception.toString());
    }
}

From source file:com.anjuke.library.uicomponent.photo.EndlessCircleIndicator.java

public EndlessCircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   w ww. j  a va  2 s.  c  o  m*/
    //Load defaults from resources
    final Resources res = getResources();

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EndlessCircleIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.EndlessCircleIndicator_centered, true);
    mOrientation = a.getInt(R.styleable.EndlessCircleIndicator_android_orientation, 0);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill
            .setColor(a.getColor(R.styleable.EndlessCircleIndicator_pageColor, Color.parseColor("#00000000")));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(
            a.getColor(R.styleable.EndlessCircleIndicator_strokeColor, Color.parseColor("#FFDDDDDD")));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.EndlessCircleIndicator_strokeWidth,
            UIUtils.dipToPx(res.getDisplayMetrics(), 1)));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill
            .setColor(a.getColor(R.styleable.EndlessCircleIndicator_fillColor, Color.parseColor("#FFFFFFFF")));
    mRadius = a.getDimension(R.styleable.EndlessCircleIndicator_radius,
            UIUtils.dipToPx(res.getDisplayMetrics(), 3));
    mSnap = a.getBoolean(R.styleable.EndlessCircleIndicator_snap, false);

    Drawable background = a.getDrawable(R.styleable.EndlessCircleIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

/**
 * Construct a new Switch with a default style determined by the given theme
 * attribute, overriding specific style attributes as requested.
 * //from ww w.ja v  a2s . c  o  m
 * @param context
 *            The Context that will determine this widget's theming.
 * @param attrs
 *            Specification of attributes that should deviate from the
 *            default styling.
 * @param defStyleAttr
 *            An attribute in the current theme that contains a reference to
 *            a style resource that supplies default values for the view.
 *            Can be 0 to not look for defaults.
 */
public SmoothSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    final Resources res = getResources();
    final float density = res.getDisplayMetrics().density;
    mTextPaint.density = density;//res.getDisplayMetrics().density;

    final int thumbSize = (int) (Default.DEFAULT_SIZE_DP * density + 0.5f);// truckSize = 15dp 
    final int thumbWidth = thumbSize;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbWidth, thumbSize);
    mThumbColorOn = Default.DEFAULT_THUMB_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOn, Default.DEFAULT_THUMB_ON_COLOR);
    mThumbColorOff = Default.DEFAULT_THUMB_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOff, Default.DEFAULT_THUMB_OFF_COLOR);
    mTrackColorOn = Default.DEFAULT_TRACK_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOn, Default.DEFAULT_TRACK_ON_COLOR);
    mTrackColorOff = Default.DEFAULT_TRACK_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOff, Default.DEFAULT_TRACK_OFF_COLOR);

    final float radius = thumbSize * Default.DEFAULT_RADIUS_PERCENT_OF_SIZE;//a.getFloat(R.styleable.SwitchCompat_radiusPercentOfThumbSize,
    //            Default.DEFAULT_RADIUS_PERCENT_OF_SIZE);
    final int thumbPadding = (int) (thumbSize * Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_thumbPaddingPercentOfThumbSize,
    //            Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE) + 0.5f);
    final int trackPadding = (int) (thumbSize * Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_trackPaddingPercentOfThumbSize,
    //            Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE) + 0.5f);

    final int curThumbColor = isChecked() ? mThumbColorOn : mThumbColorOff;
    final int curTrackColor = isChecked() ? mTrackColorOn : mTrackColorOff;
    mThumbDrawable = makeThumbDrawable(curThumbColor, thumbWidth, thumbSize, radius, thumbPadding);
    mTrackDrawable = makeTrackDrawable(curTrackColor, thumbWidth, thumbSize, radius, trackPadding);
    //      final int onDisableColor = getDisableColor(onColor);
    //      final int offDisableColor = getDisableColor(offColor);
    //      final StateListDrawable thumbDrawable = new StateListDrawable();
    //      thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked},
    //            makeThumbDrawable(onDisableColor, thumbSize));// Disabled ON
    //      thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked},
    //            makeThumbDrawable(offDisableColor, thumbSize));// Disabled OFF
    //      thumbDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked },
    //            makeThumbDrawable(onColor, thumbSize));
    //      thumbDrawable.addState(new int[] {}, makeThumbDrawable(offColor, thumbSize));
    //      mThumbDrawable = thumbDrawable;
    //
    //      final StateListDrawable trackDrawable = new StateListDrawable();
    //      trackDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked},
    //            makeTrackDrawable(onDisableColor, thumbSize));// Disabled ON
    //      trackDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked},
    //            makeTrackDrawable(offDisableColor, thumbSize));// Disabled OFF
    //      trackDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked },
    //            makeTrackDrawable(onColor, thumbSize));
    //      trackDrawable.addState(new int[] {}, makeTrackDrawable(offColor, thumbSize));
    //      mTrackDrawable = trackDrawable;

    //      mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn);
    //      mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff);
    mShowText = false;//a.getBoolean(R.styleable.SwitchCompat_showText, false);
    mThumbTextPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0);
    //      mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0);
    mSwitchMinWidth = Math.max(mSwitchMinWidth, thumbWidth * 2);
    mSwitchPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0);
    //      mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false);

    //      final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0);
    //      if (appearance != 0) {
    //         setSwitchTextAppearance(context, appearance);
    //      }else{
    //         ColorStateList colors = a.getColorStateList(R.styleable.SwitchCompat_switchTextColor);
    //         if (colors != null) {
    //            mTextColors = colors;
    //         } else {
    //            // If no color set in TextAppearance, default to the view's textColor
    //            mTextColors = getTextColors();
    //         }
    //         float ts = a.getDimension(R.styleable.SwitchCompat_switchTextSize, 0);
    //         if (ts != 0) {
    //            if (ts != mTextPaint.getTextSize()) {
    //               mTextPaint.setTextSize(ts);
    //               requestLayout();
    //            }
    //         }
    //      }

    // mTintManager = a.getTintManager();

    //      a.recycle();

    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());
}

From source file:org.kavaproject.kavatouch.internal.JSONDeviceConfiguration.java

public JSONDeviceConfiguration(Resources resources, int id) {
    InputStream jsonStream = resources.openRawResource(id);
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    int ctr;/*ww  w .j av a  2 s  . co  m*/
    try {
        ctr = jsonStream.read();
        while (ctr != -1) {
            byteArrayOutputStream.write(ctr);
            ctr = jsonStream.read();
        }
        jsonStream.close();
    } catch (IOException e) {
        throw new Error(e);
    }
    try {
        JSONObject jConfiguration = new JSONObject(byteArrayOutputStream.toString());
        flipYAxis = jConfiguration.getBoolean("flipYAxis");
        useIPadTheme = jConfiguration.getBoolean("useIPadTheme");
        JSONArray jDeviceModifiers = jConfiguration.getJSONArray("deviceModifiers");
        for (int i = 0; i < jDeviceModifiers.length(); i++) {
            deviceModifiers.add(jDeviceModifiers.getString(i));
        }
        JSONArray jImageScaleModifiers = jConfiguration.getJSONArray("imageScaleModifiers");
        for (int i = 0; i < jImageScaleModifiers.length(); i++) {
            imageScaleModifiers.add(ImageScaleModifier.createFromJSON(jImageScaleModifiers.getJSONObject(i)));
        }
        double scale = jConfiguration.optDouble("scale");
        if (Double.isNaN(scale)) {
            DisplayMetrics displayMetrics = resources.getDisplayMetrics();
            this.scale = displayMetrics.density;
        } else {
            this.scale = (float) scale;
        }
    } catch (JSONException e) {
        throw new Error(e);
    }
}

From source file:nl.atcomputing.refcard.tabs.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 av a2  s .  c  o m
 */
protected TextView createDefaultTabView(Context context) {
    Resources resources = getResources();
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.textSizeSmall));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setTextColor(resources.getColor(R.color.atwhite_secondarytext));

    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 * resources.getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java

private void init(Context context, AttributeSet attrs) {
    float barHeight;
    int thumbNormal = R.drawable.seek_thumb;
    int thumbPressed = R.drawable.seek_thumb_pressed;
    int thumbDisabled = R.drawable.seek_thumb_disabled;
    int thumbShadowColor;
    int defaultShadowColor = Color.argb(75, 0, 0, 0);
    int defaultShadowYOffset = PixelUtil.dpToPx(context, 2);
    int defaultShadowXOffset = PixelUtil.dpToPx(context, 0);
    int defaultShadowBlur = PixelUtil.dpToPx(context, 2);

    offset = PixelUtil.dpToPx(context, TEXT_LATERAL_PADDING_IN_DP);
    textSeperation = PixelUtil.dpToPx(context, DEFAULT_TEXT_SEPERATION_IN_DP);
    step = DEFAULT_STEP;// w  w w.  j  av a2  s  . c o  m
    snapTolerance = DEFAULT_SNAP_TOLERANCE_PERCENT / 100;
    minimumDistance = DEFAULT_MINIMUM_DISTANCE;
    increments = DEFAULT_INCREMENTS;
    incrementRanges = DEFAULT_INCREMENT_RANGES;

    if (attrs == null) {
        rangeType = DEFAULT_RANGE_TYPE;
        setRangeToDefaultValues();
        mInternalPad = PixelUtil.dpToPx(context, INITIAL_PADDING_IN_DP);
        barHeight = PixelUtil.dpToPx(context, LINE_HEIGHT_IN_DP);
        mActiveColor = ACTIVE_COLOR;
        mDefaultColor = Color.parseColor("#e5e8eb");
        mAlwaysActive = true;
        mShowTextAboveThumbs = true;
        mTextAboveThumbsColor = Color.WHITE;
        thumbShadowColor = defaultShadowColor;
        mThumbShadowXOffset = defaultShadowXOffset;
        mThumbShadowYOffset = defaultShadowYOffset;
        mThumbShadowBlur = defaultShadowBlur;
        mActivateOnDefaultValues = true;
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar, 0, 0);
        try {
            switch (a.getInt(R.styleable.RangeSeekBar_rangeType, 0)) {
            case 0:
                rangeType = RangeType.LINEAR;
                break;
            case 1:
                rangeType = RangeType.PREDEFINED;
                break;
            case 2:
                rangeType = RangeType.CUBIC;
                break;
            default:
                rangeType = RangeType.LINEAR;
            }
            setRangeValues(
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMinValue,
                            DEFAULT_MINIMUM),
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMaxValue,
                            DEFAULT_MAXIMUM));
            mShowTextAboveThumbs = a.getBoolean(R.styleable.RangeSeekBar_valuesAboveThumbs, true);
            mTextAboveThumbsColor = a.getColor(R.styleable.RangeSeekBar_textAboveThumbsColor, Color.WHITE);
            mSingleThumb = a.getBoolean(R.styleable.RangeSeekBar_singleThumb, false);
            mShowLabels = a.getBoolean(R.styleable.RangeSeekBar_showLabels, true);
            mInternalPad = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_internalPadding, INITIAL_PADDING_IN_DP));
            barHeight = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_barHeight, LINE_HEIGHT_IN_DP));
            mActiveColor = a.getColor(R.styleable.RangeSeekBar_activeColor, ACTIVE_COLOR);
            mDefaultColor = a.getColor(R.styleable.RangeSeekBar_defaultColor, Color.parseColor("#e5e8eb"));
            mAlwaysActive = a.getBoolean(R.styleable.RangeSeekBar_alwaysActive, true);
            customMinValueLabel = a.getString(R.styleable.RangeSeekBar_minValueLabel);
            customMaxValueLabel = a.getString(R.styleable.RangeSeekBar_maxValueLabel);

            Drawable normalDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbNormal);
            if (normalDrawable != null) {
                thumbImage = BitmapUtil.drawableToBitmap(normalDrawable);
            }
            Drawable disabledDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbDisabled);
            if (disabledDrawable != null) {
                thumbDisabledImage = BitmapUtil.drawableToBitmap(disabledDrawable);
            }
            Drawable pressedDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbPressed);
            if (pressedDrawable != null) {
                thumbPressedImage = BitmapUtil.drawableToBitmap(pressedDrawable);
            }
            mThumbShadow = a.getBoolean(R.styleable.RangeSeekBar_thumbShadow, false);
            thumbShadowColor = a.getColor(R.styleable.RangeSeekBar_thumbShadowColor, defaultShadowColor);
            mThumbShadowXOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowXOffset,
                    defaultShadowXOffset);
            mThumbShadowYOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowYOffset,
                    defaultShadowYOffset);
            mThumbShadowBlur = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowBlur,
                    defaultShadowBlur);

            mActivateOnDefaultValues = a.getBoolean(R.styleable.RangeSeekBar_activateOnDefaultValues, true);
        } finally {
            a.recycle();
        }
    }

    Resources resources = getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, resources.getDisplayMetrics());

    if (thumbImage == null) {
        thumbImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        Drawable thumbDrawableNormal = getResources().getDrawable(thumbNormal);
        thumbDrawableNormal.setBounds(0, 0, px, px);
        thumbDrawableNormal.draw(new Canvas(thumbImage));
    }
    if (thumbPressedImage == null) {
        Drawable thumbDrawablePressed = getResources().getDrawable(thumbPressed);
        thumbDrawablePressed.setBounds(0, 0, px, px);
        thumbPressedImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawablePressed.draw(new Canvas(thumbPressedImage));
    }
    if (thumbDisabledImage == null) {
        Drawable thumbDrawableDisabled = getResources().getDrawable(thumbDisabled);
        thumbDrawableDisabled.setBounds(0, 0, px, px);
        thumbDisabledImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawableDisabled.draw(new Canvas(thumbDisabledImage));
    }

    mThumbHalfWidth = 0.5f * thumbImage.getWidth();
    mThumbHalfHeight = 0.5f * thumbImage.getHeight();

    setValuePrimAndNumberType();

    mTextSize = PixelUtil.spToPx(context, DEFAULT_TEXT_SIZE_IN_SP);
    mDistanceToTop = PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_TOP_IN_DP);
    mTextOffset = !mShowTextAboveThumbs ? 0
            : this.mTextSize + PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_BUTTON_IN_DP)
                    + this.mDistanceToTop;

    mRect = new RectF(padding, mTextOffset + mThumbHalfHeight - barHeight / 2, getWidth() - padding,
            mTextOffset + mThumbHalfHeight + barHeight / 2);

    // make RangeSeekBar focusable. This solves focus handling issues in case EditText widgets are being used along with the RangeSeekBar within ScrollViews.
    setFocusable(true);
    setFocusableInTouchMode(true);
    mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();

    if (mThumbShadow) {
        // We need to remove hardware acceleration in order to blur the shadow
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        shadowPaint.setColor(thumbShadowColor);
        shadowPaint.setMaskFilter(new BlurMaskFilter(mThumbShadowBlur, BlurMaskFilter.Blur.NORMAL));
        mThumbShadowPath = new Path();
        mThumbShadowPath.addCircle(0, 0, mThumbHalfHeight, Path.Direction.CW);
    }
}

From source file:com.miz.functions.MizLib.java

public static int getThumbnailNotificationSize(Context c) {
    Resources r = c.getResources();
    return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64, r.getDisplayMetrics());
}