Skip to content

Commit

Permalink
First version of the mkdfs module
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkendk committed Jan 7, 2013
1 parent bf934af commit ff85d59
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 2 deletions.
11 changes: 11 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
This module is Copyright (c) 2013 by Mikken Digital S.M.B.A. All Rights Reserved.

The MIT License (MIT)

Copyright (c) 2013 Mikken Digital S.M.B.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
ti_androidexternalstoragemodule
Titanium module for Android external storage
===============================

Titanium Android External Storage Helper
This Titanium module for Android provides two missing Android API values:
[Environment.getExternalStorageDirectory()](https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()) and [Context.getExternalFilesDir()]((https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String))).

Examples in the [example directory](./example/), and API reference in the [documentation directory](./documentation).

The module is already compiled. Extract the [dist/dk.mikkendigital.mkdfs-android-0.1.zip](./dist/dk.mikkendigital.mkdfs-android-0.1.zip) file.

This module is Copyright (c) 2013 by Mikken Digital S.M.B.A. All Rights Reserved. The MIT License (MIT)
4 changes: 4 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
titanium.platform=/Users/kenneth/Library/Application Support/Titanium/mobilesdk/osx/2.1.4.GA/android
android.platform=/Users/kenneth/android-sdks/platforms/android-8
google.apis=/Users/kenneth/android-sdks/add-ons/addon-google_apis-google_inc_-8
android.ndk=/Users/kenneth/android-ndk-r6b
10 changes: 10 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<project name="mkdfs" default="dist">
<description>
Ant build script for Titanium Android module mkdfs
</description>

<property name="ti.module.root" location="${basedir}"/>
<property file="build.properties" />

<import file="${titanium.platform}/../module/android/build.xml"/>
</project>
Binary file added dist/dk.mikkendigital.mkdfs-android-0.1.zip
Binary file not shown.
55 changes: 55 additions & 0 deletions documentation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# mkdfs Module

## Description

Android External Storage Module

## Accessing the mkdfs Module

To access this module from JavaScript, you would do the following:

var mkdfs = require("dk.mikkendigital.mkdfs");

The mkdfs variable is a reference to the Module object.

## Reference

### dk.mikkendigital.mkdfs.externalStorageDirectory

Returns the device external storage directory as a string.
This is the same as calling [Environment.getExternalStorageDirectory()](https://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()).

### dk.mikkendigital.mkdfs.externalFilesDir

Returns the applications external storage folder as a string.
This is the same as calling [Context.getExternalFilesDir()]((https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String))).

## Usage

// Create a file in the external storage folder
if (Ti.Platform.name == "android" && Ti.Filesystem.isExternalStoragePresent()) {
var mkdfs = require('dk.mikkendigital.mkdfs');
Ti.API.info("module externalStorageDirectory is => " + mkdfs.externalStorageDirectory);
Ti.API.info("module externalFilesDir is => " + mkdfs.externalFilesDir);

var file = Ti.Filesystem.getFile('file://' + mkdfs.externalFilesDir, 'sample.txt');
file.write('Newly created file on SD card');
} else {
alert('No external storage found!');
}

## Author

Kenneth Skovhede, Mikken Digital S.M.B.A.

## License

The MIT License (MIT)

Copyright (c) 2013 Mikken Digital S.M.B.A.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 30 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// open a single window
var win = Ti.UI.createWindow({
backgroundColor:'white'
});
var label1 = Ti.UI.createLabel();
var label2 = Ti.UI.createLabel();
win.add(label1);
win.add(label2);
win.open();

if (Ti.Platform.name == "android") {
var mkdfs = require('dk.mikkendigital.mkdfs');
Ti.API.info("module is => " + mkdfs);

if (Ti.Filesystem.isExternalStoragePresent())
{
label1.text = mkdfs.getExternalStorageDirectory();
label2.text = mkdfs.getExternalFilesDir();

Ti.API.info("module externalStorageDirectory is => " + mkdfs.externalStorageDirectory);
Ti.API.info("module externalFilesDir is => " + mkdfs.externalFilesDir);
} else {
label1.text = "No external storage found";
label2.text = "No external storage found";
}
} else {
label1.text = "Not supported on this platform";
label2.text = "Not supported on this platform";
}

1 change: 1 addition & 0 deletions hooks/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
These files are not yet supported as of 1.4.0 but will be in a near future release.
35 changes: 35 additions & 0 deletions hooks/add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
#
# This is the module project add hook that will be
# called when your module is added to a project
#
import os, sys

def dequote(s):
if s[0:1] == '"':
return s[1:-1]
return s

def main(args,argc):
# You will get the following command line arguments
# in the following order:
#
# project_dir = the full path to the project root directory
# project_type = the type of project (desktop, mobile, ipad)
# project_name = the name of the project
#
project_dir = dequote(os.path.expanduser(args[1]))
project_type = dequote(args[2])
project_name = dequote(args[3])

# TODO: write your add hook here (optional)


# exit
sys.exit(0)



if __name__ == '__main__':
main(sys.argv,len(sys.argv))

19 changes: 19 additions & 0 deletions hooks/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
#
# This is the module install hook that will be
# called when your module is first installed
#
import os, sys

def main(args,argc):

# TODO: write your install hook here (optional)

# exit
sys.exit(0)



if __name__ == '__main__':
main(sys.argv,len(sys.argv))

34 changes: 34 additions & 0 deletions hooks/remove.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
#
# This is the module project remove hook that will be
# called when your module is remove from a project
#
import os, sys

def dequote(s):
if s[0:1] == '"':
return s[1:-1]
return s

def main(args,argc):
# You will get the following command line arguments
# in the following order:
#
# project_dir = the full path to the project root directory
# project_type = the type of project (desktop, mobile, ipad)
# project_name = the name of the project
#
project_dir = dequote(os.path.expanduser(args[1]))
project_type = dequote(args[2])
project_name = dequote(args[3])

# TODO: write your remove hook here (optional)

# exit
sys.exit(0)



if __name__ == '__main__':
main(sys.argv,len(sys.argv))

18 changes: 18 additions & 0 deletions hooks/uninstall.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
#
# This is the module uninstall hook that will be
# called when your module is uninstalled
#
import os, sys

def main(args,argc):

# TODO: write your uninstall hook here (optional)

# exit
sys.exit(0)


if __name__ == '__main__':
main(sys.argv,len(sys.argv))

18 changes: 18 additions & 0 deletions manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 0.1
apiversion: 2
description: Android External Storage Module
author: Kenneth Skovhede
license: MIT License
copyright: Copyright (c) 2013 by Mikken Digital S.M.B.A.


# these should not be edited
name: mkdfs
moduleid: dk.mikkendigital.mkdfs
guid: f2472240-4924-4948-abea-22f022593482
platform: android
minsdk: 2.1.4.GA
74 changes: 74 additions & 0 deletions src/dk/mikkendigital/mkdfs/MkdfsModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* This file was auto-generated by the Titanium Module SDK helper for Android
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*
*/
package dk.mikkendigital.mkdfs;

import java.io.File;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;

import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;

import android.os.Environment;

import android.content.Context;


@Kroll.module(name="Mkdfs", id="dk.mikkendigital.mkdfs")
public class MkdfsModule extends KrollModule
{

// Standard Debugging variables
private static final String LCAT = "MkdfsModule";
private static final boolean DBG = TiConfig.LOGD;

//State info
private static TiApplication m_app;

// You can define constants with @Kroll.constant, for example:
// @Kroll.constant public static final String EXTERNAL_NAME = value;

public MkdfsModule()
{
super();
}

@Kroll.onAppCreate
public static void onAppCreate(TiApplication app)
{
// put module init code that needs to run when the application is created
Log.d(LCAT, "inside onAppCreate");
m_app = app;
}

// Methods
@Kroll.method
@Kroll.getProperty
public String getExternalStorageDirectory()
{
File f = Environment.getExternalStorageDirectory();
if (!f.exists())
f.mkdirs();
return f.getAbsolutePath();
}

@Kroll.method
@Kroll.getProperty
public String getExternalFilesDir()
{
File f = m_app.getExternalFilesDir(null);
if (!f.exists())
f.mkdirs();
return f.getAbsolutePath();
}

}

16 changes: 16 additions & 0 deletions timodule.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<ti:module xmlns:ti="http://ti.appcelerator.org" xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Similar to tiapp.xml, but contains module/platform specific
configuration in <iphone>, <android>, and <mobileweb> sections
-->
<iphone>
</iphone>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</manifest>
</android>
<mobileweb>
</mobileweb>
</ti:module>

0 comments on commit ff85d59

Please sign in to comment.