diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index bdb0cabc87cf50106df6e15097dff816c8c3eb34..0000000000000000000000000000000000000000 --- a/.gitattributes +++ /dev/null @@ -1,17 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index cd2946ad76b4402e5b3cab9243a9281aad228670..37a4eb8b43d978ea05b2c6e3fb934f9b40dddd4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,47 +1,15 @@ -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - -# ========================= -# Operating System Files -# ========================= - -# OSX -# ========================= - +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store -.AppleDouble -.LSOverride - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index dff5f3a5d02a71dcf47f617135ac04564aa75973..0000000000000000000000000000000000000000 --- a/.travis.yml +++ /dev/null @@ -1 +0,0 @@ -language: java diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..1c6df917f8bdd3f093f1af344134a1455cd17254 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## 0.0.1-SNAPSHOT +* refactor: For module library Android-to-OpenHarmony + +## 2 +* 2 \ No newline at end of file diff --git a/README.md b/README.md index f56482024ee8b0d5b0a51fdd57e518557f50c51b..7ba95ec78d569e596b3a690281fc82c4feaac0de 100644 --- a/README.md +++ b/README.md @@ -1,73 +1,68 @@ -# Codeview -------------- -http://avraampiperidis.github.io/Codeview/
-[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Codeview-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/3999) - -Codeview is a android library tha lets you -preview code in webview very easy and simple with highlighs and colors. -With styles to chooses and language. - -Also you can inject html and text into webview or any extended webview class. - - -This library was inspired and is working thanks to [highlight.js](https://highlightjs.org/).
-Apps using Codeview library.
-https://play.google.com/store/apps/details?id=com.protectsoft.javatutorial
-https://play.google.com/store/apps/details?id=com.protectsoft.pythontutorial
- -https://bintray.com/zeronerone/maven/Codeview#statistics
- -Usage ------ - -#### Codeview - -#### Download/Install Gradle --------- - -```groovy -repositories { - jcenter() - } - -compile 'Codeview-1.0.0:webviewcode:1.0.0' -``` -##### 1) Get a reference to your WebView or any extended WebView - -```java -WebView webview = (WebView) findViewById(R.id.webview); -//set settings here -``` - -##### 2) Basic usage. Default style is Original, and default language is java. - -```java -//your string code -String code = "public static void main(String[] args) { \n" + - "\n" + - "//comments\n" + - " for(int i =0; i < 10; i++) {\n" + - " addnum();\n" + - " }\n" + - "\n" + - "}\n"; - -Codeview.with(getApplicationContext()) - .withCode(code) - .into(webview); +# CodeView + +**本项目是基于开源项目 CodeView 进行OpenHarmony的移植和开发的,可以通过项目标签以及github地址( https://github.com/avraampiperidis/Codeview )追踪到原项目版本** + +#### 项目介绍 +- 项目名称:CodeView +- 所属系列:OpenHarmony的第三方组件适配移植 +- 功能:代码块高亮显示。 +- 项目移植状态:完成 +- 调用差异:无 +- 开发版本:sdk5,DevEco Studio2.1 Beta4 +- 项目作者和维护人:蒋军 +- 联系方式:jiangjun073@chinasoftinc.com +- 原项目Doc地址:https://github.com/avraampiperidis/Codeview +- 基线版本:CodeView组件 Release 2 +- 编程语言:Java + +#### 安装教程 +1.在项目根目录下的build.gradle文件中, +```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} ``` - - -##### 3) set style and language. - -```java -MyTouchWebView webview = (MyTouchWebView) findViewById(R.id.mytouchwebview); -//set settings here +2.在entry模块的build.gradle文件中, +```gradle +dependencies { + implementation('com.gitee.chinasoft_ohos:CodeView:0.0.1-SNAPSHOT') + ...... +} ``` -```java -//your string java code -String code = "public static void main(String[] args) { \n" + +#### 使用说明 + +1. 创建一个WebView对象,添加到页面中: + ```java + DirectionalLayout directionalLayout = (DirectionalLayout)findComponentById(ResourceTable.Id_dl); + webView = new WebView(getContext()); + webView.setComponentSize(DirectionalLayout.LayoutConfig.MATCH_PARENT, + DirectionalLayout.LayoutConfig.MATCH_PARENT); + directionalLayout.addComponent(webView); + ``` +2. 基本用法: + ```java + String code = "public static void main(String[] args) { \n" + + "\n" + + "//comments\n" + + " for(int i =0; i < 10; i++) {\n" + + " addnum();\n" + + " }\n" + + "\n" + + "}\n"; + + Codeview.with(getApplicationContext()) + .withCode(code) + .into(webview); + ``` + +3. 设置css样式和语言类型: + ```java + String code = "public static void main(String[] args) { \n" + "\n" + "//comments\n" + " for(int i =0; i < 10; i++) {\n" + @@ -76,24 +71,15 @@ String code = "public static void main(String[] args) { \n" + "\n" + "}\n"; -Codeview.with(getApplicationContext()) + Codeview.with(getApplicationContext()) .withCode(code) .setStyle(Settings.WithStyle.DARKULA) .setLang(Settings.Lang.JAVA) .into(webview); -``` - - -##### 4) Inject html head content and text. - -```java -WebView webview = (WebView) findViewById(R.id.webview); -//set settings here -``` - -```java -//your string javascript code - String code = "function Constructor(v1,v2,v3)\n" + + ``` +4. 注入html头部以及文本:. + ```java + String code = "function Constructor(v1,v2,v3)\n" + "{\n" + " this.v1 = v1;\n" + " this.v2 = v2;\n" + @@ -113,23 +99,41 @@ WebView webview = (WebView) findViewById(R.id.webview); "}"; - Codeview.with(getApplicationContext()) - .setHtmlHeadContent("") - .withHtml("

h1 injected header

") - .withText("this text is always wrap inside pre tags") - .withCode(code) - .withHtml("

h1 header after code

") - .withHtml("
my html table
") - .setStyle(Settings.WithStyle.DARKSTYLE) - .setLang(Settings.Lang.JAVASCRIPT) - .setAutoWrap(true) - .into(webView); -``` - + .withHtml("

h1 injected header

") + .withText("this text is always wrap inside pre tags") + .withCode(code) + .withHtml("

h1 header after code

") + .withHtml("
my html table
") + .setStyle(Settings.WithStyle.DARKSTYLE) + .setLang(Settings.Lang.JAVASCRIPT) + .setAutoWrap(true) + .into(webView); + ``` + +5. 注意事项: + 鸿蒙中,HTML里含有#字符,WebView会展示出错,拼接的HTML中,无论标签,css样式,js,文本,代码块不能带有#字符,鸿蒙中,HTML里含有#字符,WebView会展示出错,需要去除所有#字符,且使用到highlight.js中的#字符都用 ` 字符替代,代码块中也不能含有这个字符。 + +#### 测试信息 + +CodeCheck代码测试无异常 + +CloudTest代码测试无异常 + +火绒安全病毒安全检测通过 + +当前版本demo功能与原组件基本无差异 + +测试员:刘飞虎 + +#### 版本迭代 + +- 0.0.1-SNAPSHOT ## License MIT License @@ -153,5 +157,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - diff --git a/build.gradle b/build.gradle index 3a50be3a593a4d97033a1c309dc578fc28e30a60..1dc510ffd5a8d3abe3f2758e193a2619aca86563 100644 --- a/build.gradle +++ b/build.gradle @@ -1,42 +1,37 @@ -apply plugin: 'com.android.library' +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' -android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' - repositories { - jcenter() - google() - } +ohos { + compileSdkVersion 5 defaultConfig { - minSdkVersion 16 - targetSdkVersion 28 - versionCode 2 - versionName "1.0" + compatibleSdkVersion 5 } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' } + jcenter() } - testOptions { - unitTests.returnDefaultValues = true + dependencies { + classpath 'com.huawei.ohos:hap:2.4.2.7' + classpath 'com.huawei.ohos:decctest:1.0.0.7' } } -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - testImplementation 'junit:junit:4.12' - androidTestImplementation 'junit:junit:4.12' - implementation 'org.mockito:mockito-all:1.8.4' -} - -buildscript { +allprojects { repositories { - jcenter() - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + jcenter() } } diff --git a/entry/.gitignore b/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..796b96d1c402326528b4ba3c12ee9d92d0e212e9 --- /dev/null +++ b/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/entry/build.gradle b/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..45bbf69c2365242508d9c5799dd7ccf5972950d0 --- /dev/null +++ b/entry/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.huawei.ohos.hap' +apply plugin: 'com.huawei.ohos.decctest' +ohos { + compileSdkVersion 5 + defaultConfig { + compatibleSdkVersion 5 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + implementation project(path: ':library') + testImplementation 'junit:junit:4.13' + ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' +} +decc { + supportType = ['html', 'xml'] +} diff --git a/entry/proguard-rules.pro b/entry/proguard-rules.pro new file mode 100644 index 0000000000000000000000000000000000000000..f7666e47561d514b2a76d5a7dfbb43ede86da92a --- /dev/null +++ b/entry/proguard-rules.pro @@ -0,0 +1 @@ +# config module specific ProGuard rules here. \ No newline at end of file diff --git a/entry/src/main/config.json b/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9fe69b2fedf678eaa1de9a0edde2cc1fd6e2e034 --- /dev/null +++ b/entry/src/main/config.json @@ -0,0 +1,74 @@ +{ + "app": { + "bundleName": "com.protectsoft.webviewcodedemo", + "vendor": "protectsoft", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.protectsoft.webviewcodedemo", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.protectsoft.webviewcodedemo.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar" + } + ] + } + }, + { + "orientation": "unspecified", + "name": "com.protectsoft.webviewcodedemo.ShowAbility", + "icon": "$media:icon", + "description": "$string:showability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar" + } + ] + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/java/com/protectsoft/webviewcodedemo/Constants.java b/entry/src/main/java/com/protectsoft/webviewcodedemo/Constants.java new file mode 100644 index 0000000000000000000000000000000000000000..d6e9f57c61e86317bf59aa43fe5a7f360bd3b839 --- /dev/null +++ b/entry/src/main/java/com/protectsoft/webviewcodedemo/Constants.java @@ -0,0 +1,268 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.protectsoft.webviewcodedemo; + +/** + * Constants + * + * @since 2021-04-30 + */ +public class Constants { + /** + * SHOW_TYPE + */ + public static final String SHOW_TYPE = "SHOW_TYPE"; + /** + * SHOW_CODE + */ + public static final String SHOW_CODE = "SHOW_CODE"; + /** + * SHOW_LANG + */ + public static final String SHOW_LANG = "SHOW_LANG"; + /** + * Basic usage. Default style is Original, and default language is java. + */ + public static final int DEFALUT_TYPE = 1; + /** + * set style and language. + */ + public static final int OTHER_TYPE = 2; + /** + * Inject html head content and text. + */ + public static final int OTHER1_TYPE = 3; + /** + * PYTHON_TYPE + */ + public static final int PYTHON_TYPE = 4; + /** + * JAVASCRIPT_TYPE + */ + public static final int JAVASCRIPT_TYPE = 5; + /** + * RUBY + */ + public static final int RUBY_TYPE = 6; + /** + * CSHARP + */ + public static final int CSHARP_TYPE = 7; + /** + * PHP + */ + public static final int PHP_TYPE = 8; + /** + * SQL + */ + public static final int SQL_TYPE = 9; + /** + * CPLUSPLUS + */ + public static final int CPLUSPLUS_TYPE = 10; + + /** + * DEFALUT_STRING + */ + public static final String DEFALUT_STRING = "public static void main(String[] args) { \n" + + "\n" + "//comments\n" + + " for(int i =0; i < 10; i++) {\n" + + " addnum();\n" + + " }\n" + + "\n" + + "}\n"; + /** + * OTHER_STRING + */ + public static final String OTHER_STRING = "public static void main(String[] args) { \n" + + "\n" + "//comments\n" + + " for(int i =0; i < 10; i++) {\n" + + " addnum();\n" + + " }\n" + + "\n" + + "}\n"; + /** + * OTHER1_STRING + */ + public static final String OTHER1_STRING = "function Constructor(v1,v2,v3)\n" + "{\n" + + " this.v1 = v1;\n" + + " this.v2 = v2;\n" + + " this.funk = function()\n" + + " {\n" + + " console.log(\"Test: \"+ v3 );\n" + + " }\n" + + "}\n" + + "\n" + + "var obj1 = new Constructor(\"par1\",\"par2\",\"par3\");\n" + + "var arr = [\"w1\",\"w2\",\"w3\",obj1];\n" + "\n" + + "function f2()\n" + "{ \n" + + " obj1.funk(); //works ok\n" + + " console.log(\"test \"+tablica[3].funk.call() ); //doesn't work\n" + + "}"; + /** + * PYTHON_STRING + */ + public static final String PYTHON_STRING = "import random\n" + + "if __name__ ==\"__main__\":\n" + + " checkcode=\"\"\n" + + " for i in range(4):\n" + + " index=random.randrange(0,4)\n" + + " if index!=i and index +1 !=i:\n" + + " checkcode +=chr(random.randint(97,122))\n" + + " elif index +1==i:\n" + + " checkcode +=chr(random.randint(65,90) )\n" + + " else:\n" + + " checkcode +=str(random.randint(1,9))\n" + + " print(checkcode)"; + + /** + * RUBY_STRING + */ + public static final String RUBY_STRING = "def fact(n) \n" + + " if n == 0 \n" + + " 1 \n" + + " else \n" + + " n * fact(n-1) \n" + + " end \n" + + "end \n" + + "print fact(ARGV[0].to_i), \"\\n\" "; + + /** + * CSHARP_STRING + */ + public static final String CSHARP_STRING = "class Program\n" + + " {\n" + + " static void Main(string[] args)\n" + + " {\n" + + " Transform t = new Transform();\n" + + " // t.GetVector().x = 10; 这边编译报错\n" + + " Vector v2 = t.GetVector();\n" + + " v2.x = 10;\n" + + " t.ShowV();\n" + + " Console.Read();\n" + + " }\n" + + " }\n" + + " \n" + + " struct Vector\n" + + " {\n" + + " public float x;\n" + + " public float y;\n" + + " public float z;\n" + + " }\n" + + " \n" + + " class Transform\n" + + " {\n" + + " public Vector v;\n" + + " //set\n" + + " public void SetVector(Vector v)\n" + + " {\n" + + " this.v = v;\n" + + " }\n" + + " //get\n" + + " public Vector GetVector()\n" + + " {\n" + + " return v;\n" + + " }\n" + + " \n" + + " public void ShowV()\n" + + " {\n" + + " Console.WriteLine(v.x + \"...\" + v.y + \"...\" + v.z);\n" + + " }\n" + + " }"; + + /** + * PHP_STRING + */ + public static final String PHP_STRING = "function is_spam($text, $file, $split = ‘:‘, $regex = false){ \n" + + "$handle = fopen($file, ‘rb‘); \n" + + "$contents = fread($handle, filesize($file)); \n" + + "fclose($handle); \n" + + "$lines = explode(\"n\", $contents); \n" + + "$arr = array(); \n" + + "foreach($lines as $line){ \n" + + "list($word, $count) = explode($split, $line); \n" + + "if($regex) \n" + + "$arr[$word] = $count; \n" + + "else \n" + + "$arr[preg_quote($word)] = $count; \n" + + "} \n" + + "preg_match_all(\"~\".implode(‘|‘, array_keys($arr)).\"~\", $text, $matches); \n" + + "$temp = array(); \n" + + "foreach($matches[0] as $match){ \n" + + "if(!in_array($match, $temp)){ \n" + + "$temp[$match] = $temp[$match] + 1; \n" + + "if($temp[$match] >= $arr[$word]) \n" + + "return true; \n" + + "} \n" + + "} \n" + + "return false; \n" + + "} \n" + + "$file = ‘spam.txt‘; \n" + + "$str = ‘This string has cat, dog word‘; \n" + + "if(is_spam($str, $file)) \n" + + "echo ‘this is spam‘; \n" + + "else \n" + + "echo ‘this is not spam‘; \n" + + "ab:3 \n" + + "dog:3 \n" + + "cat:2 \n" + + "monkey:2 "; + + /** + * SQL + */ + public static final String SQL_STRING = "CREATE TABLE ENROLLS\n" + + "\n" + + " (SNO NUMERIC(6,0) NOT NULL\n" + + "\n" + + " CNO CHAR(4) NOT NULL\n" + + "\n" + + " GRADE INT\n" + + "\n" + + " PRIMARY KEY(SNO,CNO)\n" + + "\n" + + " FOREIGN KEY(SNO) REFERENCES STUDENTS(SNO)\n" + + "\n" + + " FOREIGN KEY(CNO) REFERENCES COURSES(CNO)\n" + + "\n" + + " CHECK ((GRADE IS NULL) OR (GRADE BETWEEN 0 AND 100)))"; + + /** + * SQL + */ + public static final String CPLUSPLUS_STRING = "using namespace std;\n" + + " \n" + + "extern int a, b;\n" + + "extern int c;\n" + + "extern float f;\n" + + "int main()\n" + + "{\n" + + "\t//定义变量\n" + + "\tint a, b;\n" + + "\tint c;\n" + + "\tfloat f;\n" + + "\t\n" + + "\t//实际初始化\n" + + "\ta = 10;\n" + + "\tb = 20;\n" + + "\tc=a+b;\n" + + "\t\n" + + "\tcout << c << endl;\n" + + "\tf = 70.0/3.0;\n" + + "\tcout << f << endl;\n" + + "\treturn 0;\n" + + "}"; +} diff --git a/entry/src/main/java/com/protectsoft/webviewcodedemo/MainAbility.java b/entry/src/main/java/com/protectsoft/webviewcodedemo/MainAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..3a8e310302953c12d1cffdc6e2b131b1022c39da --- /dev/null +++ b/entry/src/main/java/com/protectsoft/webviewcodedemo/MainAbility.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.protectsoft.webviewcodedemo; + +import com.protectsoft.webviewcode.Settings; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.aafwk.content.Operation; +import ohos.agp.components.Button; + +/** + * MainAbility + * + * @since 2021-04-30 + */ +public class MainAbility extends Ability { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_main); + Button btnDefalut = (Button)findComponentById(ResourceTable.Id_btn_defalut); + btnDefalut.setClickedListener(component -> + jumpAbilityByType(Constants.DEFALUT_TYPE,Constants.DEFALUT_STRING, Settings.Lang.JAVA)); + Button btnOther = (Button)findComponentById(ResourceTable.Id_btn_other); + btnOther.setClickedListener(component -> + jumpAbilityByType(Constants.OTHER_TYPE,Constants.OTHER_STRING, Settings.Lang.JAVA)); + Button btnOther1 = (Button)findComponentById(ResourceTable.Id_btn_other1); + btnOther1.setClickedListener(component -> + jumpAbilityByType(Constants.OTHER1_TYPE,Constants.OTHER1_STRING, Settings.Lang.JAVASCRIPT)); + Button btnPython = (Button)findComponentById(ResourceTable.Id_btn_python); + btnPython.setClickedListener(component -> + jumpAbilityByType(Constants.PYTHON_TYPE,Constants.PYTHON_STRING, Settings.Lang.PYTHON)); + Button btnJavascript = (Button)findComponentById(ResourceTable.Id_btn_javascript); + btnJavascript.setClickedListener(component -> + jumpAbilityByType(Constants.JAVASCRIPT_TYPE,Constants.OTHER1_STRING, Settings.Lang.JAVASCRIPT)); + Button btnRuby = (Button)findComponentById(ResourceTable.Id_btn_ruby); + btnRuby.setClickedListener(component -> + jumpAbilityByType(Constants.RUBY_TYPE,Constants.RUBY_STRING, Settings.Lang.RUBY)); + Button btnCs = (Button)findComponentById(ResourceTable.Id_btn_cs); + btnCs.setClickedListener(component -> + jumpAbilityByType(Constants.CSHARP_TYPE,Constants.CSHARP_STRING, Settings.Lang.CSHARP)); + Button btnPhp = (Button)findComponentById(ResourceTable.Id_btn_php); + btnPhp.setClickedListener(component -> + jumpAbilityByType(Constants.PHP_TYPE,Constants.PHP_STRING, Settings.Lang.PHP)); + Button btnSql = (Button)findComponentById(ResourceTable.Id_btn_sql); + btnSql.setClickedListener(component -> + jumpAbilityByType(Constants.SQL_TYPE,Constants.SQL_STRING, Settings.Lang.SQL)); + Button btnCpp = (Button)findComponentById(ResourceTable.Id_btn_cpp); + btnCpp.setClickedListener(component -> + jumpAbilityByType(Constants.CPLUSPLUS_TYPE,Constants.CPLUSPLUS_STRING, Settings.Lang.CPLUSPLUS)); + } + + private void jumpAbilityByType(int type,String code,String lang) { + Intent intent = new Intent(); + intent.setParam(Constants.SHOW_TYPE, type); + intent.setParam(Constants.SHOW_CODE, code); + intent.setParam(Constants.SHOW_LANG, lang); + Operation mOperation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName(getBundleName()) + .withAbilityName(ShowAbility.class.getName()) + .build(); + intent.setOperation(mOperation); + startAbility(intent); + } +} diff --git a/entry/src/main/java/com/protectsoft/webviewcodedemo/MyApplication.java b/entry/src/main/java/com/protectsoft/webviewcodedemo/MyApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..2ebdf24a1935173516b459b075ab72ec08b724ca --- /dev/null +++ b/entry/src/main/java/com/protectsoft/webviewcodedemo/MyApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.protectsoft.webviewcodedemo; + +import ohos.aafwk.ability.AbilityPackage; + +/** + * MyApplication + * + * @since 2021-04-30 + */ +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/entry/src/main/java/com/protectsoft/webviewcodedemo/ShowAbility.java b/entry/src/main/java/com/protectsoft/webviewcodedemo/ShowAbility.java new file mode 100644 index 0000000000000000000000000000000000000000..28346c8851b794f696e27cffa483fadc53ac8438 --- /dev/null +++ b/entry/src/main/java/com/protectsoft/webviewcodedemo/ShowAbility.java @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.protectsoft.webviewcodedemo; + +import com.protectsoft.webviewcode.Codeview; +import com.protectsoft.webviewcode.Settings; + +import ohos.aafwk.ability.Ability; +import ohos.aafwk.content.Intent; +import ohos.agp.components.Button; +import ohos.agp.components.DirectionalLayout; +import ohos.agp.components.Text; +import ohos.agp.components.webengine.WebView; + +/** + * ShowAbility + * + * @since 2021-04-30 + */ +public class ShowAbility extends Ability { + private static final int NUM_20 = 20; + private final int[] resIds = { + ResourceTable.Id_btn_default,ResourceTable.Id_btn_agate, + ResourceTable.Id_btn_ANDROIDSTUDIO,ResourceTable.Id_btn_ARDUINO_LIGHT,ResourceTable.Id_btn_ARTA, + ResourceTable.Id_btn_ASCETIC,ResourceTable.Id_btn_ATELIER_DARK,ResourceTable.Id_btn_ATELIER_LIGHT, + ResourceTable.Id_btn_ATELIER_FOREST_DARK,ResourceTable.Id_btn_DARKSTYLE, + ResourceTable.Id_btn_DARKULA,ResourceTable.Id_btn_DOCCO,ResourceTable.Id_btn_FAR, + ResourceTable.Id_btn_GITHUB,ResourceTable.Id_btn_GITHUBGIST, + ResourceTable.Id_btn_GOOGLECODE,ResourceTable.Id_btn_IDEA,ResourceTable.Id_btn_MAGULA, + ResourceTable.Id_btn_OBSIDIAN,ResourceTable.Id_btn_XCODE}; + private final String[] styles = { + Settings.WithStyle.DEFAULT,Settings.WithStyle.AGATE, + Settings.WithStyle.ANDROIDSTUDIO,Settings.WithStyle.ARDUINO_LIGHT,Settings.WithStyle.ARTA, + Settings.WithStyle.ASCETIC,Settings.WithStyle.ATELIER_DARK, + Settings.WithStyle.ATELIER_LIGHT,Settings.WithStyle.ATELIER_FOREST_DARK,Settings.WithStyle.DARKSTYLE, + Settings.WithStyle.DARKULA,Settings.WithStyle.DOCCO, + Settings.WithStyle.FAR,Settings.WithStyle.GITHUB,Settings.WithStyle.GITHUBGIST, + Settings.WithStyle.GOOGLECODE,Settings.WithStyle.IDEA, + Settings.WithStyle.MAGULA,Settings.WithStyle.OBSIDIAN,Settings.WithStyle.XCODE}; + private final Button[] buttons = new Button[NUM_20]; + private Text textStyle; + private Text textAutoWrap; + private boolean isMyAutoWrap = false; + private WebView webView; + private Intent mIntent; + private int mPosition = 0; + + @Override + public void onStart(Intent intent) { + super.onStart(intent); + super.setUIContent(ResourceTable.Layout_ability_show); + DirectionalLayout directionalLayout = (DirectionalLayout)findComponentById(ResourceTable.Id_dl); + webView = new WebView(getContext()); + webView.setComponentSize(DirectionalLayout.LayoutConfig.MATCH_PARENT, + DirectionalLayout.LayoutConfig.MATCH_PARENT); + directionalLayout.addComponent(webView); + mIntent = intent; + initView(); + } + + private void initView() { + textStyle = (Text) findComponentById(ResourceTable.Id_t_style); + textAutoWrap = (Text) findComponentById(ResourceTable.Id_t_AutoWrap); + for (int i = 0;i < NUM_20;i++) { + Button button = (Button)findComponentById(resIds[i]); + int finalI = i; + button.setClickedListener(component -> setView(button.getText(), finalI,isMyAutoWrap)); + buttons[i] = button; + } + Button button = (Button)findComponentById(ResourceTable.Id_btn_AutoWrap); + button.setClickedListener(component -> { + isMyAutoWrap = !isMyAutoWrap; + setView(buttons[mPosition].getText(),mPosition,isMyAutoWrap); + }); + setView(buttons[mPosition].getText(),mPosition,isMyAutoWrap); + } + + private void setView(String style,int position,boolean isAutoWrap) { + mPosition = position; + textStyle.setText(style); + textAutoWrap.setText(String.valueOf(isAutoWrap)); + if (mIntent.getIntParam(Constants.SHOW_TYPE,1) == Constants.OTHER1_TYPE) { + Codeview.with(getApplicationContext()) + .setHtmlHeadContent("") + .withHtml("

h1 injected header

") + .withText("this text is always wrap inside pre tags") + .withCode(Constants.OTHER1_STRING) + .withHtml("

h1 header after code

") + .withHtml("
my html table
") + .setStyle(styles[position]) + .setLang(Settings.Lang.JAVASCRIPT) + .setAutoWrap(isAutoWrap) + .into(webView); + } else { + Codeview.with(getApplicationContext()) + .withCode(mIntent.getStringParam(Constants.SHOW_CODE)) + .setLang(mIntent.getStringParam(Constants.SHOW_LANG)) + .setStyle(styles[position]) + .setAutoWrap(isAutoWrap) + .into(webView); + } + } +} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ffc4254b06bca8a64e6ee04b39a44f49ce5f94e9 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CodeView" + }, + { + "name": "mainability_description", + "value": "Java_Phone_Empty Feature Ability" + }, + { + "name": "HelloWorld", + "value": "Hello World" + }, + { + "name": "showability_description", + "value": "Java_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_main.xml b/entry/src/main/resources/base/graphic/background_ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..c0c0a3df480fa387a452b9c40ca191cc918a3fc0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_main.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_ability_show.xml b/entry/src/main/resources/base/graphic/background_ability_show.xml new file mode 100644 index 0000000000000000000000000000000000000000..a002c2353e78af3a15235e00738328ff566bc085 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_ability_show.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_bt_color.xml b/entry/src/main/resources/base/graphic/background_bt_color.xml new file mode 100644 index 0000000000000000000000000000000000000000..86bb1b3969b1b480e45c076758b437aa1257a7d0 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_bt_color.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/graphic/background_text_color.xml b/entry/src/main/resources/base/graphic/background_text_color.xml new file mode 100644 index 0000000000000000000000000000000000000000..3bef41fd175930f55fb8fd0549eec107c5beb8c4 --- /dev/null +++ b/entry/src/main/resources/base/graphic/background_text_color.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml new file mode 100644 index 0000000000000000000000000000000000000000..5329d3c46d55383b7776cf488032b581efbe05a8 --- /dev/null +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -0,0 +1,173 @@ + + + +