List of usage examples for android.widget TextView getParent
public final ViewParent getParent()
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter("increaseClickingArea") public static void increaseClickingArea(TextView textView, float size) { // fork from http://stackoverflow.com/a/1343796 View parent = (View) textView.getParent(); // post in the parent's message queue to make sure the parent // lays out its children before we call View#getHitRect() parent.post(() -> {// w ww.j a va2s. com final int halfSize = (int) (size / 2 + 0.5); Rect rect = new Rect(); textView.getHitRect(rect); rect.top -= halfSize; rect.right += halfSize; rect.bottom += halfSize; rect.left -= halfSize; // use TouchDelegate to increase count's clicking area parent.setTouchDelegate(new TouchDelegate(rect, textView)); }); }
From source file:fr.eoit.activity.util.AmazingSimpleCursorAdapter.java
/** * Configure the view (a listview item) to display headers or not based on displaySectionHeader * (e.g. if displaySectionHeader header.setVisibility(VISIBLE) else header.setVisibility(GONE)). *//*from w w w .j a v a 2 s . c o m*/ protected void bindSectionHeader(View view, int position, boolean displaySectionHeader) { if (displaySectionHeader && defaultIndexer != null) { ((LinearLayout) view.findViewById(R.id.header).getParent()).setVisibility(View.VISIBLE); TextView lSectionTitle = (TextView) view.findViewById(R.id.header); ((LinearLayout) lSectionTitle.getParent()).setBackgroundColor(0x222222); lSectionTitle.setText(String.valueOf(getSections()[getSectionForPosition(position)])); } else { ((LinearLayout) view.findViewById(R.id.header).getParent()).setVisibility(View.GONE); } }
From source file:com.odoo.base.addons.mail.widget.MailChatterCompose.java
private void init() { TextView recordName = (TextView) findViewById(R.id.recordName); parent = (View) recordName.getParent().getParent(); ODataRow record = mModel.browse(mModel.selectRowId(server_id)); String name = record.getString(mModel.getDefaultNameColumn()); findViewById(R.id.dialogHeader).setBackgroundColor(OStringColorUtil.getStringColor(this, name)); if (mType == MessageType.Message) { edtSubject.setText("Re: " + name); recordName.setText(String.format(OResource.string(this, R.string.message_to), name)); } else {// w w w. j a va 2 s .c o m recordName.setText(R.string.add_internal_note); edtSubject.setVisibility(View.GONE); edtBody.setHint(R.string.internal_note_hint); OControls.setText(parent, R.id.btnSend, R.string.label_log_note); } edtBody.requestFocus(); }
From source file:semanticweb.hws14.movapp.activities.MovieDetail.java
private void colorIt(TextView tv) { LinearLayout p = (LinearLayout) tv.getParent(); if (rowCount % 2 == 0) { p.setBackgroundColor(Color.rgb(206, 238, 237)); } else {//from w w w . j a v a 2 s.com p.setBackgroundColor(Color.rgb(236, 248, 248)); } rowCount++; }
From source file:com.achep.base.ui.DialogBuilder.java
/** * Builds dialog's view//from ww w. j a va2s . co m * * @throws IllegalArgumentException when type is not one of defined. * @see #LAYOUT_COMMON * @see #LAYOUT_SKELETON */ public View createView(int type) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ViewGroup rootLayout = (ViewGroup) createSkeleton(); ViewGroup contentLayout = rootLayout; switch (type) { case LAYOUT_COMMON: final boolean hasMessageOnly = mView == null && mViewRes == 0; final int layoutResource = mContentViewRes != 0 ? mContentViewRes : hasMessageOnly ? R.layout.dialog_message : R.layout.dialog_content; ViewStub viewStub = (ViewStub) inflater.inflate(R.layout.dialog_main_body, rootLayout, true) .findViewById(R.id.placeholder); viewStub.setLayoutResource(layoutResource); contentLayout = (ViewGroup) viewStub.inflate().findViewById(R.id.content); if (contentLayout == null) contentLayout = rootLayout; TextView messageView = (TextView) contentLayout.findViewById(R.id.message); if (messageView != null) { if (!TextUtils.isEmpty(mMessageText)) { messageView.setMovementMethod(new LinkMovementMethod()); messageView.setText(mMessageText); } else { ViewGroup vg = (ViewGroup) messageView.getParent(); vg.removeView(messageView); } } // Fall down. case LAYOUT_SKELETON: if (mViewRes != 0) { inflater.inflate(mViewRes, contentLayout, true); } else if (mView != null) { contentLayout.addView(mView); } return rootLayout; default: throw new IllegalArgumentException(); } }
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)}./* ww w . j a va 2 s . c o m*/ */ 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.air.mobilebrowser.BrowserActivity.java
/** Logs an onscreen message for debugging. */ public void logMessage(final TextView consoleView, String message, String value, int color) { if (mIsDebugEnabled && consoleView != null) { consoleView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w w w .j a va 2 s. c om*/ public void onFocusChange(View v, boolean hasFocus) { ViewParent parent = consoleView.getParent(); final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 0); } }); Editable editable = consoleView.getEditableText(); SpannableString str = null; if (editable == null) { editable = new SpannableStringBuilder(); str = new SpannableString(message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 2 + value.length(), 0); } else { str = new SpannableString("\n" + message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 3 + value.length(), 0); } editable.append(str); consoleView.setText(editable, TextView.BufferType.EDITABLE); ViewParent parent = consoleView.getParent(); if (parent instanceof ScrollView) { final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 1000); } } }
From source file:com.android.tv.menu.MenuLayoutManager.java
private void setTempTitleView(TextView dest, TextView src) { dest.setVisibility(View.VISIBLE); dest.setText(src.getText());//from w ww .jav a2 s . c o m dest.setTranslationY(0.0f); if (src.getVisibility() == View.VISIBLE) { dest.setAlpha(src.getAlpha()); dest.setScaleX(src.getScaleX()); dest.setScaleY(src.getScaleY()); } else { dest.setAlpha(0.0f); dest.setScaleX(1.0f); dest.setScaleY(1.0f); } View parent = (View) src.getParent(); dest.setLeft(src.getLeft() + parent.getLeft()); dest.setRight(src.getRight() + parent.getLeft()); dest.setTop(src.getTop() + parent.getTop()); dest.setBottom(src.getBottom() + parent.getTop()); }
From source file:sjizl.com.FileUploadTest2.java
@SuppressLint("NewApi") @Override/*from w w w . j a va 2s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.fileuploadtest2); //ac_image_grid TextView textView2_under_title; final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext())); progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole); progressBar_hole.setVisibility(View.INVISIBLE); right_lin = (LinearLayout) findViewById(R.id.right_lin); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); //right_lin.setBackgroundColor(Color.BLUE); right_lin = (LinearLayout) findViewById(R.id.right_lin); left_lin1 = (LinearLayout) findViewById(R.id.left_lin1); left_lin3 = (LinearLayout) findViewById(R.id.left_lin3); left_lin4 = (LinearLayout) findViewById(R.id.left_lin4); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); textView2_under_title = (TextView) findViewById(R.id.textView2_under_title); ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title); textView2_under_title.setVisibility(View.GONE); ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Button upload_photo0 = (Button) findViewById(R.id.upload_photo0); Button upload_photo1 = (Button) findViewById(R.id.upload_photo1); Button upload_photo2 = (Button) findViewById(R.id.upload_photo2); upload_photo0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "UploadActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class); startActivity(dashboard); } }); upload_photo1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); upload_photo2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); final ImageView left_button; left_button = (ImageView) findViewById(R.id.imageView1_back); Brows(); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); Intent dashboard = new Intent(getApplicationContext(), ProfileActivity.class); dashboard.putExtra("user", naam); dashboard.putExtra("user_foto", foto); dashboard.putExtra("user_foto_num", foto_num); startActivity(dashboard); } }); CommonUtilities u = new CommonUtilities(); u.setHeaderConrols(getApplicationContext(), this, right_lin, left_lin3, left_lin4, left_lin1, left_button); ; }
From source file:sjizl.com.FileUploadTest.java
@SuppressLint("NewApi") @Override/*from w w w . j a v a 2 s.co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.fileuploadtest2); //ac_image_grid TextView textView2_under_title; final ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext())); progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole); progressBar_hole.setVisibility(View.INVISIBLE); right_lin = (LinearLayout) findViewById(R.id.right_lin); rand = CommonUtilities.randInt(111, 999); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); //right_lin.setBackgroundColor(Color.BLUE); right_lin = (LinearLayout) findViewById(R.id.right_lin); left_lin1 = (LinearLayout) findViewById(R.id.left_lin1); left_lin3 = (LinearLayout) findViewById(R.id.left_lin3); left_lin4 = (LinearLayout) findViewById(R.id.left_lin4); middle_lin = (LinearLayout) findViewById(R.id.middle_lin); upload_photo_text = (LinearLayout) findViewById(R.id.upload_photo_text); textView2_under_title = (TextView) findViewById(R.id.textView2_under_title); ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title); textView2_under_title.setVisibility(View.GONE); ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard); if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Button upload_photo0 = (Button) findViewById(R.id.upload_photo0); Button upload_photo1 = (Button) findViewById(R.id.upload_photo1); Button upload_photo2 = (Button) findViewById(R.id.upload_photo2); upload_photo0.setVisibility(View.GONE); upload_photo1.setVisibility(View.GONE); upload_photo2.setVisibility(View.GONE); upload_photo0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CommonUtilities.custom_toast(getApplicationContext(), FileUploadTest.this, "UploadActivity! ", null, R.drawable.iconbd); Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class); startActivity(dashboard); } }); upload_photo1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); upload_photo2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show(); Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class); startActivity(dashboard); } }); final ImageView left_button; left_button = (ImageView) findViewById(R.id.imageView1_back); Button button1 = (Button) findViewById(R.id.upload_photo1); SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE); naam = sp.getString("naam", null); username = sp.getString("username", null); password = sp.getString("password", null); foto = sp.getString("foto", null); foto_num = sp.getString("foto_num", null); imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, imageView2_dashboard, options); Brows(); listView.setLongClickable(true); registerForContextMenu(listView); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //startImagePagerActivity(position); if (position == 0) { openGallery(SELECT_FILE1); } else { listView.showContextMenuForChild(view); // registerForContextMenu(view); // openContextMenu(view); // unregisterForContextMenu(view); } } }); left_lin1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { left_lin1.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); onBackPressed(); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { left_lin1.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); CommonUtilities u = new CommonUtilities(); u.setHeaderConrols(getApplicationContext(), this, right_lin, left_lin3, left_lin4, left_lin1, left_button); ; middle_lin.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) { middle_lin.setBackgroundColor(Color.DKGRAY); v.setBackgroundColor(Color.DKGRAY); } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { middle_lin.setBackgroundColor(Color.BLACK); v.setBackgroundColor(Color.BLACK); } return false; } }); }