Example usage for android.widget RatingBar getRating

List of usage examples for android.widget RatingBar getRating

Introduction

In this page you can find the example usage for android.widget RatingBar getRating.

Prototype

public float getRating() 

Source Link

Document

Gets the current rating (number of stars filled).

Usage

From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java

public static String getTextOfView(View view) {
    Object textObj = null;//from   ww  w . j  a va2 s  .c om
    if (view instanceof TextView) {
        textObj = ((TextView) view).getText();

        if (view instanceof Switch) {
            boolean isOn = ((Switch) view).isChecked();
            textObj = isOn ? "1" : "0";
        }
    } else if (view instanceof Spinner) {
        Object selectedItem = ((Spinner) view).getSelectedItem();
        if (selectedItem != null) {
            textObj = selectedItem.toString();
        }
    } else if (view instanceof DatePicker) {
        DatePicker picker = (DatePicker) view;
        int y = picker.getYear();
        int m = picker.getMonth();
        int d = picker.getDayOfMonth();
        textObj = String.format("%04d-%02d-%02d", y, m, d);
    } else if (view instanceof TimePicker) {
        TimePicker picker = (TimePicker) view;
        int h = picker.getCurrentHour();
        int m = picker.getCurrentMinute();
        textObj = String.format("%02d:%02d", h, m);
    } else if (view instanceof RadioGroup) {
        RadioGroup radioGroup = (RadioGroup) view;
        int checkedId = radioGroup.getCheckedRadioButtonId();
        int childCount = radioGroup.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = radioGroup.getChildAt(i);
            if (child.getId() == checkedId && child instanceof RadioButton) {
                textObj = ((RadioButton) child).getText();
                break;
            }
        }
    } else if (view instanceof RatingBar) {
        RatingBar bar = (RatingBar) view;
        float rating = bar.getRating();
        textObj = String.valueOf(rating);
    }

    return textObj == null ? "" : textObj.toString();
}

From source file:se.chalmers.watchme.activity.AddMovieActivity.java

private void addMovie() {

    // Get the movie from the auto-complete field 
    Movie movie = (Movie) this.titleField.getTag();
    String title = this.titleField.getText().toString();

    /*/*from  w  w  w. j  a va 2 s  . c o m*/
     * If the auto-complete failed, or if the user choses
     * a movie from the dropdown and later erases the title
     * text to something custom, *without* choosing a new 
     * suggestion from the list.
     */
    if (movie == null || !movie.getTitle().equals(title)) {
        movie = new Movie(title);
    }

    movie.setNote(this.noteField.getText().toString());
    movie.setDate(releaseDate);

    /*
     * Extract the rating from the ratingBar and convert it to
     * an integer
     */
    RatingBar ratingBar = (RatingBar) findViewById(R.id.rating_bar);
    int rating = (int) ratingBar.getRating();
    movie.setRating(rating);

    // Insert into database
    try {
        db.addMovie(movie);
        // Set a notification for the date picked
        this.setNotification(movie);

        /* 
        * Split the text input into separate strings input at
        * commas (",") from tag-field
        */
        String[] tagStrings = tagField.getText().toString().split(",");

        db.attachTags(movie, MovieHelper.stringArrayToTagList(tagStrings));

        // If everything went alright, return to the movie list view
        finish();

    } catch (MovieAlreadyExistsException e) {
        // If the movie already exists, show a message
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.vrem.wifianalyzer.wifi.channelrating.ChannelRatingAdapterTest.java

@Test
public void testGetView() throws Exception {
    // setup// ww  w.j  a  v a  2  s. c  o  m
    int expectedSize = Strength.values().length;
    Strength expectedStrength = Strength.reverse(Strength.FOUR);
    WiFiChannel wiFiChannel = new WiFiChannel(1, 2);
    fixture.add(wiFiChannel);
    when(channelRating.getCount(wiFiChannel)).thenReturn(5);
    when(channelRating.getStrength(wiFiChannel)).thenReturn(Strength.FOUR);
    // execute
    View actual = fixture.getView(0, null, null);
    // validate
    assertNotNull(actual);

    assertEquals("1", ((TextView) actual.findViewById(R.id.channelNumber)).getText());
    assertEquals("5", ((TextView) actual.findViewById(R.id.accessPointCount)).getText());

    RatingBar ratingBar = (RatingBar) actual.findViewById(R.id.channelRating);
    assertEquals(expectedSize, ratingBar.getMax());
    assertEquals(expectedSize, ratingBar.getNumStars());
    assertEquals(expectedStrength.ordinal() + 1, (int) ratingBar.getRating());

    assertEquals("", bestChannels.getText());

    verify(channelRating).getCount(wiFiChannel);
    verify(channelRating).getStrength(wiFiChannel);
}

From source file:net.simonvt.cathode.ui.dialog.RatingDialog.java

@Override
public Dialog onCreateDialog(Bundle inState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    View v = LayoutInflater.from(builder.getContext()).inflate(R.layout.dialog_rating, null);
    final int rating = getArguments().getInt(ARG_RATING);
    final TextView ratingText = (TextView) v.findViewById(R.id.ratingText);
    ratingText.setText(this.ratingText[this.rating]);
    final RatingBar ratingBar = (RatingBar) v.findViewById(R.id.rating);
    ratingBar.setRating(rating);/*ww w  . j  av  a2s.c om*/
    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
            RatingDialog.this.rating = (int) v;
            ratingText.setText(RatingDialog.this.ratingText[(int) v]);
        }
    });

    builder.setView(v);
    builder.setPositiveButton(R.string.action_rate, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            switch (type) {
            case SHOW:
                showScheduler.rate(id, (int) ratingBar.getRating());
                break;

            case EPISODE:
                episodeScheduler.rate(id, (int) ratingBar.getRating());
                break;

            case MOVIE:
                movieScheduler.rate(id, (int) ratingBar.getRating());
                break;
            }
        }
    });

    return builder.create();
}

From source file:com.hacktx.android.activities.EventDetailActivity.java

private void setupCards() {
    final CardView rateEventCard = (CardView) findViewById(R.id.rateEventCard);

    View.OnClickListener feedbackOnClickListener = new View.OnClickListener() {
        @Override/*w  w w .  jav a2 s . c o  m*/
        public void onClick(View v) {
            if (!UserStateStore.getFeedbackSubmitted(EventDetailActivity.this, event.getId())) {
                final Dialog dialog = new Dialog(EventDetailActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.dialog_feedback);
                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                params.width = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(params);
                dialog.show();

                final RatingBar ratingBar = (RatingBar) dialog.findViewById(R.id.feedbackDialogRatingBar);
                dialog.findViewById(R.id.feedbackDialogCancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMetricsManager.logEvent(R.string.analytics_event_feedback_cancel, null);
                        dialog.dismiss();
                    }
                });
                dialog.findViewById(R.id.feedbackDialogSubmit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        HackTxService hackTxService = HackTxClient.getInstance().getApiService();
                        hackTxService.sendFeedback(event.getId(), (int) ratingBar.getRating(),
                                new Callback<EventFeedback>() {
                                    @Override
                                    public void success(EventFeedback feedback, Response response) {
                                        mMetricsManager.logEvent(R.string.analytics_event_feedback_submit,
                                                null);
                                        UserStateStore.setFeedbackSubmitted(EventDetailActivity.this,
                                                event.getId(), true);
                                        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
                                        dialog.dismiss();
                                        Snackbar.make(findViewById(android.R.id.content),
                                                R.string.event_feedback_submitted, Snackbar.LENGTH_SHORT)
                                                .show();
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        Log.e("EventDetailActivity",
                                                "Error when submitting feedback: " + error.getMessage());
                                        dialog.dismiss();
                                        Snackbar.make(findViewById(android.R.id.content),
                                                R.string.event_feedback_failed, Snackbar.LENGTH_SHORT).show();
                                    }
                                });
                    }
                });
            } else {
                mMetricsManager.logEvent(R.string.analytics_event_feedback_already_submitted, null);
                Snackbar.make(findViewById(android.R.id.content), R.string.event_feedback_already_submitted,
                        Snackbar.LENGTH_SHORT).show();
            }
        }
    };

    if (shouldShowFeedbackCard()) {
        findViewById(R.id.rateEventCardOk).setOnClickListener(feedbackOnClickListener);

        findViewById(R.id.rateEventCardNoThanks).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMetricsManager.logEvent(R.string.analytics_event_feedback_no_thanks, null);
                UserStateStore.setFeedbackIgnored(EventDetailActivity.this, event.getId(), true);
                rateEventCard.setVisibility(View.GONE);
            }
        });
    } else {
        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
    }

    if (!mConfigManager.getValue(ConfigParam.EVENT_FEEDBACK)) {
        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
    }
}

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);/*from  w ww .j a v a 2  s .  co m*/
    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);/*from  w  w  w. ja v a 2  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:gr.scify.newsum.ui.SearchViewActivity.java

protected void initRatingBar() {
    final TextView tx = (TextView) findViewById(R.id.textView1);

    // Set rating bar visibility
    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
    rb.setVisibility(View.VISIBLE);
    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
    rateLbl.setVisibility(View.VISIBLE);
    final Button btnSubmit = (Button) findViewById(R.id.submitRatingBtn);
    // Set rating bar reaction
    btnSubmit.setOnClickListener(new OnClickListener() {

        @Override//ww  w  .ja  va2  s.  c o m
        public void onClick(View v) {
            HttpParams params = new BasicHttpParams(); // Basic params
            HttpClient client = new DefaultHttpClient(params);
            HttpPost post = new HttpPost("http://scify.iit.demokritos.gr/NewSumWeb/rate.php");
            ArrayList<NameValuePair> alParams = new ArrayList<NameValuePair>();

            NameValuePair nvSummary = new NameValuePair() {

                @Override
                public String getValue() {
                    return tx.getText().toString();
                }

                @Override
                public String getName() {
                    return "sid";
                }
            };

            NameValuePair nvRating = new NameValuePair() {

                @Override
                public String getValue() {
                    return String.valueOf(rb.getRating());
                }

                @Override
                public String getName() {
                    return "rating";
                }
            };
            // added User ID
            NameValuePair nvUserID = new NameValuePair() {

                @Override
                public String getValue() {
                    SharedPreferences idSettings = getSharedPreferences(UID_PREFS_NAME, Context.MODE_PRIVATE);
                    String sUID = idSettings.getString("UID", "");
                    return sUID;
                }

                @Override
                public String getName() {
                    return "userID";
                }
            };
            alParams.add(nvSummary);
            alParams.add(nvRating);
            alParams.add(nvUserID);

            boolean bSuccess = false;
            try {
                post.setEntity(new UrlEncodedFormEntity(alParams, HTTP.UTF_8)); // with list of key-value pairs
                client.execute(post);
                bSuccess = true;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (bSuccess) {
                Toast.makeText(SearchViewActivity.this, R.string.thankyou_rate, Toast.LENGTH_SHORT).show();
                rb.setVisibility(View.GONE);
                rateLbl.setVisibility(View.GONE);
                btnSubmit.setVisibility(View.GONE);
            } else
                Toast.makeText(SearchViewActivity.this, R.string.fail_rate, Toast.LENGTH_SHORT).show();

        }
    });

    rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(final RatingBar ratingBar, float rating, boolean fromUser) {
            // Ignore auto setting
            if (!fromUser)
                return;
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);

        }
    });
    rb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);
        }
    });
    rb.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);
            return false;
        }
    });

}

From source file:gr.scify.newsum.ui.ViewActivity.java

private void initRatingBar() {
    final TextView tx = (TextView) findViewById(R.id.textView1);

    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
    rb.setVisibility(View.VISIBLE);
    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
    rateLbl.setVisibility(View.VISIBLE);
    final Button btnSubmit = (Button) findViewById(R.id.submitRatingBtn);
    // Set rating bar reaction
    btnSubmit.setOnClickListener(new OnClickListener() {

        @Override/*from   w  w  w.ja  v a 2  s.  c  om*/
        public void onClick(View v) {
            HttpParams params = new BasicHttpParams(); // Basic params
            HttpClient client = new DefaultHttpClient(params);
            String sURL = getApplicationContext().getResources().getString(R.string.urlRating);

            HttpPost post = new HttpPost(sURL);
            ArrayList<NameValuePair> alParams = new ArrayList<NameValuePair>();

            NameValuePair nvSummary = new NameValuePair() {

                @Override
                public String getValue() {
                    return tx.getText().toString();
                }

                @Override
                public String getName() {
                    return "summary";
                }
            };

            NameValuePair nvRating = new NameValuePair() {

                @Override
                public String getValue() {
                    return String.valueOf(rb.getRating());
                }

                @Override
                public String getName() {
                    return "rating";
                }
            };
            // added User ID
            NameValuePair nvUserID = new NameValuePair() {

                @Override
                public String getValue() {
                    SharedPreferences idSettings = getSharedPreferences(UID_PREFS_NAME, Context.MODE_PRIVATE);
                    String sUID = idSettings.getString("UID", "");
                    return sUID;
                }

                @Override
                public String getName() {
                    return "userID";
                }
            };

            alParams.add(nvSummary);
            alParams.add(nvRating);
            alParams.add(nvUserID);

            boolean bSuccess = false;
            try {
                post.setEntity(new UrlEncodedFormEntity(alParams, HTTP.UTF_8)); // with list of key-value pairs
                client.execute(post);
                bSuccess = true;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (bSuccess) {
                Toast.makeText(ViewActivity.this, R.string.thankyou_rate, Toast.LENGTH_SHORT).show();
                rb.setVisibility(View.GONE);
                rateLbl.setVisibility(View.GONE);
                btnSubmit.setVisibility(View.GONE);
            } else
                Toast.makeText(ViewActivity.this, R.string.fail_rate, Toast.LENGTH_SHORT).show();

        }
    });

    rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(final RatingBar ratingBar, float rating, boolean fromUser) {
            // Ignore auto setting
            if (!fromUser)
                return;
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);

        }
    });
    rb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);
        }
    });
    rb.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Allow submit
            btnSubmit.setVisibility(View.VISIBLE);
            return false;
        }
    });

}

From source file:github.daneren2005.dsub.fragments.SubsonicFragment.java

protected void setRating(final Entry entry, final OnRatingChange onRatingChange) {
    View layout = context.getLayoutInflater().inflate(R.layout.rating, null);
    final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.rating_bar);
    ratingBar.setRating((float) entry.getRating());

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getResources().getString(R.string.rating_title, entry.getTitle())).setView(layout)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override/*from   ww  w .  j ava2 s  .  co  m*/
                public void onClick(DialogInterface dialog, int id) {
                    int rating = (int) ratingBar.getRating();
                    setRating(entry, rating, onRatingChange);
                }
            }).setNegativeButton(R.string.common_cancel, null);

    AlertDialog dialog = builder.create();
    dialog.show();
}