List of usage examples for android.widget RatingBar setRating
public void setRating(float rating)
From source file:se.chalmers.watchme.ui.MovieListFragment.java
/** * Set up adapter and set adapter.// w w w .jav a2 s. c o m */ private void setUpAdapter() { // Bind columns from the table Movies to items in the rows. String[] from = new String[] { MoviesTable.COLUMN_TITLE, MoviesTable.COLUMN_RATING, MoviesTable.COLUMN_DATE, MoviesTable.COLUMN_POSTER_SMALL }; int[] to = new int[] { R.id.title, R.id.raiting, R.id.date, R.id.poster }; getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this); setAdapter(new SimpleCursorAdapter(getActivity(), R.layout.list_item_movie, null, from, to, 0)); /** * Manipulate the shown date in list */ getAdapter().setViewBinder(new ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == cursor.getColumnIndexOrThrow(MoviesTable.COLUMN_DATE)) { String dateString = cursor.getString(columnIndex); TextView textView = (TextView) view; Calendar date = Calendar.getInstance(); date.setTimeInMillis(Long.parseLong(dateString)); /* * If the movie's release date is within a given threshold (fetched * from resource file), change the text color of the field. */ int threshold = Integer.parseInt(getString(R.string.days_threshold)); if (DateTimeUtils.isDateInInterval(date, threshold, TimeUnit.DAYS)) { String color = getString(R.string.color_threshold); textView.setTextColor(Color.parseColor(color)); } /* * Set to original color if not in threshold */ else { textView.setTextColor(R.string.list_date_color); } // Format the date to relative form ("two days left") String formattedDate = DateTimeUtils.toHumanDate(date); textView.setText(formattedDate); return true; } /* * Handle rating bar conversion */ else if (columnIndex == cursor.getColumnIndexOrThrow(MoviesTable.COLUMN_RATING)) { int rating = cursor.getInt(columnIndex); RatingBar bar = (RatingBar) view; bar.setRating(rating); return true; } /* * Handle poster images */ else if (columnIndex == cursor.getColumnIndexOrThrow(MoviesTable.COLUMN_POSTER_SMALL)) { String smallImageUrl = cursor.getString(columnIndex); final ImageView imageView = (ImageView) view; if (smallImageUrl != null && !smallImageUrl.isEmpty()) { // Fetch the image in an async task imageTask = new ImageDownloadTask(new ImageDownloadTask.TaskActions() { // When task is finished, set the resulting // image on the poster view public void onFinished(Bitmap image) { if (image != null) { ((ImageView) imageView).setImageBitmap(image); } } }); imageTask.execute(new String[] { smallImageUrl }); } return true; } return false; } }); }
From source file:com.smsc.usuario.ui.MapaActivity.java
public void getDetalle(int posicion) { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(false);//from w ww . j a va2 s . c om dialog.setContentView(R.layout.dialog_incidente); TextView lblAsunto = (TextView) dialog.findViewById(R.id.lblAsunto); lblAsunto.setText(lista.get(posicion).getStr_detalle()); TextView lblNombreInciente = (TextView) dialog.findViewById(R.id.lblNombreInciente); lblNombreInciente.setText(lista.get(posicion).getStr_tipo_incidente_nombre()); TextView lblEstado = (TextView) dialog.findViewById(R.id.lblEstado); lblEstado.setText("Enviado"); if (lista.get(posicion).getInt_estado() == 1) lblEstado.setText("En Progreso"); else if (lista.get(posicion).getInt_estado() == 2) lblEstado.setText("Valido"); else if (lista.get(posicion).getInt_estado() == 3) lblEstado.setText("Invalido"); SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat hora = new SimpleDateFormat("h:mm a"); TextView lblFecha = (TextView) dialog.findViewById(R.id.lblFecha); lblFecha.setText(fecha.format(lista.get(posicion).getDat_fecha_registro())); TextView lblHora = (TextView) dialog.findViewById(R.id.lblHora); lblHora.setText(hora.format(lista.get(posicion).getDat_fecha_registro())); View ViewFoto = (View) dialog.findViewById(R.id.ViewFoto); if (lista.get(posicion).getByte_foto() == null) { ViewFoto.setVisibility(View.GONE); } else { ImageView image = (ImageView) dialog.findViewById(R.id.image); image.setImageBitmap(Funciones.getBitmap(lista.get(posicion).getByte_foto())); } View ViewCalificacion = (View) dialog.findViewById(R.id.ViewCalificacion); if (lista.get(posicion).getInt_rapides() == 0 && lista.get(posicion).getInt_conformidad() == 0) { ViewCalificacion.setVisibility(View.GONE); } else { RatingBar ratingRapides = (RatingBar) dialog.findViewById(R.id.ratingRapides); ratingRapides.setRating(lista.get(posicion).getInt_rapides()); RatingBar ratingConformidad = (RatingBar) dialog.findViewById(R.id.ratingConformidad); ratingConformidad.setRating(lista.get(posicion).getInt_conformidad()); } Button btnAceptar = (Button) dialog.findViewById(R.id.btnAceptar); btnAceptar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); }
From source file:com.physphil.android.restaurantroulette.ui.RestaurantListAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { final Restaurant restaurant = mRestaurants.get(position); if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.row_restaurant_list, parent, false); }/*w w w. jav a 2 s .c om*/ TextView tvName = (TextView) convertView.findViewById(R.id.restaurant_name); TextView tvGenre = (TextView) convertView.findViewById(R.id.restaurant_genre); RatingBar rbRating = (RatingBar) convertView.findViewById(R.id.restaurant_rating); ImageButton btnDelete = (ImageButton) convertView.findViewById(R.id.restaurant_delete_button); Typeface defaultFont = Typeface.createFromAsset(mContext.getAssets(), Constants.FONT_DEFAULT); tvName.setText(restaurant.getName()); tvName.setTypeface(defaultFont); tvGenre.setText(restaurant.getGenre()); tvGenre.setTypeface(defaultFont); rbRating.setRating(restaurant.getUserRating()); btnDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // new AlertDialog.Builder(mContext) new CustomFontDialogBuilder(mContext).setTitle(R.string.dialog_delete_restaurant_title) .setMessage(R.string.dialog_delete_restaurant_message) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Send broadcast to hosting fragment to delete restaurant from database Intent i = new Intent(RestaurantFragment.ACTION_DELETE_RESTAURANT); i.putExtra(RestaurantFragment.EXTRA_RESTAURANT_ID, restaurant.getRestaurantId()); LocalBroadcastManager.getInstance(mContext).sendBroadcast(i); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }).show(); } }); return convertView; }
From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java
/** * Sets the rating (the number of stars filled) of a RatingBar. * // w w w . jav a2 s . c om * @param viewId * The view id. * @param rating * The rating. * @return The BaseAdapterHelper for chaining. */ public BaseAdapterHelper setRating(int viewId, float rating) { RatingBar view = retrieveView(viewId); view.setRating(rating); return this; }
From source file:com.fibrobook.viewpager.custom.CardFragment.java
public void symphtomsView(LinearLayout l) { LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP); ListView symphtomList = new ListView(getActivity()); symphtomList.setLayoutParams(params); ArrayAdapter<Disease> adapter = new ArrayAdapter<Disease>(getActivity(), android.R.layout.simple_list_item_1, symphtoms); symphtomList.setAdapter(adapter);//w w w .j av a2s. com symphtomList.setClickable(true); symphtomList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { ratingDialog = new Dialog(getActivity(), com.fibrobook.R.style.FullHeightDialog); ratingDialog.setContentView(com.fibrobook.R.layout.rating_dialog); ratingDialog.setCancelable(true); RatingBar ratingBar = (RatingBar) ratingDialog.findViewById(com.fibrobook.R.id.dialog_ratingbar); int i = 0; boolean exists = false; while (i < ds.size()) { if (symphtoms.get(position).getId() == ds.get(i).getDisease().getId()) { ads = ds.get(i); ratingBar.setRating(ads.getIntensity()); exists = true; break; } i++; } if (!exists) ads = new SymphtomSummary(MainActivity.user, symphtoms.get(position), MainActivity.date); Button updateButton = (Button) ratingDialog.findViewById(com.fibrobook.R.id.rank_dialog_button); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RatingBar ratingBar = (RatingBar) ratingDialog .findViewById(com.fibrobook.R.id.dialog_ratingbar); ads.setIntensity(ratingBar.getRating()); SymphtomSummaryDAO dao = new SymphtomSummaryDAO(getActivity()); dao.save(ads); ds = dao.getSymphtomSummary(MainActivity.date); dao.close(); ratingDialog.dismiss(); } }); ratingDialog.show(); } }); l.addView(symphtomList); }
From source file:com.fibrobook.viewpager.custom.CardFragment.java
public void dayView(LinearLayout l) { LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP); ListView eventList = new ListView(getActivity()); eventList.setLayoutParams(params);/* w w w. jav a2 s. c o m*/ ArrayAdapter<DailyEvent> adapter = new ArrayAdapter<DailyEvent>(getActivity(), android.R.layout.simple_list_item_1, dailyEvents); eventList.setAdapter(adapter); eventList.setClickable(true); eventList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { ratingDialog = new Dialog(getActivity(), com.fibrobook.R.style.FullHeightDialog); ratingDialog.setContentView(com.fibrobook.R.layout.rating_dialog); ratingDialog.setCancelable(true); RatingBar ratingBar = (RatingBar) ratingDialog.findViewById(com.fibrobook.R.id.dialog_ratingbar); int i = 0; boolean exists = false; while (i < des.size()) { if (dailyEvents.get(position).getId() == des.get(i).getDailyEvent().getId()) { aes = des.get(i); ratingBar.setRating(aes.getIntensity()); exists = true; break; } i++; } if (!exists) aes = new DailyEventSummary(MainActivity.user, dailyEvents.get(position), MainActivity.date); Button updateButton = (Button) ratingDialog.findViewById(com.fibrobook.R.id.rank_dialog_button); updateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { RatingBar ratingBar = (RatingBar) ratingDialog .findViewById(com.fibrobook.R.id.dialog_ratingbar); aes.setIntensity(ratingBar.getRating()); DailyEventSummaryDAO dao = new DailyEventSummaryDAO(getActivity()); dao.save(aes); des = dao.getDailySummary(MainActivity.date); dao.close(); ratingDialog.dismiss(); } }); ratingDialog.show(); } }); l.addView(eventList); }
From source file:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java
/** * Sets the rating (the number of stars filled) and max of a RatingBar. * /* w w w . ja v a2 s. com*/ * @param viewId * The view id. * @param rating * The rating. * @param max * The range of the RatingBar to 0...max. * @return The BaseAdapterHelper for chaining. */ public BaseAdapterHelper setRating(int viewId, float rating, int max) { RatingBar view = retrieveView(viewId); view.setMax(max); view.setRating(rating); return this; }
From source file:rocks.ecox.flickster.MovieDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_movie_detail); Intent intent = this.getIntent(); // Change the ActionBar title getSupportActionBar().setTitle(R.string.title_movie_details); // Populate the ImageView and TextViews from the parcelable TextView title = (TextView) findViewById(R.id.tvTitle); ImageView poster = (ImageView) findViewById(R.id.ivPoster); Drawable placeholder = (Drawable) ContextCompat.getDrawable(this, R.drawable.poster_placeholder_backdrop); TextView releaseDate = (TextView) findViewById(R.id.tvReleaseDate); RatingBar rating = (RatingBar) findViewById(R.id.rbRating); TextView overview = (TextView) findViewById(R.id.tvOverviewDetail); getWindow().getDecorView().setBackgroundColor(Color.BLACK); if (intent != null && intent.hasExtra("movie")) { Movie movie = intent.getExtras().getParcelable("movie"); Picasso.with(getApplicationContext()).load(movie.getBackdropPath()).error(placeholder) .placeholder(placeholder).into(poster); title.setText(movie.getOriginalTitle()); releaseDate.setText(movie.getReleaseDate()); rating.setRating(movie.getRating().intValue()); overview.setText(movie.getOverview()); }//ww w. j a v a 2s . c o m }
From source file:edgargtzg.popularmovies.MovieDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_movie_details, container, false); if (mMovieItem != null) { String value;/*from ww w . jav a2 s . com*/ // Populates movie original title text view value. value = mMovieItem.getOriginalTitle(); if (!(value.isEmpty())) { TextView originalTitleTextView = (TextView) rootView.findViewById(R.id.movie_title_textView); originalTitleTextView.setText(value); } // Populates movie poster image. value = mMovieItem.getMoviePoster(); if (!(value.isEmpty())) { ImageView moviePosterImageView = (ImageView) rootView.findViewById(R.id.movie_poster_imageView); Picasso.with(getActivity()) .load(rootView.getResources().getString(R.string.details_poster_api_call) + value) .into(moviePosterImageView); } // Populates movie plot synopsis. value = mMovieItem.getPlotSynopsis(); if (!(value.isEmpty())) { TextView moviePlotTextView = (TextView) rootView.findViewById(R.id.movie_plot_textView); moviePlotTextView.setText(value); } // Populates movie user rating. value = mMovieItem.getUserRating(); if (!(value.isEmpty())) { RatingBar movieRateBar = (RatingBar) rootView.findViewById(R.id.movie_ratingBar); movieRateBar.setRating((Float.parseFloat(value) / 2)); } // Populates movie release date value. value = mMovieItem.getReleaseDate(); if (!(value.isEmpty())) { TextView movieReleaseTextView = (TextView) rootView.findViewById(R.id.movie_release_textView); movieReleaseTextView.setText(value); } ListView videoListView = (ListView) rootView.findViewById(R.id.movie_details_videos_listview); videoListView.setAdapter(mMovieVideoAdapter); // Adds play trailer using Youtube app or web browser. videoListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { MovieItemVideo videoItem = mMovieVideoAdapter.getItem(position); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + videoItem.getVideoKey())); startActivity(intent); } }); ListView reviewListView = (ListView) rootView.findViewById(R.id.movie_details_reviews_listview); reviewListView.setAdapter(mMovieReviewAdapter); reviewListView.setEnabled(false); } return rootView; }
From source file:se.chalmers.watchme.activity.MovieDetailsActivity.java
/** * Populate various view fields with data from a Movie. * //from w w w. j a v a 2s .c om * @param m The movie to fill the fields with */ public void populateFieldsFromMovie(Movie m) { setTitle(m.getTitle()); RatingBar ratingBar = (RatingBar) findViewById(R.id.my_rating_bar); TextView releaseDateLabel = (TextView) findViewById(R.id.releaseDate); this.noteField.setText(m.getNote()); ratingBar.setRating(m.getRating()); releaseDateLabel.setText(DateTimeUtils.toSimpleDate(m.getDate())); String tags = MovieHelper.getCursorString(db.getAttachedTags(m)); if (tags != null && !tags.isEmpty()) { tagField.setText(tags); } this.tagField.setText(tags.toString()); }