Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Nov 13, 2017
1 parent a0b1fef commit 7dc30cc
Show file tree
Hide file tree
Showing 104 changed files with 2,145 additions and 3 deletions.
74 changes: 74 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
matrix:
include:
- stage: "Lint"
language: node_js
os: linux
node_js: "6"
script: cd src && npm run ci.tslint && cd ../demo && npm run ci.tslint
- stage: "WebPack"
os: osx
env:
- Platform="iOS"
osx_image: xcode8.3
language: node_js
node_js: "6"
jdk: oraclejdk8
script: cd demo && npm run build.plugin && npm i && npm run build-ios-bundle
- language: android
os: linux
env:
- Platform="Android"
jdk: oraclejdk8
before_install: nvm install 6.10.3
script: cd demo && npm run build.plugin && npm i && npm run build-android-bundle
- stage: "Build and Test"
env:
- BuildAndroid="25"
language: android
os: linux
jdk: oraclejdk8
before_install: nvm install stable
script:
- cd src && npm i && npm run tsc && cd ../demo && tns build android
- os: osx
env:
- BuildiOS="10.3"
- Xcode="8.3"
osx_image: xcode8.3
language: node_js
node_js: "6"
jdk: oraclejdk8
script:
- cd src && npm i && npm run tsc && cd ../demo && tns build ios
- os: linux
language: android
dist: precise
sudo: required
jdk: oraclejdk8
before_script:
- echo no | android create avd --force -n test -t android-21 -b armeabi-v7a
- emulator -avd test -no-audio -no-window &
- android-wait-for-emulator
before_install:
- nvm install 6
script: cd src && npm run test.android
- os: osx
language: node_js
node_js: "6"
jdk: oraclejdk8
osx_image: xcode8.3
script: cd src && npm run test.ios

android:
components:
- tools
- platform-tools
- build-tools-25.0.2
- android-25
- extra-android-m2repository
- sys-img-armeabi-v7a-android-21

install:
- echo no | npm install -g nativescript
- tns usage-reporting disable
- tns error-reporting disable
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
141 changes: 140 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,141 @@
[![npm](https://img.shields.io/npm/v/nativescript-mediafilepicker.svg)](https://www.npmjs.com/package/nativescript-mediafilepicker)
[![npm](https://img.shields.io/npm/dt/nativescript-mediafilepicker.svg?label=npm%20downloads)](https://www.npmjs.com/package/nativescript-mediafilepicker)

# nativescript-mediafilepicker
NativeScript Media File Picker Plugin
This plugin will allow user to pick video & image files from their device. User can also use their camera to take picture from this plugin directly. It's combination features nativescript-imagepicker and nativescript-camera plugin with some extended features using following libaries:

* iOS: [Android-FilePicker](https://github.com/DroidNinja/Android-FilePicker)
* Android: [GMImagePicker](https://github.com/TechSmith/GMImagePicker)

**Note for iOS:** In iOS you can't use file's link directly from the picker because of the permission issue. For resolving this issue this plugin will copy the selected files in your app's document directory under a new folder `filepicker`. So, after using that file you can delete that file to reduce memory use. You can check the demo app.


**Features:**

* Image and video file picker
* Multiple or single selection
* Camera support for taking picture
* File picker (Only for Android)
* Custom file type (Only for Android)

## Installation

```javascript
tns plugin add nativescript-mediafilepicker
```

## Usage

```javascript
import { Mediafilepicker, MediaFilepickerOptions } from 'nativescript-mediafilepicker';

let options: MediaFilepickerOptions = {
android: {
mxcount: 2,
enableImagePicker: true,
enableVideoPicker: true,
enableCameraSupport: true,
},
ios: {
allowsMultipleSelection: true,
title: "Album",
showCameraButton: true,
}
};
this.mediafilepicker = new Mediafilepicker();

this.mediafilepicker.on("getFiles", function (res: any) {

let files = res.files;

if (files.length > 0) {

files = files.split(",");

files.forEach(file => {

let fileName = file.replace(/^.*[\/]/, '');

console.log(file);
console.log(fileName);

// you can do anything here


if (app.ios) {

let folder = fs.knownFolders.documents();
let file = folder.getFolder("filepicker").getFile(fileName);

if (fs.File.exists(file.path)) {
folder.getFile("filepicker/" + fileName).remove()
} else {
console.log("not found")
}
}
});
}else{
console.log("There was some problem to select the file. Looks like user has cancel it.")
}

})
this.mediafilepicker.on("error", function (res: any) {
console.log(res.msg)
})
this.mediafilepicker.startFilePicker(options);
```

## All options

```javascript
android: {
mxcount: number; //used to specify maximum count of media picks (dont use if you want no limit)
setSelectedFiles: string; //to show already selected items
setActivityTheme: string; //used to set theme for toolbar (must be an actionbar theme)
enableImagePicker: boolean; //added option to disable image picker
enableVideoPicker: boolean; //added video picker alongside images
enableDocSupport: boolean; //If you want to enable/disable default document picker, use this method. (Enabled by default)
enableCameraSupport: boolean; //to show camera in the picker (Enabled by default)
showGifs: boolean; //to show gifs images in the picker
pickFile: boolean; // if you want for file picker
addFileSupport: { //If you want to specify custom file type, use this method. (example below)
title: string;
type: any;
icon: string;
};
};
ios: {
displaySelectionInfoToolbar: boolean; //Display or not the selection info Toolbar
displayAlbumsNumberOfAssets: boolean; //Display or not the number of assets in each album:
title: string; //Custom title
mediaTypes: string; // mediatype: 'image' or 'video' .. default both
customNavigationBarPrompt: string; //Custom helper message
colsInPortrait: number; //Customize the number of cols depending on orientation and the inter-item spacing
colsInLandscape: number; //Customize the number of cols depending on orientation and the inter-item spacing
minimumInteritemSpacing: number; //Customize the number of cols depending on orientation and the inter-item spacing
allowsMultipleSelection: boolean; //multiple selecion default true
confirmSingleSelection: boolean; //Show a promt to confirm single selection
confirmSingleSelectionPrompt: string; //Show a promt to confirm single selection
showCameraButton: boolean; //Camera integration
autoSelectCameraImages: boolean; //Auto select image after take picture using camera
};
```
**example addFileSupport:**
```javascript
addFileSupport: {
title: "Zip",
type: [".zip", ".rar", ".ZIP"],
icon: android.R.drawable.ic_dialog_info
}
```

## Screenshots

<img width="40%" src="screenshots/ios_screen.png" alt="iOS" float="left">

<img width="50%" src="screenshots/android_screen.png" alt="Android" float="left">


## License

Apache License Version 2.0, January 2004
43 changes: 43 additions & 0 deletions demo/app/App_Resources/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">

<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>

<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/LaunchScreenTheme">

<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
16 changes: 16 additions & 0 deletions demo/app/App_Resources/Android/app.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
//dependencies {
// compile 'com.android.support:recyclerview-v7:+'
//}

android {
defaultConfig {
generatedDensities = []
applicationId = "org.nativescript.demo"
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="fill">
<item>
<bitmap android:gravity="fill" android:src="@drawable/background" />
</item>
<item>
<bitmap android:gravity="center" android:src="@drawable/logo" />
</item>
</layer-list>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions demo/app/App_Resources/Android/values-v21/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ns_accent">#3d5afe</color>
</resources>
23 changes: 23 additions & 0 deletions demo/app/App_Resources/Android/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Application theme -->
<style name="AppTheme" parent="AppThemeBase">
<item name="android:datePickerStyle">@style/SpinnerDatePicker</item>
<item name="android:timePickerStyle">@style/SpinnerTimePicker</item>
</style>

<!-- Default style for DatePicker - in spinner mode -->
<style name="SpinnerDatePicker" parent="android:Widget.Material.Light.DatePicker">
<item name="android:datePickerMode">spinner</item>
</style>

<!-- Default style for TimePicker - in spinner mode -->
<style name="SpinnerTimePicker" parent="android:Widget.Material.Light.TimePicker">
<item name="android:timePickerMode">spinner</item>
</style>

<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
<item name="android:elevation">4dp</item>
</style>
</resources>
7 changes: 7 additions & 0 deletions demo/app/App_Resources/Android/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ns_primary">#F5F5F5</color>
<color name="ns_primaryDark">#757575</color>
<color name="ns_accent">#33B5E5</color>
<color name="ns_blue">#272734</color>
</resources>
45 changes: 45 additions & 0 deletions demo/app/App_Resources/Android/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!-- theme to use FOR launch screen-->
<style name="LaunchScreenThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>

<item name="colorPrimary">@color/ns_primary</item>
<item name="colorPrimaryDark">@color/ns_primaryDark</item>
<item name="colorAccent">@color/ns_accent</item>

<item name="android:windowBackground">@drawable/splash_screen</item>

<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowTranslucentStatus">true</item>

</style>

<style name="LaunchScreenTheme" parent="LaunchScreenThemeBase">
</style>

<!-- theme to use AFTER launch screen is loaded-->
<style name="AppThemeBase" parent="Theme.AppCompat.Light.NoActionBar">
<item name="toolbarStyle">@style/NativeScriptToolbarStyle</item>

<item name="colorPrimary">@color/ns_primary</item>
<item name="colorPrimaryDark">@color/ns_primaryDark</item>
<item name="colorAccent">@color/ns_accent</item>

</style>

<style name="AppTheme" parent="AppThemeBase">
</style>

<!-- theme for actioon-bar -->
<style name="NativeScriptToolbarStyleBase" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/ns_primary</item>
<item name="theme">@style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="popupTheme">@style/ThemeOverlay.AppCompat</item>

</style>

<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
</style>
</resources>
Loading

0 comments on commit 7dc30cc

Please sign in to comment.