diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-07-01 18:32:52 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-07-01 18:32:52 +0200 |
commit | 3932e09089032fc91ce2d361443e5c3df5de6b41 (patch) | |
tree | fbeae0f8cbd2dd8785dd1c7c5920ae9313de6085 | |
parent | 2cf9f5045b0cc94e3fc541791781b3c0c9bb4e17 (diff) | |
download | AntennaPod-3932e09089032fc91ce2d361443e5c3df5de6b41.zip |
Added viewpager to mediaplayeractivity
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | res/layout/cover_fragment.xml | 48 | ||||
-rw-r--r-- | res/layout/mediaplayer_activity.xml | 52 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rw-r--r-- | src/de/podfetcher/activity/MediaplayerActivity.java | 100 | ||||
-rw-r--r-- | src/de/podfetcher/fragment/CoverFragment.java | 89 |
6 files changed, 244 insertions, 48 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9d296eb81..8c4ec9157 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -30,7 +30,7 @@ <activity android:name="de.podfetcher.activity.ItemviewActivity"/> <activity android:name="de.podfetcher.activity.DownloadActivity" android:label="@string/downloads_label"/> - <activity android:name="de.podfetcher.activity.MediaplayerActivity" android:launchMode="singleTask" android:configChanges="orientation"/> + <activity android:name="de.podfetcher.activity.MediaplayerActivity" android:launchMode="singleTask" android:configChanges="orientation" android:theme="@style/StyledIndicators"/> <service android:enabled="true" android:name="de.podfetcher.service.DownloadService" /> <service android:enabled="true" android:name="de.podfetcher.service.PlaybackService" > diff --git a/res/layout/cover_fragment.xml b/res/layout/cover_fragment.xml new file mode 100644 index 000000000..c7f60f2da --- /dev/null +++ b/res/layout/cover_fragment.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8"?> +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/cover_fragment_root" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <TextView + android:id="@+id/txtvTitle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentTop="true" + android:layout_marginTop="20dp" + android:gravity="center_horizontal" + android:textSize="18dp" + android:textStyle="bold" /> + + <TextView + android:id="@+id/txtvFeed" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_below="@+id/txtvTitle" + android:gravity="center_horizontal" /> + + <LinearLayout + android:id="@+id/cover_layout" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentLeft="true" + android:layout_alignParentRight="true" + android:layout_alignParentTop="false" + android:layout_below="@id/txtvFeed" + android:layout_gravity="center" + android:layout_weight="1" + android:orientation="vertical" > + + <ImageView + android:id="@+id/imgvCover" + android:layout_width="200dp" + android:layout_height="200dp" + android:layout_gravity="center" + android:gravity="center" /> + + </LinearLayout> + +</RelativeLayout>
\ No newline at end of file diff --git a/res/layout/mediaplayer_activity.xml b/res/layout/mediaplayer_activity.xml index effe3ab57..976ccabaa 100644 --- a/res/layout/mediaplayer_activity.xml +++ b/res/layout/mediaplayer_activity.xml @@ -4,16 +4,11 @@ android:layout_height="match_parent" android:orientation="vertical" > - <TextView - android:id="@+id/txtvTitle" - android:layout_width="match_parent" + <com.viewpagerindicator.TabPageIndicator + android:id="@+id/tabs" + android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_alignParentTop="true" - android:layout_marginTop="20dp" - android:gravity="center_horizontal" - android:textSize="18dp" - android:textStyle="bold" > - </TextView> + android:layout_alignParentTop="true" /> <LinearLayout android:id="@+id/player_control" @@ -71,9 +66,11 @@ android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/sbPosition" + android:layout_marginBottom="5dp" + android:layout_marginTop="5dp" android:padding="5dp" android:scaleType="fitXY" - android:src="@drawable/horizontal_divider" android:layout_marginBottom="5dp" android:layout_marginTop="5dp"/> + android:src="@drawable/horizontal_divider" /> <RelativeLayout android:id="@+id/playtime_layout" @@ -106,36 +103,23 @@ android:visibility="invisible" /> </RelativeLayout> + <android.support.v4.view.ViewPager + android:id="@+id/viewpager" + android:layout_width="match_parent" + android:layout_height="0px" + android:layout_above="@id/playtime_layout" + android:layout_below="@id/tabs" > + </android.support.v4.view.ViewPager> + <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" + android:layout_marginBottom="5dp" + android:layout_marginTop="5dp" android:padding="5dp" android:scaleType="fitXY" - android:src="@drawable/horizontal_divider" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/> - - <TextView - android:id="@+id/txtvFeed" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_alignParentLeft="true" - android:layout_below="@+id/txtvTitle" - android:gravity="center_horizontal"/> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_above="@id/playtime_layout" - android:layout_below="@id/txtvFeed" > - - <ImageView - android:id="@+id/imgvCover" - android:layout_width="200dp" - android:layout_height="200dp" - android:layout_gravity="center" - android:layout_weight="1" - android:gravity="center" /> - </LinearLayout> + android:src="@drawable/horizontal_divider" /> </RelativeLayout>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 1c8f382a1..f86a755b4 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -68,5 +68,6 @@ <string name="error_msg_prefix">An error occured:</string> <string name="download_error_connection_error">Connection error</string> <string name="txtvfeedurl_label">Type in the URL of the Feed here:</string> + <string name="cover_label">Cover</string> </resources>
\ No newline at end of file diff --git a/src/de/podfetcher/activity/MediaplayerActivity.java b/src/de/podfetcher/activity/MediaplayerActivity.java index 38f168632..5e9f90aa5 100644 --- a/src/de/podfetcher/activity/MediaplayerActivity.java +++ b/src/de/podfetcher/activity/MediaplayerActivity.java @@ -14,6 +14,11 @@ import android.media.MediaPlayer; import android.os.AsyncTask; import android.os.Bundle; import android.os.IBinder; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.ViewPager; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; @@ -28,17 +33,21 @@ import android.widget.VideoView; import android.widget.ViewSwitcher; import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.view.Menu; +import com.viewpagerindicator.TabPageIndicator; import de.podfetcher.PodcastApp; import de.podfetcher.R; import de.podfetcher.feed.FeedManager; import de.podfetcher.feed.FeedMedia; +import de.podfetcher.fragment.CoverFragment; +import de.podfetcher.fragment.ItemDescriptionFragment; import de.podfetcher.service.PlaybackService; import de.podfetcher.service.PlayerStatus; import de.podfetcher.util.Converter; -public class MediaplayerActivity extends SherlockActivity implements +public class MediaplayerActivity extends SherlockFragmentActivity implements SurfaceHolder.Callback { private final String TAG = "MediaplayerActivity"; @@ -57,9 +66,11 @@ public class MediaplayerActivity extends SherlockActivity implements private FeedManager manager; // Widgets - private TextView txtvTitle; - private TextView txtvFeed; - private ImageView imgvCover; + private CoverFragment coverFragment; + private ItemDescriptionFragment descriptionFragment; + private ViewPager viewpager; + private TabPageIndicator tabs; + private MediaPlayerPagerAdapter pagerAdapter; private VideoView videoview; private TextView txtvStatus; private TextView txtvPosition; @@ -200,7 +211,6 @@ public class MediaplayerActivity extends SherlockActivity implements break; case STOPPED: setStatusMsg(R.string.player_stopped_msg, View.VISIBLE); - imgvCover.setImageBitmap(null); break; case PREPARED: loadMediaInfo(); @@ -261,10 +271,8 @@ public class MediaplayerActivity extends SherlockActivity implements getSupportActionBar().setSubtitle(media.getItem().getTitle()); getSupportActionBar().setTitle( media.getItem().getFeed().getTitle()); - imgvCover.setImageBitmap(media.getItem().getFeed().getImage() - .getImageBitmap()); - txtvTitle.setText(media.getItem().getTitle()); - txtvFeed.setText(media.getItem().getFeed().getTitle()); + pagerAdapter.notifyDataSetChanged(); + } txtvPosition.setText(Converter.getDurationStringLong((player @@ -287,6 +295,8 @@ public class MediaplayerActivity extends SherlockActivity implements butRev = (ImageButton) findViewById(R.id.butRev); butFF = (ImageButton) findViewById(R.id.butFF); + // SEEKBAR SETUP + sbPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int duration; float prog; @@ -319,6 +329,8 @@ public class MediaplayerActivity extends SherlockActivity implements } }); + // BUTTON SETUP + butPlay.setOnClickListener(playbuttonListener); butFF.setOnClickListener(new OnClickListener() { @@ -339,12 +351,16 @@ public class MediaplayerActivity extends SherlockActivity implements } }); + // PORTRAIT ORIENTATION SETUP + if (orientation == Configuration.ORIENTATION_PORTRAIT) { - imgvCover = (ImageView) findViewById(R.id.imgvCover); txtvStatus = (TextView) findViewById(R.id.txtvStatus); - txtvTitle = (TextView) findViewById(R.id.txtvTitle); - txtvFeed = (TextView) findViewById(R.id.txtvFeed); - + viewpager = (ViewPager) findViewById(R.id.viewpager); + tabs = (TabPageIndicator) findViewById(R.id.tabs); + pagerAdapter = new MediaPlayerPagerAdapter( + getSupportFragmentManager(), 2, this); + viewpager.setAdapter(pagerAdapter); + tabs.setViewPager(viewpager); } else { setTheme(R.style.Theme_Sherlock_Light_NoActionBar); videoview = (VideoView) findViewById(R.id.videoview); @@ -458,4 +474,62 @@ public class MediaplayerActivity extends SherlockActivity implements holderCreated = false; } + public static class MediaPlayerPagerAdapter extends FragmentStatePagerAdapter { + private int numItems; + private MediaplayerActivity activity; + + private static final int POS_COVER = 0; + private static final int POS_DESCR = 1; + private static final int POS_CHAPTERS = 2; + + public MediaPlayerPagerAdapter(FragmentManager fm, int numItems, + MediaplayerActivity activity) { + super(fm); + this.numItems = numItems; + this.activity = activity; + } + + @Override + public Fragment getItem(int position) { + if (activity.media != null) { + switch (position) { + case POS_COVER: + activity.coverFragment = CoverFragment.newInstance(activity.media.getItem()); + return activity.coverFragment; + case POS_DESCR: + activity.descriptionFragment = ItemDescriptionFragment + .newInstance(activity.media.getItem()); + return activity.descriptionFragment; + default: + return CoverFragment.newInstance(null); + } + } else { + return CoverFragment.newInstance(null); + } + } + + @Override + public CharSequence getPageTitle(int position) { + switch (position) { + case POS_COVER: + return activity.getString(R.string.cover_label); + case POS_DESCR: + return activity.getString(R.string.description_label); + default: + return super.getPageTitle(position); + } + } + + @Override + public int getCount() { + return numItems; + } + + @Override + public int getItemPosition(Object object) { + return POSITION_NONE; + } + + } + } diff --git a/src/de/podfetcher/fragment/CoverFragment.java b/src/de/podfetcher/fragment/CoverFragment.java new file mode 100644 index 000000000..81a42dcec --- /dev/null +++ b/src/de/podfetcher/fragment/CoverFragment.java @@ -0,0 +1,89 @@ +package de.podfetcher.fragment; + +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.actionbarsherlock.app.SherlockFragment; + +import de.podfetcher.R; +import de.podfetcher.feed.Feed; +import de.podfetcher.feed.FeedItem; +import de.podfetcher.feed.FeedManager; +import de.podfetcher.feed.FeedMedia; + +/** Displays the cover and the title of a FeedItem. */ +public class CoverFragment extends SherlockFragment { + private static final String TAG = "CoverFragment"; + private static final String ARG_FEED_ID = "arg.feedId"; + private static final String ARG_FEEDITEM_ID = "arg.feedItem"; + + private FeedMedia media; + + private TextView txtvTitle; + private TextView txtvFeed; + private ImageView imgvCover; + + public static CoverFragment newInstance(FeedItem item) { + CoverFragment f = new CoverFragment(); + if (item != null) { + Bundle args = new Bundle(); + args.putLong(ARG_FEED_ID, item.getFeed().getId()); + args.putLong(ARG_FEEDITEM_ID, item.getId()); + f.setArguments(args); + } + return f; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + FeedManager manager = FeedManager.getInstance(); + FeedItem item = null; + Bundle args = getArguments(); + if (args != null) { + long feedId = args.getLong(ARG_FEED_ID, -1); + long itemId = args.getLong(ARG_FEEDITEM_ID, -1); + if (feedId != -1 && itemId != -1) { + Feed feed = manager.getFeed(feedId); + item = manager.getFeedItem(itemId, feed); + media = item.getMedia(); + } else { + Log.e(TAG, TAG + " was called with invalid arguments"); + } + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View root = inflater.inflate(R.layout.cover_fragment, container, false); + txtvTitle = (TextView) root.findViewById(R.id.txtvTitle); + txtvFeed = (TextView) root.findViewById(R.id.txtvFeed); + imgvCover = (ImageView) root.findViewById(R.id.imgvCover); + return root; + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + if (media != null) { + loadMediaInfo(); + } else { + Log.w(TAG, "Unable to load media info: media was null"); + } + } + + private void loadMediaInfo() { + imgvCover.setImageBitmap(media.getItem().getFeed().getImage() + .getImageBitmap()); + txtvTitle.setText(media.getItem().getTitle()); + txtvFeed.setText(media.getItem().getFeed().getTitle()); + } + +} |