Example usage for android.util TypedValue COMPLEX_UNIT_PX

List of usage examples for android.util TypedValue COMPLEX_UNIT_PX

Introduction

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

Prototype

int COMPLEX_UNIT_PX

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is raw pixels.

Usage

From source file:com.lixiang.weather.support.view.smarttab.SmartTabLayout.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 ww  .  j  av  a2s . c o m
@SuppressLint("NewApi")
protected TextView createDefaultTabView(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    // textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        // textView.setBackgroundResource(tabViewBackgroundResId);
    } 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);
    }

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

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.shuyu.apprecycler.view.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundColor(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            if (i == currentPosition) {
                tab.setTextColor(tabTextSelectColor);
            } else {
                tab.setTextColor(tabTextColor);
            }//from  w ww.java2s .c o  m
            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:scroll.com.rdemo.scroll.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);

            if (i == currentPosition) {
                v.setBackgroundResource(tabSelectBackgroundResId);
                tab.setTextColor(indicatorColor);
                tab.setTextSize(indicatorTextSize);
            } else {
                v.setBackgroundResource(tabBackgroundResId);
                tab.setTextColor(tabTextColor);
                tab.setTextSize(tabTextSize);
            }/*from www.  j a v a2 s  .com*/

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;
            IconTabProvider iconTabProvider = (IconTabProvider) pager.getAdapter();
            ViewGroup.LayoutParams params = tab.getLayoutParams();

            if (i == currentPosition) {
                int[] wh = iconTabProvider.getPageIconResWidthAndHeight();
                if (params.width != wh[0] || params.height != wh[1]) {
                    params.width = wh[0];
                    params.height = wh[1];
                    tab.setLayoutParams(params);
                }
                tab.setBackgroundResource(iconTabProvider.getPageIconResId(i));
            } else {
                int[] wh = iconTabProvider.getPageUnSelectIconResWidthAndHeight();
                if (params.width != wh[0] || params.height != wh[1]) {
                    params.width = wh[0];
                    params.height = wh[1];
                    tab.setLayoutParams(params);
                }
                tab.setBackgroundResource(iconTabProvider.getPageUnSelectIconResId(i));
            }
        }
    }
}

From source file:com.fivetrue.workout.timer.view.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < getCount(); i++) {

        View v = tabsContainer.getChildAt(i);
        v.setLayoutParams(defaultTabLayoutParams);
        //            v.setBackgroundResource(tabBackgroundColor);
        if (shouldExpand) {
            v.setPadding(0, 0, 0, 0);/*  w w  w . j a  v a  2 s . c o  m*/
        } else {
            if (i == 0) {
                v.setPadding(tabPadding + tabPadding, 0, tabPadding, 0);
            } else {
                v.setPadding(tabPadding, 0, tabPadding, 0);
            }
        }

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);
            //            tab.setMinWidth(tabMinWidth);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            //            if (textAllCaps) {
            //               if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            //                  tab.setAllCaps(true);
            //               } else {
            //                  tab.setText(tab.getText().toString().toUpperCase(locale));
            //               }
            //            }
        } else if (v instanceof ImageView && tabIconPadding > 0) {
            v.setPadding(tabIconPadding, tabIconPadding, tabIconPadding, tabIconPadding);
        }
    }

}

From source file:com.zxly.o2o.view.MPagerSlidingTab.java

public void initTabStyles() {
    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);
        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }// w ww  .  j  a  v  a  2s  .com
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
                if (oldTab != null) {
                    oldTab.setSelected(false);
                    ((TextView) oldTab).setTextColor(tabTextColor);
                }
                oldTab = tab;
                tab.setSelected(true);
            }
        }
    }
}

From source file:net.fengg.lib.tabsliding.TabSlidingView.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from  www  . ja  v  a 2s. com
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        } else if (v instanceof ImageButton) {
            ImageButton tab = (ImageButton) v;

            if (i == selectedPosition) {
                //?
                tab.setSelected(true);
            }
        } else {
            LinearLayout l = (LinearLayout) v;

            ImageButton icon = (ImageButton) l.getChildAt(0);
            icon.setBackgroundResource(tabBackgroundResId);
            icon.setSelected(false);
            if (i == selectedPosition) {
                icon.setSelected(true);
            }

            TextView text = (TextView) l.getChildAt(1);
            text.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            text.setTypeface(tabTypeface, tabTypefaceStyle);
            text.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    text.setAllCaps(true);
                } else {
                    text.setText(text.getText().toString().toUpperCase(locale));
                }
            }
            if (i == selectedPosition) {
                text.setTextColor(selectedTabTextColor);
            }

        }
    }

}

From source file:com.putaotown.views.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        v.setBackgroundResource(tabBackgroundResId);

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }//from   w w  w  .  jav a2 s .c  o m
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
            }
        } else if (v instanceof ImageButton || v instanceof ViewGroup) {
            if ("mess".equals((String) v.getTag())) {
                if (i == selectedPosition)
                    this.messImage.setImageResource(this.iconTabProvider.getSelectedPageIconResId(i));
                else
                    this.messImage.setImageResource(this.iconTabProvider.getPageIconResId(i));
                if (selectedPosition == 2) //?
                    this.messRedPos.setVisibility(View.GONE);
            } else {
                ImageButton tab = (ImageButton) v;
                tab.setImageResource(0);
                if (i == selectedPosition)
                    tab.setImageResource(this.iconTabProvider.getSelectedPageIconResId(i));
                else
                    tab.setImageResource(this.iconTabProvider.getPageIconResId(i));
            }
        }
    }

}

From source file:com.open.imooc.widght.tab.SmartTabLayout.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(CharSequence title) {
    TextView textView = new TextView(getContext());
    textView.setGravity(Gravity.CENTER);
    textView.setText(title);
    //        textView.setTextColor(tabViewTextColors);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
    textView.setTypeface(Typeface.DEFAULT);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    if (tabViewBackgroundResId != NO_ID) {
        textView.setBackgroundResource(tabViewBackgroundResId);
    } 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);
    }

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

    textView.setPadding(tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0);

    if (tabViewTextMinWidth > 0) {
        textView.setMinWidth(tabViewTextMinWidth);
    }

    return textView;
}

From source file:com.mingle.discolor.PagerSlidingTabStrip.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        //           ;

        if (v instanceof TextView) {

            TextView tab = (TextView) v;
            tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
            tab.setTypeface(tabTypeface, tabTypefaceStyle);
            tab.setTextColor(tabTextColor);

            if (i == selectIndex) {
                tab.setTextColor(selectTitleColor);
                //               tab.setTextColor(indicatorColor);
            }/*from   ww w.j  a  va 2  s  . c  o m*/
            // setAllCaps() is only available from API 14, so the upper case
            // is made manually if we are on a
            // pre-ICS-build
            if (textAllCaps) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    tab.setAllCaps(true);
                } else {
                    tab.setText(tab.getText().toString().toUpperCase(locale));
                }
            }
        }
    }

}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static int getSizeUnits(final String size) {
    int units = TypedValue.COMPLEX_UNIT_PX;
    String unitString = null;/*  w w w.  j a  va 2 s . c  o  m*/

    if (size != null) {
        Matcher m = SIZED_VALUE.matcher(size.trim());
        if (m.matches()) {
            if (m.groupCount() == 2) {
                unitString = m.group(2);
            }
        }
    }

    if (unitString == null) {
        unitString = TiApplication.getInstance().getDefaultUnit();
    }

    if (TiDimension.UNIT_PX.equals(unitString) || TiDimension.UNIT_SYSTEM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PX;
    } else if (TiDimension.UNIT_PT.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_PT;
    } else if (TiDimension.UNIT_DP.equals(unitString) || TiDimension.UNIT_DIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_DIP;
    } else if (TiDimension.UNIT_SP.equals(unitString) || TiDimension.UNIT_SIP.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_SP;
    } else if (TiDimension.UNIT_MM.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_MM;
    } else if (TiDimension.UNIT_CM.equals(unitString)) {
        units = TiDimension.COMPLEX_UNIT_CM;
    } else if (TiDimension.UNIT_IN.equals(unitString)) {
        units = TypedValue.COMPLEX_UNIT_IN;
    } else {
        if (unitString != null) {
            Log.w(TAG, "Unknown unit: " + unitString, Log.DEBUG_MODE);
        }
    }

    return units;
}