From 1a5598cd5d1f96996edc214a3686e563aafc9e31 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Mon, 25 Jun 2018 23:17:50 -0400 Subject: [PATCH] Add support for custom resolutions --- .../activity/MainActivity.java | 60 +++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 21 ++++++- app/src/main/res/values/strings.xml | 2 + 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/protect/videotranscoder/activity/MainActivity.java b/app/src/main/java/protect/videotranscoder/activity/MainActivity.java index 9ad3c0e3..5c118d7d 100644 --- a/app/src/main/java/protect/videotranscoder/activity/MainActivity.java +++ b/app/src/main/java/protect/videotranscoder/activity/MainActivity.java @@ -20,6 +20,7 @@ import android.os.Messenger; import android.os.RemoteException; import android.preference.PreferenceManager; +import android.support.annotation.IdRes; import android.support.v4.app.ActivityCompat; import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; @@ -133,6 +134,7 @@ public class MainActivity extends AppCompatActivity private Spinner videoCodecSpinner; private Spinner fpsSpinner; private Spinner resolutionSpinner; + private EditText resolutionCustom; private EditText videoBitrateValue; private Spinner audioCodecSpinner; private Spinner audioBitrateSpinner; @@ -181,6 +183,7 @@ protected void onCreate(Bundle savedInstanceState) videoCodecSpinner = findViewById(R.id.videoCodecSpinner); fpsSpinner = findViewById(R.id.fpsSpinner); resolutionSpinner = findViewById(R.id.resolutionSpinner); + resolutionCustom = findViewById(R.id.resolutionCustom); videoBitrateValue = findViewById(R.id.videoBitrateValue); audioCodecSpinner = findViewById(R.id.audioCodecSpinner); audioBitrateSpinner = findViewById(R.id.audioBitrateSpinner); @@ -776,6 +779,34 @@ private void startEncode() return; } + final String customString = getString(R.string.custom); + + if(resolution.equals(customString)) + { + resolution = resolutionCustom.getText().toString(); + String [] split = resolution.split("x"); + if(split.length != 2) + { + Toast.makeText(this, R.string.videoResolutionValueInvalid, Toast.LENGTH_LONG).show(); + return; + } + + for(String value : split) + { + try + { + // Check if the string can be parsed or not. + Integer.parseInt(value); + } + catch(NumberFormatException e) + { + Toast.makeText(this, R.string.videoResolutionValueInvalid, Toast.LENGTH_LONG).show(); + return; + } + } + } + + try { String videoBitrateKStr = videoBitrateValue.getText().toString(); @@ -1075,6 +1106,33 @@ public void onNothingSelected(AdapterView parentView) } }); + class SetCustomAdapter implements AdapterView.OnItemSelectedListener + { + private final String customString; + private final View customField; + + public SetCustomAdapter(String customString, @IdRes int customFieldId) + { + this.customString = customString; + this.customField = findViewById(customFieldId); + } + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) + { + String value = (String)parent.getItemAtPosition(position); + customField.setVisibility(value.equals(customString) ? View.VISIBLE : View.GONE); + } + + @Override + public void onNothingSelected(AdapterView parent) + { + // Nothing to do + } + } + + final String customString = getString(R.string.custom); + LinkedList fps = new LinkedList<>(Arrays.asList("15", "24", "23.98", "25", "29.97", "30", "50")); if(videoInfo.videoFramerate != null && fps.contains(videoInfo.videoFramerate) == false) { @@ -1116,7 +1174,9 @@ public int compare(String o1, String o2) } }); } + resolution.addLast(customString); resolutionSpinner.setAdapter(new ArrayAdapter<>(this, R.layout.spinner_textview, resolution)); + resolutionSpinner.setOnItemSelectedListener(new SetCustomAdapter(customString, R.id.resolutionCustomContainer)); audioCodecSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f004fa5e..b4957cef 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -282,12 +282,31 @@ android:textSize="@dimen/inputSize" android:drawSelectorOnTop="true" /> + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1411fe6a..bf47d0e7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -22,11 +22,13 @@ Audio Settings Sample Rate (Hz) Channels + Custom Not Supported This device\'s CPU architecture is not supported. Only ARM is supported. You must select a file to encode first. + Resolution value is invalid, could not encode. Video bitrate value is invalid, could not encode. Encoding %s Do you want to encode %s and output to %s?