Code example for Resources

Methods: getDisplayMetricsdecodeResource

0
          int thumbImageNormal,
          int thumbImagePressed) {
 
        final Resources res = ctx.getResources();
 
        mImageNormal = BitmapFactory.decodeResource(res, thumbImageNormal);
        mImagePressed = BitmapFactory.decodeResource(res, thumbImagePressed);
 
        // If any of the attributes are set, toggle bitmap off 
        if (thumbRadiusDP == -1 && thumbColorNormal == -1 && thumbColorPressed == -1) {
 
            mUseBitmap = true;
 
        } else { 
 
            mUseBitmap = false;
 
            // If one of the attributes are set, but the others aren't, set the 
            // attributes to default 
            if (thumbRadiusDP == -1)
                mThumbRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                                                           DEFAULT_THUMB_RADIUS_DP,
                                                           res.getDisplayMetrics());
            else 
                mThumbRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                                                           thumbRadiusDP,
                                                           res.getDisplayMetrics());
 
            if (thumbColorNormal == -1)
                mThumbColorNormal = DEFAULT_THUMB_COLOR_NORMAL;
            else 
                mThumbColorNormal = thumbColorNormal;
 
            if (thumbColorPressed == -1)
                mThumbColorPressed = DEFAULT_THUMB_COLOR_PRESSED;
            else 
                mThumbColorPressed = thumbColorPressed;
 
            // Creates the paint and sets the Paint values 
            mPaintNormal = new Paint();
            mPaintNormal.setColor(mThumbColorNormal);
            mPaintNormal.setAntiAlias(true);
 
            mPaintPressed = new Paint();
            mPaintPressed.setColor(mThumbColorPressed);
            mPaintPressed.setAntiAlias(true);
        } 
 
        mHalfWidthNormal = mImageNormal.getWidth() / 2f;
        mHalfHeightNormal = mImageNormal.getHeight() / 2f;
 
        mHalfWidthPressed = mImagePressed.getWidth() / 2f;
        mHalfHeightPressed = mImagePressed.getHeight() / 2f;
 
        // Sets the minimum touchable area, but allows it to expand based on 
        // image size 
        int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, thumbRadiusDP);
 
        mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                                                    targetRadius,
                                                    res.getDisplayMetrics());
 
        mX = mHalfWidthNormal;
        mY = y;
    } 
 
Experience pair programming with AI  Get Codota for Java