List of usage examples for android.widget TextView requestLayout
@CallSuper public void requestLayout()
From source file:Main.java
/** * Sets the text for a {@link TextView}. * * @param textview text view instance/*from w ww. j a v a2s. com*/ * @param text new text to be shown */ public static void setText(TextView textview, String text) { textview.setText(text); textview.requestLayout(); }
From source file:Main.java
/** * Sets the font size for a {@link TextView}. * * @param textview text view instance// w w w . j a v a 2 s .c o m * @param size font size in pixel */ public static void setFontSize(TextView textview, float size) { textview.setTextSize(size); textview.requestLayout(); }
From source file:com.jefftharris.passwdsafe.StorageFileListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); itsFilesAdapter = new SimpleCursorAdapter( getActivity(), R.layout.file_list_item, null, new String[] { RecentFilesDb.DB_COL_FILES_TITLE, RecentFilesDb.DB_COL_FILES_ID, RecentFilesDb.DB_COL_FILES_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date }, 0); itsFilesAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override//from w w w . j a v a2 s .co m public boolean setViewValue(View view, Cursor cursor, int columnIdx) { switch (view.getId()) { case R.id.text: { TextView tv = (TextView) view; String title = cursor.getString(columnIdx); tv.setText(title); tv.requestLayout(); return false; } case R.id.icon: { ImageView iv = (ImageView) view; iv.setImageResource(itsFileIcon); return true; } case R.id.mod_date: { TextView tv = (TextView) view; long date = cursor.getLong(RecentFilesDb.QUERY_COL_DATE); tv.setText(Utils.formatDate(date, getActivity())); return true; } } return false; } }); setListAdapter(itsFilesAdapter); LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_FILES, null, this); }
From source file:net.tjado.passwdsafe.StorageFileListFragment.java
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); itsFilesAdapter = new SimpleCursorAdapter( getActivity(), R.layout.file_list_item, null, new String[] { RecentFilesDb.DB_COL_FILES_TITLE, RecentFilesDb.DB_COL_FILES_ID, RecentFilesDb.DB_COL_FILES_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date }, 0); itsFilesAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override// w w w .j ava 2 s. co m public boolean setViewValue(View view, Cursor cursor, int columnIdx) { switch (view.getId()) { case R.id.text: { TextView tv = (TextView) view; String title = cursor.getString(columnIdx); tv.setText(title); tv.requestLayout(); return false; } case R.id.icon: { ImageView iv = (ImageView) view; iv.setImageResource(itsFileIcon); iv.setColorFilter(getResources().getColor(R.color.treeview_icons)); return true; } case R.id.mod_date: { TextView tv = (TextView) view; long date = cursor.getLong(RecentFilesDb.QUERY_COL_DATE); tv.setText(Utils.formatDate(date, getActivity())); return true; } } return false; } }); setListAdapter(itsFilesAdapter); LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_FILES, null, this); }
From source file:com.jefftharris.passwdsafe.FileListFragment.java
/** Update files after the loader is complete */ private void updateFiles(List<Map<String, Object>> fileData) { SimpleAdapter adapter = null;/*from w w w . j a v a2s .com*/ if (fileData != null) { adapter = new SimpleAdapter(getActivity(), fileData, R.layout.file_list_item, new String[] { TITLE, ICON, MOD_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date }); adapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { switch (view.getId()) { case R.id.text: { TextView tv = (TextView) view; tv.setText(textRepresentation); tv.requestLayout(); return true; } case R.id.mod_date: { if (data == null) { view.setVisibility(View.GONE); return true; } else { view.setVisibility(View.VISIBLE); return false; } } } return false; } }); } View rootView = getView(); if (rootView == null) { // Fragment destroyed return; } View groupPanel = rootView.findViewById(R.id.current_group_panel); TextView groupLabel = (TextView) rootView.findViewById(R.id.current_group_label); TextView emptyLabel = (TextView) rootView.findViewById(android.R.id.empty); if (itsDir == null) { groupPanel.setVisibility(View.GONE); groupLabel.setText(""); emptyLabel.setText(R.string.ext_storage_not_mounted); } else { groupPanel.setVisibility(View.VISIBLE); groupLabel.setText(itsDir.toString()); emptyLabel.setText(R.string.no_files); } setListAdapter(adapter); // Open the default file if (getListAdapter() != null) { Activity act = getActivity(); PasswdSafeApp app = (PasswdSafeApp) act.getApplication(); if (app.checkOpenDefault()) { SharedPreferences prefs = Preferences.getSharedPrefs(act); Uri defFile = Preferences.getDefFilePref(prefs); if (defFile != null) { itsListener.openFile(defFile, null); } } } }
From source file:net.tjado.passwdsafe.FileListFragment.java
/** Update files after the loader is complete */ private void updateFiles(List<Map<String, Object>> fileData) { SimpleAdapter adapter = null;/*from w ww . ja va 2 s . co m*/ if (fileData != null) { adapter = new SimpleAdapter(getActivity(), fileData, R.layout.file_list_item, new String[] { TITLE, ICON, MOD_DATE }, new int[] { R.id.text, R.id.icon, R.id.mod_date }); adapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { switch (view.getId()) { case R.id.icon: { ImageView iv = (ImageView) view; iv.setImageResource((int) data); iv.setColorFilter(getResources().getColor(R.color.treeview_icons)); return true; } case R.id.text: { TextView tv = (TextView) view; tv.setText(textRepresentation); tv.requestLayout(); return true; } case R.id.mod_date: { if (data == null) { view.setVisibility(View.GONE); return true; } else { view.setVisibility(View.VISIBLE); return false; } } } return false; } }); } View rootView = getView(); if (rootView == null) { // Fragment destroyed return; } View groupPanel = rootView.findViewById(R.id.current_group_panel); TextView groupLabel = (TextView) rootView.findViewById(R.id.current_group_label); TextView emptyLabel = (TextView) rootView.findViewById(android.R.id.empty); if (itsDir == null) { groupPanel.setVisibility(View.GONE); groupLabel.setText(""); emptyLabel.setText(R.string.ext_storage_not_mounted); } else { groupPanel.setVisibility(View.VISIBLE); groupLabel.setText(itsDir.toString()); emptyLabel.setText(R.string.no_files); } setListAdapter(adapter); // Open the default file if (getListAdapter() != null) { Activity act = getActivity(); PasswdSafeApp app = (PasswdSafeApp) act.getApplication(); if (app.checkOpenDefault()) { SharedPreferences prefs = Preferences.getSharedPrefs(act); Uri defFile = Preferences.getDefFilePref(prefs); if (defFile != null) { itsListener.openFile(defFile, null); } } } }
From source file:com.agenthun.readingroutine.utils.TextSharedElementCallback.java
@Override public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) { TextView initialView = getTextView(sharedElements); if (initialView == null) { Log.w(TAG, "onSharedElementEnd: No shared TextView, skipping"); return;/*from w w w. j av a 2s .c om*/ } // Setup the TextView's end values. initialView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTargetViewTextSize); ViewUtils.setPaddingStart(initialView, mTargetViewPaddingStart); // Re-measure the TextView (since the text size has changed). int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); initialView.measure(widthSpec, heightSpec); initialView.requestLayout(); }
From source file:fr.jerome.climbinggymlog.view.googletools.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 va 2 s.c om */ protected TextView createDefaultTabView(Context context) { final TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.post(new Runnable() { @Override public void run() { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); if (textView.getWidth() < ((View) textView.getParent().getParent()).getWidth() * 0.33f) { params.width = 0; params.weight = 0.33f; } textView.requestLayout(); } }); 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); return textView; }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctNameAndPriceWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override// w w w. j a va 2s . c o m protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } LinearLayout txtContainer = (LinearLayout) v.findViewById(R.id.text_container); txtContainer.measure(0, 0); int currentWidth = txtContainer.getMeasuredWidth(); int maxWidth = txtContainer.getWidth() - UIUtils.convertDipToPixels(mActivity, 35); nameLbl.measure(0, 0); int nameWidth = nameLbl.getMeasuredWidth(); int priceWidth = 0; if (row.hasPrice) { TextView priceLbl = (TextView) v.findViewById(R.id.price); priceLbl.measure(0, 0); priceWidth = priceLbl.getMeasuredWidth(); ViewGroup.LayoutParams lpPrice = priceLbl.getLayoutParams(); lpPrice.width = priceWidth; priceLbl.setLayoutParams(lpPrice); priceLbl.requestLayout(); } ViewGroup.LayoutParams lpName = nameLbl.getLayoutParams(); if (maxWidth > 0 && currentWidth < maxWidth) { if (maxWidth - priceWidth > nameWidth) { lpName.width = nameWidth; } else { lpName.width = maxWidth - priceWidth; } } else { lpName.width = maxWidth - priceWidth; } nameLbl.setLayoutParams(lpName); nameLbl.requestLayout(); } }); }
From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java
private void correctCountWidth(final View v, final AdvancedOrderCategoryItemRow row) { mActivity.getMainService().postOnUIHandler(new SafeRunnable() { @Override/*from w w w.ja v a 2 s . com*/ protected void safeRun() throws Exception { TextView nameLbl = (TextView) v.findViewById(R.id.name); if (!row.name.equals(nameLbl.getText())) { return; } TextView countLbl = (TextView) v.findViewById(R.id.count); countLbl.measure(0, 0); int countWidth = countLbl.getMeasuredWidth(); if (countWidth > 140) { ViewGroup.LayoutParams lpCount = countLbl.getLayoutParams(); lpCount.width = 140; countLbl.setLayoutParams(lpCount); countLbl.requestLayout(); } } }); }