List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
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)}.// w ww .j a va 2 s. c o m */ 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:com.consumer.widget.SlidingTabLayoutSpend.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 ww w. j ava 2 s .c om*/ */ @SuppressLint("NewApi") protected TextView createDefaultTabView(Context context) { Resources res = context.getResources(); TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); //textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTextSize(TAB_VIEW_TEXT_SIZE_SP); //textView.setTypeface(Typeface.DEFAULT_BOLD); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); textView.setLayoutParams(param); // int unSelColorBg= R.color.TabPager; int unSelColorBg = R.color.White; textView.setTextColor(context.getResources().getColor(unSelColorBg)); 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); textView.setPadding(28, 15, 28, 15); return textView; }
From source file:com.earthsea.fish.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)}./*from w w w . j a v a 2 s .c o m*/ */ protected TextView createDefaultTabView(Context context) { // String activity = context.toString(); // // Log.v("tab_context",activity); // TextView textView = new TextView(context); // // if (activity.contains("SingleReport")) { // textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); // } // Instead of messing with layout params maybe we should crank up the padding when we know the // number of tab items will be low but we don't want them to be crammed into the view width 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)); /*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(40, padding, 40, padding); return textView; }
From source file:com.yooiistudios.newskit.ui.widget.viewpager.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)}.//from w w w . j a va2 s . c om */ protected TextView createDefaultTabView(Context context) { // ? 48dp TextView textView = new TextView(context); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, getResources().getDimensionPixelSize(R.dimen.news_select_sliding_tab_height))); textView.setGravity(Gravity.CENTER); 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); } // TextAppearance_Body2 -> sans-serif-medium, 14sp // ? ? ?? textView.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Body2); textView.setTextColor(getResources().getColor(R.color.news_select_disabled_text_color)); // black with opacity 54% if (Display.isTablet(getContext())) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.text_size_subhead_material)); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.text_size_body_2_material)); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); if (Display.isTablet(getContext())) { padding *= 1.5; } textView.setPadding(padding, 0, padding, 0); return textView; }
From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java
private void setupTextDisplay(final View header) { final TextView titleView = (TextView) header.findViewById(R.id.select_album_title); if (playlistName != null) { titleView.setText(playlistName); } else if (podcastName != null) { Collections.reverse(entries); titleView.setText(podcastName);/*from w w w. ja v a 2 s . c o m*/ titleView.setPadding(0, 6, 4, 8); } else if (name != null) { titleView.setText(name); if (artistInfo != null) { titleView.setPadding(0, 6, 4, 8); } } else if (share != null) { titleView.setVisibility(View.GONE); } int songCount = 0; Set<String> artists = new HashSet<String>(); Set<Integer> years = new HashSet<Integer>(); totalDuration = 0; for (Entry entry : entries) { if (!entry.isDirectory()) { songCount++; if (entry.getArtist() != null) { artists.add(entry.getArtist()); } if (entry.getYear() != null) { years.add(entry.getYear()); } Integer duration = entry.getDuration(); if (duration != null) { totalDuration += duration; } } } String artistName = ""; bookDescription = "Could not collect any info about the book at this time"; try { artistName = artists.iterator().next(); String endpoint = "getBookDirectory"; if (Util.isTagBrowsing(context)) { endpoint = "getBook"; } SharedPreferences prefs = Util.getPreferences(context); String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json"; Log.w("GetInfo", url); String artist, title; int year = 0; artist = title = ""; try { artist = artists.iterator().next(); } catch (Exception e) { Log.w("GetInfoArtist", e.toString()); } try { title = titleView.getText().toString(); } catch (Exception e) { Log.w("GetInfoTitle", e.toString()); } try { year = years.iterator().next(); } catch (Exception e) { Log.w("GetInfoYear", e.toString()); } BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year); bookInfo = new BookInfoAPI(context).execute(params).get(); bookDescription = bookInfo[0]; bookReader = bookInfo[1]; } catch (Exception e) { Log.w("GetInfoError", e.toString()); } if (bookDescription.equals("noInfo")) { bookDescription = "The server has no description for this book"; } final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); if (podcastDescription != null || artistInfo != null || bookDescription != null) { artistView.setVisibility(View.VISIBLE); String text = ""; if (bookDescription != null) { text = bookDescription; } if (podcastDescription != null) { text = podcastDescription; } if (artistInfo != null) { text = artistInfo.getBiography(); } Spanned spanned = null; if (text != null) { String newText = ""; try { if (!artistName.equals("")) { newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: " + artistName + "<br/>"; } } catch (Exception e) { } try { if (totalDuration > 0) { newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: " + bookReader + "<br/>"; } } catch (Exception e) { } try { if (totalDuration > 0) { newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: " + Util.formatDuration(totalDuration) + "<br/>"; } } catch (Exception e) { } try { newText += text + "<br/>"; } catch (Exception e) { } spanned = Html.fromHtml(newText); } artistView.setText(spanned); artistView.setSingleLine(false); final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength); artistView.setLines(minLines); artistView.setTextAppearance(context, android.R.style.TextAppearance_Small); final Spanned spannedText = spanned; artistView.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onClick(View v) { if (artistView.getMaxLines() == minLines) { // Use LeadingMarginSpan2 to try to make text flow around image Display display = context.getWindowManager().getDefaultDisplay(); ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art); coverArtView.measure(display.getWidth(), display.getHeight()); int height, width; ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView .getLayoutParams(); if (coverArtView.getDrawable() != null) { height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } else { height = coverArtView.getHeight(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } float textLineHeight = artistView.getPaint().getTextSize(); int lines = (int) Math.ceil(height / textLineHeight) + 1; SpannableString ss = new SpannableString(spannedText); ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); View linearLayout = header.findViewById(R.id.select_album_text_layout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout .getLayoutParams(); int[] rules = params.getRules(); rules[RelativeLayout.RIGHT_OF] = 0; params.leftMargin = vlp.rightMargin; artistView.setText(ss); artistView.setMaxLines(100); vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams(); vlp.leftMargin = width; } else { artistView.setMaxLines(minLines); } } }); artistView.setMovementMethod(LinkMovementMethod.getInstance()); } else if (topTracks) { artistView.setText(R.string.menu_top_tracks); artistView.setVisibility(View.VISIBLE); } else if (showAll) { artistView.setText(R.string.menu_show_all); artistView.setVisibility(View.VISIBLE); } else if (artists.size() == 1) { String artistText = artists.iterator().next(); if (years.size() == 1) { artistText += " - " + years.iterator().next(); } artistView.setText(artistText); artistView.setVisibility(View.VISIBLE); } else { artistView.setVisibility(View.GONE); } TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count); TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length); if (podcastDescription != null || artistInfo != null) { songCountView.setVisibility(View.GONE); songLengthView.setVisibility(View.GONE); } else { String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount, songCount); songCountView.setVisibility(View.GONE); songLengthView.setVisibility(View.GONE); } }
From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java
private void createTableLayoutPsnDtls() { if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) { mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check."); mFrameLayout.removeAllViews();/*from w w w . j av a 2 s. c o m*/ mFrameLayout.addView(mTextViewPNRSts); mStrPassengerDetails = null; return; } if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) { mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!"); mFrameLayout.removeAllViews(); mFrameLayout.addView(mTextViewPNRSts); mStrPassengerDetails = null; return; } List<List<String>> passengersList; if (mPassengerDetails == null || mPassengerDetails.getPNR() != mPNRNumber) { Elements elements = Jsoup.parse(mPageResult).select("table tr td:containsOwn(S. No.)"); Iterator iterator = null; try { iterator = elements.first().parent().parent().getElementsByTag("tr").iterator(); } catch (Exception e) { Log.i("PNRStat", mPageResult); return; } passengersList = new ArrayList<List<String>>(); List<String> list; Element tmp; while (iterator.hasNext()) { tmp = (Element) iterator.next(); if (tmp.toString().contains("Passenger")) { list = new ArrayList<String>(); list.add(tmp.select("td").get(0).text()); list.add(tmp.select("td").get(1).text()); list.add(tmp.select("td").get(2).text()); if (!tmp.select("td").get(2).text().toUpperCase().contains("CNF") && !tmp.select("td").get(2).text().toUpperCase().contains("CAN")) { isWaitingList = true; } passengersList.add(list); } } mPassengerDetails = new PassengerDetails(passengersList, mPNRNumber); } else { passengersList = mPassengerDetails.getPassengerList(); } mTableLayoutPsn = new TableLayout(mActivity); TableRow row; TextView tv1, tv2, tv3, tv4; mStrPassengerDetails = new ArrayList<String>(); int current; mTableLayoutPsn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); for (int i = 0; i < passengersList.size(); ++i) { current = i + 1; row = new TableRow(mActivity); row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tv1 = new TextView(mActivity); tv2 = new TextView(mActivity); tv3 = new TextView(mActivity); tv4 = new TextView(mActivity); tv1.setText("" + (i + 1) + "."); tv2.setText(" " + passengersList.get(i).get(0)); tv3.setText(" " + passengersList.get(i).get(1)); tv4.setText(" " + passengersList.get(i).get(2)); tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv4.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium); tv1.setPadding(10, 10, 10, 10); tv2.setPadding(10, 10, 10, 10); tv3.setPadding(10, 10, 10, 10); tv4.setPadding(10, 10, 10, 10); row.addView(tv1); row.addView(tv2); row.addView(tv3); row.addView(tv4); row.setBackgroundResource(R.drawable.card_background); row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); mTableLayoutPsn.addView(row); String strPsn = "" + current + ". " + passengersList.get(i).get(0) + " " + passengersList.get(i).get(1) + " " + passengersList.get(i).get(2); mStrPassengerDetails.add(strPsn); } }
From source file:com.axolotl.yanews.customize.SlidingTabLayout.java
/** * tabview. tab view//from w w w . jav a2 s. c o m * {@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.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showThemeDialog() { final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme()); Resources resources = getResources(); float density = ResourceUtils.obtainDensity(resources); ScrollView scrollView = new ScrollView(this); LinearLayout outer = new LinearLayout(this); outer.setOrientation(LinearLayout.VERTICAL); int outerPadding = (int) (16f * density); outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding); scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme) .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create(); View.OnClickListener listener = v -> { int index = (int) v.getTag(); if (index != checkedItem) { Preferences.setTheme(Preferences.VALUES_THEME[index]); recreate();// www . j a v a2 s.co m } dialog.dismiss(); }; int circleSize = (int) (56f * density); int itemPadding = (int) (12f * density); LinearLayout inner = null; for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) { if (i % 3 == 0) { inner = new LinearLayout(this); inner.setOrientation(LinearLayout.HORIZONTAL); outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER); layout.setBackgroundResource( ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0)); layout.setPadding(0, itemPadding, 0, itemPadding); layout.setOnClickListener(listener); layout.setTag(i); inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); View view = new View(this); int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0]; int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1]; int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2]; Resources.Theme theme = getResources().newTheme(); theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true); TypedArray typedArray = theme .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr }); view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0), typedArray.getColor(2, 0))); typedArray.recycle(); if (C.API_LOLLIPOP) { view.setElevation(6f * density); } layout.addView(view, circleSize, circleSize); TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setText(Preferences.ENTRIES_THEME[i]); if (C.API_LOLLIPOP) { textView.setAllCaps(true); textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); } textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(0, (int) (8f * density), 0, 0); layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) { if (Preferences.ENTRIES_THEME.length % 3 == 1) { inner.addView(new View(this), 0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } inner.addView(new View(this), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } } dialog.show(); }
From source file:com.github.irshulx.Components.InputExtensions.java
public void UpdateTextStyle(EditorTextStyle style, TextView editText) { /// String type = getControlType(getActiveView()); try {/*from ww w.java 2 s . c o m*/ if (editText == null) { editText = (EditText) editorCore.getActiveView(); } EditorControl tag = editorCore.getControlTag(editText); int pBottom = editText.getPaddingBottom(); int pRight = editText.getPaddingRight(); int pTop = editText.getPaddingTop(); if (isEditorTextStyleHeaders(style)) { updateTextStyle(editText, style); return; } if (isEditorTextStyleContentStyles(style)) { boolean containsHeadertextStyle = containsHeaderTextStyle(tag); if (style == EditorTextStyle.BOLD) { boldifyText(tag, editText, containsHeadertextStyle ? HEADING : CONTENT); } else if (style == EditorTextStyle.ITALIC) { italicizeText(tag, editText, containsHeadertextStyle ? HEADING : CONTENT); } return; } if (style == EditorTextStyle.INDENT) { if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.INDENT)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setTag(tag); } else { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Insert); editText.setPadding(30, pTop, pRight, pBottom); editText.setTag(tag); } } else if (style == EditorTextStyle.OUTDENT) { if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.INDENT)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.INDENT, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setTag(tag); } } else if (style == EditorTextStyle.BLOCKQUOTE) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) editText.getLayoutParams(); if (editorCore.containsStyle(tag.editorTextStyles, EditorTextStyle.BLOCKQUOTE)) { tag = editorCore.updateTagStyle(tag, EditorTextStyle.BLOCKQUOTE, Op.Delete); editText.setPadding(0, pTop, pRight, pBottom); editText.setBackgroundDrawable(ContextCompat.getDrawable(this.editorCore.getContext(), R.drawable.invisible_edit_text)); params.setMargins(0, 0, 0, (int) editorCore.getContext().getResources() .getDimension(R.dimen.edittext_margin_bottom)); } else { float marginExtra = editorCore.getContext().getResources() .getDimension(R.dimen.edittext_margin_bottom) * 1.5f; tag = editorCore.updateTagStyle(tag, EditorTextStyle.BLOCKQUOTE, Op.Insert); editText.setPadding(30, pTop, 30, pBottom); editText.setBackgroundDrawable( editText.getContext().getResources().getDrawable(R.drawable.block_quote_background)); params.setMargins(0, (int) marginExtra, 0, (int) marginExtra); } editText.setTag(tag); } } catch (Exception e) { } }
From source file:de.sourcestream.movieDB.MainActivity.java
/** * First configure the Universal Image Downloader, * then we set the main layout to be activity_main.xml * and we add the slide menu items./* ww w .j av a2 s. c o m*/ * * @param savedInstanceState If non-null, this activity is being re-constructed from a previous saved state as given here. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle(); // load slide menu items navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.list_slidermenu); ViewGroup header = (ViewGroup) getLayoutInflater().inflate(R.layout.drawer_header, null, false); ImageView drawerBackButton = (ImageView) header.findViewById(R.id.drawerBackButton); drawerBackButton.setOnClickListener(onDrawerBackButton); mDrawerList.addHeaderView(header); mDrawerList.setOnItemClickListener(new SlideMenuClickListener()); // setting the nav drawer list adapter mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, R.id.title, navMenuTitles)); toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar); toolbar.bringToFront(); } mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ toolbar, R.string.app_name, // nav drawer open - description for accessibility R.string.app_name // nav drawer close - description for accessibility ) { public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // calling onPrepareOptionsMenu() to show search view invalidateOptionsMenu(); syncState(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // calling onPrepareOptionsMenu() to hide search view invalidateOptionsMenu(); syncState(); } // updates the title, toolbar transparency and search view public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); if (slideOffset > .55 && !isDrawerOpen) { // opening drawer // mDrawerTitle is app title getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); isDrawerOpen = true; } else if (slideOffset < .45 && isDrawerOpen) { // closing drawer // mTitle is title of the current view, can be movies, tv shows or movie title getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); isDrawerOpen = false; } } }; mDrawerLayout.setDrawerListener(mDrawerToggle); // Get the action bar title to set padding TextView titleTextView = null; try { Field f = toolbar.getClass().getDeclaredField("mTitleTextView"); f.setAccessible(true); titleTextView = (TextView) f.get(toolbar); } catch (NoSuchFieldException e) { } catch (IllegalAccessException e) { } if (titleTextView != null) { float scale = getResources().getDisplayMetrics().density; titleTextView.setPadding((int) scale * 15, 0, 0, 0); } phone = getResources().getBoolean(R.bool.portrait_only); searchDB = new SearchDB(getApplicationContext()); if (savedInstanceState == null) { // Check orientation and lock to portrait if we are on phone if (phone) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } // on first time display view for first nav item displayView(1); // Use hockey module to check for updates checkForUpdates(); // Universal Loader options and configuration. DisplayImageOptions options = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_default) .showImageForEmptyUri(R.drawable.placeholder_default) .showImageOnFail(R.drawable.placeholder_default).cacheOnDisk(true).build(); Context context = this; File cacheDir = StorageUtils.getCacheDirectory(context); // Create global configuration and initialize ImageLoader with this config ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) .diskCache(new UnlimitedDiscCache(cacheDir)) // default .defaultDisplayImageOptions(options).build(); ImageLoader.getInstance().init(config); // Check cache size long size = 0; File[] filesCache = cacheDir.listFiles(); for (File file : filesCache) { size += file.length(); } if (cacheDir.getUsableSpace() < MinFreeSpace || size > CacheSize) { ImageLoader.getInstance().getDiskCache().clear(); searchDB.cleanSuggestionRecords(); } } else { oldPos = savedInstanceState.getInt("oldPos"); currentMovViewPagerPos = savedInstanceState.getInt("currentMovViewPagerPos"); currentTVViewPagerPos = savedInstanceState.getInt("currentTVViewPagerPos"); restoreMovieDetailsState = savedInstanceState.getBoolean("restoreMovieDetailsState"); restoreMovieDetailsAdapterState = savedInstanceState.getBoolean("restoreMovieDetailsAdapterState"); movieDetailsBundle = savedInstanceState.getParcelableArrayList("movieDetailsBundle"); castDetailsBundle = savedInstanceState.getParcelableArrayList("castDetailsBundle"); tvDetailsBundle = savedInstanceState.getParcelableArrayList("tvDetailsBundle"); currOrientation = savedInstanceState.getInt("currOrientation"); lastVisitedSimMovie = savedInstanceState.getInt("lastVisitedSimMovie"); lastVisitedSimTV = savedInstanceState.getInt("lastVisitedSimTV"); lastVisitedMovieInCredits = savedInstanceState.getInt("lastVisitedMovieInCredits"); saveInMovieDetailsSimFragment = savedInstanceState.getBoolean("saveInMovieDetailsSimFragment"); FragmentManager fm = getFragmentManager(); // prevent the following bug: go to gallery preview -> swap orientation -> // go to movies list -> swap orientation -> action bar bugged // so if we are not on gallery preview we show toolbar if (fm.getBackStackEntryCount() == 0 || !fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName().equals("galleryList")) { new Handler().post(new Runnable() { @Override public void run() { if (getSupportActionBar() != null && !getSupportActionBar().isShowing()) getSupportActionBar().show(); } }); } } // Get reference for the imageLoader imageLoader = ImageLoader.getInstance(); // Options used for the backdrop image in movie and tv details and gallery optionsWithFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500)) .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false).showImageOnLoading(R.color.black) .showImageForEmptyUri(R.color.black).showImageOnFail(R.color.black).cacheOnDisk(true).build(); optionsWithoutFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.color.black).showImageForEmptyUri(R.color.black) .showImageOnFail(R.color.black).cacheOnDisk(true).build(); // Options used for the backdrop image in movie and tv details and gallery backdropOptionsWithFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).displayer(new FadeInBitmapDisplayer(500)) .imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_backdrop) .showImageForEmptyUri(R.drawable.placeholder_backdrop) .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build(); backdropOptionsWithoutFade = new DisplayImageOptions.Builder() // Bitmaps in RGB_565 consume 2 times less memory than in ARGB_8888. .bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.EXACTLY).cacheInMemory(false) .showImageOnLoading(R.drawable.placeholder_backdrop) .showImageForEmptyUri(R.drawable.placeholder_backdrop) .showImageOnFail(R.drawable.placeholder_backdrop).cacheOnDisk(true).build(); trailerListView = new TrailerList(); galleryListView = new GalleryList(); if (currOrientation != getResources().getConfiguration().orientation) orientationChanged = true; currOrientation = getResources().getConfiguration().orientation; iconConstantSpecialCase = 0; if (phone) { iconMarginConstant = 0; iconMarginLandscape = 0; DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); int width = displayMetrics.widthPixels; int height = displayMetrics.heightPixels; if (width <= 480 && height <= 800) iconConstantSpecialCase = -70; // used in MovieDetails, CastDetails, TVDetails onMoreIconClick // to check whether the animation should be in up or down direction threeIcons = 128; threeIconsToolbar = 72; twoIcons = 183; twoIconsToolbar = 127; oneIcon = 238; oneIconToolbar = 182; } else { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { iconMarginConstant = 232; iconMarginLandscape = 300; threeIcons = 361; threeIconsToolbar = 295; twoIcons = 416; twoIconsToolbar = 351; oneIcon = 469; oneIconToolbar = 407; } else { iconMarginConstant = 82; iconMarginLandscape = 0; threeIcons = 209; threeIconsToolbar = 146; twoIcons = 264; twoIconsToolbar = 200; oneIcon = 319; oneIconToolbar = 256; } } dateFormat = android.text.format.DateFormat.getDateFormat(this); }