diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/bean/AsrBean.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/bean/AsrBean.java
index d4a53aeee816fa9554f44b876f4667a3e7264d46..b8fd7ea68976e14c7ea2fa6281ac7e7bd8880b08 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/bean/AsrBean.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/bean/AsrBean.java
@@ -45,7 +45,7 @@ public class AsrBean {
/**
* Speech recognition result
*/
- public class Result {
+ public static class Result {
private double confidence;
private String ori_word;
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/AiMainSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/AiMainSlice.java
index 46d9efacaea6701d6813c07b0f86bed8b9642743..ecfe841f6113078e2b7643b1f3fdd0eea3ab9f22 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/AiMainSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/AiMainSlice.java
@@ -25,7 +25,7 @@ import ohos.agp.components.ComponentContainer;
* AiMainSlice
*/
public class AiMainSlice extends AbilitySlice {
- private AbilitySlice[] sliceArray = {
+ private final AbilitySlice[] sliceArray = {
new TextRecognitionSlice(), new ImageSuperResolutionSlice(), new DocumentCorrectionSlice(),
new QRCodeGenerationSlice(), new TextImageSuperResolutionSlice(), new WordSegmentationSlice(),
new PartOfSpeechTaggingSlice(), new AssistantIntentionRecognitionSlice(), new IMIntentRecognitionSlice(),
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/DocumentCorrectionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/DocumentCorrectionSlice.java
index 97581be19eedba4f4bb2795fd9d764f910f6c488..23fe95948c163304361746f51374b39720fe3931 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/DocumentCorrectionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/DocumentCorrectionSlice.java
@@ -38,8 +38,6 @@ import ohos.media.image.PixelMap;
public class DocumentCorrectionSlice extends BaseSlice {
private static final String IMAGE_PATH = "entry/resources/rawfile/doc_check.png";
- private Image originalImage;
-
private Image outImage;
private IDocRefine docRefine;
@@ -54,7 +52,7 @@ public class DocumentCorrectionSlice extends BaseSlice {
}
private void initComponents() {
- originalImage = (Image) findComponentById(ResourceTable.Id_image);
+ Image originalImage = (Image) findComponentById(ResourceTable.Id_image);
outImage = (Image) findComponentById(ResourceTable.Id_out_image);
Component startButton = findComponentById(ResourceTable.Id_start);
startButton.setClickedListener(this::doSuperResolution);
@@ -89,7 +87,7 @@ public class DocumentCorrectionSlice extends BaseSlice {
aiTitle.setText("Document Correction");
}
- private ConnectionCallback connectionCallback = new ConnectionCallback() {
+ private final ConnectionCallback connectionCallback = new ConnectionCallback() {
@Override
public void onServiceConnect() {
LogUtil.info(getLocalClassName(), "Service connect succeeded");
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/IMIntentRecognitionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/IMIntentRecognitionSlice.java
index 32b048e96caf3a93ff3960ad2f5c1bffe864febd..b9e0f6601f9fe92dc00c8ca7ee2db4ef0a8a3c5e 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/IMIntentRecognitionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/IMIntentRecognitionSlice.java
@@ -34,8 +34,6 @@ import java.util.Map;
public class IMIntentRecognitionSlice extends BaseSlice {
private TextField inputText;
- private Component startParse;
-
private TextField outText;
private boolean initEngineResult;
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/ImageSuperResolutionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/ImageSuperResolutionSlice.java
index bd953b90b8aaf74ae82f8161ee021c368713d4c2..b57dfcd56bf0038f8aeca9d366aaab6af2bde2bc 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/ImageSuperResolutionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/ImageSuperResolutionSlice.java
@@ -37,8 +37,6 @@ import ohos.media.image.PixelMap;
public class ImageSuperResolutionSlice extends BaseSlice {
private static final String IMAGE_PATH = "entry/resources/rawfile/super_image.png";
- private Image originalImage;
-
private Image outImage;
private IImageSuperResolution imageSuperResolution;
@@ -53,7 +51,7 @@ public class ImageSuperResolutionSlice extends BaseSlice {
}
private void initComponents() {
- originalImage = (Image) findComponentById(ResourceTable.Id_image);
+ Image originalImage = (Image) findComponentById(ResourceTable.Id_image);
outImage = (Image) findComponentById(ResourceTable.Id_out_image);
Component startButton = findComponentById(ResourceTable.Id_start);
startButton.setClickedListener(this::doSuperResolution);
@@ -87,7 +85,7 @@ public class ImageSuperResolutionSlice extends BaseSlice {
aiTitle.setText("Image Super Resolution");
}
- private ConnectionCallback connectionCallback = new ConnectionCallback() {
+ private final ConnectionCallback connectionCallback = new ConnectionCallback() {
@Override
public void onServiceConnect() {
LogUtil.info(getLocalClassName(), "Service connect succeeded");
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/SpeechRecognitionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/SpeechRecognitionSlice.java
index da7a1ee7b3f102e2b8f3c1a9f05f72d3a3c9e681..b2d9dac6da1c8cdbfe075d7c7caebd8735477e0d 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/SpeechRecognitionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/SpeechRecognitionSlice.java
@@ -69,13 +69,9 @@ public class SpeechRecognitionSlice extends BaseSlice {
private String result;
- private AsrIntent asrIntent;
-
private String wavCachePath;
- private String pcmCachePath;
-
- private EventHandler handler = new EventHandler(EventRunner.current()) {
+ private final EventHandler handler = new EventHandler(EventRunner.current()) {
@Override
protected void processEvent(InnerEvent event) {
switch (event.eventId) {
@@ -107,7 +103,7 @@ public class SpeechRecognitionSlice extends BaseSlice {
private void initData() {
wavCachePath = new File(getFilesDir(), "asr_test.wav").getPath();
- pcmCachePath = new File(getFilesDir(), "asr_date_conversion.pcm").getPath();
+ String pcmCachePath = new File(getFilesDir(), "asr_date_conversion.pcm").getPath();
writeToDisk(RAW_AUDIO_WAV, wavCachePath);
writeToDisk(RAW_AUDIO_PCM, pcmCachePath);
}
@@ -147,7 +143,7 @@ public class SpeechRecognitionSlice extends BaseSlice {
private void initAIEngine() {
asrClient = AsrClient.createAsrClient(this).orElse(null);
if (asrClient != null) {
- asrIntent = new AsrIntent();
+ AsrIntent asrIntent = new AsrIntent();
useDefaultAsrIntent(asrIntent);
asrIntent.setAudioSourceType(AsrIntent.AsrAudioSrcType.ASR_SRC_TYPE_PCM);
asrClient.init(asrIntent, asrListener);
@@ -183,7 +179,7 @@ public class SpeechRecognitionSlice extends BaseSlice {
}
}
- private AsrListener asrListener = new AsrListener() {
+ private final AsrListener asrListener = new AsrListener() {
@Override
public void onInit(PacMap pacMap) {
result = pacMap.getString(AsrResultKey.RESULTS_RECOGNITION);
@@ -202,7 +198,7 @@ public class SpeechRecognitionSlice extends BaseSlice {
@Override
public void onBufferReceived(byte[] bytes) {
- LogUtil.info(TAG, "onRmsChanged :" + bytes.toString());
+ LogUtil.info(TAG, "onRmsChanged :" + new String(bytes));
}
@Override
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextImageSuperResolutionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextImageSuperResolutionSlice.java
index 91c2a12d32bfcc3d0acbfa1b06924751fb46c1ca..e3dbbc6e58bf573a16ee562c663e0195e16c353a 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextImageSuperResolutionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextImageSuperResolutionSlice.java
@@ -37,8 +37,6 @@ import ohos.media.image.PixelMap;
public class TextImageSuperResolutionSlice extends BaseSlice {
private static final String IMAGE_PATH = "entry/resources/rawfile/super_text.png";
- private Image originalImage;
-
private Image outImage;
private ITxtImageSuperResolution txtImageSuperResolution;
@@ -53,7 +51,7 @@ public class TextImageSuperResolutionSlice extends BaseSlice {
}
private void initComponents() {
- originalImage = (Image) findComponentById(ResourceTable.Id_image);
+ Image originalImage = (Image) findComponentById(ResourceTable.Id_image);
outImage = (Image) findComponentById(ResourceTable.Id_out_image);
Component startButton = findComponentById(ResourceTable.Id_start);
startButton.setClickedListener(this::doSuperResolution);
@@ -86,7 +84,7 @@ public class TextImageSuperResolutionSlice extends BaseSlice {
aiTitle.setText("Text Image Super Resolution");
}
- private ConnectionCallback connectionCallback = new ConnectionCallback() {
+ private final ConnectionCallback connectionCallback = new ConnectionCallback() {
@Override
public void onServiceConnect() {
LogUtil.info(getLocalClassName(), "Service connect succeeded");
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextRecognitionSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextRecognitionSlice.java
index 41ce9f80f8bba503386d74ebbf31dc225b08ca6e..d8dc837637795ca04d5c9580abdc02e6dcffc6b7 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextRecognitionSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextRecognitionSlice.java
@@ -30,7 +30,6 @@ import ohos.ai.cv.common.VisionManager;
import ohos.ai.cv.text.ITextDetector;
import ohos.ai.cv.text.Text;
import ohos.ai.cv.text.TextConfiguration;
-import ohos.ai.cv.text.TextDetectType;
import ohos.media.image.PixelMap;
/**
@@ -39,8 +38,6 @@ import ohos.media.image.PixelMap;
public class TextRecognitionSlice extends BaseSlice {
private static final String IMAGE_PATH = "entry/resources/rawfile/text_recognition.png";
- private Image originalImage;
-
private TextField outText;
private ITextDetector textDetector;
@@ -54,7 +51,7 @@ public class TextRecognitionSlice extends BaseSlice {
}
private void initComponents() {
- originalImage = (Image) findComponentById(ResourceTable.Id_image);
+ Image originalImage = (Image) findComponentById(ResourceTable.Id_image);
outText = (TextField) findComponentById(ResourceTable.Id_out_text);
Component startButton = findComponentById(ResourceTable.Id_start);
startButton.setClickedListener(this::doSuperResolution);
@@ -87,7 +84,7 @@ public class TextRecognitionSlice extends BaseSlice {
aiTitle.setText("Text Recognition");
}
- private ConnectionCallback connectionCallback = new ConnectionCallback() {
+ private final ConnectionCallback connectionCallback = new ConnectionCallback() {
@Override
public void onServiceConnect() {
LogUtil.info(getLocalClassName(), "Service connect succeeded");
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextToSpeechSlice.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextToSpeechSlice.java
index 9e891d4806032ddf37a42143d95e2252ca507f92..8ad2b2c79c9ebc20d4e5e48388502f8e736570c7 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextToSpeechSlice.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/slice/TextToSpeechSlice.java
@@ -44,7 +44,7 @@ public class TextToSpeechSlice extends BaseSlice {
private TextField inputText;
- private EventHandler handler = new EventHandler(EventRunner.current()) {
+ private final EventHandler handler = new EventHandler(EventRunner.current()) {
@Override
protected void processEvent(InnerEvent event) {
initTTSEngine();
@@ -91,7 +91,7 @@ public class TextToSpeechSlice extends BaseSlice {
}
}
- private TtsListener ttsListener = new TtsListener() {
+ private final TtsListener ttsListener = new TtsListener() {
@Override
public void onEvent(int eventType, PacMap pacMap) {
if (eventType == TtsEvent.CREATE_TTS_CLIENT_SUCCESS) {
diff --git a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/utils/WidgetHelper.java b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/utils/WidgetHelper.java
index b7cc2333a0e19f197a315b7e2a7c68748390101c..f84336a8f465a239a9c35c2828bf9cd4b8147163 100644
--- a/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/utils/WidgetHelper.java
+++ b/AI/AIFunctionSet/entry/src/main/java/ohos/samples/aifunctionset/utils/WidgetHelper.java
@@ -36,15 +36,14 @@ public final class WidgetHelper {
* @return PixelMap pixelMap
*/
public static PixelMap getPixelMapFromRaw(Context context, String path) {
- PixelMap pixelMap = null;
try {
RawFileEntry rawFileEntry = context.getResourceManager().getRawFileEntry(path);
Resource resource = rawFileEntry.openRawFile();
ImageSource imageSource = ImageSource.create(resource, new ImageSource.SourceOptions());
- pixelMap = imageSource.createPixelmap(null);
+ return imageSource.createPixelmap(null);
} catch (IOException e) {
LogUtil.error("getPixelMapFromRaw", "IOException :" + e.toString());
}
- return pixelMap;
+ return null;
}
}
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/element/string.json b/AI/AIFunctionSet/entry/src/main/resources/base/element/string.json
index cb51c43fe4379ea18e6cdb15d45b362386ed5852..5877d2b2c1d2e905e9113990d7e8ba019c97171b 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/element/string.json
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/element/string.json
@@ -7,6 +7,70 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
+ },
+ {
+ "name": "start",
+ "value": "Start"
+ },
+ {
+ "name": "text_recognition",
+ "value": "Text Recognition"
+ },
+ {
+ "name": "image_super_resolution",
+ "value": "Image Super Resolution"
+ },
+ {
+ "name": "document_correction",
+ "value": "Document Correction"
+ },
+ {
+ "name": "qc_code",
+ "value": "QRCode Generation"
+ },
+ {
+ "name": "text_image_super_resolution",
+ "value": "Text Image Super Resolution"
+ },
+ {
+ "name": "word_segmentation",
+ "value": "Word Segmentation"
+ },
+ {
+ "name": "part_of_speech_tagging",
+ "value": "Part Of Speech Tagging"
+ },
+ {
+ "name": "assistant",
+ "value": "Assistant Intention Recognition"
+ },
+ {
+ "name": "im_intent",
+ "value": "IM Intent Recognition"
+ },
+ {
+ "name": "keyword",
+ "value": "Keyword Extraction"
+ },
+ {
+ "name": "entity",
+ "value": "Entity Identification"
+ },
+ {
+ "name": "speech_recognition",
+ "value": "Speech Recognition"
+ },
+ {
+ "name": "text_to_speech",
+ "value": "Text To Speech"
+ },
+ {
+ "name": "file_path",
+ "value": "File Path:/data/user/0/ohos.samples.ai/files/asr_test.wav"
+ },
+ {
+ "name": "enter_keyword_tips",
+ "value": "Please enter a keyword"
}
]
}
\ No newline at end of file
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/document_correction_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/document_correction_slice.xml
index 3aaf67d5edf0c29b140015fabda0f4d707985231..1a6bb56cc4a115fcffeb56473b7ac841baa09911 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/document_correction_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/document_correction_slice.xml
@@ -30,7 +30,7 @@
ohos:id="$+id:start"
ohos:height="35vp"
ohos:width="240vp"
- ohos:text="Start"
+ ohos:text="$string:start"
ohos:margin="10vp"
ohos:text_size="16fp"
ohos:background_element="$graphic:button_bg"/>
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/image_super_resolution_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/image_super_resolution_slice.xml
index e5d7eb134ae4ce2dfacf2cd8e0c0bd270efddeee..43dabfbb728187cbf5823749f26e02bccbf0ec56 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/image_super_resolution_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/image_super_resolution_slice.xml
@@ -32,7 +32,7 @@
ohos:height="35vp"
ohos:width="240vp"
ohos:background_element="$graphic:button_bg"
- ohos:text="Start"
+ ohos:text="$string:start"
ohos:text_size="16fp"
ohos:top_margin="20vp"/>
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/main_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/main_slice.xml
index 7db9500e463c5fa9f83f10b89ddf3285282923b1..dd4b8c161b56d3f8e718ff448a99cf08af0a1696 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/main_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/main_slice.xml
@@ -29,7 +29,7 @@
@@ -50,7 +50,7 @@
@@ -71,7 +71,7 @@
@@ -92,7 +92,7 @@
@@ -113,7 +113,7 @@
@@ -134,7 +134,7 @@
@@ -155,7 +155,7 @@
@@ -176,7 +176,7 @@
@@ -197,7 +197,7 @@
@@ -218,7 +218,7 @@
@@ -239,7 +239,7 @@
@@ -260,7 +260,7 @@
@@ -281,7 +281,7 @@
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/qr_code_generation_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/qr_code_generation_slice.xml
index 1ce0bed369e2c12f5bf9500146ef96bc34a1ce62..036ec56a730c1c16bcaea6e35792ff996098a4ac 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/qr_code_generation_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/qr_code_generation_slice.xml
@@ -32,7 +32,7 @@
ohos:height="35vp"
ohos:width="240vp"
ohos:background_element="$graphic:button_bg"
- ohos:text="Start"
+ ohos:text="$string:start"
ohos:text_size="16fp"
ohos:top_margin="20vp"/>
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/speech_recognition_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/speech_recognition_slice.xml
index 58f526e42ea85a3378f136adb101992a4cd6e691..3e158a803d640d127fe9882cfc13a0ff3bea97b2 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/speech_recognition_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/speech_recognition_slice.xml
@@ -28,7 +28,7 @@
ohos:left_margin="10vp"
ohos:padding="10vp"
ohos:right_margin="10vp"
- ohos:text="File Path:/data/user/0/ohos.samples.ai/files/asr_test.wav"
+ ohos:text="$string:file_path"
ohos:text_size="16fp"/>
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/text_recognition_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/text_recognition_slice.xml
index 642136719cf5812ebb18fca2112dbe0fc6813649..da05f8be1a9a435e6f8f03d1cc1de01a05320429 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/text_recognition_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/text_recognition_slice.xml
@@ -32,7 +32,7 @@
ohos:width="240vp"
ohos:background_element="$graphic:button_bg"
ohos:margin="20vp"
- ohos:text="Start"
+ ohos:text="$string:start"
ohos:text_size="16fp"/>
\ No newline at end of file
diff --git a/AI/AIFunctionSet/entry/src/main/resources/base/layout/word_segmentation_slice.xml b/AI/AIFunctionSet/entry/src/main/resources/base/layout/word_segmentation_slice.xml
index f44ffe19db293bb3c9914752dec07f83393714ef..a19b1ca6291f8dd394ee9678a9c8cfa108e5ef89 100644
--- a/AI/AIFunctionSet/entry/src/main/resources/base/layout/word_segmentation_slice.xml
+++ b/AI/AIFunctionSet/entry/src/main/resources/base/layout/word_segmentation_slice.xml
@@ -26,7 +26,7 @@
ohos:height="match_content"
ohos:width="match_parent"
ohos:background_element="$graphic:textfield_bg"
- ohos:hint="Please enter a keyword"
+ ohos:hint="$string:enter_keyword_tips"
ohos:left_margin="10vp"
ohos:padding="10vp"
ohos:right_margin="10vp"
@@ -39,7 +39,7 @@
ohos:width="240vp"
ohos:background_element="$graphic:button_bg"
ohos:margin="20vp"
- ohos:text="Start"
+ ohos:text="$string:start"
ohos:text_size="16fp"/>
contentList = accessibilityEventInfo.getContentList();
- try {
- Element element = getContext().getResourceManager()
- .getElement(ResourceTable.String_string_button_perform_click);
- String string = element.getString();
- for (CharSequence content : contentList) {
- LogUtils.info(TAG, "type view clicked,content:" + content.toString() + ",string:" + string);
- if (content.toString().equals(string)) {
- LogUtils.info(TAG, "type view clicked,content:equals");
- TtsManager.getInstance().speakText(content.toString(), null);
- performCommonAction(AccessibleAbility.GLOBAL_ACTION_HOME);
- }
+ if (AccessibilityEventInfo.TYPE_VIEW_CLICKED_EVENT == eventType) {
+ LogUtils.info(TAG, "type view clicked");
+ ArrayList contentList = accessibilityEventInfo.getContentList();
+ try {
+ Element element = getContext().getResourceManager()
+ .getElement(ResourceTable.String_string_button_perform_click);
+ String string = element.getString();
+ for (CharSequence content : contentList) {
+ LogUtils.info(TAG, "type view clicked,content:" + content.toString() + ",string:" + string);
+ if (content.toString().equals(string)) {
+ LogUtils.info(TAG, "type view clicked,content:equals");
+ TtsManager.getInstance().speakText(content.toString(), null);
+ performCommonAction(AccessibleAbility.GLOBAL_ACTION_HOME);
}
- } catch (IOException | NotExistException | WrongTypeException e) {
- LogUtils.error(TAG, "type view clicked,Exception:" + e.getMessage());
}
- break;
- default:
- break;
+ } catch (IOException | NotExistException | WrongTypeException e) {
+ LogUtils.error(TAG, "type view clicked,Exception:" + e.getMessage());
+ }
}
switch (windowType) {
case AccessibilityEventInfo.WINDOWS_CHANGE_ADDED:
Optional accessibilityInfo = getRootAccessibilityInfo();
String bundleName = accessibilityInfo.get().getBundleName().toString();
LogUtils.info(TAG, "WINDOWS_CHANGE_ADDED:" + bundleName);
- if (bundleName.equals(BUNDLE_NAME) && isInSpecialApp == false) {
+ if (bundleName.equals(BUNDLE_NAME) && !isInSpecialApp) {
isInSpecialApp = true;
LogUtils.info(TAG, "You are in the " + bundleName);
runUIThread(() -> new ToastDialog(getContext()).setText("You are in the " + BUNDLE_NAME).show());
@@ -120,26 +116,10 @@ public class MyAccessibilityService extends AccessibleAbility {
if (isNeedCustomVolumeKey) {
if (keyEvent.getKeyCode() == KeyEvent.KEY_VOLUME_DOWN || keyEvent.getKeyCode() == KeyEvent.KEY_VOLUME_UP) {
if (keyEvent.getKeyCode() == KeyEvent.KEY_VOLUME_DOWN && keyEvent.isKeyDown()) {
- runUIThread(() -> {
- try {
- Class mClass = Class.forName("ohos.samples.accessibilityservice.slice.KeyPressEventSlice");
- mClass.getDeclaredMethod("scrollDown").invoke(mClass.newInstance(), new Object[]{});
- } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException
- | ClassNotFoundException | InstantiationException e) {
- LogUtils.error(TAG, "KEY_VOLUME_DOWN error:" + e.getMessage());
- }
- });
+ runUIThread(KeyPressEventSlice::scrollDown);
}
if (keyEvent.getKeyCode() == KeyEvent.KEY_VOLUME_UP && keyEvent.isKeyDown()) {
- runUIThread(() -> {
- try {
- Class mClass = Class.forName("ohos.samples.accessibilityservice.slice.KeyPressEventSlice");
- mClass.getDeclaredMethod("scrollUp").invoke(mClass.newInstance(), new Object[]{});
- } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException
- | ClassNotFoundException | InstantiationException e) {
- LogUtils.error(TAG, "KEY_VOLUME_UP error:" + e.getMessage());
- }
- });
+ runUIThread(KeyPressEventSlice::scrollUp);
}
return true;
}
diff --git a/AccessibilityService/AccessibilityService/entry/src/main/java/ohos/samples/accessibilityservice/slice/KeyPressEventSlice.java b/AccessibilityService/AccessibilityService/entry/src/main/java/ohos/samples/accessibilityservice/slice/KeyPressEventSlice.java
index cab0cb1fc37592abd4d91f60b1561fdca75148e3..e5765989b4d11cdb64edf6480c73827fa4d00e48 100644
--- a/AccessibilityService/AccessibilityService/entry/src/main/java/ohos/samples/accessibilityservice/slice/KeyPressEventSlice.java
+++ b/AccessibilityService/AccessibilityService/entry/src/main/java/ohos/samples/accessibilityservice/slice/KeyPressEventSlice.java
@@ -44,7 +44,7 @@ public class KeyPressEventSlice extends AbilitySlice {
/**
* scrollUp
*/
- public void scrollUp() {
+ public static void scrollUp() {
LogUtils.info(TAG, "scrollUp");
if (tabList != null && tabList.getSelectedTabIndex() > 0) {
tabList.selectTabAt(tabList.getSelectedTabIndex() - 1);
@@ -54,7 +54,7 @@ public class KeyPressEventSlice extends AbilitySlice {
/**
* scrollDown
*/
- public void scrollDown() {
+ public static void scrollDown() {
LogUtils.info(TAG, "scrollDown");
if (tabList != null && tabList.getSelectedTabIndex() < tabList.getTabCount() - 1) {
tabList.selectTabAt(tabList.getSelectedTabIndex() + 1);
diff --git a/README.md b/README.md
index aa50d07a98bbadd2893f81807af6eb29cf404076..a67add36ffc4070b7b2eedb2ac95a405b8656f07 100755
--- a/README.md
+++ b/README.md
@@ -22,7 +22,22 @@ We provide a series of app samples to help you quickly get familiar with the API
3. The following app samples can run on OpenHarmony, and other app samples can run only on HarmonyOS:
- common/Clock
- common/JsHelloWorld
+ - common/DistributeCalc
+ - common/ECG
+ - common/Flashlight
- ability/JsDistributedMusicPlayer
+ - common/DistributeCalc
+ - UI/AtomicLayout
+ - UI/Badge
+ - UI/chart
+ - UI/JsAnimationStyle
+ - UI/Picker
+ - UI/Popup
+ - UI/RefreshContainer
+ - UI/Stack
+ - UI/StepNavigator
+ - UI/Swiper
+ - UI/Tabs
## Repositories Involved
diff --git a/README_zh.md b/README_zh.md
index 97181dbd694484e08fdc25fc848f90680f527155..8b1638af3d7f275da57b5d6a4345261becfcc80f 100755
--- a/README_zh.md
+++ b/README_zh.md
@@ -22,7 +22,22 @@
3. 以下路径下的应用示例支持在OpenHarmony上运行,其余应用示例仅支持在HarmonyOS上运行。
- common/Clock
- common/JsHelloWorld
+ - common/DistributeCalc
+ - common/ECG
+ - common/Flashlight
- ability/JsDistributedMusicPlayer
+ - common/DistributeCalc
+ - UI/AtomicLayout
+ - UI/Badge
+ - UI/chart
+ - UI/JsAnimationStyle
+ - UI/Picker
+ - UI/Popup
+ - UI/RefreshContainer
+ - UI/Stack
+ - UI/StepNavigator
+ - UI/Swiper
+ - UI/Tabs
## 相关仓
diff --git a/data/DistributedPictures/entry/src/main/java/ohos/samples/distributedpictures/slice/MainAbilitySlice.java b/data/DistributedPictures/entry/src/main/java/ohos/samples/distributedpictures/slice/MainAbilitySlice.java
index cf34ae3d6bc2bf5878a5dbbb39d8dd856532b50f..a6ec5cc358f1be3ffd17c11d35267f2f133b669b 100644
--- a/data/DistributedPictures/entry/src/main/java/ohos/samples/distributedpictures/slice/MainAbilitySlice.java
+++ b/data/DistributedPictures/entry/src/main/java/ohos/samples/distributedpictures/slice/MainAbilitySlice.java
@@ -108,7 +108,7 @@ public class MainAbilitySlice extends AbilitySlice {
}
private void copyPicToDistributedDir() {
- writeToDistributedDir("entry/resources/rawfile/icon.png", distributedFile);
+ writeToDistributedDir(distributedFile);
File file = new File(distributedFile);
if (file.exists()) {
showTip(this, "shared success");
@@ -122,8 +122,8 @@ public class MainAbilitySlice extends AbilitySlice {
toastDialog.show();
}
- private void writeToDistributedDir(String rawFilePathString, String targetFilePath) {
- RawFileEntry rawFileEntry = getResourceManager().getRawFileEntry(rawFilePathString);
+ private void writeToDistributedDir(String targetFilePath) {
+ RawFileEntry rawFileEntry = getResourceManager().getRawFileEntry("entry/resources/rawfile/icon.png");
try (FileOutputStream output = new FileOutputStream(new File(targetFilePath))) {
Resource resource = rawFileEntry.openRawFile();
byte[] cache = new byte[CACHE_SIZE];
diff --git a/data/DistributedPictures/entry/src/main/resources/base/element/string.json b/data/DistributedPictures/entry/src/main/resources/base/element/string.json
index e05de56594a0dd7bd1b8afd510ad015d6d220d82..e0c6f3ebc128920a455f9e07b1856ae4a8e99418 100644
--- a/data/DistributedPictures/entry/src/main/resources/base/element/string.json
+++ b/data/DistributedPictures/entry/src/main/resources/base/element/string.json
@@ -7,6 +7,26 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
+ },
+ {
+ "name": "local_pictures",
+ "value": "Local Pictures"
+ },
+ {
+ "name": "share_to_distributed_dir",
+ "value": "Share Local Picture To Distributed Dir"
+ },
+ {
+ "name": "refresh",
+ "value": "Refresh"
+ },
+ {
+ "name": "delete",
+ "value": "Delete"
+ },
+ {
+ "name": "remote_picture",
+ "value": "Remote Pictures"
}
]
}
\ No newline at end of file
diff --git a/data/DistributedPictures/entry/src/main/resources/base/layout/main_ability_slice.xml b/data/DistributedPictures/entry/src/main/resources/base/layout/main_ability_slice.xml
index 65e082e822934a79251fda077e28ac1cd8d60202..7e3abe42af1d830378a6110bdfd95167939a8aa6 100644
--- a/data/DistributedPictures/entry/src/main/resources/base/layout/main_ability_slice.xml
+++ b/data/DistributedPictures/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -33,7 +33,7 @@
ohos:height="match_content"
ohos:width="match_content"
ohos:padding="8vp"
- ohos:text="Local Pictures"
+ ohos:text="$string:local_pictures"
ohos:text_size="15fp"/>
@@ -83,7 +83,7 @@
ohos:background_element="#55000055"
ohos:left_margin="10vp"
ohos:padding="5vp"
- ohos:text="Delete"
+ ohos:text="$string:delete"
ohos:text_size="15fp"
ohos:weight="1"/>
@@ -101,7 +101,7 @@
ohos:height="match_content"
ohos:width="match_content"
ohos:padding="8vp"
- ohos:text="Remote Pictures"
+ ohos:text="$string:remote_picture"
ohos:text_size="15fp"/>
remoteObjectHandlers = new HashSet<>();
- remoteObjectHandlers.add(data.readRemoteObject());
+ private void subscribe(MessageParcel reply, MessageOption option) {
Map subscribeResult = new HashMap<>();
subscribeResult.put(Constants.CODE, SUCCESS);
subscribeResult.put(Constants.DATA, Constants.SUCCESS);
diff --git a/data/Preferences/entry/src/main/java/ohos/samples/preferences/utils/LogUtil.java b/data/Preferences/entry/src/main/java/ohos/samples/preferences/utils/LogUtil.java
index 12df1c06df5838158b542c9f159588b667a203c4..214b44b6585ac30358393f121dbcd01552618483 100644
--- a/data/Preferences/entry/src/main/java/ohos/samples/preferences/utils/LogUtil.java
+++ b/data/Preferences/entry/src/main/java/ohos/samples/preferences/utils/LogUtil.java
@@ -56,16 +56,6 @@ public class LogUtil {
HiLog.info(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg));
}
- /**
- * Print warn log
- *
- * @param tag log tag
- * @param msg log message
- */
- public static void warn(String tag, String msg) {
- HiLog.warn(LABEL_LOG, String.format(Locale.ROOT, LOG_FORMAT, tag, msg));
- }
-
/**
* Print error log
*
diff --git a/data/Preferences/entry/src/main/js/default/pages/login/login.js b/data/Preferences/entry/src/main/js/default/pages/login/login.js
index d51e3f120aa77e0aac9057d1492a3e800c48f39d..a735acc3a72413e4393ac72caf74b8bc8746cf1d 100644
--- a/data/Preferences/entry/src/main/js/default/pages/login/login.js
+++ b/data/Preferences/entry/src/main/js/default/pages/login/login.js
@@ -16,10 +16,6 @@
import prompt from "@system.prompt";
import router from "@system.router";
-const injectRef = Object.getPrototypeOf(global) || global;
-
-injectRef.regeneratorRuntime = require("@babel/runtime/regenerator");
-
export default {
data: {
userID: "",
diff --git a/data/Preferences/entry/src/main/js/default/pages/main/main.js b/data/Preferences/entry/src/main/js/default/pages/main/main.js
index cd7fe330e8dc7d47c0d532ffcf89c95d753817c5..e5c12b319e90368ac813156465dbb4b2e86da8bc 100644
--- a/data/Preferences/entry/src/main/js/default/pages/main/main.js
+++ b/data/Preferences/entry/src/main/js/default/pages/main/main.js
@@ -15,12 +15,9 @@
import prompt from "@system.prompt";
-const injectRef = Object.getPrototypeOf(global) || global;
-
-injectRef.regeneratorRuntime = require("@babel/runtime/regenerator");
-
export default {
data: {
+ lastSelectedColor:null,
selectedColor: "#ffffff",
appliedColor: "#ffffff",
tempVar: true,
diff --git a/data/Preferences/entry/src/main/js/default/pages/splash/splash.js b/data/Preferences/entry/src/main/js/default/pages/splash/splash.js
index a1ef85c2b015e99d45810c3035885c06a64313c6..f0b1fea04f9f758c167d6a88c46b17a9d401e7c3 100644
--- a/data/Preferences/entry/src/main/js/default/pages/splash/splash.js
+++ b/data/Preferences/entry/src/main/js/default/pages/splash/splash.js
@@ -15,10 +15,6 @@
import router from "@system.router";
-const injectRef = Object.getPrototypeOf(global) || global;
-
-injectRef.regeneratorRuntime = require("@babel/runtime/regenerator");
-
export default {
data: {
loginStatus: false,
@@ -171,7 +167,6 @@ export default {
},
onChanged: async function (checked) {
try {
- var that = this;
var actionData = {};
actionData.checkState = checked ? 1 : 0;
var action = {};
diff --git a/data/Search/entry/src/main/java/ohos/samples/search/slice/MainAbilitySlice.java b/data/Search/entry/src/main/java/ohos/samples/search/slice/MainAbilitySlice.java
index e8758423709566111b7b66704dea55560ca6aa31..2d5fca3162546e17ed1bd33dcbfa73f31987cc99 100644
--- a/data/Search/entry/src/main/java/ohos/samples/search/slice/MainAbilitySlice.java
+++ b/data/Search/entry/src/main/java/ohos/samples/search/slice/MainAbilitySlice.java
@@ -104,7 +104,7 @@ public class MainAbilitySlice extends AbilitySlice {
Component btnSearchByPage = findComponentById(ResourceTable.Id_btnSearchByPage);
btnSearchByPage.setClickedListener(this::searchByPage);
- Component searchComponent = findComponentById(ResourceTable.Id_searchResult);;
+ Component searchComponent = findComponentById(ResourceTable.Id_searchResult);
if (searchComponent instanceof Text) {
searchResult = (Text) searchComponent;
}
diff --git a/data/Search/entry/src/main/java/ohos/samples/search/utils/SearchUtils.java b/data/Search/entry/src/main/java/ohos/samples/search/utils/SearchUtils.java
index 3eef5411f87b5aa1056d7bdb4c490e94d01567ec..2a4c2cd092c002bf6865ce58fb05b3cd980758cd 100644
--- a/data/Search/entry/src/main/java/ohos/samples/search/utils/SearchUtils.java
+++ b/data/Search/entry/src/main/java/ohos/samples/search/utils/SearchUtils.java
@@ -26,6 +26,7 @@ import ohos.utils.zson.ZSONObject;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -281,14 +282,14 @@ public class SearchUtils {
filter1.put(CommonItem.IDENTIFIER, new ZSONArray(Arrays.asList(0, 1, 2, 3, 4, 5))); // The index is also hit if its value is 0 , 1, 2, 3, 4 or 5 for the CommonItem.IDENTIFIER field.
filterCondition.add(filter1);
ZSONObject filter2 = new ZSONObject();
- filter2.put("tag", new ZSONArray(Arrays.asList("position")));
- filter2.put(CommonItem.TITLE, new ZSONArray(Arrays.asList("position"))); // An index is hit if the value of the tag or CommonItem.TITLE field is position.
+ filter2.put("tag", new ZSONArray(Collections.singletonList("position")));
+ filter2.put(CommonItem.TITLE, new ZSONArray(Collections.singletonList("position"))); // An index is hit if the value of the tag or CommonItem.TITLE field is position.
filterCondition.add(filter2);
zsonObject.put(SearchParameter.FILTER_CONDITION, filterCondition); // An index is hit only if both the first and second conditions are met.
// SearchParameter.DEVICE_ID_LIST indicates the device ID list. Indexes with the specified IDs are hit.
ZSONObject deviceId = new ZSONObject();
- deviceId.put("device_id", new ZSONArray(Arrays.asList("localDeviceId"))); // Specify the local device.
+ deviceId.put("device_id", new ZSONArray(Collections.singletonList("localDeviceId"))); // Specify the local device.
zsonObject.put(SearchParameter.DEVICE_ID_LIST, deviceId);
// Start a search by specifying the value range of a specified index field.
diff --git a/device/BatteryInfo/entry/src/main/java/ohos/samples/batteryinfo/slice/MainAbilitySlice.java b/device/BatteryInfo/entry/src/main/java/ohos/samples/batteryinfo/slice/MainAbilitySlice.java
index d3ee81782f185842be95ccb49e24811202601548..b56f4d2eeb5e0fe1cefb869fdaa8473def2837c8 100644
--- a/device/BatteryInfo/entry/src/main/java/ohos/samples/batteryinfo/slice/MainAbilitySlice.java
+++ b/device/BatteryInfo/entry/src/main/java/ohos/samples/batteryinfo/slice/MainAbilitySlice.java
@@ -60,9 +60,8 @@ public class MainAbilitySlice extends AbilitySlice {
private void initComponents() {
batteryInfoText = (Text) findComponentById(ResourceTable.Id_battery_level_result);
- findComponentById(ResourceTable.Id_get_battery_level).setClickedListener(listener -> {
- batteryInfoText.setText(getBatteryInfo());
- });
+ findComponentById(ResourceTable.Id_get_battery_level)
+ .setClickedListener(listener -> batteryInfoText.setText(getBatteryInfo()));
Button subscribeBatteryChange = (Button) findComponentById(ResourceTable.Id_subscribe_battery_level_change);
subscribeBatteryChange.setClickedListener(listener -> {
if (!isSubscribedBatteryChange) {
diff --git a/device/BatteryInfo/entry/src/main/resources/base/element/string.json b/device/BatteryInfo/entry/src/main/resources/base/element/string.json
index cfcd62df9dd7b3ad060f08a599e4fd411d53602e..717bc6c060ec0a0fc83c9a3a2cee38fbca7bee99 100644
--- a/device/BatteryInfo/entry/src/main/resources/base/element/string.json
+++ b/device/BatteryInfo/entry/src/main/resources/base/element/string.json
@@ -7,6 +7,14 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
+ },
+ {
+ "name": "get_battery_level",
+ "value": "Get Battery Level"
+ },
+ {
+ "name": "subscribe_battery_level",
+ "value": "Subscribe Battery Level"
}
]
}
\ No newline at end of file
diff --git a/device/BatteryInfo/entry/src/main/resources/base/layout/main_ability_slice.xml b/device/BatteryInfo/entry/src/main/resources/base/layout/main_ability_slice.xml
index 0c26cce0698f4087eed09adbdd1c260b9463a27c..0ab9f8d728698b02450e71286e88abe9047d2882 100644
--- a/device/BatteryInfo/entry/src/main/resources/base/layout/main_ability_slice.xml
+++ b/device/BatteryInfo/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -24,7 +24,7 @@
ohos:height="40vp"
ohos:top_margin="50vp"
ohos:layout_alignment="horizontal_center"
- ohos:text="Get Battery Level"
+ ohos:text="$string:get_battery_level"
ohos:text_size="20vp"
ohos:text_color="#ffffffff"
ohos:background_element="$graphic:bg"/>
@@ -35,7 +35,7 @@
ohos:height="40vp"
ohos:top_margin="50vp"
ohos:layout_alignment="horizontal_center"
- ohos:text="Subscribe Battery Level"
+ ohos:text="$string:subscribe_battery_level"
ohos:text_size="20vp"
ohos:text_color="#ffffffff"
ohos:background_element="$graphic:bg"/>
diff --git a/device/Compass/entry/src/main/java/ohos/samples/compass/slice/PageAbilitySlice.java b/device/Compass/entry/src/main/java/ohos/samples/compass/slice/PageAbilitySlice.java
index 118326c024b7dc60c7a90bc56ba2ec2ef470c8e5..be1c6f7dd4f0a5110bce3ca8bbc45dcdf475e3f7 100644
--- a/device/Compass/entry/src/main/java/ohos/samples/compass/slice/PageAbilitySlice.java
+++ b/device/Compass/entry/src/main/java/ohos/samples/compass/slice/PageAbilitySlice.java
@@ -56,7 +56,7 @@ public class PageAbilitySlice extends AbilitySlice {
private ICategoryOrientationDataCallback categoryOrientationDataCallback;
- private EventHandler handler = new EventHandler(EventRunner.current()) {
+ private final EventHandler handler = new EventHandler(EventRunner.current()) {
@Override
protected void processEvent(InnerEvent event) {
compassAngleText.setText(getRotation(degree));
diff --git a/device/Location/entry/src/main/java/ohos/samples/location/slice/MainAbilitySlice.java b/device/Location/entry/src/main/java/ohos/samples/location/slice/MainAbilitySlice.java
index 2fcc5ae557cce679083fda12e0892936c8ad0e5a..de090a36632a1917e54c0381085c31db88e47653 100644
--- a/device/Location/entry/src/main/java/ohos/samples/location/slice/MainAbilitySlice.java
+++ b/device/Location/entry/src/main/java/ohos/samples/location/slice/MainAbilitySlice.java
@@ -54,14 +54,12 @@ public class MainAbilitySlice extends AbilitySlice {
private static final String PERM_LOCATION = "ohos.permission.LOCATION";
- private LocatorResult locatorResult = new LocatorResult();
+ private final LocatorResult locatorResult = new LocatorResult();
private Context context;
private Locator locator;
- private RequestParam requestParam;
-
private GeoConvert geoConvert;
private List gaList;
@@ -110,7 +108,7 @@ public class MainAbilitySlice extends AbilitySlice {
geoAddressInfoText.append("CountryName : " + locationDetails.getCountryName());
}
- private EventHandler handler = new EventHandler(EventRunner.current()) {
+ private final EventHandler handler = new EventHandler(EventRunner.current()) {
@Override
protected void processEvent(InnerEvent event) {
if (event.eventId == EVENT_ID) {
@@ -121,15 +119,15 @@ public class MainAbilitySlice extends AbilitySlice {
private void register(Context ability) {
context = ability;
- requestPermission(PERM_LOCATION);
+ requestPermission();
}
private void registerLocationEvent() {
- if (hasPermissionGranted(PERM_LOCATION)) {
+ if (hasPermissionGranted()) {
int timeInterval = 0;
int distanceInterval = 0;
locator = new Locator(context);
- requestParam = new RequestParam(RequestParam.PRIORITY_ACCURACY, timeInterval, distanceInterval);
+ RequestParam requestParam = new RequestParam(RequestParam.PRIORITY_ACCURACY, timeInterval, distanceInterval);
locator.startLocating(requestParam, locatorResult);
}
}
@@ -140,13 +138,13 @@ public class MainAbilitySlice extends AbilitySlice {
}
}
- private boolean hasPermissionGranted(String permission) {
- return context.verifySelfPermission(permission) == IBundleManager.PERMISSION_GRANTED;
+ private boolean hasPermissionGranted() {
+ return context.verifySelfPermission(PERM_LOCATION) == IBundleManager.PERMISSION_GRANTED;
}
- private void requestPermission(String permission) {
- if (context.verifySelfPermission(permission) != IBundleManager.PERMISSION_GRANTED) {
- context.requestPermissionsFromUser(new String[] {permission}, 0);
+ private void requestPermission() {
+ if (context.verifySelfPermission(PERM_LOCATION) != IBundleManager.PERMISSION_GRANTED) {
+ context.requestPermissionsFromUser(new String[] {PERM_LOCATION}, 0);
}
}
@@ -188,7 +186,7 @@ public class MainAbilitySlice extends AbilitySlice {
}
}
- private boolean fillGeoInfo(LocationBean locationDetails, double geoLatitude, double geoLongitude) {
+ private void fillGeoInfo(LocationBean locationDetails, double geoLatitude, double geoLongitude) {
if (geoConvert == null) {
geoConvert = new GeoConvert();
}
@@ -198,13 +196,11 @@ public class MainAbilitySlice extends AbilitySlice {
if (!gaList.isEmpty()) {
GeoAddress geoAddress = gaList.get(0);
setGeo(locationDetails, geoAddress);
- return true;
}
} catch (IllegalArgumentException | IOException e) {
HiLog.error(LABEL_LOG, "%{public}s", "fillGeoInfo exception");
}
}
- return false;
}
private void setGeo(LocationBean locationDetails, GeoAddress geoAddress) {
diff --git a/device/Location/entry/src/main/resources/base/element/string.json b/device/Location/entry/src/main/resources/base/element/string.json
index 6d7e386baa48eaebb43f33a2f0f898ad6d103d08..0cd87513b7c7512ef7cfda7bcaa5973c87865bea 100644
--- a/device/Location/entry/src/main/resources/base/element/string.json
+++ b/device/Location/entry/src/main/resources/base/element/string.json
@@ -11,6 +11,22 @@
{
"name": "reason_description",
"value": "location sample get permisssion"
+ },
+ {
+ "name": "start_location",
+ "value": "Start Location"
+ },
+ {
+ "name": "stop_location",
+ "value": "Stop Location"
+ },
+ {
+ "name": "location_info",
+ "value": "Location Info"
+ },
+ {
+ "name": "geo_address_info",
+ "value": " Geo Address Info"
}
]
}
\ No newline at end of file
diff --git a/device/Location/entry/src/main/resources/base/layout/main_ability_slice.xml b/device/Location/entry/src/main/resources/base/layout/main_ability_slice.xml
index fb063fc11a133031db45ee23def96ba37f96ebb1..abc97ab35c40bddc38c2249dc95c6ba526bc414f 100644
--- a/device/Location/entry/src/main/resources/base/layout/main_ability_slice.xml
+++ b/device/Location/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -26,7 +26,7 @@
ohos:left_margin="24vp"
ohos:padding="10vp"
ohos:right_margin="24vp"
- ohos:text="Start Location"
+ ohos:text="$string:start_location"
ohos:text_alignment="center"
ohos:text_size="16fp"
ohos:top_margin="10vp"/>
@@ -39,7 +39,7 @@
ohos:left_margin="24vp"
ohos:padding="10vp"
ohos:right_margin="24vp"
- ohos:text="Stop Location"
+ ohos:text="$string:stop_location"
ohos:text_alignment="center"
ohos:text_size="16fp"
ohos:top_margin="10vp"/>
@@ -47,7 +47,7 @@
@@ -64,7 +64,7 @@
diff --git a/device/Setting/entry/src/main/java/ohos/samples/setting/slice/MainAbilitySlice.java b/device/Setting/entry/src/main/java/ohos/samples/setting/slice/MainAbilitySlice.java
index 534d417ec3918054b2de6976d84e03d1d1f2e002..7f92c9a61773401c074684955441f8ffd25a1185 100644
--- a/device/Setting/entry/src/main/java/ohos/samples/setting/slice/MainAbilitySlice.java
+++ b/device/Setting/entry/src/main/java/ohos/samples/setting/slice/MainAbilitySlice.java
@@ -69,7 +69,7 @@ public class MainAbilitySlice extends AbilitySlice {
setAirplaneModeStatus(SystemSettings.getValue(dataAbilityHelper, SystemSettings.General.AIRPLANE_MODE_STATUS));
}
- private IDataAbilityObserver dataAbilityObserver = new IDataAbilityObserver() {
+ private final IDataAbilityObserver dataAbilityObserver = new IDataAbilityObserver() {
@Override
public void onChange() {
String wifiFormat = SystemSettings.getValue(dataAbilityHelper, SystemSettings.Wireless.WIFI_STATUS);
diff --git a/device/Setting/entry/src/main/resources/base/element/string.json b/device/Setting/entry/src/main/resources/base/element/string.json
index 7b0b2bdff266438ca5e04adcd7ee5a09d00f6dfb..93b14e3eaefe72da181c7dce1c60953934894bb7 100644
--- a/device/Setting/entry/src/main/resources/base/element/string.json
+++ b/device/Setting/entry/src/main/resources/base/element/string.json
@@ -7,6 +7,22 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
+ },
+ {
+ "name": "get_system_config",
+ "value": "Get System Config"
+ },
+ {
+ "name": "wifi_status",
+ "value": "wifi_status : "
+ },
+ {
+ "name": "bluetooth_status",
+ "value": "Bluetooth Status : "
+ },
+ {
+ "name": "airplane_status",
+ "value": "Airplane Mode Status : "
}
]
}
\ No newline at end of file
diff --git a/device/Setting/entry/src/main/resources/base/layout/main_ability_slice.xml b/device/Setting/entry/src/main/resources/base/layout/main_ability_slice.xml
index 67ee907dde85d6d75014f0facb350165494d2ccd..61b8b3e18d059036c3a4ae18db6b846d980b00bd 100644
--- a/device/Setting/entry/src/main/resources/base/layout/main_ability_slice.xml
+++ b/device/Setting/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -23,7 +23,7 @@
@@ -38,7 +38,7 @@
ohos:height="match_content"
ohos:width="match_content"
ohos:left_padding="15vp"
- ohos:text="WIFI Status : "
+ ohos:text="$string:wifi_status"
ohos:text_size="16fp"/>
permissionFiltered = Arrays.stream(permissions)
- .filter(permission -> verifySelfPermission(permission) != IBundleManager.PERMISSION_GRANTED)
- .collect(Collectors.toList());
- requestPermissionsFromUser(permissionFiltered.toArray(new String[permissionFiltered.size()]), 0);
+ requestPermissionsFromUser(Arrays.stream(permissions)
+ .filter(permission -> verifySelfPermission(permission) != IBundleManager.PERMISSION_GRANTED).toArray(String[]::new), 0);
}
@Override
diff --git a/media/Audio/entry/src/main/java/ohos/samples/audio/slice/AudioRecorderSlice.java b/media/Audio/entry/src/main/java/ohos/samples/audio/slice/AudioRecorderSlice.java
index 034c27dc4ba9afaf0c583703550b2dc270c18b63..8454c7bbfab73c13cd0cfacf110cd29784d6622e 100644
--- a/media/Audio/entry/src/main/java/ohos/samples/audio/slice/AudioRecorderSlice.java
+++ b/media/Audio/entry/src/main/java/ohos/samples/audio/slice/AudioRecorderSlice.java
@@ -63,7 +63,7 @@ public class AudioRecorderSlice extends AbilitySlice {
private Text pathText;
- private AudioCapturerCallback callback = new AudioCapturerCallback() {
+ private final AudioCapturerCallback callback = new AudioCapturerCallback() {
@Override
public void onCapturerConfigChanged(List configs) {
HiLog.info(LABEL_LOG, "%{public}s", "on capturer config changed");
@@ -126,7 +126,7 @@ public class AudioRecorderSlice extends AbilitySlice {
isRecording = false;
recordButton.setText("Start");
showTips("Stop record");
- pathText.setText("Path:" + getFilesDir() + File.separator + "record.mp3");
+ pathText.setText("Path:" + getFilesDir() + File.separator + "record.pcm");
}
}
@@ -141,7 +141,7 @@ public class AudioRecorderSlice extends AbilitySlice {
private void runRecord() {
getGlobalTaskDispatcher(TaskPriority.DEFAULT).asyncDispatch(() -> {
- file = new File(getFilesDir() + File.separator + "record.mp3");
+ file = new File(getFilesDir() + File.separator + "record.pcm");
try (FileOutputStream outputStream = new FileOutputStream(file)) {
byte[] bytes = new byte[BUFFER_SIZE];
while (audioCapturer.read(bytes, 0, bytes.length) != -1) {
diff --git a/media/Audio/entry/src/main/resources/base/element/string.json b/media/Audio/entry/src/main/resources/base/element/string.json
index a677b58e114f80ef7954d072aaaa0e18a5f35af7..78e2dd570007ec35b925ed68974796092fa8f711 100644
--- a/media/Audio/entry/src/main/resources/base/element/string.json
+++ b/media/Audio/entry/src/main/resources/base/element/string.json
@@ -7,6 +7,46 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
+ },
+ {
+ "name": "sound_recorder",
+ "value": "Sound Recorder"
+ },
+ {
+ "name": "record",
+ "value": "Record"
+ },
+ {
+ "name": "player",
+ "value": "Player"
+ },
+ {
+ "name": "recorder",
+ "value": "Recorder"
+ },
+ {
+ "name": "short_sound_palyer",
+ "value": "Short Sound Player"
+ },
+ {
+ "name": "sound_player",
+ "value": "Sound Player"
+ },
+ {
+ "name": "play",
+ "value": "Play"
+ },
+ {
+ "name": "play_music_sound",
+ "value": "Play Music Sound"
+ },
+ {
+ "name": "play_tone_sound",
+ "value": "Play Tone Sound"
+ },
+ {
+ "name": "play_system_sound",
+ "value": "Play System Sound"
}
]
}
\ No newline at end of file
diff --git a/media/Audio/entry/src/main/resources/base/layout/audio_recorder_slice_layout.xml b/media/Audio/entry/src/main/resources/base/layout/audio_recorder_slice_layout.xml
index 211cb9e7497b2529d06d76e3aae7db8e10420250..02b1dafa838cc984c57b4dce47e7c4dca5b0025d 100644
--- a/media/Audio/entry/src/main/resources/base/layout/audio_recorder_slice_layout.xml
+++ b/media/Audio/entry/src/main/resources/base/layout/audio_recorder_slice_layout.xml
@@ -21,7 +21,7 @@
diff --git a/media/Audio/entry/src/main/resources/base/layout/main_ability_slice.xml b/media/Audio/entry/src/main/resources/base/layout/main_ability_slice.xml
index 757854044b2d8777e0c16d00b5ce74962a198719..7bf77b6cf1a9a1d597318c41b07c9dae395ce7d4 100644
--- a/media/Audio/entry/src/main/resources/base/layout/main_ability_slice.xml
+++ b/media/Audio/entry/src/main/resources/base/layout/main_ability_slice.xml
@@ -26,7 +26,7 @@
ohos:element_right="$media:ic_arrow_right"
ohos:left_padding="14vp"
ohos:padding="10vp"
- ohos:text="Player"
+ ohos:text="$string:play"
ohos:text_alignment="left"
ohos:text_size="16vp"
ohos:top_margin="10vp"/>
@@ -38,7 +38,7 @@
ohos:element_right="$media:ic_arrow_right"
ohos:left_padding="14vp"
ohos:padding="10vp"
- ohos:text="Recorder"
+ ohos:text="$string:recorder"
ohos:text_alignment="left"
ohos:text_size="16vp"
ohos:top_margin="10vp"/>
@@ -50,7 +50,7 @@
ohos:element_right="$media:ic_arrow_right"
ohos:left_padding="14vp"
ohos:padding="10vp"
- ohos:text="Short Sound Player"
+ ohos:text="$string:short_sound_palyer"
ohos:text_alignment="left"
ohos:text_size="16vp"
ohos:top_margin="10vp"/>
diff --git a/media/Audio/entry/src/main/resources/base/layout/player_slice_layout.xml b/media/Audio/entry/src/main/resources/base/layout/player_slice_layout.xml
index 842b972a9a96a7662677c9875d0db9dae71383b1..6bbed90b4d4ecc20605e220f3de730def7b47cc5 100644
--- a/media/Audio/entry/src/main/resources/base/layout/player_slice_layout.xml
+++ b/media/Audio/entry/src/main/resources/base/layout/player_slice_layout.xml
@@ -22,7 +22,7 @@
\ No newline at end of file
diff --git a/media/Audio/entry/src/main/resources/base/layout/short_sound_player_slice_layout.xml b/media/Audio/entry/src/main/resources/base/layout/short_sound_player_slice_layout.xml
index 004d315eff75152b6bd7aae90a0533a8530607d1..41482f5fb4c1b947e956e00337af3456850c49ef 100644
--- a/media/Audio/entry/src/main/resources/base/layout/short_sound_player_slice_layout.xml
+++ b/media/Audio/entry/src/main/resources/base/layout/short_sound_player_slice_layout.xml
@@ -28,7 +28,7 @@
ohos:left_margin="24vp"
ohos:padding="10vp"
ohos:right_margin="24vp"
- ohos:text="Play Music Sound"
+ ohos:text="$string:play_music_sound"
ohos:text_size="16vp"
ohos:top_margin="10vp"/>
@@ -42,7 +42,7 @@
ohos:top_margin="20vp"
ohos:padding="10vp"
ohos:right_margin="24vp"
- ohos:text="Play Tone Sound"
+ ohos:text="$string:play_tone_sound"
ohos:text_size="16vp"/>