Skip to content

Commit

Permalink
Merge branch 'master' of github.com:appcelerator/titanium_mobile into…
Browse files Browse the repository at this point in the history
… AUTO_LAYOUT
  • Loading branch information
pec1985 committed Feb 1, 2016
2 parents fdc8529 + 817c8ee commit 93170ec
Show file tree
Hide file tree
Showing 353 changed files with 4,349 additions and 1,386 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -31,3 +31,5 @@ anvil/hub/config.js
support/mobileweb/dependencyAnalyzer/node_modules/*
anvil/driver/node_modules/*
apidoc/node_modules/*

support/ti_mocha_script/testApp
2 changes: 2 additions & 0 deletions .travis.yml
Expand Up @@ -56,6 +56,8 @@ script:
- cd dist
- ti sdk install *osx.zip
- cd ..
- npm install glob
- npm install grunt-cli
- npm test -- run-on-travis

after_success:
Expand Down
2 changes: 1 addition & 1 deletion android/cli/commands/_build.js
Expand Up @@ -2942,7 +2942,7 @@ AndroidBuilder.prototype.processTiSymbols = function processTiSymbols(next) {

// make sure that the module was not built before 1.8.0.1
if (~~module.manifest.apiversion < 2) {
this.logger.error(__('The "apiversion" for "%s" in the module manifest is less than version 2.', id.cyan));
this.logger.error(__('The "apiversion" for "%s" in the module manifest is less than version 2.', module.manifest.moduleid.cyan));
this.logger.error(__('The module was likely built against a Titanium SDK 1.8.0.1 or older.'));
this.logger.error(__('Please use a version of the module that has "apiversion" 2 or greater'));
this.logger.log();
Expand Down
6 changes: 3 additions & 3 deletions android/dependency.json
Expand Up @@ -6,7 +6,7 @@
"cardview":[],
"accelerometer":[],
"analytics":[],
"android":[],
"android":["filesystem"],
"app":[],
"calendar":[],
"contacts":[],
Expand All @@ -24,9 +24,9 @@
"xml":[]
},
"required": ["analytics","android","app","ui","locale","network"],
"libraries":
"libraries":
{
"android":["jaxen-1.1.1.jar","ti-commons-codec-1.3.jar","kroll-common.jar","titanium.jar"],
"android":["jaxen-1.1.1.jar","ti-commons-codec-1.3.jar","kroll-common.jar","titanium.jar","filesystem.jar"],
"xml":["jaxen-1.1.1.jar"],
"ui":["nineoldandroids-appc-2.4.0.jar"],
"appcompat":["android-support-v4.jar", "android-support-v7-appcompat.jar"],
Expand Down
Expand Up @@ -7,6 +7,7 @@
package ti.modules.titanium.analytics;

import java.util.HashMap;
import java.util.Iterator;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollModule;
Expand All @@ -15,6 +16,7 @@
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiPlatformHelper;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -35,6 +37,15 @@ public class AnalyticsModule extends KrollModule
protected static final String PROPERTY_APP_USER = "app.user";
private APSAnalytics analytics = APSAnalytics.getInstance();

public static final int MAX_LEVELS = 5;
public static final int MAX_SERLENGTH = 1000;
public static final int MAX_KEYS = 25;
public static final int MAX_KEYLENGTH = 50;

public static final int SUCCESS = 0;
public static final int JSON_VALIDATION_FAILED = -1;
public static final int ANALYTICS_DISABLED = -2;

public AnalyticsModule()
{
super();
Expand Down Expand Up @@ -86,23 +97,91 @@ public void filterEvents(Object eventsObj) {
}

@Kroll.method
public void featureEvent(String event, @Kroll.argument(optional = true) KrollDict data)
public int featureEvent(String event, @Kroll.argument(optional = true) KrollDict data)
{
if (TiApplication.getInstance().isAnalyticsEnabled()) {
if (data instanceof HashMap) {
analytics.sendAppFeatureEvent(event, TiConvert.toJSON(data));
} else if (data != null) {
try {
analytics.sendAppFeatureEvent(event, new JSONObject(data.toString()));
} catch (JSONException e) {
Log.e(TAG, "Cannot convert data into JSON");
}
} else {
analytics.sendAppFeatureEvent(event, null);
}
} else {
Log.e(TAG, "Analytics is disabled. To enable, please update the <analytics></analytics> node in your tiapp.xml");
}
if (TiApplication.getInstance().isAnalyticsEnabled()) {
if (data instanceof HashMap) {
JSONObject jsonData = TiConvert.toJSON(data);
if (AnalyticsModule.validateJSON(jsonData, 0) == SUCCESS) {
analytics.sendAppFeatureEvent(event, jsonData);
return SUCCESS;
} else {
Log.e(TAG, "Feature event "+ event +" not conforming to recommended usage.");
return JSON_VALIDATION_FAILED;
}
} else if (data != null) {
try {
JSONObject jsonData = new JSONObject(data.toString());
if (AnalyticsModule.validateJSON(jsonData, 0) == SUCCESS) {
analytics.sendAppFeatureEvent(event, jsonData);
return SUCCESS;
} else {
Log.e(TAG, "Feature event "+ event +" not conforming to recommended usage.");
return JSON_VALIDATION_FAILED;
}
} catch (JSONException e) {
Log.e(TAG, "Cannot convert data into JSON");
return JSON_VALIDATION_FAILED;
}
} else {
analytics.sendAppFeatureEvent(event, null);
return SUCCESS;
}
} else {
Log.e(TAG, "Analytics is disabled. To enable, please update the <analytics></analytics> node in your tiapp.xml");
return ANALYTICS_DISABLED;
}
}

public static int validateJSON(JSONObject jsonObject, int level) {

if (level > MAX_LEVELS) {
Log.w(TAG, "Feature event cannot have more than "+ MAX_LEVELS + " nested JSONs");
return JSON_VALIDATION_FAILED;
}
if (jsonObject == null) {
return JSON_VALIDATION_FAILED;
}
if ((level == 0) & (jsonObject.toString().getBytes().length > MAX_SERLENGTH)) {
Log.w(TAG, "Feature event cannot exceed more than "+ MAX_SERLENGTH + " total serialized bytes");
return JSON_VALIDATION_FAILED;
}
if (jsonObject.length() > MAX_KEYS) {
Log.w(TAG, "Feature event maxium keys should not exceed "+ MAX_KEYS);
return JSON_VALIDATION_FAILED;
}

Iterator<String> keys = jsonObject.keys();

while(keys.hasNext()) {
String key = (String)keys.next();
if (key.length() > MAX_KEYLENGTH) {
Log.w(TAG, "Feature event key "+key+" length should not exceed "+MAX_KEYLENGTH+" characters");
return JSON_VALIDATION_FAILED;
}
try {
Object child;
child = jsonObject.get(key);
if (child instanceof JSONObject) {
if (validateJSON(((JSONObject)child), level+1) != SUCCESS){
return JSON_VALIDATION_FAILED;
}
} else if (jsonObject.get(key) instanceof JSONArray) {
JSONArray jsonArray = (JSONArray) child;
for(int i=0; i< jsonArray.length(); i++) {
Object o = jsonArray.get(i);
if (o instanceof JSONObject) {
if (validateJSON(((JSONObject)o), level+1) != SUCCESS){
return JSON_VALIDATION_FAILED;
}
}
}
}
} catch (JSONException e) {
Log.w(TAG, "Unable to validate JSON: " + e);
}
}
return SUCCESS;
}

@Kroll.getProperty @Kroll.method
Expand Down
1 change: 1 addition & 0 deletions android/modules/android/.classpath
Expand Up @@ -7,6 +7,7 @@
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry combineaccessrules="false" kind="src" path="/kroll-common"/>
<classpathentry combineaccessrules="false" kind="src" path="/titanium"/>
<classpathentry combineaccessrules="false" kind="src" path="/titanium-filesystem"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
6 changes: 5 additions & 1 deletion android/modules/android/build.xml
@@ -1,3 +1,7 @@
<project name="android" default="build">
<import file="../../build/build-module.xml"/>
</project>

<path id="dependencies">
<path path="${dist.classes.dir}/filesystem"/>
</path>
</project>
1 change: 1 addition & 0 deletions android/modules/android/project.properties
Expand Up @@ -12,3 +12,4 @@ android.library=true
target=android-23
android.library.reference.1=../../runtime/common
android.library.reference.2=../../titanium
android.library.reference.3=../filesystem
@@ -0,0 +1,119 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2014 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 ti.modules.titanium.android.notificationmanager;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiDrawableReference;

import ti.modules.titanium.android.AndroidModule;
import ti.modules.titanium.filesystem.FileProxy;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.NotificationCompat.BigPictureStyle;

@Kroll.proxy(creatableInModule = AndroidModule.class, propertyAccessors = {
TiC.PROPERTY_DECODE_RETRIES
})
public class BigPictureStyleProxy extends StyleProxy {

private static final String TAG = "TiNotificationBigPictureStyle";

public BigPictureStyleProxy() {
super();
style = new BigPictureStyle();
}

@Override
public void handleCreationDict(KrollDict d)
{
super.handleCreationDict(d);

if (d == null) {
return;
}

if (d.containsKey(TiC.PROPERTY_BIG_LARGE_ICON)) {
setBigLargeIcon(d.get(TiC.PROPERTY_BIG_LARGE_ICON));
}

if (d.containsKey(TiC.PROPERTY_BIG_PICTURE)) {
setBigPicture(d.get(TiC.PROPERTY_BIG_PICTURE));
}

if (d.containsKey(TiC.PROPERTY_BIG_CONTENT_TITLE)) {
setBigContentTitle(TiConvert.toString(d.get(TiC.PROPERTY_BIG_CONTENT_TITLE)));
}

if (d.containsKey(TiC.PROPERTY_SUMMARY_TEXT)) {
setSummaryText(TiConvert.toString(d.get(TiC.PROPERTY_SUMMARY_TEXT)));
}
}

private TiDrawableReference makeImageSource(Object object)
{
if (object instanceof FileProxy) {
return TiDrawableReference.fromFile(this.getActivity(), ((FileProxy) object).getBaseFile());
} else if (object instanceof String) {
return TiDrawableReference.fromUrl(this, (String) object);
} else {
return TiDrawableReference.fromObject(this.getActivity(), object);
}
}

@Kroll.method @Kroll.setProperty
public void setBigLargeIcon(Object icon)
{
if(icon instanceof Number) {
Bitmap bigLargeIcon = BitmapFactory.decodeResource(TiApplication.getInstance().getResources(), ((Number)icon).intValue());
((BigPictureStyle)style).bigLargeIcon(bigLargeIcon);
} else {
String iconUrl = TiConvert.toString(icon);
if (iconUrl == null) {
Log.e(TAG, "Url is null");
return;
}
String iconFullUrl = resolveUrl(null, iconUrl);
Bitmap bigLargeIcon = BitmapFactory.decodeResource(TiApplication.getInstance().getResources(), TiUIHelper.getResourceId(iconFullUrl));
((BigPictureStyle)style).bigLargeIcon(bigLargeIcon);
}

setProperty(TiC.PROPERTY_BIG_LARGE_ICON, icon);
}

@Kroll.method @Kroll.setProperty
public void setBigPicture(Object picture)
{
TiDrawableReference source = makeImageSource(picture);

// Check for decodeRetries
if (hasProperty(TiC.PROPERTY_DECODE_RETRIES)) {
source.setDecodeRetries(TiConvert.toInt(getProperty(TiC.PROPERTY_DECODE_RETRIES), TiDrawableReference.DEFAULT_DECODE_RETRIES));
}

((BigPictureStyle)style).bigPicture(source.getBitmap());

setProperty(TiC.PROPERTY_BIG_PICTURE, picture);
}

@Kroll.method @Kroll.setProperty
public void setBigContentTitle(String title) {
((BigPictureStyle)style).setBigContentTitle(title);
setProperty(TiC.PROPERTY_BIG_CONTENT_TITLE, title);
}

@Kroll.method @Kroll.setProperty
public void setSummaryText(String text) {
((BigPictureStyle)style).setSummaryText(text);
setProperty(TiC.PROPERTY_SUMMARY_TEXT, text);
}
}
@@ -0,0 +1,64 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2014 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 ti.modules.titanium.android.notificationmanager;

import ti.modules.titanium.android.AndroidModule;
import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiConvert;

import android.support.v4.app.NotificationCompat.BigTextStyle;

@Kroll.proxy(creatableInModule = AndroidModule.class)
public class BigTextStyleProxy extends StyleProxy {

public BigTextStyleProxy() {
super();
style = new BigTextStyle();
}

@Override
public void handleCreationDict(KrollDict d)
{
super.handleCreationDict(d);

if (d == null) {
return;
}

if (d.containsKey(TiC.PROPERTY_BIG_TEXT)) {
setBigText(TiConvert.toString(d.get(TiC.PROPERTY_BIG_TEXT)));
}

if (d.containsKey(TiC.PROPERTY_BIG_CONTENT_TITLE)) {
setBigContentTitle(TiConvert.toString(d.get(TiC.PROPERTY_BIG_CONTENT_TITLE)));
}

if (d.containsKey(TiC.PROPERTY_SUMMARY_TEXT)) {
setSummaryText(TiConvert.toString(d.get(TiC.PROPERTY_SUMMARY_TEXT)));
}
}

@Kroll.method @Kroll.setProperty
public void setBigText(String text) {
((BigTextStyle)style).bigText(text);
setProperty(TiC.PROPERTY_BIG_TEXT, text);
}

@Kroll.method @Kroll.setProperty
public void setBigContentTitle(String title) {
((BigTextStyle)style).setBigContentTitle(title);
setProperty(TiC.PROPERTY_BIG_CONTENT_TITLE, title);
}

@Kroll.method @Kroll.setProperty
public void setSummaryText(String text) {
((BigTextStyle)style).setSummaryText(text);
setProperty(TiC.PROPERTY_SUMMARY_TEXT, text);
}
}

0 comments on commit 93170ec

Please sign in to comment.