List of usage examples for android.widget TextView getTag
@ViewDebug.ExportedProperty
public Object getTag()
From source file:Main.java
private static void setCustomFont(TextView c) { Object tag = c.getTag(); if (tag instanceof String) { if (((String) tag).contains("bold")) { c.setTypeface(bold);//from ww w .ja v a 2 s. c o m return; } if (((String) tag).contains("condensed")) { c.setTypeface(condensed); return; } if (((String) tag).contains("light")) { c.setTypeface(light); return; } } c.setTypeface(normal); }
From source file:Main.java
private static void setCustomFont(TextView c) { Object tag = c.getTag(); if (tag instanceof String) { final String tagString = (String) tag; if (tagString.contains(TAG_BOLD) && bold != null) { c.setTypeface(bold);/*w w w . j a v a2s . co m*/ return; } if (tagString.contains(TAG_CONDENSED) && condensed != null) { c.setTypeface(condensed); return; } if (tagString.contains(TAG_LIGHT) && light != null) { c.setTypeface(light); return; } } if (normal != null) { c.setTypeface(normal); } }
From source file:Main.java
/** * Make a textview to a collapsible textview with the indicator on the right of the textview * /*from w w w . j ava 2 s . c o m*/ * @param tv , {@link TextView} to be converted * @param upDrawableResId , drawable resource id to be used as up indicator * @param downDrawableResId , drawable resource id to be used as down indicator * @param lineTreshold , no of line to be displayed for the collapsed state */ public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId, final int lineTreshold) { final Drawable[] drawables = tv.getCompoundDrawables(); final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId); final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setEllipsize(TruncateAt.END); tv.setMaxLines(lineTreshold); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { // show everything snippet = false; tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { // show snippet snippet = true; tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); } else { tv.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { ViewTreeObserver vto = tv.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public void onGlobalLayout() { tv.setEllipsize(TruncateAt.END); int line = tv.getLineCount(); tv.setMaxLines(lineTreshold); if (line <= lineTreshold) { tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // empty listener // Log.d("line count", "count: "+ // tv.getLineCount()); } }); if (tv.getLayout() != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } return; } tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); tv.setTag(true); tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (v instanceof TextView) { TextView tv = (TextView) v; boolean snippet = (Boolean) tv.getTag(); if (snippet) { snippet = false; // show everything tv.setMaxLines(Integer.MAX_VALUE); tv.setEllipsize(null); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up, drawables[3]); } else { snippet = true; // show snippet tv.setMaxLines(lineTreshold); tv.setEllipsize(TruncateAt.END); tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]); } tv.setTag(snippet); } } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { tv.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { tv.getViewTreeObserver().removeOnGlobalLayoutListener(this); } } }); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } }); } }
From source file:com.jasonchen.microlang.view.LinearViewPagerIndicator.java
@Override public void onClick(View v) { TextView tv = (TextView) v; mPager.setCurrentItem(Integer.valueOf(tv.getTag().toString())); }
From source file:com.alexive.graphicalutils.view.CardBuilder.java
private void setTextColor(List<TextView> views, int primaryColor, int secondaryColor) { boolean primary; for (TextView tv : views) { primary = tv.getTag() != null || tv instanceof Button; tv.setTextColor(primary ? primaryColor : secondaryColor); }/* w w w . j ava 2 s .c o m*/ }
From source file:org.ounl.lifelonglearninghub.learntracker.gis.ou.swipe.TimeLineActivity.java
/** * Removes record both from sqlite and backend * /* w w w . j a v a 2s.c om*/ * @param v */ public void onClickDeleteActivity(View v) { LinearLayout llCheckItemRow = (LinearLayout) v.getParent(); LinearLayout llCheckItemWrapper = (LinearLayout) llCheckItemRow.getParent(); int iNumItemsHistory = 0; int iTag = 0; int iClicked = 0; try { llHistory = (LinearLayout) llCheckItemWrapper.getParent(); llListFragment = (LinearLayout) llHistory.getParent(); iNumItemsHistory = ((llHistory.getChildCount() - 1) / 2) - 1; iTag = new Integer(llCheckItemWrapper.getTag().toString()); iClicked = (iTag - iNumItemsHistory) * (-1); iToRemove = (iClicked + 1) * 2; } catch (Exception e) { e.printStackTrace(); } TextView myText = (TextView) llCheckItemRow.findViewById(R.id.textViewTimeStamp); lCheckInToDelete = (Long) myText.getTag(); String sCheckIn = (String) myText.getText(); TextView tvDur = (TextView) llCheckItemRow.findViewById(R.id.textViewDuration); sIdSbuject = (String) tvDur.getTag(); new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Remove activity?") .setMessage("Are you sure to remove activity started at " + sCheckIn + " ?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Toast.makeText(getApplicationContext(), "About to delete activity "+sCheckIn+" ... ", Toast.LENGTH_SHORT).show(); Log.d(CLASSNAME, "About to delte activity mills[" + lCheckInToDelete + "]"); // Delete this transactional // Issue 16 // https://code.google.com/p/lifelong-learning-hub/issues/detail?id=16 deleteActivityBackend(lCheckInToDelete, Session.getSingleInstance().getUserName()); Session.getSingleInstance().getDatabaseHandler().deleteActivity(lCheckInToDelete); DateUtils du = new DateUtils(); TextView tvDuration = (TextView) llListFragment.findViewById(R.id.tvDuration); tvDuration.setText(du.duration( Session.getSingleInstance().getDatabaseHandler().getAccumulatedTime(sIdSbuject))); llHistory.getChildAt(iToRemove).setVisibility(View.GONE); //Stop the activity //TimeLineActivity.this.finish(); } }).setNegativeButton("No", null).show(); }
From source file:org.ale.scanner.zotero.EditItemActivity.java
private void extractValues() throws JSONException { JSONObject info = mWorkingItem.getSelectedInfo(); LinearLayout container = ((LinearLayout) findViewById(R.id.editContainer)); LinearLayout row;/*from ww w. j av a 2 s . c o m*/ LinearLayout crow; for (int i = 0; i < container.getChildCount(); i++) { row = (LinearLayout) container.getChildAt(i); switch (row.getId()) { case R.id.edit_field: TextView tv = (TextView) row.findViewById(R.id.label); EditText et = (EditText) row.findViewById(R.id.content); String label = (String) tv.getTag(); String content = et.getText().toString(); info.put(label, content); break; case R.id.edit_creators: JSONArray creators = new JSONArray(); JSONObject creator; for (int c = 0; c < row.getChildCount(); c++) { crow = (LinearLayout) row.getChildAt(c); EditText name = (EditText) crow.findViewById(R.id.creator); if (TextUtils.isEmpty(name.getText().toString())) { continue; } Spinner sp = (Spinner) crow.findViewById(R.id.creator_type); creator = new JSONObject(); int indx = CreatorType.LocalizedBook.indexOf((String) sp.getSelectedItem()); creator.put(CreatorType.type, CreatorType.Book.get(indx)); creator.put(ItemField.Creator.name, name.getText().toString()); creators.put(creator); } info.put(ItemField.creators, creators); break; case R.id.edit_notes: JSONArray notes = new JSONArray(); JSONObject note; EditText note_et; for (int c = 0; c < row.getChildCount(); c++) { crow = (LinearLayout) row.getChildAt(c); note_et = (EditText) crow.findViewById(R.id.content); String note_content = note_et.getText().toString(); if (TextUtils.isEmpty(note_content)) continue; note = new JSONObject(); note.put(ItemField.Note.itemType, ItemField.Note.note); note.put(ItemField.Note.note, note_content); notes.put(note); } info.put(ItemField.notes, notes); break; case R.id.edit_tags: JSONArray tags = new JSONArray(); JSONObject tag; EditText tag_et; for (int c = 0; c < row.getChildCount(); c++) { crow = (LinearLayout) row.getChildAt(c); tag_et = (EditText) crow.findViewById(R.id.content); String tag_content = tag_et.getText().toString(); if (TextUtils.isEmpty(tag_content)) continue; tag = new JSONObject(); tag.put(ItemField.Tag.tag, tag_content); tags.put(tag); } info.put(ItemField.tags, tags); break; default: break; } } }
From source file:com.gh4a.activities.IssueEditActivity.java
private void setLabelSelection(TextView view, boolean selected) { Label label = (Label) view.getTag(); if (selected) { int color = ApiHelpers.colorForLabel(label); view.setTypeface(view.getTypeface(), Typeface.BOLD); view.setBackgroundColor(color);//from ww w. j ava 2 s . c om view.setTextColor(UiUtils.textColorForBackground(this, color)); } else { view.setTypeface(view.getTypeface(), 0); view.setBackgroundColor(0); view.setTextColor(ContextCompat.getColor(this, Gh4Application.THEME != R.style.LightTheme ? R.color.label_fg_light : R.color.label_fg_dark)); } }
From source file:com.jbirdvegas.mgerrit.cards.PatchSetPropertiesCard.java
private void setupUserDetails(final TextView view, final int id, final String email, final String name) { view.setTag(id);/*ww w .j a v a2s. c o m*/ // attach owner's gravatar GravatarHelper.attachGravatarToTextView(view, email, mRequestQuery); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setTrackingUser((Integer) view.getTag()); } }); setImageCaption(view, R.string.commit_owner, name); }
From source file:com.secbro.qark.customintent.CreateCustomIntentActivity.java
private ArrayList<String> findAllKeys(ArrayList<String> keys, ViewGroup viewGroup) { int count = viewGroup.getChildCount(); for (int i = 0; i < count; i++) { View view = viewGroup.getChildAt(i); if (view instanceof ViewGroup) findAllKeys(keys, (ViewGroup) view); else if (view instanceof TextView) { TextView textview = (TextView) view; // if (!textview.getText().toString().equals(getResources().getString(R.string.intent_extras_key)) && // !textview.getText().toString().equals(getResources().getString(R.string.intent_extras_value)) && // !textview.getTag().toString().equals("value_field")) { if (textview.getTag() != null && textview.getTag().toString().equals("key_field")) { keys.add(textview.getText().toString()); }//from w w w.j a v a 2s . c o m } } return keys; }