setting 优化

Signed-off-by: weiyunxing <weiyunxing@huawei.com>
This commit is contained in:
weiyunxing 2022-07-25 11:52:00 +08:00
parent 01bc4f495c
commit 020acfd5bc
20 changed files with 341 additions and 237 deletions

View File

@ -78,7 +78,7 @@ export struct SubEntryComponent {
@Component
export struct SubEntryComponentWithEndText {
@State isTouched: boolean = false;
@Prop endText: string;
private endText: string | Resource;
private targetPage: string;
private title: string | Resource;

View File

@ -87,7 +87,6 @@ export default class BluetoothDeviceController extends BaseSettingsController {
clearTimeout(this.discoveryStopTimeoutId);
}
BluetoothModel.unsubscribeStateChange();
BluetoothModel.unsubscribeBluetoothDeviceFind();
BluetoothModel.unsubscribeBondStateChange();
BluetoothModel.unsubscribeDeviceStateChange();

View File

@ -55,6 +55,7 @@ export class AboutDeviceModel extends BaseModel {
constructor(){
super();
this.urivar = this.getUri();
// @ts-ignore
this.dataAbilityHelper = featureAbility.acquireDataAbilityHelper(globalThis.settingsAbilityContext, this.uri);
}

View File

@ -15,80 +15,103 @@
import BaseModel from '../../../../../../../common/utils/src/main/ets/default/model/BaseModel';
import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
import Bundle from '@ohos.bundle';
//import ResMgr from '@ohos.resourceManager';
import appManager from '@ohos.application.appManager'
import osAccount from '@ohos.account.osAccount';
import ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
import {LogAll} from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator';
import { LogAll } from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogDecorator';
const INDEX = 0;
const IS_INCLUDE_ABILITY_INFO = 0;
const URI_PAGE = 'pages/applicationInfo';
let icon_arrow = $r('app.media.ic_settings_arrow');
let icon_default = $r('app.media.icon_default');
let icon_default_str = "";
const MODULE_TAG = ConfigData.TAG + 'application-> ';
/**
* app management service class
*/
@LogAll
export class AppManagementModel extends BaseModel {
private mBundleInfoList: any[]= [];
/**
* get application data
*/
setAppManagementListener() {
this.mBundleInfoList = [];
Bundle.getAllBundleInfo(IS_INCLUDE_ABILITY_INFO)
.then((data) => {
LogUtil.info('settings AppManagementModel setAppManagementListener getBundleInfos() start ');
LogUtil.info('settings AppManagementModel data.length: ' + data.length + ' data: ' + JSON.stringify(data));
this.getResourceItem(INDEX, data.length, data);
});
LogUtil.info('settings appManagement init AppManagementModel setAppManagementListener end');
}
private mBundleInfoList: any[] = [];
/**
* get resource information according to resource id
*
* @param index - array position
* @param count - array length
* @param data - data
*/
getResourceItem(index, count, data) {
LogUtil.info('settings AppManagementModel getIconItem start data.length' + data.length);
let imageValue = '';
let label = '';
let that = this;
LogUtil.info('settings AppManagementModel data[index].name :' + data[index].name);
try {
let appInfo = data[index].appInfo;
LogUtil.info('settings AppManagementModel getResourceManager appInfo.labelId:' + JSON.stringify(appInfo));
let bundleContext = globalThis.settingsAbilityContext.createBundleContext(data[index].name)
if (appInfo.labelId > 0) {
bundleContext.resourceManager.getString(appInfo.labelId, (error, value) => {
LogUtil.info('settings AppManagementModel getResourceManager value.length:' + value.length);
if (value != null) {
LogUtil.info('settings AppManagementModel getResourceManager getString() value:' + value);
label = value;
LogUtil.info('settings AppManagementModel getResourceManager getString() label:' + label);
constructor() {
super();
globalThis.settingsAbilityContext.resourceManager.getMediaBase64(icon_default)
.then((res) => {
icon_default_str = res;
LogUtil.info('settings AppManagementModel getResourceManager init defaultIcon res:' + icon_default_str);
})
.catch((err) => {
LogUtil.info('settings AppManagementModel getResourceManager init defaultIcon error:' + err);
});
}
/**
* get application data
*/
setAppManagementListener() {
this.mBundleInfoList = [];
Bundle.getAllBundleInfo(IS_INCLUDE_ABILITY_INFO)
.then((data) => {
LogUtil.info('settings AppManagementModel setAppManagementListener getBundleInfos() start ');
LogUtil.info('settings AppManagementModel data.length: ' + data.length + ' data: ' + JSON.stringify(data));
this.getResourceItem(INDEX, data.length, data);
});
LogUtil.info('settings appManagement init AppManagementModel setAppManagementListener end');
}
/**
* get resource information according to resource id
*
* @param index - array position
* @param count - array length
* @param data - data
*/
async getResourceItem(index, count, data) {
LogUtil.info('settings AppManagementModel getIconItem start data.length' + data.length);
let imageValue = '';
let label = '';
let that = this;
LogUtil.info('settings AppManagementModel data[index].name :' + data[index].name);
try {
let context = globalThis.settingsAbilityContext;
let appInfo = data[index].appInfo;
LogUtil.info('settings AppManagementModel getResourceManager appInfo.labelId:' + JSON.stringify(appInfo.labelResource));
if (appInfo.labelResource.id > 0) {
await context.resourceManager.getString(appInfo.labelResource)
.then((res) => {
label = res;
LogUtil.info('settings AppManagementModel getResourceManager getString() res:' + label);
})
.catch((err) => {
LogUtil.info('settings AppManagementModel getResourceManager getString() error:' + err);
});
} else {
LogUtil.info('settings AppManagementModel getResourceManager getString() error:' + error);
label = appInfo.label;
if (label.length == 0) {
label = appInfo.labelResource.bundleName;
}
LogUtil.info('settings AppManagementModel getResourceManager getString() id=0:' + appInfo.label);
}
});
} else {
LogUtil.info('settings AppManagementModel getResourceManager getString() label:' + appInfo.label);
label = appInfo.label;
}
LogUtil.info('settings AppManagementModel getResourceManager getString() finish label:' + label);
if (appInfo.iconId > 0) {
bundleContext.resourceManager.getMediaBase64(appInfo.iconId, (error, value) => {
LogUtil.info('settings AppManagementModel getMediaBase64 error:' + error);
if (error != null) {
LogUtil.info('settings AppManagementModel getMediaBase64 error!=null:' + error);
this.mBundleInfoList.push({
settingIcon: icon_default,
LogUtil.info('settings AppManagementModel getResourceManager getString() value:' + label);
LogUtil.info('settings AppManagementModel getResourceManager appInfo.iconResource:' + JSON.stringify(appInfo.iconResource));
if (appInfo.iconResource.id > 0) {
await context.resourceManager.getMediaBase64(appInfo.iconResource)
.then((res) => {
imageValue = res;
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() res:' + imageValue);
})
.catch((err) => {
LogUtil.info('settings AppManagementModel getResourceManager getString() error:' + err);
imageValue = icon_default_str;
});
} else {
imageValue = icon_default_str;
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() id=0:' + icon_default_str);
}
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() value:' + imageValue);
this.mBundleInfoList.push({
settingIcon: imageValue,
settingTitle: label,
settingValue: '',
settingArrow: icon_arrow,
@ -96,129 +119,91 @@ export class AppManagementModel extends BaseModel {
settingBundleName: data[index].name,
settingIconId: appInfo.iconId,
settingUri: URI_PAGE
});
if (count - 1 > index) {
});
if (count - 1 > index) {
LogUtil.info('settings AppManagementModel getMediaBase64() id=0:' + index + ' | count:' + count);
index = index + 1;
that.getResourceItem(index, count, data);
} else {
} else {
LogUtil.info('settings AppManagementModel getMediaBase64() id=0:' + index + ' | count:' + count);
LogUtil.info('settings AppManagementModel mBundleInfoList[i]: ' + JSON.stringify(this.mBundleInfoList));
AppStorage.SetOrCreate('appManagementList', this.mBundleInfoList);
}
}
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() :' + value.length);
if (value.length > 0) {
imageValue = value;
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() imageValue:' + imageValue);
} catch (error) {
LogUtil.error('settings AppManagementModel catch error:' + error);
}
LogUtil.info('settings appManagement AppManagementModel getIconItem end');
}
/**
* Remove duplicate item
*/
public distinct(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i].settingBundleName === arr[j].settingBundleName) {
arr.splice(j, 1);
j--;
}
}
LogUtil.info('settings AppManagementModel getResourceManager getMediaBase64() end');
this.mBundleInfoList.push({
settingIcon: imageValue,
settingTitle: label,
settingValue: '',
settingArrow: icon_arrow,
settingSummary: data[index].versionName,
settingBundleName: data[index].name,
settingIconId: appInfo.iconId,
settingUri: URI_PAGE
}
return arr;
}
/**
* Clear up application data by bundle name
* @param bundleName bundle name
*/
clearUpApplicationData(bundleName: string, callback) {
appManager.clearUpApplicationData(bundleName, callback);
}
/**
* Clears cache data of a specified application.
* @param bundleName bundle name
*/
cleanBundleCacheFiles(bundleName: string, callback) {
Bundle.cleanBundleCacheFiles(bundleName, callback);
}
/**
* Uninstall an application.
* @param bundleName bundle name
*/
async uninstall(bundleName: string, callback) {
LogUtil.info(ConfigData.TAG + "start uninstall in model");
const bundlerInstaller = await Bundle.getBundleInstaller();
const accountManager = await osAccount.getAccountManager();
const mUserID = await accountManager.getOsAccountLocalIdFromProcess();
LogUtil.info(ConfigData.TAG + "get bundlerInstaller : " + typeof bundlerInstaller);
bundlerInstaller.uninstall(bundleName,
{
userId: mUserID,
installFlag: 0,
isKeepData: false
}, (err, result) => {
AppStorage.SetOrCreate('appManagementList', []);
this.setAppManagementListener();
callback(err, result);
});
if (count - 1 > index) {
LogUtil.info('settings AppManagementModel getMediaBase64() if index:' + index + ' | count:' + count);
index = index + 1;
that.getResourceItem(index, count, data);
} else {
LogUtil.info('settings AppManagementModel getMediaBase64() else index:' + index + ' | count:' + count);
LogUtil.info('settings AppManagementModel mBundleInfoList[i]: ' + JSON.stringify(this.mBundleInfoList));
AppStorage.SetOrCreate('appManagementList', this.mBundleInfoList);
}
});
} else {
if (count - 1 > index) {
LogUtil.info('settings AppManagementModel getMediaBase64() id=0:' + index + ' | count:' + count);
index = index + 1;
that.getResourceItem(index, count, data);
} else {
LogUtil.info('settings AppManagementModel getMediaBase64() id=0:' + index + ' | count:' + count);
LogUtil.info('settings AppManagementModel mBundleInfoList[i]: ' + JSON.stringify(this.mBundleInfoList));
AppStorage.SetOrCreate('appManagementList', this.mBundleInfoList);
}
}
AppStorage.SetOrCreate('appManagementList', this.distinct(AppStorage.Get('appManagementList')));
} catch (error) {
LogUtil.error('settings AppManagementModel catch error:' + error);
LogUtil.info(ConfigData.TAG + "end uninstall in model");
}
LogUtil.info('settings appManagement AppManagementModel getIconItem end');
}
/**
* Remove duplicate item
*/
public distinct(arr){
for(let i = 0; i < arr.length; i++ ){
for(let j=i+1; j < arr.length; j++ ){
if(arr[i].settingBundleName === arr[j].settingBundleName){
arr.splice(j,1);
j--;
}
}
getBundleInfo(bundleName, callback) {
LogUtil.info(MODULE_TAG + 'start get bundle info');
Bundle.getBundleInfo(bundleName, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, callback);
LogUtil.info(MODULE_TAG + 'end get bundle info');
}
return arr;
}
/**
* Clear up application data by bundle name
* @param bundleName bundle name
*/
clearUpApplicationData(bundleName: string, callback) {
appManager.clearUpApplicationData(bundleName, callback);
}
/**
* Clears cache data of a specified application.
* @param bundleName bundle name
*/
cleanBundleCacheFiles(bundleName: string, callback) {
Bundle.cleanBundleCacheFiles(bundleName, callback);
}
/**
* Uninstall an application.
* @param bundleName bundle name
*/
async uninstall(bundleName: string, callback) {
LogUtil.info(ConfigData.TAG + "start uninstall in model");
const bundlerInstaller = await Bundle.getBundleInstaller();
const accountManager = await osAccount.getAccountManager();
const mUserID = await accountManager.getOsAccountLocalIdFromProcess();
LogUtil.info(ConfigData.TAG + "get bundlerInstaller : " + typeof bundlerInstaller);
bundlerInstaller.uninstall(bundleName,
{
userId: mUserID,
installFlag: 0,
isKeepData: false
}, (err, result) => {
AppStorage.SetOrCreate('appManagementList', []);
this.setAppManagementListener();
callback(err, result);
});
LogUtil.info(ConfigData.TAG + "end uninstall in model");
}
getBundleInfo(bundleName, callback) {
LogUtil.info(MODULE_TAG + 'start get bundle info');
Bundle.getBundleInfo(bundleName, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, callback);
LogUtil.info(MODULE_TAG + 'end get bundle info');
}
/**
* Kill processes by bundle name
* @param bundleName bundle name
*/
killProcessesByBundleName(bundleName: string, callback) {
appManager.killProcessesByBundleName(bundleName, callback);
}
/**
* Kill processes by bundle name
* @param bundleName bundle name
*/
killProcessesByBundleName(bundleName: string, callback) {
appManager.killProcessesByBundleName(bundleName, callback);
}
}
let appManagementModel = new AppManagementModel();

View File

@ -34,6 +34,7 @@ export class DateAndTimeModel extends BaseModel {
constructor() {
super();
this.urivar = this.getUri();
// @ts-ignore
this.dataAbilityHelper = featureAbility.acquireDataAbilityHelper(globalThis.settingsAbilityContext, this.uri);
}

View File

@ -39,6 +39,7 @@ export class BrightnessSettingModel extends BaseModel{
constructor() {
super();
this.urivar = this.getUri();
// @ts-ignore
this.dataAbilityHelper = featureAbility.acquireDataAbilityHelper(globalThis.settingsAbilityContext, this.uri);
this.updateValue();
}

View File

@ -12,23 +12,53 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import LogUtil from '../../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
import ConfigData from '../../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
import nfcController from '@ohos.nfc.controller';
export class NfcModel {
private isNfcOpen: boolean;
private TAG = ConfigData.TAG + 'NfcModel ';
const TAG = ConfigData.TAG + 'NfcModel: ';
export class NfcModel {
/**
* register Nfc Status change
* @param callback
*/
registerNfcStatusObserver(callback) {
LogUtil.info(TAG + 'start register nfc status observer' );
nfcController.on('nfcStateChange', (code) => {
AppStorage.SetOrCreate('nfcStatus', nfcController.isNfcOpen());
callback(code);
})
}
/**
* check whether NFC is open
* return boolean. true is mean of NFC open, false is mean of NFC close
*/
isNfcOpen(): boolean {
const isOpen: boolean = nfcController.isNfcOpen();
LogUtil.info(TAG + 'check nfc is open: ' + isOpen);
return isOpen;
}
/**
* open NFC
* return boolean. true is mean of NFC open success, false is mean of NFC open failed
*/
openNfc(): boolean {
let enableNfc = nfcController.openNfc()
LogUtil.info(this.TAG + enableNfc)
let enableNfc = nfcController.openNfc();
LogUtil.info(TAG + 'open nfc: ' + enableNfc);
return enableNfc;
}
/**
* close NFC
* return boolean. true is mean of NFC close success, false is mean of NFC close failed
*/
closeNfc(): boolean {
let disableNfc = nfcController.closeNfc()
LogUtil.info(this.TAG + disableNfc)
let disableNfc = nfcController.closeNfc();
LogUtil.info(TAG + 'close nfc' + disableNfc);
return disableNfc;
}
}

View File

@ -304,6 +304,7 @@ export class WifiModel extends BaseModel {
connectWiFi(password: string) {
let apInfo = this.userSelectedAp.getApInfo();
let ret = false;
let connectParam: any = {
"ssid": apInfo.ssid,
"bssid": apInfo.bssid,
@ -311,13 +312,20 @@ export class WifiModel extends BaseModel {
"isHiddenSsid": false, // we don't support connect to hidden ap yet
"securityType": apInfo.securityType
};
LogUtil.info(MODULE_TAG + 'disconnect WiFi isConnected is ' + wifi.isConnected());
if (wifi.isConnected() === true) {
wifi.disconnect();
ret = wifi.disconnect();
LogUtil.info(MODULE_TAG + 'disconnect WiFi ret is ' + ret);
this.registerWiFiConnectionObserver((code: Number) => {
if (code === 0) {
ret = wifi.connectToDevice(connectParam);
this.unregisterWiFiConnectionObserver();
}
})
}else{
ret = wifi.connectToDevice(connectParam);
LogUtil.info(MODULE_TAG + 'connect WiFi ret is ' + ret);
}
let ret = wifi.connectToDevice(connectParam);
LogUtil.info(MODULE_TAG + 'connect WiFi ret is ' + ret);
return ret;
}
@ -351,7 +359,7 @@ export class WifiModel extends BaseModel {
return WiFiEncryptMethodMap.OPEN;
}
if (apInfo.securityType === 2) {
return WiFiEncryptMethodMap.WPA;
return WiFiEncryptMethodMap.WEP;
}
return WiFiEncryptMethodMap.WPA2;
}

View File

@ -17,7 +17,12 @@ import ConfigData from '../../../../../../common/utils/src/main/ets/default/base
import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
import {SubEntryComponentWithEndText} from '../../../../../../common/component/src/main/ets/default/subEntryComponent';
import ResourceUtil from '../../../../../../common/search/src/main/ets/default/common/ResourceUtil';
import nfcController from '@ohos.nfc.controller';
import NfcModel from '../model/moreConnectionsImpl/NfcModel';
import display from '@ohos.display';
import deviceInfo from '@ohos.deviceInfo';
const TAG = ConfigData.TAG + 'MoreConnections: ';
const deviceTypeInfo = deviceInfo.deviceType;
/**
* MoreConnections
@ -27,12 +32,17 @@ import nfcController from '@ohos.nfc.controller';
struct MoreConnections {
@State columnMargin: string = '24vp';
@State nfcEnable: string = '';
@State isNfcEnable: boolean = false;
@StorageLink('nfcStatus') nfcStatus: boolean = NfcModel.isNfcOpen();
private maxScreenWidth;
private maxScreenHeight;
private nfcImageWidth;
private nfcImageHeight;
build() {
Column(){
GridContainer({columns:12, sizeType: SizeType.Auto, gutter: vp2px(1) === 2 ? '12vp' : '0vp', margin: vp2px(1) === 2 ? '24vp' : '0vp'}) {
Row({}) {
Column() {
GridContainer({columns: 12, sizeType: SizeType.Auto,
gutter: vp2px(1) === 2 ? '12vp' : '0vp', margin: vp2px(1) === 2 ? '24vp' : '0vp'}) {
Row() {
Column() {
}
.width(ConfigData.WH_100_100)
@ -45,12 +55,12 @@ struct MoreConnections {
Column() {
HeadComponent({ headName: $r('app.string.moreConnectionsTab'), isActive: true })
Column({space: this.columnMargin}){
SubEntryComponentWithEndText({targetPage:'pages/nfc', title: $r('app.string.NFC'), endText: this.nfcEnable})
SubEntryComponentWithEndText({targetPage:'pages/nfc', title: $r('app.string.NFC'), endText: this.nfcStatus ? $r("app.string.enabled") : $r("app.string.disabled")})
}
.margin({ top: $r("app.float.distance_8") })
.width(ConfigData.WH_100_100)
}
.padding({ left: $r('app.float.distance_24'), right: $r('app.float.distance_24') })
.margin({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
.width(ConfigData.WH_100_100)
.height(ConfigData.WH_100_100)
.useSizeType({
@ -79,19 +89,45 @@ struct MoreConnections {
}
aboutToAppear(){
LogUtil.info('settings moreConnections aboutToAppear in');
LogUtil.info(TAG + 'aboutToAppear in');
ResourceUtil.getString($r('app.float.distance_24')).then(value => this.columnMargin = value);
let nfcState = nfcController.getNfcState();
if (nfcState === ConfigData.STATE_ON) {
this.isNfcEnable = true;
this.nfcEnable = ConfigData.NFC_OPEN;
}
if (nfcState === ConfigData.STATE_OFF) {
this.isNfcEnable = false;
this.nfcEnable = ConfigData.NFC_CLOSE;
}
AppStorage.SetOrCreate('isNfcEnable', this.isNfcEnable)
LogUtil.info('settings moreConnections aboutToAppear out');
// get screen max width and max height to show nfc image width and height
display.getDefaultDisplay((err, data) => {
if (err.code) {
LogUtil.error(TAG + 'Failed to obtain the default display object. Code: ' + JSON.stringify(err));
return;
}
LogUtil.info(TAG + 'Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
// screen max width
this.maxScreenWidth = data.width;
// screen max height
this.maxScreenHeight = data.height;
if (deviceTypeInfo === 'phone') {
if (this.maxScreenWidth < this.maxScreenHeight / 2) {
this.nfcImageWidth = this.maxScreenWidth * 0.8;
this.nfcImageHeight = this.maxScreenWidth * 0.8;
} else {
this.nfcImageWidth = (this.maxScreenHeight / 2) * 0.8;
this.nfcImageHeight = (this.maxScreenHeight / 2) * 0.8;
}
}
else {
if (this.maxScreenHeight > this.maxScreenWidth / 2) {
this.nfcImageWidth = (this.maxScreenWidth / 2) * 0.7;
this.nfcImageHeight = (this.maxScreenWidth / 2) * 0.7;
} else {
this.nfcImageWidth = this.maxScreenHeight * 0.7;
this.nfcImageHeight = this.maxScreenHeight * 0.7;
}
}
AppStorage.SetOrCreate('nfcImageWidth', this.nfcImageWidth);
AppStorage.SetOrCreate('nfcImageHeight', this.nfcImageHeight);
LogUtil.info('cq=====' + this.nfcImageWidth + typeof(this.maxScreenHeight));
})
LogUtil.info(TAG + 'aboutToAppear out');
}
}

View File

@ -381,7 +381,7 @@ struct CurrentDialogBuilder {
.onClick((event) => {
LogUtil.info("Click to modify user image.")
let chooseImageDialog = new CustomDialogController({
builder: ChooseImageDialog({ controller: this.controller }),
builder: ChooseImageDialog(),
alignment: DialogAlignment.Bottom,
offset: ({ dx: 0, dy: '-24dp' }),
});

View File

@ -6,22 +6,26 @@
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or
{
"name": "bluetoothTab", agreed to in writing, software
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import LogUtil from '../../../../../../common/utils/src/main/ets/default/baseUtil/LogUtil';
import HeadComponent from '../../../../../../common/component/src/main/ets/default/headComponent';
import ConfigData from '../../../../../../common/utils/src/main/ets/default/baseUtil/ConfigData';
import NfcModel from '../model/moreConnectionsImpl/NfcModel';
const TAG = ConfigData.TAG + 'Nfc: ';
@Entry
@Component
struct Nfc {
@StorageLink('isNfcEnable') isNfcEnable: boolean = false;
@State isNfcEnable: boolean = false;
@StorageLink('nfcImageWidth') nfcImageWidth: number = null;
@StorageLink('nfcImageWidth') nfcImageHeight: number = null;
build() {
Column() {
@ -46,19 +50,19 @@ struct Nfc {
}
Image($r("app.media.ic_nfc"))
.height($r("app.float.wh_value_298"))
.width($r("app.float.wh_value_208"))
.width(this.nfcImageWidth + "px")
.height(this.nfcImageHeight + "px")
.margin({ top: $r("app.float.distance_19") })
Text($r("app.string.nfcTips"))
.fontFamily('HarmonyHeiTi')
.fontWeight(FontWeight.Regular)
.fontSize($r("app.float.font_14"))
.height($r("app.float.wh_value_19"))
.lineHeight($r("app.float.lineHeight_19"))
.fontColor($r("app.color.font_color_182431"))
.margin({ bottom: $r("app.float.distance_36"), top: $r("app.float.distance_27_5") })
.margin({ bottom: $r("app.float.distance_36"), top: $r("app.float.distance_24") })
.opacity($r("app.float.opacity_100_60"))
.textAlign(TextAlign.Center)
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
Row() {
@ -75,15 +79,20 @@ struct Nfc {
left: $r("app.float.wh_value_12") })
Toggle({ type: ToggleType.Switch, isOn: this.isNfcEnable })
.width('36vp')
.height('20vp')
.selectedColor('#007DFF')
.width($r("app.float.switch_toggle_width"))
.height($r("app.float.switch_toggle_height"))
.selectedColor($r("app.color.toggle_selected_color_007DFF"))
.margin({ right: $r('app.float.wh_value_6') })
.onChange((isOn: boolean) => {
if (isOn) {
this.isNfcEnable = !this.isNfcEnable;
if (this.isNfcEnable) {
// open NFC
NfcModel.openNfc()
LogUtil.info(TAG + 'enable nfc: ' + NfcModel.openNfc());
} else {
// close NFC
NfcModel.closeNfc()
LogUtil.info(TAG + 'disable nfc: ' + NfcModel.openNfc());
}
});
}
@ -93,11 +102,7 @@ struct Nfc {
.borderRadius($r('app.float.radius_24'))
}
.backgroundColor($r("sys.color.ohos_id_color_sub_background"))
.padding({
left: $r('app.float.wh_24'),
right: $r('app.float.wh_24'),
bottom: $r('app.float.distance_32')
})
.margin({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
.width(ConfigData.WH_100_100)
.height(ConfigData.WH_100_100)
.useSizeType({
@ -125,4 +130,16 @@ struct Nfc {
.width(ConfigData.WH_100_100)
.height(ConfigData.WH_100_100);
}
aboutToAppear() {
LogUtil.info(TAG + 'aboutToAppear in');
NfcModel.registerNfcStatusObserver((code) => {
LogUtil.info(TAG + 'aboutToAppear status code: ' + code);
this.isNfcEnable = NfcModel.isNfcOpen();
LogUtil.info(TAG + 'aboutToAppear nfc open status: ' + this.isNfcEnable);
})
// init nfc active status
this.isNfcEnable = NfcModel.isNfcOpen();
LogUtil.info(TAG + 'aboutToAppear out');
}
}

View File

@ -23,7 +23,7 @@ import Router from '@system.router';
import FeatureAbility from '@ohos.ability.featureAbility';
import { BaseData } from '../../../../../../common/utils/src/main/ets/default/bean/BaseData';
import deviceInfo from '@ohos.deviceInfo';
import parameter from '@ohos.systemParameter';
import parameter from '@ohos.systemparameter';
const PAGE_SEARCH = 'pages/searchPage'; // for search
const deviceTypeInfo = deviceInfo.deviceType
@ -652,10 +652,12 @@ struct bluetoothItemComponent {
aboutToAppear() {
LogUtil.info('settings SettingList bluetoothItem aboutToAppear in');
this.bluetoothIsOn = BluetoothModel.isStateOn();
LogUtil.info('settings SettingList bluetoothItem aboutToAppear end');
}
onPageShow(){
BluetoothModel.subscribeStateChange((isOn: boolean) => {
AppStorage.SetOrCreate('bluetoothIsOn', isOn);
});
LogUtil.info('settings SettingList bluetoothItem aboutToAppear end');
}
aboutToDisappear() {

View File

@ -319,10 +319,12 @@ struct Index {
}
// as the ConnectionStateChange event is diff with the getLinkInfo callback,
// we always get the diff status between them
if (this.connectedWiFi.settingTitle === '') {
return false
let titleSign: boolean = (!!this.connectedWiFi.settingTitle) && (this.connectedWiFi.settingTitle.length > 0);
let arrowSign: boolean = (!!this.connectedWiFi.settingArrow) && (this.connectedWiFi.settingArrow.length > 0);
if(titleSign && arrowSign){
return true;
}
return true;
return false;
}
jumpToConnectApPage(apInfo: WifiScanInfo) {
@ -379,6 +381,8 @@ struct Index {
} else {
this.isPhone = false
}
AppStorage.SetOrCreate('slConnectedWifi', (new ApScanResult()).renderToListModel());
}
aboutToDisappear(): void {

View File

@ -41,6 +41,7 @@ struct WifiPsd {
private tobeConnectedAp: WifiScanInfo = null;
private isConnectedBefore: boolean = false;
private taskId: number = -1;
private toConnected: boolean = false;
@State isPhone: boolean = false
@State @Watch("controlFailedDialog") ControlFailedDialog : boolean = false;
private connectDialog: CustomDialogController = new CustomDialogController({
@ -172,6 +173,7 @@ struct WifiPsd {
() => {
WifiModel.setUserSelectedAp(this.tobeConnectedAp);
WifiModel.connectWiFi(this.userInputs);
this.toConnected = true;
this.connectDialog.open();
});
}
@ -229,6 +231,7 @@ struct WifiPsd {
}
this.initTextInputHint();
this.isConnectedBefore = wifi.isConnected();
if (this.isConnectedBefore) {
LogUtil.info(MODULE_TAG + 'start task');
this.startLinkedInfoTask();
@ -315,7 +318,8 @@ struct WifiPsd {
});
WifiModel.refreshApScanResults();
}
if (result.connState === 6) {
if (result.connState === 6 && this.toConnected) {
this.toConnected = false;
this.connectDialog.close()
this.failedDialog.open()
WifiModel.removeDeviceConfig(this.tobeConnectedAp);

View File

@ -44,6 +44,10 @@
"name": "font_color_007DFF",
"value": "#007DFF"
},
{
"name": "toggle_selected_color_007DFF",
"value": "#007DFF"
},
{
"name": "search_no_result_text_color",
"value": "$color:font_color_182431"

View File

@ -188,10 +188,6 @@
"name": "wh_value_200",
"value": "200vp"
},
{
"name": "wh_value_208",
"value": "208vp"
},
{
"name": "wh_value_210",
"value": "210vp"
@ -220,10 +216,6 @@
"name": "wh_value_280",
"value": "280vp"
},
{
"name": "wh_value_298",
"value": "298vp"
},
{
"name": "wh_value_336",
"value": "336vp"
@ -416,10 +408,6 @@
"name": "distance_26",
"value": "26vp"
},
{
"name": "distance_27_5",
"value": "27.5vp"
},
{
"name": "distance_30",
"value": "30vp"

View File

@ -462,7 +462,7 @@
},
{
"name": "isCreatingUser",
"value": "正在创建..."
"value": "Is Creating User..."
},
{
"name": "isRemoving",
@ -817,7 +817,7 @@
"value": "Brightness"
},
{
"name": "Screen",
"name": "screen",
"value": "Screen"
},
{
@ -1032,6 +1032,10 @@
"name": "softwareUpdateFailed",
"value": "Software update startup failed, please make sure the function is available."
},
{
"name": "add",
"value": "Add"
},
{
"name": "MANAGE_LOCAL_ACCOUNTS",
"value": "MANAGE LOCAL ACCOUNTS"

View File

@ -995,6 +995,10 @@
{
"name": "head_font_24",
"value": "20vp"
},
{
"name": "opacity_100_60",
"value": "0.6"
}
]
}

View File

@ -8,6 +8,18 @@
"name": "mainability_description",
"value": "ETS_Empty Feature Ability"
},
{
"name": "moreConnectionsTab",
"value": "更多连接"
},
{
"name": "NFC",
"value": "NFC"
},
{
"name": "nfcTips",
"value": "若要进行移动支付、钥匙验证、碰一碰等操作,可将本设备背部触碰其他终端 NFC 感应区。"
},
{
"name": "enabled",
"value": "已开启"

View File

@ -1036,6 +1036,10 @@
"name": "softwareUpdateFailed",
"value": "软件更新启动失败,请确定该功能是否可用"
},
{
"name": "add",
"value": "添加"
},
{
"name": "MANAGE_LOCAL_ACCOUNTS",
"value": "管理本地帐户"