List of usage examples for android.util TypedValue COMPLEX_UNIT_SP
int COMPLEX_UNIT_SP
To view the source code for android.util TypedValue COMPLEX_UNIT_SP.
Click Source Link
From source file:codepath.watsiapp.utils.Util.java
public static float getPixelsFont(Activity activity, float sp) { Resources r = activity.getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics()); return px;//from w ww. ja v a 2 s .c o m }
From source file:com.crazy.toutiaonews.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 . jav a2 s .c om*/ */ protected TextView createDefaultTabView(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); // Holo ?? // 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); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.leo.tablayout.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)}.// www .j av a 2s . com */ protected TextView createDefaultTabView(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); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // TypedValue outValue = new TypedValue(); // getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, // outValue, true); // textView.setBackgroundResource(outValue.resourceId); // textView.setAllCaps(true); if (colorStateList != null) { textView.setTextColor(colorStateList); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.bryan.example.widget.slidingtablayout.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 v a 2 s. c om*/ @SuppressLint("NewApi") protected TextView createDefaultTabView(Context context) { /** * ?Holo?? */ 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);// textView.setTypeface(Typeface.DEFAULT); // 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); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.gustavofao.materialtabs.SlidingTabLayout.java
private void populateTabStrip() { final SlidingFragmentPagerAdapter adapter = (SlidingFragmentPagerAdapter) mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); if (tabType == null) tabType = TEXT_ONLY;// ww w. j a v a 2 s .c om int focused_color = customFocusedColor != 0 ? customFocusedColor : FOCUSED_WHITE; int unfocused_color = customUnfocusedColor != 0 ? customUnfocusedColor : NOT_FOCUSED_WHITE; for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null; ImageView tabImageView = null; switch (tabType) { case TEXT_ONLY: tabView = LayoutInflater.from(getContext()).inflate(TEXT_ONLY_TAB, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(TEXT_ID); break; case ICON_ONLY: tabView = LayoutInflater.from(getContext()).inflate(ICON_ONLY_TAB, mTabStrip, false); tabImageView = (ImageView) tabView.findViewById(ICON_ID); break; case TEXT_ICON: tabView = LayoutInflater.from(getContext()).inflate(TEXT_ICON_TAB, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(TEXT_ID); tabImageView = (ImageView) tabView.findViewById(ICON_ID); break; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } if (i == mViewPager.getCurrentItem()) tabView.setSelected(true); if (tabTitleView != null && adapter.getPageTitle(i) != null) { tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, this.textSize); tabTitleView.setTextColor(i == mViewPager.getCurrentItem() ? focused_color : unfocused_color); } if (tabImageView != null && adapter.getPageDrawable(i) != null) { tabImageView.setImageDrawable(adapter.getPageDrawable(i)); tabImageView.setColorFilter(i == mViewPager.getCurrentItem() ? focused_color : unfocused_color, PorterDuff.Mode.MULTIPLY); } tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:com.QuarkLabs.BTCeClient.fragments.OrdersBookFragment.java
@Override public void onLoadFinished(Loader<JSONObject> loader, JSONObject data) { if (data == null) { Toast.makeText(getActivity(), R.string.GeneralErrorText, Toast.LENGTH_LONG).show(); } else if (data.length() == 0) { Toast.makeText(getActivity(), R.string.GeneralErrorText, Toast.LENGTH_LONG).show(); } else {// w ww . j a va2 s . c om final JSONArray asks = data.optJSONArray("asks"); final JSONArray bids = data.optJSONArray("bids"); mAsksAdapter.pushData(asks); mBidsAdapter.pushData(bids); mAsksList.setAdapter(mAsksAdapter); mBidsList.setAdapter(mBidsAdapter); mChartArea.removeAllViews(); StockChartView chartView = new StockChartView(getActivity()); final LinearSeries asksSeries = new LinearSeries(); final LinearSeries bidsSeries = new LinearSeries(); asksSeries.getAppearance().setOutlineColor(0xffff4444); bidsSeries.getAppearance().setOutlineColor(0xff0099cc); double sumAsks = 0.0; double sumBids = 0.0; for (int i = 0; i < bids.length(); i++) { sumBids += bids.optJSONArray(i).optDouble(1); } for (int i = bids.length() - 1; i >= 0; i--) { sumBids -= bids.optJSONArray(i).optDouble(1); bidsSeries.addPoint(sumBids); } for (int i = 0; i < asks.length(); i++) { asksSeries.addPoint(sumAsks); sumAsks += asks.optJSONArray(i).optDouble(1); } asksSeries.setIndexOffset(bidsSeries.getPointCount()); chartView.addArea().getSeries().add(asksSeries); chartView.getAreas().get(0).getSeries().add(bidsSeries); Axis.ILabelFormatProvider provider = new Axis.ILabelFormatProvider() { @Override public String getAxisLabel(Axis axis, double v) { int index = bidsSeries.convertToArrayIndex(v); if (index < 0) { index = 0; } if (index >= 0) { if (index >= bidsSeries.getPointCount()) { index = asksSeries.convertToArrayIndex(v); if (index < 0) { index = 0; } if (index >= 0) { if (index >= asksSeries.getPointCount()) { index = asksSeries.getPointCount() - 1; } } return asks.optJSONArray(index).optString(0); } return bids.optJSONArray(bidsSeries.getPointCount() - 1 - index).optString(0); } return null; } }; chartView.getAreas().get(0).getBottomAxis().setLabelFormatProvider(provider); //customizing fonts for chart chartView.getAreas().get(0).setTitle( "Market Depth for " + mPairsSpinner.getSelectedItem().toString() + " (Price vs. Volume)"); chartView.getAreas().get(0).getPlot().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 14, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getLeftAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getTopAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getBottomAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getRightAxis().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getBottomAxis().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 9, getResources().getDisplayMetrics())); chartView.getAreas().get(0).getRightAxis().getAppearance().getFont().setSize( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 9, getResources().getDisplayMetrics())); mChartArea.addView(chartView); chartView.invalidate(); } }
From source file:com.axolotl.yanews.customize.SlidingTabLayout.java
/** * tabview. tab view/*from w w w.ja v a 2s. c om*/ * {@link #setCustomTabView(int, int)}. */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context, null, 0); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTab_text_size_sp); if (mBold) { textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD); } else { textView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); } if (mChangeTextColor) { textView.setTextColor(mNormalColor); } textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (mBackgroundResource != 0) { textView.setBackgroundResource(mBackgroundResource); } 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); } } //wtf // 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, 0, padding, 0); return textView; }
From source file:com.lizhi.library.widget.WechatTab.java
private void setTabsValue() { DisplayMetrics dm = getResources().getDisplayMetrics(); // Tab?/*from www .j a va 2 s.co m*/ setShouldExpand(true); // Tab? setDividerColor(Color.TRANSPARENT); // Tab setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm)); // Tab Indicator setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, dm)); // Tab? setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, dm)); // Tab Indicator //TODO // setIndicatorColor(getResources().getColor(R.color.theme_color)); // Tab () //TODO // setSelectedTextColor(getResources().getColor(R.color.theme_color)); // ?Tab setTabBackground(0); }
From source file:com.kksmartcontrol.view.pagersliding.PagerSlidingTabStrip.java
/** * PagerSlidingTabStrip?//ww w . ja v a 2s . c o m */ public void setTabsValue(DisplayMetrics displayMetrics) { // Tab? setShouldExpand(true); // Tab? setDividerColor(Color.TRANSPARENT); // Tab setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, displayMetrics)); // Tab Indicator setIndicatorHeight((int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, displayMetrics) / 1.5)); // Tab? setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, displayMetrics)); // Tab Indicator setIndicatorColor(Color.parseColor("#45c01a")); // Tab () setSelectedTextColor(Color.parseColor("#45c01a")); // Tab setTabBackground(0); }
From source file:com.cairoconfessions.MainActivity.java
public void addLocation(View view) { TextView newView = new TextView(this); AutoCompleteTextView addLoc = ((AutoCompleteTextView) findViewById(R.id.addLocation)); String newLoc = addLoc.getText().toString(); ViewGroup locList = ((ViewGroup) findViewById(R.id.locations)); boolean notFound = true; for (int i = 0; i < locList.getChildCount(); i++) { if (newLoc.equals(((TextView) locList.getChildAt(i)).getText().toString())) notFound = false;/*from w w w . j ava2 s.c o m*/ break; } if (Arrays.asList(COUNTRIES).contains(newLoc) && notFound) { newView.setText(newLoc); newView.setClickable(true); newView.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { addItem(view); } }); float scale = getResources().getDisplayMetrics().density; newView.setGravity(17); newView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30); newView.setBackgroundResource(R.drawable.city2); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) (150 * scale)); lp.setMargins((int) (0 * scale), (int) (0 * scale), (int) (0 * scale), (int) (2 * scale)); newView.setLayoutParams(lp); locList.addView(newView, 0); addLoc.setText(""); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(addLoc.getWindowToken(), 0); addLoc.setCursorVisible(false); } else { Toast.makeText(this, "Invalid location", Toast.LENGTH_LONG).show(); } }