Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom resolutions #111

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<String> fps = new LinkedList<>(Arrays.asList("15", "24", "23.98", "25", "29.97", "30", "50"));
if(videoInfo.videoFramerate != null && fps.contains(videoInfo.videoFramerate) == false)
{
Expand Down Expand Up @@ -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()
{
Expand Down
21 changes: 20 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,31 @@
android:textSize="@dimen/inputSize"
android:drawSelectorOnTop="true" />
</LinearLayout>

<!-- Resolution Custom-->
<RelativeLayout
android:id="@+id/resolutionCustomContainer"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/inputBackground"
android:layout_below="@id/resolutionContainer"
android:visibility="gone">
<EditText
android:id="@+id/resolutionCustom"
android:hint="1920×1080"
android:layout_alignParentEnd="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="@dimen/inputPadding"
android:textSize="@dimen/inputSize"/>
</RelativeLayout>
<View
android:id="@+id/resolutionContainerDivider"
android:layout_height="@dimen/inputBorderThickness"
android:layout_width="match_parent"
android:background="@color/inputBorder"
android:layout_below="@id/resolutionContainer"
android:layout_below="@id/resolutionCustomContainer"
android:visibility="gone"/>

<!-- Video Bitrate -->
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
<string name="audioSettingsTitle">Audio Settings</string>
<string name="sampleRate">Sample Rate (Hz)</string>
<string name="channels">Channels</string>
<string name="custom">Custom</string>

<string name="notSupportedTitle">Not Supported</string>
<string name="notSupportedMessage">This device\'s CPU architecture is not supported. Only ARM is supported.</string>

<string name="selectFileFirst">You must select a file to encode first.</string>
<string name="videoResolutionValueInvalid">Resolution value is invalid, could not encode.</string>
<string name="videoBitrateValueInvalid">Video bitrate value is invalid, could not encode.</string>
<string name="encodingNotification">Encoding <xliff:g id="input_filename">%s</xliff:g></string>
<string name="encodeStartConfirmation">Do you want to encode <xliff:g id="input_filename">%s</xliff:g> and output to <xliff:g id="output_filename">%s</xliff:g>?</string>
Expand Down