Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-27994
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaysingh-axway authored Jul 7, 2020
2 parents 46e094f + 7630868 commit 4c7dc8e
Show file tree
Hide file tree
Showing 54 changed files with 1,797 additions and 397 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ android/runtime/v8/tools/bootstrap.js
android/dev
android/modules/ui/assets/Resources/ti.internal/webview/*.js
android/titanium/build
android/**/generated/

iphone/Resources/app.js

# TODO: We probably do want to lint these eventually!
templates/**


titanium-mobile-mocha-suite/
tests/Resources/fake_node_modules/

dist/
android/**/generated/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ junit_report.xml

.nyc_output/
coverage/

tests/diffs/
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def androidUnitTests(nodeVersion, npmVersion, testSuiteBranch, testOnDevices) {
stash includes: 'junit.*.xml', name: 'test-report-android'
junit 'junit.*.xml'
} // dir('scripts')
archiveArtifacts allowEmptyArchive: true, artifacts: 'diffs/'
} // nodejs
} // dir('titanium-mobile-mocha-suite')
} finally {
Expand Down Expand Up @@ -172,6 +173,7 @@ def iosUnitTests(deviceFamily, nodeVersion, npmVersion, testSuiteBranch) {
stash includes: 'junit.ios.*.xml', name: "test-report-ios-${deviceFamily}"
junit 'junit.ios.*.xml'
} // dir('scripts')
archiveArtifacts allowEmptyArchive: true, artifacts: 'diffs/'
} // nodejs
} // dir('titanium-mobile-mocha-suite')
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.io.TiFileFactory;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Build;

Expand Down Expand Up @@ -64,8 +66,7 @@ public void handleCreationDict(KrollDict dict)
id = dict.getString(TiC.PROPERTY_ID);
shortcutBuilder = new ShortcutInfo.Builder(context, id);
} else {
Log.e(TAG, "id is required to create a shortcut!");
return;
throw new Error("id is required to create a shortcut!");
}

// create shortcut intent
Expand All @@ -83,14 +84,24 @@ public void handleCreationDict(KrollDict dict)
}
if (dict.containsKey(TiC.PROPERTY_ICON)) {
Object icon = dict.get(TiC.PROPERTY_ICON);
if (icon instanceof Number) {
int resId = ((Number) icon).intValue();
shortcutBuilder.setIcon(Icon.createWithResource(context, resId));
} else if (icon instanceof String) {
String uri = resolveUrl(null, dict.getString(TiC.PROPERTY_ICON));
shortcutBuilder.setIcon(Icon.createWithResource(context, TiUIHelper.getResourceId(uri)));
} else {
Log.w(TAG, "icon invalid, expecting resourceId (Number) or path (String)!");
try {
if (icon instanceof Number) {
int resId = ((Number) icon).intValue();
shortcutBuilder.setIcon(Icon.createWithResource(context, resId));

} else if (icon instanceof String) {
final String uri = resolveUrl(null, (String) icon);
final TiBlob blob = TiBlob.blobFromFile(TiFileFactory.createTitaniumFile(uri, false));
final Bitmap bitmap = blob.getImage();

if (bitmap != null) {
shortcutBuilder.setIcon(Icon.createWithBitmap(bitmap));
}
} else {
Log.w(TAG, "icon invalid, expecting resourceId (Number) or path (String)!");
}
} catch (Exception e) {
Log.w(TAG, e.getMessage());
}
}

Expand All @@ -102,40 +113,45 @@ public void handleCreationDict(KrollDict dict)
this.shortcuts.remove(shortcut);
}
}
this.shortcutManager.setDynamicShortcuts(shortcuts);
for (ShortcutInfo shortcut : this.shortcutManager.getDynamicShortcuts()) {
if (shortcut.getId().equals(this.shortcut.getId())) {
if (shortcut.isEnabled()) {
this.show();
}
} else {
this.shortcuts.add(shortcut);
}
}
this.shortcuts.add(shortcut);

super.handleCreationDict(dict);
}

@SuppressLint("NewApi")
@Deprecated
@Kroll.method
public void show()
{
if (shortcut != null) {
if (!shortcuts.contains(shortcut)) {
shortcuts.add(shortcut);
shortcutManager.setDynamicShortcuts(shortcuts);
try {
shortcutManager.addDynamicShortcuts(shortcuts);
} catch (Exception e) {
Log.w(TAG, e.getMessage());
}
}
}
}

@SuppressLint("NewApi")
@Deprecated
@Kroll.method
public void hide()
{
if (shortcut != null) {
if (shortcuts.contains(shortcut)) {
final List<String> shortcutIds = new ArrayList<>();

shortcutIds.add(shortcut.getId());
shortcuts.remove(shortcut);
shortcutManager.setDynamicShortcuts(shortcuts);

try {
shortcutManager.removeDynamicShortcuts(shortcutIds);
} catch (Exception e) {
Log.w(TAG, e.getMessage());
}
}
}
}
Expand All @@ -159,17 +175,32 @@ public void pin()
}
}

@SuppressLint("NewApi")
@Kroll.method
@Kroll.getProperty
public String getId()
{
if (shortcut != null) {
return shortcut.getId();
}
return null;
return properties.getString(TiC.PROPERTY_ID);
}

public String getTitle()
{
return properties.getString(TiC.PROPERTY_TITLE);
}

public String getDescription()
{
return properties.getString(TiC.PROPERTY_DESCRIPTION);
}

public Object getIcon()
{
return properties.get(TiC.PROPERTY_ICON);
}

public KrollDict getData()
{
return properties.getKrollDict(TiC.PROPERTY_DATA);
}

@Deprecated
@Kroll.method
@Kroll.getProperty
public boolean getVisible()
Expand All @@ -186,7 +217,6 @@ public void release()
{
if (shortcut != null) {
shortcuts.remove(shortcut);
shortcutManager.setDynamicShortcuts(shortcuts);
shortcut = null;
}
super.release();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2020 by Axway, 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.ui;

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

/**
* This module exist so `Ti.UI.Shortcut.addEventListener()` is defined.
* `Ti.UI.createShortcut` is manually defined in `UIModule`.
*/
@Kroll.module(parentModule = UIModule.class)
public class ShortcutModule extends KrollModule
{
private static final String TAG = "ShortcutModule";

public ShortcutModule()
{
super("Shortcut");
}

@Override
public String getApiName()
{
return "Ti.UI.Shortcut";
}
}
Loading

0 comments on commit 4c7dc8e

Please sign in to comment.