replace inline video player with a separate activity

This commit is contained in:
Andrew Dolgov 2015-07-10 09:47:35 +03:00
parent 5c0768b40d
commit 5e5c76c7e2
6 changed files with 224 additions and 76 deletions

View File

@ -21,9 +21,9 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:theme="@android:style/Theme.NoDisplay"
android:name=".LaunchActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:theme="@android:style/Theme.NoDisplay" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -40,7 +40,7 @@
</activity>
<activity
android:name=".MasterActivity"
android:label="@string/app_name">
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
@ -48,7 +48,7 @@
<activity
android:name=".DetailActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name">
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
@ -70,11 +70,11 @@
</activity>
<activity
android:name=".offline.OfflineMasterActivity"
android:label="@string/app_name">
android:label="@string/app_name" >
</activity>
<activity
android:name=".offline.OfflineDetailActivity"
android:label="@string/app_name">
android:label="@string/app_name" >
</activity>
<activity
android:name=".share.ShareActivity"
@ -256,13 +256,17 @@
android:name=".ArticleImagesPagerActivity"
android:label="Article Images" >
</activity>
<activity android:name="org.acra.CrashReportDialog"
android:theme="@style/DarkDialogTheme"
android:launchMode="singleInstance"
<activity
android:name="org.acra.CrashReportDialog"
android:excludeFromRecents="true"
android:finishOnTaskLaunch="true" />
android:finishOnTaskLaunch="true"
android:launchMode="singleInstance"
android:theme="@style/DarkDialogTheme" />
<activity
android:name=".VideoPlayerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/title_activity_video_player" >
</activity>
</application>
</manifest>

View File

@ -1037,7 +1037,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
try {
Element source = video.select("source").first();
String streamUri = source.attr("src");
final String streamUri = source.attr("src");
String posterUri = video.attr("poster");
if (streamUri != null && posterUri != null) {
@ -1056,11 +1056,22 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.flavorImageView.setVisibility(View.VISIBLE);
holder.flavorVideoPlayView.setVisibility(View.VISIBLE);
ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_VIDEO_PLAYER");
holder.flavorImageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//
Intent intent = new Intent(m_activity, VideoPlayerActivity.class);
intent.putExtra("streamUri", streamUri);
intent.putExtra("title", article.title);
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(m_activity,
holder.flavorImageView, // The view which starts the transition
"TRANSITION:ARTICLE_VIDEO_PLAYER" // The transitionName of the view were transitioning to
);
ActivityCompat.startActivity(m_activity, intent, options.toBundle());
}
});
@ -1075,68 +1086,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
/* if (m_prefs.getBoolean("enable_headlines_video", false) && article.articleDoc != null && holder.flavorVideoView != null) {
Element source = article.articleDoc.select("video > source").first();
if (source != null) {
try {
Uri streamUri = Uri.parse(source.attr("src"));
if (streamUri != null) {
videoFound = true;
holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorVideoView.setVisibility(View.VISIBLE);
holder.flavorImageView.setVisibility(View.GONE);
holder.flavorVideoPlayView.setVisibility(View.VISIBLE);
if (!streamUri.equals(holder.flavorVideoView.getTag())) {
holder.flavorVideoView.setTag(streamUri);
holder.flavorVideoView.setVideoURI(streamUri);
holder.flavorVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//mp.setLooping(true);
mp.seekTo(1000);
}
});
holder.flavorVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.seekTo(0);
}
});
holder.flavorVideoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
VideoView video = (VideoView) v;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (video.isPlaying()) {
video.pause();
holder.flavorVideoPlayView.setVisibility(View.VISIBLE);
} else {
video.start();
holder.flavorVideoPlayView.setVisibility(View.GONE);
}
}
return true;
}
});
}
}
} catch (Exception e) {
e.printStackTrace();
videoFound = false;
}
}
} */
if (!videoFound && showFlavorImage && holder.flavorImageView != null) {
holder.flavorImageArrow.setVisibility(View.GONE);

View File

@ -0,0 +1,146 @@
package org.fox.ttrss;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoPlayerActivity extends CommonActivity {
private final String TAG = this.getClass().getSimpleName();
private String m_streamUri;
@Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.DarkTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (!isPortrait())
getSupportActionBar().hide();
VideoView videoView = (VideoView) findViewById(R.id.video_player);
registerForContextMenu(videoView); // doesn't work :[
setTitle(getIntent().getStringExtra("title"));
if (savedInstanceState == null) {
m_streamUri = getIntent().getStringExtra("streamUri");
} else {
m_streamUri = savedInstanceState.getString("streamUri");
}
final MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse(m_streamUri));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.seekTo(0);
}
});
videoView.start();
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (!isPortrait())
getSupportActionBar().hide();
else
getSupportActionBar().show();
}
@Override
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putString("streamUri", m_streamUri);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_video_player, menu);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
getMenuInflater().inflate(R.menu.activity_video_player, menu);
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return onContextItemSelected(item); // this is really bad :()
}
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
case R.id.article_vid_open:
if (m_streamUri != null) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(m_streamUri));
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
toast(R.string.error_other_error);
}
}
return true;
case R.id.article_vid_share:
if (m_streamUri != null) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/mp4");
intent.putExtra(Intent.EXTRA_SUBJECT, m_streamUri);
intent.putExtra(Intent.EXTRA_TEXT, m_streamUri);
startActivity(Intent.createChooser(intent, m_streamUri));
}
return true;
default:
Log.d(TAG, "onContextItemSelected, unhandled id=" + item.getItemId());
return super.onContextItemSelected(item);
}
}
}

View File

@ -0,0 +1,30 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="?android:colorBackground"
tools:context="org.fox.ttrss.VideoPlayerActivity">
<!--
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="@+id/video_player"
android:transitionName="TRANSITION:ARTICLE_VIDEO_PLAYER" />
</FrameLayout>
<include layout="@layout/toolbar" android:id="@+id/toolbar" />
</RelativeLayout>

View File

@ -0,0 +1,15 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="org.fox.ttrss.VideoPlayerActivity">
<item
android:id="@+id/article_vid_open"
app:showAsAction=""
android:title="Open video"/>
<item
android:id="@+id/article_vid_share"
android:icon="@drawable/ic_share"
app:showAsAction="ifRoom"
android:title="Share video"/>
</menu>

View File

@ -224,4 +224,8 @@
<string name="prefs_widget_show_fresh">Show Fresh articles</string>
<string name="prefs_widget_show_fresh_summary">Instead of total unread display amount of Fresh articles</string>
<string name="prefs_widget">Widget</string>
<string name="title_activity_video_player">Video Player</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
</resources>