Skip to content

Commit

Permalink
master - Updated sample to support pre KitKat devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
masterwok committed Jul 11, 2018
1 parent c05d29f commit 8624916
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
3 changes: 3 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'

// Provides file picker for pre KitKat (API 19) devices.
implementation 'com.nononsenseapps:filepicker:4.1.0'

implementation project(path: ':simplevlcplayer')
}

Expand Down
22 changes: 22 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
</intent-filter>
</activity>

<!-- File picker provider for pre KitKat (API 19) devices -->
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/nnf_provider_paths"/>
</provider>


</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;

import com.masterwok.demosimplevlcplayer.R;
import com.masterwok.simplevlcplayer.VlcOptionsProvider;
import com.masterwok.simplevlcplayer.activities.MediaPlayerActivity;
import com.nononsenseapps.filepicker.FilePickerActivity;


/**
Expand Down Expand Up @@ -74,8 +77,20 @@ protected void onStart() {
* Show the activity for picking file.
*/
private void showOpenDocumentActivity() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
Intent intent;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Use storage access framework
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
} else {
// Fallback to external file picker.
intent = new Intent(this, FilePickerActivity.class);
intent.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
intent.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, false);
intent.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_FILE);
intent.putExtra(FilePickerActivity.EXTRA_START_PATH, Environment.getExternalStorageDirectory().getPath());
}

startActivityForResult(intent, OpenDocumentRequestCode);
}
Expand Down Expand Up @@ -106,15 +121,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
private void startMediaPlayerActivity(Uri videoUri, Uri subtitleUri) {
Intent intent = new Intent(this, MediaPlayerActivity.class);

intent.putExtra(MediaPlayerActivity.MediaUri, videoUri);
intent.putExtra(MediaPlayerActivity.SubtitleUri, subtitleUri);

// Example of using an http resource.
// intent.putExtra(MediaPlayerActivity.MediaUri, Uri.parse(
// "http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4"
//// "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_stereo.avi"
// ));

// TODO: Seek partial files setTime fails when seeking past downloaded portion of file.
intent.putExtra(MediaPlayerActivity.MediaUri, videoUri);
intent.putExtra(MediaPlayerActivity.SubtitleUri, subtitleUri);

startActivity(intent);
}
Expand Down
23 changes: 23 additions & 0 deletions sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,27 @@

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

<!-- You can also inherit from NNF_BaseTheme.Light -->
<style name="FilePickerTheme" parent="NNF_BaseTheme">
<!-- Set these to match your theme -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<!-- Setting a divider is entirely optional -->
<item name="nnf_list_item_divider">?android:attr/listDivider</item>

<!-- Need to set this also to style create folder dialog -->
<item name="alertDialogTheme">@style/FilePickerAlertDialogTheme</item>

<!-- If you want to set a specific toolbar theme, do it here -->
<!-- <item name="nnf_toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item> -->
</style>

<style name="FilePickerAlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>

0 comments on commit 8624916

Please sign in to comment.