|
@@ -24,14 +24,17 @@ import com.xplora.xpchat.observer.Listener;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
-public class VideoFragment extends DialogFragment implements Listener.PlayListener {
|
|
|
+public class VideoFragment extends DialogFragment implements Listener.PlayListener, View.OnClickListener {
|
|
|
public String TAG = "losion / xpchat :" + getClass().getSimpleName();
|
|
|
private Context mContext = null;
|
|
|
private int position;
|
|
|
private MessageBean bean;
|
|
|
private MediaPlayerUtils mMediaPlayerUtils = null;
|
|
|
private SurfaceHolder mSurfaceHolder = null;
|
|
|
- private ImageView mActionButton = null;
|
|
|
+ private ImageButton mPlayPauseBtn = null;
|
|
|
+ private ImageButton mShareBtn = null;
|
|
|
+ private ImageButton mSaveFileBtn = null;
|
|
|
+ private ImageButton mCloseBtn = null;
|
|
|
|
|
|
public static VideoFragment newInstance(Context context) {
|
|
|
VideoFragment fragment = new VideoFragment();
|
|
@@ -50,13 +53,20 @@ public class VideoFragment extends DialogFragment implements Listener.PlayListen
|
|
|
getDialog().getWindow().requestFeature(Window.FEATURE_SWIPE_TO_DISMISS);
|
|
|
View rootView = inflater.inflate(R.layout.chat_fragment_video, container, false);
|
|
|
SurfaceView surfaceView = (SurfaceView) rootView.findViewById(R.id.surfaceView);
|
|
|
- mActionButton = (ImageView)rootView.findViewById(R.id.mActionBtn);
|
|
|
- TextView noFileText = (TextView)rootView.findViewById(R.id.mNoFileText);
|
|
|
-
|
|
|
mSurfaceHolder = surfaceView.getHolder();
|
|
|
- mActionButton.setOnClickListener(onActionClick);
|
|
|
+
|
|
|
+ mPlayPauseBtn = (ImageButton) rootView.findViewById(R.id.mPlayPauseBtn);
|
|
|
+ mShareBtn = (ImageButton)rootView.findViewById(R.id.mShareBtn);
|
|
|
+ mSaveFileBtn = (ImageButton)rootView.findViewById(R.id.mSaveFileBtn);
|
|
|
+ mCloseBtn = (ImageButton)rootView.findViewById(R.id.mCloseBtn);
|
|
|
+
|
|
|
+ mPlayPauseBtn.setOnClickListener(this);
|
|
|
+ mShareBtn.setOnClickListener(this);
|
|
|
+ mSaveFileBtn.setOnClickListener(this);
|
|
|
+ mCloseBtn.setOnClickListener(this);
|
|
|
initVideo();
|
|
|
|
|
|
+ TextView noFileText = (TextView)rootView.findViewById(R.id.mNoFileText);
|
|
|
Uri uri = Uri.parse(bean.videoPath);
|
|
|
if (noFileText != null) {
|
|
|
noFileText.setVisibility(uri == null ? View.VISIBLE : View.GONE);
|
|
@@ -77,12 +87,26 @@ public class VideoFragment extends DialogFragment implements Listener.PlayListen
|
|
|
}, 30);
|
|
|
}
|
|
|
|
|
|
- View.OnClickListener onActionClick = new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- actionButtonClick();
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v == mCloseBtn) {
|
|
|
+ dismissAllowingStateLoss();
|
|
|
+ } else if (v == mShareBtn) {
|
|
|
+ Listener.ClickButtonListener listener = (Listener.ClickButtonListener)mContext;
|
|
|
+ listener.onShareFile(position, bean);
|
|
|
+ } else if (v == mSaveFileBtn) {
|
|
|
+ Listener.ClickButtonListener listener = (Listener.ClickButtonListener)mContext;
|
|
|
+ listener.onSaveFile(position, bean);
|
|
|
+ } else if (v == mPlayPauseBtn) {
|
|
|
+ if (mMediaPlayerUtils.getIsPlaying()) {
|
|
|
+ mMediaPlayerUtils.mediaPause();
|
|
|
+ setButtonStatus(false);
|
|
|
+ } else {
|
|
|
+ mMediaPlayerUtils.mediaStart();
|
|
|
+ setButtonStatus(true);
|
|
|
+ }
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
|
|
|
MediaPlayer.OnCompletionListener onPlayCompletion = new MediaPlayer.OnCompletionListener() {
|
|
|
@Override
|
|
@@ -92,19 +116,9 @@ public class VideoFragment extends DialogFragment implements Listener.PlayListen
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- private void actionButtonClick() {
|
|
|
- if (mMediaPlayerUtils.getIsPlaying()) {
|
|
|
- mMediaPlayerUtils.mediaPause();
|
|
|
- setButtonStatus(false);
|
|
|
- } else {
|
|
|
- mMediaPlayerUtils.mediaStart();
|
|
|
- setButtonStatus(true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void setButtonStatus(boolean isPlaying) {
|
|
|
- int resId = isPlaying ? R.drawable.icon_video_pause : R.drawable.icon_video_play;
|
|
|
- mActionButton.setImageResource(resId);
|
|
|
+ int resId = isPlaying ? R.drawable.action_pause : R.drawable.action_play;
|
|
|
+ mPlayPauseBtn.setBackgroundResource(resId);
|
|
|
}
|
|
|
|
|
|
public void setItemInfo(int position, MessageBean bean) {
|