Example usage for android.widget RatingBar setMax

List of usage examples for android.widget RatingBar setMax

Introduction

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

Prototype

@Override
    public synchronized void setMax(int max) 

Source Link

Usage

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

@NonNull
@Override/*from   w ww. j  a  v a 2 s .c o  m*/
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/*from  w  w w  . jav a2 s . c o  m*/
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  w w . j a  va 2s  .  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(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:com.cicada.yuanxiaobao.common.BaseAdapterHelper.java

/**
 * Sets the rating (the number of stars filled) and max of a RatingBar.
 * //from  w  ww  . jav  a 2 s. c o m
 * @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:com.aware.ui.ESM_UI.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    //      getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE);
    //      getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    //        getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    builder = new AlertDialog.Builder(getActivity());
    inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);

    TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0
            ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG)
            : TAG;/*  w  ww  .j  a va 2s. c o m*/

    Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null,
            ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1");
    if (visible_esm != null && visible_esm.moveToFirst()) {
        esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID));

        //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation
        ContentValues update_state = new ContentValues();
        update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE);
        getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state,
                ESM_Data._ID + "=" + esm_id, null);

        esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE));
        expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD));

        builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE)));

        View ui = null;
        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            ui = inflater.inflate(R.layout.esm_text, null);
            break;
        case ESM.TYPE_ESM_RADIO:
            ui = inflater.inflate(R.layout.esm_radio, null);
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            ui = inflater.inflate(R.layout.esm_checkbox, null);
            break;
        case ESM.TYPE_ESM_LIKERT:
            ui = inflater.inflate(R.layout.esm_likert, null);
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            ui = inflater.inflate(R.layout.esm_quick, null);
            break;
        }

        final View layout = ui;
        builder.setView(layout);
        current_dialog = builder.create();
        sContext = current_dialog.getContext();

        TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions);
        esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS)));

        switch (esm_type) {
        case ESM.TYPE_ESM_TEXT:
            final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback);
            Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel);
            cancel_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);
                    current_dialog.cancel();
                }
            });
            Button submit_text = (Button) layout.findViewById(R.id.esm_submit);
            submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0);

                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, feedback.getText().toString());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_RADIO:
            try {
                final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                final JSONArray radios = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS)));

                for (int i = 0; i < radios.length(); i++) {
                    final RadioButton radioOption = new RadioButton(getActivity());
                    radioOption.setId(i);
                    radioOption.setText(radios.getString(i));
                    radioOptions.addView(radioOption);

                    if (radios.getString(i).equals("Other")) {
                        radioOption.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                final Dialog editOther = new Dialog(getActivity());
                                editOther.setTitle("Can you be more specific, please?");
                                editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                editOther.getWindow().setGravity(Gravity.TOP);
                                editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                        LayoutParams.WRAP_CONTENT);

                                LinearLayout editor = new LinearLayout(getActivity());
                                editor.setOrientation(LinearLayout.VERTICAL);

                                editOther.setContentView(editor);
                                editOther.show();

                                final EditText otherText = new EditText(getActivity());
                                editor.addView(otherText);

                                Button confirm = new Button(getActivity());
                                confirm.setText("OK");
                                confirm.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if (otherText.length() > 0)
                                            radioOption.setText(otherText.getText());
                                        inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0);
                                        editOther.dismiss();
                                    }
                                });
                                editor.addView(confirm);
                            }
                        });
                    }
                }
                Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_radio = (Button) layout.findViewById(R.id.esm_submit);
                submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_radio.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio);
                        if (radioOptions.getCheckedRadioButtonId() != -1) {
                            RadioButton selected = (RadioButton) radioOptions
                                    .getChildAt(radioOptions.getCheckedRadioButtonId());
                            rowData.put(ESM_Data.ANSWER, selected.getText().toString());
                        }
                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_CHECKBOX:
            try {
                final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes);
                final JSONArray checks = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES)));

                for (int i = 0; i < checks.length(); i++) {
                    final CheckBox checked = new CheckBox(getActivity());
                    checked.setText(checks.getString(i));
                    checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                        @Override
                        public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) {
                            if (isChecked) {
                                if (buttonView.getText().equals("Other")) {
                                    checked.setOnClickListener(new View.OnClickListener() {
                                        @Override
                                        public void onClick(View v) {
                                            final Dialog editOther = new Dialog(getActivity());
                                            editOther.setTitle("Can you be more specific, please?");
                                            editOther.getWindow()
                                                    .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                                            editOther.getWindow().setGravity(Gravity.TOP);
                                            editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT,
                                                    LayoutParams.WRAP_CONTENT);

                                            LinearLayout editor = new LinearLayout(getActivity());
                                            editor.setOrientation(LinearLayout.VERTICAL);
                                            editOther.setContentView(editor);
                                            editOther.show();

                                            final EditText otherText = new EditText(getActivity());
                                            editor.addView(otherText);

                                            Button confirm = new Button(getActivity());
                                            confirm.setText("OK");
                                            confirm.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View v) {
                                                    if (otherText.length() > 0) {
                                                        inputManager.hideSoftInputFromWindow(
                                                                otherText.getWindowToken(), 0);
                                                        selected_options
                                                                .remove(buttonView.getText().toString());
                                                        checked.setText(otherText.getText());
                                                        selected_options.add(otherText.getText().toString());
                                                    }
                                                    editOther.dismiss();
                                                }
                                            });
                                            editor.addView(confirm);
                                        }
                                    });
                                } else {
                                    selected_options.add(buttonView.getText().toString());
                                }
                            } else {
                                selected_options.remove(buttonView.getText().toString());
                            }
                        }
                    });
                    checkboxes.addView(checked);
                }
                Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel);
                cancel_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        current_dialog.cancel();
                    }
                });
                Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit);
                submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
                submit_checkbox.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        if (expires_seconds > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);

                        ContentValues rowData = new ContentValues();
                        rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());

                        if (selected_options.size() > 0) {
                            rowData.put(ESM_Data.ANSWER, selected_options.toString());
                        }

                        rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                        sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                ESM_Data._ID + "=" + esm_id, null);

                        Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                        getActivity().sendBroadcast(answer);

                        if (Aware.DEBUG)
                            Log.d(TAG, "Answer:" + rowData.toString());

                        current_dialog.dismiss();
                    }
                });
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        case ESM.TYPE_ESM_LIKERT:
            final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert);
            ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));
            ratingBar.setStepSize(
                    (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP)));
            ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX)));

            TextView min_label = (TextView) layout.findViewById(R.id.esm_min);
            min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL)));

            TextView max_label = (TextView) layout.findViewById(R.id.esm_max);
            max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL)));

            Button cancel = (Button) layout.findViewById(R.id.esm_cancel);
            cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    current_dialog.cancel();
                }
            });
            Button submit = (Button) layout.findViewById(R.id.esm_submit);
            submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT)));
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (expires_seconds > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);

                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Data.ANSWER, ratingBar.getRating());
                    rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);

                    sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                            ESM_Data._ID + "=" + esm_id, null);

                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    getActivity().sendBroadcast(answer);

                    if (Aware.DEBUG)
                        Log.d(TAG, "Answer:" + rowData.toString());

                    current_dialog.dismiss();
                }
            });
            break;
        case ESM.TYPE_ESM_QUICK_ANSWERS:
            try {
                final JSONArray answers = new JSONArray(
                        visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS)));
                final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers);

                //If we have more than 3 possibilities, better that the UI is vertical for UX
                if (answers.length() > 3) {
                    answersHolder.setOrientation(LinearLayout.VERTICAL);
                }

                for (int i = 0; i < answers.length(); i++) {
                    final Button answer = new Button(getActivity());
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                            LayoutParams.WRAP_CONTENT, 1.0f);
                    answer.setLayoutParams(params);
                    answer.setText(answers.getString(i));
                    answer.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            if (expires_seconds > 0 && expire_monitor != null)
                                expire_monitor.cancel(true);

                            ContentValues rowData = new ContentValues();
                            rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                            rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                            rowData.put(ESM_Data.ANSWER, (String) answer.getText());

                            sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData,
                                    ESM_Data._ID + "=" + esm_id, null);

                            Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                            getActivity().sendBroadcast(answer);

                            if (Aware.DEBUG)
                                Log.d(TAG, "Answer:" + rowData.toString());

                            current_dialog.dismiss();
                        }
                    });
                    answersHolder.addView(answer);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            break;
        }
    }
    if (visible_esm != null && !visible_esm.isClosed())
        visible_esm.close();

    //Start dialog visibility threshold
    if (expires_seconds > 0) {
        expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id);
        expire_monitor.execute();
    }

    //Fixed: doesn't dismiss the dialog if touched outside or ghost touches
    current_dialog.setCanceledOnTouchOutside(false);

    return current_dialog;
}