From 0c2548a785fa18b249ccd26a3623f39db2303f26 Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Thu, 10 Aug 2017 00:46:26 -0400 Subject: [PATCH] simplification AND improvement to video obscura features --- app/app.iml | 1 + .../org/witness/ssc/video/FFMPEGWrapper.java | 118 +++-- .../org/witness/ssc/video/RegionTrail.java | 7 +- .../org/witness/ssc/video/VideoEditor.java | 466 +++++++----------- .../main/java/org/witness/sscphase1/Eula.java | 128 ----- .../org/witness/sscphase1/MainActivity.java | 1 - app/src/main/res/layout/videoeditor.xml | 85 +++- app/src/main/res/values/strings.xml | 9 + 8 files changed, 329 insertions(+), 486 deletions(-) delete mode 100644 app/src/main/java/org/witness/sscphase1/Eula.java diff --git a/app/app.iml b/app/app.iml index e3902d2..7662dec 100644 --- a/app/app.iml +++ b/app/app.iml @@ -110,6 +110,7 @@ + diff --git a/app/src/main/java/org/witness/ssc/video/FFMPEGWrapper.java b/app/src/main/java/org/witness/ssc/video/FFMPEGWrapper.java index c2e905e..e52aec3 100644 --- a/app/src/main/java/org/witness/ssc/video/FFMPEGWrapper.java +++ b/app/src/main/java/org/witness/ssc/video/FFMPEGWrapper.java @@ -53,9 +53,9 @@ public void onFinish() {} - public void processVideo(File redactSettingsFile, - ArrayList regionTrails, File inputFile, File outputFile, String format, int mDuration, - int iWidth, int iHeight, int oWidth, int oHeight, int frameRate, int kbitRate, String vcodec, String acodec, ExecuteBinaryResponseHandler listener) throws Exception { + public void processVideo( + ArrayList regionTrails, File inputFile, File outputFile, int frameRate, int mDuration, int mOutputLength, + boolean compressVideo, int obscureVideoAmount, int obscureAudioAmount, ExecuteBinaryResponseHandler listener) throws Exception { DecimalFormat df = new DecimalFormat("####0.00"); @@ -65,46 +65,74 @@ public void processVideo(File redactSettingsFile, alCmds.add("-i"); alCmds.add(inputFile.getCanonicalPath()); + if (mOutputLength > 0) + { + alCmds.add("-t"); + alCmds.add(mOutputLength+""); + } - float widthMod = ((float)oWidth)/((float)iWidth); - float heightMod = ((float)oHeight)/((float)iHeight); - - // writeRedactData(redactSettingsFile, obscureRegionTrails, widthMod, heightMod, mDuration); + if (frameRate > 0) + { + alCmds.add("-r"); + alCmds.add(frameRate+""); + } - alCmds.add("-b:v"); - alCmds.add("1M"); + if (compressVideo) { + alCmds.add("-b:v"); + alCmds.add("500K"); + + } - alCmds.add("-b:a"); - alCmds.add("64k"); + if (obscureAudioAmount > 0) { + alCmds.add("-filter_complex"); + alCmds.add("vibrato=f=" + obscureAudioAmount); - alCmds.add("-vf"); + alCmds.add("-b:a"); + alCmds.add("4K"); + + alCmds.add("-ab"); + alCmds.add("4K"); + + alCmds.add("-ar"); + alCmds.add("11025"); + + alCmds.add("-ac"); + alCmds.add("1"); + } StringBuffer filters = new StringBuffer(); + if (obscureVideoAmount > 0) { + int pixelScale = obscureVideoAmount; + + //scale down and up to fully pixelize + filters.append("scale=iw/" + pixelScale + ":ih/" + pixelScale + ",scale=" + pixelScale + "*iw:" + pixelScale + "*ih:flags=neighbor,"); + } - for (RegionTrail trail : regionTrails) - { - if (trail.isDoTweening()) - { + if (regionTrails.size() == 0) { + //do what? + } + else { + for (RegionTrail trail : regionTrails) { + + if (trail.isDoTweening() && trail.getRegionCount() > 1) { int timeInc = 100; - for (int i = 0; i < mDuration; i = i+timeInc) - { + for (int i = 0; i < mDuration; i = i + timeInc) { ObscureRegion or = trail.getCurrentRegion(i, trail.isDoTweening()); - if (or != null) - { + if (or != null) { - int x = (int)or.getBounds().left; - int y = (int)or.getBounds().top; - int height = (int)or.getBounds().height(); - int width = (int)or.getBounds().width(); + int x = (int) or.getBounds().left; + int y = (int) or.getBounds().top; + int height = (int) or.getBounds().height(); + int width = (int) or.getBounds().width(); String color = "black"; - float timeStart = ((float)or.timeStamp)/1000f; - float timeStop = (((float)or.timeStamp)+100)/1000f; + float timeStart = ((float) or.timeStamp) / 1000f; + float timeStop = (((float) or.timeStamp) + 100) / 1000f; - float timeEnd = ((float)mDuration)/1000f; - timeStop = Math.max(timeStop,timeEnd); + float timeEnd = ((float) mDuration) / 1000f; + timeStop = Math.max(timeStop, timeEnd); filters.append("drawbox=x=" + x + ":y=" + y + ":w=" + width + ":h=" + height @@ -115,18 +143,15 @@ public void processVideo(File redactSettingsFile, } } - } - else - { + } else { - for (Integer orKey : trail.getRegionKeys()) - { + for (Integer orKey : trail.getRegionKeys()) { ObscureRegion or = trail.getRegion(orKey); - int x = (int)or.getBounds().left; - int y = (int)or.getBounds().top; - int height = (int)or.getBounds().height(); - int width = (int)or.getBounds().width(); + int x = (int) or.getBounds().left; + int y = (int) or.getBounds().top; + int height = (int) or.getBounds().height(); + int width = (int) or.getBounds().width(); String color = "black"; filters.append("drawbox=x=" + x + ":y=" + y @@ -134,24 +159,29 @@ public void processVideo(File redactSettingsFile, + ":color=" + color + ":t=max"); - } + } } } + } - Log.d(getClass().getName(),"filters: " + filters.toString()); + if (filters.toString().length() > 0) { + Log.d(getClass().getName(), "filters: " + filters.toString()); - String filterCmd = filters.toString(); + alCmds.add("-vf"); - alCmds.add(filterCmd.substring(0,filterCmd.length()-1)); + String filterCmd = filters.toString(); + + alCmds.add(filterCmd.substring(0, filterCmd.length() - 1)); + } - alCmds.add(outputFile.getCanonicalPath()); + alCmds.add(outputFile.getCanonicalPath()); - String[] cmd = alCmds.toArray(new String[alCmds.size()]); + String[] cmd = alCmds.toArray(new String[alCmds.size()]); - try { + try { FFmpeg ffmpeg = FFmpeg.getInstance(context); diff --git a/app/src/main/java/org/witness/ssc/video/RegionTrail.java b/app/src/main/java/org/witness/ssc/video/RegionTrail.java index 5c28cb8..2893ef1 100644 --- a/app/src/main/java/org/witness/ssc/video/RegionTrail.java +++ b/app/src/main/java/org/witness/ssc/video/RegionTrail.java @@ -78,7 +78,12 @@ public ObscureRegion getRegion (Integer key) { return regionMap.get(key); } - + + public int getRegionCount () + { + return regionMap.size(); + } + public TreeSet getRegionKeys () { TreeSet regionKeys = new TreeSet(regionMap.keySet()); diff --git a/app/src/main/java/org/witness/ssc/video/VideoEditor.java b/app/src/main/java/org/witness/ssc/video/VideoEditor.java index a6d23ed..bdd45ce 100644 --- a/app/src/main/java/org/witness/ssc/video/VideoEditor.java +++ b/app/src/main/java/org/witness/ssc/video/VideoEditor.java @@ -30,6 +30,7 @@ import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.RectF; +import android.graphics.drawable.Drawable; import android.media.MediaMetadataRetriever; import android.media.MediaPlayer; import android.media.MediaPlayer.OnBufferingUpdateListener; @@ -63,6 +64,7 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.MediaController; +import android.widget.SeekBar; import android.widget.Toast; import android.widget.VideoView; @@ -93,7 +95,7 @@ public class VideoEditor extends AppCompatActivity implements OnCompletionListener, OnErrorListener, OnInfoListener, OnBufferingUpdateListener, OnPreparedListener, OnSeekCompleteListener, OnVideoSizeChangedListener, SurfaceHolder.Callback, - MediaController.MediaPlayerControl, OnTouchListener, OnClickListener, + MediaController.MediaPlayerControl, OnTouchListener, InOutPlayheadSeekBarChangeListener, OnActionItemClickListener { public static final String LOGTAG = ObscuraApp.TAG; @@ -110,16 +112,16 @@ public class VideoEditor extends AppCompatActivity implements private final static int HUMAN_OFFSET_BUFFER = 50; ProgressDialog progressDialog; - int completeActionFlag = -1; + int completeActionFlag = 3; Uri originalVideoUri; + Uri currentUri; + boolean mIsPreview = false; File fileExternDir; File redactSettingsFile; File saveFile; File recordingFile; - Random rand = new Random(); - Display currentDisplay; @@ -137,12 +139,6 @@ public class VideoEditor extends AppCompatActivity implements Paint selectedPaint; Bitmap bitmapPixel; - /* - Bitmap bitmapCornerUL; - Bitmap bitmapCornerUR; - Bitmap bitmapCornerLL; - Bitmap bitmapCornerLR; - */ InOutPlayheadSeekBar progressBar; //RegionBarArea regionBarArea; @@ -161,6 +157,9 @@ public class VideoEditor extends AppCompatActivity implements int autoDetectTimeInterval = 300; //ms FFMPEGWrapper ffmpeg; + boolean mCompressVideo = true; + int mObscureAudioAmount = 0; + int mObscureVideoAmount = 0; int timeNudgeOffset = 2; @@ -192,9 +191,6 @@ public void handleMessage(Message msg) { break; case 1: //status - progressDialog.setMessage(msg.getData().getString("status")); - - //progressDialog.setProgress(msg.getData().getInt("progress")); try { if (msg.getData().getString("time") != null) { @@ -239,16 +235,6 @@ public void handleMessage(Message msg) { private boolean mCancelled = false; - QuickAction popupMenu; - ActionItem[] popupMenuItems; - - /* - public static final int CORNER_NONE = 0; - public static final int CORNER_UPPER_LEFT = 1; - public static final int CORNER_LOWER_LEFT = 2; - public static final int CORNER_UPPER_RIGHT = 3; - public static final int CORNER_LOWER_RIGHT = 4; - */ private int mDuration; @@ -268,6 +254,7 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.videoeditor); + if (getIntent() != null) { // Passed in from ObscuraApp originalVideoUri = getIntent().getData(); @@ -294,10 +281,7 @@ public void onCreate(Bundle savedInstanceState) { fileExternDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); - regionsView = (ImageView) this.findViewById(R.id.VideoEditorImageView); - regionsView.setOnTouchListener(this); - - mAutoDetectEnabled = true; //first time do autodetect + mAutoDetectEnabled = false; //first time do autodetect setPrefs(); @@ -307,20 +291,18 @@ public void onCreate(Bundle savedInstanceState) { bitmapPixel = BitmapFactory.decodeResource(getResources(), R.drawable.ic_context_pixelate); - - showAutoDetectDialog(); } catch (RuntimeException re) { Toast.makeText(this, "There was an error with the video file", Toast.LENGTH_LONG).show(); finish(); } } - private void resetMediaPlayer() { + private void resetMediaPlayer(Uri videoUri) { Log.i(LOGTAG, "releasing/loading media Player"); mediaPlayer.release(); - loadMedia(); + loadMedia(videoUri); mediaPlayer.setDisplay(surfaceHolder); @@ -337,9 +319,13 @@ private void resetMediaPlayer() { finish(); } + seekTo(0); + } - private void loadMedia() { + private void loadMedia(Uri uriVideo) { + + currentUri = uriVideo; mediaPlayer = new MediaPlayer(); mediaPlayer.setOnCompletionListener(this); @@ -350,10 +336,10 @@ private void loadMedia() { mediaPlayer.setOnVideoSizeChangedListener(this); mediaPlayer.setOnBufferingUpdateListener(this); - mediaPlayer.setLooping(false); + mediaPlayer.setLooping(true); try { - mediaPlayer.setDataSource(this, originalVideoUri); + mediaPlayer.setDataSource(this, currentUri); } catch (IllegalArgumentException e) { Log.e(LOGTAG, originalVideoUri.toString() + ": " + e.getMessage()); @@ -436,7 +422,7 @@ public boolean onError(MediaPlayer mp, int whatError, int extra) { //if (wasAutoDetect) mAutoDetectEnabled = false; - resetMediaPlayer(); + resetMediaPlayer(originalVideoUri); } else if (whatError == MediaPlayer.MEDIA_ERROR_UNKNOWN) { @@ -473,29 +459,6 @@ public void onPrepared(MediaPlayer mp) { } - private void showAutoDetectDialog() { - DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - beginAutoDetect(); - break; - - case DialogInterface.BUTTON_NEGATIVE: - //start(); - seekTo(1); - break; - } - } - }; - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage("Would you like to detect faces in this video?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); - - } - private void beginAutoDetect() { mAutoDetectEnabled = true; @@ -667,14 +630,14 @@ public void run() { Bitmap bmp = retriever.getFrameAtTime(f * 1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC); if (bmp == null) { - resetMediaPlayer(); + resetMediaPlayer(originalVideoUri); break; } else { autoDetectFrame(bmp, f, FACE_TIME_BUFFER, mDuration, eyesOnly); } } catch (Exception e) { Log.v(LOGTAG, "error occured on frame " + f, e); - loadMedia(); + } } @@ -705,7 +668,7 @@ public void run() { try { if (mediaPlayer != null && mediaPlayer.isPlaying()) { int curr = mediaPlayer.getCurrentPosition(); - // progressBar.setProgress(curr); + progressBar.setProgress(curr); updateRegionDisplay(curr); mHandler.post(this); } @@ -798,17 +761,9 @@ private void displayRegion(ObscureRegion region, boolean selected, int color, St paintingRect.right *= vRatio; paintingRect.top *= vRatio; paintingRect.bottom *= vRatio; - - /* - */ - - - //obscuredPaint.setTextSize(30); - //obscuredPaint.setFakeBoldText(false); if (mode.equals(RegionTrail.OBSCURE_MODE_PIXELATE)) { obscuredPaint.setAlpha(150); - obscuredCanvas.drawBitmap(bitmapPixel, null, paintingRect, obscuredPaint); @@ -882,23 +837,25 @@ public boolean onTouch(View v, MotionEvent event) { if (v == progressBar) { - // It's the progress bar/scrubber - if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { - start(); - } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) { - pause(); - + if (currentUri != originalVideoUri) + { + resetMediaPlayer(originalVideoUri); + seekTo(0); } - - /* - Log.v(LOGTAG,"" + event.getX() + " " + event.getX()/progressBar.getWidth()); - Log.v(LOGTAG,"Seeking To: " + (int)(mDuration*(float)(event.getX()/progressBar.getWidth()))); - Log.v(LOGTAG,"MediaPlayer Position: " + mediaPlayer.getCurrentPosition()); - */ - //int newTime = (int)(mediaPlayer.getDuration()*(float)(event.getX()/progressBar.getWidth())); + else { + + // It's the progress bar/scrubber + if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { + start(); + } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) { + pause(); + + } + - mediaPlayer.seekTo(progressBar.getProgress()); - // Attempt to get the player to update it's view - NOT WORKING + mediaPlayer.seekTo(progressBar.getProgress()); + // Attempt to get the player to update it's view - NOT WORKING + } handled = false; // The progress bar doesn't get it if we have true here } else { @@ -919,12 +876,16 @@ public boolean onTouch(View v, MotionEvent event) { if (newActiveRegion != null) { activeRegionTrail = newActiveRegion.getRegionTrail(); - updateProgressBar(activeRegionTrail); - - if (fingerCount == 1) - inflatePopup(false, (int) x, (int) y); + // updateProgressBar(activeRegionTrail); activeRegion = newActiveRegion; + + if (fingerCount == 3) + { + obscureTrails.remove(activeRegionTrail); + activeRegionTrail = null; + activeRegion = null; + } } else { activeRegion = makeNewRegion(fingerCount, x, y, event, HUMAN_OFFSET_BUFFER); @@ -1030,55 +991,8 @@ private ObscureRegion makeNewRegion(int fingerCount, float x, float y, MotionEve } private void updateProgressBar(RegionTrail rTrail) { - progressBar.setThumbsActive((int) ((double) rTrail.getStartTime() / (double) mDuration * 100), (int) ((double) rTrail.getEndTime() / (double) mDuration * 100)); - - } - /* - public int getRegionCornerMode(ObscureRegion region, float x, float y) - { - if (Math.abs(region.getBounds().left-x) 0) + { + frameRate = 15; + } // Could make some high/low quality presets - ffmpeg.processVideo(redactSettingsFile, obscureTrails, recordingFile, saveFile, outFormat, - mDuration, videoWidth, videoHeight, processVWidth, processVHeight, outFrameRate, outBitRate, outVcodec, outAcodec, + ffmpeg.processVideo(obscureTrails, recordingFile, saveFile, + frameRate, mDuration, outputLength, mCompressVideo, mObscureVideoAmount, mObscureAudioAmount, new ExecuteBinaryResponseHandler() { @Override @@ -1276,7 +1158,8 @@ public void onSuccess(String message) { Log.i(getClass().getName(), "SUCCESS: " + message); - addVideoToGallery(saveFile); + if (!mIsPreview) + addVideoToGallery(saveFile); Message msg = mHandler.obtainMessage(completeActionFlag); msg.getData().putString("status", "complete"); @@ -1285,10 +1168,8 @@ public void onSuccess(String message) { @Override public void onFinish() { - progressDialog.dismiss(); Log.i(getClass().getName(), "FINISHED"); - wl.release(); } @@ -1308,14 +1189,20 @@ private void addVideoToGallery(File videoToAdd) { private void askPostProcessAction() { if (saveFile != null && saveFile.exists()) { - Snackbar snackbar = Snackbar.make(findViewById(R.id.frameRoot), R.string.processing_complete, Snackbar.LENGTH_INDEFINITE); - snackbar.setAction("Open", new OnClickListener() { - @Override - public void onClick(View view) { - playVideo(); - } - }); - snackbar.show(); + + resetMediaPlayer(Uri.fromFile(saveFile)); + start(); + + if (!mIsPreview) { + Snackbar snackbar = Snackbar.make(findViewById(R.id.frameRoot), R.string.processing_complete, Snackbar.LENGTH_LONG); + snackbar.setAction("Open", new OnClickListener() { + @Override + public void onClick(View view) { + playVideoExternal(); + } + }); + snackbar.show(); + } } } @@ -1326,7 +1213,7 @@ private void showFailure (String message) snackbar.show(); } - private void playVideo() { + private void playVideoExternal() { if (saveFile != null && saveFile.exists()) { @@ -1365,69 +1252,6 @@ public void inOutValuesChanged(int thumbInValue, int thumbOutValue) { }*/ } - boolean isPopupShowing = false; - - public void inflatePopup(boolean showDelayed, int x, int y) { - if (popupMenu == null) - initPopup(); - - popupMenu.show(regionsView, x, y); - - isPopupShowing = !isPopupShowing; - } - - private void initPopup() { - popupMenu = new QuickAction(this); - - - ActionItem menu = new ActionItem(); - menu.setTitle("Set In Point"); - menu.setActionId(0); - menu.setIcon(getResources().getDrawable(R.drawable.ic_add)); - popupMenu.addActionItem(menu); - - //popupMenuItems[0].setIcon(getResources().getDrawable(R.drawable.icon)); - - menu = new ActionItem(); - menu.setActionId(1); - menu.setTitle("Set Out Point"); - menu.setIcon(getResources().getDrawable(R.drawable.ic_add)); - popupMenu.addActionItem(menu); - - menu = new ActionItem(); - menu.setActionId(4); - menu.setTitle("Set Redact"); - menu.setIcon(getResources().getDrawable(R.drawable.ic_context_fill)); - popupMenu.addActionItem(menu); - - menu = new ActionItem(); - menu.setActionId(5); - menu.setTitle("Set Pixelate"); - menu.setIcon(getResources().getDrawable(R.drawable.ic_context_pixelate)); - popupMenu.addActionItem(menu); - - menu = new ActionItem(); - menu.setActionId(3); - menu.setTitle("Remove Trail"); - menu.setIcon(getResources().getDrawable(R.drawable.ic_context_delete)); - popupMenu.addActionItem(menu); - - menu = new ActionItem(); - menu.setActionId(6); - menu.setTitle("Do Tween"); - menu.setIcon(getResources().getDrawable(android.R.drawable.ic_menu_rotate)); - popupMenu.addActionItem(menu); - - menu = new ActionItem(); - menu.setActionId(2); - menu.setTitle("Remove Keyframe"); - menu.setIcon(getResources().getDrawable(R.drawable.ic_context_delete)); - popupMenu.addActionItem(menu); - - - popupMenu.setOnActionItemClickListener(this); - } - @Override protected void onPause() { @@ -1487,9 +1311,17 @@ public void shellOut(char[] msg) { protected void onResume() { super.onResume(); - videoView = (VideoView) this.findViewById(R.id.SurfaceView); + regionsView = (ImageView) this.findViewById(R.id.VideoEditorImageView); + regionsView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + resetMediaPlayer(originalVideoUri); + } + }); + // regionsView.setOnTouchListener(this); + surfaceHolder = videoView.getHolder(); surfaceHolder.addCallback(this); @@ -1507,7 +1339,20 @@ protected void onResume() { progressBar.setOnTouchListener(this); playPauseButton = (ImageButton) this.findViewById(R.id.PlayPauseImageButton); - playPauseButton.setOnClickListener(this); + playPauseButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + if (mediaPlayer.isPlaying()) { + mediaPlayer.pause(); + playPauseButton.setImageDrawable(getResources().getDrawable(android.R.drawable.ic_media_play)); + mAutoDetectEnabled = false; + } else { + start(); + + + } + } + }); //regionBarArea = (RegionBarArea) this.findViewById(R.id.RegionBarArea); @@ -1523,9 +1368,64 @@ protected void onResume() { selectedPaint.setStyle(Style.STROKE); selectedPaint.setStrokeWidth(10f); + /** + findViewById(R.id.button_auto).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + beginAutoDetect(); + } + });**/ + + findViewById(R.id.button_preview).setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + processVideo(true); + } + }); + + ((SeekBar)findViewById(R.id.seekbar_video_obscure)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + + //make it even! + if (i%2!=0) { + i+=1; + } + + mObscureVideoAmount = i; + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + + ((SeekBar)findViewById(R.id.seekbar_audio_obscure)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int i, boolean b) { + mObscureAudioAmount = i; + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + }); + setPrefs(); - loadMedia(); + loadMedia(originalVideoUri); } @@ -1843,30 +1743,6 @@ public void onItemClick(QuickAction source, int pos, int actionId) { } - /* - * Call this to delete the original image, will ask the user - */ - private void showDeleteOriginalDialog() { - final AlertDialog.Builder b = new AlertDialog.Builder(this); - b.setIcon(android.R.drawable.ic_dialog_alert); - b.setTitle(getString(R.string.app_name)); - b.setMessage(getString(R.string.confirm_delete)); - b.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - - try { - // User clicked OK so go ahead and delete - deleteOriginal(); - - } catch (IOException e) { - Log.e(ObscuraApp.TAG, "error saving", e); - } finally { - finish(); - } - } - }); - b.show(); - } /* * Actual deletion of original diff --git a/app/src/main/java/org/witness/sscphase1/Eula.java b/app/src/main/java/org/witness/sscphase1/Eula.java deleted file mode 100644 index b9d432c..0000000 --- a/app/src/main/java/org/witness/sscphase1/Eula.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.witness.sscphase1; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.DialogInterface; -import android.content.SharedPreferences; - -import java.io.IOException; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.io.Closeable; - -/** - * Displays an EULA ("End User License Agreement") that the user has to accept before - * using the application. Your application should call {@link Eula#show(android.app.Activity)} - * in the onCreate() method of the first activity. If the user accepts the EULA, it will never - * be shown again. If the user refuses, {@link android.app.Activity#finish()} is invoked - * on your activity. - */ -class Eula { - public static final String ASSET_EULA = "EULA"; - public static final String PREFERENCE_EULA_ACCEPTED = "eula.accepted"; - public static final String PREFERENCES_EULA = "eula"; - - /** - * callback to let the activity know when the user has accepted the EULA. - */ - static interface OnEulaAgreedTo { - - /** - * Called when the user has accepted the eula and the dialog closes. - */ - void onEulaAgreedTo(); - } - - /** - * Displays the EULA if necessary. This method should be called from the onCreate() - * method of your main Activity. - * - * @param activity The Activity to finish if the user rejects the EULA. - * @return Whether the user has agreed already. - */ - static boolean show(final Activity activity) { - final SharedPreferences preferences = activity.getSharedPreferences(PREFERENCES_EULA, - Activity.MODE_PRIVATE); - if (!preferences.getBoolean(PREFERENCE_EULA_ACCEPTED, false)) { - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.eula_title); - builder.setCancelable(true); - builder.setPositiveButton(R.string.eula_accept, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - accept(preferences); - if (activity instanceof OnEulaAgreedTo) { - ((OnEulaAgreedTo) activity).onEulaAgreedTo(); - } - } - }); - builder.setNegativeButton(R.string.eula_refuse, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - refuse(activity); - } - }); - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - public void onCancel(DialogInterface dialog) { - refuse(activity); - } - }); - builder.setMessage(readEula(activity)); - builder.create().show(); - return false; - } - return true; - } - - private static void accept(SharedPreferences preferences) { - preferences.edit().putBoolean(PREFERENCE_EULA_ACCEPTED, true).commit(); - } - - private static void refuse(Activity activity) { - activity.finish(); - } - - private static CharSequence readEula(Activity activity) { - BufferedReader in = null; - try { - in = new BufferedReader(new InputStreamReader(activity.getAssets().open(ASSET_EULA))); - String line; - StringBuilder buffer = new StringBuilder(); - while ((line = in.readLine()) != null) buffer.append(line).append('\n'); - return buffer; - } catch (IOException e) { - return ""; - } finally { - closeStream(in); - } - } - - /** - * Closes the specified stream. - * - * @param stream The stream to close. - */ - private static void closeStream(Closeable stream) { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - // Ignore - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/org/witness/sscphase1/MainActivity.java b/app/src/main/java/org/witness/sscphase1/MainActivity.java index 3739e5d..7738805 100644 --- a/app/src/main/java/org/witness/sscphase1/MainActivity.java +++ b/app/src/main/java/org/witness/sscphase1/MainActivity.java @@ -73,7 +73,6 @@ public void onCreate(Bundle savedInstanceState) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); deleteTmpFile(); - Eula.show(this); layoutGalleryInfo = findViewById(R.id.gallery_info); Button btnOk = (Button) layoutGalleryInfo.findViewById(R.id.btnGalleryInfoOk); diff --git a/app/src/main/res/layout/videoeditor.xml b/app/src/main/res/layout/videoeditor.xml index fb197fb..cb22598 100644 --- a/app/src/main/res/layout/videoeditor.xml +++ b/app/src/main/res/layout/videoeditor.xml @@ -1,29 +1,36 @@ + - + - - + + + + + + + + + +