List of usage examples for android.widget TableRow setOnLongClickListener
public void setOnLongClickListener(@Nullable OnLongClickListener l)
From source file:com.uoit.freeroomfinder.RoomsBooked.java
/** * SetupUpTableView Sets up the logic for handling what happens inside the table of booking * entries.// www . j a va2s . c o m * * @param inflater The specified inflater for the view. * @param container The ViewGroup container for the view. * @param index The index of the selected row. * * @return Returns the corresponding table row that was selected. */ public TableRow SetupUpTableView(LayoutInflater inflater, ViewGroup container, final int index) { // Get all the handles to the UI elements inside the view. View newView = inflater.inflate(R.layout.room_book_item, container, false); TextView room = (TextView) newView.findViewById(R.id.book_room); TextView start = (TextView) newView.findViewById(R.id.book_stime); TextView end = (TextView) newView.findViewById(R.id.book_etime); TextView date = (TextView) newView.findViewById(R.id.book_date); // Get the index of the result. Rooms first = results.get(index); // Get the attributes of this booking. room.setText(first.getRoom()); start.setText(DateTimeUtility.formatTime(new Date(first.getStartTime()))); end.setText(DateTimeUtility.formatTime(new Date(first.getEndTime()))); date.setText(DateTimeUtility.formatDate(first.getDate())); TableRow tr = (TableRow) newView.findViewById(R.id.tableRow2); tr.setOnLongClickListener(new View.OnLongClickListener() { /* * (non-Javadoc) * * @see android.view.View.OnLongClickListener#onLongClick(android.view.View) */ public boolean onLongClick(View view) { // Called when the user long-clicks on a View. if (mActionMode != null) { return false; } // Set the row as highlighted. selectedRow = (TableRow) view; background = selectedRow.getBackground(); selectedRow.setBackgroundColor( RoomsBooked.this.getResources().getColor(android.R.color.holo_blue_light)); rowIndex = index; // Start the CAB using the ActionMode. Callback defined above. mActionMode = getActivity().startActionMode(mActionModeCallback); view.setSelected(true); return true; } }); this.registerForContextMenu(tr); return tr; }
From source file:se.frikod.payday.DailyBudgetFragment.java
private void updateBudgetItems() { TableLayout itemsTable = (TableLayout) V.findViewById(R.id.budgetItems); itemsTable.removeAllViews();/*w w w. j a v a 2s . co m*/ for (int i = 0; i < budget.budgetItems.size(); i++) { BudgetItem bi = budget.budgetItems.get(i); final int currentIndex = i; LayoutInflater inflater = activity.getLayoutInflater(); TableRow budgetItemView = (TableRow) inflater.inflate(R.layout.daily_budget_budget_item, itemsTable, false); TextView amount = (TextView) budgetItemView.findViewById(R.id.budgetItemAmount); TextView title = (TextView) budgetItemView.findViewById(R.id.budgetItemLabel); amount.setText(budget.formatter.format(bi.amount)); title.setText(bi.title); if (bi.exclude) { amount.setTextColor(0xffCCCCCC); amount.setPaintFlags(amount.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); title.setTextColor(0xffCCCCCC); title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } budgetItemView.setClickable(true); budgetItemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(10); BudgetItem bi = budget.budgetItems.get(currentIndex); bi.exclude = !bi.exclude; budget.saveBudgetItems(); updateBudgetItems(); } }); budgetItemView.setLongClickable(true); budgetItemView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { editBudgetItem(v, currentIndex); return true; } }); itemsTable.addView(budgetItemView); } FontUtils.setRobotoFont(activity, itemsTable); updateBudget(); }
From source file:io.github.runassudo.ptoffline.adapters.TripAdapter.java
private static void bindStops(Context context, final LegHolder leg_holder, List<Stop> stops) { leg_holder.stops.setVisibility(View.GONE); leg_holder.duration.setVisibility(View.GONE); leg_holder.info.setOnClickListener(new View.OnClickListener() { @Override/*from w ww .j a v a2 s .com*/ public void onClick(View v) { if (leg_holder.stops.getVisibility() == View.GONE) { leg_holder.stops.setVisibility(View.VISIBLE); leg_holder.duration.setVisibility(View.VISIBLE); } else { leg_holder.stops.setVisibility(View.GONE); leg_holder.duration.setVisibility(View.GONE); } } }); // highlight duration to set it apart from platforms/positions leg_holder.duration.setTextColor(leg_holder.departureLocation.getCurrentTextColor()); // stop here, if there are no stops if (stops == null) return; // Remove previous stops in case we are refreshing the view. leg_holder.stops.removeAllViews(); for (final Stop stop : stops) { TableRow stopView = (TableRow) LayoutInflater.from(context).inflate(R.layout.stop, leg_holder.stops, false); StopHolder stopHolder = new StopHolder(stopView); Date arrivalTime = stop.getArrivalTime(); Date departureTime = stop.getDepartureTime(); if (arrivalTime != null) { TransportrUtils.setArrivalTimes(context, stopHolder.arrivalTime, stopHolder.arrivalDelay, stop); } else { stopHolder.arrivalTime.setVisibility(View.GONE); stopHolder.arrivalDelay.setVisibility(View.GONE); } if (departureTime != null) { TransportrUtils.setDepartureTimes(context, stopHolder.departureTime, stopHolder.departureDelay, stop); } else { stopHolder.departureTime.setVisibility(View.GONE); stopHolder.departureDelay.setVisibility(View.GONE); } stopHolder.location.setText(TransportrUtils.getLocName(stop.location)); if (stop.plannedArrivalPosition != null) { stopHolder.arrivalPlatform.setText(stop.plannedArrivalPosition.name); } if (stop.plannedDeparturePosition != null) { stopHolder.departurePlatform.setText(stop.plannedDeparturePosition.name); } SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); if (settings.getBoolean("pref_key_hide_departure_time", false)) { stopHolder.departureTime.setVisibility(View.GONE); stopHolder.departureDelay.setVisibility(View.GONE); stopHolder.departurePlatform.setVisibility(View.GONE); } // Creating PopupMenu for stop final LegPopupMenu popup = new LegPopupMenu(context, stopView, stop); // show popup on click stopView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { popup.show(); } }); // show popup also on long click stopView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { popup.show(); return true; } }); leg_holder.stops.addView(stopView); } }
From source file:pro.dbro.bart.TheActivity.java
public void displayRouteResponse(routeResponse routeResponse) { // Log.d("displayRouteResponse","Is this real?: "+routeResponse.toString()); // Previously, if the device's locale wasn't in Pacific Standard Time // Responses with all expired routes could present, causing a looping refresh cycle // This is now remedied by coercing response dates into PST boolean expiredResponse = false; if (routeResponse.routes.size() == 0) { Log.d("displayRouteResponse", "no routes to display"); expiredResponse = true;// w w w. jav a2s . com } if (timer != null) timer.cancel(); // cancel previous timer timerViews = new ArrayList(); // release old ETA text views maxTimer = 0; try { tableLayout.removeAllViews(); //Log.v("DATE",new Date().toString()); long now = new Date().getTime(); if (!expiredResponse) { fareTv.setVisibility(0); fareTv.setText("$" + routeResponse.routes.get(0).fare); for (int x = 0; x < routeResponse.routes.size(); x++) { route thisRoute = routeResponse.routes.get(x); TableRow tr = (TableRow) View.inflate(c, R.layout.tablerow, null); tr.setPadding(0, 20, 0, 0); LinearLayout legLayout = (LinearLayout) View.inflate(c, R.layout.routelinearlayout, null); for (int y = 0; y < thisRoute.legs.size(); y++) { TextView trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity // If route has multiple legs, generate "Transfer At [station name]" and "To [train name] " rows for each leg after the first if (y > 0) { trainTv.setText("transfer at " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y - 1)).disembarkStation.toLowerCase())); trainTv.setPadding(0, 0, 0, 0); legLayout.addView(trainTv); trainTv.setTextSize(14); trainTv = (TextView) View.inflate(c, R.layout.tabletext, null); trainTv.setPadding(0, 0, 0, 0); trainTv.setTextSize(20); trainTv.setGravity(3); // set left gravity trainTv.setText("to " + BART.REVERSE_STATION_MAP .get(((leg) thisRoute.legs.get(y)).trainHeadStation.toLowerCase())); } else { // For first route leg, display "Take [train name]" row trainTv.setText("take " + BART.REVERSE_STATION_MAP.get(((leg) thisRoute.legs.get(y)).trainHeadStation)); } legLayout.addView(trainTv); } if (thisRoute.legs.size() == 1) { legLayout.setPadding(0, 10, 0, 0); // Address detination train and ETA not aligning } tr.addView(legLayout); // Prepare ETA TextView TextView arrivalTimeTv = (TextView) View.inflate(c, R.layout.tabletext, null); arrivalTimeTv.setPadding(10, 0, 0, 0); //Log.v("DEPART_DATE",thisRoute.departureDate.toString()); // Don't report a train that may JUST be leaving with a negative ETA long eta; if (thisRoute.departureDate.getTime() - now <= 0) { eta = 0; } else { eta = thisRoute.departureDate.getTime() - now; } if (eta > maxTimer) { maxTimer = eta; } // Set timeTv Tag to departure date for interpretation by ViewCountDownTimer arrivalTimeTv.setTag(thisRoute.departureDate.getTime()); // Print arrival as time, not eta if greater than BART.ETA_THRESHOLD_MS if (thisRoute.departureDate.getTime() - now > BART.ETA_IN_MINUTES_THRESHOLD_MS) { SimpleDateFormat sdf = new SimpleDateFormat("h:mm a"); arrivalTimeTv.setText(sdf.format(thisRoute.departureDate)); arrivalTimeTv.setTextSize(20); } // Display ETA as minutes until arrival else { arrivalTimeTv.setTextSize(36); // Display eta less than 1m as "<1" if (eta < 60 * 1000) arrivalTimeTv.setText("<1"); // TODO - remove this? Does countdown tick on start else arrivalTimeTv.setText(String.valueOf(eta / (1000 * 60))); // TODO - remove this? Does countdown tick on start // Add the timerView to the list of views to be passed to the ViewCountDownTimer timerViews.add(arrivalTimeTv); } //new ViewCountDownTimer(arrivalTimeTv, eta, 60*1000).start(); tr.addView(arrivalTimeTv); // Set the Row View (containing train names and times) Tag to the route it represents tr.setTag(thisRoute); tableLayout.addView(tr); tr.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { Log.d("RouteViewTag", ((route) arg0.getTag()).toString()); usherRoute = (route) arg0.getTag(); TextView guidanceTv = (TextView) View.inflate(c, R.layout.tabletext, null); guidanceTv.setText(Html.fromHtml(getString(R.string.service_prompt))); guidanceTv.setTextSize(18); guidanceTv.setPadding(0, 0, 0, 0); new AlertDialog.Builder(c).setTitle("Route Guidance").setIcon(R.drawable.ic_launcher) .setView(guidanceTv).setPositiveButton(R.string.service_start_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(c, UsherService.class); //i.putExtra("departure", ((leg)usherRoute.legs.get(0)).boardStation); //Log.v("SERVICE","Starting"); if (usherServiceIsRunning()) { stopService(i); } startService(i); } }) .setNeutralButton("Cancel", null).show(); return true; // consumed the long click } }); tr.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { int index = tableLayout.indexOfChild(arg0); // index of clicked view. Expanded view will always be +1 route thisRoute = (route) arg0.getTag(); if (!thisRoute.isExpanded) { // if route not expanded thisRoute.isExpanded = true; LinearLayout routeDetail = (LinearLayout) View.inflate(c, R.layout.routedetail, null); TextView arrivalTv = (TextView) View.inflate(c, R.layout.tabletext, null); SimpleDateFormat curFormater = new SimpleDateFormat("h:mm a"); //arrivalTv.setTextColor(0xFFC9C7C8); arrivalTv.setText("arrives " + curFormater.format(thisRoute.arrivalDate)); arrivalTv.setTextSize(20); routeDetail.addView(arrivalTv); ImageView bikeIv = (ImageView) View.inflate(c, R.layout.bikeimage, null); if (!thisRoute.bikes) { bikeIv.setImageResource(R.drawable.no_bicycle); } routeDetail.addView(bikeIv); tableLayout.addView(routeDetail, index + 1); } else { thisRoute.isExpanded = false; tableLayout.removeViewAt(index + 1); } } }); } // end route iteration } // end expiredResponse check // expiredResponse == True // If a late-night routeResponse includes the next morning's routes, they will be // presented with HH:MM ETAs, instead of minutes // Else if a late-night routeResponse includes routes from earlier in the evening // We will display "This route has stopped for tonight" else { String message = "This route has stopped for tonight"; TextView specialScheduleTextView = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTextView.setText(message); specialScheduleTextView.setPadding(0, 0, 0, 0); tableLayout.addView(specialScheduleTextView); } if (routeResponse.specialSchedule != null) { ImageView specialSchedule = (ImageView) View.inflate(c, R.layout.specialschedulelayout, null); specialSchedule.setTag(routeResponse.specialSchedule); specialSchedule.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { TextView specialScheduleTv = (TextView) View.inflate(c, R.layout.tabletext, null); specialScheduleTv.setPadding(0, 0, 0, 0); specialScheduleTv.setText(Html.fromHtml(arg0.getTag().toString())); specialScheduleTv.setTextSize(16); specialScheduleTv.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(c).setTitle("Route Alerts").setIcon(R.drawable.warning) .setView(specialScheduleTv).setPositiveButton("Okay!", null).show(); } }); tableLayout.addView(specialSchedule); } // Don't set timer if response is expired if (!expiredResponse) { timer = new ViewCountDownTimer(timerViews, "route", maxTimer, 30 * 1000); timer.start(); } } catch (Throwable t) { Log.d("displayRouteResponseError", t.getStackTrace().toString()); } }