/**
* Copyright 2009 Pau Haro
*
* This file is part of eTracks.
*
* eTracks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* eTracks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with eTracks. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.etracks.gui;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.VideoView;
import com.etracks.R;
import com.etracks.domini.CtrlVideo;
public class VideoActivity extends Activity {
// constants
private static final int RECORD_VIDEO = 0;
// attributes
private CtrlVideo videoCtrl;
private long routeId;
private long videoId;
private VideoView videoView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routeId = this.getIntent().getLongExtra("route_id", -1); // XXX valor per defecte?
videoId = this.getIntent().getLongExtra("video_id", -1);
boolean first = false;
if (videoId == -1) {
videoCtrl = new CtrlVideo(routeId, this);
videoId = videoCtrl.getId();
newVideo(videoId);
first = true;
}
else
videoCtrl = new CtrlVideo(routeId, videoId, this);
// GUI
setContentView(R.layout.video);
// Text inputs initialized
//final TextView videoPath = (TextView) findViewById(R.id.video_path); // DEBUG
//videoPath.setText(videoCtrl.getPath());
final EditText videoDescEdit = (EditText) findViewById(R.id.video_desc);
videoDescEdit.setText(videoCtrl.getDesc());
// Video display
videoView = (VideoView) findViewById(R.id.video_display);
if (!first) playVideo();
// Buttons
Button saveButton = (Button)this.findViewById(R.id.save_video);
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
videoCtrl.save(videoDescEdit.getText().toString());
Intent intent = new Intent();
intent.putExtra("msg", getString(R.string.video_saved));
setResult(RESULT_OK, intent);
finish();
}
});
// Button changeButton = (Button)this.findViewById(R.id.change_video);
// changeButton.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// newVideo(videoId);
// }
// });
Button deleteButton = (Button)this.findViewById(R.id.delete_video);
deleteButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
videoCtrl.delete();
Intent intent = new Intent();
intent.putExtra("msg", getString(R.string.video_deleted));
setResult(RESULT_OK, intent);
finish();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case RECORD_VIDEO:
if (resultCode == RESULT_OK)
playVideo();
break;
default:
break;
}
}
/** Display the activity to record a new video. */
protected void newVideo(long videoId) {
Intent intent = new Intent(VideoActivity.this, CamcorderActivity.class);
intent.putExtra("video_id", videoId);
startActivityForResult(intent, RECORD_VIDEO);
}
/** Set the recorded video to be shown. */
protected void playVideo() {
String path = videoCtrl.getPath();
if (!path.startsWith("http"))
videoView.setVideoPath(path);
else
videoView.setVideoURI(Uri.parse(path));
videoView.setMediaController(new MediaController(this));
//videoView.start(); // autostart not enabled
videoView.requestFocus();
}
}
|