Example usage for android.widget RatingBar setRating

List of usage examples for android.widget RatingBar setRating

Introduction

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

Prototype

public void setRating(float rating) 

Source Link

Document

Sets the rating (the number of stars filled).

Usage

From source file:Main.java

public static void setRaiting(Activity r, final RatingBar v, final String value) {
    r.runOnUiThread(new Runnable() {
        @Override// w w  w  .  j  a  v a2 s  .c o m
        public void run() {
            try {
                v.setRating(new Float(value));
            } catch (Exception e) {
            }
        }
    });
}

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);
    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override/*from   w w  w . ja va2 s  .com*/
        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.test.shopping.view.ProductDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /*/*from  w  w  w .j a  v  a 2s  . c o  m*/
     * Inflate the layout based on the current product details.
     * Fetch the product associated with the current position in product id list
     */
    ProductDataModel product = CacheUtil.getInstance(getActivity()).getProduct(mPosition);

    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.product_detail, container, false);

    TextView productName = (TextView) rootView.findViewById(R.id.product_name);
    productName.setText(StringEscapeUtils.unescapeJava(product.getProductName()));

    String longDes = product.getLongDescription();
    TextView longDescLabel = (TextView) rootView.findViewById(R.id.long_description_label);
    TextView longDesc = (TextView) rootView.findViewById(R.id.long_description);
    if (longDes != null && longDes.length() > 0) {
        longDesc.setText(Jsoup.clean(longDes, Whitelist.simpleText()));
        longDesc.setVisibility(View.VISIBLE);
        longDescLabel.setVisibility(View.VISIBLE);
    } else {
        longDesc.setVisibility(View.INVISIBLE);
        longDescLabel.setVisibility(View.INVISIBLE);
    }

    TextView price = (TextView) rootView.findViewById(R.id.price);
    price.setText(product.getPrice());

    ImageView imageView = (ImageView) rootView.findViewById(R.id.image);
    ImageLoader loader = ConnectionUtil.getInstance(sContext).getImageLoader();
    loader.get(product.getProductImage(),
            ImageLoader.getImageListener(imageView, R.mipmap.ic_launcher, R.mipmap.ic_launcher));

    TextView ratingCountView = (TextView) rootView.findViewById(R.id.rating_count);

    ratingCountView.setText("(" + String.valueOf(product.getReviewCount() + ")"));

    RatingBar bar = (RatingBar) rootView.findViewById(R.id.ratingBar);

    bar.setRating((int) product.getReviewRating());
    bar.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    TextView inStock = (TextView) rootView.findViewById(R.id.inStock);
    if (product.isInStock()) {
        inStock.setTextColor(getResources().getColor(android.R.color.holo_green_dark));
        inStock.setText(R.string.in_stock_label);
    } else {
        inStock.setTextColor(getResources().getColor(android.R.color.holo_red_dark));
        inStock.setText(R.string.out_of_stock_label);
    }

    return rootView;
}

From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java

private void initView() {
    ratingBar = (RatingBar) findViewById(R.id.ratingBar1);
    btnSubmit = (Button) findViewById(R.id.submit);
    etContent = (EditText) findViewById(R.id.edittext);
    btnSubmit.setOnClickListener(new MyClickListener());
    ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

        @Override/*from   w  ww  .ja va  2s . com*/
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            if (rating < 1.0f) {
                ratingBar.setRating(1.0f);
            }
        }
    });
}

From source file:org.smilec.smile.ui.fragment.StudentsFragment.java

private void setTopScorersArea(Results results, Board board) {
    try {//from w  w  w . j av  a  2s .  com
        TextView tvTopScorersTop = (TextView) getActivity().findViewById(R.id.tv_top_scorers_top);

        String sBestScoredStudentNames = results.getBestScoredStudentNames();
        JSONArray bestScoredStudentNames = new JSONArray(
                sBestScoredStudentNames == null ? "" : sBestScoredStudentNames);
        tvTopScorersTop.setText(
                getString(R.string.top_scorer) + ": " + bestScoredStudentNames.join(", ").replaceAll("\"", ""));

        TextView tvTopScorersRating = (TextView) getActivity().findViewById(R.id.tv_top_scorers_rating);
        tvTopScorersRating.setText(getString(R.string.rating) + ": " + results.getWinnerRating());

        final RatingBar rbRatingBar = (RatingBar) getActivity().findViewById(R.id.rb_ratingbar);
        rbRatingBar.setRating(results.getWinnerRating());
    } catch (JSONException e) {
        Log.e("StudentsFragment", "Error: " + e);
    }
}

From source file:com.gammalabs.wifianalyzer.wifi.ChannelRatingAdapter.java

@NonNull
@Override//from ww w. jav a2  s  .com
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(R.layout.channel_rating_details, parent, false);
    }

    WiFiChannel wiFiChannel = getItem(position);
    if (wiFiChannel == null) {
        return view;
    }

    ((TextView) view.findViewById(R.id.channelNumber))
            .setText(String.format(Locale.ENGLISH, "%d", wiFiChannel.getChannel()));
    ((TextView) view.findViewById(R.id.accessPointCount))
            .setText(String.format(Locale.ENGLISH, "%d", channelRating.getCount(wiFiChannel)));
    Strength strength = Strength.reverse(channelRating.getStrength(wiFiChannel));
    RatingBar ratingBar = (RatingBar) view.findViewById(R.id.channelRating);
    int size = Strength.values().length;
    ratingBar.setMax(size);
    ratingBar.setNumStars(size);
    ratingBar.setRating(strength.ordinal() + 1);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ratingBar.getProgressDrawable().setColorFilter(
                ContextCompat.getColor(getContext(), R.color.success_color), PorterDuff.Mode.SRC_ATOP);
    } else {
        ratingBar.setProgressTintList(
                ColorStateList.valueOf(ContextCompat.getColor(getContext(), strength.colorResource())));
    }

    return view;
}

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

@NonNull
@Override/* w ww  .  j a  v  a  2 s  . com*/
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(R.layout.channel_rating_details, parent, false);
    }

    WiFiChannel wiFiChannel = getItem(position);
    if (wiFiChannel == null) {
        return view;
    }

    ((TextView) view.findViewById(R.id.channelNumber))
            .setText(String.format(Locale.ENGLISH, "%d", wiFiChannel.getChannel()));
    ((TextView) view.findViewById(R.id.accessPointCount))
            .setText(String.format(Locale.ENGLISH, "%d", channelRating.getCount(wiFiChannel)));
    Strength strength = Strength.reverse(channelRating.getStrength(wiFiChannel));
    RatingBar ratingBar = (RatingBar) view.findViewById(R.id.channelRating);
    int size = Strength.values().length;
    ratingBar.setMax(size);
    ratingBar.setNumStars(size);
    ratingBar.setRating(strength.ordinal() + 1);
    int color = ContextCompat.getColor(getContext(), strength.colorResource());
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        setRatingBarColor(ratingBar.getProgressDrawable(), color);
    } else {
        ratingBar.setProgressTintList(ColorStateList.valueOf(color));
    }

    return view;
}

From source file:kr.co.generic.wifianalyzer.wifi.ChannelRatingAdapter.java

@NonNull
@Override//w  ww .j  a  va2  s .c  om
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater layoutInflater = MainContext.INSTANCE.getMainActivity().getLayoutInflater();
        view = layoutInflater.inflate(kr.co.generic.wifianalyzer.R.layout.channel_rating_details, parent,
                false);
    }

    WiFiChannel wiFiChannel = getItem(position);
    if (wiFiChannel == null) {
        return view;
    }

    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.channelNumber))
            .setText(String.format(Locale.ENGLISH, "%d", wiFiChannel.getChannel()));
    ((TextView) view.findViewById(kr.co.generic.wifianalyzer.R.id.accessPointCount))
            .setText(String.format(Locale.ENGLISH, "%d", channelRating.getCount(wiFiChannel)));
    Strength strength = Strength.reverse(channelRating.getStrength(wiFiChannel));
    RatingBar ratingBar = (RatingBar) view.findViewById(kr.co.generic.wifianalyzer.R.id.channelRating);
    int size = Strength.values().length;
    ratingBar.setMax(size);
    ratingBar.setNumStars(size);
    ratingBar.setRating(strength.ordinal() + 1);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ratingBar.getProgressDrawable().setColorFilter(
                ContextCompat.getColor(getContext(), kr.co.generic.wifianalyzer.R.color.success_color),
                PorterDuff.Mode.SRC_ATOP);
    } else {
        ratingBar.setProgressTintList(
                ColorStateList.valueOf(ContextCompat.getColor(getContext(), strength.colorResource())));
    }

    return view;
}

From source file:eu.iescities.pilot.rovereto.roveretoexplorer.custom.CommentsHandler.java

private void updateRating() {
    if (main != null) {
        RatingBar rating = (RatingBar) main.findViewById(R.id.rating);
        if (object.getCommunityData() != null) {
            CommunityData cd = object.getCommunityData();
            rating.setRating(cd.getAverageRating());

            // total raters
            ((TextView) main.findViewById(R.id.rating_raters))
                    .setText(activity.getString(R.string.ratingtext_raters, "" + cd.getRatingsCount()));
        }//w w w  .java2s.c  o  m
    }

}

From source file:com.autoparts.sellers.activity.SellerUserInfoActivity.java

private void setViewData() {
    //        "id":"",
    //                "nam":"??",
    //                "adr":"??",
    //                "ton":"?"
    //        "lat":"",
    //                "lp1":"??16?",
    //                "lp2":"??16?",
    //                "pic":"16?",
    //                "license":"?16?",
    //                "agent":"?16?"

    tel.setText(preferences.getLoginPhone());
    String adr = preferences.getStringData("adr");
    String nam = preferences.getStringData("nam");
    if (!TextUtils.isEmpty(adr)) {
        address.setText(adr);// ww  w .jav  a2 s. c  o  m
    }

    if (!TextUtils.isEmpty(nam)) {
        user_title.setText(nam);
    }
    String pic = preferences.getStringData("pic");
    if (!TextUtils.isEmpty(pic)) {
        ImageLoaderBitmapUtil.getInstance(context).showBitmap(pic, photos.get(3));
    }

    String license = preferences.getStringData("license");
    if (!TextUtils.isEmpty(license)) {
        ImageLoaderBitmapUtil.getInstance(context).showBitmap(license, photos.get(0));
    }
    String lp1 = preferences.getStringData("lp1");
    if (!TextUtils.isEmpty(lp1)) {
        ImageLoaderBitmapUtil.getInstance(context).showBitmap(lp1, photos.get(1));
    }
    String agent = preferences.getStringData("agent");
    if (!TextUtils.isEmpty(agent)) {
        ImageLoaderBitmapUtil.getInstance(context).showBitmap(agent, photos.get(2));
    }
    String lp2 = preferences.getStringData("lp2");
    if (!TextUtils.isEmpty(lp2)) {
        ImageLoaderBitmapUtil.getInstance(context).showBitmap(lp2, photos.get(4));
    }

    String sell_level = (String) preferences.getStringData("sell_level");//
    int level = CommonData.getInstance(context).getIntData(sell_level);
    if (level > 15) {
        level = 15;
    }
    company_level_image.setImageResource(CommonData.images[level - 1]);

    String sell_score = preferences.getStringData("sell_score");
    String[] scores = JsonParserUtils.jsonParseStringArray(sell_score);
    if (scores != null && scores.length > 0) {
        for (int i = 0; i < scores.length; i++) {
            float score = Float.parseFloat(scores[i]);
            RatingBar ratingBar = ratingBars.get(i);
            ratingBar.setRating(score);
            TextView textView = texts.get(i);
            textView.setText(score + "");
        }
    }

}