Added viewpager to mediaplayeractivity
This commit is contained in:
parent
2cf9f5045b
commit
3932e09089
|
@ -30,7 +30,7 @@
|
||||||
<activity android:name="de.podfetcher.activity.ItemviewActivity"/>
|
<activity android:name="de.podfetcher.activity.ItemviewActivity"/>
|
||||||
<activity android:name="de.podfetcher.activity.DownloadActivity"
|
<activity android:name="de.podfetcher.activity.DownloadActivity"
|
||||||
android:label="@string/downloads_label"/>
|
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.DownloadService" />
|
||||||
<service android:enabled="true" android:name="de.podfetcher.service.PlaybackService" >
|
<service android:enabled="true" android:name="de.podfetcher.service.PlaybackService" >
|
||||||
|
|
|
@ -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>
|
|
@ -4,16 +4,11 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<TextView
|
<com.viewpagerindicator.TabPageIndicator
|
||||||
android:id="@+id/txtvTitle"
|
android:id="@+id/tabs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true" />
|
||||||
android:layout_marginTop="20dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:textSize="18dp"
|
|
||||||
android:textStyle="bold" >
|
|
||||||
</TextView>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/player_control"
|
android:id="@+id/player_control"
|
||||||
|
@ -71,9 +66,11 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_below="@+id/sbPosition"
|
android:layout_below="@+id/sbPosition"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:src="@drawable/horizontal_divider" android:layout_marginBottom="5dp" android:layout_marginTop="5dp"/>
|
android:src="@drawable/horizontal_divider" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/playtime_layout"
|
android:id="@+id/playtime_layout"
|
||||||
|
@ -106,36 +103,23 @@
|
||||||
android:visibility="invisible" />
|
android:visibility="invisible" />
|
||||||
</RelativeLayout>
|
</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
|
<ImageView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
android:padding="5dp"
|
android:padding="5dp"
|
||||||
android:scaleType="fitXY"
|
android:scaleType="fitXY"
|
||||||
android:src="@drawable/horizontal_divider" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/>
|
android:src="@drawable/horizontal_divider" />
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
|
@ -68,5 +68,6 @@
|
||||||
<string name="error_msg_prefix">An error occured:</string>
|
<string name="error_msg_prefix">An error occured:</string>
|
||||||
<string name="download_error_connection_error">Connection error</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="txtvfeedurl_label">Type in the URL of the Feed here:</string>
|
||||||
|
<string name="cover_label">Cover</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -14,6 +14,11 @@ import android.media.MediaPlayer;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
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.util.Log;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
|
@ -28,17 +33,21 @@ import android.widget.VideoView;
|
||||||
import android.widget.ViewSwitcher;
|
import android.widget.ViewSwitcher;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.viewpagerindicator.TabPageIndicator;
|
||||||
|
|
||||||
import de.podfetcher.PodcastApp;
|
import de.podfetcher.PodcastApp;
|
||||||
import de.podfetcher.R;
|
import de.podfetcher.R;
|
||||||
import de.podfetcher.feed.FeedManager;
|
import de.podfetcher.feed.FeedManager;
|
||||||
import de.podfetcher.feed.FeedMedia;
|
import de.podfetcher.feed.FeedMedia;
|
||||||
|
import de.podfetcher.fragment.CoverFragment;
|
||||||
|
import de.podfetcher.fragment.ItemDescriptionFragment;
|
||||||
import de.podfetcher.service.PlaybackService;
|
import de.podfetcher.service.PlaybackService;
|
||||||
import de.podfetcher.service.PlayerStatus;
|
import de.podfetcher.service.PlayerStatus;
|
||||||
import de.podfetcher.util.Converter;
|
import de.podfetcher.util.Converter;
|
||||||
|
|
||||||
public class MediaplayerActivity extends SherlockActivity implements
|
public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||||
SurfaceHolder.Callback {
|
SurfaceHolder.Callback {
|
||||||
|
|
||||||
private final String TAG = "MediaplayerActivity";
|
private final String TAG = "MediaplayerActivity";
|
||||||
|
@ -57,9 +66,11 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
private FeedManager manager;
|
private FeedManager manager;
|
||||||
|
|
||||||
// Widgets
|
// Widgets
|
||||||
private TextView txtvTitle;
|
private CoverFragment coverFragment;
|
||||||
private TextView txtvFeed;
|
private ItemDescriptionFragment descriptionFragment;
|
||||||
private ImageView imgvCover;
|
private ViewPager viewpager;
|
||||||
|
private TabPageIndicator tabs;
|
||||||
|
private MediaPlayerPagerAdapter pagerAdapter;
|
||||||
private VideoView videoview;
|
private VideoView videoview;
|
||||||
private TextView txtvStatus;
|
private TextView txtvStatus;
|
||||||
private TextView txtvPosition;
|
private TextView txtvPosition;
|
||||||
|
@ -200,7 +211,6 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
break;
|
break;
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
setStatusMsg(R.string.player_stopped_msg, View.VISIBLE);
|
setStatusMsg(R.string.player_stopped_msg, View.VISIBLE);
|
||||||
imgvCover.setImageBitmap(null);
|
|
||||||
break;
|
break;
|
||||||
case PREPARED:
|
case PREPARED:
|
||||||
loadMediaInfo();
|
loadMediaInfo();
|
||||||
|
@ -261,10 +271,8 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
getSupportActionBar().setSubtitle(media.getItem().getTitle());
|
getSupportActionBar().setSubtitle(media.getItem().getTitle());
|
||||||
getSupportActionBar().setTitle(
|
getSupportActionBar().setTitle(
|
||||||
media.getItem().getFeed().getTitle());
|
media.getItem().getFeed().getTitle());
|
||||||
imgvCover.setImageBitmap(media.getItem().getFeed().getImage()
|
pagerAdapter.notifyDataSetChanged();
|
||||||
.getImageBitmap());
|
|
||||||
txtvTitle.setText(media.getItem().getTitle());
|
|
||||||
txtvFeed.setText(media.getItem().getFeed().getTitle());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
txtvPosition.setText(Converter.getDurationStringLong((player
|
txtvPosition.setText(Converter.getDurationStringLong((player
|
||||||
|
@ -287,6 +295,8 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
butRev = (ImageButton) findViewById(R.id.butRev);
|
butRev = (ImageButton) findViewById(R.id.butRev);
|
||||||
butFF = (ImageButton) findViewById(R.id.butFF);
|
butFF = (ImageButton) findViewById(R.id.butFF);
|
||||||
|
|
||||||
|
// SEEKBAR SETUP
|
||||||
|
|
||||||
sbPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
sbPosition.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
|
||||||
int duration;
|
int duration;
|
||||||
float prog;
|
float prog;
|
||||||
|
@ -319,6 +329,8 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// BUTTON SETUP
|
||||||
|
|
||||||
butPlay.setOnClickListener(playbuttonListener);
|
butPlay.setOnClickListener(playbuttonListener);
|
||||||
|
|
||||||
butFF.setOnClickListener(new OnClickListener() {
|
butFF.setOnClickListener(new OnClickListener() {
|
||||||
|
@ -339,12 +351,16 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
// PORTRAIT ORIENTATION SETUP
|
||||||
imgvCover = (ImageView) findViewById(R.id.imgvCover);
|
|
||||||
txtvStatus = (TextView) findViewById(R.id.txtvStatus);
|
|
||||||
txtvTitle = (TextView) findViewById(R.id.txtvTitle);
|
|
||||||
txtvFeed = (TextView) findViewById(R.id.txtvFeed);
|
|
||||||
|
|
||||||
|
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
txtvStatus = (TextView) findViewById(R.id.txtvStatus);
|
||||||
|
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 {
|
} else {
|
||||||
setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
|
setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
|
||||||
videoview = (VideoView) findViewById(R.id.videoview);
|
videoview = (VideoView) findViewById(R.id.videoview);
|
||||||
|
@ -458,4 +474,62 @@ public class MediaplayerActivity extends SherlockActivity implements
|
||||||
holderCreated = false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue