Skip to content

Commit

Permalink
Merge pull request #31 from learning-layers/integration
Browse files Browse the repository at this point in the history
Release v1.0.4.
  • Loading branch information
lnikkila committed Feb 4, 2015
2 parents 314d9ed + 80877ff commit 009bd4e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import android.view.MenuItem;
import android.widget.Toast;

import com.bugsnag.android.Bugsnag;
import com.google.gson.JsonObject;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import fi.aalto.legroup.achso.R;
import fi.aalto.legroup.achso.app.App;
import fi.aalto.legroup.achso.authentication.LoginActivity;
Expand Down Expand Up @@ -65,6 +65,9 @@ public class BrowserActivity extends ActionBarActivity {
// been recorded.
private VideoCreatorService.VideoBuilder videoBuilder;

// URI to the file to which the video should be written.
private Uri videoFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -192,14 +195,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case REQUEST_RECORD_VIDEO:
case REQUEST_CHOOSE_VIDEO:
if (resultCode == RESULT_OK) {
createVideo(data.getData());
createVideo(data);
}

break;

// FIXME: Default is not good here
Expand All @@ -213,12 +215,11 @@ private void recordVideo() {
App.locationManager.startLocationUpdates();

videoBuilder = VideoCreatorService.build();
videoFile = Uri.fromFile(VideoCreatorService.getStorageVideoFile(videoBuilder));

// TODO: Keep using URIs instead of files
File videoFile = VideoCreatorService.getStorageVideoFile(videoBuilder);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(videoFile));
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoFile);

startActivityForResult(intent, REQUEST_RECORD_VIDEO);
}
Expand Down Expand Up @@ -246,10 +247,15 @@ private void chooseVideo() {
}
}

private void createVideo(final Uri contentUri) {
if (contentUri == null) {
Bugsnag.notify(new IllegalArgumentException("Result contained a null URI."));
return;
private void createVideo(@Nullable Intent resultData) {
final Uri contentUri;

// Some camera apps (looking at you, Samsung) don't return any data if the EXTRA_OUTPUT
// flag is set. If this is the case, let's just pass in the URI in EXTRA_OUTPUT.
if (resultData == null) {
contentUri = videoFile;
} else {
contentUri = resultData.getData();
}

GenreDialogFragment fragment = new GenreDialogFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private void populateVideoInformation() {
toolbar.setSubtitle(video.getGenre());
}

private void refreshRenderedAnnotations() {
private void refreshAnnotations() {
List<Annotation> annotations = video.getAnnotations();
List<Integer> markers = new ArrayList<>();

Expand Down Expand Up @@ -302,7 +302,7 @@ public void createAnnotation(PointF position) {

editAnnotation(annotation);

refreshRenderedAnnotations();
refreshAnnotations();
}

@Override
Expand All @@ -312,10 +312,17 @@ public void moveAnnotation(Annotation annotation, PointF position) {
if (!video.save()) {
Toast.makeText(this, R.string.storage_error, Toast.LENGTH_LONG).show();
}

refreshAnnotations();
}

@Override
public void editAnnotation(final Annotation annotation) {
// Allow editing annotations only when paused
if (playerFragment.getState() != VideoPlayerFragment.State.PAUSED) {
return;
}

showAnnotationControls();

annotationText.setText(annotation.getText());
Expand All @@ -332,7 +339,7 @@ public void onClick(View view) {
Toast.LENGTH_LONG).show();
}

refreshRenderedAnnotations();
refreshAnnotations();

hideAnnotationControls();
}
Expand All @@ -348,7 +355,7 @@ public void onClick(View view) {
Toast.LENGTH_LONG).show();
}

refreshRenderedAnnotations();
refreshAnnotations();

hideAnnotationControls();
}
Expand Down Expand Up @@ -379,6 +386,20 @@ private void hideAnnotationControls() {
anchorSubtitleContainerTo(playbackControls);
}

private void enableControls() {
seekBar.setEnabled(true);
playPauseButton.setEnabled(true);
playPauseButton.setImageAlpha(0xFF);
}

private void disableControls() {
seekBar.setEnabled(false);
playPauseButton.setEnabled(false);

// Material design spec specifies 30% alpha for disabled icons
playPauseButton.setImageAlpha(0x4D);
}

/**
* Fired when the player fragment changes state.
*/
Expand All @@ -391,10 +412,11 @@ public void onPlaybackStateChanged(VideoPlayerFragment.State state) {
seekBar.setProgress((int) playerFragment.getPlaybackPosition());
seekBarUpdater.run();

refreshRenderedAnnotations();
refreshAnnotations();
break;

case PLAYING:
enableControls();
hideControlsOverlay();
playPauseButton.setImageResource(R.drawable.ic_action_pause);
break;
Expand All @@ -403,6 +425,11 @@ public void onPlaybackStateChanged(VideoPlayerFragment.State state) {
showControlsOverlay();
playPauseButton.setImageResource(R.drawable.ic_action_play);
break;

case ANNOTATION_PAUSED:
disableControls();
playPauseButton.setImageResource(R.drawable.ic_action_play);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ public void prepare(Uri videoUri, AnnotationEditor annotationEditor) {
* We're not prepared unless both ExoPlayer and the surface are ready.
*/
private void finishPreparing() {
if (!(isExoPlayerPrepared && isSurfacePrepared)) return;
if (!(isExoPlayerPrepared && isSurfacePrepared)) {
return;
}

SurfaceTexture texture = videoSurface.getSurfaceTexture();
Surface surface = new Surface(texture);
Expand Down Expand Up @@ -409,6 +411,8 @@ public void onAnnotationPauseStart(int duration) {
ObjectAnimator.ofInt(pauseProgress, "progress", 0, pauseProgress.getMax())
.setDuration(duration)
.start();

setState(State.ANNOTATION_PAUSED);
}

/**
Expand All @@ -417,13 +421,18 @@ public void onAnnotationPauseStart(int duration) {
@Override
public void onAnnotationPauseEnd() {
pauseProgress.setVisibility(View.GONE);

if (state == State.ANNOTATION_PAUSED) {
setState(State.PLAYING);
}
}

public static enum State {
UNPREPARED,
PREPARED,
PLAYING,
PAUSED
PAUSED,
ANNOTATION_PAUSED
}

public static interface PlaybackStateListener {
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/fi/aalto/legroup/achso/views/Marker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.GestureDetector;
Expand Down Expand Up @@ -72,16 +71,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(width, height);
}

@Override
@SuppressWarnings("deprecation")
public void setBackground(Drawable background) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
super.setBackgroundDrawable(background);
} else {
super.setBackground(background);
}
}

@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
Expand Down

0 comments on commit 009bd4e

Please sign in to comment.