Skip to content

Commit cb58ba5

Browse files
committed
OpenHarmony: shell update
1 parent e954eb5 commit cb58ba5

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

ohos-project/AppScope/resources/base/element/string.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
{
44
"name": "app_name",
55
"value": "MyApplication"
6+
},
7+
{
8+
"name": "perm_reason",
9+
"value": "Subsystem for SDL / SDL 子系统"
610
}
711
]
812
}

ohos-project/entry/oh-package-lock.json5

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ohos-project/entry/src/main/cpp/napi_init.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "SDL3/SDL_timer.h"
66
#include "SDL3/SDL_video.h"
77
#include "SDL3/SDL_vulkan.h"
8+
#include "SDL3/SDL_locale.h"
89
#include "napi/native_api.h"
910
#include "SDL3/SDL_log.h"
1011
#include "SDL3/SDL_hints.h"
@@ -73,7 +74,9 @@ int main()
7374
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
7475
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
7576
SDL_Init(SDL_INIT_VIDEO);
76-
SDL_Log("Main func invoke !!!");
77+
int i = 0;
78+
auto t = SDL_GetPreferredLocales(&i);
79+
SDL_Log("Main func invoke !!! %s %s", t[0]->country, t[0]->language);
7780
// SDL_GL_LoadLibrary("libGLESv2.so");
7881
SDL_Log("sdl error: %s", SDL_GetError());
7982
SDL_Window* win = SDL_CreateWindow("test", 1024, 1024, SDL_WINDOW_OPENGL);

ohos-project/entry/src/main/ets/entryability/EntryAbility.ets

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1-
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
1+
import { abilityAccessCtrl, AbilityConstant,
2+
common,
3+
ConfigurationConstant,
4+
Permissions,
5+
UIAbility, Want } from '@kit.AbilityKit';
26
import { hilog } from '@kit.PerformanceAnalysisKit';
3-
import { window } from '@kit.ArkUI';
7+
import { promptAction, window } from '@kit.ArkUI';
48
import { KeyboardAvoidMode } from '@ohos.arkui.UIContext';
9+
import { BusinessError } from '@kit.BasicServicesKit';
510

611
const DOMAIN = 0x0000;
712

13+
const permissions: Array<Permissions> = ['ohos.permission.INPUT_KEYBOARD_CONTROLLER'];
14+
function reqPermissionsFromUser(permissions: Array<Permissions>, context: common.UIAbilityContext): void {
15+
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
16+
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
17+
let grantStatus: Array<number> = data.authResults;
18+
let length: number = grantStatus.length;
19+
for (let i = 0; i < length; i++) {
20+
if (grantStatus[i] === 0) {
21+
promptAction.showDialog({title: "permissions", message: "granted", buttons: [{text: 'Ok', color: '#999999'}]});
22+
} else {
23+
promptAction.showDialog({title: "permissions", message: "not granted", buttons: [{text: 'Ok', color: '#999999'}]});
24+
return;
25+
}
26+
}
27+
// 授权成功
28+
}).catch((err: BusinessError) => {
29+
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
30+
})
31+
}
32+
833
export default class EntryAbility extends UIAbility {
934
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
1035
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
@@ -20,6 +45,7 @@ export default class EntryAbility extends UIAbility {
2045
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
2146

2247
windowStage.loadContent('pages/Index', (err) => {
48+
reqPermissionsFromUser(permissions, this.context);
2349
if (err.code) {
2450
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
2551
return;

ohos-project/entry/src/main/ets/pages/Index.ets

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@ export class ArkNapiCallback {
1010
sdltest.sdlLaunchMain("libentry.so", "main")
1111
}
1212
showDialog(title: string, message: string) {
13-
promptAction.showDialog({title: title, message: message, buttons: [{text: 'Ok', color: '#999999'}]});
13+
promptAction.showDialog({title: title, message: message, buttons: [{text: 'Ok', color: '#999999'}]})
1414
}
1515
fetchLocale(): string {
16-
let locale = new intl.Locale();
17-
return locale.toString();
16+
let locale = new intl.Locale()
17+
return locale.language + "_" + locale.region
1818
}
1919
test(): number {
20-
hilog.info(DOMAIN, 'testTag', 'Call from native !!!');
21-
focusControl.requestFocus("inputHandler")
22-
let locale = new intl.Locale();
23-
hilog.info(DOMAIN, 'testTag', locale.toString());
24-
return 1;
20+
hilog.info(DOMAIN, 'testTag', 'Call from native !!!')
21+
return 1
2522
}
2623
}
2724

ohos-project/oh-package-lock.json5

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)