List of usage examples for android.widget TextView setMaxLines
@android.view.RemotableViewMethod public void setMaxLines(int maxLines)
From source file:net.maa123.tatuky.MainActivity.java
private void setupSearchView() { searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); // Setup content descriptions for the different elements in the search view. final View leftAction = searchView.findViewById(R.id.left_action); leftAction.setContentDescription(getString(R.string.action_open_drawer)); searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override// w w w .j ava 2s . c o m public void onFocus() { leftAction.setContentDescription(getString(R.string.action_close)); } @Override public void onFocusCleared() { leftAction.setContentDescription(getString(R.string.action_open_drawer)); } }); View clearButton = searchView.findViewById(R.id.clear_btn); clearButton.setContentDescription(getString(R.string.action_clear)); searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { searchView.clearSuggestions(); return; } if (newQuery.length() < 3) { return; } searchView.showProgress(); mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() { @Override public void onResponse(Call<List<Account>> call, Response<List<Account>> response) { if (response.isSuccessful()) { searchView.swapSuggestions(response.body()); searchView.hideProgress(); } else { searchView.hideProgress(); } } @Override public void onFailure(Call<List<Account>> call, Throwable t) { searchView.hideProgress(); } }); } }); searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(SearchSuggestion searchSuggestion) { Account accountSuggestion = (Account) searchSuggestion; Intent intent = new Intent(MainActivity.this, AccountActivity.class); intent.putExtra("id", accountSuggestion.id); startActivity(intent); } @Override public void onSearchAction(String currentQuery) { } }); searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { Account accountSuggestion = ((Account) item); Picasso.with(MainActivity.this).load(accountSuggestion.avatar) .placeholder(R.drawable.avatar_default).into(leftIcon); String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; final SpannableStringBuilder str = new SpannableStringBuilder(searchStr); str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(str); textView.setMaxLines(1); textView.setEllipsize(TextUtils.TruncateAt.END); } }); }
From source file:com.application.akscorp.yandextranslator2017.TranslateScreen.java
/** * This method use for notify user about error * * @param Message// w w w .j ava 2 s.c o m * @param ButtonText * @param action */ private void ShowErrorMessage(String Message, String ButtonText, final Runnable action) { ErrorSnackBar = Snackbar.make(getActivity().findViewById(R.id.activity_start_screen), Message, Snackbar.LENGTH_INDEFINITE); ErrorSnackBar.setAction(ButtonText, new View.OnClickListener() { @Override public void onClick(View v) { action.run(); ErrorSnackBar.dismiss(); } }); View snackbarView = ErrorSnackBar.getView(); snackbarView.setBackgroundColor(Color.WHITE); TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); textView.setMaxLines(4); ErrorSnackBar.show(); }
From source file:org.michaelbel.bottomsheet.BottomSheet.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (backgroundColor == 0) { backgroundColor = darkTheme ? 0xFF424242 : 0xFFFFFFFF; }//from www .j a v a2 s. co m if (titleTextColor == 0) { titleTextColor = darkTheme ? 0xB3FFFFFF : 0x8A000000; } if (itemTextColor == 0) { itemTextColor = darkTheme ? 0xFFFFFFFF : 0xDE000000; } if (iconColor == 0) { iconColor = darkTheme ? 0xFFFFFFFF : 0x8A000000; } if (itemSelector == 0) { itemSelector = darkTheme ? R.drawable.selectable_dark : R.drawable.selectable_light; } Window window = getWindow(); window.setWindowAnimations(R.style.DialogNoAnimation); setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (containerView == null) { containerView = new FrameLayout(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; if (Build.VERSION.SDK_INT >= 16) { containerView.setBackground(shadowDrawable); } else { containerView.setBackgroundDrawable(shadowDrawable); } containerView.setPadding(0, backgroundPaddingTop, 0, Utils.dp(getContext(), 8)); } if (Build.VERSION.SDK_INT >= 21) { containerView.setFitsSystemWindows(true); } containerView.setVisibility(View.INVISIBLE); containerView.setBackgroundColor(backgroundColor); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.BOTTOM; containerView.setLayoutParams(params); container.addView(containerView, 0); if (customView != null) { if (customView.getParent() != null) { ViewGroup viewGroup = (ViewGroup) customView.getParent(); viewGroup.removeView(customView); } FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) containerView.getLayoutParams(); params1.width = ViewGroup.LayoutParams.MATCH_PARENT; params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; params1.gravity = Gravity.START | Gravity.TOP; containerView.addView(customView, params1); } else { int topOffset = 0; if (titleText != null) { TextView titleTextView = new TextView(getContext()); titleTextView.setLines(1); titleTextView.setMaxLines(1); titleTextView.setSingleLine(true); titleTextView.setText(titleText); titleTextView.setTextColor(titleTextColor); titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); titleTextView.setGravity(Gravity.CENTER_VERTICAL); FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, Utils.dp(getContext(), 56)); params0.gravity = Gravity.START | Gravity.TOP; params0.leftMargin = Utils.dp(getContext(), 16); params0.rightMargin = Utils.dp(getContext(), 16); titleTextView.setLayoutParams(params0); containerView.addView(titleTextView); titleTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); topOffset += 56; } BottomSheetAdapter adapter = new BottomSheetAdapter(); if (mItems != null || mItemsRes != null) { if (contentType == LIST) { FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params2.topMargin = Utils.dp(getContext(), topOffset); ListView listView = new ListView(getContext()); listView.setSelector(itemSelector); listView.setDividerHeight(0); listView.setAdapter(adapter); listView.setDrawSelectorOnTop(true); listView.setVerticalScrollBarEnabled(false); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dismissWithButtonClick(i); } }); listView.setLayoutParams(params2); containerView.addView(listView); } else if (contentType == GRID) { FrameLayout.LayoutParams params3 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); GridView gridView = new GridView(getContext()); gridView.setSelector(itemSelector); gridView.setAdapter(adapter); gridView.setNumColumns(3); gridView.setVerticalScrollBarEnabled(false); gridView.setVerticalSpacing(Utils.dp(getContext(), 16)); gridView.setPadding(Utils.dp(getContext(), 0), Utils.dp(getContext(), topOffset + 8), Utils.dp(getContext(), 0), Utils.dp(getContext(), 16)); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dismissWithButtonClick(i); } }); gridView.setLayoutParams(params3); containerView.addView(gridView); } if (mItems != null) { for (int a = 0; a < mItems.length; a++) { items.add(new Item(mItems[a], mIcons != null ? mIcons[a] : 0)); } } else { for (int a = 0; a < mItemsRes.length; a++) { items.add(new Item(getContext().getText(mItemsRes[a]), mIcons != null ? mIcons[a] : 0)); } } adapter.notifyDataSetChanged(); } } WindowManager.LayoutParams params4 = window.getAttributes(); params4.width = ViewGroup.LayoutParams.MATCH_PARENT; params4.gravity = Gravity.TOP | Gravity.START; params4.dimAmount = 0; params4.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; if (!focusable) { params4.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } params4.height = ViewGroup.LayoutParams.MATCH_PARENT; window.setAttributes(params4); }
From source file:com.starshow.app.view.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); frgCount = adapter.getCount();// w ww . j a va2 s. co m for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextSize(tabTitleTextSize); tabTitleView.setMaxLines(1); tabView.setOnClickListener(new TabClickListener()); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } textViewList.add(tabTitleView); } textViewList.get(0).setTextColor(selectedTitleTextColor); // textViewList.get(0).setBackgroundColor(selectedTitleBgColor); for (int i = 1; i < frgCount; i++) { textViewList.get(i).setTextColor(unselectedTitleTextColor); // textViewList.get(i).setBackgroundColor(unselectedTitleBgColor); } }
From source file:com.fa.mastodon.activity.MainActivity.java
private void setupSearchView() { searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout()); // Setup content descriptions for the different elements in the search view. final View leftAction = searchView.findViewById(R.id.left_action); leftAction.setContentDescription(getString(R.string.action_open_drawer)); searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() { @Override/*from w w w . j av a 2 s . c o m*/ public void onFocus() { leftAction.setContentDescription(getString(R.string.action_close)); } @Override public void onFocusCleared() { leftAction.setContentDescription(getString(R.string.action_open_drawer)); } }); View clearButton = searchView.findViewById(R.id.clear_btn); clearButton.setContentDescription(getString(R.string.action_clear)); searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() { @Override public void onSearchTextChanged(String oldQuery, String newQuery) { if (!oldQuery.equals("") && newQuery.equals("")) { searchView.clearSuggestions(); return; } if (newQuery.length() < 3) { return; } searchView.showProgress(); mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() { @Override public void onResponse(Call<List<Account>> call, Response<List<Account>> response) { if (response.isSuccessful()) { searchView.swapSuggestions(response.body()); searchView.hideProgress(); } else { searchView.hideProgress(); } } @Override public void onFailure(Call<List<Account>> call, Throwable t) { searchView.hideProgress(); } }); } }); searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() { @Override public void onSuggestionClicked(SearchSuggestion searchSuggestion) { Account accountSuggestion = (Account) searchSuggestion; Intent intent = new Intent(MainActivity.this, AccountActivity.class); intent.putExtra("id", accountSuggestion.id); startActivity(intent); } @Override public void onSearchAction(String currentQuery) { } }); searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() { @Override public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) { Account accountSuggestion = ((Account) item); Picasso.with(MainActivity.this).load(accountSuggestion.avatar) .placeholder(R.drawable.avatar_default).into(leftIcon); String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username; final SpannableStringBuilder str = new SpannableStringBuilder(searchStr); str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(str); textView.setMaxLines(1); textView.setEllipsize(TextUtils.TruncateAt.END); } }); if (PreferenceManager.getDefaultSharedPreferences(this).getString("theme_selection", "light") .equals("black")) { searchView.setBackgroundColor(Color.parseColor("#444444")); } }
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }//from ww w .j a v a 2s. c o m builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); 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 boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:com.example.SmartBoard.DrawingView.java
public Bitmap textToBitmap(String text, int color, float posX, float posY, int size) { TextView textView = new TextView(getContext()); textView.setVisibility(View.VISIBLE); textView.setTextColor(color);//from w w w . j ava2 s . c o m textView.setMaxWidth(500); textView.setMaxHeight(500); textView.setMaxLines(4); textView.setX(posX); textView.setY(posY); textView.setText(text); textView.setTextSize(size); LinearLayout layout = new LinearLayout(getContext()); layout.addView(textView); layout.measure(500, 500); layout.layout(0, 0, 500, 500); textView.setDrawingCacheEnabled(true); textView.buildDrawingCache(); Bitmap bm = textView.getDrawingCache(); return bm; }
From source file:cm.aptoide.pt.ApkInfo.java
private void loadDescription() { Cursor c = getContentResolver().query(ExtrasContentProvider.CONTENT_URI, new String[] { ExtrasDbOpenHelper.COLUMN_COMMENTS_COMMENT }, ExtrasDbOpenHelper.COLUMN_COMMENTS_APKID + "=?", new String[] { viewApk.getApkid() }, null); description_text = ""; if (c.moveToFirst()) { description_text = c.getString(0); } else {//from w w w . j av a 2 s. c om description_text = getString(R.string.no_descript); } c.close(); runOnUiThread(new Runnable() { @Override public void run() { final TextView description = (TextView) findViewById(R.id.descript); description.setText(description_text); if (description.getLineCount() > 10) { description.setMaxLines(10); findViewById(R.id.show_all_description).setVisibility(View.VISIBLE); findViewById(R.id.show_all_description).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (collapsed) { collapsed = false; scrollPosition = findViewById(R.id.app_info_scroller).getScrollY(); description.setMaxLines(Integer.MAX_VALUE); ((TextView) findViewById(R.id.show_all_description)) .setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_more_arrow_up, 0); ((TextView) findViewById(R.id.show_all_description)) .setText(getString(R.string.show_less)); } else { collapsed = true; ((TextView) findViewById(R.id.show_all_description)) .setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_more_arrow_down, 0); description.setMaxLines(10); findViewById(R.id.app_info_scroller).scrollTo(0, scrollPosition); ((TextView) findViewById(R.id.show_all_description)) .setText(getString(R.string.show_more)); } } }); findViewById(R.id.description_container).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (collapsed) { collapsed = false; scrollPosition = findViewById(R.id.app_info_scroller).getScrollY(); description.setMaxLines(Integer.MAX_VALUE); ((TextView) findViewById(R.id.show_all_description)) .setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_more_arrow_up, 0); ((TextView) findViewById(R.id.show_all_description)) .setText(getString(R.string.show_less)); } else { collapsed = true; ((TextView) findViewById(R.id.show_all_description)) .setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_more_arrow_down, 0); description.setMaxLines(10); findViewById(R.id.app_info_scroller).scrollTo(0, scrollPosition); ((TextView) findViewById(R.id.show_all_description)) .setText(getString(R.string.show_more)); } } }); } } }); }
From source file:github.daneren2005.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) { titleView.setText(podcastName);/* ww w .j a v a 2 s . co 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>(); 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; } } } final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); if (podcastDescription != null || artistInfo != null) { artistView.setVisibility(View.VISIBLE); String text = podcastDescription != null ? podcastDescription : artistInfo.getBiography(); Spanned spanned = null; if (text != null) { spanned = Html.fromHtml(text); } 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); 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.setText(s.toUpperCase()); songLengthView.setText(Util.formatDuration(totalDuration)); } }
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);/* www. j a v a2 s .c om*/ 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); } }