List of usage examples for android.widget TextView setEllipsize
public void setEllipsize(TextUtils.TruncateAt where)
From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java
private View handleTrains(final int position, View convertView, @NonNull final ViewGroup parent) { // Train//from w ww .j a v a 2 s .c o m final Station station = stations.get(position); final Set<TrainLine> trainLines = station.getLines(); TrainViewHolder viewHolder; if (convertView == null || convertView.getTag() == null) { final LayoutInflater vi = (LayoutInflater) parent.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.list_nearby, parent, false); viewHolder = new TrainViewHolder(); viewHolder.resultLayout = (LinearLayout) convertView.findViewById(R.id.nearby_results); viewHolder.stationNameView = (TextView) convertView.findViewById(R.id.station_name); viewHolder.imageView = (ImageView) convertView.findViewById(R.id.icon); viewHolder.details = new HashMap<>(); viewHolder.arrivalTime = new HashMap<>(); convertView.setTag(viewHolder); } else { viewHolder = (TrainViewHolder) convertView.getTag(); } viewHolder.stationNameView.setText(station.getName()); viewHolder.imageView .setImageDrawable(ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_train_white_24dp)); for (final TrainLine trainLine : trainLines) { if (trainArrivals.indexOfKey(station.getId()) != -1) { final List<Eta> etas = trainArrivals.get(station.getId()).getEtas(trainLine); if (etas.size() != 0) { final LinearLayout llv; boolean cleanBeforeAdd = false; if (viewHolder.details.containsKey(trainLine)) { llv = viewHolder.details.get(trainLine); cleanBeforeAdd = true; } else { final LinearLayout llh = new LinearLayout(context); llh.setOrientation(LinearLayout.HORIZONTAL); llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0); llv = new LinearLayout(context); llv.setOrientation(LinearLayout.VERTICAL); llv.setPadding(line1PaddingColor, 0, 0, 0); llh.addView(llv); viewHolder.resultLayout.addView(llh); viewHolder.details.put(trainLine, llv); } final List<String> keysCleaned = new ArrayList<>(); for (final Eta eta : etas) { final Stop stop = eta.getStop(); final String key = station.getName() + "_" + trainLine.toString() + "_" + stop.getDirection().toString() + "_" + eta.getDestName(); if (viewHolder.arrivalTime.containsKey(key)) { final RelativeLayout insideLayout = viewHolder.arrivalTime.get(key); final TextView timing = (TextView) insideLayout.getChildAt(2); if (cleanBeforeAdd && !keysCleaned.contains(key)) { timing.setText(""); keysCleaned.add(key); } final String timingText = timing.getText() + eta.getTimeLeftDueDelay() + " "; timing.setText(timingText); } else { final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); final RelativeLayout insideLayout = new RelativeLayout(context); insideLayout.setLayoutParams(leftParam); final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, trainLine); int lineId = Util.generateViewId(); lineIndication.setId(lineId); final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableParam.addRule(RelativeLayout.RIGHT_OF, lineId); availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0); final TextView stopName = new TextView(context); final String destName = eta.getDestName() + ": "; stopName.setText(destName); stopName.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey_5)); stopName.setLayoutParams(availableParam); int availableId = Util.generateViewId(); stopName.setId(availableId); final RelativeLayout.LayoutParams availableValueParam = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); availableValueParam.addRule(RelativeLayout.RIGHT_OF, availableId); availableValueParam.setMargins(0, 0, 0, 0); final TextView timing = new TextView(context); final String timeLeftDueDelay = eta.getTimeLeftDueDelay() + " "; timing.setText(timeLeftDueDelay); timing.setTextColor(ContextCompat.getColor(parent.getContext(), R.color.grey)); timing.setLines(1); timing.setEllipsize(TruncateAt.END); timing.setLayoutParams(availableValueParam); insideLayout.addView(lineIndication); insideLayout.addView(stopName); insideLayout.addView(timing); llv.addView(insideLayout); viewHolder.arrivalTime.put(key, insideLayout); } } } } } convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, station.getId(), station.getStopsPosition().get(0).getLatitude(), station.getStopsPosition().get(0).getLongitude())); return convertView; }
From source file:com.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }//from w ww .j a va 2 s. c o m if (action == MotionEvent.ACTION_DOWN) { v.setBackgroundColor(0xff606060); mInitialX = mLastX = (int) event.getX(); mDraggingLabel = false; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { v.setBackgroundColor(0); if (mDraggingLabel) { Message msg = mLabelScroller.obtainMessage(0, tv); mLabelScroller.sendMessageDelayed(msg, 1000); } } else if (action == MotionEvent.ACTION_MOVE) { if (mDraggingLabel) { int scrollx = tv.getScrollX(); int x = (int) event.getX(); int delta = mLastX - x; if (delta != 0) { mLastX = x; scrollx += delta; if (scrollx > mTextWidth) { // scrolled the text completely off the view to the left scrollx -= mTextWidth; scrollx -= mViewWidth; } if (scrollx < -mViewWidth) { // scrolled the text completely off the view to the right scrollx += mViewWidth; scrollx += mTextWidth; } tv.scrollTo(scrollx, 0); } return true; } int delta = mInitialX - (int) event.getX(); if (Math.abs(delta) > mTouchSlop) { // start moving mLabelScroller.removeMessages(0, tv); // Only turn ellipsizing off when it's not already off, because it // causes the scroll position to be reset to 0. if (tv.getEllipsize() != null) { tv.setEllipsize(null); } Layout ll = tv.getLayout(); // layout might be null if the text just changed, or ellipsizing // was just turned off if (ll == null) { return false; } // get the non-ellipsized line width, to determine whether scrolling // should even be allowed mTextWidth = (int) tv.getLayout().getLineWidth(0); mViewWidth = tv.getWidth(); if (mViewWidth > mTextWidth) { tv.setEllipsize(TruncateAt.END); v.cancelLongPress(); return false; } mDraggingLabel = true; tv.setHorizontalFadingEdgeEnabled(true); v.cancelLongPress(); return true; } } return false; }