Example usage for android.util TypedValue COMPLEX_UNIT_DIP

List of usage examples for android.util TypedValue COMPLEX_UNIT_DIP

Introduction

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

Prototype

int COMPLEX_UNIT_DIP

To view the source code for android.util TypedValue COMPLEX_UNIT_DIP.

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is Device Independent Pixels.

Usage

From source file:com.bluelinelabs.conductor.demo.widget.ElasticDragDismissFrameLayout.java

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

    dragDismissDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80,
            getResources().getDisplayMetrics());
    dragDismissFraction = 0.7f;//  w w  w .  j  a v a 2s  . c  o m
    dragDismissScale = 0.8f;
    shouldScale = true;
}

From source file:com.csform.android.uiapptemplate.TabSocialActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tab_social);

    toolbar = (Toolbar) findViewById(R.id.toolbar_tab_social);
    toolbar.setTitle("Tabs social");
    ImageView toolbarImage = (ImageView) toolbar.findViewById(R.id.toolbar_tab_social_image);
    toolbarLike = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_like);
    toolbarFavorite = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_favorite);
    toolbarShare = (TextView) toolbar.findViewById(R.id.toolbar_tab_social_share);

    ImageUtil.displayRoundImage(toolbarImage, "http://pengaja.com/uiapptemplate/newphotos/profileimages/0.jpg",
            null);//from w  w w.java2 s .  com
    toolbarLike.setOnClickListener(this);
    toolbarFavorite.setOnClickListener(this);
    toolbarShare.setOnClickListener(this);
    setSupportActionBar(toolbar);
    tabs = (PagerSlidingTabStrip) findViewById(R.id.activity_tab_social_tabs);
    pager = (ViewPager) findViewById(R.id.activity_tab_social_pager);

    adapter = new MyPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(adapter);
    tabs.setViewPager(pager);
    final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
            getResources().getDisplayMetrics());
    pager.setPageMargin(pageMargin);
    pager.setCurrentItem(2);

    tabs.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
        @Override
        public void onTabReselected(int position) {
            Toast.makeText(TabSocialActivity.this, "Tab reselected: " + position, Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:cc.kenai.common.AnimatedSvgView.java

private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);/*www  . ja v  a 2 s.c om*/
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        Log.i(TAG, "mViewportWidth=" + mViewportWidth);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_oakSvgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_oakSvgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_oakSvgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }
    loadConfig();
}

From source file:com.azhansy.linky.view.PagerSlidingIndicator.java

public PagerSlidingIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//w w w .  j a va  2  s .c o m
    setWillNotDraw(false);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);

    backgroundStrokeWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, backgroundStrokeWidth,
            dm);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingIndicator);

    shouldExpand = a.getBoolean(R.styleable.PagerSlidingIndicator_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingIndicator_scrollOffset, scrollOffset);

    backgroundStrokeColor = a.getColor(R.styleable.PagerSlidingIndicator_background_stroke_color,
            backgroundStrokeColor);
    backgroundStrokeWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingIndicator_background_stroke_width,
            backgroundStrokeWidth);

    backgroundColor = a.getColor(R.styleable.PagerSlidingIndicator_background_color, backgroundColor);

    checkedBackgroundColor = a.getColor(R.styleable.PagerSlidingIndicator_checked_background_color,
            checkedBackgroundColor);

    a.recycle();

    // 
    backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    backgroundPaint.setColor(backgroundColor);
    backgroundPaint.setStyle(Style.FILL);

    // 
    checkedBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    checkedBackgroundPaint.setColor(checkedBackgroundColor);
    checkedBackgroundPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

}

From source file:com.example.QQReader.OpenSourceWidget.astuetz.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {

    super(context, attrs, defStyle);

    setFillViewport(true);//from ww w.  ja v a 2s  . c o m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.evilduck.animtest.DraggedPanelLayout.java

public void initAttrs(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.DraggedPanelLayout, 0, 0);

    try {//ww w .j  a  va2 s . c  om
        parallaxFactor = a.getFloat(R.styleable.DraggedPanelLayout_parallax_factor, PARALLAX_FACTOR);
        if (parallaxFactor < 0.1 || parallaxFactor > 0.9) {
            parallaxFactor = PARALLAX_FACTOR;
        }

        int defaultHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        bottomPanelPeekHeight = a.getDimensionPixelSize(R.styleable.DraggedPanelLayout_bottom_panel_height,
                defaultHeight);
        int shadowDrawableId = a.getResourceId(R.styleable.DraggedPanelLayout_shadow_drawable, -1);
        if (shadowDrawableId != -1) {
            shadowDrawable = getResources().getDrawable(shadowDrawableId);
            willDrawShadow = true;
            setWillNotDraw(!willDrawShadow);
        }
    } finally {
        a.recycle();
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = configuration.getScaledTouchSlop();
}

From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java

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

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);//from www .  j ava 2 s .  com

    mMinTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_MIN_TEXT_SIZE,
            getResources().getDisplayMetrics());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingTitleLayout);

    mExpandedMargin = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedMargin, 0);
    mRequestedExpandedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_expandedTextSize, 0);
    mRequestedCollapsedTitleTextSize = a
            .getDimensionPixelSize(R.styleable.CollapsingTitleLayout_collapsedTextSize, 0);
    mTextPaint.setColor(a.getColor(R.styleable.CollapsingTitleLayout_android_textColor, Color.WHITE));

    final int defaultMinTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            DEFAULT_MIN_TEXT_SIZE, getResources().getDisplayMetrics());
    mMinTextSize = a.getDimensionPixelSize(R.styleable.CollapsingTitleLayout_minTextSize, defaultMinTextSize);

    a.recycle();

    mTextPaintBounds = new Rect();
    mDrawnTextBounds = new Rect();
    mToolbarContentBounds = new Rect();

    setWillNotDraw(false);
}

From source file:org.lol.reddit.common.General.java

public static int dpToPixels(final Context context, final float dp) {
    return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
            context.getResources().getDisplayMetrics()));
}

From source file:com.evilduck.piano.views.instrument.PianoView.java

public PianoView(Context context, AttributeSet attrs) {
    super(context, attrs);

    init();//from www .j av  a2s. co m

    leftEdgeEffect = new EdgeEffectCompat(getContext());
    rightEdgeEffect = new EdgeEffectCompat(getContext());

    setVerticalScrollBarEnabled(false);
    setHorizontalScrollBarEnabled(true);

    TypedArray a = context.obtainStyledAttributes(R.styleable.View);
    initializeScrollbars(a);
    a.recycle();

    TypedArray pianoAttrs = context.obtainStyledAttributes(attrs, R.styleable.PianoView);

    boolean asBitmaps;
    int circleColor;
    float circleRadius;
    float circleTextSize;
    try {
        asBitmaps = pianoAttrs.getBoolean(R.styleable.PianoView_overlay_bitmaps, true);
        circleColor = pianoAttrs.getColor(R.styleable.PianoView_overlay_color, Color.GREEN);
        circleRadius = pianoAttrs.getDimension(R.styleable.PianoView_overlay_circle_radius, TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, context.getResources().getDisplayMetrics()));
        circleTextSize = pianoAttrs.getDimension(R.styleable.PianoView_overlay_circle_text_size, TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, context.getResources().getDisplayMetrics()));
    } finally {
        pianoAttrs.recycle();
    }

    keyboard = new Keyboard(getContext(), asBitmaps, circleColor, circleRadius, circleTextSize);
}

From source file:com.donsen.svg.ui.common.AnimatedSvgView.java

@SuppressWarnings("NewApi")
private void init(Context context, AttributeSet attrs) {
    mFillPaint = new Paint();
    mFillPaint.setAntiAlias(true);//from w w w. j av a2s.co m
    mFillPaint.setStyle(Paint.Style.FILL);

    mMarkerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, MARKER_LENGTH_DIP,
            getResources().getDisplayMetrics());

    mTraceColors = new int[1];
    mTraceColors[0] = Color.BLACK;
    mTraceResidueColors = new int[1];
    mTraceResidueColors[0] = Color.argb(50, 0, 0, 0);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AnimatedSvgView);

        mViewportWidth = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeX, 433);
        mRatioSizingInfo.aspectRatioWidth = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeX, 433);
        mViewportHeight = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeY, 433);
        mRatioSizingInfo.aspectRatioHeight = a.getInt(R.styleable.AnimatedSvgView_svgImageSizeY, 433);

        mTraceTime = a.getInt(R.styleable.AnimatedSvgView_svgTraceTime, 2000);
        mTraceTimePerGlyph = a.getInt(R.styleable.AnimatedSvgView_svgTraceTimePerGlyph, 1000);
        mFillStart = a.getInt(R.styleable.AnimatedSvgView_svgFillStart, 1200);
        mFillTime = a.getInt(R.styleable.AnimatedSvgView_svgFillTime, 1000);

        a.recycle();

        mViewport = new PointF(mViewportWidth, mViewportHeight);
    }

    // See https://github.com/romainguy/road-trip/blob/master/application/src/main/java/org/curiouscreature/android/roadtrip/IntroView.java
    // Note: using a software layer here is an optimization. This view works with
    // hardware accelerated rendering but every time a path is modified (when the
    // dash path effect is modified), the graphics pipeline will rasterize the path
    // again in a new texture. Since we are dealing with dozens of paths, it is much
    // more efficient to rasterize the entire view into a single re-usable texture
    // instead. Ideally this should be toggled using a heuristic based on the number
    // and or dimensions of paths to render.
    // Note that PathDashPathEffects can lead to clipping issues with hardware rendering.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_SOFTWARE, null);
    }
}