List of usage examples for android.widget TextView setTextSize
public void setTextSize(int unit, float size)
From source file:com.asksven.betterbatterystats.StatsActivity.java
@Override protected void onResume() { super.onResume(); Log.i(TAG, "OnResume called"); if (Analytics.getInstance(this).isEnabled()) { Tracking.startUsage(this); }//from ww w. j ava 2 s .c o m // if debug we check for updates try { PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); if (pinfo.packageName.endsWith("_xdaedition")) { UpdateManager.register(this); CrashManager.register(this); } } catch (Exception e) { Log.e(TAG, "An error occured registering update/crash manager: " + e.getMessage()); } // Analytics opt-in final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean wasPresentedOptOutAnalytics = prefs.getBoolean("analytics_opt_out_offered", false); if (!wasPresentedOptOutAnalytics) { Log.i(TAG, "Application was launched for the first time with analytics"); Snackbar.make(findViewById(android.R.id.content), R.string.message_first_start, Snackbar.LENGTH_LONG) .show(); Snackbar bar = Snackbar.make(findViewById(android.R.id.content), R.string.pref_app_analytics_summary, Snackbar.LENGTH_LONG).setAction(R.string.label_button_no, new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("analytics", false); editor.commit(); } }); bar.show(); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("analytics_opt_out_offered", true); editor.commit(); } Log.i(TAG, "OnResume called"); Log.i(TAG, "onResume references state: refFrom=" + m_refFromName + " refTo=" + m_refToName); // register the broadcast receiver IntentFilter intentFilter = new IntentFilter(ReferenceStore.REF_UPDATED); m_referenceSavedReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //extract our message from intent String refName = intent.getStringExtra(Reference.EXTRA_REF_NAME); //log our message value if (LogSettings.DEBUG) Log.i(TAG, "Received broadcast, reference was updated:" + refName); // reload the spinners to make sure all refs are in the right sequence when current gets refreshed // if (refName.equals(Reference.CURRENT_REF_FILENAME)) // { refreshSpinners(); // } } }; //registering our receiver this.registerReceiver(m_referenceSavedReceiver, intentFilter); // the service is always started as it handles the widget updates too SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); // show/hide spinners boolean showSpinners = sharedPrefs.getBoolean("show_from_to_ref", true); if (!showSpinners) { LinearLayout spinnerLayout = (LinearLayout) this.findViewById(R.id.LayoutSpinners); if (spinnerLayout != null) { spinnerLayout.setVisibility(View.GONE); } } if (!EventWatcherService.isServiceRunning(this)) { Intent i = new Intent(this, EventWatcherService.class); this.startService(i); } // make sure to create a valid "current" stat if none exists // or if prefs re set to auto refresh boolean bAutoRefresh = sharedPrefs.getBoolean("auto_refresh", true); if ((bAutoRefresh) || (!ReferenceStore.hasReferenceByName(Reference.CURRENT_REF_FILENAME, this))) { Intent serviceIntent = new Intent(this, WriteCurrentReferenceService.class); this.startService(serviceIntent); doRefresh(true); } else { refreshSpinners(); doRefresh(false); } // check if active monitoring is on: if yes make sure the alarm is scheduled if (sharedPrefs.getBoolean("active_mon_enabled", false)) { if (!StatsProvider.isActiveMonAlarmScheduled(this)) { StatsProvider.scheduleActiveMonAlarm(this); } } //Log.i(TAG, "OnResume end"); // we do some stuff here to handle settings about font size String fontSize = sharedPrefs.getString("medium_font_size", "16"); int mediumFontSize = Integer.parseInt(fontSize); //we need to change "since" fontsize TextView tvSince = (TextView) findViewById(R.id.TextViewSince); tvSince.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize); }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
private void updateWifiList(TableLayout table, LociWifiFingerprint wifi) { ArrayList<WifiViewListItem> items = new ArrayList<WifiViewListItem>(); HashMap<String, APInfoMapItem> apMap = wifi.getAps(); Set<String> keys = apMap.keySet(); Iterator<String> iter = keys.iterator(); while (iter.hasNext()) { String bssid = iter.next(); APInfoMapItem ap = apMap.get(bssid); items.add(new WifiViewListItem(bssid, ap.ssid, ap.rss, ap.count, ap.rssBuckets)); }// w w w. j av a 2 s. c o m Collections.sort(items); table.setColumnCollapsed(0, false); table.setColumnCollapsed(1, true); table.setColumnShrinkable(0, true); for (int i = 0; i < mAddedRows.size(); i++) { table.removeView(mAddedRows.get(i)); } mAddedRows.clear(); int totalCount = wifi.getScanCount(); for (WifiViewListItem item : items) { TableRow row = new TableRow(this); TextView ssidView = new TextView(this); ssidView.setText(item.ssid); //ssidView.setText("very very very veryvery very very very very very"); ssidView.setPadding(2, 2, 2, 2); ssidView.setTextColor(0xffffffff); TextView bssidView = new TextView(this); bssidView.setText(item.bssid); bssidView.setPadding(2, 2, 2, 2); bssidView.setTextColor(0xffffffff); TextView cntView = new TextView(this); cntView.setText("" + (item.count * 100) / totalCount); cntView.setPadding(2, 2, 2, 2); cntView.setGravity(Gravity.CENTER); cntView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); TextView rssView = new TextView(this); rssView.setText("" + item.rss); rssView.setPadding(2, 2, 6, 2); rssView.setGravity(Gravity.CENTER); rssView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); row.addView(ssidView, new TableRow.LayoutParams(0)); row.addView(bssidView, new TableRow.LayoutParams(1)); row.addView(cntView, new TableRow.LayoutParams(2)); row.addView(rssView, new TableRow.LayoutParams(3)); //Log.d(TAG, item.ssid); for (int i = 0; i < item.rssBuckets.length; i++) { TextView box = new TextView(this); box.setText(" "); box.setGravity(Gravity.RIGHT); box.setPadding(2, 2, 2, 2); box.setHeight(15); box.setGravity(Gravity.CENTER_VERTICAL); float colorVal = 256 * ((float) item.rssBuckets[i] / (float) wifi.getScanCount()); //Log.d(TAG, "colorVal=" + (int) colorVal + ", " + item.histogram[i]); int colorValInt = ((int) colorVal) - 1; if (colorValInt < 0) colorValInt = 0; box.setBackgroundColor(0xff000000 + colorValInt);//+ 0x000000ff * (item.histogram[i]/totScan)); box.setTextColor(0xffffffff); row.addView(box, new TableRow.LayoutParams(4 + i)); } row.setGravity(Gravity.CENTER); table.addView(row, new TableLayout.LayoutParams()); table.setColumnStretchable(3, true); mAddedRows.add(row); } }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
private Toast createToastShort(String text) { Toast toast = new Toast(this); TextView tv = new TextView(this); tv.setText(text);// w w w . j a v a 2s . c om tv.setTextColor(ContextCompat.getColor(this, R.color.colorAccent)); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, TOAST_TEXT_SIZE); // int pixel = (int)mWindowDensity * 56; int toastMargin = getResources().getDimensionPixelSize(R.dimen.toast_margin_top_bottom); tv.setPadding(0, toastMargin, 0, toastMargin); toast.setView(tv); toast.setGravity(mToastPosition, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); return toast; }
From source file:gr.scify.newsum.ui.ViewActivity.java
protected void updateTextSize() { final TextView tx = (TextView) findViewById(R.id.textView1); float defSize = tx.getTextSize(); SharedPreferences usersize = ViewActivity.this.getSharedPreferences("textS", 0); float newSize = usersize.getFloat("size", defSize); tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize); }
From source file:com.android.contacts.common.list.ViewPagerTabs.java
private void addTab(CharSequence tabTitle, final int position) { View tabView;/*from www. ja va 2 s . c o m*/ if (mTabIcons != null && position < mTabIcons.length) { View layout = LayoutInflater.from(getContext()).inflate(R.layout.unread_count_tab, null); View iconView = layout.findViewById(R.id.icon); iconView.setBackgroundResource(mTabIcons[position]); iconView.setContentDescription(tabTitle); TextView textView = (TextView) layout.findViewById(R.id.count); if (mUnreadCounts != null && mUnreadCounts[position] > 0) { textView.setText(Integer.toString(mUnreadCounts[position])); textView.setVisibility(View.VISIBLE); iconView.setContentDescription( getResources().getQuantityString(R.plurals.tab_title_with_unread_items, mUnreadCounts[position], tabTitle.toString(), mUnreadCounts[position])); } else { textView.setVisibility(View.INVISIBLE); iconView.setContentDescription(tabTitle); } tabView = layout; } else { final TextView textView = new TextView(getContext()); textView.setText(tabTitle); textView.setBackgroundResource(R.drawable.view_pager_tab_background); // Assign various text appearance related attributes to child views. if (mTextStyle > 0) { textView.setTypeface(textView.getTypeface(), mTextStyle); } if (mTextSize > 0) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } if (mTextColor != null) { textView.setTextColor(mTextColor); } textView.setAllCaps(mTextAllCaps); textView.setGravity(Gravity.CENTER); tabView = textView; } tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(getRtlPosition(position)); } }); tabView.setOnLongClickListener(new OnTabLongClickListener(position)); tabView.setPadding(mSidePadding, 0, mSidePadding, 0); mTabStrip.addView(tabView, position, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1)); // Default to the first child being selected if (position == 0) { mPrevSelected = 0; tabView.setSelected(true); } }
From source file:terse.a1.TerseActivity.java
private void postMortem(Throwable ex) { String explain = Static.describe(ex); TextView explainv = new TextView(this); explainv.setText(explain);/*from w ww . j a va 2 s .c o m*/ explainv.setBackgroundColor(Color.BLACK); explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); explainv.setTextColor(Color.RED); SetContentViewWithHomeButtonAndScroll(explainv); }
From source file:gr.scify.newsum.ui.ViewActivity.java
private void initZoomControls() { final TextView tx = (TextView) findViewById(R.id.textView1); final float minm = tx.getTextSize(); final float maxm = (minm + 24); // Add zoom controls ZoomControls zoom = (ZoomControls) findViewById(R.id.zoomControls1); zoom.setOnZoomInClickListener(new OnClickListener() { @Override/*from ww w .j av a 2s.c o m*/ public void onClick(View v) { if (tx.getTextSize() < maxm) { tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, tx.getTextSize() + 2); SharedPreferences textsize = getSharedPreferences("textS", 0); SharedPreferences.Editor editor = textsize.edit(); editor.putFloat("size", tx.getTextSize()); editor.commit(); } } }); zoom.setOnZoomOutClickListener(new OnClickListener() {// to the default // size @Override public void onClick(View v) { if (tx.getTextSize() > minm) tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, tx.getTextSize() - 2); SharedPreferences textsize = getSharedPreferences("textS", 0); SharedPreferences.Editor editor = textsize.edit(); editor.putFloat("size", tx.getTextSize()); editor.commit(); } }); }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) { statusView.setVisibility(View.GONE); viewfinderView.setVisibility(View.GONE); resultView.setVisibility(View.VISIBLE); ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view); if (barcode == null) { barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.qr_scan)); } else {/* w w w . ja v a2 s . c o m*/ barcodeImageView.setImageBitmap(barcode); } TextView formatTextView = (TextView) findViewById(R.id.format_text_view); formatTextView.setText(rawResult.getBarcodeFormat().toString()); TextView typeTextView = (TextView) findViewById(R.id.type_text_view); typeTextView.setText(resultHandler.getType().toString()); DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String formattedTime = formatter.format(new Date(rawResult.getTimestamp())); TextView timeTextView = (TextView) findViewById(R.id.time_text_view); timeTextView.setText(formattedTime); TextView metaTextView = (TextView) findViewById(R.id.meta_text_view); View metaTextViewLabel = findViewById(R.id.meta_text_view_label); metaTextView.setVisibility(View.GONE); metaTextViewLabel.setVisibility(View.GONE); Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata(); if (metadata != null) { StringBuilder metadataText = new StringBuilder(20); for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) { if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) { metadataText.append(entry.getValue()).append('\n'); } } if (metadataText.length() > 0) { metadataText.setLength(metadataText.length() - 1); metaTextView.setText(metadataText); metaTextView.setVisibility(View.VISIBLE); metaTextViewLabel.setVisibility(View.VISIBLE); } } TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view); CharSequence displayContents = resultHandler.getDisplayContents(); contentsTextView.setText(displayContents); // Crudely scale betweeen 22 and 32 -- bigger font for shorter text int scaledSize = Math.max(22, 32 - displayContents.length() / 4); contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize); TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view); supplementTextView.setText(""); supplementTextView.setOnClickListener(null); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) { SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView, resultHandler.getResult(), historyManager, this); } int buttonCount = resultHandler.getButtonCount(); ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view); buttonView.requestFocus(); for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) { TextView button = (TextView) buttonView.getChildAt(x); if (x < buttonCount) { button.setVisibility(View.VISIBLE); button.setText(resultHandler.getButtonText(x)); button.setOnClickListener(new ResultButtonListener(resultHandler, x)); } else { button.setVisibility(View.GONE); } } if (copyToClipboard && !resultHandler.areContentsSecure()) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (displayContents != null) { clipboard.setText(displayContents); } } }
From source file:ca.mimic.apphangar.Settings.java
protected void launchThanks(int which) { String thankYouMsg = getResources().getString(R.string.donate_thanks); if (which == THANK_YOU_PAYPAL) thankYouMsg += "\n\n" + getResources().getString(R.string.donate_thanks_paypal); AlertDialog alert = new AlertDialog.Builder(Settings.this).setTitle(R.string.donate_thanks_title) .setIcon(R.drawable.ic_logo).setMessage(thankYouMsg) .setPositiveButton(R.string.donate_thanks_continue, null).show(); TextView msgTxt = (TextView) alert.findViewById(android.R.id.message); msgTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); }