diff --git a/app/Ability-onBackPressed.md b/app/Ability-onBackPressed.md new file mode 100644 index 0000000000000000000000000000000000000000..61a13aff871afbb0a2592c34e26c236074e35846 --- /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/content/Intent.md b/content/Intent.md new file mode 100644 index 0000000000000000000000000000000000000000..bbeec8b8440897c8be602da0155e73bba53a80b8 --- /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/database/sqlite/SQLiteDatabase.md b/database/sqlite/SQLiteDatabase.md index 72bfaf2289269e53537ae738f07a939098235615..c503384d50b0134772cffcbc62fce38e38328dc9 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/graphics/Canvas.md b/graphics/Canvas.md index 11246dda1f341e1bc69769c8bcc18cbef8c73045..88a2bdc9f8c14a2ca68114a813f2b83c51b4d780 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)`方法 + diff --git a/graphics/Carema.md b/graphics/Carema.md new file mode 100644 index 0000000000000000000000000000000000000000..da4c75d686b892a137a3824505df9e44e4e8d587 --- /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 diff --git a/graphics/LinearGradient.md b/graphics/LinearGradient.md new file mode 100644 index 0000000000000000000000000000000000000000..9788a20f933f61cde94efcab3053db4beb212a10 --- /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 diff --git a/graphics/Path.md b/graphics/Path.md index 7b803e7cb1e9454047bec82aa88648f912b89c03..f16bb2b62f59208b98fd6cc4d38a33d3240c7d93 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/graphics/drawable/Drawable.md b/graphics/drawable/Drawable.md index f7878252a6f3f124a332123e20ea11c741a0f201..d8e01d646465bd1ced45393c0270c832b8dc2c44 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 0000000000000000000000000000000000000000..53b52765d1ec4a7529079df8f32b9bd20dc7b30b --- /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(); +``` diff --git a/hardware/Sensor/Sensor.md b/hardware/Sensor/Sensor.md new file mode 100644 index 0000000000000000000000000000000000000000..c941c586ca0ba4ef8577d51b9e7605c80cfa1c1a --- /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 diff --git a/media/Visualizer.md b/media/Visualizer.md new file mode 100644 index 0000000000000000000000000000000000000000..ca04375022f8c4c5b2c5f5302858f9f819bde3b7 --- /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/net/Wifi.md b/net/Wifi.md new file mode 100644 index 0000000000000000000000000000000000000000..686df7df37d6d1368ed64c8bffd311e2923d8d98 --- /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/os/DelayUpdateUi.md b/os/DelayUpdateUi.md new file mode 100644 index 0000000000000000000000000000000000000000..57034c7478b95a337c6be184bade821c4b9037db --- /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); +``` + + diff --git a/view/Display.md b/view/Display.md new file mode 100644 index 0000000000000000000000000000000000000000..43e4f5d04536041d339020f9c199a615c4c5de83 --- /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/EditText.md b/view/EditText.md new file mode 100644 index 0000000000000000000000000000000000000000..7a49975e80af9468d3988da3715bd887d405c6b3 --- /dev/null +++ b/view/EditText.md @@ -0,0 +1,46 @@ +### 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; + } + }); +``` +### 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/View.md b/view/View.md index 48127a92a4768d7ee2339fc03462f1cc8ff600ca..f6bb0d3de044a3315fc15f486b14fa79af9a58d3 100644 --- a/view/View.md +++ b/view/View.md @@ -69,4 +69,29 @@ >+ 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)。 + +### **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); +``` + +## 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/ViewGroup.md b/view/ViewGroup.md new file mode 100644 index 0000000000000000000000000000000000000000..05c38cc7bb651881c4a660c1fd8e4e5635ae6cfb --- /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/ViewPager.md b/view/ViewPager.md index 0255410ff8fe206dec378f334d8bbee2a0d6fbd1..29c68d1929c493ce40bad469f0369e98cd72e919 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 diff --git a/view/WebView.md b/view/WebView.md new file mode 100644 index 0000000000000000000000000000000000000000..17a5332c0a8047be42d8f48a1b81f0c55ec3aefd --- /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 +>+ 实现方案:直接替换 diff --git a/view/WindowManager.LayoutParams.md b/view/WindowManager.LayoutParams.md new file mode 100644 index 0000000000000000000000000000000000000000..8c5f229ab6e224f48ad8f40da2e1b3c31f10ff96 --- /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/view/WindowManager.md b/view/WindowManager.md index a1a5d8867c501fd6b876a32278f64f8bd29e801d..7571908d454c3542bc5398bd75b2899cc107d930 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); +``` + diff --git a/view/inflate.md b/view/inflate.md new file mode 100644 index 0000000000000000000000000000000000000000..930b24e80989d463a2989f21d31dde29550598bc --- /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/view/inputmethod.md b/view/inputmethod.md new file mode 100644 index 0000000000000000000000000000000000000000..09124fa350a580a969d0db6aa8281e8afaa1cfbc --- /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 diff --git a/view/onMeasure.md b/view/onMeasure.md new file mode 100644 index 0000000000000000000000000000000000000000..ac9d41718aa98f13edfc54815fa04b2958c86d1d --- /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; + } +``` + diff --git a/webkit/WebSettings.md b/webkit/WebSettings.md new file mode 100644 index 0000000000000000000000000000000000000000..6022496d9a19ee88e0a14a5e4cfd6858cf3ea075 --- /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 0000000000000000000000000000000000000000..c87f55c307800ad1651c2876ffcde4df4f6b0f4d --- /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 +* 实现方案:直接替换 + + diff --git a/widget/EditText.md b/widget/EditText.md new file mode 100644 index 0000000000000000000000000000000000000000..4747884ff16d1232ca7d6b9cd39997e802a177aa --- /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 0000000000000000000000000000000000000000..1b6612e3cb1ff3a019fd015975a9c944b07a46e5 --- /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 diff --git a/widget/TextSwitcher.md b/widget/TextSwitcher.md new file mode 100644 index 0000000000000000000000000000000000000000..bfe66f4fee505b70eb42043750c64c3eb9c7c804 --- /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 diff --git a/widget/TextView.md b/widget/TextView.md new file mode 100644 index 0000000000000000000000000000000000000000..d7fc4cb611b60e7a81fdf5ba166d30016371dab1 --- /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; + } + }); +``` diff --git a/widget/Toast.md b/widget/Toast.md new file mode 100644 index 0000000000000000000000000000000000000000..fcd43604fec22be54bb17dfc65eebee41a65da1a --- /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