Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-25045
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews committed Nov 14, 2017
2 parents 9cf49ec + f90e8c3 commit d0cf1fd
Show file tree
Hide file tree
Showing 103 changed files with 805 additions and 3,583 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def unitTests(os, nodeVersion, testSuiteBranch) {
}
}
// copy over any overridden unit tests into this workspace
sh 'rm -rf tests'
unstash 'override-tests'
sh 'cp -R tests/ titanium-mobile-mocha-suite'
// Now run the unit test suite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,10 @@ Local<FunctionTemplate> ${className}::getProxyTemplate(Isolate* isolate)
<#else>
<#if constant.type = "java.lang.String">
DEFINE_STRING_CONSTANT(isolate, t, "${name}", "${constant.value}");
// TODO: deprecate in 7.0.0
DEFINE_STRING_CONSTANT(isolate, prototypeTemplate, "${name}", "${constant.value}");
<#elseif constant.type = "int" || constant.type = "long" || constant.type = "short">
DEFINE_INT_CONSTANT(isolate, t, "${name}", ${constant.value?c});
// TODO: deprecate in 7.0.0
DEFINE_INT_CONSTANT(isolate, prototypeTemplate, "${name}", ${constant.value?c});
<#else>
DEFINE_NUMBER_CONSTANT(isolate, t, "${name}", ${constant.value?c});
// TODO: deprecate in 7.0.0
DEFINE_NUMBER_CONSTANT(isolate, prototypeTemplate, "${name}", ${constant.value?c});
</#if>
</#if>
<#else>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ private static File createExternalStorageFile(String extension, String type, boo
File file;
String ext = extension == null ? ".jpg" : extension;
try {
file = TiFileHelper.getInstance().getTempFile(appDir, ext, false);
file = TiFileHelper.getInstance().getTempFile(appDir, ext, !isPublic);
} catch (IOException e) {
Log.e(TAG, "Failed to create file: " + e.getMessage());
return null;
Expand Down Expand Up @@ -809,7 +809,7 @@ public void onResult(Activity activity, int requestCode, int resultCode, Intent
copyFile(imageFile, dataFile);
imageFile.delete();
imageFile = dataFile;

TiFileHelper.getInstance().destroyOnExit(imageFile);
} catch(Throwable t) {
if (errorCallback != null) {
KrollDict response = new KrollDict();
Expand Down
18 changes: 11 additions & 7 deletions android/modules/network/src/js/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@

var bootstrap = require("bootstrap");

// Keeps an object alive until dispose() is called.
// This is currently used to keep "top level" objects
// (ex: windows, tab groups) alive until their lifecycle ends.
function PersistentHandle(object) {
this.cell = PersistentHandle.lastId++;
PersistentHandle.objects[this.cell] = object;
}

// Objects retained by persistent handles.
// Each element in this array acts as a storage "cell"
// keeping the object reachable and alive until it is removed.
persistentObjects = [];
PersistentHandle.objects = {};

// Keeps an object alive until dispose() is called.
function PersistentHandle(object) {
this.cell = persistentObjects.length;
persistentObjects.push(object);
}
PersistentHandle.lastId = 0;

PersistentHandle.prototype.dispose = function() {
if (this.cell == -1) {
// This handle has already been disposed.
return;
}

persistentObjects.splice(this.cell, 1);
delete PersistentHandle.objects[this.cell];
this.cell = -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.appcelerator.titanium.util.TiUIHelper;

import android.app.Activity;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spannable;
Expand All @@ -25,6 +26,7 @@
import android.text.style.AbsoluteSizeSpan;
import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.LineHeightSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
Expand Down Expand Up @@ -207,6 +209,16 @@ public static Bundle toSpannableInBundle(AttributedStringProxy attrString, Activ
}
results.putBoolean(TiC.PROPERTY_HAS_LINK, true);
break;
case UIModule.ATTRIBUTE_BASELINE_OFFSET:
final int offset = TiConvert.toInt(attrValue, 5);
spannableText.setSpan(new LineHeightSpan() {
@Override
public void chooseHeight(CharSequence charSequence, int i, int i1, int i2, int i3, Paint.FontMetricsInt fontMetricsInt) {
fontMetricsInt.bottom = offset * 2;
fontMetricsInt.descent = offset * 2;
}
}, range[0], range[0] + range[1], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public class UIModule extends KrollModule implements Handler.Callback
@Kroll.constant public static final int ATTRIBUTE_UNDERLINE_COLOR = 6;
@Kroll.constant public static final int ATTRIBUTE_SUPERSCRIPT_STYLE = 7;
@Kroll.constant public static final int ATTRIBUTE_SUBSCRIPT_STYLE = 8;
@Kroll.constant public static final int ATTRIBUTE_BASELINE_OFFSET = 9;

@Kroll.constant public static final int INPUT_TYPE_CLASS_NUMBER = InputType.TYPE_CLASS_NUMBER;
@Kroll.constant public static final int INPUT_TYPE_CLASS_TEXT = InputType.TYPE_CLASS_TEXT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,27 @@ public void handleEvent(int id)
int cancelIndex = (proxy.hasProperty(TiC.PROPERTY_CANCEL)) ?
TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_CANCEL)) : -1;
KrollDict data = new KrollDict();
if ((id & BUTTON_MASK) != 0) {
data.put(TiC.PROPERTY_BUTTON, true);
id &= ~BUTTON_MASK;
} else {
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);

// TIMOB-18500 Android: event.cancel not set properly for optionsDialog
boolean isCancel = id == cancelIndex;
if (!isCancel) {
if ((id & BUTTON_MASK) != 0) {
data.put(TiC.PROPERTY_BUTTON, true);
id &= ~BUTTON_MASK;
} else {
data.put(TiC.PROPERTY_BUTTON, false);
// If an option was selected and the user accepted it, update the proxy.
if (proxy.hasProperty(TiC.PROPERTY_OPTIONS)) {
proxy.setProperty(TiC.PROPERTY_SELECTED_INDEX, id);
}
}
}
data.put(TiC.EVENT_PROPERTY_INDEX, id);
data.put(TiC.PROPERTY_CANCEL, id == cancelIndex);
fireEvent(TiC.EVENT_CLICK, data);
data.put(TiC.PROPERTY_CANCEL, isCancel);
if (isCancel) {
fireEvent(TiC.EVENT_CANCEL, data);
} else {
fireEvent(TiC.EVENT_CLICK, data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class TiUIWebView extends TiUIView
private TiWebChromeClient chromeClient;
private boolean bindingCodeInjected = false;
private boolean isLocalHTML = false;
private boolean disableContextMenu = false;
private HashMap<String, String> extraHeaders = new HashMap<String, String>();

private static Enum<?> enumPluginStateOff;
Expand All @@ -74,7 +75,10 @@ public class TiUIWebView extends TiUIView
public static final int PLUGIN_STATE_ON = 1;
public static final int PLUGIN_STATE_ON_DEMAND = 2;

private boolean disableContextMenu = false;
// TIMOB-25462: minor 'hack' to prevent 'beforeload' and 'load' being
// called when the user-agent has been changed, this is a chromium bug
// https://bugs.chromium.org/p/chromium/issues/detail?id=315891
public boolean hasSetUserAgent = false;

private static enum reloadTypes
{
Expand Down Expand Up @@ -460,6 +464,10 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_DISABLE_CONTEXT_MENU)) {
disableContextMenu = TiConvert.toBoolean(d, TiC.PROPERTY_DISABLE_CONTEXT_MENU);
}

if (d.containsKey(TiC.PROPERTY_USER_AGENT)) {
((WebViewProxy) getProxy()).setUserAgent(d.getString(TiC.PROPERTY_USER_AGENT));
}
}

@Override
Expand Down Expand Up @@ -491,6 +499,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
}
} else if (TiC.PROPERTY_DISABLE_CONTEXT_MENU.equals(key)) {
disableContextMenu = TiConvert.toBoolean(newValue);
} else if (TiC.PROPERTY_USER_AGENT.equals(key)) {
((WebViewProxy) getProxy()).setUserAgent(TiConvert.toString(newValue));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down Expand Up @@ -828,6 +838,7 @@ public void setUserAgentString(String userAgentString)
{
WebView currWebView = getWebView();
if (currWebView != null) {
hasSetUserAgent = true;
currWebView.getSettings().setUserAgentString(userAgentString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void onPageFinished(WebView view, String url)
{
super.onPageFinished(view, url);
WebViewProxy proxy = (WebViewProxy) webView.getProxy();
if (proxy == null) {
if (proxy == null || webView.hasSetUserAgent) {
webView.hasSetUserAgent = false;
return;
}
webView.changeProxyUrl(url);
Expand Down Expand Up @@ -80,7 +81,7 @@ public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
WebViewProxy proxy = (WebViewProxy) webView.getProxy();
if (proxy == null) {
if (proxy == null || webView.hasSetUserAgent) {
return;
}
KrollDict data = new KrollDict();
Expand Down
18 changes: 10 additions & 8 deletions android/modules/ui/src/js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@

var bootstrap = require("bootstrap");

// Objects retained by persistent handles.
// Each element in this array acts as a storage "cell"
// keeping the object reachable and alive until it is removed.
persistentObjects = [];

// Keeps an object alive until dispose() is called.
// This is currently used to keep "top level" objects
// (ex: windows, tab groups) alive until their lifecycle ends.
function PersistentHandle(object) {
this.cell = persistentObjects.length;
persistentObjects.push(object);
this.cell = PersistentHandle.lastId++;
PersistentHandle.objects[this.cell] = object;
}

// Objects retained by persistent handles.
// Each element in this array acts as a storage "cell"
// keeping the object reachable and alive until it is removed.
PersistentHandle.objects = {};

PersistentHandle.lastId = 0;

PersistentHandle.prototype.dispose = function() {
if (this.cell == -1) {
// This handle has already been disposed.
return;
}

persistentObjects.splice(this.cell, 1);
delete PersistentHandle.objects[this.cell];
this.cell = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"minSDKVersion": "16",
"compileSDKVersion": "26",
"vendorDependencies": {
"android sdk": "25.x",
"android sdk": ">=23.x <=25.x",
"android build tools": "26.x",
"android platform tools": "26.x",
"android tools": "<=26.x",
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,11 @@ public class TiC
*/
public static final String PROPERTY_USE_SPINNER = "useSpinner";

/**
* @module.api
*/
public static final String PROPERTY_USER_AGENT = "userAgent";

/**
* @module.api
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ public ActionBarProxy(AppCompatActivity activity)
{
super();
actionBar = activity.getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
// Guard against calls to ActionBar made before inflating the ActionBarView
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
} else {
Log.w(TAG, "Trying to get a reference to ActionBar before its container was inflated.");
}
}

@Kroll.method @Kroll.setProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ public File getTempFileFromInputStream(InputStream is, String suffix, boolean de
return null;
}

public void destroyOnExit(File file)
{
tempFiles.add(file);
}

// Destroys all temporary files that have been created.
// This is called when the application is exited/destroyed.
public void destroyTempFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ private void initializeBorder(KrollDict d, Integer bgColor)
}
borderView.setRadius(radius);
}

if (bgColor != null) {
borderView.setBgColor(bgColor);
borderView.setColor(bgColor);
Expand All @@ -1428,14 +1428,21 @@ private void initializeBorder(KrollDict d, Integer bgColor)
borderView.setColor(TiConvert.toColor(d, TiC.PROPERTY_BORDER_COLOR));
}

//Have a default border width of 1
Object borderWidth = "1";
if (d.containsKey(TiC.PROPERTY_BORDER_WIDTH)) {
TiDimension width = TiConvert.toTiDimension(d.get(TiC.PROPERTY_BORDER_WIDTH), TiDimension.TYPE_WIDTH);
if (width != null) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
disableHWAcceleration();
}
borderView.setBorderWidth((float) width.getPixels(borderView));
borderWidth = d.get(TiC.PROPERTY_BORDER_WIDTH);
} else {
// Add the default width of 1 to the proxy as well
proxy.setProperty(TiC.PROPERTY_BORDER_WIDTH, borderWidth);
}

TiDimension width = TiConvert.toTiDimension(borderWidth, TiDimension.TYPE_WIDTH);
if (width != null) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) {
disableHWAcceleration();
}
borderView.setBorderWidth((float) width.getPixels(borderView));
}

nativeView.invalidate();
Expand Down
26 changes: 20 additions & 6 deletions android/titanium/src/java/ti/modules/titanium/TitaniumModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2017 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.
*/
Expand Down Expand Up @@ -255,7 +255,7 @@ public String stringFormat(String format, Object args[])
}

@Kroll.method @Kroll.topLevel("String.formatDate")
public String stringFormatDate(Date date, @Kroll.argument(optional=true) String format)
public String stringFormatDate(Object date, @Kroll.argument(optional=true) String format)
{
int style = DateFormat.SHORT;

Expand All @@ -269,16 +269,30 @@ public String stringFormatDate(Date date, @Kroll.argument(optional=true) String
style = DateFormat.FULL;
}
}

return (DateFormat.getDateInstance(style)).format(date);
if (date instanceof Date) {
return (DateFormat.getDateInstance(style)).format(date);
} else {
Log.e(TAG, "The string.formatDate() function was given an invalid argument. Must be of type 'Date'.");
return null;
}
}

@Kroll.method @Kroll.topLevel("String.formatTime")
public String stringFormatTime(Date time)
public String stringFormatTime(Object time)
{
int style = DateFormat.SHORT;

return (DateFormat.getTimeInstance(style)).format(time);
if (time instanceof Date) {
try {
return (DateFormat.getTimeInstance(style)).format(time);
} catch (Exception ex) {
Log.e(TAG, "Error occurred while formatting time", ex);
return null;
}
} else {
Log.e(TAG, "The string.formatTime() function was given an invalid argument. Must be of type 'Date'.");
return null;
}
}

@Kroll.method @Kroll.topLevel("String.formatCurrency")
Expand Down

0 comments on commit d0cf1fd

Please sign in to comment.