-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Imanol Martin
committed
Dec 24, 2015
0 parents
commit f5e4e62
Showing
5 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Cocoon Plugin for Android Application | ||
====================================== | ||
|
||
This plugin adds support for application level life cycle events in Android it doesn't really adds any functionality by itself and is only intended to work as a dependency for other plugins like the multidex plugin or the Parse notifications plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "cocoon-plugin-application-android", | ||
"version": "1.0.2", | ||
"description": "Android Application plugin", | ||
"cordova": { | ||
"id": "cocoon-plugin-application-android", | ||
"platforms": [ | ||
"android" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ludei/cocoon-plugin-application-android" | ||
}, | ||
"keywords": [ | ||
"cordova", | ||
"application", | ||
"android", | ||
"cocoon", | ||
"atomic", | ||
"plugins", | ||
"ecosystem:cordova", | ||
"cordova-android" | ||
], | ||
"author": "ludei", | ||
"license": "MPL 2.0", | ||
"bugs": { | ||
"url": "https://github.com/ludei/cocoon-plugin-application-android/issues" | ||
}, | ||
"homepage": "https://github.com/ludei/cocoon-plugin-application-android#readme" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
id="cocoon-plugin-application-android" | ||
version="1.0.2"> | ||
|
||
<name>Cocoon Android Application plugin</name> | ||
<description>Cocoon plugin to add support for Android Application life cycle methods.</description> | ||
<license>Copyright Ludei</license> | ||
<keywords>cordova, ludei, cocoon, application</keywords> | ||
<repo></repo> | ||
<issue></issue> | ||
|
||
<engines> | ||
<engine name="cordova-android" version=">=4" /> | ||
<engine name="cordova-plugman" version=">=4.2.0" /><!-- needed for gradleReference support --> | ||
</engines> | ||
|
||
<!-- android --> | ||
<platform name="android"> | ||
<hook type="after_plugin_install" src="scripts/after_install.js" /> | ||
|
||
<source-file src="src/CocoonApp.java" target-dir="src/com/ludei" /> | ||
</platform> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
module.exports = function(context) { | ||
if (context.opts.cordova.platforms.indexOf('android') <= -1) | ||
return; | ||
|
||
var manifest_xml = path.join(context.opts.projectRoot, 'platforms', 'android','AndroidManifest.xml'); | ||
var et = context.requireCordovaModule('elementtree'); | ||
|
||
var data = fs.readFileSync(manifest_xml).toString(); | ||
var etree = et.parse(data); | ||
|
||
// Add Multidex application | ||
var applications = etree.findall('./application'); | ||
applications[0].attrib['android:name'] = "com.ludei.CocoonApp"; | ||
|
||
data = etree.write({'indent': 4}); | ||
fs.writeFileSync(manifest_xml, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.ludei; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
import org.apache.cordova.ConfigXmlParser; | ||
import org.apache.cordova.PluginEntry; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by imanolmartin on 22/12/15. | ||
*/ | ||
public class CocoonApp extends Application { | ||
|
||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
ConfigXmlParser parser = new ConfigXmlParser(); | ||
parser.parse(this); | ||
List<PluginEntry> pluginEntries = parser.getPluginEntries(); | ||
for (PluginEntry entry : pluginEntries) { | ||
try { | ||
Class clazz = Class.forName(entry.pluginClass); | ||
Method method = clazz.getMethod("onApplicationCreate", Application.class); | ||
method.invoke(null, this); | ||
|
||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (NoSuchMethodException e) { | ||
//e.printStackTrace(); | ||
|
||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void attachBaseContext(Context base) { | ||
super.attachBaseContext(base); | ||
|
||
ConfigXmlParser parser = new ConfigXmlParser(); | ||
parser.parse(this); | ||
List<PluginEntry> pluginEntries = parser.getPluginEntries(); | ||
for (PluginEntry entry : pluginEntries) { | ||
try { | ||
Class clazz = Class.forName(entry.pluginClass); | ||
Method method = clazz.getMethod("onApplicationAttachBaseContext", Application.class); | ||
method.invoke(null, this); | ||
|
||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (NoSuchMethodException e) { | ||
//e.printStackTrace(); | ||
|
||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onTerminate() { | ||
super.onTerminate(); | ||
|
||
ConfigXmlParser parser = new ConfigXmlParser(); | ||
parser.parse(this); | ||
List<PluginEntry> pluginEntries = parser.getPluginEntries(); | ||
for (PluginEntry entry : pluginEntries) { | ||
try { | ||
Class clazz = Class.forName(entry.pluginClass); | ||
Method method = clazz.getMethod("onApplicationTerminate", Application.class); | ||
method.invoke(null, this); | ||
|
||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
|
||
} catch (NoSuchMethodException e) { | ||
//e.printStackTrace(); | ||
|
||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |