Example usage for android.widget RatingBar setOnRatingBarChangeListener

List of usage examples for android.widget RatingBar setOnRatingBarChangeListener

Introduction

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

Prototype

public void setOnRatingBarChangeListener(OnRatingBarChangeListener listener) 

Source Link

Document

Sets the listener to be called when the rating changes.

Usage

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  .  jav  a  2  s.  c  o  m*/
    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:srdes.menupp.EntreeEdit.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //hide keyboard
    //   getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    //set and find views
    setContentView(R.layout.review_create);
    setTitle(R.string.review_write);/*from ww w . j  a  v  a2 s .  c o m*/
    mTitleText = (EditText) findViewById(R.id.review_title);
    mBodyText = (EditText) findViewById(R.id.review_body);
    mRatingFloat = 0;
    Button confirmButton = (Button) findViewById(R.id.confirm);

    DebugLog.LOGD("getting row id");
    mRowId = (savedInstanceState == null) ? null
            : (Long) savedInstanceState.getSerializable(EntreeDbAdapter.KEY_ROWID);
    DebugLog.LOGD("row id is " + mRowId);

    //create a rating bar
    ratingbar = (RatingBar) findViewById(R.id.ratingbar);
    ratingbar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            mRatingFloat = rating;
        }
    });
    confirmButton.setOnClickListener(new View.OnClickListener() {
        //create a review when the confirm button is pressed
        public void onClick(View view) {
            Bundle extras = getIntent().getExtras();
            String entree = null;
            if (extras != null) {
                entree = extras.getString("key_entree_name");
            } else {
                DebugLog.LOGD("null extras");
            }
            saveState(entree);
            setResult(RESULT_OK);
            finish();
        }
    });
}

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//w ww . j  a  v  a 2  s  .c  o  m
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            if (rating < 1.0f) {
                ratingBar.setRating(1.0f);
            }
        }
    });
}

From source file:com.aniruddhc.acemusic.player.NowPlayingActivity.PlaylistPagerFlippedFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_flipped, container,
            false);//  w  w w  .  j a va2s.  com
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;

    ratingBar = (RatingBar) rootView.findViewById(R.id.playlist_pager_flipped_rating_bar);
    lyricsRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.lyricsRelativeLayout);
    lyricsTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_lyrics);
    headerTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_title);
    noLyricsFoundText = (TextView) rootView.findViewById(R.id.no_embedded_lyrics_found_text);

    lyricsTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    lyricsTextView
            .setPaintFlags(lyricsTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    headerTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    headerTextView
            .setPaintFlags(headerTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    noLyricsFoundText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    noLyricsFoundText.setPaintFlags(
            noLyricsFoundText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    lyricsRelativeLayout.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View arg0) {
            //Fire a broadcast that notifies the PlaylistPager to update flip back to the album art.
            Intent intent = new Intent(broadcastMessage);
            intent.putExtra("MESSAGE", broadcastMessage);

            //Initialize the local broadcast manager.
            localBroadcastManager = LocalBroadcastManager.getInstance(mContext);
            localBroadcastManager.sendBroadcast(intent);

            return true;
        }

    });

    //Get the file path of the current song.
    String updatedSongTitle = "";
    String updatedSongArtist = "";
    String songFilePath = "";
    String songId = "";
    MediaMetadataRetriever mmdr = new MediaMetadataRetriever();
    tempCursor = mApp.getService().getCursor();
    tempCursor.moveToPosition(
            mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex()));
    if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {
        //Retrieve the info from the file's metadata.
        songFilePath = tempCursor.getString(tempCursor.getColumnIndex(null));
        mmdr.setDataSource(songFilePath);

        updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
        updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);

    } else {
        /* Check if the cursor has the SONG_FILE_PATH column. If it does, we're dealing 
         * with the SONGS table. If not, we're dealing with the PLAYLISTS table. We'll 
         * retrieve data from the appropriate columns using this info. */
        if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {
            //We're dealing with the Playlists table.
            songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_FILE_PATH));
            mmdr.setDataSource(songFilePath);

            updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
        } else {
            //We're dealing with the songs table.
            songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH));
            updatedSongTitle = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE));
            updatedSongArtist = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST));
            songId = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID));
        }

    }

    headerTextView.setText(updatedSongTitle + " - " + updatedSongArtist);
    ratingBar.setStepSize(1);
    int rating = mApp.getDBAccessHelper().getSongRating(songId);
    ratingBar.setRating(rating);

    //Get the rating value for the song.
    AudioFile audioFile = null;
    File file = null;
    try {
        audioFile = null;
        file = new File(songFilePath);
        try {
            audioFile = AudioFileIO.read(file);
        } catch (CannotReadException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (org.jaudiotagger.tag.TagException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (ReadOnlyFileException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InvalidAudioFrameException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        final AudioFile finalizedAudioFile = audioFile;
        final String finalSongFilePath = songFilePath;
        final String finalSongId = songId;
        ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                //Change the rating in the DB and the actual audio file itself.

                Log.e("DEBUG", ">>>>>RATING: " + rating);

                try {
                    Tag tag = finalizedAudioFile.getTag();
                    tag.addField(FieldKey.RATING, "" + ((int) rating));
                } catch (KeyNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FieldDataInvalidException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("DEBUG", ">>>>>>>RATING FIELD NOT FOUND");
                }

                try {
                    finalizedAudioFile.commit();
                } catch (CannotWriteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }

                mApp.getDBAccessHelper().setSongRating(finalSongId, (int) rating);

            }

        });

        //Check if the audio file has any embedded lyrics.
        String lyrics = null;
        try {
            Tag tag = audioFile.getTag();
            lyrics = tag.getFirst(FieldKey.LYRICS);

            if (lyrics == null || lyrics.isEmpty()) {
                lyricsTextView.setVisibility(View.GONE);
                noLyricsFoundText.setVisibility(View.VISIBLE);
                return rootView;
            }

            //Since the song has embedded lyrics, display them in the layout.
            lyricsTextView.setVisibility(View.VISIBLE);
            noLyricsFoundText.setVisibility(View.GONE);
            lyricsTextView.setText(lyrics);

        } catch (Exception e) {
            e.printStackTrace();
            lyricsTextView.setVisibility(View.GONE);
            noLyricsFoundText.setVisibility(View.VISIBLE);
            return rootView;
        }
    } catch (Exception e) {
        e.printStackTrace();
        //Can't do much here.
    }

    return rootView;
}

From source file:reportsas.com.formulapp.Formulario.java

public LinearLayout obtenerLayout(LayoutInflater infla, Pregunta preg) {
    int id;/*from  w ww .  jav a 2s.com*/
    int tipo_pregunta = preg.getTipoPregunta();
    LinearLayout pregunta;
    TextView textView;
    TextView textAyuda;
    switch (tipo_pregunta) {
    case 1:
        id = R.layout.pregunta_texto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloPregunta);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    case 2:
        id = R.layout.pregunta_multitexto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.mtxtTritulo);
        textAyuda = (TextView) pregunta.findViewById(R.id.mtxtAyuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 3:
        id = R.layout.pregunta_seleccion;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloSeleccion);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_seleccion);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        RadioGroup rg = (RadioGroup) pregunta.findViewById(R.id.opcionesUnica);
        ArrayList<OpcionForm> opciones = preg.getOpciones();
        final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();

        for (int i = 0; i < opciones.size(); i++) {
            OpcionForm opcion = opciones.get(i);
            rb.add(new RadioButton(this));
            rg.addView(rb.get(i));
            rb.get(i).setText(opcion.getEtInicial());

        }
        final TextView respt = (TextView) pregunta.findViewById(R.id.respuestaGruop);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int radioButtonID = group.getCheckedRadioButtonId();
                RadioButton radioButton = (RadioButton) group.findViewById(radioButtonID);
                respt.setText(radioButton.getText());
            }
        });

        break;
    case 4:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones2 = preg.getOpciones();
        final EditText ediOtros = new EditText(this);
        ArrayList<CheckBox> cb = new ArrayList<CheckBox>();

        for (int i = 0; i < opciones2.size(); i++) {
            OpcionForm opcion = opciones2.get(i);
            cb.add(new CheckBox(this));
            pregunta.addView(cb.get(i));
            cb.get(i).setText(opcion.getEtInicial());
            if (opcion.getEditble().equals("S")) {

                ediOtros.setEnabled(false);
                ediOtros.setId(R.id.edtTexto);
                pregunta.addView(ediOtros);
                cb.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            ediOtros.setEnabled(true);
                        } else {
                            ediOtros.setText("");
                            ediOtros.setEnabled(false);
                        }
                    }
                });
            }

        }
        TextView spacio = new TextView(this);
        spacio.setText("        ");
        spacio.setVisibility(View.INVISIBLE);
        pregunta.addView(spacio);
        break;
    case 5:
        id = R.layout.pregunta_escala;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloEscala);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_escala);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());

        TextView etInicial = (TextView) pregunta.findViewById(R.id.etInicial);
        TextView etFinal = (TextView) pregunta.findViewById(R.id.etFinal);
        OpcionForm opci = preg.getOpciones().get(0);
        etInicial.setText(opci.getEtInicial());
        etFinal.setText(opci.getEtFinal());
        final TextView respEscala = (TextView) pregunta.findViewById(R.id.seleEscala);
        RatingBar rtBar = (RatingBar) pregunta.findViewById(R.id.escala);
        rtBar.setNumStars(Integer.parseInt(opci.getValores().get(0).getDescripcion()));
        rtBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                respEscala.setText("" + Math.round(rating));
            }
        });

        break;
    case 6:
        id = R.layout.pregunta_lista;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloLista);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_lista);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones3 = preg.getOpciones();
        //Creamos la lista
        LinkedList<ObjetoSpinner> opcn = new LinkedList<ObjetoSpinner>();
        //La poblamos con los ejemplos
        for (int i = 0; i < opciones3.size(); i++) {
            opcn.add(new ObjetoSpinner(opciones3.get(i).getIdOpcion(), opciones3.get(i).getEtInicial()));
        }

        //Creamos el adaptador*/
        Spinner listad = (Spinner) pregunta.findViewById(R.id.opcionesListado);
        ArrayAdapter<ObjetoSpinner> spinner_adapter = new ArrayAdapter<ObjetoSpinner>(this,
                android.R.layout.simple_spinner_item, opcn);
        //Aadimos el layout para el men y se lo damos al spinner
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        listad.setAdapter(spinner_adapter);

        break;
    case 7:
        id = R.layout.pregunta_tabla;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloTabla);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_tabla);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        TableLayout tba = (TableLayout) pregunta.findViewById(R.id.tablaOpciones);
        ArrayList<OpcionForm> opciones4 = preg.getOpciones();
        ArrayList<RadioButton> radiosbotonoes = new ArrayList<RadioButton>();
        for (int i = 0; i < opciones4.size(); i++) {
            TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.row_pregunta_tabla, null);
            RadioGroup tg_valores = (RadioGroup) row.findViewById(R.id.valoresRow);

            final ArrayList<RadioButton> valoOpc = new ArrayList<RadioButton>();
            ArrayList<Valor> valoresT = opciones4.get(i).getValores();
            for (int k = 0; k < valoresT.size(); k++) {
                RadioButton rb_nuevo = new RadioButton(this);
                rb_nuevo.setText(valoresT.get(k).getDescripcion());
                tg_valores.addView(rb_nuevo);
                valoOpc.add(rb_nuevo);
            }

            ((TextView) row.findViewById(R.id.textoRow)).setText(opciones4.get(i).getEtInicial());
            tba.addView(row);
        }
        TextView espacio = new TextView(this);
        espacio.setText("        ");
        pregunta.addView(espacio);
        break;
    case 8:
        id = R.layout.pregunta_fecha;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloFecha);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_fecha);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 9:
        id = R.layout.pregunta_hora;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloHora);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_hora);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    default:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    }

    return pregunta;
}

From source file:com.mycodehurts.rapidmath.app.ProfilePageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_profile_page, container, false);
    //TextView textView = (TextView) rootView.findViewById(R.id.section_label);
    //textView.setText(Integer.toString(getArguments().getInt(ARG_SECTION_NUMBER)));
    RatingBar ratingBar = (RatingBar) rootView.findViewById(R.id.ratingBar);
    Button playStore = (Button) rootView.findViewById(R.id.btnGooglePlay);

    {//www.  j a  va  2s.  c o m
        SharedPreferences store = getActivity().getSharedPreferences("RapidMathPref", 0);
        SharedPreferences.Editor editor = store.edit();
        String strProfileName = store.getString("strStarRating", "NotFound");

        if (strProfileName.compareToIgnoreCase("NotFound") == 0) {
            ratingBar.setVisibility(View.VISIBLE);
            playStore.setVisibility(View.GONE);

        } else {
            ratingBar.setVisibility(View.GONE);
            playStore.setVisibility(View.VISIBLE);

            playStore.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Uri uri = Uri.parse("market://details?id=com.mycodehurts.rapidmath.app");
                    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                    try {
                        startActivity(goToMarket);
                    } catch (ActivityNotFoundException e) {
                        //Toast.makeText(this, "Could not launch Play store", Toast.LENGTH_LONG).show();
                    }
                }
            });

        }
        String strProfileNam = store.getString("strProfileName", "NotFound");

        if (strProfileNam.compareToIgnoreCase("NotFound") != 0) {
            TextView txtView = (TextView) rootView.findViewById(R.id.txtWelcomeName);
            txtView.setText("Welcome " + strProfileNam);

        }
    }

    //if rating value is changed,
    //display the current rating value in the result (textview) automatically
    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

            ((RMApplication) getActivity().getApplication()).getTracker(RMApplication.TrackerName.APP_TRACKER)
                    .send(new HitBuilders.EventBuilder().setCategory("Rating").setAction("StarRating")
                            .setValue((long) rating).build());

            Log.i("JS:", "Rating" + rating);

            ratingBar.setVisibility(View.GONE);
            Button playStore = (Button) getActivity().findViewById(R.id.btnGooglePlay);

            playStore.setVisibility(View.VISIBLE);

            SharedPreferences store = getActivity().getSharedPreferences("RapidMathPref", 0);
            SharedPreferences.Editor editor = store.edit();
            String strProfileName = store.getString("strStarRating", "NotFound");

            if (strProfileName.compareToIgnoreCase("NotFound") == 0) {

                editor.putString("strStarRating", " " + rating);
                editor.commit();

            }

        }
    });
    Button gplus = (Button) rootView.findViewById(R.id.btnFB);

    gplus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent shareIntent = new PlusShare.Builder(getActivity()).setType("text/plain").setText(
                    "RapidMath is a collection of techniques that help improve basic math skills. Download from here - \n"
                            + "https://play.google.com/store/apps/details?id=com.mycodehurts.rapidmath.app\n")
                    .setContentUrl(Uri.parse("https://developers.google.com/+/")).getIntent();

            startActivityForResult(shareIntent, 0);
        }
    });

    return rootView;
}

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/*from ww w  .  j ava2  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 va2s  . co m
        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;
        }
    });

}