From 9bf1f49fe83499ecddadfcecfd3b9726fd249863 Mon Sep 17 00:00:00 2001 From: liu luming Date: Mon, 5 Jul 2021 15:35:27 +0800 Subject: [PATCH 01/31] Create drawPixelMap --- drawPixelMap.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 drawPixelMap.md diff --git a/drawPixelMap.md b/drawPixelMap.md new file mode 100644 index 0000000..d33450a --- /dev/null +++ b/drawPixelMap.md @@ -0,0 +1,16 @@ +### **setBlendMode()** +>+ openharmony API: setBlendMode +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java + paint.setBlendMode(BlendMode.DST_IN); +``` + +### **drawPixelMapHolder()** +>+ openharmony API: drawPixelMapHolder(PixelMapHolder holder, float left, float top, Paint paint) +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java +canvas.drawPixelMapHolder(pixelMapHolder, 0, 0, paint); \ No newline at end of file -- Gitee From 9be45d39dde91a72580184c1359d7d119e69a828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=20=E7=BC=98?= Date: Mon, 5 Jul 2021 15:51:09 +0800 Subject: [PATCH 02/31] update meidia --- media/Visualizer.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 media/Visualizer.md diff --git a/media/Visualizer.md b/media/Visualizer.md new file mode 100644 index 0000000..ca04375 --- /dev/null +++ b/media/Visualizer.md @@ -0,0 +1,35 @@ +openharmony 替换类`ohos.media.audio.AudioWaver` + +创建`AudioWaver` +```java +AudioWaver audioWaver = new AudioWaver(sessionId, packageName); +``` + +### **setCaptureSize(int size)** +>+ openharmony API: ohos.media.audio.AudioWaver.setDataSize(int size); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **setDataCaptureListener(OnDataCaptureListener listener, int rate, boolean waveform, boolean fft)** +>+ openharmony API: ohos.media.audio.AudioWaver +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:拆分为两个方法,替换使用,使用方法如下: +```java +audioWaver.setWaveDataObserver(AudioWaver.WaveDataObserver observer, int interval); + +audioWaver.setFrequencyDataObserver(AudioWaver.FrequencyDataObserver observer, int interval); +``` + +### **setEnabled(boolean enabled)** +>+ openharmony API: ohos.media.audio.AudioWaver.setActivated(boolean activated); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **release()** +>+ openharmony API: ohos.media.audio.AudioWaver.release(); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 \ No newline at end of file -- Gitee From fc18806f6c21d9b392b68ac568a2ae2af35d7e19 Mon Sep 17 00:00:00 2001 From: liu luming Date: Mon, 5 Jul 2021 15:53:36 +0800 Subject: [PATCH 03/31] liuluming deleted page: drawPixelMap --- drawPixelMap.md | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 drawPixelMap.md diff --git a/drawPixelMap.md b/drawPixelMap.md deleted file mode 100644 index d33450a..0000000 --- a/drawPixelMap.md +++ /dev/null @@ -1,16 +0,0 @@ -### **setBlendMode()** ->+ openharmony API: setBlendMode ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java - paint.setBlendMode(BlendMode.DST_IN); -``` - -### **drawPixelMapHolder()** ->+ openharmony API: drawPixelMapHolder(PixelMapHolder holder, float left, float top, Paint paint) ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: -```java -canvas.drawPixelMapHolder(pixelMapHolder, 0, 0, paint); \ No newline at end of file -- Gitee From 6456e0f3d42eae880c8f1e1c2787472168ef00cf Mon Sep 17 00:00:00 2001 From: renpengfei Date: Mon, 5 Jul 2021 16:54:57 +0800 Subject: [PATCH 04/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- widget/LinearLayout.md | 116 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 widget/LinearLayout.md diff --git a/widget/LinearLayout.md b/widget/LinearLayout.md new file mode 100644 index 0000000..1b6612e --- /dev/null +++ b/widget/LinearLayout.md @@ -0,0 +1,116 @@ +### **LinearLayout** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案: + +* 原库实现 + +```xml + + + +``` + +```java + LinearLayout linearLayout = new LinearLayout(context); + linearLayout.setId(View.generateViewId()); + linearLayout.setOrientation(LinearLayout.VERTICAL); + linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); +``` + +* 替换实现 + +```xml + + + +``` +```java + DirectionalLayout directionalLayout = new DirectionalLayout(context); + directionalLayout.setId(component.getId()); + directionalLayout.setOrientation(DirectionalLayout.VERTICAL); + DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig( + DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT); + directionalLayout.setLayoutConfig(layoutConfig); +``` + +#### **setOrientation** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.setOrientation` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.setOrientation + + +#### **getOrientation** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.getOrientation` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.getOrientation + + +#### **setGravity** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.setAlignment` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.setAlignment + + +#### **getGravity** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.getAlignment` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.getAlignment + + +#### **setWeightSum** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.setTotalWeight` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.setTotalWeight + + +#### **getWeightSum** + +>+ openharmony class:`ohos.agp.components.DirectionalLayout.getTotalWeight` +>+ openharmony SDK版本:2.1.1.21上 +>+ IDE版本:2.2.0.200 +>+ 实现方案:DirectionalLayout.getTotalWeight -- Gitee From 704816ccc2427f6a72b0aa731eba1e1b2fb889e7 Mon Sep 17 00:00:00 2001 From: wangguan Date: Mon, 5 Jul 2021 17:16:38 +0800 Subject: [PATCH 05/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphics/LinearGradient.md | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 graphics/LinearGradient.md diff --git a/graphics/LinearGradient.md b/graphics/LinearGradient.md new file mode 100644 index 0000000..9788a20 --- /dev/null +++ b/graphics/LinearGradient.md @@ -0,0 +1,46 @@ +### **LinearGradient** + +* openharmony API: ohos.agp.render.LinearShader +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + + +原三方库: + +linearGradient线性渐变,会用到Paint的setShader,Shader 被称为着色器,在opengl中这个概念经常被用到,android中的shader主要用来给图像着色,Shader在绘制过程中会返回横向重要的颜色组,Paint设置shader后,绘制时会从shader中获取颜色,也就是需要shader告诉画笔某处的颜色值。 + + +``` java + mPaint = new Paint(); + mPaint.setColor(Color.BLUE); + mPaint.setAntiAlias(true); + mPaint.setStrokeWidth(3); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setTextSize(20); + + LinearGradient linearGradient = new LinearGradient(getWidth(),400,0,0,Color.RED,Color.GREEN, Shader.TileMode.CLAMP); + mPaint.setShader(linearGradient); + canvas.drawRect(0,0,getWidth(),400,mPaint); +``` + +openharmony: + +线性渐变绘制 + +``` java + public void drawCircle(Component component, Canvas canvas){ + Paint paint = new Paint(); + float centerX = 450; + float centerY = 450; + int R = 150; + // 渐变颜色 + Color[] colors = {Color.YELLOW,Color.RED}; + // 渐变开始和结束坐标 + Point[] points = new Point[]{new Point(centerX,centerY + R),new Point(centerX,centerY - R)}; + LinearShader linearShader = new LinearShader(points,null,colors, Shader.TileMode.CLAMP_TILEMODE); + // 设置线性渐变 + paint.setShader(linearShader,Paint.ShaderType.LINEAR_SHADER); + canvas.drawCircle(centerX,centerY,R,paint); + } +``` \ No newline at end of file -- Gitee From 962a6831763c0a4a3492096b91728d9bb1c02c52 Mon Sep 17 00:00:00 2001 From: litongzhou Date: Mon, 5 Jul 2021 17:24:09 +0800 Subject: [PATCH 06/31] =?UTF-8?q?=20=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webkit/WebSettings.md | 12 ++++++++++++ webkit/WebView.md | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 webkit/WebSettings.md create mode 100644 webkit/WebView.md diff --git a/webkit/WebSettings.md b/webkit/WebSettings.md new file mode 100644 index 0000000..6022496 --- /dev/null +++ b/webkit/WebSettings.md @@ -0,0 +1,12 @@ + +# setJavaScriptEnabled +* openharmony API: ohos.agp.components.webengine.WebConfig.setJavaScriptPermit +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 + +# setLoadsImagesAutomatically +* openharmony API: ohos.agp.components.webengine.WebConfig.setLoadsImagesPermit +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 \ No newline at end of file diff --git a/webkit/WebView.md b/webkit/WebView.md new file mode 100644 index 0000000..c87f55c --- /dev/null +++ b/webkit/WebView.md @@ -0,0 +1,27 @@ + +# setWebChromeClient +* openharmony API: ohos.agp.components.webengine.WebView.setBrowserAgent +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 + +# WebChromeClient +* openharmony API: ohos.agp.components.webengine.BrowserAgent +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 + +# getSettings +* openharmony API: ohos.agp.components.webengine.WebView.getWebConfig +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 + + +# loadDataWithBaseURL +* openharmony API: ohos.agp.components.webengine.WebView.load +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案:直接替换 + + -- Gitee From 4f05c5b9227be369e41f83916bbe9c476c748b49 Mon Sep 17 00:00:00 2001 From: chentao Date: Mon, 5 Jul 2021 17:24:57 +0800 Subject: [PATCH 07/31] =?UTF-8?q?G2=E7=BB=84=E9=B8=BF=E8=92=99=E5=8C=96?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/Intent.md | 0 view/Display.md | 0 view/View.md | 42 +++++++++++++++++++++++++++++++- view/inflate.md | 10 ++++++++ widget/EditText.md | 54 ++++++++++++++++++++++++++++++++++++++++++ widget/LinearLayout.md | 5 ++++ widget/TextView.md | 43 +++++++++++++++++++++++++++++++++ widget/Toast.md | 11 +++++++++ 8 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 content/Intent.md create mode 100644 view/Display.md create mode 100644 view/inflate.md create mode 100644 widget/EditText.md create mode 100644 widget/LinearLayout.md create mode 100644 widget/TextView.md create mode 100644 widget/Toast.md diff --git a/content/Intent.md b/content/Intent.md new file mode 100644 index 0000000..e69de29 diff --git a/view/Display.md b/view/Display.md new file mode 100644 index 0000000..e69de29 diff --git a/view/View.md b/view/View.md index 48127a9..71a966a 100644 --- a/view/View.md +++ b/view/View.md @@ -69,4 +69,44 @@ >+ openharmony API: ohos.agp.components.Component.invalidate >+ openharmony SDK版本:2.1.0.17 >+ IDE版本:2.1.0.141 ->+ 实现方案:在onDraw()方法中调用直接invalidate()方法无效,需在asyncDispatch方法中调用,如下:getContext().getUITaskDispatcher().asyncDispatch(this::invalidate)。 \ No newline at end of file +>+ 实现方案:在onDraw()方法中调用直接invalidate()方法无效,需在asyncDispatch方法中调用,如下:getContext().getUITaskDispatcher().asyncDispatch(this::invalidate)。 + +### **beginTransaction()** + +>+ openharmony API: ohos.data.rdb.RdbStore.beginTransaction() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **endTransaction()** + +>+ openharmony API: ohos.data.rdb.RdbStore.endTransaction() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **markAsCommit()** + +>+ openharmony API: ohos.data.rdb.RdbStore.markAsCommit() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **executeSql(String var1)** + +>+ openharmony API: ohos.data.rdb.RdbStore.executeSql(String var1) +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **android.view.inflate** + +>+ openharmony API: ohos.agp.components.LayoutScatter +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +rootLayout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_styleable_layout, null, true); +``` + diff --git a/view/inflate.md b/view/inflate.md new file mode 100644 index 0000000..930b24e --- /dev/null +++ b/view/inflate.md @@ -0,0 +1,10 @@ +### **android.view.inflate** + +>+ openharmony API: ohos.agp.components.LayoutScatter +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +rootLayout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_styleable_layout, null, true); +``` \ No newline at end of file diff --git a/widget/EditText.md b/widget/EditText.md new file mode 100644 index 0000000..4747884 --- /dev/null +++ b/widget/EditText.md @@ -0,0 +1,54 @@ +## onSelectionChanged(int selStart, int selEnd) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: 自定义TextField,在方法内容实现接口setCursorChangedListener(TextField.CursorChangedListener listener) + +``` java +setCursorChangedListener(new CursorChangedListener() { + @Override + public void onCursorChange(TextField textField, int selStart, int selEnd) { + int tempStart = selStart; + int tempEnd = selEnd; + } + }); +``` + +## setOnEditorActionListener(OnEditorActionListener l) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: + +步骤一: 自定义TextField,在方法内部重写方法setEditorActionListener(Text.EditorActionListener listener) + +步骤二: 实现EditorActionListener +``` java + private final EditorActionListener onEditorActionListener = new EditorActionListener() { + @Override + public boolean onTextEditorAction(int actionId) { + switch (actionId) { + default: + return true; + } + } + }; + + setEditorActionListener(onEditorActionListener); +``` + +## addTextChangedListener(TextWatcher watcher) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: 自定义TextField,实现接口addTextObserver(Text.TextObserver observer) + +``` java + @Override + public void onTextUpdated(String str, int start, int before, int count) { + // str 当前最新文本 + // start 旧文本起始位置 + // before 旧文本长度 + // count 文本长度的变化 + } +``` \ No newline at end of file diff --git a/widget/LinearLayout.md b/widget/LinearLayout.md new file mode 100644 index 0000000..4fea7ff --- /dev/null +++ b/widget/LinearLayout.md @@ -0,0 +1,5 @@ +### **android.widget.LinearLayout** +>+ openharmony API: ohos.agp.components. DirectionalLayout +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:直接替换 \ No newline at end of file diff --git a/widget/TextView.md b/widget/TextView.md new file mode 100644 index 0000000..be91ccf --- /dev/null +++ b/widget/TextView.md @@ -0,0 +1,43 @@ +### **android.widget.TextView.setTypeface** +>+ openharmony API: ohos.agp.text.Font +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:暂无直接替换,需要自己去写,使用方法如下: +```java + private Font createFontBuild(Context context, String name) { + ResourceManager resManager = context.getResourceManager(); + RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/" + name); + Resource resource = null; + try { + resource = rawFileEntry.openRawFile(); + } catch (IOException e) { + e.printStackTrace(); + } + StringBuffer fileName = new StringBuffer(name); + File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(file); + int index; + byte[] bytes = new byte[Constants.BYTE]; + while ((index = resource.read(bytes)) != Constants.DEFAULT_NUMBER) { + outputStream.write(bytes, 0, index); + outputStream.flush(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + resource.close(); + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + Font.Builder builder = new Font.Builder(file); + return builder.build(); + } +``` \ No newline at end of file diff --git a/widget/Toast.md b/widget/Toast.md new file mode 100644 index 0000000..911065a --- /dev/null +++ b/widget/Toast.md @@ -0,0 +1,11 @@ +### **android.widget.Toast** + +>+ openharmony API: ohos.agp.window.dialog. ToastDialog; +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +ToastDialog toast = new ToastDialog(getContext()); +toast.show(); +``` \ No newline at end of file -- Gitee From 02c7097db50d83e071c6a9b220211696cec18ada Mon Sep 17 00:00:00 2001 From: chentao Date: Mon, 5 Jul 2021 17:27:19 +0800 Subject: [PATCH 08/31] =?UTF-8?q?Display=20=E6=B7=BB=E5=8A=A0=E9=B8=BF?= =?UTF-8?q?=E8=92=99=E5=8C=96=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/Display.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/view/Display.md b/view/Display.md index e69de29..43e4f5d 100644 --- a/view/Display.md +++ b/view/Display.md @@ -0,0 +1,18 @@ +## android.view.Display + +>+ openharmony API: ohos.agp.window.service.Display +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可用于替换其中的获取屏幕分辨率信息 + +```java +//获取屏幕分辨率 +Optional display = DisplayManager.getInstance().getDefaultDisplay(getContext()); +Point pt = new Point(); +display.get().getSize(pt); + +//获取屏幕的高 +double height = display.get().getAttributes().height; +//获取屏幕的宽 +double width = display.get().getAttributes().width; +``` \ No newline at end of file -- Gitee From 9dae30b76327beab37a63adaadbd52f9b9b15cf3 Mon Sep 17 00:00:00 2001 From: 17351781990 <827990754@qq.com> Date: Mon, 5 Jul 2021 17:33:29 +0800 Subject: [PATCH 09/31] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=91=EF=BC=9A=E6=8E=A5=E5=8F=A3=E9=B8=BF=E8=92=99?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/WebView.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 view/WebView.md diff --git a/view/WebView.md b/view/WebView.md new file mode 100644 index 0000000..17a5332 --- /dev/null +++ b/view/WebView.md @@ -0,0 +1,17 @@ +### **load** +>+ openharmony API: ohos.agp.components.webengine.WebView +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:直接替换 + +### **getWebConfig** +>+ openharmony API: ohos.agp.components.webengine.WebView +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:直接替换 + +### **setBrowserAgent** +>+ openharmony API: ohos.agp.components.webengine.WebView +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:直接替换 -- Gitee From 610e92b455ca8f860625c52602a9ab0dea8c164b Mon Sep 17 00:00:00 2001 From: YuJianZhang Date: Mon, 5 Jul 2021 17:56:31 +0800 Subject: [PATCH 10/31] yujianzhang deleted page: Intent --- content/Intent.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 content/Intent.md diff --git a/content/Intent.md b/content/Intent.md deleted file mode 100644 index e69de29..0000000 -- Gitee From c67861ebb57f84586ff89ba51292d8278d8f5cfd Mon Sep 17 00:00:00 2001 From: wangguan Date: Mon, 5 Jul 2021 18:01:48 +0800 Subject: [PATCH 11/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphics/Carema.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 graphics/Carema.md diff --git a/graphics/Carema.md b/graphics/Carema.md new file mode 100644 index 0000000..da4c75d --- /dev/null +++ b/graphics/Carema.md @@ -0,0 +1,24 @@ +### **Carema** + +* openharmony API: ohos.agp.render.ThreeDimView +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案:3D效果转换 + +openharmony: + +``` java + public void onDraw(Component component,Canvas canvas){ + Paint paint = new Paint(); + paint.setColor(Color.BLUE); + ThreeDimView threeDimView = new ThreeDimView(); + Matrix cameraMatrix = new Matrix(); + threeDimView.rotateY(100); + threeDimView.rotateX(100); + threeDimView.getMatrix(cameraMatrix); + cameraMatrix.preTranslate(-300,-300); + cameraMatrix.postTranslate(-300,-300); + canvas.concat(cameraMatrix); + canvas.drawRect(150,150,450,450,paint); + } +``` \ No newline at end of file -- Gitee From 884cfceaa38b9f850238598316568b214281894e Mon Sep 17 00:00:00 2001 From: jjy188013 Date: Mon, 5 Jul 2021 18:05:15 +0800 Subject: [PATCH 12/31] =?UTF-8?q?pageSlider=E7=9A=84=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/ViewPager.md | 71 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/view/ViewPager.md b/view/ViewPager.md index 0255410..29c68d1 100644 --- a/view/ViewPager.md +++ b/view/ViewPager.md @@ -1,13 +1,72 @@ - + # PageSlider * openharmony API: ohos.agp.components.PageSlider * openharmony SDK版本:2.1.1.21 * IDE版本:2.1.0.501 * 实现方案: -openharmony: + **1. 组件初始化和设置数据** + + 原三方库: + + bannerView = (PageSlider)findComponentById(ResourceTable.Id_page_slider); + bannerView.setAdapter(new TabPagerProvider(this, titles)) + + openharmony: + + bannerView = (PageSlider)findComponentById(ResourceTable.Id_page_slider); + bannerView.setProvider(new TabPagerProvider(this, titles)) + + **2. 组件设置滑动监听** + + 原三方库: + + verticalViewPager.addOnPageChangeListener(pageChangeListener); + public interface OnPageChangeListener { + void onPageScrolled(int var1, float var2, int var3); + void onPageSelected(int var1); + void onPageScrollStateChanged(int var1); + } + openharmony: + + pageSlider.addPageChangedListener(this); + public interface PageChangedListener { + void onPageSliding(int var1, float var2, int var3); + void onPageSlideStateChanged(int var1); + void onPageChosen(int var1); + } + + **3. 组件滑动时操作子view** + + 原三方库: -``` java - bannerView = (PageSlider)findComponentById(ResourceTable.Id_page_slider); - bannerView.setProvider(new TabPagerProvider(this, titles)) -``` \ No newline at end of file + setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) + class VerticalPageTransformer implements ViewPager.PageTransformer { + @Override + public void transformPage(View view, float position) { + // view是pageSlider的根view + } + openharmony: + + 第一步:保存pageSlider所有子view + public class VerticalIntroPagerAdapter extends PageSliderProvider { + public VerticalIntroPagerAdapter(Context context, List datas) { + this.context = context; + this.datas = datas; + pageComonent = new ArrayList<>(); + LinkedHashMap pageComonents = new LinkedHashMap(); + } + @Override + public Object createPageInContainer(ComponentContainer componentContainer, int i) { + if (!pageComonents.containsValue(component)) { + pageComonents.put(i, component); + } + } + } + 第一步:在需要操作子view的地方调用 + Image image = (Image) adapter.pageComonents.get(currentPage) + .findComponentById(ResourceTable.Id_sliderImage); + + + + \ No newline at end of file -- Gitee From 2e2ee008e11275ca30e4d4110d448a53421d2caf Mon Sep 17 00:00:00 2001 From: wangguan Date: Mon, 5 Jul 2021 18:13:56 +0800 Subject: [PATCH 13/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- widget/Toast.md | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 widget/Toast.md diff --git a/widget/Toast.md b/widget/Toast.md new file mode 100644 index 0000000..fcd4360 --- /dev/null +++ b/widget/Toast.md @@ -0,0 +1,58 @@ +### **Toast** + +* openharmony API: ohos.agp.window.dialog.ToastDialog +* openharmony SDK版本:2.1.1.21 +* IDE版本:2.1.0.501 +* 实现方案: + + +原三方库: +简易的消息提示框,当视图显示给用户,在应用程序中显示为浮动 + +``` java + Toast.makeText(this, "测试",Toast.LENGTH_SHORT); +``` + +openharmony: + +openharmony系统中通过ToastDialog实现与android显示效果类似: + +``` java + public static void showCustomText(Context context, String toastStr) { + Text textComponent = new Text(context); + textComponent.setText(toastStr); + + //设置间距为10vp + textComponent.setPadding(60, 40, 60, 40); + textComponent.setTextColor(Color.WHITE); + textComponent.setWidth(500); + textComponent.setTextAlignment(TextAlignment.CENTER); + textComponent.setTextSize(40); + + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setShape(ShapeElement.RECTANGLE); + shapeElement.setCornerRadius(50); + //设置背景半透明 + shapeElement.setRgbColor(RgbColor.fromArgbInt(Color.argb(180, 11, 11, 11))); + textComponent.setBackground(shapeElement); + //设置文字允许多行 + textComponent.setMultipleLine(true); + + DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(); + layoutConfig.width = ComponentContainer.LayoutConfig.MATCH_CONTENT; + layoutConfig.height = ComponentContainer.LayoutConfig.MATCH_CONTENT; + layoutConfig.alignment = LayoutAlignment.CENTER; + layoutConfig.setMarginBottom(220); + textComponent.setLayoutConfig(layoutConfig); + + ToastDialog toastDialog = new ToastDialog(context).setDuration(500).setComponent(textComponent).setAlignment(LayoutAlignment.BOTTOM); + //设置弹框背景透明 + toastDialog.setTransparent(true); + toastDialog.show(); + } +``` + +调用方式 +``` java + Utils.showCustomText(getContext(), "测试"); +``` \ No newline at end of file -- Gitee From 05c6e7424f863a30bb300f1aa55592c83991c61e Mon Sep 17 00:00:00 2001 From: YuJianZhang Date: Mon, 5 Jul 2021 18:26:22 +0800 Subject: [PATCH 14/31] yujianzhang deleted page: TextView --- widget/TextView.md | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 widget/TextView.md diff --git a/widget/TextView.md b/widget/TextView.md deleted file mode 100644 index be91ccf..0000000 --- a/widget/TextView.md +++ /dev/null @@ -1,43 +0,0 @@ -### **android.widget.TextView.setTypeface** ->+ openharmony API: ohos.agp.text.Font ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:暂无直接替换,需要自己去写,使用方法如下: -```java - private Font createFontBuild(Context context, String name) { - ResourceManager resManager = context.getResourceManager(); - RawFileEntry rawFileEntry = resManager.getRawFileEntry("resources/rawfile/" + name); - Resource resource = null; - try { - resource = rawFileEntry.openRawFile(); - } catch (IOException e) { - e.printStackTrace(); - } - StringBuffer fileName = new StringBuffer(name); - File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), fileName.toString()); - OutputStream outputStream = null; - try { - outputStream = new FileOutputStream(file); - int index; - byte[] bytes = new byte[Constants.BYTE]; - while ((index = resource.read(bytes)) != Constants.DEFAULT_NUMBER) { - outputStream.write(bytes, 0, index); - outputStream.flush(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - resource.close(); - outputStream.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - Font.Builder builder = new Font.Builder(file); - return builder.build(); - } -``` \ No newline at end of file -- Gitee From 75e1f604838e0e7cb523c715783448791ba5996b Mon Sep 17 00:00:00 2001 From: yujianzhang Date: Mon, 5 Jul 2021 18:39:15 +0800 Subject: [PATCH 15/31] shezhen add ohos api doc --- media/Visualizer.md | 35 +++++++++++++++++++++++++++++ view/Display.md | 18 +++++++++++++++ view/inflate.md | 10 +++++++++ widget/EditText.md | 54 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 media/Visualizer.md create mode 100644 view/Display.md create mode 100644 view/inflate.md create mode 100644 widget/EditText.md diff --git a/media/Visualizer.md b/media/Visualizer.md new file mode 100644 index 0000000..ca04375 --- /dev/null +++ b/media/Visualizer.md @@ -0,0 +1,35 @@ +openharmony 替换类`ohos.media.audio.AudioWaver` + +创建`AudioWaver` +```java +AudioWaver audioWaver = new AudioWaver(sessionId, packageName); +``` + +### **setCaptureSize(int size)** +>+ openharmony API: ohos.media.audio.AudioWaver.setDataSize(int size); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **setDataCaptureListener(OnDataCaptureListener listener, int rate, boolean waveform, boolean fft)** +>+ openharmony API: ohos.media.audio.AudioWaver +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:拆分为两个方法,替换使用,使用方法如下: +```java +audioWaver.setWaveDataObserver(AudioWaver.WaveDataObserver observer, int interval); + +audioWaver.setFrequencyDataObserver(AudioWaver.FrequencyDataObserver observer, int interval); +``` + +### **setEnabled(boolean enabled)** +>+ openharmony API: ohos.media.audio.AudioWaver.setActivated(boolean activated); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 + +### **release()** +>+ openharmony API: ohos.media.audio.AudioWaver.release(); +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用 \ No newline at end of file diff --git a/view/Display.md b/view/Display.md new file mode 100644 index 0000000..43e4f5d --- /dev/null +++ b/view/Display.md @@ -0,0 +1,18 @@ +## android.view.Display + +>+ openharmony API: ohos.agp.window.service.Display +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:可用于替换其中的获取屏幕分辨率信息 + +```java +//获取屏幕分辨率 +Optional display = DisplayManager.getInstance().getDefaultDisplay(getContext()); +Point pt = new Point(); +display.get().getSize(pt); + +//获取屏幕的高 +double height = display.get().getAttributes().height; +//获取屏幕的宽 +double width = display.get().getAttributes().width; +``` \ No newline at end of file diff --git a/view/inflate.md b/view/inflate.md new file mode 100644 index 0000000..930b24e --- /dev/null +++ b/view/inflate.md @@ -0,0 +1,10 @@ +### **android.view.inflate** + +>+ openharmony API: ohos.agp.components.LayoutScatter +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +rootLayout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_styleable_layout, null, true); +``` \ No newline at end of file diff --git a/widget/EditText.md b/widget/EditText.md new file mode 100644 index 0000000..4747884 --- /dev/null +++ b/widget/EditText.md @@ -0,0 +1,54 @@ +## onSelectionChanged(int selStart, int selEnd) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: 自定义TextField,在方法内容实现接口setCursorChangedListener(TextField.CursorChangedListener listener) + +``` java +setCursorChangedListener(new CursorChangedListener() { + @Override + public void onCursorChange(TextField textField, int selStart, int selEnd) { + int tempStart = selStart; + int tempEnd = selEnd; + } + }); +``` + +## setOnEditorActionListener(OnEditorActionListener l) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: + +步骤一: 自定义TextField,在方法内部重写方法setEditorActionListener(Text.EditorActionListener listener) + +步骤二: 实现EditorActionListener +``` java + private final EditorActionListener onEditorActionListener = new EditorActionListener() { + @Override + public boolean onTextEditorAction(int actionId) { + switch (actionId) { + default: + return true; + } + } + }; + + setEditorActionListener(onEditorActionListener); +``` + +## addTextChangedListener(TextWatcher watcher) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: 自定义TextField,实现接口addTextObserver(Text.TextObserver observer) + +``` java + @Override + public void onTextUpdated(String str, int start, int before, int count) { + // str 当前最新文本 + // start 旧文本起始位置 + // before 旧文本长度 + // count 文本长度的变化 + } +``` \ No newline at end of file -- Gitee From d5cf9892ff249fcc624455f58779ec07f99c3fed Mon Sep 17 00:00:00 2001 From: JiangJun <2680104782@qq.com> Date: Mon, 5 Jul 2021 19:00:00 +0800 Subject: [PATCH 16/31] md --- app/Ability-onBackPressed.md | 16 ++++++++++++++++ view/EditText.md | 35 +++++++++++++++++++++++++++++++++++ view/ViewGroup.md | 24 ++++++++++++++++++++++++ view/onMeasure.md | 20 ++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 app/Ability-onBackPressed.md create mode 100644 view/EditText.md create mode 100644 view/ViewGroup.md create mode 100644 view/onMeasure.md diff --git a/app/Ability-onBackPressed.md b/app/Ability-onBackPressed.md new file mode 100644 index 0000000..61a13af --- /dev/null +++ b/app/Ability-onBackPressed.md @@ -0,0 +1,16 @@ +### onBackPressed返回键监听 + +>* openharmony class:`ohos.aafwk.ability.Ability` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +在Ability中重写onBackPressed方法 + +```java +@Override + protected void onBackPressed() { + super.onBackPressed(); + } +``` + diff --git a/view/EditText.md b/view/EditText.md new file mode 100644 index 0000000..0aeb7b9 --- /dev/null +++ b/view/EditText.md @@ -0,0 +1,35 @@ +### onTextUpdated输入监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +调用addTextObserver方法 + +```java +@Override + public void onTextUpdated(String s, int i, int i1, int i2) { + + } +``` + +### onCursorChange光标改变监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要继承TextField,在类中调用setCursorChangedListener,i为开始的下标,i1为结束的下标 + +```java +setCursorChangedListener(new CursorChangedListener() { + @Override + public void onCursorChange(TextField textField, int i, int i1) { + startPosition = i; + endPosition = i1; + } + }); +``` + diff --git a/view/ViewGroup.md b/view/ViewGroup.md new file mode 100644 index 0000000..05c38cc --- /dev/null +++ b/view/ViewGroup.md @@ -0,0 +1,24 @@ +### onArrange布局定位监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要继承ComponentContainer,实现ArrangeListener接口,并重写onArrange方法 + +```java +@Override + public boolean onArrange(int l, int t, int r, int b) { + return false; + } +``` + +如需在Component中更改布局位置,可调用arrange方法 + +```java +public void arrange(int left, int top, int width, int height) { + throw new RuntimeException("Stub!"); + } +``` + diff --git a/view/onMeasure.md b/view/onMeasure.md new file mode 100644 index 0000000..ac9d417 --- /dev/null +++ b/view/onMeasure.md @@ -0,0 +1,20 @@ +### onEstimateSize布局测量监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要实现EstimateSizeListener接口并重写onEstimateSize方法,并调用setEstimateSizeListener方法,对于提供的w和h需要调用EstimateSpec.getSize()提取出准确值 + +```java +setEstimateSizeListener(this::onEstimateSize); + + @Override + public boolean onEstimateSize(int w, int h) { + int width = EstimateSpec.getSize(w); + int height = EstimateSpec.getSize(h); + return false; + } +``` + -- Gitee From 65b58e9e5374755ebee36fe6bc16ee2d9d3feb82 Mon Sep 17 00:00:00 2001 From: ZYF949 <446962864@qq.com> Date: Mon, 5 Jul 2021 19:02:03 +0800 Subject: [PATCH 17/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Ability-onBackPressed.md | 16 ++++++++++++++++ view/EditText.md | 35 +++++++++++++++++++++++++++++++++++ view/ViewGroup.md | 24 ++++++++++++++++++++++++ view/onMeasure.md | 20 ++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 app/Ability-onBackPressed.md create mode 100644 view/EditText.md create mode 100644 view/ViewGroup.md create mode 100644 view/onMeasure.md diff --git a/app/Ability-onBackPressed.md b/app/Ability-onBackPressed.md new file mode 100644 index 0000000..61a13af --- /dev/null +++ b/app/Ability-onBackPressed.md @@ -0,0 +1,16 @@ +### onBackPressed返回键监听 + +>* openharmony class:`ohos.aafwk.ability.Ability` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +在Ability中重写onBackPressed方法 + +```java +@Override + protected void onBackPressed() { + super.onBackPressed(); + } +``` + diff --git a/view/EditText.md b/view/EditText.md new file mode 100644 index 0000000..0aeb7b9 --- /dev/null +++ b/view/EditText.md @@ -0,0 +1,35 @@ +### onTextUpdated输入监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +调用addTextObserver方法 + +```java +@Override + public void onTextUpdated(String s, int i, int i1, int i2) { + + } +``` + +### onCursorChange光标改变监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要继承TextField,在类中调用setCursorChangedListener,i为开始的下标,i1为结束的下标 + +```java +setCursorChangedListener(new CursorChangedListener() { + @Override + public void onCursorChange(TextField textField, int i, int i1) { + startPosition = i; + endPosition = i1; + } + }); +``` + diff --git a/view/ViewGroup.md b/view/ViewGroup.md new file mode 100644 index 0000000..05c38cc --- /dev/null +++ b/view/ViewGroup.md @@ -0,0 +1,24 @@ +### onArrange布局定位监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要继承ComponentContainer,实现ArrangeListener接口,并重写onArrange方法 + +```java +@Override + public boolean onArrange(int l, int t, int r, int b) { + return false; + } +``` + +如需在Component中更改布局位置,可调用arrange方法 + +```java +public void arrange(int left, int top, int width, int height) { + throw new RuntimeException("Stub!"); + } +``` + diff --git a/view/onMeasure.md b/view/onMeasure.md new file mode 100644 index 0000000..ac9d417 --- /dev/null +++ b/view/onMeasure.md @@ -0,0 +1,20 @@ +### onEstimateSize布局测量监听 + +>* openharmony class:`ohos.agp.components` +>* openharmony SDK版本:2.1.1.21 +>* IDE版本:2.1.0.501 +>* 实现方案:直接替换 + +需要实现EstimateSizeListener接口并重写onEstimateSize方法,并调用setEstimateSizeListener方法,对于提供的w和h需要调用EstimateSpec.getSize()提取出准确值 + +```java +setEstimateSizeListener(this::onEstimateSize); + + @Override + public boolean onEstimateSize(int w, int h) { + int width = EstimateSpec.getSize(w); + int height = EstimateSpec.getSize(h); + return false; + } +``` + -- Gitee From 6b53e817ea0b9ce62e8a96f4d7d94107ddef2aa8 Mon Sep 17 00:00:00 2001 From: gaojianming108 Date: Mon, 5 Jul 2021 19:10:19 +0800 Subject: [PATCH 18/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphics/Canvas.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/graphics/Canvas.md b/graphics/Canvas.md index 11246dd..88a2bdc 100644 --- a/graphics/Canvas.md +++ b/graphics/Canvas.md @@ -66,4 +66,17 @@ Canvas canvas = new Canvas(new Texture(pixelMap)); >+ openharmony API: `ohos.agp.render.Canvas` >+ openharmony SDK版本:2.1.0.17 >+ IDE版本:2.1.0.141 ->+ 实现方案:使用`drawLine(Point point1 ,Point point2,Paint)`方法 \ No newline at end of file +>+ 实现方案:使用`drawLine(Point point1 ,Point point2,Paint)`方法 + +### **drawRoundRect(RectF rect, float rx, float ry, Paint paint)** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:使用`drawRoundRect(RectFloat rect, float radiusX, float radiusY, Paint paint)`方法 + +### **drawText(String text, float x, float y, Paint paint)** +>+ openharmony API: `ohos.agp.render.Canvas` +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:使用`drawText(Paint paint, String text, float x, float y)`方法 + -- Gitee From ff88c52120b8299fa367103d0ecb563f9feb9c80 Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 5 Jul 2021 19:12:03 +0800 Subject: [PATCH 19/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20addTextObserver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/addTextObserver.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 view/addTextObserver.md diff --git a/view/addTextObserver.md b/view/addTextObserver.md new file mode 100644 index 0000000..db219a0 --- /dev/null +++ b/view/addTextObserver.md @@ -0,0 +1,5 @@ +addTextChangedListener +>+ openharmony API: ohos.agp.components.Text.addTextObserver +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:直接替换 \ No newline at end of file -- Gitee From 16239fc74514468c21d9f37564969bf5c3afd7d4 Mon Sep 17 00:00:00 2001 From: TFStudy <3202410880@qq.com> Date: Mon, 5 Jul 2021 19:33:38 +0800 Subject: [PATCH 20/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/EditText.md | 11 +++++++++++ view/addTextObserver.md | 5 ----- 2 files changed, 11 insertions(+), 5 deletions(-) delete mode 100644 view/addTextObserver.md diff --git a/view/EditText.md b/view/EditText.md index 0aeb7b9..7a49975 100644 --- a/view/EditText.md +++ b/view/EditText.md @@ -32,4 +32,15 @@ setCursorChangedListener(new CursorChangedListener() { } }); ``` +### setCursorElement设置光标颜色 +```java + ShapeElement shapeElement = new ShapeElement(); + shapeElement.setShape(ShapeElement.LINE); + shapeElement.setRgbColors(new RgbColor[]{RgbColor.fromArgbInt( + Color.rgb(156, 39, 176)), + RgbColor.fromArgbInt(Color.rgb(33, 150, 243))}); + shapeElement.setGradientOrientation(ShapeElement.Orientation.TOP_TO_BOTTOM); + shapeElement.setStroke(0, RgbColor.fromArgbInt(Color.rgb(255, 0, 0))); + setCursorElement(shapeElement); +``` \ No newline at end of file diff --git a/view/addTextObserver.md b/view/addTextObserver.md deleted file mode 100644 index db219a0..0000000 --- a/view/addTextObserver.md +++ /dev/null @@ -1,5 +0,0 @@ -addTextChangedListener ->+ openharmony API: ohos.agp.components.Text.addTextObserver ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:直接替换 \ No newline at end of file -- Gitee From 3360aa04375d5df10c6570f7e4416921df4677c6 Mon Sep 17 00:00:00 2001 From: "229144497@qq.com" Date: Mon, 5 Jul 2021 19:40:04 +0800 Subject: [PATCH 21/31] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9B=BF=E6=8D=A2API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphics/Path.md | 42 +++++++++++++++++++++++++++++++++++++++--- os/DelayUpdateUi.md | 15 +++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 os/DelayUpdateUi.md diff --git a/graphics/Path.md b/graphics/Path.md index 7b803e7..f16bb2b 100644 --- a/graphics/Path.md +++ b/graphics/Path.md @@ -6,7 +6,6 @@ ```java Path path = new Path(); path.moveTo(100f, 100f); - ``` ### **lineTo** @@ -17,7 +16,6 @@ path.moveTo(100f, 100f); ```java Path path = new Path(); path.lineTo(200f, 200f); - ``` ### **setLastPoint** @@ -30,7 +28,6 @@ Path path = new Path(); path.setLastPoint(100f, 100f); // 或者 path.setLastPoint(new Point(100f, 100f)); - ``` ### **addRect** @@ -41,5 +38,44 @@ path.setLastPoint(new Point(100f, 100f)); ```java Path path = new Path(); path.addRect(new RectFloat(0f, 0f, 100f, 100f), Path.Direction.CLOCK_WISE); +``` +### **addCircle** +>+ openharmony API: ohos.agp.render.Path.addCircle +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.addCircle(x, y, 1f, Path.Direction.CLOCK_WISE); ``` + +### **rLineTo** +>+ openharmony API: ohos.agp.render.Path.rLineTo +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.rLineTo(x, 0); +``` + +### **cubicTo** +>+ openharmony API: ohos.agp.render.Path.cubicTo +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.cubicTo(x1, y1, x2, y2, x, y) +``` + +### **rMoveTo** +>+ openharmony API: ohos.agp.render.Path.rMoveTo +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +Path path = new Path(); +path.rMoveTo(x, y); +``` \ No newline at end of file diff --git a/os/DelayUpdateUi.md b/os/DelayUpdateUi.md new file mode 100644 index 0000000..57034c7 --- /dev/null +++ b/os/DelayUpdateUi.md @@ -0,0 +1,15 @@ +### **延时更新UI** +>+ ohos.app.dispatcher.TaskDispatcher#delayDispatch +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案如下 +``` java +getContext().getUITaskDispatcher().delayDispatch(new Runnable() { + @Override + public void run() { + //TODO + } + }, 10); +``` + + -- Gitee From 0a558d36f54876e4cf18f70d0d0efa102317a897 Mon Sep 17 00:00:00 2001 From: miaoqiulong Date: Mon, 5 Jul 2021 20:06:22 +0800 Subject: [PATCH 22/31] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=B8=BF=E8=92=99=E5=8C=96=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VibratorAgent.md | 15 ++++ app/AbilitySlice.md | 12 ++++ app/ability.md | 48 +++++++++++++ content/doc(simple_search_view).md | 108 +++++++++++++++++++++++++++++ view/LayoutConfig.md | 19 +++++ 5 files changed, 202 insertions(+) create mode 100644 VibratorAgent.md create mode 100644 app/AbilitySlice.md create mode 100644 app/ability.md create mode 100644 content/doc(simple_search_view).md create mode 100644 view/LayoutConfig.md diff --git a/VibratorAgent.md b/VibratorAgent.md new file mode 100644 index 0000000..e34a247 --- /dev/null +++ b/VibratorAgent.md @@ -0,0 +1,15 @@ +### **VibratorAgent** +>+ openharmony API:ohos.vibrator.agent.VibratorAgent +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:自行实现,使用方法如下: + + + +```java + +mVibrator = new VibratorAgent(); +mVibrator.startOnce(5); + + +``` \ No newline at end of file diff --git a/app/AbilitySlice.md b/app/AbilitySlice.md new file mode 100644 index 0000000..29c3aab --- /dev/null +++ b/app/AbilitySlice.md @@ -0,0 +1,12 @@ +### **Activity** +View view1=(DirectionalLayout)findViewById(R.id.view1) +>+ openharmony API:ohos.aafwk.ability.AbilitySlice +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:自行实现,使用方法如下: + + + +```java +Component component1 = (DirectionalLayout) findComponentById(ResourceTable.Id_component1); +``` \ No newline at end of file diff --git a/app/ability.md b/app/ability.md new file mode 100644 index 0000000..3ab4979 --- /dev/null +++ b/app/ability.md @@ -0,0 +1,48 @@ +## onConfigurationChanged(Configuration newConfig) +>+ openharmony API:ohos.aafwk.ability.onOrientationChanged +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:在ability中,重写onOrientationChanged方法,监听横竖屏切换。须在config.json ability节点申明 "configChanges": [ + "orientation" + ] + 及 "orientation": "unspecified", +``` java +@Override + protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) { + super.onOrientationChanged(displayOrientation); + initPages(); + if(displayOrientation.ordinal() == AbilityInfo.DisplayOrientation.PORTRAIT.ordinal()){ + //do something + }else if(displayOrientation.ordinal() == AbilityInfo.DisplayOrientation.LANDSCAPE.ordinal()){ + //do something + } + } +``` + +## startScroll(int startX, int startY, int dx, int dy) +>+ openharmony API:ohos.agp.components.ScrollHelper +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:ScrollHelper实例化对象,控制弹性滑动 +``` java + ScrollHelper scroller = new ScrollHelper(); + scroller.startScroll(int startX, int startY, int dx, int dy); + //handler post线程更新位置数据 + handler.postSyncTask(runnable); + private Runnable runnable = new Runnable() { + @Override + public void run() { + if (!scroller.isFinished()) { + scroller.updateScroll(); + scrollOffsetY = scroller.getCurrValue(AXIS_Y); + //do something + //handler.postTask(this, 16, EventHandler.Priority.HIGH); + //invalidate(); + } + } + }; + +``` + + + diff --git a/content/doc(simple_search_view).md b/content/doc(simple_search_view).md new file mode 100644 index 0000000..6e64a7a --- /dev/null +++ b/content/doc(simple_search_view).md @@ -0,0 +1,108 @@ +### **Intent** +>+ openharmony API: ohos.aafwk.content.Intent +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java + Intent secondIntent = new Intent(); +Operation operation = new Intent.OperationBuilder() + .withDeviceId("") + .withBundleName("it.neokree.materialnavigationdrawer") + .withAbilityName("it.neokree.example.Settings") + .build(); + secondIntent.setOperation(operation); +``` + +### **Configuration** +>+ openharmony API: ohos.global.configuration.Configuration +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 +``` +``` + +### **Bundle** +>+ openharmony API: ohos.aafwk.content.IntentParams +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java +// 直接构建 +IntentParams intentParams = new IntentParams(); +// 设置键值对 +intentParams.setParam("num",100); +``` + +### **Fragment** +>+ openharmony API: ohos.aafwk.ability.fraction.Fraction +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java + FractionScheduler ft = getFractionManager().startFractionScheduler(); + Fraction fraction = new Fraction(); + ft.replace(ResourceTable.Id_frame_container, (fraction).submit(); +``` +### **FragmentManager** +>+ openharmony API: ohos.aafwk.ability.fraction.FragmentManager +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 +``` +``` +### **FragmentPagerAdapter** +>+ openharmony API: ohos.agp.components.PageSliderProvider +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 +``` +``` +### **ViewPager** +>+ openharmony API: ohos.agp.components.PageSlider +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:直接替换 +``` +``` +### **TabLayout** +>+ openharmony API: ohos.agp.components.TabList +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:替换使用,使用方法如下: +```java + TabList mTabList = (TabList) findComponentById(ResourceTable.Id_tab_list); + TabList.Tab tabItem1 = mTabList.new Tab(getContext()); + tabItem1.setText("TAB 1"); + mTabList.addTab(tabItem1, true); + + TabList.Tab tabItem2 = mTabList.new Tab(getContext()); + tabItem2.setText("TAB 2"); + mTabList.addTab(tabItem2); + + TabList.Tab tabItem3 = mTabList.new Tab(getContext()); + tabItem3.setText("TAB 3"); + mTabList.addTab(tabItem3); +``` +### **Menu** +>+ openharmony API: 暂无 +>+ openharmony SDK版本:2.1.1.21 以上 +>+ IDE版本:2.1.0.501 +>+ 实现方案:暂无直接替换,通过PopupDialog代替实现 +```java + Component component = LayoutScatter.getInstance(getContext()) + .parse(ResourceTable.Layout_menu_pop_layout, null, false); + PopupDialog popupDialog = new PopupDialog(getContext(), null); + popupDialog.setCustomComponent(component); + popupDialog.setDialogListener(() -> { + popupDialog.destroy(); + return false; + }); + component.setClickedListener(component2 -> { + popupDialog.destroy(); + }); + + int[] position = mSlBar.getLocationOnScreen(); + int x = mSlBar.getWidth() - component.getWidth(); + int y = position[1]; + popupDialog.showOnCertainPosition(LayoutAlignment.TOP, x, y); +``` \ No newline at end of file diff --git a/view/LayoutConfig.md b/view/LayoutConfig.md new file mode 100644 index 0000000..24de6c6 --- /dev/null +++ b/view/LayoutConfig.md @@ -0,0 +1,19 @@ +### **VibratorAgent** +>+ openharmony API:ohos.agp.components.DirectionalLayout.LayoutConfig +>+ openharmony SDK版本:2.1.1.21 +>+ IDE版本:2.2.0.200 +>+ 实现方案:自行实现,使用方法如下: + + + +```java +component001 = (DirectionalLayout) findComponentById(ResourceTable.Id_component001); +DirectionalLayout.LayoutConfig config = new DirectionalLayout.LayoutConfig(); +config.width = AttrHelper.vp2px(20,abilitySlice.getContext()); +config.height = AttrHelper.vp2px(20,abilitySlice.getContext()); +config.setMarginLeft(AttrHelper.vp2px(10,abilitySlice.getContext())); +component001.setLayoutConfig(config); + + + +``` \ No newline at end of file -- Gitee From b7642a46828d7811329b06c28ebf3d6488471842 Mon Sep 17 00:00:00 2001 From: chentao Date: Mon, 5 Jul 2021 20:14:53 +0800 Subject: [PATCH 23/31] =?UTF-8?q?sqlite/SQLiteDatabase=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=B8=BF=E8=92=99=E5=8C=96=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database/sqlite/SQLiteDatabase.md | 34 +++++++++++++++++++++---- view/View.md | 41 ++++++++++--------------------- view/inflate.md | 10 -------- 3 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 view/inflate.md diff --git a/database/sqlite/SQLiteDatabase.md b/database/sqlite/SQLiteDatabase.md index 72bfaf2..c503384 100644 --- a/database/sqlite/SQLiteDatabase.md +++ b/database/sqlite/SQLiteDatabase.md @@ -18,11 +18,7 @@ RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); } database.markAsCommit(); ``` - - - - - + #### **update()** >+ openharmony API: `ohos.data.rdb.RdbStore.update()` >+ openharmony SDK版本:2.1.0.17 以上 @@ -58,3 +54,31 @@ RawRdbPredicates rawRdbPredicates = new RawRdbPredicates(getTableName()); database.delete(rdbPredicates); database.markAsCommit(); ``` + +### **beginTransaction()** + +>+ openharmony API: ohos.data.rdb.RdbStore.beginTransaction() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **endTransaction()** + +>+ openharmony API: ohos.data.rdb.RdbStore.endTransaction() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **markAsCommit()** + +>+ openharmony API: ohos.data.rdb.RdbStore.markAsCommit() +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 + +### **executeSql(String var1)** + +>+ openharmony API: ohos.data.rdb.RdbStore.executeSql(String var1) +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用。 \ No newline at end of file diff --git a/view/View.md b/view/View.md index 71a966a..f6bb0d3 100644 --- a/view/View.md +++ b/view/View.md @@ -71,34 +71,6 @@ >+ IDE版本:2.1.0.141 >+ 实现方案:在onDraw()方法中调用直接invalidate()方法无效,需在asyncDispatch方法中调用,如下:getContext().getUITaskDispatcher().asyncDispatch(this::invalidate)。 -### **beginTransaction()** - ->+ openharmony API: ohos.data.rdb.RdbStore.beginTransaction() ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用。 - -### **endTransaction()** - ->+ openharmony API: ohos.data.rdb.RdbStore.endTransaction() ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用。 - -### **markAsCommit()** - ->+ openharmony API: ohos.data.rdb.RdbStore.markAsCommit() ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用。 - -### **executeSql(String var1)** - ->+ openharmony API: ohos.data.rdb.RdbStore.executeSql(String var1) ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用。 - ### **android.view.inflate** >+ openharmony API: ohos.agp.components.LayoutScatter @@ -110,3 +82,16 @@ rootLayout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_styleable_layout, null, true); ``` +## setOnFocusChangeListener(OnFocusChangeListener l) +>+ openharmony API:ohos.agp.components.Component +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案:自定义Component,在方法内实现接口setFocusChangedListener(Component.FocusChangedListener listener) + +``` java + setFocusChangedListener(new FocusChangedListener() { + @Override + public void onFocusChange(Component component, boolean isHasFocus) { + } +}); +``` \ No newline at end of file diff --git a/view/inflate.md b/view/inflate.md deleted file mode 100644 index 930b24e..0000000 --- a/view/inflate.md +++ /dev/null @@ -1,10 +0,0 @@ -### **android.view.inflate** - ->+ openharmony API: ohos.agp.components.LayoutScatter ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:替换使用,使用方法如下: - -```java -rootLayout = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_styleable_layout, null, true); -``` \ No newline at end of file -- Gitee From 68ef4bf3ac2a943f78a73404720376f91479f8af Mon Sep 17 00:00:00 2001 From: chentao Date: Mon, 5 Jul 2021 20:15:54 +0800 Subject: [PATCH 24/31] =?UTF-8?q?content/Intent.md=20widget/TextView.md=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=B8=BF=E8=92=99=E5=8C=96=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/Intent.md | 14 ++++++++++++++ widget/TextView.md | 15 +++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 content/Intent.md create mode 100644 widget/TextView.md diff --git a/content/Intent.md b/content/Intent.md new file mode 100644 index 0000000..bbeec8b --- /dev/null +++ b/content/Intent.md @@ -0,0 +1,14 @@ +## android.content.Intent + +>+ openharmony API: ohos.aafwk.content.Intent +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: + +```java +Intent intent = new Intent(); +intent.setAction("android.intent.action.VIEW"); +Uri uri = Uri.parse("https://gitee.com/chinasoft_ohos/Conductor"); +intent.setUri(uri); +component.getContext().startAbility(intent,1); +``` diff --git a/widget/TextView.md b/widget/TextView.md new file mode 100644 index 0000000..d7fc4cb --- /dev/null +++ b/widget/TextView.md @@ -0,0 +1,15 @@ +## onSelectionChanged(int selStart, int selEnd) +>+ openharmony API:ohos.agp.components.TextField +>+ openharmony SDK版本:2.1.0.303 +>+ IDE版本:2.1.0.303 +>+ 实现方案: 自定义TextField,在方法内容实现接口setCursorChangedListener(TextField.CursorChangedListener listener) + +``` java +setCursorChangedListener(new CursorChangedListener() { + @Override + public void onCursorChange(TextField textField, int selStart, int selEnd) { + int tempStart = selStart; + int tempEnd = selEnd; + } + }); +``` -- Gitee From 16aee6d0e29e986172b4caba972d07d8d2872673 Mon Sep 17 00:00:00 2001 From: yujianzhang Date: Tue, 6 Jul 2021 09:02:52 +0800 Subject: [PATCH 25/31] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E8=8B=A5=E5=B9=B2?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VibratorAgent.md | 15 ---- app/AbilitySlice.md | 12 ---- app/ability.md | 48 ------------- content/doc(simple_search_view).md | 108 ----------------------------- view/LayoutConfig.md | 19 ----- 5 files changed, 202 deletions(-) delete mode 100644 VibratorAgent.md delete mode 100644 app/AbilitySlice.md delete mode 100644 app/ability.md delete mode 100644 content/doc(simple_search_view).md delete mode 100644 view/LayoutConfig.md diff --git a/VibratorAgent.md b/VibratorAgent.md deleted file mode 100644 index e34a247..0000000 --- a/VibratorAgent.md +++ /dev/null @@ -1,15 +0,0 @@ -### **VibratorAgent** ->+ openharmony API:ohos.vibrator.agent.VibratorAgent ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.2.0.200 ->+ 实现方案:自行实现,使用方法如下: - - - -```java - -mVibrator = new VibratorAgent(); -mVibrator.startOnce(5); - - -``` \ No newline at end of file diff --git a/app/AbilitySlice.md b/app/AbilitySlice.md deleted file mode 100644 index 29c3aab..0000000 --- a/app/AbilitySlice.md +++ /dev/null @@ -1,12 +0,0 @@ -### **Activity** -View view1=(DirectionalLayout)findViewById(R.id.view1) ->+ openharmony API:ohos.aafwk.ability.AbilitySlice ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.2.0.200 ->+ 实现方案:自行实现,使用方法如下: - - - -```java -Component component1 = (DirectionalLayout) findComponentById(ResourceTable.Id_component1); -``` \ No newline at end of file diff --git a/app/ability.md b/app/ability.md deleted file mode 100644 index 3ab4979..0000000 --- a/app/ability.md +++ /dev/null @@ -1,48 +0,0 @@ -## onConfigurationChanged(Configuration newConfig) ->+ openharmony API:ohos.aafwk.ability.onOrientationChanged ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:在ability中,重写onOrientationChanged方法,监听横竖屏切换。须在config.json ability节点申明 "configChanges": [ - "orientation" - ] - 及 "orientation": "unspecified", -``` java -@Override - protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) { - super.onOrientationChanged(displayOrientation); - initPages(); - if(displayOrientation.ordinal() == AbilityInfo.DisplayOrientation.PORTRAIT.ordinal()){ - //do something - }else if(displayOrientation.ordinal() == AbilityInfo.DisplayOrientation.LANDSCAPE.ordinal()){ - //do something - } - } -``` - -## startScroll(int startX, int startY, int dx, int dy) ->+ openharmony API:ohos.agp.components.ScrollHelper ->+ openharmony SDK版本:2.1.0.17 ->+ IDE版本:2.1.0.141 ->+ 实现方案:ScrollHelper实例化对象,控制弹性滑动 -``` java - ScrollHelper scroller = new ScrollHelper(); - scroller.startScroll(int startX, int startY, int dx, int dy); - //handler post线程更新位置数据 - handler.postSyncTask(runnable); - private Runnable runnable = new Runnable() { - @Override - public void run() { - if (!scroller.isFinished()) { - scroller.updateScroll(); - scrollOffsetY = scroller.getCurrValue(AXIS_Y); - //do something - //handler.postTask(this, 16, EventHandler.Priority.HIGH); - //invalidate(); - } - } - }; - -``` - - - diff --git a/content/doc(simple_search_view).md b/content/doc(simple_search_view).md deleted file mode 100644 index 6e64a7a..0000000 --- a/content/doc(simple_search_view).md +++ /dev/null @@ -1,108 +0,0 @@ -### **Intent** ->+ openharmony API: ohos.aafwk.content.Intent ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java - Intent secondIntent = new Intent(); -Operation operation = new Intent.OperationBuilder() - .withDeviceId("") - .withBundleName("it.neokree.materialnavigationdrawer") - .withAbilityName("it.neokree.example.Settings") - .build(); - secondIntent.setOperation(operation); -``` - -### **Configuration** ->+ openharmony API: ohos.global.configuration.Configuration ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 -``` -``` - -### **Bundle** ->+ openharmony API: ohos.aafwk.content.IntentParams ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java -// 直接构建 -IntentParams intentParams = new IntentParams(); -// 设置键值对 -intentParams.setParam("num",100); -``` - -### **Fragment** ->+ openharmony API: ohos.aafwk.ability.fraction.Fraction ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java - FractionScheduler ft = getFractionManager().startFractionScheduler(); - Fraction fraction = new Fraction(); - ft.replace(ResourceTable.Id_frame_container, (fraction).submit(); -``` -### **FragmentManager** ->+ openharmony API: ohos.aafwk.ability.fraction.FragmentManager ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 -``` -``` -### **FragmentPagerAdapter** ->+ openharmony API: ohos.agp.components.PageSliderProvider ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 -``` -``` -### **ViewPager** ->+ openharmony API: ohos.agp.components.PageSlider ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:直接替换 -``` -``` -### **TabLayout** ->+ openharmony API: ohos.agp.components.TabList ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:替换使用,使用方法如下: -```java - TabList mTabList = (TabList) findComponentById(ResourceTable.Id_tab_list); - TabList.Tab tabItem1 = mTabList.new Tab(getContext()); - tabItem1.setText("TAB 1"); - mTabList.addTab(tabItem1, true); - - TabList.Tab tabItem2 = mTabList.new Tab(getContext()); - tabItem2.setText("TAB 2"); - mTabList.addTab(tabItem2); - - TabList.Tab tabItem3 = mTabList.new Tab(getContext()); - tabItem3.setText("TAB 3"); - mTabList.addTab(tabItem3); -``` -### **Menu** ->+ openharmony API: 暂无 ->+ openharmony SDK版本:2.1.1.21 以上 ->+ IDE版本:2.1.0.501 ->+ 实现方案:暂无直接替换,通过PopupDialog代替实现 -```java - Component component = LayoutScatter.getInstance(getContext()) - .parse(ResourceTable.Layout_menu_pop_layout, null, false); - PopupDialog popupDialog = new PopupDialog(getContext(), null); - popupDialog.setCustomComponent(component); - popupDialog.setDialogListener(() -> { - popupDialog.destroy(); - return false; - }); - component.setClickedListener(component2 -> { - popupDialog.destroy(); - }); - - int[] position = mSlBar.getLocationOnScreen(); - int x = mSlBar.getWidth() - component.getWidth(); - int y = position[1]; - popupDialog.showOnCertainPosition(LayoutAlignment.TOP, x, y); -``` \ No newline at end of file diff --git a/view/LayoutConfig.md b/view/LayoutConfig.md deleted file mode 100644 index 24de6c6..0000000 --- a/view/LayoutConfig.md +++ /dev/null @@ -1,19 +0,0 @@ -### **VibratorAgent** ->+ openharmony API:ohos.agp.components.DirectionalLayout.LayoutConfig ->+ openharmony SDK版本:2.1.1.21 ->+ IDE版本:2.2.0.200 ->+ 实现方案:自行实现,使用方法如下: - - - -```java -component001 = (DirectionalLayout) findComponentById(ResourceTable.Id_component001); -DirectionalLayout.LayoutConfig config = new DirectionalLayout.LayoutConfig(); -config.width = AttrHelper.vp2px(20,abilitySlice.getContext()); -config.height = AttrHelper.vp2px(20,abilitySlice.getContext()); -config.setMarginLeft(AttrHelper.vp2px(10,abilitySlice.getContext())); -component001.setLayoutConfig(config); - - - -``` \ No newline at end of file -- Gitee From e631133955604053a831cb94de67a537babde84a Mon Sep 17 00:00:00 2001 From: gaojianming108 Date: Tue, 6 Jul 2021 10:34:16 +0800 Subject: [PATCH 26/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphics/drawable/Drawable.md | 11 ++++++++++- graphics/drawable/LayerDrawable.md | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 graphics/drawable/LayerDrawable.md diff --git a/graphics/drawable/Drawable.md b/graphics/drawable/Drawable.md index f787825..d8e01d6 100644 --- a/graphics/drawable/Drawable.md +++ b/graphics/drawable/Drawable.md @@ -1,4 +1,13 @@ -### **draw(Canvas canvas)** +### **Drawable()** +>+ openharmony API: ohos.agp.components.element.ShapeElement +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java + ShapeElement shapeElement = new ShapeElement(); +``` + +### **draw(Canvas canvas)** >+ openharmony API: ohos.agp.components.element.Element.drawToCanvas >+ openharmony SDK版本:2.1.0.17 >+ IDE版本:2.1.0.141 diff --git a/graphics/drawable/LayerDrawable.md b/graphics/drawable/LayerDrawable.md new file mode 100644 index 0000000..53b5276 --- /dev/null +++ b/graphics/drawable/LayerDrawable.md @@ -0,0 +1,8 @@ +### **LayerDrawable()** +>+ openharmony API: ohos.agp.components.element.ShapeElement +>+ openharmony SDK版本:2.1.0.17 +>+ IDE版本:2.1.0.141 +>+ 实现方案:替换使用,使用方法如下: +```java + ShapeElement shapeElement = new ShapeElement(); +``` -- Gitee From ca63cfdffefa34198a8e68618065b9c4c3b79e84 Mon Sep 17 00:00:00 2001 From: yujianzhang Date: Fri, 9 Jul 2021 11:58:29 +0800 Subject: [PATCH 27/31] =?UTF-8?q?add=20Sensor=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=BF=90=E5=8A=A8=E7=B1=BB=E4=BC=A0=E6=84=9F=E5=99=A8=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardware/Sensor/Sensor.md | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hardware/Sensor/Sensor.md diff --git a/hardware/Sensor/Sensor.md b/hardware/Sensor/Sensor.md new file mode 100644 index 0000000..c941c58 --- /dev/null +++ b/hardware/Sensor/Sensor.md @@ -0,0 +1,64 @@ + +# sensor +* openharmony API: ohos.sensor.agent.CategoryMotionAgent +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案: + + +原三方库: + +获取传感器 +``` java + //获取SensorManager实例 + SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + //获取Sensor实例 + Sensor sensor = sensorManager.getDefaultSensor(TYPE_ACCELEROMETER) + //注册监听事件 + sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL); +``` + +openharmony: + +获取运动类传感器 +``` java + private CategoryOrientationAgent categoryOrientationAgent = new CategoryOrientationAgent(); + private ICategoryOrientationDataCallback orientationDataCallback; + private CategoryOrientation orientationSensor; + + // 创建传感器回调对象。 + orientationDataCallback = new ICategoryOrientationDataCallback() { + @Override + public void onSensorDataModified(CategoryOrientationData categoryOrientationData) { + // 对接收的categoryOrientationData传感器数据对象解析和使用 + int dim = categoryOrientationData.getSensorDataDim(); // 获取传感器的维度信息 + float degree = categoryOrientationData.getValues()[0]; // 获取方向类传感器的第一维数据 + float[] rotationMatrix = new float[matrix_length]; + CategoryOrientationData.getDeviceRotationMatrix(rotationMatrix, categoryOrientationData.values); // 根据旋转矢量传感器的数据获得旋转矩阵 + float[] rotationAngle = new float[rotationVectorLength]; + rotationAngle = CategoryOrientationData.getDeviceOrientation(rotationMatrix, rotationAngle); // 根据计算出来的旋转矩阵获取设备的方向 + } + + @Override + public void onAccuracyDataModified(CategoryOrientation categoryOrientation, int index) { + // 使用变化的精度 + } + + @Override + public void onCommandCompleted(CategoryOrientation categoryOrientation) { + // 传感器执行命令回调 + } + }; + + // 获取传感器对象,并订阅传感器数据 + orientationSensor = categoryOrientationAgent.getSingleSensor( + CategoryOrientation.SENSOR_TYPE_ORIENTATION); + if (orientationSensor != null) { + categoryOrientationAgent.setSensorDataCallback( + orientationDataCallback, orientationSensor, INTERVAL); + } + + // 取消订阅传感器数据 + categoryOrientationAgent.releaseSensorDataCallback( + orientationDataCallback, orientationSensor); +``` \ No newline at end of file -- Gitee From 2c6270a61241520695d50840c1529bcc478fee07 Mon Sep 17 00:00:00 2001 From: shetaotao Date: Fri, 9 Jul 2021 17:08:50 +0800 Subject: [PATCH 28/31] =?UTF-8?q?=E6=B7=BB=E5=8A=A0wifi=E5=92=8C=E8=BD=AF?= =?UTF-8?q?=E9=94=AE=E7=9B=98=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- net/Wifi.md | 55 +++++++++++++++++++++++++++++++++++++++++++++ view/inputmethod.md | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 net/Wifi.md create mode 100644 view/inputmethod.md diff --git a/net/Wifi.md b/net/Wifi.md new file mode 100644 index 0000000..686df7d --- /dev/null +++ b/net/Wifi.md @@ -0,0 +1,55 @@ +### **获取Wifi扫描信息** +>+ openharmony API:ohos.wifi +>+ openharmony SDK版本:SDK6 +>+ IDE版本:2.2 Beta1 +>+ 实现方案: + +``` +public static List getWifiScanResults(Context context) { + // 获取WLAN管理对象 + WifiDevice wifiDevice = WifiDevice.getInstance(context); + // 调用获取WLAN开关状态接口,若WLAN打开,则返回true,否则返回false + boolean isWifiActive = wifiDevice.isWifiActive(); + if (!isWifiActive) { + return null; + } else { + // 调用WLAN扫描接口 + boolean isScanSuccess = wifiDevice.scan(); + if (isScanSuccess) { + // 调用获取扫描结果 + return wifiDevice.getScanInfoList(); + } else { + return null; + } + } +} +``` + +### **获取Wifi连接信息** + +>+ openharmony API:ohos.wifi +>+ openharmony SDK版本:SDK6 +>+ IDE版本:2.2 Beta1 +>+ 实现方案: + +``` +public static Optional getWifiConnectionInfo(Context context) { + // 获取WLAN管理对象 + WifiDevice wifiDevice = WifiDevice.getInstance(context); + // 调用WLAN连接状态接口,确定当前设备是否连接WLAN + boolean isConnected = wifiDevice.isConnected(); + if (isConnected) { + // 获取WLAN连接信息 + return wifiDevice.getLinkedInfo(); + // Optional linkedInfo = wifiDevice.getLinkedInfo(); + // // 获取连接信息中的SSID + // String ssid = linkedInfo.get().getSsid(); + // // 获取WLAN的IP信息 + // Optional ipInfo = wifiDevice.getIpInfo(); + // // 获取IP信息中的IP地址与网关 + // int ipAddress = ipInfo.get().getIpAddress(); + // int gateway = ipInfo.get().getGateway(); + } + return null; +} +``` \ No newline at end of file diff --git a/view/inputmethod.md b/view/inputmethod.md new file mode 100644 index 0000000..09124fa --- /dev/null +++ b/view/inputmethod.md @@ -0,0 +1,43 @@ +### **唤醒软键盘** + +>+ openharmony API:invoke +>+ openharmony SDK版本:SDK6 +>+ IDE版本:2.2 Beta1 +>+ 实现方案: + +``` +public static boolean showSoftInput() { + try { + Class inputClass = Class.forName("ohos.miscservices.inputmethod.InputMethodController"); + Method method = inputClass.getMethod("getInstance"); + Object object = method.invoke(new Object[]{}); + Method startInput = inputClass.getMethod("startInput", int.class, boolean.class); + return (boolean) startInput.invoke(object, 1, true); + } catch (Exception e) { + e.printStackTrace(); + } + return false; +} +``` + +### **关闭软键盘** + +>+ openharmony API:invoke +>+ openharmony SDK版本:SDK6 +>+ IDE版本:2.2 Beta1 +>+ 实现方案: + +``` +public static boolean hideSoftInput() { + try { + Class inputClass = Class.forName("ohos.miscservices.inputmethod.InputMethodController"); + Method method = inputClass.getMethod("getInstance"); + Object object = method.invoke(new Object[]{}); + Method stopInput = inputClass.getMethod("stopInput", int.class); + return (boolean) stopInput.invoke(object, 1); + } catch (Exception e) { + e.printStackTrace(); + } + return false; +} +``` \ No newline at end of file -- Gitee From 9c3ad88f8306965bf859d5fc6834702202bcf063 Mon Sep 17 00:00:00 2001 From: xujianhong Date: Wed, 14 Jul 2021 10:53:38 +0800 Subject: [PATCH 29/31] =?UTF-8?q?WindowManager=20addView=20=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E4=BA=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/WindowManager.md | 49 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/view/WindowManager.md b/view/WindowManager.md index a1a5d88..8078b04 100644 --- a/view/WindowManager.md +++ b/view/WindowManager.md @@ -1,4 +1,4 @@ -### **addView** +### **addView** >+ openharmony API: ohos.agp.window.dialog.PopupDialog.show >+ openharmony SDK版本:2.1.0.17 >+ IDE版本:2.1.0.141 @@ -23,4 +23,49 @@ popupDialog.setBackColor(new Color(0x00000000)); popupDialog.show(); ``` ->+ 补充说明:当前SDK版本:2.1.0.17不生效,后续支持。 \ No newline at end of file +>+ 补充说明:当前SDK版本:2.1.0.17不生效,后续支持。 + + + +### 方案二 + +### addView + +>+ openharmony API: ohos.agp.window.service.WindowManager +>+ openharmony SDK版本:6 +>+ IDE版本:2.2.0.200 +>+ 实现方案:自行实现,实现方法如下 + +``` java +WindowManager windowManager = WindowManager.getInstance(); +/** + * component 需要加载的布局自定义Component + * context 当前上下文 + * typeFlag 窗口的类型 例如:WindowManager.LayoutConfig.MOD_APPLICATION_OVERLAY + */ +Window window = WindowManager.getInstance().addComponent(ComponentContainer component, Context context, int typeFlag); +//窗口是否可以拖动 +window.setMovable(true); +//设置是否启用透明度。 +window.setTransparent(true); +WindowManager.LayoutConfig layoutConfig1 = new WindowManager.LayoutConfig(); +//表示窗口的宽度。 +layoutConfig1.width = 100; +//表示窗口的高度。 +layoutConfig1.height = 100; +//对其方式 +layoutConfig1.alignment = LayoutAlignment.CENTER; +//指示窗口的各种标志。 +layoutConfig1.flags = WindowManager.LayoutConfig.INPUT_ADJUST_PAN; +// 表示窗口的 X 坐标。 +layoutConfig1.x = 0; +// 表示窗口的 y 坐标。 +layoutConfig1.y = 0; +//设置移动窗口的边界。 +window.setBoundRect(Rect rect); +window.setLayoutConfig(layoutConfig1); + +//关闭当前window。 +windowManager.destroyWindow(window); +``` + -- Gitee From 3037c7391b10694b177a497ee0b02f6b1ad94416 Mon Sep 17 00:00:00 2001 From: xujianhong Date: Wed, 14 Jul 2021 11:04:31 +0800 Subject: [PATCH 30/31] =?UTF-8?q?WindowManager=20addView=20=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E4=BA=8C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/WindowManager.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/WindowManager.md b/view/WindowManager.md index 8078b04..7571908 100644 --- a/view/WindowManager.md +++ b/view/WindowManager.md @@ -65,7 +65,7 @@ layoutConfig1.y = 0; window.setBoundRect(Rect rect); window.setLayoutConfig(layoutConfig1); -//关闭当前window。 +//关闭当前window windowManager.destroyWindow(window); ``` -- Gitee From ce75c3c5c9a33d843ff4b5c3b8075691a3e9a095 Mon Sep 17 00:00:00 2001 From: wangguan Date: Wed, 14 Jul 2021 15:05:42 +0800 Subject: [PATCH 31/31] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A7=BB=E6=A4=8D?= =?UTF-8?q?=E5=8C=96=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/WindowManager.LayoutParams.md | 47 ++++++++++++++++++ widget/TextSwitcher.md | 78 ++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 view/WindowManager.LayoutParams.md create mode 100644 widget/TextSwitcher.md diff --git a/view/WindowManager.LayoutParams.md b/view/WindowManager.LayoutParams.md new file mode 100644 index 0000000..8c5f229 --- /dev/null +++ b/view/WindowManager.LayoutParams.md @@ -0,0 +1,47 @@ + +# WindowManager +* openharmony API: ohos.agp.window.service.WindowManager +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案: + +原三方库: +android.view.WindowManager.LayoutParams 隐藏与显示标题栏与状态栏 + +**设置状态栏** +``` java +getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) //显示状态栏 +getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) //隐藏状态栏 +``` +**设置标题栏** +``` java +mActivity.getActionBar().show()//显示标题栏 +mActivity.getActionBar().hide()//隐藏标题栏 +``` + +openharmony: +隐藏与显示标题栏与状态栏 +**设置状态栏** +``` java +//显示状态栏 +WindowManager.getInstance().getTopWindow().get().setStatusBarVisibility(Component.VISIBLE) +//隐藏状态栏 +WindowManager.getInstance().getTopWindow().get().setStatusBarVisibility(Component.INVISIBLE) +``` +**设置标题栏** + 因openharmony未找到获取标题栏的方法,隐藏系统的标题栏,需要在config中进行配置 +``` java +// 隐藏标题栏 +"metaData": { + "customizeData": [ + { + "name": "hwc-theme", + "value": "androidhwext:style/Theme.Emui.NoTitleBar", + "extra": "" + } + ] +} +``` + + + diff --git a/widget/TextSwitcher.md b/widget/TextSwitcher.md new file mode 100644 index 0000000..bfe66f4 --- /dev/null +++ b/widget/TextSwitcher.md @@ -0,0 +1,78 @@ + +# TextSwitcher +* openharmony API: ohos.agp.components.PageFlipper +* openharmony SDK版本:2.2.0.1 +* IDE版本:2.2.0.200 +* 实现方案: + + +**原三方库:** + +`android.widget.ViewSwitcher`仅包含类型为 的子项的特殊化`android.widget.TextView`。TextSwitcher 可用于为屏幕上的标签设置动画。每当`setText(java.lang.CharSequence)`被调用时,TextSwitcher 都会将当前文本动画化,并将新文本动画化。 + +``` java + textSwitcher = new TextSwitcher(context); + textSwitcher.addView(createViewForTextSwitcher(context)); + textSwitcher.addView(createViewForTextSwitcher(context)); +``` +``` java +public void update(int newPosition, int oldPosition, int totalElements) { + textView.setText(" / " + totalElements); + int offset = (int) (textSwitcher.getHeight() * 0.75); + int duration = 250; + if (newPosition > oldPosition) { + textSwitcher.setInAnimation(createPositionAnimation(-offset, 0, 0f, 1f, duration)); + textSwitcher.setOutAnimation(createPositionAnimation(0, offset, 1f, 0f, duration)); + } else if (oldPosition > newPosition) { + textSwitcher.setInAnimation(createPositionAnimation(offset, 0, 0f, 1f, duration)); + textSwitcher.setOutAnimation(createPositionAnimation(0, -offset, 1f, 0f, duration)); + } + textSwitcher.setText(String.valueOf(newPosition + 1)); +} +``` + +``` java +/** + * Sets the text of the next view and switches to the next view. This can + * be used to animate the old text out and animate the next text in. + * + * @param text the new text to display + */ +public void setText(CharSequence text) { + final TextView t = (TextView) getNextView(); + t.setText(text); + showNext(); +} +``` + + +**openharmony:** + +当PageFlipper在切换过程中为两个或多个子组件设置动画时,页面翻转器提供翻转效果。它还可以在预定的时间段内自动翻阅添加的子组件。 +**PageFlipper中调用setText之前需要先执行showNext进行切换,再获取当前Text组件后进行赋值** +``` java + private PageFlipper textSwitcher; + ... + textSwitcher = new PageFlipper(context); + textSwitcher.addComponent(createViewForTextSwitcher(context)); + textSwitcher.addComponent(createViewForTextSwitcher(context)); + addComponent(textSwitcher, new LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT, + ComponentContainer.LayoutConfig.MATCH_CONTENT)); +``` + +``` java +public void update(int newPosition, int oldPosition, int totalElements) { + textView.setText(" / " + totalElements); + int offset = (int)(textSwitcher.getHeight()*0.75f); + if (newPosition > oldPosition) { + textSwitcher.setIncomingAnimation(createPositionAnimation(-offset, 0, 0f, 1f, DURATION)); + textSwitcher.setOutgoingAnimation(createPositionAnimation(0, offset, 1f, 0f, DURATION)); + } else if (oldPosition > newPosition) { + textSwitcher.setIncomingAnimation(createPositionAnimation(offset, 0, 0f, 1f, DURATION)); + textSwitcher.setOutgoingAnimation(createPositionAnimation(0, -offset, 1f, 0f, DURATION)); + } + textSwitcher.showNext(); + Text text = (Text) textSwitcher.getCurrentComponent(); + text.setText(String.valueOf(newPosition + 1)); +} +``` \ No newline at end of file -- Gitee