List of usage examples for android.util TypedValue COMPLEX_UNIT_PX
int COMPLEX_UNIT_PX
To view the source code for android.util TypedValue COMPLEX_UNIT_PX.
Click Source Link
From source file:com.it520.activity.main.wight.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)}./* www . ja v a2 s . c om*/ */ 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.yibairun.ui.components.PagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { RelativeLayout tabLayout = (RelativeLayout) tabsContainer.getChildAt(i); View v = tabLayout.getChildAt(0); 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)); }//ww w .j a v a 2 s. c om } if (i == selectedPosition) { tab.setTextColor(selectedTabTextColor); } } } }
From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java
/** * Specify whether this widget should automatically scale the text to try to perfectly fit * within the layout bounds. If at least one value from the <code>presetSizes</code> is valid * then the type of auto-size is set to {@link TextViewCompat#AUTO_SIZE_TEXT_TYPE_UNIFORM}. * * @param presetSizes an {@code int} array of sizes in pixels * @param unit the desired dimension unit for the preset sizes above. See {@link TypedValue} for * the possible dimension units * * @throws IllegalArgumentException if all of the <code>presetSizes</code> are invalid. *_//from www . j ava2 s .c o m * @attr ref R.styleable#AppCompatTextView_autoSizeTextType * @attr ref R.styleable#AppCompatTextView_autoSizePresetSizes * * @see #setAutoSizeTextTypeWithDefaults(int) * @see #setAutoSizeTextTypeUniformWithConfiguration(int, int, int, int) * @see #getAutoSizeMinTextSize() * @see #getAutoSizeMaxTextSize() * @see #getAutoSizeTextAvailableSizes() * * @hide */ @RestrictTo(LIBRARY_GROUP) void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull int[] presetSizes, int unit) throws IllegalArgumentException { if (supportsAutoSizeText()) { final int presetSizesLength = presetSizes.length; if (presetSizesLength > 0) { int[] presetSizesInPx = new int[presetSizesLength]; if (unit == TypedValue.COMPLEX_UNIT_PX) { presetSizesInPx = Arrays.copyOf(presetSizes, presetSizesLength); } else { final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics(); // Convert all to sizes to pixels. for (int i = 0; i < presetSizesLength; i++) { presetSizesInPx[i] = Math .round(TypedValue.applyDimension(unit, presetSizes[i], displayMetrics)); } } mAutoSizeTextSizesInPx = cleanupAutoSizePresetSizes(presetSizesInPx); if (!setupAutoSizeUniformPresetSizesConfiguration()) { throw new IllegalArgumentException( "None of the preset sizes is valid: " + Arrays.toString(presetSizes)); } } else { mHasPresetAutoSizeValues = false; } if (setupAutoSizeText()) { autoSizeText(); } } }
From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java
/** update the style of number text */ private void updateNumTextStyle(TextView tab) { tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumTextSize); tab.setTypeface(mTabTypeface, mTabTypefaceStyle); tab.setTextColor(mNumTextColor);//from www . j av a 2s . co m if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { setBackgroud(tab); } else { setBackgroundJelly(tab); } }
From source file:com.shine.demo.viewpager.smartTabLayout.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 a v a 2 s . com */ 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.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 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(0, tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding); if (tabViewTextMinWidth > 0) { textView.setMinHeight(tabViewTextMinWidth); } return textView; }
From source file:pageslidingtabstrip.ConsumingPagerSlidingTabStrip.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setBackgroundResource(tabBackgroundResId); if (v instanceof RelativeLayout) { TextView tab = (TextView) v.findViewById(R.id.text); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab.setTypeface(tabTypeface, tabTypefaceStyle); 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 .ja va 2 s.co m*/ } } else { TextView classname = (TextView) v.findViewById(R.id.classname); TextView schoolname = (TextView) v.findViewById(R.id.schoolname); classname.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); classname.setTypeface(tabTypeface, tabTypefaceStyle); schoolname.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); schoolname.setTypeface(tabTypeface, tabTypefaceStyle); if (textAllCaps) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { classname.setAllCaps(true); schoolname.setAllCaps(true); } else { classname.setText(classname.getText().toString().toUpperCase(locale)); schoolname.setText(schoolname.getText().toString().toUpperCase(locale)); } } } } }
From source file:com.jch.lib.view.PagerSlidingTabStrip.java
private void updateCurTab(int position) { for (int i = 0; i < tabCount; i++) { View view = tabsContainer.getChildAt(i); if (view instanceof TextView) { TextView tab = (TextView) view; if (i == position) { tab.setTextColor(curTabTextColor); tab.setTypeface(tabTypeface, curTypefaceStyle); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, curTabTextSize); } else { tab.setTextColor(tabTextColor); tab.setTypeface(tabTypeface, tabTypefaceStyle); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); }// ww w.java2 s. c o m } } }
From source file:com.homechart.app.commont.matertab.MaterialTabs.java
private void updateTabStyles() { for (int i = 0; i < tabCount; i++) { View v = tabsContainer.getChildAt(i); v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom()); TextView tab_title = (TextView) v.findViewById(R.id.mt_tab_title); if (tab_title != null) { tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); tab_title.setTextColor(tabTextColorUnselected); // 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_title.setAllCaps(true); } else { tab_title.setText(tab_title.getText().toString().toUpperCase(locale)); }// w w w. j a v a 2 s . co m } } } }
From source file:com.github.yggie.pulltorefresh.PullListFragment.java
/** * Applies the xml attributes sent through the Bundle object * * @param a The TypedArray object containing the xml attributes *//*from w w w . ja va2 s.c om*/ private void parseXmlAttributes(final TypedArray a) { if (a != null) { /** apply the background color */ final int backgroundColor = a.getColor(R.styleable.PullListFragment_list_backgroundColor, 0); if (backgroundColor != 0) { setListViewBackgroundColor(backgroundColor); } /** * Applies the padding, more specific padding has higher priority */ int paddingTop = listView.getPaddingTop(); int paddingBottom = listView.getPaddingBottom(); int paddingLeft = listView.getPaddingLeft(); int paddingRight = listView.getPaddingRight(); final int padding = a.getDimensionPixelSize(R.styleable.PullListFragment_list_padding, -1); if (padding != -1) { paddingTop = padding; paddingBottom = padding; paddingLeft = padding; paddingRight = padding; } paddingTop = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingTop, paddingTop); paddingBottom = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingBottom, paddingBottom); paddingLeft = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingLeft, paddingLeft); paddingRight = a.getDimensionPixelSize(R.styleable.PullListFragment_list_paddingRight, paddingRight); listView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); /** * apply pull modes */ final int topMode = a.getInt(R.styleable.PullListFragment_top_mode, MODE_PULL); if (topMode != MODE_PULL) { enableTopPull(false); } final int bottomMode = a.getInt(R.styleable.PullListFragment_bottom_mode, MODE_PULL); if (bottomMode != MODE_PULL) { enableBottomPull(false); } /** * apply custom pulled views */ final int topViewResId = a.getResourceId(R.styleable.PullListFragment_top_view, -1); if (topViewResId != -1) { setTopPulledView(topViewResId); } final int bottomViewResId = a.getResourceId(R.styleable.PullListFragment_bottom_view, -1); if (bottomViewResId != -1) { setBottomPulledView(bottomViewResId); } /** * apply custom text to default views */ if (topManager != null) { final String pullStartedText = a.getString(R.styleable.PullListFragment_top_pullStartedText); if (pullStartedText != null) { topManager.setPullStartedText(pullStartedText); } final String pullThresholdText = a.getString(R.styleable.PullListFragment_top_pullThresholdText); if (pullThresholdText != null) { topManager.setPullThresholdText(pullThresholdText); } final String refreshingText = a.getString(R.styleable.PullListFragment_top_refreshingText); if (refreshingText != null) { topManager.setRefreshingText(refreshingText); } final String refreshSuccessText = a.getString(R.styleable.PullListFragment_top_refreshSuccessText); if (refreshSuccessText != null) { topManager.setRefreshSuccessText(refreshSuccessText); } final String refreshFailedText = a.getString(R.styleable.PullListFragment_top_refreshFailedText); if (refreshFailedText != null) { topManager.setRefreshFailedText(refreshFailedText); } final int bgColor = a.getInt(R.styleable.PullListFragment_top_backgroundColor, -1); if (bgColor != -1) { topManager.setBackgroundColor(bgColor); } final int innerBgColor = a.getInt(R.styleable.PullListFragment_top_innerBackgroundColor, -1); if (innerBgColor != -1) { topManager.setInnerBackgroundColor(innerBgColor); } final int textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_top_textSize, (int) topManager.getTextSize()); topManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); final int textColor = a.getInt(R.styleable.PullListFragment_top_textColor, topManager.getTextColor()); topManager.setTextColor(textColor); } if (bottomManager != null) { final String pullStartedText = a.getString(R.styleable.PullListFragment_bottom_pullStartedText); if (pullStartedText != null) { bottomManager.setPullStartedText(pullStartedText); } final String pullThresholdText = a.getString(R.styleable.PullListFragment_bottom_pullThresholdText); if (pullThresholdText != null) { bottomManager.setPullThresholdText(pullThresholdText); } final String refreshingText = a.getString(R.styleable.PullListFragment_bottom_refreshingText); if (refreshingText != null) { bottomManager.setRefreshingText(refreshingText); } final String refreshSuccessText = a .getString(R.styleable.PullListFragment_bottom_refreshSuccessText); if (refreshSuccessText != null) { bottomManager.setRefreshSuccessText(refreshSuccessText); } final String refreshFailedText = a.getString(R.styleable.PullListFragment_bottom_refreshFailedText); if (refreshFailedText != null) { bottomManager.setRefreshFailedText(refreshFailedText); } final int bgColor = a.getInt(R.styleable.PullListFragment_bottom_backgroundColor, -1); if (bgColor != -1) { bottomManager.setBackgroundColor(bgColor); } final int innerBgColor = a.getInt(R.styleable.PullListFragment_bottom_innerBackgroundColor, -1); if (innerBgColor != -1) { bottomManager.setInnerBackgroundColor(innerBgColor); } final float textSize = a.getDimensionPixelSize(R.styleable.PullListFragment_bottom_textSize, (int) bottomManager.getTextSize()); bottomManager.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); final int textColor = a.getInt(R.styleable.PullListFragment_bottom_textSize, bottomManager.getTextColor()); bottomManager.setTextColor(textColor); } /** * Apply custom empty view configurations */ final int emptyViewId = a.getResourceId(R.styleable.PullListFragment_empty_view, -1); if (emptyViewId != -1) { setEmptyView(emptyViewId); } else { final String emptyText = a.getString(R.styleable.PullListFragment_empty_text); if (emptyText != null) { setEmptyText(emptyText); } } /** * Apply custom behaviour to scroller */ final int delay = a.getInt(R.styleable.PullListFragment_pull_delay, scroller.getOnRequestCompleteDelay()); scroller.setOnRequestCompleteDelay(delay); final float damping = a.getFloat(R.styleable.PullListFragment_pull_damping, scroller.getDamping()); scroller.setDamping(damping); final float easing = a.getFloat(R.styleable.PullListFragment_release_easing, scroller.getEasing()); scroller.setEasing(easing); a.recycle(); } }
From source file:gr.scify.newsum.ui.SearchViewActivity.java
private void initTopicSpinner() { // Get topics in category. Null accepts all user sources. Modify // according to user selection final String[] saTopicIDs = SearchTopicActivity.saTopicIDs; final String[] saTitles = SearchTopicActivity.saTopicTitles; final String[] saDates = SearchTopicActivity.saTopicDates; // TODO add TopicInfo for SearchResults as well and parse accordingly // final String[] saTopicIDs = extras.getStringArray("searchresults"); final TextView title = (TextView) findViewById(R.id.title); // Fill topic spinner ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, saTitles); final TextView tx = (TextView) findViewById(R.id.textView1); // tx.setMovementMethod(LinkMovementMethod.getInstance()); // final float minm = tx.getTextSize(); // final float maxm = (minm + 24); // create an invisible spinner just to control the summaries of the // category (i will use it later on Swipe) Spinner spinner = (Spinner) findViewById(R.id.spinner1); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);// w w w . ja va2 s .c o m // Scroll view init final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); // Add selection event spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Show waiting dialog showWaitingDialog(); // Changing summary loading = true; // Update visibility of rating bar final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar); rb.setRating(0.0f); rb.setVisibility(View.VISIBLE); final TextView rateLbl = (TextView) findViewById(R.id.rateLbl); rateLbl.setVisibility(View.VISIBLE); scroll.scrollTo(0, 0); // String[] saTopicIDs = sTopicIds.split(sSeparator); SharedPreferences settings = getSharedPreferences("urls", 0); // get user settings for sources String UserSources = settings.getString("UserLinks", "All"); String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources); if (Summary.length == 0) { // WORK. Updated: CHECK // Close waiting dialog closeWaitingDialog(); AlertDialog.Builder alert = new AlertDialog.Builder(SearchViewActivity.this); alert.setMessage(R.string.shouldReloadSummaries); alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); } }); alert.setCancelable(false); alert.show(); loading = false; return; } // track summary views per Search and topic title if (getAnalyticsPref()) { EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, "From Search", saTitles[arg2] + ": " + saDates[arg2], 0l); } // Generate summary text sText = ViewActivity.generateSummaryText(Summary, SearchViewActivity.this); pText = ViewActivity.generatesummarypost(Summary, SearchViewActivity.this); tx.setText(Html.fromHtml(sText)); tx.setMovementMethod(LinkMovementMethod.getInstance()); title.setText(saTitles[arg2] + ": " + saDates[arg2]); float defSize = tx.getTextSize(); SharedPreferences usersize = getSharedPreferences("textS", 0); float newSize = usersize.getFloat("size", defSize); tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize); // update the TopicActivity with viewed item TopicActivity.addVisitedTopicID(saTopicIDs[arg2]); // Close waiting dialog closeWaitingDialog(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); }