List of usage examples for android.widget TextView getTextSize
@ViewDebug.ExportedProperty(category = "text") public float getTextSize()
From source file:com.inmobi.ultrapush.AnalyzeActivity.java
@SuppressWarnings("deprecation") private void setTextViewFontSize() { TextView tv = (TextView) findViewById(R.id.textview_cur); // At this point tv.getWidth(), tv.getLineCount() will return 0 Paint mTestPaint = new Paint(); mTestPaint.setTextSize(tv.getTextSize()); mTestPaint.setTypeface(Typeface.MONOSPACE); final String text = getString(R.string.textview_peak_text); Display display = getWindowManager().getDefaultDisplay(); // pixels left float px = display.getWidth() - getResources().getDimension(R.dimen.textview_RMS_layout_width) - 5; float fs = tv.getTextSize(); // size in pixel while (mTestPaint.measureText(text) > px && fs > 5) { fs -= 0.5;// w ww. j ava2 s . c om mTestPaint.setTextSize(fs); } ((TextView) findViewById(R.id.textview_cur)).setTextSize(fs / DPRatio); ((TextView) findViewById(R.id.textview_peak)).setTextSize(fs / DPRatio); }
From source file:com.hctrom.romcontrol.licenseadapter.LicenseDialogoAlerta.java
public void applyBlurMaskFilter(TextView tv, BlurMaskFilter.Blur style) { /*//from www.j a v a 2 s . com MaskFilter Known Direct Subclasses BlurMaskFilter, EmbossMaskFilter MaskFilter is the base class for object that perform transformations on an alpha-channel mask before drawing it. A subclass of MaskFilter may be installed into a Paint. Blur and emboss are implemented as subclasses of MaskFilter. */ /* BlurMaskFilter This takes a mask, and blurs its edge by the specified radius. Whether or or not to include the original mask, and whether the blur goes outside, inside, or straddles, the original mask's border, is controlled by the Blur enum. */ /* public BlurMaskFilter (float radius, BlurMaskFilter.Blur style) Create a blur maskfilter. Parameters radius : The radius to extend the blur from the original mask. Must be > 0. style : The Blur to use Returns The new blur maskfilter */ /* BlurMaskFilter.Blur INNER : Blur inside the border, draw nothing outside. NORMAL : Blur inside and outside the original border. OUTER : Draw nothing inside the border, blur outside. SOLID : Draw solid inside the border, blur outside. */ /* public float getTextSize () Returns the size (in pixels) of the default text size in this TextView. */ // Define the blur effect radius float radius = tv.getTextSize() / 10; // Initialize a new BlurMaskFilter instance BlurMaskFilter filter = new BlurMaskFilter(radius, style); /* public void setLayerType (int layerType, Paint paint) Specifies the type of layer backing this view. The layer can be LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE. A layer is associated with an optional Paint instance that controls how the layer is composed on screen. Parameters layerType : The type of layer to use with this view, must be one of LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE paint : The paint used to compose the layer. This argument is optional and can be null. It is ignored when the layer type is LAYER_TYPE_NONE */ /* public static final int LAYER_TYPE_SOFTWARE Indicates that the view has a software layer. A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled. */ // Set the TextView layer type tv.setLayerType(View.LAYER_TYPE_SOFTWARE, null); /* public MaskFilter setMaskFilter (MaskFilter maskfilter) Set or clear the maskfilter object. Pass null to clear any previous maskfilter. As a convenience, the parameter passed is also returned. Parameters maskfilter : May be null. The maskfilter to be installed in the paint Returns maskfilter */ // Finally, apply the blur effect on TextView text tv.getPaint().setMaskFilter(filter); }
From source file:plugin.google.maps.GoogleMaps.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override//w w w . jav a 2 s. co m public View getInfoContents(Marker marker) { String title = marker.getTitle(); String snippet = marker.getSnippet(); if ((title == null) && (snippet == null)) { return null; } JSONObject properties = null; JSONObject styles = null; String propertyId = "marker_property_" + marker.getId(); PluginEntry pluginEntry = this.plugins.get("Marker"); PluginMarker pluginMarker = (PluginMarker) pluginEntry.plugin; if (pluginMarker.objects.containsKey(propertyId)) { properties = (JSONObject) pluginMarker.objects.get(propertyId); if (properties.has("styles")) { try { styles = (JSONObject) properties.getJSONObject("styles"); } catch (JSONException e) { } } } // Linear layout LinearLayout windowLayer = new LinearLayout(activity); windowLayer.setPadding(3, 3, 3, 3); windowLayer.setOrientation(LinearLayout.VERTICAL); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER; windowLayer.setLayoutParams(layoutParams); //---------------------------------------- // text-align = left | center | right //---------------------------------------- int gravity = Gravity.LEFT; int textAlignment = View.TEXT_ALIGNMENT_GRAVITY; if (styles != null) { try { String textAlignValue = styles.getString("text-align"); switch (TEXT_STYLE_ALIGNMENTS.valueOf(textAlignValue)) { case left: gravity = Gravity.LEFT; textAlignment = View.TEXT_ALIGNMENT_GRAVITY; break; case center: gravity = Gravity.CENTER; textAlignment = View.TEXT_ALIGNMENT_CENTER; break; case right: gravity = Gravity.RIGHT; textAlignment = View.TEXT_ALIGNMENT_VIEW_END; break; } } catch (Exception e) { } } if (title != null) { if (title.indexOf("data:image/") > -1 && title.indexOf(";base64,") > -1) { String[] tmp = title.split(","); Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]); image = PluginUtil.scaleBitmapForDevice(image); ImageView imageView = new ImageView(this.cordova.getActivity()); imageView.setImageBitmap(image); windowLayer.addView(imageView); } else { TextView textView = new TextView(this.cordova.getActivity()); textView.setText(title); textView.setSingleLine(false); int titleColor = Color.BLACK; if (styles != null && styles.has("color")) { try { titleColor = PluginUtil.parsePluginColor(styles.getJSONArray("color")); } catch (JSONException e) { } } textView.setTextColor(titleColor); textView.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setTextAlignment(textAlignment); } //---------------------------------------- // font-style = normal | italic // font-weight = normal | bold //---------------------------------------- int fontStyle = Typeface.NORMAL; if (styles != null) { try { if ("italic".equals(styles.getString("font-style"))) { fontStyle = Typeface.ITALIC; } } catch (JSONException e) { } try { if ("bold".equals(styles.getString("font-weight"))) { fontStyle = fontStyle | Typeface.BOLD; } } catch (JSONException e) { } } textView.setTypeface(Typeface.DEFAULT, fontStyle); windowLayer.addView(textView); } } if (snippet != null) { //snippet = snippet.replaceAll("\n", ""); TextView textView2 = new TextView(this.cordova.getActivity()); textView2.setText(snippet); textView2.setTextColor(Color.GRAY); textView2.setTextSize((textView2.getTextSize() / 6 * 5) / density); textView2.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView2.setTextAlignment(textAlignment); } windowLayer.addView(textView2); } return windowLayer; }
From source file:org.de.jmg.learn._MainActivity.java
void SetTxtStatusSize(int width) { if (width == 0) width = mainView.getWidth();/*ww w. ja v a2s . c om*/ if (width == 0 && _OriginalWidth == 0) return; if (width == 0) width = _OriginalWidth; _OriginalWidth = width; TextView t = _txtStatus; Paint p = new Paint(); if (t.getText() instanceof SpannedString) { p.setTextSize(t.getTextSize()); SpannedString s = (SpannedString) t.getText(); width = width - width / (_isSmallDevice ? 4 : 5); float measuredWidth = p.measureText(s.toString()); if (measuredWidth != width) { float scaleA = (float) width / measuredWidth; if (libString.IsNullOrEmpty(_vok.getFileName())) scaleA *= .75f; if (scaleA < .5f) scaleA = .5f; if (scaleA > 2.0f) scaleA = 2.0f; float size = t.getTextSize(); t.setTextSize(TypedValue.COMPLEX_UNIT_PX, size * scaleA); } } }
From source file:org.de.jmg.learn._MainActivity.java
public void resizeActionbar(final int width) { /*/*w w w. java2s . co m*/ View tb = this.findViewById(R.id.action_bar); Paint p = new Paint(); int SizeOther = 0; if (tb != null) { if (width == 0) width = tb.getWidth(); if (width > 0) { ViewGroup g = (ViewGroup) tb; for (int i = 0; i < g.getChildCount(); i++) { View v = g.getChildAt(i); if (!(v instanceof TextView)) { SizeOther += v.getWidth(); } } if (SizeOther == 0) SizeOther=lib.dpToPx(50); for (int i = 0; i < g.getChildCount(); i++) { View v = g.getChildAt(i); if (v instanceof TextView) { TextView t = (TextView) v; if (_main.ActionBarOriginalTextSize[i] == 0 ) { _main.ActionBarOriginalTextSize[i] = t.getTextSize(); } else { t.setTextSize(TypedValue.COMPLEX_UNIT_PX,_main.ActionBarOriginalTextSize[i]); } if (t.getText() instanceof SpannedString) { p.setTextSize(t.getTextSize()); SpannedString s = (SpannedString) t.getText(); width = width - SizeOther - lib.dpToPx(50); float measuredWidth = p.measureText(s.toString()); if (measuredWidth > width) { float scaleA = (float)width / (float)measuredWidth; if (scaleA < .5f) scaleA = .5f; t.setTextSize( TypedValue.COMPLEX_UNIT_PX, (float) (t.getTextSize() * (scaleA))); } } } } } } */ if (mainView == null) return; TextView t = _txtStatus; if (_main.ActionBarOriginalTextSize == 0) { _main.ActionBarOriginalTextSize = t.getTextSize(); SetTxtStatusSize(width); } else if (t.getTextSize() != _main.ActionBarOriginalTextSize) { t.setTextSize(TypedValue.COMPLEX_UNIT_PX, _main.ActionBarOriginalTextSize); SetTxtStatusSize(width); } else { SetTxtStatusSize(width); } }
From source file:com.juick.android.MainActivity.java
public void updateNavigation() { navigationItems = new ArrayList<NavigationItem>(); List<MicroBlog> blogs = new ArrayList<MicroBlog>(microBlogs.values()); Collections.<MicroBlog>sort(blogs, new Comparator<MicroBlog>() { @Override// ww w.jav a 2 s . c o m public int compare(MicroBlog microBlog, MicroBlog microBlog2) { return microBlog.getPiority() - microBlog2.getPiority(); } }); for (MicroBlog blog : blogs) { blog.addNavigationSources(navigationItems, this); } navigationItems.add(new NavigationItem(NAVITEM_UNREAD, R.string.navigationUnread, R.drawable.navicon_juickadvanced, "msrcUnread") { @Override public void action() { final NavigationItem thisNi = this; final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true); pd.setTitle(R.string.navigationUnread); pd.setCancelable(true); pd.show(); UnreadSegmentsView.loadPeriods(MainActivity.this, new Utils.Function<Void, ArrayList<DatabaseService.Period>>() { @Override public Void apply(ArrayList<DatabaseService.Period> periods) { if (pd.isShowing()) { pd.cancel(); AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog alerDialog; if (periods.size() == 0) { alerDialog = builder.setTitle(getString(R.string.UnreadSegments)) .setMessage(getString(R.string.YouHaveNotEnabledForUnreadSegments)) .setCancelable(true) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }).create(); } else { UnreadSegmentsView unreadSegmentsView = new UnreadSegmentsView( MainActivity.this, periods); final int myIndex = navigationItems.indexOf(thisNi); alerDialog = builder.setTitle(getString(R.string.ChooseUnreadSegment)) .setView(unreadSegmentsView).setCancelable(true) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); restoreLastNavigationPosition(); } }) .create(); unreadSegmentsView.setListener(new UnreadSegmentsView.PeriodListener() { @Override public void onPeriodClicked(DatabaseService.Period period) { alerDialog.dismiss(); int beforeMid = period.beforeMid; Bundle args = new Bundle(); args.putSerializable("messagesSource", new UnreadSegmentMessagesSource( getString(R.string.navigationUnread), MainActivity.this, period)); if (getSelectedNavigationIndex() != myIndex) { setSelectedNavigationItem(myIndex); } runDefaultFragmentWithBundle(args, thisNi); } }); } alerDialog.show(); restyleChildrenOrWidget(alerDialog.getWindow().getDecorView()); } return null; } }); return; } }); navigationItems.add(new NavigationItem(NAVITEM_SAVED, R.string.navigationSaved, R.drawable.navicon_juickadvanced, "msrcSaved") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new SavedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_READ, R.string.navigationRecentlyOpened, R.drawable.navicon_juickadvanced, "msrcRecentOpen") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyOpenedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_RECENT_WRITE, R.string.navigationRecentlyCommented, R.drawable.navicon_juickadvanced, "msrcRecentComment") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new RecentlyCommentedMessagesSource(MainActivity.this)); runDefaultFragmentWithBundle(args, this); } }); navigationItems.add(new NavigationItem(NAVITEM_ALL_COMBINED, R.string.navigationAllCombined, R.drawable.navicon_juickadvanced, "msrcAllCombined") { @Override public void action() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedAllMessagesSource(MainActivity.this, "combined_all")); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllCombined(); break; } } }); navigationItems.add(new NavigationItem(NAVITEM_SUBS_COMBINED, R.string.navigationSubsCombined, R.drawable.navicon_juickadvanced, "msrcSubsCombined") { @Override public void action() { final NavigationItem thiz = this; new Thread("MessageSource Initializer") { @Override public void run() { final Bundle args = new Bundle(); args.putSerializable("messagesSource", new CombinedSubscriptionMessagesSource(MainActivity.this)); runOnUiThread(new Runnable() { @Override public void run() { runDefaultFragmentWithBundle(args, thiz); } }); } }.start(); final Bundle args = new Bundle(); runDefaultFragmentWithBundle(args, this); } @Override public ArrayList<String> getMenuItems() { String s = getString(R.string.SelectSources); ArrayList<String> strings = new ArrayList<String>(); strings.add(s); return strings; } @Override public void handleMenuAction(int which, String value) { switch (which) { case 0: selectSourcesForAllSubs(); break; } } }); int index = 10000; final SharedPreferences sp_order = getSharedPreferences("messages_source_ordering", MODE_PRIVATE); for (NavigationItem navigationItem : navigationItems) { navigationItem.itemOrder = sp_order.getInt("order_" + navigationItem.id, -1); if (navigationItem.itemOrder == -1) { navigationItem.itemOrder = index; sp_order.edit().putInt("order_" + navigationItem.id, navigationItem.itemOrder).commit(); } index++; } Collections.sort(navigationItems, new Comparator<NavigationItem>() { @Override public int compare(NavigationItem lhs, NavigationItem rhs) { return lhs.itemOrder - rhs.itemOrder; // increasing } }); allNavigationItems = new ArrayList<NavigationItem>(navigationItems); final Iterator<NavigationItem> iterator = navigationItems.iterator(); while (iterator.hasNext()) { NavigationItem next = iterator.next(); if (next.sharedPrefsKey != null) { if (!sp.getBoolean(next.sharedPrefsKey, defaultValues(next.sharedPrefsKey))) { iterator.remove(); } } } sp_order.edit().commit(); // save final boolean compressedMenu = sp.getBoolean("compressedMenu", false); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final float finalMenuFontScale = menuFontScale; navigationList = (DragSortListView) findViewById(R.id.navigation_list); // adapter for old-style navigation final BaseAdapter navigationAdapter = new BaseAdapter() { @Override public int getCount() { return navigationItems.size(); } @Override public Object getItem(int position) { return navigationItems.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } final int screenHeight = getWindow().getWindowManager().getDefaultDisplay().getHeight(); final int layoutId = R.layout.simple_list_item_1_mine; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); if (parent instanceof Spinner) { tv.setTextSize(18 * finalMenuFontScale); tv.setEllipsize(TextUtils.TruncateAt.MARQUEE); } else { tv.setTextSize(22 * finalMenuFontScale); } tv.setText(getString(navigationItems.get(position).labelId)); if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } retval.setPressedListener(new PressableLinearLayout.PressedListener() { @Override public void onPressStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } @Override public void onSelectStateChanged(boolean selected) { MainActivity.restyleChildrenOrWidget(retval, false); } }); MainActivity.restyleChildrenOrWidget(retval, false); return retval; } }; // adapter for new-style navigation final BaseAdapter navigationListAdapter = new BaseAdapter() { @Override public int getCount() { return getItems().size(); } private ArrayList<NavigationItem> getItems() { if (navigationList.isDragEnabled()) { return allNavigationItems; } else { return navigationItems; } } @Override public Object getItem(int position) { return getItems().get(position); } @Override public long getItemId(int position) { return position; } float textSize = -1; @Override public View getView(int position, View convertView, ViewGroup parent) { if (position == -1) { // NOOK is funny return convertView; } if (textSize < 0) { View inflate = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView text = (TextView) inflate.findViewById(android.R.id.text1); textSize = text.getTextSize(); } final int layoutId = R.layout.navigation_list_item; final PressableLinearLayout retval = convertView != null ? (PressableLinearLayout) convertView : (PressableLinearLayout) getLayoutInflater().inflate(layoutId, null); TextView tv = (TextView) retval.findViewById(android.R.id.text1); final ArrayList<NavigationItem> items = getItems(); final NavigationItem theItem = items.get(position); tv.setText(getString(theItem.labelId)); ImageButton menuButton = (ImageButton) retval.findViewById(R.id.menu_button); menuButton.setFocusable(false); ArrayList<String> menuItems = theItem.getMenuItems(); menuButton.setVisibility(menuItems != null && menuItems.size() > 0 ? View.VISIBLE : View.GONE); menuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { doNavigationItemMenu(theItem); } }); ImageView iv = (ImageView) retval.findViewById(android.R.id.icon); iv.setImageResource(theItem.imageId); retval.findViewById(R.id.draggable) .setVisibility(items != allNavigationItems ? View.GONE : View.VISIBLE); retval.findViewById(R.id.checkbox).setVisibility( items != allNavigationItems || theItem.sharedPrefsKey == null ? View.GONE : View.VISIBLE); CheckBox cb = (CheckBox) retval.findViewById(R.id.checkbox); cb.setOnCheckedChangeListener(null); if (theItem.sharedPrefsKey != null) { cb.setChecked(sp.getBoolean(theItem.sharedPrefsKey, defaultValues(theItem.sharedPrefsKey))); } cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sp.edit().putBoolean(theItem.sharedPrefsKey, isChecked).commit(); } }); int spacing = sp.getInt("navigation_spacing", 0); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize + spacing); retval.setPadding(0, spacing, 0, spacing); return retval; } }; ActionBar bar = getSupportActionBar(); updateActionBarMode(); navigationList.setDragEnabled(false); ((DragSortController) navigationList.getFloatViewManager()).setDragHandleId(R.id.draggable); navigationList.setAdapter(navigationListAdapter); navigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { setSelectedNavigationItem(position); closeNavigationMenu(true, false); } }); navigationList.setDropListener(new DragSortListView.DropListener() { @Override public void drop(int from, int to) { final NavigationItem item = allNavigationItems.remove(from); allNavigationItems.add(to, item); int index = 0; for (NavigationItem allNavigationItem : allNavigationItems) { if (allNavigationItem.itemOrder != index) { allNavigationItem.itemOrder = index; sp_order.edit().putInt("order_" + allNavigationItem.id, allNavigationItem.itemOrder) .commit(); } index++; } sp_order.edit().commit(); // save navigationListAdapter.notifyDataSetChanged(); //To change body of implemented methods use File | Settings | File Templates. } }); bar.setListNavigationCallbacks(navigationAdapter, this); final View navigationMenuButton = (View) findViewById(R.id.navigation_menu_button); navigationMenuButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this) .setItems(navigationList.isDragEnabled() ? R.array.navigation_menu_end : R.array.navigation_menu_start, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int spacing = sp.getInt("navigation_spacing", 0); switch (which) { case 0: if (navigationList.isDragEnabled()) { navigationList.setDragEnabled(false); updateNavigation(); } else { navigationList.setDragEnabled(true); } break; case 1: final Map<String, ?> all = sp_order.getAll(); for (String s : all.keySet()) { sp_order.edit().remove(s).commit(); } sp_order.edit().commit(); updateNavigation(); break; case 2: // wider sp.edit().putInt("navigation_spacing", spacing + 1).commit(); ((BaseAdapter) navigationList.getAdapter()).notifyDataSetInvalidated(); break; case 3: // narrower if (spacing > 0) { sp.edit().putInt("navigation_spacing", spacing - 1).commit(); ((BaseAdapter) navigationList.getAdapter()) .notifyDataSetInvalidated(); } break; case 4: // logout from.. logoutFromSomeServices(); break; } navigationListAdapter.notifyDataSetChanged(); } }) .setCancelable(true).create().show(); } }); final SharedPreferences spn = getSharedPreferences("saved_last_navigation_type", MODE_PRIVATE); int restoredLastNavItem = spn.getInt("last_navigation", 0); if (restoredLastNavItem != 0) { NavigationItem allSources = null; for (int i = 0; i < navigationItems.size(); i++) { NavigationItem navigationItem = navigationItems.get(i); if (navigationItem.labelId == restoredLastNavItem) { lastNavigationItem = navigationItem; } if (navigationItem.labelId == R.string.navigationAll) { allSources = navigationItem; } } if (lastNavigationItem == null) { lastNavigationItem = allSources; // could be null if not configured } if (lastNavigationItem == null && navigationItems.size() > 0) { lastNavigationItem = navigationItems.get(0); // last default } if (lastNavigationItem != null) { restoreLastNavigationPosition(); lastNavigationItem.action(); } } }
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);/*www . j av a2 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) { } }); }