Skip to content

Commit

Permalink
- fixed incorrect display of item length (duration) in time zones wit…
Browse files Browse the repository at this point in the history
…h a half-hour increment (ie: GMT +5:30, GMT +10:30)

- updated play/resume/stop icons to be a flat white color
- created ic_fileviewer, for the CardView icon
  • Loading branch information
dkim0419 committed Jan 9, 2015
1 parent 671c993 commit 622c1ad
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.danielkim.soundrecorder"
minSdkVersion 16
targetSdkVersion 21
versionCode 3
versionName "1.2.0"
versionCode 4
versionName "1.2.1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
* Created by Daniel on 12/29/2014.
Expand All @@ -37,7 +38,6 @@ public class FileViewerAdapter extends RecyclerView.Adapter<FileViewerAdapter.Re
private DBHelper mDatabase;
private static final SimpleDateFormat mDateAddedFormatter =
new SimpleDateFormat("MMM dd, yyyy - hh:mm a", Locale.getDefault());
private static final SimpleDateFormat mLengthFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());

RecordingItem item;
Context mContext;
Expand All @@ -55,9 +55,14 @@ public FileViewerAdapter(Context context, LinearLayoutManager linearLayoutManage
public void onBindViewHolder(final RecordingsViewHolder holder, int position) {

item = getItem(position);
long itemDuration = item.getLength();

long minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration);
long seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration)
- TimeUnit.MINUTES.toSeconds(minutes);

holder.vName.setText(item.getName());
holder.vLength.setText(mLengthFormatter.format(item.getLength()));
holder.vLength.setText(String.format("%02d:%02d", minutes,seconds));
holder.vDateAdded.setText(mDateAddedFormatter.format(item.getTime()));

// define an on click listener to open PlaybackFragment
Expand All @@ -67,6 +72,7 @@ public void onClick(View view) {
try {
PlaybackFragment playbackFragment =
new PlaybackFragment().newInstance(getItem(holder.getPosition()));

FragmentTransaction transaction = ((FragmentActivity) mContext)
.getSupportFragmentManager()
.beginTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import com.melnykov.fab.FloatingActionButton;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
* Created by Daniel on 1/1/2015.
Expand All @@ -36,7 +35,6 @@ public class PlaybackFragment extends DialogFragment{

private Handler mHandler = new Handler();

private static final SimpleDateFormat mLengthFormatter = new SimpleDateFormat("mm:ss", Locale.getDefault());
private MediaPlayer mMediaPlayer = null;

private SeekBar mSeekBar = null;
Expand All @@ -48,6 +46,10 @@ public class PlaybackFragment extends DialogFragment{
//stores whether or not the mediaplayer is currently playing audio
private boolean isPlaying = false;

//stores minutes and seconds of the length of the file.
long minutes = 0;
long seconds = 0;

public PlaybackFragment newInstance(RecordingItem item) {
PlaybackFragment f = new PlaybackFragment();
Bundle b = new Bundle();
Expand All @@ -61,6 +63,16 @@ public PlaybackFragment newInstance(RecordingItem item) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
item = getArguments().getParcelable(ARG_ITEM);

long itemDuration = item.getLength();
minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration);
seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration)
- TimeUnit.MINUTES.toSeconds(minutes);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}

@NonNull
Expand Down Expand Up @@ -88,7 +100,12 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(mMediaPlayer != null && fromUser) {
mMediaPlayer.seekTo(progress);
mHandler.removeCallbacks(mRunnable);
mCurrentProgressTextView.setText(mLengthFormatter.format(mMediaPlayer.getCurrentPosition()));

long minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getCurrentPosition());
long seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getCurrentPosition())
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes,seconds));

updateSeekBar();

} else if (mMediaPlayer == null && fromUser) {
Expand All @@ -110,7 +127,11 @@ public void onStopTrackingTouch(SeekBar seekBar) {
if (mMediaPlayer != null) {
mHandler.removeCallbacks(mRunnable);
mMediaPlayer.seekTo(seekBar.getProgress());
mCurrentProgressTextView.setText(mLengthFormatter.format(mMediaPlayer.getCurrentPosition()));

long minutes = TimeUnit.MILLISECONDS.toMinutes(mMediaPlayer.getCurrentPosition());
long seconds = TimeUnit.MILLISECONDS.toSeconds(mMediaPlayer.getCurrentPosition())
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes,seconds));
updateSeekBar();
}
}
Expand All @@ -126,7 +147,7 @@ public void onClick(View v) {
});

mFileNameTextView.setText(item.getName());
mFileLengthTextView.setText(mLengthFormatter.format(item.getLength()));
mFileLengthTextView.setText(String.format("%02d:%02d", minutes,seconds));

builder.setView(view);

Expand Down Expand Up @@ -267,7 +288,7 @@ private void stopPlaying() {
mSeekBar.setProgress(mSeekBar.getMax());
isPlaying = !isPlaying;

mCurrentProgressTextView.setText(mLengthFormatter.format(item.getLength()));
mCurrentProgressTextView.setText(mFileLengthTextView.getText());
mSeekBar.setProgress(mSeekBar.getMax());

//allow the screen to turn off again once audio is finished playing
Expand All @@ -282,7 +303,12 @@ public void run() {

int mCurrentPosition = mMediaPlayer.getCurrentPosition();
mSeekBar.setProgress(mCurrentPosition);
mCurrentProgressTextView.setText(mLengthFormatter.format(mCurrentPosition));

long minutes = TimeUnit.MILLISECONDS.toMinutes(mCurrentPosition);
long seconds = TimeUnit.MILLISECONDS.toSeconds(mCurrentPosition)
- TimeUnit.MINUTES.toSeconds(minutes);
mCurrentProgressTextView.setText(String.format("%02d:%02d", minutes,seconds));

updateSeekBar();
}
}
Expand Down
Binary file modified app/src/main/res/drawable-hdpi/ic_media_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/ic_media_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/ic_media_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-mdpi/ic_media_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-mdpi/ic_media_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-mdpi/ic_media_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xhdpi/ic_media_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xhdpi/ic_media_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xhdpi/ic_media_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xxhdpi/ic_media_pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xxhdpi/ic_media_play.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xxhdpi/ic_media_stop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions app/src/main/res/layout/card_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_fileviewer"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"/>

<LinearLayout
android:layout_width="wrap_content"
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@
<!-- specify shared element enter and exit transitions -->
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>

<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition">@android:transition/explode</item>
<item name="android:windowExitTransition">@android:transition/explode</item>
</style>

<!-- Theme for Playback DialogFragment -->
<style name="PlaybackFragmentAnimation" parent="@android:style/Theme.Panel">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>

<!-- specify shared element enter and exit transitions -->
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>

<!-- specify enter and exit transitions -->
<item name="android:windowEnterTransition">@android:transition/explode</item>
<item name="android:windowExitTransition">@android:transition/explode</item>
Expand Down

0 comments on commit 622c1ad

Please sign in to comment.