diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-09-05 14:51:02 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-09-05 14:51:02 -0400 |
commit | 1ac58a34ebeaa144958cc248b59ffa3771b128cc (patch) | |
tree | 4dd0efac113492e185e0afa8dd3f40bba41fc392 | |
parent | 5814727180029871ecda7693346d6cc8c2a60716 (diff) | |
parent | 14977413d56908371045a7dd212aefb52241c02b (diff) | |
download | AntennaPod-1ac58a34ebeaa144958cc248b59ffa3771b128cc.zip |
Merge pull request #1165 from mfietz/issue/1123-playback-speed
Choose playback speed directly
-rw-r--r-- | app/build.gradle | 3 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java | 194 | ||||
-rw-r--r-- | app/src/main/res/layout/audioplayer_activity.xml | 2 | ||||
-rw-r--r-- | app/src/main/res/layout/choose_speed_dialog.xml | 45 |
4 files changed, 160 insertions, 84 deletions
diff --git a/app/build.gradle b/app/build.gradle index a9cd05bd4..90d0c108e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,6 +11,7 @@ dependencies { compile 'com.android.support:support-v4:22.2.1' compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:gridlayout-v7:22.2.1' + compile 'com.android.support:cardview-v7:22.2.1' compile 'org.apache.commons:commons-lang3:3.3.2' compile('org.shredzone.flattr4j:flattr4j-core:2.12') { exclude group: 'org.json', module: 'json' @@ -24,7 +25,7 @@ dependencies { compile 'de.greenrobot:eventbus:2.4.0' compile 'io.reactivex:rxandroid:1.0.1' compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.0.3' - + compile project(':core') compile project(':library:drag-sort-listview') } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index b975d482a..c3d82c41d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.TypedArray; +import android.graphics.drawable.BitmapDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -15,21 +16,26 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.ContextMenu; +import android.view.Gravity; +import android.view.LayoutInflater; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnLongClickListener; +import android.view.ViewGroup; +import android.view.animation.LinearInterpolator; +import android.view.animation.ScaleAnimation; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageButton; import android.widget.ListView; +import android.widget.PopupWindow; +import android.widget.SeekBar; import android.widget.TextView; import com.bumptech.glide.Glide; -import com.bumptech.glide.load.engine.DiskCacheStrategy; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import de.danoeh.antennapod.R; @@ -50,7 +56,6 @@ import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.playback.ExternalMedia; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; -import de.danoeh.antennapod.dialog.VariableSpeedDialog; import de.danoeh.antennapod.fragment.CoverFragment; import de.danoeh.antennapod.fragment.ItemDescriptionFragment; import de.danoeh.antennapod.menuhandler.NavDrawerActivity; @@ -61,6 +66,7 @@ import de.danoeh.antennapod.preferences.PreferenceController; */ public class AudioplayerActivity extends MediaplayerActivity implements ItemDescriptionFragment.ItemDescriptionFragmentCallback, NavDrawerActivity { + private static final int POS_COVER = 0; private static final int POS_DESCR = 1; private static final int POS_CHAPTERS = 2; @@ -98,6 +104,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc private ImageButton butNavChaptersShownotes; private ImageButton butShowCover; + private PopupWindow popupWindow; + private void resetFragmentView() { FragmentTransaction fT = getSupportFragmentManager().beginTransaction(); @@ -325,14 +333,11 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc }; chapterFragment.setListAdapter(new ChapterListAdapter( AudioplayerActivity.this, 0, media - .getChapters(), media, new ChapterListAdapter.Callback() { - @Override - public void onPlayChapterButtonClicked(int position) { - Chapter chapter = (Chapter) - chapterFragment.getListAdapter().getItem(position); - controller.seekToChapter(chapter); - } - } + .getChapters(), media, position -> { + Chapter chapter = (Chapter) + chapterFragment.getListAdapter().getItem(position); + controller.seekToChapter(chapter); + } )); } currentlyShownFragment = chapterFragment; @@ -426,91 +431,117 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc navAdapter = new NavListAdapter(itemAccess, this); navList.setAdapter(navAdapter); - navList.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - int viewType = parent.getAdapter().getItemViewType(position); - if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) { - Intent intent = new Intent(AudioplayerActivity.this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType); - intent.putExtra(MainActivity.EXTRA_NAV_INDEX, position); - startActivity(intent); - } - drawerLayout.closeDrawer(navDrawer); + navList.setOnItemClickListener((parent, view, position, id) -> { + int viewType = parent.getAdapter().getItemViewType(position); + if (viewType != NavListAdapter.VIEW_TYPE_SECTION_DIVIDER) { + Intent intent = new Intent(AudioplayerActivity.this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_NAV_TYPE, viewType); + intent.putExtra(MainActivity.EXTRA_NAV_INDEX, position); + startActivity(intent); } + drawerLayout.closeDrawer(navDrawer); }); registerForContextMenu(navList); drawerToggle.syncState(); - findViewById(R.id.nav_settings).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - drawerLayout.closeDrawer(navDrawer); - startActivity(new Intent(AudioplayerActivity.this, PreferenceController.getPreferenceActivity())); - } + findViewById(R.id.nav_settings).setOnClickListener(v -> { + drawerLayout.closeDrawer(navDrawer); + startActivity(new Intent(AudioplayerActivity.this, PreferenceController.getPreferenceActivity())); }); - butNavChaptersShownotes.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (currentlyShownPosition == POS_CHAPTERS) { - switchToFragment(POS_DESCR); - } else if (currentlyShownPosition == POS_DESCR) { - switchToFragment(POS_CHAPTERS); - } else if (currentlyShownPosition == POS_COVER) { - switchToLastFragment(); - } - } - }); - - butShowCover.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - switchToFragment(POS_COVER); + butNavChaptersShownotes.setOnClickListener(v -> { + if (currentlyShownPosition == POS_CHAPTERS) { + switchToFragment(POS_DESCR); + } else if (currentlyShownPosition == POS_DESCR) { + switchToFragment(POS_CHAPTERS); + } else if (currentlyShownPosition == POS_COVER) { + switchToLastFragment(); } }); - butPlaybackSpeed.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - if (controller != null && controller.canSetPlaybackSpeed()) { - String[] availableSpeeds = UserPreferences - .getPlaybackSpeedArray(); - String currentSpeed = UserPreferences.getPlaybackSpeed(); - - // Provide initial value in case the speed list has changed - // out from under us - // and our current speed isn't in the new list - String newSpeed; - if (availableSpeeds.length > 0) { - newSpeed = availableSpeeds[0]; - } else { - newSpeed = "1.0"; - } + butShowCover.setOnClickListener(v -> switchToFragment(POS_COVER)); + + butPlaybackSpeed.setOnClickListener(v -> { + if (controller != null && controller.canSetPlaybackSpeed()) { + String[] availableSpeeds = UserPreferences + .getPlaybackSpeedArray(); + String currentSpeed = UserPreferences.getPlaybackSpeed(); + + // Provide initial value in case the speed list has changed + // out from under us + // and our current speed isn't in the new list + String newSpeed; + if (availableSpeeds.length > 0) { + newSpeed = availableSpeeds[0]; + } else { + newSpeed = "1.0"; + } - for (int i = 0; i < availableSpeeds.length; i++) { - if (availableSpeeds[i].equals(currentSpeed)) { - if (i == availableSpeeds.length - 1) { - newSpeed = availableSpeeds[0]; - } else { - newSpeed = availableSpeeds[i + 1]; - } - break; + for (int i = 0; i < availableSpeeds.length; i++) { + if (availableSpeeds[i].equals(currentSpeed)) { + if (i == availableSpeeds.length - 1) { + newSpeed = availableSpeeds[0]; + } else { + newSpeed = availableSpeeds[i + 1]; } + break; } - UserPreferences.setPlaybackSpeed(newSpeed); - controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); } + UserPreferences.setPlaybackSpeed(newSpeed); + controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); } }); - butPlaybackSpeed.setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - VariableSpeedDialog.showDialog(AudioplayerActivity.this); - return true; - } + butPlaybackSpeed.setOnLongClickListener(v -> { + + String[] availableSpeeds = getResources().getStringArray(R.array.playback_speed_values); + String currentSpeed = UserPreferences.getPlaybackSpeed(); + + LayoutInflater inflater = getLayoutInflater(); + View popupView = inflater.inflate(R.layout.choose_speed_dialog, null); + TextView txtvSelectedSpeed = (TextView) popupView.findViewById(R.id.txtvSelectedSpeed); + SeekBar sbSelectSpeed = (SeekBar) popupView.findViewById(R.id.sbSelectSpeed); + + txtvSelectedSpeed.setText(currentSpeed); + int progress = ArrayUtils.indexOf(availableSpeeds, currentSpeed); + int max = Math.max(progress, ArrayUtils.indexOf(availableSpeeds, "2.50")); + sbSelectSpeed.setMax(max); + sbSelectSpeed.setProgress(progress); + sbSelectSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + txtvSelectedSpeed.setText(availableSpeeds[progress]); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + String selectedSpeed = availableSpeeds[sbSelectSpeed.getProgress()]; + UserPreferences.setPlaybackSpeed(selectedSpeed); + controller.setPlaybackSpeed(Float.parseFloat(selectedSpeed)); + if (popupWindow != null && popupWindow.isShowing()) { + popupWindow.dismiss(); + } + ScaleAnimation anim = new ScaleAnimation(1.0f, 1.33f, 1.0f, 1.33f, + butPlaybackSpeed.getWidth()/2, butPlaybackSpeed.getHeight()/2); + anim.setDuration(150); + anim.setRepeatMode(ScaleAnimation.REVERSE); + anim.setRepeatCount(1); + anim.setInterpolator(new LinearInterpolator()); + butPlaybackSpeed.startAnimation(anim); + } + }); + popupWindow = new PopupWindow(popupView, + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT, + true); + popupWindow.setBackgroundDrawable(new BitmapDrawable()); + popupWindow.setOutsideTouchable(true); + popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); + return true; }); } @@ -630,7 +661,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc } public interface AudioplayerContentFragment { - public void onDataSetChanged(Playable media); + void onDataSetChanged(Playable media); } @Override @@ -793,4 +824,5 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; } }; + } diff --git a/app/src/main/res/layout/audioplayer_activity.xml b/app/src/main/res/layout/audioplayer_activity.xml index 827e06e00..379028c8e 100644 --- a/app/src/main/res/layout/audioplayer_activity.xml +++ b/app/src/main/res/layout/audioplayer_activity.xml @@ -26,7 +26,6 @@ android:paddingLeft="8dp" android:paddingRight="8dp"> - <TextView android:id="@+id/txtvTitle" android:layout_width="0dp" @@ -138,7 +137,6 @@ android:background="?attr/selectableItemBackground" android:contentDescription="@string/set_playback_speed_label" android:src="?attr/av_fast_forward" - android:textColor="@color/gray" android:textSize="@dimen/text_size_medium" android:visibility="gone" tools:background="@android:color/holo_green_dark" /> diff --git a/app/src/main/res/layout/choose_speed_dialog.xml b/app/src/main/res/layout/choose_speed_dialog.xml new file mode 100644 index 000000000..1b461c77e --- /dev/null +++ b/app/src/main/res/layout/choose_speed_dialog.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <android.support.v7.widget.CardView + xmlns:card_view="http://schemas.android.com/apk/res-auto" + android:id="@+id/card_view" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_margin="16dp" + card_view:cardElevation="12dp" + card_view:cardCornerRadius="4dp" + card_view:cardUseCompatPadding="true" + card_view:cardBackgroundColor="?attr/overlay_background"> + + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:gravity="center"> + + <TextView + android:id="@+id/txtvSelectedSpeed" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:textSize="22sp" + android:textStyle="bold"/> + + <SeekBar + android:id="@+id/sbSelectSpeed" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp"/> + + </LinearLayout> + + </android.support.v7.widget.CardView> + +</LinearLayout> |