Example usage for android.util TypedValue COMPLEX_UNIT_SP

List of usage examples for android.util TypedValue COMPLEX_UNIT_SP

Introduction

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

Prototype

int COMPLEX_UNIT_SP

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

Click Source Link

Document

#TYPE_DIMENSION complex unit: Value is a scaled pixel.

Usage

From source file:com.materialdesign.view.tab.TabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

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

        View tabView = createDefaultTabView(getContext());

        TextView tabText = (TextView) tabView.findViewById(R.id.tv_tabText);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        if (mTabs.size() > i) {
            Tab tab = mTabs.get(i);//from  w w w .ja va2s  .co  m
            if (tab.icon != 0) {
                tabIcon.setImageResource(tab.icon);
            } else {
                tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextMediumSize);
                int padding = (int) (mTabViewCustomPadding * getResources().getDisplayMetrics().density);
                tabView.setPadding(0, padding, 0, padding);
            }

            if (tab.tabText != null) {
                tabText.setText(tab.tabText);
            }
        }

        tabText.setTextColor(mTabTextColorStateList);

        if (mTabViewTextCustomSize != 0) {
            tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextCustomSize);
        }

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT,
                1);
        if (i == 0) {
            tabText.setSelected(true);
            tabIcon.setSelected(true);
        }
        mTabStrip.addView(tabView, lp);
    }

    //tab,tab-?
    if (hasMiddleTabView) {
        View tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_layout, null);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText);

        textView.setVisibility(GONE);

        LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(
                (int) (36 * getResources().getDisplayMetrics().density),
                (int) (36 * getResources().getDisplayMetrics().density));
        tabIcon.setLayoutParams(iconParams);
        tabIcon.setImageResource(mMiddleIconResId);

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,
                1);

        mTabStrip.addView(tabView, 2, lp);
    }
}

From source file:com.materialdesign.view.tab.VerticalTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

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

        View tabView = createDefaultTabView(getContext());

        TextView tabText = (TextView) tabView.findViewById(R.id.tv_tabText);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        if (mTabs.size() > i) {
            Tab tab = mTabs.get(i);//from w  w w. ja va  2 s .  com
            if (tab.icon != 0) {
                tabIcon.setImageResource(tab.icon);
            } else {
                tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextMediumSize);
                int padding = (int) (mTabViewCustomPadding * getResources().getDisplayMetrics().density);
                tabView.setPadding(0, padding, 0, padding);
            }

            if (tab.tabText != null) {
                tabText.setText(tab.tabText);
            }
        }

        tabText.setTextColor(mTabTextColorStateList);

        if (mTabViewTextCustomSize != 0) {
            tabText.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabViewTextCustomSize);
        }

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 0, 1);
        if (i == 0) {
            tabText.setSelected(true);
            tabIcon.setSelected(true);
        }
        mTabStrip.addView(tabView, lp);
    }

    if (hasMiddleTabView) {
        View tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_layout, null);

        ImageView tabIcon = (ImageView) tabView.findViewById(R.id.iv_tabIcon);

        TextView textView = (TextView) tabView.findViewById(R.id.tv_tabText);

        textView.setVisibility(GONE);

        LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(
                (int) (36 * getResources().getDisplayMetrics().density),
                (int) (36 * getResources().getDisplayMetrics().density));
        tabIcon.setLayoutParams(iconParams);
        tabIcon.setImageResource(mMiddleIconResId);

        tabView.setOnClickListener(tabClickListener);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,
                1);

        mTabStrip.addView(tabView, 2, lp);
    }
}

From source file:com.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private float spToPixels(int sp) {
    Resources r = getResources();
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics());
}

From source file:com.achenging.view.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)}.//w w w .  j  a va 2s  .c om
 */
protected TextView createDefaultTabView(Context context) {
    AppCompatTextView textView = new AppCompatTextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setBackgroundColor(Color.WHITE);
    textView.setPadding(mTextPadding, mTextPadding, mTextPadding, mTextPadding);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);

    if (mAvgSplit) {
        int screenWidth = getResources().getDisplayMetrics().widthPixels;
        textView.setWidth(screenWidth / mViewPager.getAdapter().getCount());
    }

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

    return textView;
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private TextView createErrorView(String key) {
    TextView ret = new TextView(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//from   ww  w.  j  a va  2s. co m
    params.topMargin = 10;
    params.bottomMargin = 10;
    ret.setLayoutParams(params);
    ret.setTextColor(Color.RED);
    ret.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);

    HashMap<String, String> errors = mAccount.getErrors();
    if (errors != null && errors.containsKey(key)) {
        ret.setText(errors.get(key));
        ret.setVisibility(View.VISIBLE);
    } else {
        ret.setVisibility(View.INVISIBLE);
    }

    return ret;
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

/**
 * Refreshes funds table with fetched data
 *
 * @param response JSONObject with funds data
 *///from  w  ww .ja v a 2  s .c o  m
private void refreshFunds(JSONObject response) {
    try {
        if (response == null) {
            Toast.makeText(getActivity(), getResources().getString(R.string.GeneralErrorText),
                    Toast.LENGTH_LONG).show();
            return;
        }
        String notificationText;
        if (response.getInt("success") == 1) {

            View.OnClickListener fillAmount = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ScrollView scrollView = (ScrollView) getView();
                    if (scrollView != null) {
                        EditText tradeAmount = (EditText) scrollView.findViewById(R.id.TradeAmount);
                        tradeAmount.setText(((TextView) v).getText());
                        scrollView.smoothScrollTo(0, scrollView.findViewById(R.id.tradingSection).getBottom());
                    }
                }
            };

            notificationText = getResources().getString(R.string.FundsInfoUpdatedtext);
            TableLayout fundsContainer = (TableLayout) getView().findViewById(R.id.FundsContainer);
            fundsContainer.removeAllViews();
            JSONObject funds = response.getJSONObject("return").getJSONObject("funds");
            JSONArray fundsNames = response.getJSONObject("return").getJSONObject("funds").names();
            List<String> arrayList = new ArrayList<>();

            for (int i = 0; i < fundsNames.length(); i++) {
                arrayList.add(fundsNames.getString(i));
            }
            Collections.sort(arrayList);
            TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0,
                    ViewGroup.LayoutParams.MATCH_PARENT, 1);

            for (String anArrayList : arrayList) {

                TableRow row = new TableRow(getActivity());
                TextView currency = new TextView(getActivity());
                TextView amount = new TextView(getActivity());
                currency.setText(anArrayList.toUpperCase(Locale.US));
                amount.setText(funds.getString(anArrayList));
                currency.setLayoutParams(layoutParams);
                currency.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                currency.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
                currency.setGravity(Gravity.CENTER);
                amount.setLayoutParams(layoutParams);
                amount.setGravity(Gravity.CENTER);
                amount.setOnClickListener(fillAmount);
                row.addView(currency);
                row.addView(amount);
                fundsContainer.addView(row);
            }

        } else {
            notificationText = response.getString("error");
        }

        mCallback.makeNotification(ConstantHolder.ACCOUNT_INFO_NOTIF_ID, notificationText);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private TextView createTitle(String text) {
    TextView ret = new TextView(mContext);
    LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    ret.setLayoutParams(params);//from w  ww.j a va  2s.  com
    ret.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
    ret.setTextColor(Color.BLACK);
    ret.setText(text);

    return ret;
}

From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java

protected TextView createDefaultTextTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    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);
    }//from   w ww. j  a  va2s  .com

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

    //System.out.println("c " + titleColor);
    if (titleColor != null) {
        textView.setTextColor(titleColor);
    }

    return textView;
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

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

    this.mDebugPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    this.mDebugPaint.setColor(Color.RED);
    this.mDebugPaint.setStrokeWidth(5);
    this.mDebugPaint.setTextSize(
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 20, getResources().getDisplayMetrics()));

    ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop() / 2;
    this.mVelocity = VelocityTracker.obtain();

    mMinimumVelocity = config.getScaledMinimumFlingVelocity();
    mMaximumVelocity = config.getScaledMaximumFlingVelocity();

    this.mTopEdgeEffect = new EdgeEffect(getContext());
    this.mBottomEdgeEffect = new EdgeEffect(getContext());

    this.mLeftEdgeEffect = new EdgeEffect(getContext());
    this.mRightEdgeEffect = new EdgeEffect(getContext());

    mDividerHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f,
            getResources().getDisplayMetrics());
    mDivider = new ColorDrawable(Color.LTGRAY);

    if (attrs != null)
        initAttrs(attrs);/*from   w w  w. j  a v  a  2  s  . c  o  m*/

    setWillNotDraw(false);

    previewInEditMode();
}

From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java

private float sp2px(float sp) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, this.metrics);
}