Example usage for android.util TypedValue applyDimension

List of usage examples for android.util TypedValue applyDimension

Introduction

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

Prototype

public static float applyDimension(int unit, float value, DisplayMetrics metrics) 

Source Link

Document

Converts an unpacked complex data value holding a dimension to its final floating point value.

Usage

From source file:com.agenmate.lollipop.util.ViewUtils.java

/**
 * Recursive binary search to find the best size for the text.
 *
 * Adapted from https://github.com/grantland/android-autofittextview
 *//*from www.j av a  2s . c o  m*/
public static float getSingleLineTextSize(String text, TextPaint paint, float targetWidth, float low,
        float high, float precision, DisplayMetrics metrics) {
    final float mid = (low + high) / 2.0f;

    paint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, metrics));
    final float maxLineWidth = paint.measureText(text);

    if ((high - low) < precision) {
        return low;
    } else if (maxLineWidth > targetWidth) {
        return getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics);
    } else if (maxLineWidth < targetWidth) {
        return getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics);
    } else {
        return mid;
    }
}

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

public void setItemTextSize(int sp) {
    mItemTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
            getResources().getDisplayMetrics());
    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = getChildAt(i);
        if (child instanceof TextView) {
            ((TextView) child).setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemTextSize);
        }//w ww. j  a  v a  2s.c  o  m
    }
}

From source file:cn.com.hgh.view.PagerSlidingTabStrip.java

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

    setFillViewport(true);// ww w. j  a v a2  s.  co 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);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(0, tabTextColor);

    a.recycle();

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);

    //tab, 
    selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_selectedTabTextColor, indicatorColor);

    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    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.ch.ch_library.smartlayout.SmartTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from ww  w.  j ava 2s  .co  m
    setOverScrollMode(OVER_SCROLL_NEVER);

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
    int textColor = TAB_VIEW_TEXT_COLOR;
    float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int textLayoutId = NO_ID;
    int textViewId = NO_ID;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
    textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor);
    textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    textLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, textLayoutId);
    textViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, textViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    a.recycle();

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * density);
    mTabViewTextAllCaps = textAllCaps;
    mTabViewTextColor = textColor;
    mTabViewTextSize = textSize;
    mTabViewTextHorizontalPadding = textHorizontalPadding;
    mTabViewTextMinWidth = textMinWidth;
    mTabViewLayoutId = textLayoutId;
    mTabViewTextViewId = textViewId;
    mDistributeEvenly = distributeEvenly;

    mTabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
}

From source file:cn.xiaocool.android_etong.view.PagerSlidingTabStrip.java

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

    setFillViewport(true);//w ww .  j  a v a2 s  . co 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);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);

    //tab, 
    selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_selectedTabTextColor, indicatorColor);

    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    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:cc.wudoumi.framework.views.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    tabBackgroundResId = R.drawable.background_tab;
    setFillViewport(true);/* www  .j  a va2 s. c  om*/
    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);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    //tabTextColor = a.getColor(1, tabTextColor);
    textColor = a.getColorStateList(1);
    if (textColor == null) {
        textColor = ColorStateList.valueOf(tabTextColor);
    }
    a.recycle();

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    selecttabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsSelectTextSize,
            tabTextSize);
    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

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

    tabTextSizeChange = tabTextSize != selecttabTextSize;
}

From source file:com.eall.installer.widget.PagerSlidingTabStrip.java

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

    setFillViewport(true);//from   ww  w. j  ava2  s. c om
    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);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);

    //tab,
    selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_selectedTabTextColor, indicatorColor);

    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    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.annanovas.bestprice.Fragment.DashBoardFragment.java

private void updateDashboard() {
    int imageDimen = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
            getResources().getDimension(R.dimen.size_150dp), getResources().getDisplayMetrics());

    myDB.open();/*from w w w  .j  a  va 2  s  .c  o  m*/
    Cursor cursor = myDB.getUserInfo(userType, sharedPreferences.getString("user_phone_number", ""));

    if (userType == AppGlobal.CAR_OWNER) {
        carLayout.setVisibility(View.VISIBLE);
        quotationLayout.setVisibility(View.VISIBLE);
        searchProductLayout.setVisibility(View.VISIBLE);
        if (myDB.getUserCount() > 1) {
            buttonUserType.setVisibility(View.VISIBLE);
        }

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                String name = "";
                if (cursor.getString(cursor.getColumnIndex("firstname")) != null
                        && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) {
                    name = cursor.getString(cursor.getColumnIndex("firstname")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("middlename")) != null
                        && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("lastname")) != null
                        && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("lastname"));
                }
                tvName.setText(name.trim());
                tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                tvEmail.setText(cursor.getString(cursor.getColumnIndex("email")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    //showLog("Image Path: " + AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")));
                    Glide.with(getActivity())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_car_owner).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_car_owner);
                }

                sharedPreferences.edit()
                        .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply();
                sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply();
            }
        }
        cursor.close();
        tvUserType.setText(getResources().getString(R.string.user_type1));

    } else if (userType == AppGlobal.SUPPLIER) {
        tvAddress.setVisibility(View.VISIBLE);
        tvDealership.setVisibility(View.VISIBLE);
        quotationLayout.setVisibility(View.VISIBLE);
        if (myDB.getUserCount() > 1) {
            buttonUserType.setVisibility(View.VISIBLE);
        }

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                String name = "";
                if (cursor.getString(cursor.getColumnIndex("firstname")) != null
                        && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("middlename")) != null
                        && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("lastname")) != null
                        && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("lastname"));
                }
                tvName.setText(name.trim());
                tvAddress.setText(cursor.getString(cursor.getColumnIndex("address")));
                tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                tvEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                tvDealership.setText("Dealership With: "
                        + myDB.getBrandsNameFromUserId(cursor.getInt(cursor.getColumnIndex("id"))));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getActivity())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_supplier).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_supplier);
                }

                sharedPreferences.edit()
                        .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply();
                sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply();
            }
        }
        cursor.close();
        tvUserType.setText(getResources().getString(R.string.user_type2));

    } else if (userType == AppGlobal.DRIVER) {
        tvDrivingLicense.setVisibility(View.VISIBLE);
        tvNid.setVisibility(View.VISIBLE);
        tvExperience.setVisibility(View.VISIBLE);
        pendingTaskLayout.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                String name = "";
                if (cursor.getString(cursor.getColumnIndex("firstname")) != null
                        && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("middlename")) != null
                        && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("lastname")) != null
                        && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("lastname"));
                }
                tvName.setText(name.trim());
                tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                tvEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                tvDrivingLicense.setText(
                        "Driving License no.: " + cursor.getString(cursor.getColumnIndex("drivinglicence")));
                tvNid.setText("NID no.: " + cursor.getString(cursor.getColumnIndex("nid")));
                tvExperience.setText(
                        "Years of Experience: " + cursor.getString(cursor.getColumnIndex("yearofexperience")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getActivity())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_driver).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_driver);
                }

                sharedPreferences.edit()
                        .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply();
                sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply();
            }
        }
        cursor.close();
        tvUserType.setText(getResources().getString(R.string.user_type3));

    } else if (userType == AppGlobal.SHOP_WORKER) {
        tvShopName.setVisibility(View.VISIBLE);
        tvNid.setVisibility(View.VISIBLE);
        pendingTaskLayout.setVisibility(View.VISIBLE);

        if (!cursor.isLast()) {
            while (cursor.moveToNext()) {
                String name = "";
                if (cursor.getString(cursor.getColumnIndex("firstname")) != null
                        && !cursor.getString(cursor.getColumnIndex("firstname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("firstname")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("middlename")) != null
                        && !cursor.getString(cursor.getColumnIndex("middlename")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("middlename")) + " ";
                }
                if (cursor.getString(cursor.getColumnIndex("lastname")) != null
                        && !cursor.getString(cursor.getColumnIndex("lastname")).equals("null")) {
                    name = name + cursor.getString(cursor.getColumnIndex("lastname"));
                }
                tvName.setText(name.trim());
                tvPhoneNumber.setText(cursor.getString(cursor.getColumnIndex("phone")));
                tvEmail.setText(cursor.getString(cursor.getColumnIndex("email")));
                tvShopName.setText("Shop Name: " + cursor.getString(cursor.getColumnIndex("shopname")));
                tvNid.setText("NID no.: " + cursor.getString(cursor.getColumnIndex("nid")));

                if (cursor.getString(cursor.getColumnIndex("image")) != null
                        && !cursor.getString(cursor.getColumnIndex("image")).equals("null")) {
                    Glide.with(getActivity())
                            .load(AppGlobal.userImagePath + cursor.getString(cursor.getColumnIndex("image")))
                            .error(R.drawable.ic_shop_worker).dontAnimate().override(imageDimen, imageDimen)
                            .into(userImage);
                } else {
                    userImage.setImageResource(R.drawable.ic_shop_worker);
                }

                sharedPreferences.edit()
                        .putString("api_token", cursor.getString(cursor.getColumnIndex("api_token"))).apply();
                sharedPreferences.edit().putInt("user_id", cursor.getInt(cursor.getColumnIndex("id"))).apply();
            }
        }
        cursor.close();
        tvUserType.setText(getResources().getString(R.string.user_type4));
    }
    myDB.close();
}

From source file:com.appyvet.materialrangebar.PinView.java

/**
 * The view is created empty with a default constructor. Use init to set all the initial
 * variables for the pin/*from w  w w. jav  a  2s. com*/
 *
 * @param ctx                 Context
 * @param y                   The y coordinate to raw the pin (i.e. the bar location)
 * @param pinRadiusDP         the initial size of the pin
 * @param pinColor            the color of the pin
 * @param textColor           the color of the value text in the pin
 * @param circleRadius        the radius of the selector circle
 * @param circleColor         the color of the selector circle
 * @param circleBoundaryColor The color of the selector circle boundary
 * @param circleBoundarySize  The size of the selector circle boundary line
 * @param minFont             the minimum font size for the pin text
 * @param maxFont             the maximum font size for the pin text
 * @param pinsAreTemporary    whether to show the pin initially or just the circle
 */
public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius,
        int circleColor, int circleBoundaryColor, float circleBoundarySize, float minFont, float maxFont,
        boolean pinsAreTemporary) {

    mRes = ctx.getResources();
    mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate);

    mDensity = getResources().getDisplayMetrics().density;
    mMinPinFont = minFont / mDensity;
    mMaxPinFont = maxFont / mDensity;
    mPinsAreTemporary = pinsAreTemporary;

    mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, mRes.getDisplayMetrics());
    mCircleRadiusPx = circleRadius;
    mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.5f,
            mRes.getDisplayMetrics());
    // If one of the attributes are set, but the others aren't, set the
    // attributes to default
    if (pinRadiusDP == -1) {
        mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP,
                mRes.getDisplayMetrics());
    } else {
        mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP,
                mRes.getDisplayMetrics());
    }
    //Set text size in px from dp
    int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, mRes.getDisplayMetrics());

    // Creates the paint and sets the Paint values
    mTextPaint = new Paint();
    mTextPaint.setColor(textColor);
    mTextPaint.setAntiAlias(true);
    mTextPaint.setTextSize(textSize);
    // Creates the paint and sets the Paint values
    mCirclePaint = new Paint();
    mCirclePaint.setColor(circleColor);
    mCirclePaint.setAntiAlias(true);

    if (circleBoundarySize != 0) {
        mCircleBoundaryPaint = new Paint();
        mCircleBoundaryPaint.setStyle(Paint.Style.STROKE);
        mCircleBoundaryPaint.setColor(circleBoundaryColor);
        mCircleBoundaryPaint.setStrokeWidth(circleBoundarySize);
        mCircleBoundaryPaint.setAntiAlias(true);
    }

    this.pinColor = pinColor;

    // Sets the minimum touchable area, but allows it to expand based on
    // image size
    int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx);

    mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius,
            mRes.getDisplayMetrics());
    mY = y;
}

From source file:cn.qbcbyb.library.view.VerticalPagerSlidingTabStrip.java

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

    setFillViewport(true);//from   w w w .j  a va2s  . 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);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    tabSelectedTextSize = tabTextSize;

    // get custom attrs

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

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_textSize, tabTextSize);
    tabSelectedTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_selectedTextSize,
            tabTextSize);
    ColorStateList colorStateList = a.getColorStateList(R.styleable.PagerSlidingTabStrip_android_textColor);
    if (colorStateList != null) {
        tabTextColor = colorStateList;
    }

    a.recycle();

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

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

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