├── bin ├── templates │ ├── .weex_plugin.json │ ├── settings.gradle │ ├── app │ │ ├── src │ │ │ └── main │ │ │ │ ├── res │ │ │ │ ├── values │ │ │ │ │ ├── drawables.xml │ │ │ │ │ ├── dimens.xml │ │ │ │ │ ├── colors.xml │ │ │ │ │ ├── attrs.xml │ │ │ │ │ ├── strings.xml │ │ │ │ │ ├── themes.xml │ │ │ │ │ └── styles.xml │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ └── ic_launcher.png │ │ │ │ ├── drawable-hdpi │ │ │ │ │ ├── ic_action_scan.png │ │ │ │ │ └── ic_action_refresh.png │ │ │ │ ├── drawable-mdpi │ │ │ │ │ ├── ic_action_scan.png │ │ │ │ │ └── ic_action_refresh.png │ │ │ │ ├── drawable-xhdpi │ │ │ │ │ ├── ic_action_scan.png │ │ │ │ │ └── ic_action_refresh.png │ │ │ │ ├── drawable-xxhdpi │ │ │ │ │ ├── ic_action_scan.png │ │ │ │ │ └── ic_action_refresh.png │ │ │ │ ├── values-w820dp │ │ │ │ │ └── dimens.xml │ │ │ │ ├── values-v21 │ │ │ │ │ └── styles.xml │ │ │ │ ├── menu │ │ │ │ │ ├── main.xml │ │ │ │ │ └── main_scan.xml │ │ │ │ ├── xml │ │ │ │ │ └── app_config.xml │ │ │ │ ├── layout │ │ │ │ │ ├── activity_splash.xml │ │ │ │ │ └── activity_wxpage.xml │ │ │ │ └── values-zh-rCN │ │ │ │ │ └── strings.xml │ │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── weex │ │ │ │ │ └── app │ │ │ │ │ ├── util │ │ │ │ │ ├── Constants.java │ │ │ │ │ ├── AppConfig.java │ │ │ │ │ ├── AppConfigXmlParser.java │ │ │ │ │ ├── AppPreferences.java │ │ │ │ │ └── CommonUtils.java │ │ │ │ │ ├── WXApplication.java │ │ │ │ │ ├── extend │ │ │ │ │ ├── WXEventModule.java │ │ │ │ │ ├── BlurTransformation.java │ │ │ │ │ ├── ImageAdapter.java │ │ │ │ │ └── BlurTool.java │ │ │ │ │ ├── SplashActivity.java │ │ │ │ │ ├── hotreload │ │ │ │ │ └── HotReloadManager.java │ │ │ │ │ ├── WXPageActivity.java │ │ │ │ │ └── AbsWeexActivity.java │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── assets │ │ │ │ └── index.js │ │ ├── tools │ │ │ └── debug.keystore │ │ ├── .gitignore │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── README.md │ ├── NOTICE │ ├── gradle.properties │ ├── .gitignore │ ├── build.gradle │ ├── gradlew.bat │ ├── gradlew │ ├── LICENSE │ └── codeStyleSettings.xml ├── create.bat ├── update.bat ├── check_reqs.bat ├── android_sdk_version.bat ├── android_sdk_version ├── check_reqs ├── update ├── lib │ ├── android_sdk_version.js │ ├── create.js │ └── check_reqs.js └── create ├── README.md ├── NOTICE ├── .gitignore ├── package.json └── LICENSE /bin/templates/.weex_plugin.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### weex app template for weexpack -------------------------------------------------------------------------------- /bin/templates/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /bin/templates/app/tools/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/tools/debug.keystore -------------------------------------------------------------------------------- /bin/templates/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/templates/README.md: -------------------------------------------------------------------------------- 1 | ### weex apps samples 2 | 3 | *Please install the weex-toolkit before use hotrefresh* 4 | 5 | [Development Tools link](https://github.com/alibaba/weex_toolchain) -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-hdpi/ic_action_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-hdpi/ic_action_scan.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-mdpi/ic_action_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-mdpi/ic_action_scan.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-xhdpi/ic_action_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-xhdpi/ic_action_scan.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-hdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-hdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-mdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-mdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-xhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-xhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-xxhdpi/ic_action_scan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-xxhdpi/ic_action_scan.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weexteam/pack-android-tools-for-Apache-Weex/HEAD/bin/templates/app/src/main/res/drawable-xxhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Weex android playground 2 | Copyright 2016 Alibaba Group 3 | 4 | This product includes software developed at Alibaba Group. (http://www.alibabagroup.com) 5 | 6 | This product contains software zxing(https://github.com/zxing/zxing) developed 7 | by Google Inc. , licensed under the Apache License. -------------------------------------------------------------------------------- /bin/templates/NOTICE: -------------------------------------------------------------------------------- 1 | Weex android playground 2 | Copyright 2016 Alibaba Group 3 | 4 | This product includes software developed at Alibaba Group. (http://www.alibabagroup.com) 5 | 6 | This product contains software zxing(https://github.com/zxing/zxing) developed 7 | by Google Inc. , licensed under the Apache License. -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3eb4ff 4 | #3eb4ff 5 | #FF4081 6 | 7 | #66000000 8 | 9 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /bin/templates/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Dec 15 12:24:19 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | #distributionUrl=http://gw.alicdn.com/bao/uploaded/LB1J5WLJVXXXXcMXpXXXXXXXXXX.zip 8 | #distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 9 | #distributionUrl=gradle-2.10-bin.zip -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/xml/app_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | Hello 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/menu/main_scan.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 14 | 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | */bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/workspace.xml 38 | .idea/ 39 | 40 | # Keystore files 41 | *.jks 42 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /bin/templates/gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Mon Jun 27 20:06:22 CST 2016 16 | android.useDeprecatedNdk=true 17 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | WEEX APP 3 | WEEX\nPLAYGROUND 4 | 请将条码置于取景框内扫描 5 | Sorry, your current device is x86 architecture.\n We only 6 | support arm architecture devices! 7 | 8 | Network Error!\n1.Make sure you use the command "npm run serve" 9 | launched local service\n2.Make sure you modify "your_current_ip" to your local IP in 10 | "WXMainActivity" 11 | 12 | 扫码 13 | 刷新 14 | 15 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/layout/activity_splash.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 18 | 19 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | WEEX APP 19 | 20 | 请将条码置于取景框内扫描 21 | 对不起,您当前的设备是X86架构.\n我们只支持ARM架构的设备! 22 | 23 | 24 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.weex.app.util; 2 | 3 | public class Constants { 4 | 5 | // public static final String BUNDLE_URL = "http://t.cn?_wx_tpl=http://h5.waptest.taobao.com/app/weextc031/build/TC__Home.js"; 6 | public static final String BUNDLE_URL = "http://t.cn?_wx_tpl=http://g.tbcdn.cn/weex/weex-tc/0.1.0/build/TC__Home.js"; 7 | public static final String TEST_BUNDLE_URL = BUNDLE_URL; 8 | public static final String WEEX_SAMPLES_KEY = "?weex-samples"; 9 | public static final String WEEX_TPL_KEY = "_wx_tpl"; 10 | public static final String PARAM_BUNDLE_URL = "bundleUrl"; 11 | 12 | 13 | //hot refresh 14 | public static final int HOT_REFRESH_CONNECT = 0x111; 15 | public static final int HOT_REFRESH_DISCONNECT = HOT_REFRESH_CONNECT + 1; 16 | public static final int HOT_REFRESH_REFRESH = HOT_REFRESH_DISCONNECT + 1; 17 | public static final int HOT_REFRESH_CONNECT_ERROR = HOT_REFRESH_REFRESH + 1; 18 | 19 | public static final String ACTION_OPEN_URL = "com.alibaba.weex.protocol.openurl"; 20 | } 21 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/util/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.weex.app.util; 2 | 3 | import android.content.Context; 4 | 5 | 6 | /** 7 | * Created by budao on 2016/10/12. 8 | */ 9 | public class AppConfig { 10 | private static final String TAG = "AppConfig"; 11 | private static AppPreferences sPreferences = new AppPreferences(); 12 | 13 | public static void init(Context context) { 14 | loadAppSetting(context); 15 | } 16 | 17 | public static String getLaunchUrl() { 18 | if (isLaunchLocally()) { 19 | return sPreferences.getString("local_url", "file://assets/index.js"); 20 | } 21 | return sPreferences.getString("launch_url", "http://127.0.0.1:8080/dist/index.js"); 22 | } 23 | 24 | public static Boolean isLaunchLocally() { 25 | return sPreferences.getBoolean("launch_locally", false); 26 | } 27 | 28 | private static void loadAppSetting(Context context) { 29 | AppConfigXmlParser parser = new AppConfigXmlParser(); 30 | parser.parse(context); 31 | sPreferences = parser.getPreferences(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/WXApplication.java: -------------------------------------------------------------------------------- 1 | package com.weex.app; 2 | 3 | import android.app.Application; 4 | 5 | import com.weex.app.extend.ImageAdapter; 6 | import com.weex.app.extend.WXEventModule; 7 | import com.alibaba.weex.plugin.loader.WeexPluginContainer; 8 | import com.weex.app.util.AppConfig; 9 | import com.taobao.weex.InitConfig; 10 | import com.taobao.weex.WXSDKEngine; 11 | import com.taobao.weex.common.WXException; 12 | 13 | public class WXApplication extends Application { 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | WXSDKEngine.addCustomOptions("appName", "WXSample"); 19 | WXSDKEngine.addCustomOptions("appGroup", "WXApp"); 20 | WXSDKEngine.initialize(this, 21 | new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build() 22 | ); 23 | try { 24 | WXSDKEngine.registerModule("event", WXEventModule.class); 25 | } catch (WXException e) { 26 | e.printStackTrace(); 27 | } 28 | AppConfig.init(this); 29 | WeexPluginContainer.loadAll(this); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/extend/WXEventModule.java: -------------------------------------------------------------------------------- 1 | package com.weex.app.extend; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.text.TextUtils; 6 | 7 | import com.weex.app.WXPageActivity; 8 | import com.taobao.weex.annotation.JSMethod; 9 | import com.taobao.weex.common.WXModule; 10 | 11 | 12 | public class WXEventModule extends WXModule { 13 | @JSMethod() 14 | public void openURL(String url) { 15 | if (TextUtils.isEmpty(url)) { 16 | return; 17 | } 18 | Uri uri = Uri.parse(url); 19 | String scheme = uri.getScheme(); 20 | 21 | if (scheme.equals("http") || scheme.equals("https") || scheme.equals("file")) { 22 | Intent renderIntent = new Intent(mWXSDKInstance.getContext(), WXPageActivity.class); 23 | renderIntent.setData(uri); 24 | mWXSDKInstance.getContext().startActivity(renderIntent); 25 | } else { 26 | Intent intent = new Intent(Intent.ACTION_VIEW); 27 | intent.setData(uri); 28 | mWXSDKInstance.getContext().startActivity(intent); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 24 | 25 | -------------------------------------------------------------------------------- /bin/create.bat: -------------------------------------------------------------------------------- 1 | :: Licensed to the Apache Software Foundation (ASF) under one 2 | :: or more contributor license agreements. See the NOTICE file 3 | :: distributed with this work for additional information 4 | :: regarding copyright ownership. The ASF licenses this file 5 | :: to you under the Apache License, Version 2.0 (the 6 | :: "License"); you may not use this file except in compliance 7 | :: with the License. You may obtain a copy of the License at 8 | :: 9 | :: http://www.apache.org/licenses/LICENSE-2.0 10 | :: 11 | :: Unless required by applicable law or agreed to in writing, 12 | :: software distributed under the License is distributed on an 13 | :: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | :: KIND, either express or implied. See the License for the 15 | :: specific language governing permissions and limitations 16 | :: under the License. 17 | 18 | @ECHO OFF 19 | SET script_path="%~dp0create" 20 | IF EXIST %script_path% ( 21 | node %script_path% %* 22 | ) ELSE ( 23 | ECHO. 24 | ECHO ERROR: Could not find 'create' script in 'bin' folder, aborting...>&2 25 | EXIT /B 1 26 | ) -------------------------------------------------------------------------------- /bin/templates/app/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | 59 | -------------------------------------------------------------------------------- /bin/update.bat: -------------------------------------------------------------------------------- 1 | :: Licensed to the Apache Software Foundation (ASF) under one 2 | :: or more contributor license agreements. See the NOTICE file 3 | :: distributed with this work for additional information 4 | :: regarding copyright ownership. The ASF licenses this file 5 | :: to you under the Apache License, Version 2.0 (the 6 | :: "License"); you may not use this file except in compliance 7 | :: with the License. You may obtain a copy of the License at 8 | :: 9 | :: http://www.apache.org/licenses/LICENSE-2.0 10 | :: 11 | :: Unless required by applicable law or agreed to in writing, 12 | :: software distributed under the License is distributed on an 13 | :: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | :: KIND, either express or implied. See the License for the 15 | :: specific language governing permissions and limitations 16 | :: under the License. 17 | 18 | @ECHO OFF 19 | SET script_path="%~dp0update" 20 | IF EXIST %script_path% ( 21 | node %script_path% %* 22 | ) ELSE ( 23 | ECHO. 24 | ECHO ERROR: Could not find 'update' script in 'bin' folder, aborting...>&2 25 | EXIT /B 1 26 | ) 27 | -------------------------------------------------------------------------------- /bin/check_reqs.bat: -------------------------------------------------------------------------------- 1 | :: Licensed to the Apache Software Foundation (ASF) under one 2 | :: or more contributor license agreements. See the NOTICE file 3 | :: distributed with this work for additional information 4 | :: regarding copyright ownership. The ASF licenses this file 5 | :: to you under the Apache License, Version 2.0 (the 6 | :: "License"); you may not use this file except in compliance 7 | :: with the License. You may obtain a copy of the License at 8 | :: 9 | :: http://www.apache.org/licenses/LICENSE-2.0 10 | :: 11 | :: Unless required by applicable law or agreed to in writing, 12 | :: software distributed under the License is distributed on an 13 | :: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | :: KIND, either express or implied. See the License for the 15 | :: specific language governing permissions and limitations 16 | :: under the License. 17 | 18 | @ECHO OFF 19 | SET script_path="%~dp0check_reqs" 20 | IF EXIST %script_path% ( 21 | node "%script_path%" %* 22 | ) ELSE ( 23 | ECHO. 24 | ECHO ERROR: Could not find 'check_reqs' script in 'bin' folder, aborting...>&2 25 | EXIT /B 1 26 | ) 27 | -------------------------------------------------------------------------------- /bin/templates/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Android template 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # Intellij 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/dictionaries 43 | .idea/libraries 44 | 45 | # Keystore files 46 | *.jks 47 | 48 | # External native build folder generated in Android Studio 2.2 and later 49 | .externalNativeBuild 50 | 51 | # Google Services (e.g. APIs or Firebase) 52 | google-services.json 53 | 54 | # Freeline 55 | freeline.py 56 | freeline/ 57 | freeline_project_description.json 58 | 59 | .classpath 60 | .project 61 | .settings/ 62 | -------------------------------------------------------------------------------- /bin/android_sdk_version.bat: -------------------------------------------------------------------------------- 1 | :: Licensed to the Apache Software Foundation (ASF) under one 2 | :: or more contributor license agreements. See the NOTICE file 3 | :: distributed with this work for additional information 4 | :: regarding copyright ownership. The ASF licenses this file 5 | :: to you under the Apache License, Version 2.0 (the 6 | :: "License"); you may not use this file except in compliance 7 | :: with the License. You may obtain a copy of the License at 8 | :: 9 | :: http://www.apache.org/licenses/LICENSE-2.0 10 | :: 11 | :: Unless required by applicable law or agreed to in writing, 12 | :: software distributed under the License is distributed on an 13 | :: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | :: KIND, either express or implied. See the License for the 15 | :: specific language governing permissions and limitations 16 | :: under the License. 17 | 18 | @ECHO OFF 19 | SET script_path="%~dp0android_sdk_version" 20 | IF EXIST %script_path% ( 21 | node "%script_path%" %* 22 | ) ELSE ( 23 | ECHO. 24 | ECHO ERROR: Could not find 'android_sdk_version' script in 'bin' folder, aborting...>&2 25 | EXIT /B 1 26 | ) 27 | -------------------------------------------------------------------------------- /bin/android_sdk_version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | 22 | var android_sdk_version = require('./lib/android_sdk_version'); 23 | 24 | android_sdk_version.run().done(null, function(err) { 25 | console.log(err); 26 | process.exit(2); 27 | }); 28 | 29 | 30 | -------------------------------------------------------------------------------- /bin/templates/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | mavenLocal() 6 | jcenter() 7 | mavenCentral() 8 | maven { 9 | url 'https://maven.google.com/' 10 | name 'Google' 11 | } 12 | } 13 | dependencies { 14 | classpath 'com.android.tools.build:gradle:2.2.2' 15 | classpath 'com.taobao.android:weexplugin-gradle-plugin:1.3' 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | mavenLocal() 22 | jcenter() 23 | mavenCentral() 24 | maven { 25 | url 'https://maven.google.com/' 26 | name 'Google' 27 | } 28 | } 29 | } 30 | 31 | task clean(type: Delete) { 32 | delete rootProject.buildDir 33 | } 34 | 35 | subprojects { 36 | ext { 37 | compileSdkVersion=26 38 | buildToolsVersion="26.0.0" 39 | minSdkVersion=14 40 | appMinSdkVersion=15 41 | targetSdkVersion=26 42 | supportLibVersion="26.1.0" 43 | fastjsonLibVersion="1.1.46.android" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /bin/check_reqs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | 22 | var check_reqs = require('./lib/check_reqs'); 23 | 24 | check_reqs.run().done( 25 | function success() { 26 | console.log('Looks like your environment fully supports cordova-android development!'); 27 | }, function fail(err) { 28 | console.log(err); 29 | process.exit(2); 30 | } 31 | ); 32 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 27 | 28 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /bin/templates/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/lixinke/Tool/android-eclipse/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | ##weex 19 | -keep class com.taobao.weex.bridge.**{*;} 20 | -keep class com.taobao.weex.dom.**{*;} 21 | -keep class com.taobao.weex.adapter.**{*;} 22 | -keep class com.taobao.weex.common.**{*;} 23 | -keep class * implements com.taobao.weex.IWXObject{*;} 24 | -keep class com.taobao.weex.ui.**{*;} 25 | -keep class com.taobao.weex.ui.component.**{*;} 26 | -keep class com.taobao.weex.utils.**{ 27 | public ; 28 | public ; 29 | } 30 | -keep class com.taobao.weex.view.**{*;} 31 | -keep class com.taobao.weex.module.**{*;} 32 | -keep public class * extends com.taobao.weex.common.WXModule{*;} 33 | -keep public class com.taobao.weex.WXDebugTool{*;} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "weexpack-android", 3 | "version": "6.3.17", 4 | "description": "weexpack-android release", 5 | "bin": { 6 | "create": "bin/create" 7 | }, 8 | "main": "bin/templates/cordova/Api.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/weexteam/weexpack-android.git" 12 | }, 13 | "keywords": [ 14 | "android", 15 | "weexpack" 16 | ], 17 | "scripts": { 18 | "test": "npm run jshint && jasmine-node --color spec/unit", 19 | "cover": "istanbul cover --root bin/templates/cordova --print detail node_modules/jasmine-node/bin/jasmine-node -- spec/unit", 20 | "test-build": "jasmine-node --captureExceptions --color spec/e2e", 21 | "jshint": "node node_modules/jshint/bin/jshint bin && node node_modules/jshint/bin/jshint spec" 22 | }, 23 | "author": "Apache Software Foundation", 24 | "license": "Apache-2.0", 25 | "dependencies": { 26 | "cordova-common": "^1.5.0", 27 | "elementtree": "^0.1.6", 28 | "nopt": "^3.0.1", 29 | "properties-parser": "^0.2.3", 30 | "q": "^1.4.1", 31 | "shelljs": "^0.5.3", 32 | "weexpack-android": "^6.3.2" 33 | }, 34 | "bundledDependencies": [ 35 | "cordova-common", 36 | "elementtree", 37 | "nopt", 38 | "properties-parser", 39 | "q", 40 | "shelljs" 41 | ], 42 | "devDependencies": { 43 | "istanbul": "^0.4.2", 44 | "jasmine-node": "^1.14.5", 45 | "jshint": "^2.6.0", 46 | "promise-matchers": "~0", 47 | "rewire": "^2.1.3" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | var path = require('path'); 22 | var Api = require('./templates/cordova/Api'); 23 | var args = require('nopt')({ 24 | 'link': Boolean, 25 | 'shared': Boolean, 26 | 'help': Boolean 27 | }, { 'd' : '--verbose' }); 28 | 29 | if (args.help || args.argv.remain.length === 0) { 30 | console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update')) + ' [--link]'); 31 | console.log(' --link will use the CordovaLib project directly instead of making a copy.'); 32 | process.exit(1); 33 | } 34 | 35 | require('./templates/cordova/loggingHelper').adjustLoggerLevel(args); 36 | 37 | Api.updatePlatform(args.argv.remain[0], {link: (args.link || args.shared)}).done(); 38 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/res/layout/activity_wxpage.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 14 | 15 | 20 | 21 | 22 | 23 | 29 | 30 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/extend/BlurTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.weex.app.extend; 20 | 21 | import android.graphics.Bitmap; 22 | 23 | import com.squareup.picasso.Transformation; 24 | 25 | public class BlurTransformation implements Transformation { 26 | 27 | private int mRadius; 28 | 29 | public BlurTransformation(int radius) { 30 | mRadius = radius; 31 | } 32 | 33 | @Override public Bitmap transform(Bitmap source) { 34 | if(mRadius <= 0) { 35 | return source; 36 | } 37 | Bitmap bitmap; 38 | try { 39 | bitmap = BlurTool.blur(source, mRadius); 40 | }catch (Exception e){ 41 | bitmap = source; 42 | } 43 | if(bitmap != source) { 44 | source.recycle(); 45 | } 46 | return bitmap; 47 | } 48 | 49 | @Override public String key() { 50 | return "BlurTransformation(radius=" + mRadius + ")"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/SplashActivity.java: -------------------------------------------------------------------------------- 1 | package com.weex.app; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.view.animation.Animation; 9 | import android.view.animation.AnimationSet; 10 | import android.view.animation.RotateAnimation; 11 | import android.view.animation.ScaleAnimation; 12 | 13 | 14 | public class SplashActivity extends AppCompatActivity { 15 | 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_splash); 21 | 22 | View textView = findViewById(R.id.fullscreen_content); 23 | ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 24 | RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 25 | 26 | AnimationSet animationSet = new AnimationSet(false); 27 | animationSet.addAnimation(scaleAnimation); 28 | animationSet.addAnimation(rotateAnimation); 29 | animationSet.setDuration(1500); 30 | 31 | animationSet.setAnimationListener(new Animation.AnimationListener() { 32 | @Override 33 | public void onAnimationStart(Animation animation) { 34 | } 35 | 36 | @Override 37 | public void onAnimationEnd(Animation animation) { 38 | Intent intent = new Intent(SplashActivity.this, WXPageActivity.class); 39 | Uri data = getIntent().getData(); 40 | if (data != null) { 41 | intent.setData(data); 42 | } 43 | intent.putExtra("from", "splash"); 44 | startActivity(intent); 45 | finish(); 46 | } 47 | 48 | @Override 49 | public void onAnimationRepeat(Animation animation) { 50 | } 51 | }); 52 | textView.startAnimation(animationSet); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/assets/index.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) 10 | /******/ return installedModules[moduleId].exports; 11 | 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ exports: {}, 15 | /******/ id: moduleId, 16 | /******/ loaded: false 17 | /******/ }; 18 | 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | 22 | /******/ // Flag the module as loaded 23 | /******/ module.loaded = true; 24 | 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | 29 | 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | 36 | /******/ // __webpack_public_path__ 37 | /******/ __webpack_require__.p = ""; 38 | 39 | /******/ // Load entry module and return exports 40 | /******/ return __webpack_require__(0); 41 | /******/ }) 42 | /************************************************************************/ 43 | /******/ ([ 44 | /* 0 */ 45 | /***/ function(module, exports) { 46 | 47 | ;__weex_define__("@weex-component/0f3c9ae76450de3e67cfabcbf5621bf7", [], function(__weex_require__, __weex_exports__, __weex_module__){ 48 | 49 | ;__weex_module__.exports.template = __weex_module__.exports.template || {} 50 | ;Object.assign(__weex_module__.exports.template, { 51 | "type": "div", 52 | "children": [ 53 | { 54 | "type": "text", 55 | "style": { 56 | "fontSize": 100 57 | }, 58 | "attr": { 59 | "value": "Hello World." 60 | } 61 | } 62 | ] 63 | }) 64 | }) 65 | ;__weex_bootstrap__("@weex-component/0f3c9ae76450de3e67cfabcbf5621bf7", { 66 | "transformerVersion": "0.3.1" 67 | },undefined) 68 | 69 | /***/ } 70 | /******/ ]); -------------------------------------------------------------------------------- /bin/lib/android_sdk_version.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | 22 | var child_process = require('child_process'), 23 | Q = require('q'); 24 | 25 | var get_highest_sdk = function(results){ 26 | var reg = /\d+/; 27 | var apiLevels = []; 28 | for(var i=0;iNUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /bin/create: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | var path = require('path'); 22 | var ConfigParser = require('cordova-common').ConfigParser; 23 | var Api = require('./templates/cordova/Api'); 24 | 25 | var argv = require('nopt')({ 26 | 'help' : Boolean, 27 | 'cli' : Boolean, 28 | 'shared' : Boolean, 29 | 'link' : Boolean, 30 | 'activity-name' : [String, undefined] 31 | }, { 'd' : '--verbose' }); 32 | 33 | if (argv.help || argv.argv.remain.length === 0) { 34 | console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create')) + ' [] [--activity-name ] [--link]'); 35 | console.log(' : Path to your new Cordova Android project'); 36 | console.log(' : Package name, following reverse-domain style convention'); 37 | console.log(' : Project name'); 38 | console.log(' : Path to a custom application template to use'); 39 | console.log(' --activity-name : Activity name'); 40 | console.log(' --link will use the CordovaLib project directly instead of making a copy.'); 41 | process.exit(1); 42 | } 43 | 44 | var config = new ConfigParser(path.resolve(__dirname, 'templates/project/res/xml/config.xml')); 45 | 46 | if (argv.argv.remain[1]) config.setPackageName(argv.argv.remain[1]); 47 | if (argv.argv.remain[2]) config.setName(argv.argv.remain[2]); 48 | if (argv['activity-name']) config.setName(argv['activity-name']); 49 | 50 | var options = { 51 | link: argv.link || argv.shared, 52 | customTemplate: argv.argv.remain[3], 53 | activityName: argv['activity-name'] 54 | }; 55 | 56 | require('./templates/cordova/loggingHelper').adjustLoggerLevel(argv); 57 | 58 | Api.createPlatform(argv.argv.remain[0], config, options).done(); 59 | -------------------------------------------------------------------------------- /bin/templates/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.taobao.android.weex.plugin.gradle' 3 | 4 | android { 5 | compileSdkVersion project.compileSdkVersion 6 | buildToolsVersion project.buildToolsVersion 7 | 8 | defaultConfig { 9 | applicationId "com.weex.app" 10 | minSdkVersion project.appMinSdkVersion 11 | targetSdkVersion project.targetSdkVersion 12 | versionCode 1 13 | versionName "1.0.0" 14 | ndk { 15 | abiFilters "x86" 16 | abiFilters "armeabi" 17 | } 18 | } 19 | applicationVariants.all { variant -> 20 | variant.outputs.each { output -> 21 | def outputFile = output.outputFile 22 | if (outputFile != null && outputFile.name.equals('app-debug.apk')) { 23 | def fileName = outputFile.name.replace("app-debug.apk", "weex-app.apk") 24 | output.outputFile = new File(outputFile.parent, fileName) 25 | } 26 | } 27 | } 28 | signingConfigs { 29 | debug { 30 | storeFile file("tools/debug.keystore") 31 | storePassword "android" 32 | keyAlias "androiddebugkey" 33 | keyPassword "android" 34 | } 35 | } 36 | buildTypes { 37 | debug { 38 | signingConfig signingConfigs.debug 39 | } 40 | } 41 | sourceSets { 42 | main { 43 | java { 44 | srcDirs = ["src/main/java", "src/main/java_zxing"]; 45 | } 46 | } 47 | } 48 | lintOptions { 49 | abortOnError false 50 | } 51 | 52 | packagingOptions { 53 | exclude 'LICENSE.txt' 54 | } 55 | 56 | compileOptions { 57 | sourceCompatibility JavaVersion.VERSION_1_7 58 | targetCompatibility JavaVersion.VERSION_1_7 59 | } 60 | } 61 | 62 | 63 | dependencies { 64 | compile fileTree(include: ['*.jar'], dir: 'libs') 65 | compile 'com.taobao.android:weex_sdk:0.16.0' 66 | compile 'com.google.code.findbugs:jsr305:2.0.1' 67 | compile 'com.squareup.okhttp:okhttp:2.3.0' 68 | compile 'com.squareup.okhttp:okhttp-ws:2.3.0' 69 | compile 'com.squareup.okio:okio:1.0.1' 70 | compile 'com.squareup.picasso:picasso:2.5.2' 71 | compile "com.alibaba:fastjson:${project.fastjsonLibVersion}" 72 | compile "com.android.support:support-v4:${project.supportLibVersion}" 73 | compile "com.android.support:appcompat-v7:${project.supportLibVersion}" 74 | compile "com.android.support:design:${project.supportLibVersion}" 75 | compile "com.android.support:support-annotations:${project.supportLibVersion}" 76 | compile 'com.taobao.android:weex_inspector:0.10.0.5' 77 | compile 'com.journeyapps:zxing-android-embedded:3.4.0' 78 | // PLUGIN GRADLE EXTENSIONS START 79 | compile 'com.taobao.android:weexplugin-loader:1.3' 80 | compile 'com.taobao.android:weexplugin-processor:1.3' 81 | compile 'com.taobao.android:weexplugin-annotation:1.3' 82 | // PLUGIN GRADLE EXTENSIONS END 83 | } 84 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/util/AppConfigXmlParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | package com.weex.app.util; 21 | 22 | import android.content.Context; 23 | import android.util.Log; 24 | 25 | import org.xmlpull.v1.XmlPullParser; 26 | import org.xmlpull.v1.XmlPullParserException; 27 | 28 | import java.io.IOException; 29 | import java.util.Locale; 30 | 31 | public class AppConfigXmlParser { 32 | private static String TAG = "AppConfigXmlParser"; 33 | 34 | private AppPreferences prefs = new AppPreferences(); 35 | 36 | public AppPreferences getPreferences() { 37 | return prefs; 38 | } 39 | 40 | public synchronized void parse(Context action) { 41 | // First checking the class namespace for config.xml 42 | int id = action.getResources().getIdentifier("app_config", "xml", action.getClass().getPackage() 43 | .getName()); 44 | if (id == 0) { 45 | // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml 46 | id = action.getResources().getIdentifier("app_config", "xml", action.getPackageName()); 47 | if (id == 0) { 48 | Log.e(TAG, "res/xml/app_config.xml is missing!"); 49 | return; 50 | } 51 | } 52 | parse(action.getResources().getXml(id)); 53 | } 54 | 55 | public void parse(XmlPullParser xml) { 56 | int eventType = -1; 57 | 58 | while (eventType != XmlPullParser.END_DOCUMENT) { 59 | if (eventType == XmlPullParser.START_TAG) { 60 | handleStartTag(xml); 61 | } else if (eventType == XmlPullParser.END_TAG) { 62 | handleEndTag(xml); 63 | } 64 | try { 65 | eventType = xml.next(); 66 | } catch (XmlPullParserException e) { 67 | e.printStackTrace(); 68 | } catch (IOException e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | } 73 | 74 | private void handleStartTag(XmlPullParser xml) { 75 | String strNode = xml.getName(); 76 | if (strNode.equals("preference")) { 77 | String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.ENGLISH); 78 | String value = xml.getAttributeValue(null, "value"); 79 | prefs.set(name, value); 80 | } 81 | } 82 | 83 | private void handleEndTag(XmlPullParser xml) { 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/util/AppPreferences.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | package com.weex.app.util; 21 | 22 | import android.os.Bundle; 23 | 24 | import java.util.HashMap; 25 | import java.util.Locale; 26 | import java.util.Map; 27 | 28 | public class AppPreferences { 29 | private HashMap prefs = new HashMap(20); 30 | private Bundle preferencesBundleExtras; 31 | 32 | public void setPreferencesBundle(Bundle extras) { 33 | preferencesBundleExtras = extras; 34 | } 35 | 36 | public void set(String name, String value) { 37 | prefs.put(name.toLowerCase(Locale.ENGLISH), value); 38 | } 39 | 40 | public void set(String name, boolean value) { 41 | set(name, "" + value); 42 | } 43 | 44 | public void set(String name, int value) { 45 | set(name, "" + value); 46 | } 47 | 48 | public void set(String name, double value) { 49 | set(name, "" + value); 50 | } 51 | 52 | public Map getAll() { 53 | return prefs; 54 | } 55 | 56 | public boolean getBoolean(String name, boolean defaultValue) { 57 | name = name.toLowerCase(Locale.ENGLISH); 58 | String value = prefs.get(name); 59 | if (value != null) { 60 | return Boolean.parseBoolean(value); 61 | } 62 | return defaultValue; 63 | } 64 | 65 | // Added in 4.0.0 66 | public boolean contains(String name) { 67 | return getString(name, null) != null; 68 | } 69 | 70 | public int getInteger(String name, int defaultValue) { 71 | name = name.toLowerCase(Locale.ENGLISH); 72 | String value = prefs.get(name); 73 | if (value != null) { 74 | // Use Integer.decode() can't handle it if the highest bit is set. 75 | return (int)(long) Long.decode(value); 76 | } 77 | return defaultValue; 78 | } 79 | 80 | public double getDouble(String name, double defaultValue) { 81 | name = name.toLowerCase(Locale.ENGLISH); 82 | String value = prefs.get(name); 83 | if (value != null) { 84 | return Double.valueOf(value); 85 | } 86 | return defaultValue; 87 | } 88 | 89 | public String getString(String name, String defaultValue) { 90 | name = name.toLowerCase(Locale.ENGLISH); 91 | String value = prefs.get(name); 92 | if (value != null) { 93 | return value; 94 | } 95 | return defaultValue; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/extend/ImageAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.weex.app.extend; 20 | 21 | import android.net.Uri; 22 | import android.text.TextUtils; 23 | import android.widget.ImageView; 24 | 25 | import com.squareup.picasso.Callback; 26 | import com.squareup.picasso.Picasso; 27 | import com.taobao.weex.WXEnvironment; 28 | import com.taobao.weex.WXSDKManager; 29 | import com.taobao.weex.adapter.IWXImgLoaderAdapter; 30 | import com.taobao.weex.common.WXImageStrategy; 31 | import com.taobao.weex.dom.WXImageQuality; 32 | 33 | public class ImageAdapter implements IWXImgLoaderAdapter { 34 | 35 | public ImageAdapter() { 36 | } 37 | 38 | @Override 39 | public void setImage(final String url, final ImageView view, 40 | WXImageQuality quality, final WXImageStrategy strategy) { 41 | 42 | WXSDKManager.getInstance().postOnUiThread(new Runnable() { 43 | 44 | @Override 45 | public void run() { 46 | if(view==null||view.getLayoutParams()==null){ 47 | return; 48 | } 49 | if (TextUtils.isEmpty(url)) { 50 | view.setImageBitmap(null); 51 | return; 52 | } 53 | String temp = url; 54 | if (url.startsWith("//")) { 55 | temp = "http:" + url; 56 | } 57 | if (view.getLayoutParams().width <= 0 || view.getLayoutParams().height <= 0) { 58 | return; 59 | } 60 | 61 | 62 | if(!TextUtils.isEmpty(strategy.placeHolder)){ 63 | Picasso.Builder builder=new Picasso.Builder(WXEnvironment.getApplication()); 64 | Picasso picasso=builder.build(); 65 | picasso.load(Uri.parse(strategy.placeHolder)).into(view); 66 | 67 | view.setTag(strategy.placeHolder.hashCode(),picasso); 68 | } 69 | 70 | Picasso.with(WXEnvironment.getApplication()) 71 | .load(temp) 72 | .transform(new BlurTransformation(strategy.blurRadius)) 73 | .into(view, new Callback() { 74 | @Override 75 | public void onSuccess() { 76 | if(strategy.getImageListener()!=null){ 77 | strategy.getImageListener().onImageFinish(url,view,true,null); 78 | } 79 | 80 | if(!TextUtils.isEmpty(strategy.placeHolder)){ 81 | ((Picasso) view.getTag(strategy.placeHolder.hashCode())).cancelRequest(view); 82 | } 83 | } 84 | 85 | @Override 86 | public void onError() { 87 | if(strategy.getImageListener()!=null){ 88 | strategy.getImageListener().onImageFinish(url,view,false,null); 89 | } 90 | } 91 | }); 92 | } 93 | },0); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/hotreload/HotReloadManager.java: -------------------------------------------------------------------------------- 1 | package com.weex.app.hotreload; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.squareup.okhttp.OkHttpClient; 6 | import com.squareup.okhttp.Request; 7 | import com.squareup.okhttp.Response; 8 | import com.squareup.okhttp.ws.WebSocket; 9 | import com.squareup.okhttp.ws.WebSocketCall; 10 | import com.squareup.okhttp.ws.WebSocketListener; 11 | import com.taobao.weex.utils.WXLogUtils; 12 | 13 | import org.json.JSONException; 14 | import org.json.JSONObject; 15 | 16 | import java.io.IOException; 17 | 18 | import okio.Buffer; 19 | import okio.BufferedSource; 20 | 21 | /** 22 | * Created by moxun on 29/12/2017. 23 | */ 24 | 25 | public class HotReloadManager { 26 | private static final String TAG = "HotReloadManager"; 27 | private ActionListener listener; 28 | private WebSocket session; 29 | 30 | public HotReloadManager(String ws, final ActionListener actionListener) { 31 | if (TextUtils.isEmpty(ws) || actionListener == null) { 32 | WXLogUtils.w("HotReloadManager", "Illegal arguments"); 33 | return; 34 | } 35 | this.listener = actionListener; 36 | 37 | OkHttpClient client = new OkHttpClient(); 38 | Request.Builder builder = new Request.Builder(); 39 | builder.url(ws); 40 | Request request = builder.build(); 41 | WebSocketCall call = WebSocketCall.create(client, request); 42 | call.enqueue(new WebSocketListener() { 43 | @Override 44 | public void onOpen(WebSocket webSocket, Request request, Response response) throws IOException { 45 | WXLogUtils.w(TAG, "ws session open"); 46 | session = webSocket; 47 | } 48 | 49 | @Override 50 | public void onMessage(BufferedSource bufferedSource, WebSocket.PayloadType payloadType) throws IOException { 51 | WXLogUtils.w(TAG, "on message"); 52 | if (payloadType == WebSocket.PayloadType.TEXT) { 53 | String message = bufferedSource.readUtf8(); 54 | bufferedSource.close(); 55 | try { 56 | JSONObject rpcMessage = new JSONObject(message); 57 | String method = rpcMessage.optString("method", null); 58 | if (!TextUtils.isEmpty(method)) { 59 | if ("WXReload".equals(method)) { 60 | listener.reload(); 61 | } else if ("WXReloadBundle".equals(method)) { 62 | String bundleUrl = rpcMessage.optString("params", null); 63 | if (!TextUtils.isEmpty(bundleUrl)) { 64 | listener.render(bundleUrl); 65 | } 66 | } 67 | } 68 | } catch (JSONException e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | } 73 | 74 | @Override 75 | public void onPong(Buffer buffer) { 76 | WXLogUtils.w(TAG, "on pong"); 77 | } 78 | 79 | @Override 80 | public void onClose(int i, String s) { 81 | WXLogUtils.w("HotReloadManager", "Closed:" + i + ", " + s); 82 | } 83 | 84 | @Override 85 | public void onFailure(IOException e) { 86 | e.printStackTrace(); 87 | } 88 | }); 89 | } 90 | 91 | public void destroy() { 92 | if (session != null) { 93 | try { 94 | session.close(1001, "GOING_AWAY"); 95 | } catch (IOException e) { 96 | e.printStackTrace(); 97 | } 98 | } 99 | } 100 | 101 | public interface ActionListener { 102 | void reload(); 103 | 104 | void render(String bundleUrl); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /bin/templates/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/WXPageActivity.java: -------------------------------------------------------------------------------- 1 | package com.weex.app; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.content.LocalBroadcastManager; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.ProgressBar; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.weex.app.hotreload.HotReloadManager; 19 | import com.weex.app.util.AppConfig; 20 | import com.weex.app.util.Constants; 21 | import com.google.zxing.integration.android.IntentIntegrator; 22 | import com.google.zxing.integration.android.IntentResult; 23 | import com.taobao.weex.WXEnvironment; 24 | import com.taobao.weex.WXRenderErrorCode; 25 | import com.taobao.weex.WXSDKEngine; 26 | import com.taobao.weex.WXSDKInstance; 27 | import com.taobao.weex.ui.component.NestedContainer; 28 | import com.taobao.weex.utils.WXLogUtils; 29 | import com.taobao.weex.utils.WXSoInstallMgrSdk; 30 | 31 | import org.json.JSONException; 32 | import org.json.JSONObject; 33 | 34 | 35 | public class WXPageActivity extends AbsWeexActivity implements 36 | WXSDKInstance.NestedInstanceInterceptor { 37 | 38 | private static final String TAG = "WXPageActivity"; 39 | private ProgressBar mProgressBar; 40 | private TextView mTipView; 41 | private boolean mFromSplash = false; 42 | private HotReloadManager mHotReloadManager; 43 | 44 | @Override 45 | public void onCreateNestInstance(WXSDKInstance instance, NestedContainer container) { 46 | Log.d(TAG, "Nested Instance created."); 47 | } 48 | 49 | @Override 50 | protected void onCreate(Bundle savedInstanceState) { 51 | super.onCreate(savedInstanceState); 52 | setContentView(R.layout.activity_wxpage); 53 | mContainer = (ViewGroup) findViewById(R.id.container); 54 | mProgressBar = (ProgressBar) findViewById(R.id.progress); 55 | mTipView = (TextView) findViewById(R.id.index_tip); 56 | 57 | Intent intent = getIntent(); 58 | Uri uri = intent.getData(); 59 | String from = intent.getStringExtra("from"); 60 | mFromSplash = "splash".equals(from); 61 | 62 | if (uri == null) { 63 | uri = Uri.parse("{}"); 64 | } 65 | if (uri != null) { 66 | try { 67 | JSONObject initData = new JSONObject(uri.toString()); 68 | String bundleUrl = initData.optString("WeexBundle", null); 69 | if (bundleUrl != null) { 70 | mUri = Uri.parse(bundleUrl); 71 | } 72 | 73 | String ws = initData.optString("Ws", null); 74 | if (!TextUtils.isEmpty(ws)) { 75 | mHotReloadManager = new HotReloadManager(ws, new HotReloadManager.ActionListener() { 76 | @Override 77 | public void reload() { 78 | runOnUiThread(new Runnable() { 79 | @Override 80 | public void run() { 81 | Toast.makeText(WXPageActivity.this, "Hot reload", Toast.LENGTH_SHORT).show(); 82 | createWeexInstance(); 83 | renderPage(); 84 | } 85 | }); 86 | } 87 | 88 | @Override 89 | public void render(final String bundleUrl) { 90 | runOnUiThread(new Runnable() { 91 | @Override 92 | public void run() { 93 | Toast.makeText(WXPageActivity.this, "Render: " + bundleUrl, Toast.LENGTH_SHORT).show(); 94 | createWeexInstance(); 95 | loadUrl(bundleUrl); 96 | } 97 | }); 98 | } 99 | }); 100 | } else { 101 | WXLogUtils.w("Weex", "can not get hot reload config"); 102 | } 103 | } catch (JSONException e) { 104 | e.printStackTrace(); 105 | } 106 | } 107 | 108 | if (mUri == null) { 109 | mUri = Uri.parse(AppConfig.getLaunchUrl()); 110 | } 111 | 112 | if (!WXSoInstallMgrSdk.isCPUSupport()) { 113 | mProgressBar.setVisibility(View.INVISIBLE); 114 | mTipView.setText(R.string.cpu_not_support_tip); 115 | return; 116 | } 117 | 118 | String url = getUrl(mUri); 119 | if (getSupportActionBar() != null) { 120 | getSupportActionBar().setTitle(url); 121 | getSupportActionBar().hide(); 122 | } 123 | loadUrl(url); 124 | } 125 | 126 | private String getUrl(Uri uri) { 127 | String url = uri.toString(); 128 | String scheme = uri.getScheme(); 129 | if (uri.isHierarchical()) { 130 | if (TextUtils.equals(scheme, "http") || TextUtils.equals(scheme, "https")) { 131 | String weexTpl = uri.getQueryParameter(Constants.WEEX_TPL_KEY); 132 | if (!TextUtils.isEmpty(weexTpl)) { 133 | url = weexTpl; 134 | } 135 | } 136 | } 137 | return url; 138 | } 139 | 140 | protected void preRenderPage() { 141 | mProgressBar.setVisibility(View.VISIBLE); 142 | } 143 | 144 | @Override 145 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 146 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 147 | Intent intent = new Intent("requestPermission"); 148 | intent.putExtra("REQUEST_PERMISSION_CODE", requestCode); 149 | intent.putExtra("permissions", permissions); 150 | intent.putExtra("grantResults", grantResults); 151 | LocalBroadcastManager.getInstance(this).sendBroadcast(intent); 152 | } 153 | 154 | 155 | @Override 156 | public void onRenderSuccess(WXSDKInstance instance, int width, int height) { 157 | mProgressBar.setVisibility(View.GONE); 158 | mTipView.setVisibility(View.GONE); 159 | } 160 | 161 | @Override 162 | public void onException(WXSDKInstance instance, String errCode, String msg) { 163 | mProgressBar.setVisibility(View.GONE); 164 | mTipView.setVisibility(View.VISIBLE); 165 | if (TextUtils.equals(errCode, WXRenderErrorCode.WX_NETWORK_ERROR)) { 166 | mTipView.setText(R.string.index_tip); 167 | } else { 168 | mTipView.setText("render error:" + errCode); 169 | } 170 | } 171 | 172 | @Override 173 | public boolean onCreateOptionsMenu(Menu menu) { 174 | getMenuInflater().inflate(mFromSplash ? R.menu.main_scan : R.menu.main, menu); 175 | return super.onCreateOptionsMenu(menu); 176 | } 177 | 178 | @Override 179 | public boolean onOptionsItemSelected(MenuItem item) { 180 | switch (item.getItemId()) { 181 | case R.id.action_refresh: 182 | createWeexInstance(); 183 | renderPage(); 184 | break; 185 | case R.id.action_scan: 186 | IntentIntegrator integrator = new IntentIntegrator(this); 187 | integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES); 188 | integrator.setPrompt("Scan a barcode"); 189 | //integrator.setCameraId(0); // Use a specific camera of the device 190 | integrator.setBeepEnabled(true); 191 | integrator.setOrientationLocked(false); 192 | integrator.setBarcodeImageEnabled(true); 193 | integrator.setPrompt(getString(R.string.capture_qrcode_prompt)); 194 | integrator.initiateScan(); 195 | break; 196 | case android.R.id.home: 197 | finish(); 198 | default: 199 | break; 200 | } 201 | 202 | return super.onOptionsItemSelected(item); 203 | } 204 | 205 | @Override 206 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 207 | IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 208 | if (result != null) { 209 | if (result.getContents() == null) { 210 | Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); 211 | } else { 212 | handleDecodeInternally(result.getContents()); 213 | } 214 | } 215 | super.onActivityResult(requestCode, resultCode, data); 216 | } 217 | 218 | // Put up our own UI for how to handle the decoded contents. 219 | private void handleDecodeInternally(String code) { 220 | 221 | if (!TextUtils.isEmpty(code)) { 222 | Uri uri = Uri.parse(code); 223 | if (uri.getQueryParameterNames().contains("bundle")) { 224 | WXEnvironment.sDynamicMode = uri.getBooleanQueryParameter("debug", false); 225 | WXEnvironment.sDynamicUrl = uri.getQueryParameter("bundle"); 226 | String tip = WXEnvironment.sDynamicMode ? "Has switched to Dynamic Mode" : "Has switched to Normal Mode"; 227 | Toast.makeText(this, tip, Toast.LENGTH_SHORT).show(); 228 | finish(); 229 | return; 230 | } else if (uri.getQueryParameterNames().contains("_wx_devtool")) { 231 | WXEnvironment.sRemoteDebugProxyUrl = uri.getQueryParameter("_wx_devtool"); 232 | WXEnvironment.sDebugServerConnectable = true; 233 | WXSDKEngine.reload(); 234 | Toast.makeText(this, "devtool", Toast.LENGTH_SHORT).show(); 235 | return; 236 | } else if (code.contains("_wx_debug")) { 237 | uri = Uri.parse(code); 238 | String debug_url = uri.getQueryParameter("_wx_debug"); 239 | WXSDKEngine.switchDebugModel(true, debug_url); 240 | finish(); 241 | } else { 242 | JSONObject data = new JSONObject(); 243 | try { 244 | data.put("WeexBundle", Uri.parse(code).toString()); 245 | Intent intent = new Intent(WXPageActivity.this, WXPageActivity.class); 246 | intent.setData(Uri.parse(data.toString())); 247 | startActivity(intent); 248 | } catch (JSONException e) { 249 | e.printStackTrace(); 250 | } 251 | } 252 | } 253 | } 254 | 255 | @Override 256 | public void onDestroy() { 257 | super.onDestroy(); 258 | if (mHotReloadManager != null) { 259 | mHotReloadManager.destroy(); 260 | } 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/extend/BlurTool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package com.weex.app.extend; 20 | 21 | import android.graphics.Bitmap; 22 | import android.support.annotation.NonNull; 23 | import android.support.annotation.Nullable; 24 | 25 | import com.taobao.weex.utils.WXLogUtils; 26 | 27 | import java.util.concurrent.ExecutorService; 28 | import java.util.concurrent.Executors; 29 | import java.util.concurrent.ThreadFactory; 30 | 31 | /** 32 | * Created by rowandjj(chuyi)
33 | */ 34 | 35 | public class BlurTool { 36 | 37 | public interface OnBlurCompleteListener { 38 | /** 39 | * blur complete event.(Notice:in sub thread) 40 | * 41 | * @param bitmap the blurred bitmap 42 | * */ 43 | void onBlurComplete(@NonNull Bitmap bitmap); 44 | } 45 | 46 | private static ExecutorService sExecutorService = Executors.newCachedThreadPool(new ThreadFactory() { 47 | @Override 48 | public Thread newThread(Runnable r) { 49 | return new Thread(r,"wx_blur_thread"); 50 | } 51 | }); 52 | 53 | private static final String TAG = "BlurTool"; 54 | 55 | /** 56 | * radius in [0,10] 57 | * */ 58 | @NonNull 59 | @SuppressWarnings("unused") 60 | public static Bitmap blur(@NonNull Bitmap originalImage, int radius) { 61 | long start = System.currentTimeMillis(); 62 | radius = Math.min(10, Math.max(0,radius));//[0,10] 63 | if(radius == 0) { 64 | return originalImage; 65 | } 66 | int width = originalImage.getWidth(); 67 | int height = originalImage.getHeight(); 68 | 69 | if(width <= 0 || height <= 0) { 70 | return originalImage; 71 | } 72 | 73 | double sampling = calculateSampling(radius); 74 | int retryTimes = 3; 75 | Bitmap sampledImage = Bitmap.createScaledBitmap(originalImage,(int)(sampling*width),(int)(sampling*height),true); 76 | for(int i = 0; i < retryTimes; i++) { 77 | try { 78 | if(radius == 0) { 79 | return originalImage; 80 | } 81 | double s = calculateSampling(radius); 82 | if(s != sampling) { 83 | sampling = s; 84 | sampledImage = Bitmap.createScaledBitmap(originalImage,(int)(sampling*width),(int)(sampling*height),true); 85 | } 86 | 87 | Bitmap result = stackBlur(sampledImage,radius); 88 | WXLogUtils.d(TAG, "elapsed time on blurring image(radius:"+ radius + ",sampling: " + sampling + "): " + (System.currentTimeMillis() - start) + "ms"); 89 | return result; 90 | }catch (Exception e) { 91 | WXLogUtils.e(TAG, "thrown exception when blurred image(times = " + i + "),"+ e.getMessage()); 92 | radius -= 1; 93 | radius = Math.max(0,radius); 94 | } 95 | } 96 | WXLogUtils.d(TAG, "elapsed time on blurring image(radius:"+ radius + ",sampling: " + sampling + "): " + (System.currentTimeMillis() - start) + "ms"); 97 | return originalImage; 98 | } 99 | 100 | private static double calculateSampling(int radius){ 101 | double sampling; 102 | if(radius <= 3) { 103 | sampling = 1/(double)2; 104 | }else if(radius <= 8) { 105 | sampling = 1/(double)4; 106 | }else { 107 | sampling = 1/(double)8; 108 | } 109 | 110 | return sampling; 111 | } 112 | 113 | @SuppressWarnings("unused") 114 | public static void asyncBlur(@NonNull final Bitmap originalImage, final int radius, @Nullable final OnBlurCompleteListener listener) { 115 | sExecutorService.execute(new Runnable() { 116 | @Override 117 | public void run() { 118 | if(listener != null) { 119 | listener.onBlurComplete(blur(originalImage,radius)); 120 | } 121 | } 122 | }); 123 | } 124 | 125 | private static Bitmap stackBlur(Bitmap sentBitmap, int radius) { 126 | // Stack Blur Algorithm by Mario Klingemann 127 | Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true); 128 | 129 | if (radius < 1) { 130 | return (null); 131 | } 132 | 133 | int w = bitmap.getWidth(); 134 | int h = bitmap.getHeight(); 135 | 136 | int[] pix = new int[w * h]; 137 | bitmap.getPixels(pix, 0, w, 0, 0, w, h); 138 | 139 | int wm = w - 1; 140 | int hm = h - 1; 141 | int wh = w * h; 142 | int div = radius + radius + 1; 143 | 144 | int r[] = new int[wh]; 145 | int g[] = new int[wh]; 146 | int b[] = new int[wh]; 147 | int rsum, gsum, bsum, x, y, i, p, yp, yi, yw; 148 | int vmin[] = new int[Math.max(w, h)]; 149 | 150 | int divsum = (div + 1) >> 1; 151 | divsum *= divsum; 152 | int dv[] = new int[256 * divsum]; 153 | for (i = 0; i < 256 * divsum; i++) { 154 | dv[i] = (i / divsum); 155 | } 156 | 157 | yw = yi = 0; 158 | 159 | int[][] stack = new int[div][3]; 160 | int stackpointer; 161 | int stackstart; 162 | int[] sir; 163 | int rbs; 164 | int r1 = radius + 1; 165 | int routsum, goutsum, boutsum; 166 | int rinsum, ginsum, binsum; 167 | 168 | for (y = 0; y < h; y++) { 169 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 170 | for (i = -radius; i <= radius; i++) { 171 | p = pix[yi + Math.min(wm, Math.max(i, 0))]; 172 | sir = stack[i + radius]; 173 | sir[0] = (p & 0xff0000) >> 16; 174 | sir[1] = (p & 0x00ff00) >> 8; 175 | sir[2] = (p & 0x0000ff); 176 | rbs = r1 - Math.abs(i); 177 | rsum += sir[0] * rbs; 178 | gsum += sir[1] * rbs; 179 | bsum += sir[2] * rbs; 180 | if (i > 0) { 181 | rinsum += sir[0]; 182 | ginsum += sir[1]; 183 | binsum += sir[2]; 184 | } else { 185 | routsum += sir[0]; 186 | goutsum += sir[1]; 187 | boutsum += sir[2]; 188 | } 189 | } 190 | stackpointer = radius; 191 | 192 | for (x = 0; x < w; x++) { 193 | 194 | r[yi] = dv[rsum]; 195 | g[yi] = dv[gsum]; 196 | b[yi] = dv[bsum]; 197 | 198 | rsum -= routsum; 199 | gsum -= goutsum; 200 | bsum -= boutsum; 201 | 202 | stackstart = stackpointer - radius + div; 203 | sir = stack[stackstart % div]; 204 | 205 | routsum -= sir[0]; 206 | goutsum -= sir[1]; 207 | boutsum -= sir[2]; 208 | 209 | if (y == 0) { 210 | vmin[x] = Math.min(x + radius + 1, wm); 211 | } 212 | p = pix[yw + vmin[x]]; 213 | 214 | sir[0] = (p & 0xff0000) >> 16; 215 | sir[1] = (p & 0x00ff00) >> 8; 216 | sir[2] = (p & 0x0000ff); 217 | 218 | rinsum += sir[0]; 219 | ginsum += sir[1]; 220 | binsum += sir[2]; 221 | 222 | rsum += rinsum; 223 | gsum += ginsum; 224 | bsum += binsum; 225 | 226 | stackpointer = (stackpointer + 1) % div; 227 | sir = stack[(stackpointer) % div]; 228 | 229 | routsum += sir[0]; 230 | goutsum += sir[1]; 231 | boutsum += sir[2]; 232 | 233 | rinsum -= sir[0]; 234 | ginsum -= sir[1]; 235 | binsum -= sir[2]; 236 | 237 | yi++; 238 | } 239 | yw += w; 240 | } 241 | for (x = 0; x < w; x++) { 242 | rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0; 243 | yp = -radius * w; 244 | for (i = -radius; i <= radius; i++) { 245 | yi = Math.max(0, yp) + x; 246 | 247 | sir = stack[i + radius]; 248 | 249 | sir[0] = r[yi]; 250 | sir[1] = g[yi]; 251 | sir[2] = b[yi]; 252 | 253 | rbs = r1 - Math.abs(i); 254 | 255 | rsum += r[yi] * rbs; 256 | gsum += g[yi] * rbs; 257 | bsum += b[yi] * rbs; 258 | 259 | if (i > 0) { 260 | rinsum += sir[0]; 261 | ginsum += sir[1]; 262 | binsum += sir[2]; 263 | } else { 264 | routsum += sir[0]; 265 | goutsum += sir[1]; 266 | boutsum += sir[2]; 267 | } 268 | 269 | if (i < hm) { 270 | yp += w; 271 | } 272 | } 273 | yi = x; 274 | stackpointer = radius; 275 | for (y = 0; y < h; y++) { 276 | // Preserve alpha channel: ( 0xff000000 & pix[yi] ) 277 | pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16) | (dv[gsum] << 8) | dv[bsum]; 278 | 279 | rsum -= routsum; 280 | gsum -= goutsum; 281 | bsum -= boutsum; 282 | 283 | stackstart = stackpointer - radius + div; 284 | sir = stack[stackstart % div]; 285 | 286 | routsum -= sir[0]; 287 | goutsum -= sir[1]; 288 | boutsum -= sir[2]; 289 | 290 | if (x == 0) { 291 | vmin[y] = Math.min(y + r1, hm) * w; 292 | } 293 | p = x + vmin[y]; 294 | 295 | sir[0] = r[p]; 296 | sir[1] = g[p]; 297 | sir[2] = b[p]; 298 | 299 | rinsum += sir[0]; 300 | ginsum += sir[1]; 301 | binsum += sir[2]; 302 | 303 | rsum += rinsum; 304 | gsum += ginsum; 305 | bsum += binsum; 306 | 307 | stackpointer = (stackpointer + 1) % div; 308 | sir = stack[stackpointer]; 309 | 310 | routsum += sir[0]; 311 | goutsum += sir[1]; 312 | boutsum += sir[2]; 313 | 314 | rinsum -= sir[0]; 315 | ginsum -= sir[1]; 316 | binsum -= sir[2]; 317 | 318 | yi += w; 319 | } 320 | } 321 | 322 | bitmap.setPixels(pix, 0, w, 0, 0, w, h); 323 | 324 | return (bitmap); 325 | } 326 | } 327 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Alibaba Group 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /bin/templates/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Alibaba Group 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /bin/lib/create.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | 22 | var shell = require('shelljs'), 23 | Q = require('q'), 24 | path = require('path'), 25 | fs = require('fs'), 26 | check_reqs = require('./check_reqs'), 27 | ROOT = path.join(__dirname, '..', '..'); 28 | 29 | var MIN_SDK_VERSION = 16; 30 | 31 | var CordovaError = require('cordova-common').CordovaError; 32 | var AndroidManifest = require('../templates/cordova/lib/AndroidManifest'); 33 | 34 | function setShellFatal(value, func) { 35 | var oldVal = shell.config.fatal; 36 | shell.config.fatal = value; 37 | func(); 38 | shell.config.fatal = oldVal; 39 | } 40 | 41 | function getFrameworkDir(projectPath, shared) { 42 | return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib'); 43 | } 44 | 45 | function copyJsAndLibrary(projectPath, shared, projectName) { 46 | var nestedCordovaLibPath = getFrameworkDir(projectPath, false); 47 | var srcCordovaJsPath = path.join(ROOT, 'bin', 'templates', 'project', 'assets', 'www', 'cordova.js'); 48 | shell.cp('-f', srcCordovaJsPath, path.join(projectPath, 'assets', 'www', 'cordova.js')); 49 | 50 | // Copy the cordova.js file to platforms//platform_www/ 51 | // The www dir is nuked on each prepare so we keep cordova.js in platform_www 52 | shell.mkdir('-p', path.join(projectPath, 'platform_www')); 53 | shell.cp('-f', srcCordovaJsPath, path.join(projectPath, 'platform_www')); 54 | 55 | // Copy cordova-js-src directory into platform_www directory. 56 | // We need these files to build cordova.js if using browserify method. 57 | shell.cp('-rf', path.join(ROOT, 'cordova-js-src'), path.join(projectPath, 'platform_www')); 58 | 59 | // Don't fail if there are no old jars. 60 | setShellFatal(false, function() { 61 | shell.ls(path.join(projectPath, 'libs', 'cordova-*.jar')).forEach(function(oldJar) { 62 | console.log('Deleting ' + oldJar); 63 | shell.rm('-f', oldJar); 64 | }); 65 | var wasSymlink = true; 66 | try { 67 | // Delete the symlink if it was one. 68 | fs.unlinkSync(nestedCordovaLibPath); 69 | } catch (e) { 70 | wasSymlink = false; 71 | } 72 | // Delete old library project if it existed. 73 | if (shared) { 74 | shell.rm('-rf', nestedCordovaLibPath); 75 | } else if (!wasSymlink) { 76 | // Delete only the src, since Eclipse / Android Studio can't handle their project files being deleted. 77 | shell.rm('-rf', path.join(nestedCordovaLibPath, 'src')); 78 | } 79 | }); 80 | if (shared) { 81 | var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath, true)); 82 | fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir'); 83 | } else { 84 | shell.mkdir('-p', nestedCordovaLibPath); 85 | shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath); 86 | shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath); 87 | shell.cp('-f', path.join(ROOT, 'framework', 'build.gradle'), nestedCordovaLibPath); 88 | shell.cp('-f', path.join(ROOT, 'framework', 'cordova.gradle'), nestedCordovaLibPath); 89 | shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath); 90 | } 91 | } 92 | 93 | function extractSubProjectPaths(data) { 94 | var ret = {}; 95 | var r = /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg; 96 | var m; 97 | while ((m = r.exec(data))) { 98 | ret[m[1]] = 1; 99 | } 100 | return Object.keys(ret); 101 | } 102 | 103 | function writeProjectProperties(projectPath, target_api) { 104 | var dstPath = path.join(projectPath, 'project.properties'); 105 | var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties'); 106 | var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath; 107 | 108 | var data = fs.readFileSync(srcPath, 'utf8'); 109 | data = data.replace(/^target=.*/m, 'target=' + target_api); 110 | var subProjects = extractSubProjectPaths(data); 111 | subProjects = subProjects.filter(function(p) { 112 | return !(/^CordovaLib$/m.exec(p) || 113 | /[\\\/]cordova-android[\\\/]framework$/m.exec(p) || 114 | /^(\.\.[\\\/])+framework$/m.exec(p) 115 | ); 116 | }); 117 | subProjects.unshift('CordovaLib'); 118 | data = data.replace(/^\s*android\.library\.reference\.\d+=.*\n/mg, ''); 119 | if (!/\n$/.exec(data)) { 120 | data += '\n'; 121 | } 122 | for (var i = 0; i < subProjects.length; ++i) { 123 | data += 'android.library.reference.' + (i+1) + '=' + subProjects[i] + '\n'; 124 | } 125 | fs.writeFileSync(dstPath, data); 126 | } 127 | 128 | function prepBuildFiles(projectPath) { 129 | var buildModule = require(path.resolve(projectPath, 'cordova/lib/builders/builders')); 130 | buildModule.getBuilder('gradle').prepBuildFiles(); 131 | } 132 | 133 | function copyBuildRules(projectPath) { 134 | var srcDir = path.join(ROOT, 'bin', 'templates', 'project'); 135 | 136 | shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath); 137 | } 138 | 139 | function copyScripts(projectPath) { 140 | var srcScriptsDir = path.join(ROOT, 'bin', 'templates', 'cordova'); 141 | var destScriptsDir = path.join(projectPath, 'cordova'); 142 | // Delete old scripts directory if this is an update. 143 | shell.rm('-rf', destScriptsDir); 144 | // Copy in the new ones. 145 | shell.cp('-r', srcScriptsDir, projectPath); 146 | shell.cp('-r', path.join(ROOT, 'node_modules'), destScriptsDir); 147 | shell.cp(path.join(ROOT, 'bin', 'check_reqs*'), destScriptsDir); 148 | shell.cp(path.join(ROOT, 'bin', 'lib', 'check_reqs.js'), path.join(projectPath, 'cordova', 'lib', 'check_reqs.js')); 149 | shell.cp(path.join(ROOT, 'bin', 'android_sdk_version'), path.join(destScriptsDir, 'android_sdk_version')); 150 | shell.cp(path.join(ROOT, 'bin', 'lib', 'android_sdk_version.js'), path.join(projectPath, 'cordova', 'lib', 'android_sdk_version.js')); 151 | } 152 | 153 | /** 154 | * Test whether a package name is acceptable for use as an android project. 155 | * Returns a promise, fulfilled if the package name is acceptable; rejected 156 | * otherwise. 157 | */ 158 | function validatePackageName(package_name) { 159 | //Make the package conform to Java package types 160 | //http://developer.android.com/guide/topics/manifest/manifest-element.html#package 161 | //Enforce underscore limitation 162 | var msg = 'Error validating package name. '; 163 | if (!/^[a-zA-Z][a-zA-Z0-9_]+(\.[a-zA-Z][a-zA-Z0-9_]*)+$/.test(package_name)) { 164 | return Q.reject(new CordovaError(msg + 'Package name must look like: com.company.Name')); 165 | } 166 | 167 | //Class is a reserved word 168 | if(/\b[Cc]lass\b/.test(package_name)) { 169 | return Q.reject(new CordovaError(msg + '"class" is a reserved word')); 170 | } 171 | 172 | return Q.resolve(); 173 | } 174 | 175 | /** 176 | * Test whether a project name is acceptable for use as an android class. 177 | * Returns a promise, fulfilled if the project name is acceptable; rejected 178 | * otherwise. 179 | */ 180 | function validateProjectName(project_name) { 181 | var msg = 'Error validating project name. '; 182 | //Make sure there's something there 183 | if (project_name === '') { 184 | return Q.reject(new CordovaError(msg + 'Project name cannot be empty')); 185 | } 186 | 187 | //Enforce stupid name error 188 | if (project_name === 'CordovaActivity') { 189 | return Q.reject(new CordovaError(msg + 'Project name cannot be CordovaActivity')); 190 | } 191 | 192 | //Classes in Java don't begin with numbers 193 | if (/^[0-9]/.test(project_name)) { 194 | return Q.reject(new CordovaError(msg + 'Project name must not begin with a number')); 195 | } 196 | 197 | return Q.resolve(); 198 | } 199 | 200 | /** 201 | * Creates an android application with the given options. 202 | * 203 | * @param {String} project_path Path to the new Cordova android project. 204 | * @param {ConfigParser} config Instance of ConfigParser to retrieve basic 205 | * project properties. 206 | * @param {Object} [options={}] Various options 207 | * @param {String} [options.activityName='MainActivity'] Name for the 208 | * activity 209 | * @param {Boolean} [options.link=false] Specifies whether javascript files 210 | * and CordovaLib framework will be symlinked to created application. 211 | * @param {String} [options.customTemplate] Path to project template 212 | * (override) 213 | * @param {EventEmitter} [events] An EventEmitter instance for logging 214 | * events 215 | * 216 | * @return {Promise} Directory where application has been created 217 | */ 218 | exports.create = function(project_path, config, options, events) { 219 | 220 | options = options || {}; 221 | 222 | // Set default values for path, package and name 223 | project_path = path.relative(process.cwd(), (project_path || 'CordovaExample')); 224 | // Check if project already exists 225 | if(fs.existsSync(project_path)) { 226 | return Q.reject(new CordovaError('Project already exists! Delete and recreate')); 227 | } 228 | 229 | var package_name = config.packageName() || 'my.cordova.project'; 230 | var project_name = config.name() ? 231 | config.name().replace(/[^\w.]/g,'_') : 'CordovaExample'; 232 | 233 | var safe_activity_name = config.android_activityName() || options.activityName || 'MainActivity'; 234 | var target_api = check_reqs.get_target(); 235 | 236 | //Make the package conform to Java package types 237 | return validatePackageName(package_name) 238 | .then(function() { 239 | validateProjectName(project_name); 240 | }).then(function() { 241 | // Log the given values for the project 242 | events.emit('log', 'Creating Cordova project for the Android platform:'); 243 | events.emit('log', '\tPath: ' + project_path); 244 | events.emit('log', '\tPackage: ' + package_name); 245 | events.emit('log', '\tName: ' + project_name); 246 | events.emit('log', '\tActivity: ' + safe_activity_name); 247 | events.emit('log', '\tAndroid target: ' + target_api); 248 | 249 | events.emit('verbose', 'Copying android template project to ' + project_path); 250 | 251 | setShellFatal(true, function() { 252 | var project_template_dir = options.customTemplate || path.join(ROOT, 'bin', 'templates', 'project'); 253 | // copy project template 254 | shell.cp('-r', path.join(project_template_dir, 'assets'), project_path); 255 | shell.cp('-r', path.join(project_template_dir, 'res'), project_path); 256 | shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore')); 257 | 258 | // Manually create directories that would be empty within the template (since git doesn't track directories). 259 | shell.mkdir(path.join(project_path, 'libs')); 260 | 261 | // copy cordova.js, cordova.jar 262 | copyJsAndLibrary(project_path, options.link, safe_activity_name); 263 | 264 | // interpolate the activity name and package 265 | var packagePath = package_name.replace(/\./g, path.sep); 266 | var activity_dir = path.join(project_path, 'src', packagePath); 267 | var activity_path = path.join(activity_dir, safe_activity_name + '.java'); 268 | shell.mkdir('-p', activity_dir); 269 | shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path); 270 | shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path); 271 | shell.sed('-i', /__NAME__/, project_name, path.join(project_path, 'res', 'values', 'strings.xml')); 272 | shell.sed('-i', /__ID__/, package_name, activity_path); 273 | 274 | var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml')); 275 | manifest.setPackageId(package_name) 276 | .setTargetSdkVersion(target_api.split('-')[1]) 277 | .getActivity().setName(safe_activity_name); 278 | 279 | var manifest_path = path.join(project_path, 'AndroidManifest.xml'); 280 | manifest.write(manifest_path); 281 | 282 | copyScripts(project_path); 283 | copyBuildRules(project_path); 284 | }); 285 | // Link it to local android install. 286 | writeProjectProperties(project_path, target_api); 287 | prepBuildFiles(project_path); 288 | events.emit('log', generateDoneMessage('create', options.link)); 289 | }).thenResolve(project_path); 290 | }; 291 | 292 | function generateDoneMessage(type, link) { 293 | var pkg = require('../../package'); 294 | var msg = 'Android project ' + (type == 'update' ? 'updated ' : 'created ') + 'with ' + pkg.name + '@' + pkg.version; 295 | if (link) { 296 | msg += ' and has a linked CordovaLib'; 297 | } 298 | return msg; 299 | } 300 | 301 | // Returns a promise. 302 | exports.update = function(projectPath, options, events) { 303 | options = options || {}; 304 | 305 | return Q() 306 | .then(function() { 307 | 308 | var manifest = new AndroidManifest(path.join(projectPath, 'AndroidManifest.xml')); 309 | 310 | if (Number(manifest.getMinSdkVersion()) < MIN_SDK_VERSION) { 311 | events.emit('verbose', 'Updating minSdkVersion to ' + MIN_SDK_VERSION + ' in AndroidManifest.xml'); 312 | manifest.setMinSdkVersion(MIN_SDK_VERSION); 313 | } 314 | 315 | manifest.setDebuggable(false).write(); 316 | 317 | var projectName = manifest.getActivity().getName(); 318 | var target_api = check_reqs.get_target(); 319 | 320 | copyJsAndLibrary(projectPath, options.link, projectName); 321 | copyScripts(projectPath); 322 | copyBuildRules(projectPath); 323 | writeProjectProperties(projectPath, target_api); 324 | prepBuildFiles(projectPath); 325 | events.emit('log', generateDoneMessage('update', options.link)); 326 | }).thenResolve(projectPath); 327 | }; 328 | 329 | 330 | // For testing 331 | exports.validatePackageName = validatePackageName; 332 | exports.validateProjectName = validateProjectName; 333 | -------------------------------------------------------------------------------- /bin/lib/check_reqs.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /* 4 | Licensed to the Apache Software Foundation (ASF) under one 5 | or more contributor license agreements. See the NOTICE file 6 | distributed with this work for additional information 7 | regarding copyright ownership. The ASF licenses this file 8 | to you under the Apache License, Version 2.0 (the 9 | "License"); you may not use this file except in compliance 10 | with the License. You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, 15 | software distributed under the License is distributed on an 16 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | KIND, either express or implied. See the License for the 18 | specific language governing permissions and limitations 19 | under the License. 20 | */ 21 | 22 | /* jshint sub:true */ 23 | 24 | var shelljs = require('shelljs'), 25 | child_process = require('child_process'), 26 | Q = require('q'), 27 | path = require('path'), 28 | fs = require('fs'), 29 | ROOT = path.join(__dirname, '..', '..'); 30 | var CordovaError = require('cordova-common').CordovaError; 31 | 32 | var isWindows = process.platform == 'win32'; 33 | 34 | function forgivingWhichSync(cmd) { 35 | try { 36 | return fs.realpathSync(shelljs.which(cmd)); 37 | } catch (e) { 38 | return ''; 39 | } 40 | } 41 | 42 | function tryCommand(cmd, errMsg, catchStderr) { 43 | var d = Q.defer(); 44 | child_process.exec(cmd, function(err, stdout, stderr) { 45 | if (err) d.reject(new CordovaError(errMsg)); 46 | // Sometimes it is necessary to return an stderr instead of stdout in case of success, since 47 | // some commands prints theirs output to stderr instead of stdout. 'javac' is the example 48 | else d.resolve((catchStderr ? stderr : stdout).trim()); 49 | }); 50 | return d.promise; 51 | } 52 | 53 | // Get valid target from framework/project.properties 54 | module.exports.get_target = function() { 55 | function extractFromFile(filePath) { 56 | var target = shelljs.grep(/\btarget=/, filePath); 57 | if (!target) { 58 | throw new Error('Could not find android target within: ' + filePath); 59 | } 60 | return target.split('=')[1].trim(); 61 | } 62 | if (fs.existsSync(path.join(ROOT, 'framework', 'project.properties'))) { 63 | return extractFromFile(path.join(ROOT, 'framework', 'project.properties')); 64 | } 65 | if (fs.existsSync(path.join(ROOT, 'project.properties'))) { 66 | // if no target found, we're probably in a project and project.properties is in ROOT. 67 | return extractFromFile(path.join(ROOT, 'project.properties')); 68 | } 69 | throw new Error('Could not find android target. File missing: ' + path.join(ROOT, 'project.properties')); 70 | }; 71 | 72 | // Returns a promise. Called only by build and clean commands. 73 | module.exports.check_ant = function() { 74 | return tryCommand('ant -version', 'Failed to run "ant -version", make sure you have ant installed and added to your PATH.') 75 | .then(function (output) { 76 | // Parse Ant version from command output 77 | return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1]; 78 | }); 79 | }; 80 | 81 | // Returns a promise. Called only by build and clean commands. 82 | module.exports.check_gradle = function() { 83 | var sdkDir = process.env['ANDROID_HOME']; 84 | if (!sdkDir) 85 | return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.\n' + 86 | 'Might need to install Android SDK or set up \'ANDROID_HOME\' env variable.')); 87 | 88 | var wrapperDir = path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper'); 89 | if (!fs.existsSync(wrapperDir)) { 90 | return Q.reject(new CordovaError('Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.\n' + 91 | 'Looked here: ' + wrapperDir)); 92 | } 93 | return Q.when(); 94 | }; 95 | 96 | // Returns a promise. 97 | module.exports.check_java = function() { 98 | var javacPath = forgivingWhichSync('javac'); 99 | var hasJavaHome = !!process.env['JAVA_HOME']; 100 | return Q().then(function() { 101 | if (hasJavaHome) { 102 | // Windows java installer doesn't add javac to PATH, nor set JAVA_HOME (ugh). 103 | if (!javacPath) { 104 | process.env['PATH'] += path.delimiter + path.join(process.env['JAVA_HOME'], 'bin'); 105 | } 106 | } else { 107 | if (javacPath) { 108 | var msg = 'Failed to find \'JAVA_HOME\' environment variable. Try setting setting it manually.'; 109 | // OS X has a command for finding JAVA_HOME. 110 | if (fs.existsSync('/usr/libexec/java_home')) { 111 | return tryCommand('/usr/libexec/java_home', msg) 112 | .then(function(stdout) { 113 | process.env['JAVA_HOME'] = stdout.trim(); 114 | }); 115 | } else { 116 | // See if we can derive it from javac's location. 117 | // fs.realpathSync is require on Ubuntu, which symplinks from /usr/bin -> JDK 118 | var maybeJavaHome = path.dirname(path.dirname(javacPath)); 119 | if (fs.existsSync(path.join(maybeJavaHome, 'lib', 'tools.jar'))) { 120 | process.env['JAVA_HOME'] = maybeJavaHome; 121 | } else { 122 | throw new CordovaError(msg); 123 | } 124 | } 125 | } else if (isWindows) { 126 | // Try to auto-detect java in the default install paths. 127 | var oldSilent = shelljs.config.silent; 128 | shelljs.config.silent = true; 129 | var firstJdkDir = 130 | shelljs.ls(process.env['ProgramFiles'] + '\\java\\jdk*')[0] || 131 | shelljs.ls('C:\\Program Files\\java\\jdk*')[0] || 132 | shelljs.ls('C:\\Program Files (x86)\\java\\jdk*')[0]; 133 | shelljs.config.silent = oldSilent; 134 | if (firstJdkDir) { 135 | // shelljs always uses / in paths. 136 | firstJdkDir = firstJdkDir.replace(/\//g, path.sep); 137 | if (!javacPath) { 138 | process.env['PATH'] += path.delimiter + path.join(firstJdkDir, 'bin'); 139 | } 140 | process.env['JAVA_HOME'] = firstJdkDir; 141 | } 142 | } 143 | } 144 | }).then(function() { 145 | var msg = 146 | 'Failed to run "javac -version", make sure that you have a JDK installed.\n' + 147 | 'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n'; 148 | if (process.env['JAVA_HOME']) { 149 | msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n'; 150 | } 151 | // We use tryCommand with catchStderr = true, because 152 | // javac writes version info to stderr instead of stdout 153 | return tryCommand('javac -version', msg, true) 154 | .then(function (output) { 155 | //Let's check for at least Java 8, and keep it future proof so we can support Java 10 156 | var match = /javac ((?:1\.)(?:[8-9]\.)(?:\d+))|((?:1\.)(?:[1-9]\d+\.)(?:\d+))/i.exec(output); 157 | return match && match[1]; 158 | }); 159 | }); 160 | }; 161 | 162 | // Returns a promise. 163 | module.exports.check_android = function() { 164 | return Q().then(function() { 165 | var androidCmdPath = forgivingWhichSync('android'); 166 | var adbInPath = !!forgivingWhichSync('adb'); 167 | var hasAndroidHome = !!process.env['ANDROID_HOME'] && fs.existsSync(process.env['ANDROID_HOME']); 168 | function maybeSetAndroidHome(value) { 169 | if (!hasAndroidHome && fs.existsSync(value)) { 170 | hasAndroidHome = true; 171 | process.env['ANDROID_HOME'] = value; 172 | } 173 | } 174 | if (!hasAndroidHome && !androidCmdPath) { 175 | if (isWindows) { 176 | // Android Studio 1.0 installer 177 | maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'sdk')); 178 | maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'sdk')); 179 | // Android Studio pre-1.0 installer 180 | maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-studio', 'sdk')); 181 | maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-studio', 'sdk')); 182 | // Stand-alone installer 183 | maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-sdk')); 184 | maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-sdk')); 185 | } else if (process.platform == 'darwin') { 186 | // Android Studio 1.0 installer 187 | maybeSetAndroidHome(path.join(process.env['HOME'], 'Library', 'Android', 'sdk')); 188 | // Android Studio pre-1.0 installer 189 | maybeSetAndroidHome('/Applications/Android Studio.app/sdk'); 190 | // Stand-alone zip file that user might think to put under /Applications 191 | maybeSetAndroidHome('/Applications/android-sdk-macosx'); 192 | maybeSetAndroidHome('/Applications/android-sdk'); 193 | } 194 | if (process.env['HOME']) { 195 | // Stand-alone zip file that user might think to put under their home directory 196 | maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk-macosx')); 197 | maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk')); 198 | } 199 | } 200 | if (hasAndroidHome && !androidCmdPath) { 201 | process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'tools'); 202 | } 203 | if (androidCmdPath && !hasAndroidHome) { 204 | var parentDir = path.dirname(androidCmdPath); 205 | var grandParentDir = path.dirname(parentDir); 206 | if (path.basename(parentDir) == 'tools') { 207 | process.env['ANDROID_HOME'] = path.dirname(parentDir); 208 | hasAndroidHome = true; 209 | } else if (fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) { 210 | process.env['ANDROID_HOME'] = grandParentDir; 211 | hasAndroidHome = true; 212 | } else { 213 | throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' + 214 | 'Detected \'android\' command at ' + parentDir + ' but no \'tools\' directory found near.\n' + 215 | 'Try reinstall Android SDK or update your PATH to include path to valid SDK directory.'); 216 | } 217 | } 218 | if (hasAndroidHome && !adbInPath) { 219 | process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'], 'platform-tools'); 220 | } 221 | if (!process.env['ANDROID_HOME']) { 222 | throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable. Try setting setting it manually.\n' + 223 | 'Failed to find \'android\' command in your \'PATH\'. Try update your \'PATH\' to include path to valid SDK directory.'); 224 | } 225 | if (!fs.existsSync(process.env['ANDROID_HOME'])) { 226 | throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent path: ' + process.env['ANDROID_HOME'] + 227 | '\nTry update it manually to point to valid SDK directory.'); 228 | } 229 | return hasAndroidHome; 230 | }); 231 | }; 232 | 233 | module.exports.getAbsoluteAndroidCmd = function () { 234 | var cmd = forgivingWhichSync('android'); 235 | if (process.platform === 'win32') { 236 | return '"' + cmd + '"'; 237 | } 238 | return cmd.replace(/(\s)/g, '\\$1'); 239 | }; 240 | 241 | module.exports.check_android_target = function(originalError) { 242 | // valid_target can look like: 243 | // android-19 244 | // android-L 245 | // Google Inc.:Google APIs:20 246 | // Google Inc.:Glass Development Kit Preview:20 247 | var valid_target = module.exports.get_target(); 248 | var msg = 'Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.'; 249 | return tryCommand('android list targets --compact', msg) 250 | .then(function(output) { 251 | var targets = output.split('\n'); 252 | if (targets.indexOf(valid_target) >= 0) { 253 | return targets; 254 | } 255 | 256 | var androidCmd = module.exports.getAbsoluteAndroidCmd(); 257 | var msg = 'Please install Android target: "' + valid_target + '".\n\n' + 258 | 'Hint: Open the SDK manager by running: ' + androidCmd + '\n' + 259 | 'You will require:\n' + 260 | '1. "SDK Platform" for ' + valid_target + '\n' + 261 | '2. "Android SDK Platform-tools (latest)\n' + 262 | '3. "Android SDK Build-tools" (latest)'; 263 | if (originalError) { 264 | msg = originalError + '\n' + msg; 265 | } 266 | throw new CordovaError(msg); 267 | }); 268 | }; 269 | 270 | // Returns a promise. 271 | module.exports.run = function() { 272 | return Q.all([this.check_java(), this.check_android()]) 273 | .then(function(values) { 274 | console.log('ANDROID_HOME=' + process.env['ANDROID_HOME']); 275 | console.log('JAVA_HOME=' + process.env['JAVA_HOME']); 276 | 277 | if (!values[0]) { 278 | throw new CordovaError('Requirements check failed for JDK 1.8 or greater'); 279 | } 280 | 281 | 282 | if (!values[1]) { 283 | throw new CordovaError('Requirements check failed for Android SDK'); 284 | } 285 | }); 286 | }; 287 | 288 | 289 | /** 290 | * Object thar represents one of requirements for current platform. 291 | * @param {String} id The unique identifier for this requirements. 292 | * @param {String} name The name of requirements. Human-readable field. 293 | * @param {String} version The version of requirement installed. In some cases could be an array of strings 294 | * (for example, check_android_target returns an array of android targets installed) 295 | * @param {Boolean} installed Indicates whether the requirement is installed or not 296 | */ 297 | var Requirement = function (id, name, version, installed) { 298 | this.id = id; 299 | this.name = name; 300 | this.installed = installed || false; 301 | this.metadata = { 302 | version: version, 303 | }; 304 | }; 305 | 306 | /** 307 | * Methods that runs all checks one by one and returns a result of checks 308 | * as an array of Requirement objects. This method intended to be used by cordova-lib check_reqs method 309 | * 310 | * @return Promise Array of requirements. Due to implementation, promise is always fulfilled. 311 | */ 312 | module.exports.check_all = function() { 313 | 314 | var requirements = [ 315 | new Requirement('java', 'Java JDK'), 316 | new Requirement('androidSdk', 'Android SDK'), 317 | new Requirement('androidTarget', 'Android target'), 318 | new Requirement('gradle', 'Gradle') 319 | ]; 320 | 321 | var checkFns = [ 322 | this.check_java, 323 | this.check_android, 324 | this.check_android_target, 325 | this.check_gradle 326 | ]; 327 | 328 | // Then execute requirement checks one-by-one 329 | return checkFns.reduce(function (promise, checkFn, idx) { 330 | // Update each requirement with results 331 | var requirement = requirements[idx]; 332 | return promise.then(checkFn) 333 | .then(function (version) { 334 | requirement.installed = true; 335 | requirement.metadata.version = version; 336 | }, function (err) { 337 | requirement.metadata.reason = err instanceof Error ? err.message : err; 338 | }); 339 | }, Q()) 340 | .then(function () { 341 | // When chain is completed, return requirements array to upstream API 342 | return requirements; 343 | }); 344 | }; 345 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/util/CommonUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Apache License 4 | * Version 2.0, January 2004 5 | * http://www.apache.org/licenses/ 6 | * 7 | * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 8 | * 9 | * 1. Definitions. 10 | * 11 | * "License" shall mean the terms and conditions for use, reproduction, 12 | * and distribution as defined by Sections 1 through 9 of this document. 13 | * 14 | * "Licensor" shall mean the copyright owner or entity authorized by 15 | * the copyright owner that is granting the License. 16 | * 17 | * "Legal Entity" shall mean the union of the acting entity and all 18 | * other entities that control, are controlled by, or are under common 19 | * control with that entity. For the purposes of this definition, 20 | * "control" means (i) the power, direct or indirect, to cause the 21 | * direction or management of such entity, whether by contract or 22 | * otherwise, or (ii) ownership of fifty percent (50%) or more of the 23 | * outstanding shares, or (iii) beneficial ownership of such entity. 24 | * 25 | * "You" (or "Your") shall mean an individual or Legal Entity 26 | * exercising permissions granted by this License. 27 | * 28 | * "Source" form shall mean the preferred form for making modifications, 29 | * including but not limited to software source code, documentation 30 | * source, and configuration files. 31 | * 32 | * "Object" form shall mean any form resulting from mechanical 33 | * transformation or translation of a Source form, including but 34 | * not limited to compiled object code, generated documentation, 35 | * and conversions to other media types. 36 | * 37 | * "Work" shall mean the work of authorship, whether in Source or 38 | * Object form, made available under the License, as indicated by a 39 | * copyright notice that is included in or attached to the work 40 | * (an example is provided in the Appendix below). 41 | * 42 | * "Derivative Works" shall mean any work, whether in Source or Object 43 | * form, that is based on (or derived from) the Work and for which the 44 | * editorial revisions, annotations, elaborations, or other modifications 45 | * represent, as a whole, an original work of authorship. For the purposes 46 | * of this License, Derivative Works shall not include works that remain 47 | * separable from, or merely link (or bind by name) to the interfaces of, 48 | * the Work and Derivative Works thereof. 49 | * 50 | * "Contribution" shall mean any work of authorship, including 51 | * the original version of the Work and any modifications or additions 52 | * to that Work or Derivative Works thereof, that is intentionally 53 | * submitted to Licensor for inclusion in the Work by the copyright owner 54 | * or by an individual or Legal Entity authorized to submit on behalf of 55 | * the copyright owner. For the purposes of this definition, "submitted" 56 | * means any form of electronic, verbal, or written communication sent 57 | * to the Licensor or its representatives, including but not limited to 58 | * communication on electronic mailing lists, source code control systems, 59 | * and issue tracking systems that are managed by, or on behalf of, the 60 | * Licensor for the purpose of discussing and improving the Work, but 61 | * excluding communication that is conspicuously marked or otherwise 62 | * designated in writing by the copyright owner as "Not a Contribution." 63 | * 64 | * "Contributor" shall mean Licensor and any individual or Legal Entity 65 | * on behalf of whom a Contribution has been received by Licensor and 66 | * subsequently incorporated within the Work. 67 | * 68 | * 2. Grant of Copyright License. Subject to the terms and conditions of 69 | * this License, each Contributor hereby grants to You a perpetual, 70 | * worldwide, non-exclusive, no-charge, royalty-free, irrevocable 71 | * copyright license to reproduce, prepare Derivative Works of, 72 | * publicly display, publicly perform, sublicense, and distribute the 73 | * Work and such Derivative Works in Source or Object form. 74 | * 75 | * 3. Grant of Patent License. Subject to the terms and conditions of 76 | * this License, each Contributor hereby grants to You a perpetual, 77 | * worldwide, non-exclusive, no-charge, royalty-free, irrevocable 78 | * (except as stated in this section) patent license to make, have made, 79 | * use, offer to sell, sell, import, and otherwise transfer the Work, 80 | * where such license applies only to those patent claims licensable 81 | * by such Contributor that are necessarily infringed by their 82 | * Contribution(s) alone or by combination of their Contribution(s) 83 | * with the Work to which such Contribution(s) was submitted. If You 84 | * institute patent litigation against any entity (including a 85 | * cross-claim or counterclaim in a lawsuit) alleging that the Work 86 | * or a Contribution incorporated within the Work constitutes direct 87 | * or contributory patent infringement, then any patent licenses 88 | * granted to You under this License for that Work shall terminate 89 | * as of the date such litigation is filed. 90 | * 91 | * 4. Redistribution. You may reproduce and distribute copies of the 92 | * Work or Derivative Works thereof in any medium, with or without 93 | * modifications, and in Source or Object form, provided that You 94 | * meet the following conditions: 95 | * 96 | * (a) You must give any other recipients of the Work or 97 | * Derivative Works a copy of this License; and 98 | * 99 | * (b) You must cause any modified files to carry prominent notices 100 | * stating that You changed the files; and 101 | * 102 | * (c) You must retain, in the Source form of any Derivative Works 103 | * that You distribute, all copyright, patent, trademark, and 104 | * attribution notices from the Source form of the Work, 105 | * excluding those notices that do not pertain to any part of 106 | * the Derivative Works; and 107 | * 108 | * (d) If the Work includes a "NOTICE" text file as part of its 109 | * distribution, then any Derivative Works that You distribute must 110 | * include a readable copy of the attribution notices contained 111 | * within such NOTICE file, excluding those notices that do not 112 | * pertain to any part of the Derivative Works, in at least one 113 | * of the following places: within a NOTICE text file distributed 114 | * as part of the Derivative Works; within the Source form or 115 | * documentation, if provided along with the Derivative Works; or, 116 | * within a display generated by the Derivative Works, if and 117 | * wherever such third-party notices normally appear. The contents 118 | * of the NOTICE file are for informational purposes only and 119 | * do not modify the License. You may add Your own attribution 120 | * notices within Derivative Works that You distribute, alongside 121 | * or as an addendum to the NOTICE text from the Work, provided 122 | * that such additional attribution notices cannot be construed 123 | * as modifying the License. 124 | * 125 | * You may add Your own copyright statement to Your modifications and 126 | * may provide additional or different license terms and conditions 127 | * for use, reproduction, or distribution of Your modifications, or 128 | * for any such Derivative Works as a whole, provided Your use, 129 | * reproduction, and distribution of the Work otherwise complies with 130 | * the conditions stated in this License. 131 | * 132 | * 5. Submission of Contributions. Unless You explicitly state otherwise, 133 | * any Contribution intentionally submitted for inclusion in the Work 134 | * by You to the Licensor shall be under the terms and conditions of 135 | * this License, without any additional terms or conditions. 136 | * Notwithstanding the above, nothing herein shall supersede or modify 137 | * the terms of any separate license agreement you may have executed 138 | * with Licensor regarding such Contributions. 139 | * 140 | * 6. Trademarks. This License does not grant permission to use the trade 141 | * names, trademarks, service marks, or product names of the Licensor, 142 | * except as required for reasonable and customary use in describing the 143 | * origin of the Work and reproducing the content of the NOTICE file. 144 | * 145 | * 7. Disclaimer of Warranty. Unless required by applicable law or 146 | * agreed to in writing, Licensor provides the Work (and each 147 | * Contributor provides its Contributions) on an "AS IS" BASIS, 148 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 149 | * implied, including, without limitation, any warranties or conditions 150 | * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 151 | * PARTICULAR PURPOSE. You are solely responsible for determining the 152 | * appropriateness of using or redistributing the Work and assume any 153 | * risks associated with Your exercise of permissions under this License. 154 | * 155 | * 8. Limitation of Liability. In no event and under no legal theory, 156 | * whether in tort (including negligence), contract, or otherwise, 157 | * unless required by applicable law (such as deliberate and grossly 158 | * negligent acts) or agreed to in writing, shall any Contributor be 159 | * liable to You for damages, including any direct, indirect, special, 160 | * incidental, or consequential damages of any character arising as a 161 | * result of this License or out of the use or inability to use the 162 | * Work (including but not limited to damages for loss of goodwill, 163 | * work stoppage, computer failure or malfunction, or any and all 164 | * other commercial damages or losses), even if such Contributor 165 | * has been advised of the possibility of such damages. 166 | * 167 | * 9. Accepting Warranty or Additional Liability. While redistributing 168 | * the Work or Derivative Works thereof, You may choose to offer, 169 | * and charge a fee for, acceptance of support, warranty, indemnity, 170 | * or other liability obligations and/or rights consistent with this 171 | * License. However, in accepting such obligations, You may act only 172 | * on Your own behalf and on Your sole responsibility, not on behalf 173 | * of any other Contributor, and only if You agree to indemnify, 174 | * defend, and hold each Contributor harmless for any liability 175 | * incurred by, or claims asserted against, such Contributor by reason 176 | * of your accepting any such warranty or additional liability. 177 | * 178 | * END OF TERMS AND CONDITIONS 179 | * 180 | * APPENDIX: How to apply the Apache License to your work. 181 | * 182 | * To apply the Apache License to your work, attach the following 183 | * boilerplate notice, with the fields enclosed by brackets "[]" 184 | * replaced with your own identifying information. (Don't include 185 | * the brackets!) The text should be enclosed in the appropriate 186 | * comment syntax for the file format. We also recommend that a 187 | * file or class name and description of purpose be included on the 188 | * same "printed page" as the copyright notice for easier 189 | * identification within third-party archives. 190 | * 191 | * Copyright 2016 Alibaba Group 192 | * 193 | * Licensed under the Apache License, Version 2.0 (the "License"); 194 | * you may not use this file except in compliance with the License. 195 | * You may obtain a copy of the License at 196 | * 197 | * http://www.apache.org/licenses/LICENSE-2.0 198 | * 199 | * Unless required by applicable law or agreed to in writing, software 200 | * distributed under the License is distributed on an "AS IS" BASIS, 201 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 202 | * See the License for the specific language governing permissions and 203 | * limitations under the License. 204 | */ 205 | package com.weex.app.util; 206 | 207 | import android.app.ActionBar; 208 | import android.app.Activity; 209 | import android.content.res.TypedArray; 210 | import android.graphics.Point; 211 | import android.os.Build; 212 | import android.util.Log; 213 | import android.view.ViewConfiguration; 214 | 215 | import com.taobao.weex.WXEnvironment; 216 | 217 | import java.lang.reflect.Field; 218 | import java.lang.reflect.InvocationTargetException; 219 | import java.lang.reflect.Method; 220 | 221 | public class CommonUtils { 222 | private static final String TAG = "WXTBUtil"; 223 | 224 | private static boolean isSupportSmartBar = false; 225 | private static Boolean hasHardwareMenuKey = null; 226 | 227 | static { 228 | isSupportSmartBar = isSupportSmartBar(); 229 | } 230 | public static int getDisplayWidth(Activity activity){ 231 | int width=0; 232 | if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { 233 | Point point=new Point(); 234 | activity.getWindowManager().getDefaultDisplay().getSize(point); 235 | width = point.x; 236 | } 237 | return width; 238 | } 239 | 240 | public static int getDisplayHeight(Activity activity) { 241 | int height = 0; 242 | if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { 243 | Point point=new Point(); 244 | activity.getWindowManager().getDefaultDisplay().getSize(point); 245 | height=point.y; 246 | } 247 | 248 | Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar); 249 | 250 | if (isSupportSmartBar) { 251 | int smartBarHeight = getSmartBarHeight(activity); 252 | Log.e(TAG, "smartBarHeight:" + smartBarHeight); 253 | height -= smartBarHeight; 254 | } 255 | 256 | if (activity != null && activity.getActionBar() != null) { 257 | int actionbar= activity.getActionBar().getHeight(); 258 | if(actionbar==0){ 259 | TypedArray actionbarSizeTypedArray=activity.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); 260 | actionbar= (int) actionbarSizeTypedArray.getDimension(0,0); 261 | } 262 | Log.d(TAG, "actionbar:" + actionbar); 263 | height -= actionbar; 264 | } 265 | 266 | int status = getStatusBarHeight(activity); 267 | Log.d(TAG, "status:" + status); 268 | 269 | height -= status; 270 | 271 | Log.d(TAG,"height:"+height); 272 | return height; 273 | } 274 | 275 | private static int getStatusBarHeight(Activity activity) { 276 | Class c; 277 | Object obj; 278 | Field field; 279 | int x; 280 | int statusBarHeight = 0; 281 | try { 282 | c = Class.forName("com.android.internal.R$dimen"); 283 | obj = c.newInstance(); 284 | field = c.getField("status_bar_height"); 285 | x = Integer.parseInt(field.get(obj).toString()); 286 | statusBarHeight = activity.getResources().getDimensionPixelSize(x); 287 | } catch (Exception e1) { 288 | e1.printStackTrace(); 289 | } 290 | return statusBarHeight; 291 | } 292 | 293 | private static int getSmartBarHeight(Activity activity) { 294 | ActionBar actionbar = activity.getActionBar(); 295 | if (actionbar != null) 296 | try { 297 | Class c = Class.forName("com.android.internal.R$dimen"); 298 | Object obj = c.newInstance(); 299 | Field field = c.getField("mz_action_button_min_height"); 300 | int height = Integer.parseInt(field.get(obj).toString()); 301 | return activity.getResources().getDimensionPixelSize(height); 302 | } catch (Exception e) { 303 | e.printStackTrace(); 304 | actionbar.getHeight(); 305 | } 306 | return 0; 307 | } 308 | 309 | private static boolean isSupportSmartBar() { 310 | boolean hasSmartBar = false; 311 | try { 312 | final Method method = Build.class.getMethod("hasSmartBar"); 313 | if (method != null) { 314 | hasSmartBar = true; 315 | } 316 | } catch (final Exception e) { 317 | // return false; 318 | } 319 | return hasSmartBar; 320 | } 321 | 322 | public static void throwIfNull(Object object,T e) throws T { 323 | if(object == null){ 324 | throw e; 325 | } 326 | } 327 | 328 | public static boolean hasHardwareMenuKey() { 329 | if (hasHardwareMenuKey == null) { 330 | ViewConfiguration vc = ViewConfiguration.get(WXEnvironment.getApplication()); 331 | if (Build.VERSION.SDK_INT >= 14) { 332 | // boolean vc.hasPermanentMenuKey(); 333 | try { 334 | Method m = vc.getClass().getMethod("hasPermanentMenuKey", 335 | new Class[] {}); 336 | try { 337 | hasHardwareMenuKey = (Boolean) m.invoke(vc, new Object[] {}); 338 | } catch (IllegalArgumentException e) { 339 | hasHardwareMenuKey = false; 340 | } catch (IllegalAccessException e) { 341 | hasHardwareMenuKey = false; 342 | } catch (InvocationTargetException e) { 343 | hasHardwareMenuKey = false; 344 | } 345 | } catch (NoSuchMethodException e) { 346 | hasHardwareMenuKey = false; 347 | } 348 | } 349 | if (hasHardwareMenuKey == null) { 350 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) 351 | hasHardwareMenuKey = true; 352 | else 353 | hasHardwareMenuKey = false; 354 | } 355 | } 356 | return hasHardwareMenuKey; 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /bin/templates/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 372 | 375 | -------------------------------------------------------------------------------- /bin/templates/app/src/main/java/com/weex/app/AbsWeexActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Apache License 3 | * Version 2.0, January 2004 4 | * http://www.apache.org/licenses/ 5 | *

6 | * TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | *

8 | * 1. Definitions. 9 | *

10 | * "License" shall mean the terms and conditions for use, reproduction, 11 | * and distribution as defined by Sections 1 through 9 of this document. 12 | *

13 | * "Licensor" shall mean the copyright owner or entity authorized by 14 | * the copyright owner that is granting the License. 15 | *

16 | * "Legal Entity" shall mean the union of the acting entity and all 17 | * other entities that control, are controlled by, or are under common 18 | * control with that entity. For the purposes of this definition, 19 | * "control" means (i) the power, direct or indirect, to cause the 20 | * direction or management of such entity, whether by contract or 21 | * otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | * outstanding shares, or (iii) beneficial ownership of such entity. 23 | *

24 | * "You" (or "Your") shall mean an individual or Legal Entity 25 | * exercising permissions granted by this License. 26 | *

27 | * "Source" form shall mean the preferred form for making modifications, 28 | * including but not limited to software source code, documentation 29 | * source, and configuration files. 30 | *

31 | * "Object" form shall mean any form resulting from mechanical 32 | * transformation or translation of a Source form, including but 33 | * not limited to compiled object code, generated documentation, 34 | * and conversions to other media types. 35 | *

36 | * "Work" shall mean the work of authorship, whether in Source or 37 | * Object form, made available under the License, as indicated by a 38 | * copyright notice that is included in or attached to the work 39 | * (an example is provided in the Appendix below). 40 | *

41 | * "Derivative Works" shall mean any work, whether in Source or Object 42 | * form, that is based on (or derived from) the Work and for which the 43 | * editorial revisions, annotations, elaborations, or other modifications 44 | * represent, as a whole, an original work of authorship. For the purposes 45 | * of this License, Derivative Works shall not include works that remain 46 | * separable from, or merely link (or bind by name) to the interfaces of, 47 | * the Work and Derivative Works thereof. 48 | *

49 | * "Contribution" shall mean any work of authorship, including 50 | * the original version of the Work and any modifications or additions 51 | * to that Work or Derivative Works thereof, that is intentionally 52 | * submitted to Licensor for inclusion in the Work by the copyright owner 53 | * or by an individual or Legal Entity authorized to submit on behalf of 54 | * the copyright owner. For the purposes of this definition, "submitted" 55 | * means any form of electronic, verbal, or written communication sent 56 | * to the Licensor or its representatives, including but not limited to 57 | * communication on electronic mailing lists, source code control systems, 58 | * and issue tracking systems that are managed by, or on behalf of, the 59 | * Licensor for the purpose of discussing and improving the Work, but 60 | * excluding communication that is conspicuously marked or otherwise 61 | * designated in writing by the copyright owner as "Not a Contribution." 62 | *

63 | * "Contributor" shall mean Licensor and any individual or Legal Entity 64 | * on behalf of whom a Contribution has been received by Licensor and 65 | * subsequently incorporated within the Work. 66 | *

67 | * 2. Grant of Copyright License. Subject to the terms and conditions of 68 | * this License, each Contributor hereby grants to You a perpetual, 69 | * worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | * copyright license to reproduce, prepare Derivative Works of, 71 | * publicly display, publicly perform, sublicense, and distribute the 72 | * Work and such Derivative Works in Source or Object form. 73 | *

74 | * 3. Grant of Patent License. Subject to the terms and conditions of 75 | * this License, each Contributor hereby grants to You a perpetual, 76 | * worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | * (except as stated in this section) patent license to make, have made, 78 | * use, offer to sell, sell, import, and otherwise transfer the Work, 79 | * where such license applies only to those patent claims licensable 80 | * by such Contributor that are necessarily infringed by their 81 | * Contribution(s) alone or by combination of their Contribution(s) 82 | * with the Work to which such Contribution(s) was submitted. If You 83 | * institute patent litigation against any entity (including a 84 | * cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | * or a Contribution incorporated within the Work constitutes direct 86 | * or contributory patent infringement, then any patent licenses 87 | * granted to You under this License for that Work shall terminate 88 | * as of the date such litigation is filed. 89 | *

90 | * 4. Redistribution. You may reproduce and distribute copies of the 91 | * Work or Derivative Works thereof in any medium, with or without 92 | * modifications, and in Source or Object form, provided that You 93 | * meet the following conditions: 94 | *

95 | * (a) You must give any other recipients of the Work or 96 | * Derivative Works a copy of this License; and 97 | *

98 | * (b) You must cause any modified files to carry prominent notices 99 | * stating that You changed the files; and 100 | *

101 | * (c) You must retain, in the Source form of any Derivative Works 102 | * that You distribute, all copyright, patent, trademark, and 103 | * attribution notices from the Source form of the Work, 104 | * excluding those notices that do not pertain to any part of 105 | * the Derivative Works; and 106 | *

107 | * (d) If the Work includes a "NOTICE" text file as part of its 108 | * distribution, then any Derivative Works that You distribute must 109 | * include a readable copy of the attribution notices contained 110 | * within such NOTICE file, excluding those notices that do not 111 | * pertain to any part of the Derivative Works, in at least one 112 | * of the following places: within a NOTICE text file distributed 113 | * as part of the Derivative Works; within the Source form or 114 | * documentation, if provided along with the Derivative Works; or, 115 | * within a display generated by the Derivative Works, if and 116 | * wherever such third-party notices normally appear. The contents 117 | * of the NOTICE file are for informational purposes only and 118 | * do not modify the License. You may add Your own attribution 119 | * notices within Derivative Works that You distribute, alongside 120 | * or as an addendum to the NOTICE text from the Work, provided 121 | * that such additional attribution notices cannot be construed 122 | * as modifying the License. 123 | *

124 | * You may add Your own copyright statement to Your modifications and 125 | * may provide additional or different license terms and conditions 126 | * for use, reproduction, or distribution of Your modifications, or 127 | * for any such Derivative Works as a whole, provided Your use, 128 | * reproduction, and distribution of the Work otherwise complies with 129 | * the conditions stated in this License. 130 | *

131 | * 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | * any Contribution intentionally submitted for inclusion in the Work 133 | * by You to the Licensor shall be under the terms and conditions of 134 | * this License, without any additional terms or conditions. 135 | * Notwithstanding the above, nothing herein shall supersede or modify 136 | * the terms of any separate license agreement you may have executed 137 | * with Licensor regarding such Contributions. 138 | *

139 | * 6. Trademarks. This License does not grant permission to use the trade 140 | * names, trademarks, service marks, or product names of the Licensor, 141 | * except as required for reasonable and customary use in describing the 142 | * origin of the Work and reproducing the content of the NOTICE file. 143 | *

144 | * 7. Disclaimer of Warranty. Unless required by applicable law or 145 | * agreed to in writing, Licensor provides the Work (and each 146 | * Contributor provides its Contributions) on an "AS IS" BASIS, 147 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | * implied, including, without limitation, any warranties or conditions 149 | * of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | * PARTICULAR PURPOSE. You are solely responsible for determining the 151 | * appropriateness of using or redistributing the Work and assume any 152 | * risks associated with Your exercise of permissions under this License. 153 | *

154 | * 8. Limitation of Liability. In no event and under no legal theory, 155 | * whether in tort (including negligence), contract, or otherwise, 156 | * unless required by applicable law (such as deliberate and grossly 157 | * negligent acts) or agreed to in writing, shall any Contributor be 158 | * liable to You for damages, including any direct, indirect, special, 159 | * incidental, or consequential damages of any character arising as a 160 | * result of this License or out of the use or inability to use the 161 | * Work (including but not limited to damages for loss of goodwill, 162 | * work stoppage, computer failure or malfunction, or any and all 163 | * other commercial damages or losses), even if such Contributor 164 | * has been advised of the possibility of such damages. 165 | *

166 | * 9. Accepting Warranty or Additional Liability. While redistributing 167 | * the Work or Derivative Works thereof, You may choose to offer, 168 | * and charge a fee for, acceptance of support, warranty, indemnity, 169 | * or other liability obligations and/or rights consistent with this 170 | * License. However, in accepting such obligations, You may act only 171 | * on Your own behalf and on Your sole responsibility, not on behalf 172 | * of any other Contributor, and only if You agree to indemnify, 173 | * defend, and hold each Contributor harmless for any liability 174 | * incurred by, or claims asserted against, such Contributor by reason 175 | * of your accepting any such warranty or additional liability. 176 | *

177 | * END OF TERMS AND CONDITIONS 178 | *

179 | * APPENDIX: How to apply the Apache License to your work. 180 | *

181 | * To apply the Apache License to your work, attach the following 182 | * boilerplate notice, with the fields enclosed by brackets "[]" 183 | * replaced with your own identifying information. (Don't include 184 | * the brackets!) The text should be enclosed in the appropriate 185 | * comment syntax for the file format. We also recommend that a 186 | * file or class name and description of purpose be included on the 187 | * same "printed page" as the copyright notice for easier 188 | * identification within third-party archives. 189 | *

190 | * Copyright 2016 Alibaba Group 191 | *

192 | * Licensed under the Apache License, Version 2.0 (the "License"); 193 | * you may not use this file except in compliance with the License. 194 | * You may obtain a copy of the License at 195 | *

196 | * http://www.apache.org/licenses/LICENSE-2.0 197 | *

198 | * Unless required by applicable law or agreed to in writing, software 199 | * distributed under the License is distributed on an "AS IS" BASIS, 200 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | * See the License for the specific language governing permissions and 202 | * limitations under the License. 203 | */ 204 | package com.weex.app; 205 | 206 | import android.content.BroadcastReceiver; 207 | import android.content.Context; 208 | import android.content.Intent; 209 | import android.content.IntentFilter; 210 | import android.content.pm.PackageManager; 211 | import android.net.Uri; 212 | import android.os.Bundle; 213 | import android.support.annotation.Nullable; 214 | import android.support.v4.app.ActivityCompat; 215 | import android.support.v4.content.ContextCompat; 216 | import android.support.v4.content.LocalBroadcastManager; 217 | import android.support.v7.app.AppCompatActivity; 218 | import android.text.TextUtils; 219 | import android.view.View; 220 | import android.view.ViewGroup; 221 | import android.widget.Toast; 222 | 223 | import com.taobao.weex.IWXRenderListener; 224 | import com.taobao.weex.WXSDKEngine; 225 | import com.taobao.weex.WXSDKInstance; 226 | import com.taobao.weex.common.IWXDebugProxy; 227 | import com.taobao.weex.common.WXRenderStrategy; 228 | import com.weex.app.util.CommonUtils; 229 | 230 | import java.util.HashMap; 231 | import java.util.Map; 232 | 233 | public abstract class AbsWeexActivity extends AppCompatActivity implements IWXRenderListener { 234 | private static final String TAG = "AbsWeexActivity"; 235 | protected BroadcastReceiver mBroadcastReceiver; 236 | protected ViewGroup mContainer; 237 | protected WXSDKInstance mInstance; 238 | protected Uri mUri; 239 | private WxReloadListener mReloadListener; 240 | private WxRefreshListener mRefreshListener; 241 | private String mUrl;// "http://your_current_IP:12580/examples/build/index.js"; 242 | private String mPageName = TAG; 243 | protected Boolean isLocalUrl = false; 244 | 245 | @Override 246 | protected void onCreate(@Nullable Bundle savedInstanceState) { 247 | super.onCreate(savedInstanceState); 248 | createWeexInstance(); 249 | mInstance.onActivityCreate(); 250 | registerBroadcastReceiver(mBroadcastReceiver, null); 251 | } 252 | 253 | protected final ViewGroup getContainer() { 254 | return mContainer; 255 | } 256 | 257 | protected final void setContainer(ViewGroup container) { 258 | mContainer = container; 259 | } 260 | 261 | protected void destoryWeexInstance() { 262 | if (mInstance != null) { 263 | mInstance.registerRenderListener(null); 264 | mInstance.destroy(); 265 | mInstance = null; 266 | } 267 | } 268 | 269 | protected void createWeexInstance() { 270 | destoryWeexInstance(); 271 | mInstance = new WXSDKInstance(this); 272 | mInstance.registerRenderListener(this); 273 | } 274 | 275 | protected void renderPageByURL(String url) { 276 | renderPageByURL(url, null); 277 | } 278 | 279 | protected void renderPageByURL(String url, String jsonInitData) { 280 | CommonUtils.throwIfNull(mContainer, new RuntimeException("Can't render page, container is null")); 281 | Map options = new HashMap<>(); 282 | options.put(WXSDKInstance.BUNDLE_URL, url); 283 | mInstance.renderByUrl( 284 | getPageName(), 285 | url, 286 | options, 287 | jsonInitData, 288 | CommonUtils.getDisplayWidth(this), 289 | CommonUtils.getDisplayHeight(this), 290 | WXRenderStrategy.APPEND_ASYNC); 291 | } 292 | 293 | public String getPageName() { 294 | return mPageName; 295 | } 296 | 297 | @Override 298 | public void onStart() { 299 | super.onStart(); 300 | if (mInstance != null) { 301 | mInstance.onActivityStart(); 302 | } 303 | } 304 | 305 | @Override 306 | public void onResume() { 307 | super.onResume(); 308 | if (mInstance != null) { 309 | mInstance.onActivityResume(); 310 | } 311 | } 312 | 313 | @Override 314 | public void onPause() { 315 | super.onPause(); 316 | if (mInstance != null) { 317 | mInstance.onActivityPause(); 318 | } 319 | } 320 | 321 | @Override 322 | public void onStop() { 323 | super.onStop(); 324 | if (mInstance != null) { 325 | mInstance.onActivityStop(); 326 | } 327 | } 328 | 329 | @Override 330 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 331 | if (mInstance != null) { 332 | mInstance.onRequestPermissionsResult(requestCode, permissions, grantResults); 333 | } 334 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 335 | } 336 | 337 | @Override 338 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 339 | if (mInstance != null) { 340 | mInstance.onActivityResult(requestCode, resultCode, data); 341 | } 342 | super.onActivityResult(requestCode, resultCode, data); 343 | } 344 | 345 | @Override 346 | public void onDestroy() { 347 | super.onDestroy(); 348 | if (mInstance != null) { 349 | mInstance.onActivityDestroy(); 350 | } 351 | unregisterBroadcastReceiver(); 352 | 353 | } 354 | 355 | @Override 356 | public void onViewCreated(WXSDKInstance wxsdkInstance, View view) { 357 | if (mContainer != null) { 358 | mContainer.removeAllViews(); 359 | mContainer.addView(view); 360 | } 361 | } 362 | 363 | @Override 364 | public void onRefreshSuccess(WXSDKInstance wxsdkInstance, int width, int height) { 365 | 366 | } 367 | 368 | public void runWithPermissionsCheck(int requestCode, String permission, Runnable runnable) { 369 | if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { 370 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { 371 | Toast.makeText(this, "please give me the permission", Toast.LENGTH_SHORT).show(); 372 | } else { 373 | ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode); 374 | } 375 | } else { 376 | if (runnable != null) { 377 | runnable.run(); 378 | } 379 | } 380 | } 381 | 382 | @Override 383 | public void onRenderSuccess(WXSDKInstance instance, int width, int height) { 384 | 385 | } 386 | 387 | @Override 388 | public void onException(WXSDKInstance instance, String errCode, String msg) { 389 | 390 | } 391 | 392 | public void setReloadListener(WxReloadListener reloadListener) { 393 | mReloadListener = reloadListener; 394 | } 395 | 396 | public void registerBroadcastReceiver(BroadcastReceiver receiver, IntentFilter filter) { 397 | mBroadcastReceiver = receiver != null ? receiver : new DefaultBroadcastReceiver(); 398 | if (filter == null) { 399 | filter = new IntentFilter(); 400 | } 401 | filter.addAction(IWXDebugProxy.ACTION_DEBUG_INSTANCE_REFRESH); 402 | filter.addAction(WXSDKEngine.JS_FRAMEWORK_RELOAD); 403 | LocalBroadcastManager.getInstance(getApplicationContext()) 404 | .registerReceiver(mBroadcastReceiver, filter); 405 | if (mReloadListener == null) { 406 | setReloadListener(new WxReloadListener() { 407 | 408 | @Override 409 | public void onReload() { 410 | createWeexInstance(); 411 | renderPage(); 412 | } 413 | 414 | }); 415 | } 416 | 417 | if (mRefreshListener == null) { 418 | setRefreshListener(new WxRefreshListener() { 419 | 420 | @Override 421 | public void onRefresh() { 422 | createWeexInstance(); 423 | renderPage(); 424 | } 425 | 426 | }); 427 | } 428 | } 429 | 430 | public void unregisterBroadcastReceiver() { 431 | if (mBroadcastReceiver != null) { 432 | LocalBroadcastManager.getInstance(getApplicationContext()) 433 | .unregisterReceiver(mBroadcastReceiver); 434 | mBroadcastReceiver = null; 435 | } 436 | setReloadListener(null); 437 | setRefreshListener(null); 438 | } 439 | 440 | public void setRefreshListener(WxRefreshListener refreshListener) { 441 | mRefreshListener = refreshListener; 442 | } 443 | 444 | public String getUrl() { 445 | return mUrl; 446 | } 447 | 448 | public void setUrl(String url) { 449 | mUrl = url; 450 | } 451 | 452 | public void loadUrl(String url) { 453 | setUrl(url); 454 | renderPage(); 455 | } 456 | 457 | protected void preRenderPage() { 458 | 459 | } 460 | 461 | protected void postRenderPage() { 462 | 463 | } 464 | 465 | protected void renderPage() { 466 | preRenderPage(); 467 | renderPageByURL(mUrl); 468 | postRenderPage(); 469 | } 470 | 471 | protected boolean isLocalPage() { 472 | boolean isLocalPage = true; 473 | if (mUri != null) { 474 | String scheme = mUri.getScheme(); 475 | isLocalPage = !mUri.isHierarchical() || 476 | (!TextUtils.equals(scheme, "http") && !TextUtils.equals(scheme, "https")); 477 | } 478 | return isLocalPage; 479 | } 480 | 481 | public void setPageName(String pageName) { 482 | mPageName = pageName; 483 | } 484 | 485 | public interface WxReloadListener { 486 | void onReload(); 487 | } 488 | 489 | public interface WxRefreshListener { 490 | void onRefresh(); 491 | } 492 | 493 | public class DefaultBroadcastReceiver extends BroadcastReceiver { 494 | @Override 495 | public void onReceive(Context context, Intent intent) { 496 | if (IWXDebugProxy.ACTION_DEBUG_INSTANCE_REFRESH.equals(intent.getAction())) { 497 | if (mRefreshListener != null) { 498 | mRefreshListener.onRefresh(); 499 | } 500 | } else if (WXSDKEngine.JS_FRAMEWORK_RELOAD.equals(intent.getAction())) { 501 | if (mReloadListener != null) { 502 | mReloadListener.onReload(); 503 | } 504 | } 505 | } 506 | } 507 | } 508 | --------------------------------------------------------------------------------