use of android.widget.RatingBar.OnRatingBarChangeListener in project JamsMusicPlayer by psaravan.
the class PlaylistPagerFlippedFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_flipped, container, false);
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;
}
use of android.widget.RatingBar.OnRatingBarChangeListener in project coursera-android by aporter.
the class SamplerActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//
final ImageButton button = (ImageButton) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message
Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "Done" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Show Toast message
Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Show Toast message indicating the CheckBox's Checked state
if (((CheckBox) v).isChecked()) {
Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);
final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {
Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
}
}
});
final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
}
});
}
use of android.widget.RatingBar.OnRatingBarChangeListener in project coursera-android by aporter.
the class RatingsBarActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView tv = (TextView) findViewById(R.id.textView);
final RatingBar bar = (RatingBar) findViewById(R.id.ratingbar);
bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
// Called when the user swipes the RatingBar
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
tv.setText("Rating:" + rating);
}
});
}
Aggregations