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:com.hybris.mobile.activity.AbstractProductDetailActivity.java

/**
 * Refresh the UI with data from the product
 *//*from w w  w .j a  v a 2  s. c  o  m*/
public void updateUI() {

    // Title
    this.setTitle(mProduct.getName());

    // Images
    if (mProduct.getGalleryImageURLs() != null) {
        GalleryAdapter adapter = new GalleryAdapter(this, mProduct.getGalleryImageURLs());
        Gallery gallery = (Gallery) findViewById(R.id.galleryImages);
        gallery.setAdapter(adapter);

        // Set the onClick listener for the gallery
        gallery.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) {
                viewImage(position);

            }
        });
    }

    // Reviews
    TextView reviewTextView = (TextView) findViewById(R.id.textViewReviews);
    reviewTextView.setText(this.getResources().getString(R.string.show_reviews, mProduct.getReviews().size()));

    // Rating (stars)
    RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBarRating);
    if (mProduct.getAverageRating() != null) {
        ratingBar.setRating(mProduct.getAverageRating().floatValue());
    }

    // Promotions
    TextView promotionsTextView = (TextView) findViewById(R.id.textViewPromotion);
    if (mProduct.getPotentialPromotions().size() == 0) {
        promotionsTextView.setVisibility(View.GONE);
    } else {
        if (mProduct.getPotentialPromotions() != null && !mProduct.getPotentialPromotions().isEmpty()) {
            promotionsTextView.setText(
                    Html.fromHtml(Product.generatePromotionString(mProduct.getPotentialPromotions().get(0))));
            StringUtil.removeUnderlines((Spannable) promotionsTextView.getText());
        }

    }

    TextView priceTextView = (TextView) findViewById(R.id.textViewPrice);
    priceTextView.setText(mProduct.getPrice().getFormattedValue());

    // Description
    TextView descriptionTextView = (TextView) findViewById(R.id.textViewDescription);
    descriptionTextView.setText(mProduct.getDescription());

    // Stock level
    TextView stockLevelTextView = (TextView) findViewById(R.id.textViewStockLevel);
    String stockLevelText = mProduct.getStockLevelText(Hybris.getAppContext());
    if (mProduct.getStock().getStockLevel() > 0) {
        stockLevelText = mProduct.getStock().getStockLevel() + " "
                + mProduct.getStockLevelText(Hybris.getAppContext()).toLowerCase();
    }
    stockLevelTextView.setText(stockLevelText);

    // Disable / Enable the add to cart button
    Button addToCartButton = (Button) findViewById(R.id.buttonAddToCart);

    Button quantityButton = (Button) findViewById(R.id.quantityButton);
    quantityButton.setText(getString(R.string.quantity_button, quantityToAddToCart));

    try {

        if (mProduct.getStock().getStockLevelStatus() != null
                && StringUtils.equalsIgnoreCase(mProduct.getStock().getStockLevelStatus().getCode(),
                        ProductStockLevelStatus.CODE_OUT_OF_STOCK)) {
            addToCartButton.setEnabled(false);
            quantityButton.setEnabled(false);
            quantityButton.setText(R.string.quantity);
        } else {
            addToCartButton.setEnabled(true);
            quantityButton.setEnabled(true);
        }
    } catch (Exception e) {
    }

    invalidateOptionsMenu();
}

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

private void initTopicSpinner() {
    // Get topics in category. Null accepts all user sources. Modify
    // according to user selection
    final String[] saTopicIDs = SearchTopicActivity.saTopicIDs;
    final String[] saTitles = SearchTopicActivity.saTopicTitles;
    final String[] saDates = SearchTopicActivity.saTopicDates;
    // TODO add TopicInfo for SearchResults as well and parse accordingly

    // final String[] saTopicIDs = extras.getStringArray("searchresults");
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    // tx.setMovementMethod(LinkMovementMethod.getInstance());
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from   w w  w  .java2 s. c o m*/

    // Scroll view init
    final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
    // Add selection event
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            // Show waiting dialog
            showWaitingDialog();

            // Changing summary
            loading = true;
            // Update visibility of rating bar
            final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
            rb.setRating(0.0f);
            rb.setVisibility(View.VISIBLE);
            final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
            rateLbl.setVisibility(View.VISIBLE);

            scroll.scrollTo(0, 0);
            //            String[] saTopicIDs = sTopicIds.split(sSeparator);

            SharedPreferences settings = getSharedPreferences("urls", 0);
            // get user settings for sources
            String UserSources = settings.getString("UserLinks", "All");
            String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
            if (Summary.length == 0) { // WORK. Updated: CHECK
                // Close waiting dialog
                closeWaitingDialog();

                AlertDialog.Builder alert = new AlertDialog.Builder(SearchViewActivity.this);
                alert.setMessage(R.string.shouldReloadSummaries);
                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                    }
                });
                alert.setCancelable(false);
                alert.show();
                loading = false;
                return;
            }
            // track summary views per Search and topic title
            if (getAnalyticsPref()) {
                EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, "From Search",
                        saTitles[arg2] + ": " + saDates[arg2], 0l);
            }
            // Generate summary text
            sText = ViewActivity.generateSummaryText(Summary, SearchViewActivity.this);
            pText = ViewActivity.generatesummarypost(Summary, SearchViewActivity.this);
            tx.setText(Html.fromHtml(sText));
            tx.setMovementMethod(LinkMovementMethod.getInstance());
            title.setText(saTitles[arg2] + ": " + saDates[arg2]);
            float defSize = tx.getTextSize();
            SharedPreferences usersize = getSharedPreferences("textS", 0);
            float newSize = usersize.getFloat("size", defSize);
            tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize);
            // update the TopicActivity with viewed item
            TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);

            // Close waiting dialog
            closeWaitingDialog();

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

}

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

@Override
public void run() {
    // take the String from the TopicActivity
    Bundle extras = getIntent().getExtras();
    Category = extras.getString(CATEGORY_INTENT_VAR);

    // Make sure we have updated the data source
    NewSumUiActivity.setDataSource(this);

    // Get user sources
    String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

    // get Topics from TopicActivity (avoid multiple server calls)
    TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this);

    // Also get Topic Titles, to display to adapter
    final String[] saTopicTitles = new String[tiTopics.length];
    // Also get Topic IDs
    final String[] saTopicIDs = new String[tiTopics.length];
    // Also get Dates, in order to show in summary title
    final String[] saTopicDates = new String[tiTopics.length];
    // DeHTML titles
    for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) {
        // update Titles Array
        saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString();
        // update IDs Array
        saTopicIDs[iCnt] = tiTopics[iCnt].getID();
        // update Date Array
        saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale());
    }//from   w ww .j av a 2  s. c om
    // get the value of the TopicIDs list size (to use in swipe)
    saTopicIDsLength = saTopicIDs.length;
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTopicTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // Get active topic
    int iTopicNum;
    // If we have returned from a pause
    if (iPrvSelectedItem >= 0)
        // use previous selection before pause
        iTopicNum = iPrvSelectedItem;
    // else
    else
        // use selection from topic page
        iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR);
    final int num = iTopicNum;

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setAdapter(adapter);

            // Scroll view init
            final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
            final String[] saTopicTitlesArg = saTopicTitles;
            final String[] saTopicIDsArg = saTopicIDs;
            final String[] SaTopicDatesArg = saTopicDates;

            // Add selection event
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    // Changing summary
                    loading = true;
                    showWaitingDialog();
                    // Update visibility of rating bar
                    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
                    rb.setRating(0.0f);
                    rb.setVisibility(View.VISIBLE);
                    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
                    rateLbl.setVisibility(View.VISIBLE);
                    scroll.scrollTo(0, 0);

                    String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

                    String[] saTopicIDs = saTopicIDsArg;

                    // track summary views per category and topic title
                    if (getAnalyticsPref()) {
                        EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category,
                                saTopicTitlesArg[arg2], 0l);
                    }

                    if (sCustomCategory.trim().length() > 0) {
                        if (Category.equals(sCustomCategory)) {
                            Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this);
                            String sCustomCategoryURL = ctxCur.getResources()
                                    .getString(R.string.custom_category_url);
                            // Check if specific element needs to be read
                            String sElementID = ctxCur.getResources()
                                    .getString(R.string.custom_category_elementId);
                            // If an element needs to be selected
                            if (sElementID.trim().length() > 0) {
                                try {
                                    // Check if specific element needs to be read
                                    String sViewOriginalPage = ctxCur.getResources()
                                            .getString(R.string.custom_category_visit_source);
                                    // Init text by a link to the original page
                                    sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage
                                            + "</a></p>";
                                    // Get document
                                    Document doc = Jsoup.connect(sCustomCategoryURL).get();
                                    // If a table
                                    Element eCur = doc.getElementById(sElementID);
                                    if (eCur.tagName().equalsIgnoreCase("table")) {
                                        // Get table rows
                                        Elements eRows = eCur.select("tr");

                                        // For each row
                                        StringBuffer sTextBuf = new StringBuffer();
                                        for (Element eCurRow : eRows) {
                                            // Append content
                                            // TODO: Use HTML if possible. Now problematic (crashes when we click on link)
                                            sTextBuf.append("<p>" + eCurRow.text() + "</p>");
                                        }
                                        // Return as string
                                        sText = sText + sTextBuf.toString();
                                    } else
                                        // else get text
                                        sText = eCur.text();

                                } catch (IOException e) {
                                    // Show unavailable text
                                    sText = ctxCur.getResources()
                                            .getString(R.string.custom_category_unavailable);
                                    e.printStackTrace();
                                }

                            } else
                                sText = Utils.getFromHttp(sCustomCategoryURL, false);
                        }

                    } else {
                        // call getSummary with (sTopicID, sUserSources). Use "All" for
                        // all Sources
                        String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
                        // check if Summary exists, otherwise display message
                        if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT
                            // WORK. Updated: Probably OK
                            nothingFound = true;
                            AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this);
                            al.setMessage(R.string.shouldReloadSummaries);
                            al.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface arg0, int arg1) {
                                    // Reset cache
                                    CacheController.clearCache();
                                    // Restart main activity
                                    startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                                }
                            });
                            al.setCancelable(false);
                            al.show();
                            // Return to home activity
                            loading = false;
                            return;
                        }
                        // Generate Summary text for normal categories
                        sText = generateSummaryText(Summary, ViewActivity.this);
                        pText = generatesummarypost(Summary, ViewActivity.this);
                    }

                    // Update HTML
                    tx.setText(Html.fromHtml(sText));
                    // Allow links to be followed into browser
                    tx.setMovementMethod(LinkMovementMethod.getInstance());
                    // Also Add Date to Topic Title inside Summary
                    title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]);

                    // Update size
                    updateTextSize();

                    // Update visited topics
                    TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);
                    // Done
                    loading = false;
                    closeWaitingDialog();
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                }

            });

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Get active topic
                    spinner.setSelection(num);
                }
            });

        }
    });

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    });

    closeWaitingDialog();
}

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

private void setupButtonEvents(View header) {
    ImageView shareButton = (ImageView) header.findViewById(R.id.select_album_share);
    if (share != null || podcastId != null
            || !Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_SHARED, true)
            || Util.isOffline(context) || !UserUtil.canShare() || artistInfo != null) {
        shareButton.setVisibility(View.GONE);
    } else {/*from w  ww.  ja  v  a 2s  .c  o m*/
        shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createShare(SelectDirectoryFragment.this.entries);
            }
        });
    }

    final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star);
    if (directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)
            && artistInfo == null) {
        if (directory.isStarred()) {
            starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
        } else {
            starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline));
        }
        starButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                toggleStarred(directory, new OnStarChange() {
                    @Override
                    void starChange(boolean starred) {
                        if (directory.isStarred()) {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                            starButton.setImageDrawable(
                                    DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
                        } else {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                        }
                    }
                });
            }
        });
    } else {
        starButton.setVisibility(View.GONE);
    }

    View ratingBarWrapper = header.findViewById(R.id.select_album_rate_wrapper);
    final RatingBar ratingBar = (RatingBar) header.findViewById(R.id.select_album_rate);
    if (directory != null
            && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true)
            && !Util.isOffline(context) && artistInfo == null) {
        ratingBar.setRating(directory.getRating());
        ratingBarWrapper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setRating(directory, new OnRatingChange() {
                    @Override
                    void ratingChange(int rating) {
                        ratingBar.setRating(directory.getRating());
                    }
                });
            }
        });
    } else {
        ratingBar.setVisibility(View.GONE);
    }
}

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  ww.ja va2s  .c  om*/
    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:github.popeen.dsub.fragments.SelectDirectoryFragment.java

private void setupButtonEvents(View header) {
    ImageView shareButton = (ImageView) header.findViewById(R.id.select_album_share);
    if (share != null || podcastId != null
            || !Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_SHARED, true)
            || Util.isOffline(context) || !UserUtil.canShare() || artistInfo != null) {
        shareButton.setVisibility(View.GONE);
    } else {/* ww w  .  jav a 2 s.  c  o  m*/
        shareButton.setVisibility(View.GONE);
        shareButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createShare(SelectDirectoryFragment.this.entries);
            }
        });
    }

    final ImageButton starButton = (ImageButton) header.findViewById(R.id.select_album_star);
    if (directory != null && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_STAR, true)
            && artistInfo == null) {
        if (directory.isStarred()) {
            starButton.setImageDrawable(DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
        } else {
            starButton.setImageResource(DrawableTint.getDrawableRes(context, R.attr.star_outline));
        }
        starButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateHelper.toggleStarred(context, directory, new UpdateHelper.OnStarChange() {
                    @Override
                    public void starChange(boolean starred) {
                        if (directory.isStarred()) {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                            starButton.setImageDrawable(
                                    DrawableTint.getTintedDrawable(context, R.drawable.ic_toggle_star));
                        } else {
                            starButton.setImageResource(
                                    DrawableTint.getDrawableRes(context, R.attr.star_outline));
                        }
                    }

                    @Override
                    public void starCommited(boolean starred) {

                    }
                });
            }
        });
        starButton.setVisibility(View.GONE);
    } else {
        starButton.setVisibility(View.GONE);
    }

    View ratingBarWrapper = header.findViewById(R.id.select_album_rate_wrapper);
    final RatingBar ratingBar = (RatingBar) header.findViewById(R.id.select_album_rate);
    if (directory != null
            && Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_MENU_RATING, true)
            && !Util.isOffline(context) && artistInfo == null) {
        ratingBar.setRating(directory.getRating());
        ratingBarWrapper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateHelper.setRating(context, directory, new UpdateHelper.OnRatingChange() {
                    @Override
                    public void ratingChange(int rating) {
                        ratingBar.setRating(directory.getRating());
                    }
                });
            }
        });
        ratingBar.setVisibility(View.GONE);
    } else {
        ratingBar.setVisibility(View.GONE);
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Set the rating of a RatingBar.//from   ww w  .ja  va  2s  .com
 * @param rating the rating
 * @return self
 */
public T rating(float rating) {
    if (view instanceof RatingBar) {
        RatingBar rb = (RatingBar) view;
        rb.setRating(rating);
    }
    return self();
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * This method is used in MovieDetails, CastDetails and TVDetails.
 * runOnUiThread() is called because we can't update it from async task.
 *
 * @param ratingBar the ratingBar we set value.
 * @param value     the value we will set on the ratingBar.
 *//*from  ww w. j a  v a2s.  co  m*/
public void setRatingBarValue(final RatingBar ratingBar, final float value) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ratingBar.setRating(value);
        }
    });
}

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/* w  w w  .  ja v a  2s  . c  o  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();
}

From source file:com.androidquery.AQuery.java

/**
 * Set the rating of a RatingBar.//from   w w  w  .ja  v  a  2 s .co m
 *
 * @param rating the rating
 * @return self
 */
public AQuery rating(float rating) {

    if (view instanceof RatingBar) {
        RatingBar rb = (RatingBar) view;
        rb.setRating(rating);
    }
    return self();
}