mirror of
https://gitee.com/openharmony/applications_call
synced 2024-11-22 22:09:41 +00:00
获取当前SIM卡网络制式并显示列表,提供手动设置移动网络制式的操作
Signed-off-by: 陈锐 <ruichendj@isoftstone.com>
This commit is contained in:
parent
99da06d094
commit
d2ecea1372
@ -13,6 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import LogUtils from '../utils/LogUtils'
|
||||
import { Router } from '@ohos.arkui.UIContext';
|
||||
import router from '@ohos.router';
|
||||
|
||||
const TAG = 'HeadComponent'
|
||||
|
||||
@ -21,7 +23,9 @@ const TAG = 'HeadComponent'
|
||||
*/
|
||||
@Component
|
||||
export default struct HeadComponent {
|
||||
@State isTouch: boolean = false;
|
||||
@State isTouch?: boolean = false;
|
||||
title: Resource = $r('app.string.mobile_data');
|
||||
isTerminateSelf: boolean = true
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
@ -34,9 +38,13 @@ export default struct HeadComponent {
|
||||
.margin({ right: 16 })
|
||||
.backgroundColor(this.isTouch ? $r('app.color.color_E3E3E3_grey') : $r('app.color.color_00000000_transparent'))
|
||||
.onClick(() => {
|
||||
globalThis.settingsAbilityContext?.terminateSelf().then((data) => {
|
||||
LogUtils.i(TAG, 'terminateSelfCallBack');
|
||||
});
|
||||
if (this.isTerminateSelf) {
|
||||
globalThis.settingsAbilityContext?.terminateSelf().then((data) => {
|
||||
LogUtils.i(TAG, "terminateSelfCallBack");
|
||||
});
|
||||
} else {
|
||||
router.back()
|
||||
}
|
||||
})
|
||||
.onTouch((event: TouchEvent) => {
|
||||
if (event.type === TouchType.Down) {
|
||||
@ -47,7 +55,7 @@ export default struct HeadComponent {
|
||||
}
|
||||
});
|
||||
|
||||
Text($r('app.string.mobile_data'))
|
||||
Text(this.title)
|
||||
.fontSize(20)
|
||||
.fontFamily('HarmonyHeiTi-Bold')
|
||||
.fontWeight(FontWeight.Medium)
|
||||
|
@ -0,0 +1,42 @@
|
||||
@Preview
|
||||
@Component
|
||||
export default struct NetworkStandItem {
|
||||
@Link networkMode: number;
|
||||
title: ResourceStr = '';
|
||||
thisNetworkMode: number = 5
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Row() {
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
|
||||
Column() {
|
||||
Text(this.title)
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontSize($r('sys.float.ohos_id_text_size_body1'))
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor($r('sys.color.ohos_id_color_text_primary'))
|
||||
.opacity(this.networkMode == this.thisNetworkMode ? 0.9 : 0.6)
|
||||
.letterSpacing(1)
|
||||
.lineHeight(22)
|
||||
.textAlign(TextAlign.Start)
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.margin({ right: 26 })
|
||||
|
||||
Image(this.networkMode == this.thisNetworkMode ? $r('app.media.ic_redio_check') : '')
|
||||
.width(24)
|
||||
.height(24)
|
||||
}
|
||||
}
|
||||
}
|
||||
.height(50)
|
||||
.justifyContent(FlexAlign.Center)
|
||||
.borderRadius(16)
|
||||
.margin({ top: 5, left: 10, right: 10, bottom: 5 })
|
||||
.padding({ left: 10, right: 10 })
|
||||
.onClick(() => {
|
||||
this.networkMode = this.thisNetworkMode
|
||||
})
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ import {
|
||||
import HeadComponent from '../common/components/headComponent';
|
||||
import { SubHeader } from '../common/components/subHeader';
|
||||
import LogUtils from '../common/utils/LogUtils';
|
||||
import router from '@ohos.router';
|
||||
|
||||
const TAG = 'Index';
|
||||
|
||||
@ -80,6 +81,8 @@ struct Index {
|
||||
@State ceshi: boolean = false;
|
||||
@State cardOne: number = 0;
|
||||
@State cardTwo: number = 1;
|
||||
@State controllerMobileNetworkIsOn: boolean = false;
|
||||
childComponentTitle:Resource=$r('app.string.mobile_data')
|
||||
|
||||
/**
|
||||
* Get network mode
|
||||
@ -321,13 +324,28 @@ struct Index {
|
||||
}
|
||||
}
|
||||
|
||||
clickHandle(click:number) {
|
||||
switch (click) {
|
||||
case 0:
|
||||
router.pushUrl({
|
||||
url: 'pages/networkStand'
|
||||
})
|
||||
break
|
||||
case 1:
|
||||
router.pushUrl({
|
||||
url: 'pages/apnSettings'
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
GridRow({ columns: { sm: 4, md: 8, lg: 12 }, gutter: { x: 12 } }) {
|
||||
GridCol({ span: { sm: 4, md: 8, lg: 8 }, offset: { sm: 0, md: 1, lg: 2 } }) {
|
||||
Column() {
|
||||
Column() {
|
||||
|
||||
HeadComponent();
|
||||
HeadComponent({isTouch:true,title:this.childComponentTitle});
|
||||
|
||||
Stack({ alignContent: Alignment.TopStart }) {
|
||||
Scroll(this.scroller) {
|
||||
@ -432,6 +450,50 @@ struct Index {
|
||||
isCard: true,
|
||||
isCon: 22,
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color("#E3E3E3")
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ right: '2%' })
|
||||
|
||||
Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
|
||||
Column() {
|
||||
Text( $r('app.string.network_standard'))
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontSize($r('sys.float.ohos_id_text_size_body1'))
|
||||
.fontWeight(FontWeight.Medium)
|
||||
.fontColor($r('sys.color.ohos_id_color_text_primary'))
|
||||
.opacity((this.simStateStatusCardOne && !this.controllerMobileNetworkIsOn) ? 0.9 : 0.6)
|
||||
.letterSpacing(1)
|
||||
.lineHeight(22)
|
||||
.textAlign(TextAlign.Start)
|
||||
Text( $r('app.string.network_standard_select'))
|
||||
.margin({ top: 2 })
|
||||
.fontFamily('HarmonyHeiTi')
|
||||
.fontWeight(FontWeight.Regular)
|
||||
.fontSize($r('sys.float.ohos_id_text_size_body2'))
|
||||
.fontColor($r('sys.color.ohos_id_color_text_secondary'))
|
||||
.opacity(0.6)
|
||||
.lineHeight(19)
|
||||
.letterSpacing(1)
|
||||
}
|
||||
.width('100%')
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
.margin({ right: 26 })
|
||||
Image($r('app.media.next_icon'))
|
||||
.width(10)
|
||||
.height(15)
|
||||
.margin({ right: 10 })
|
||||
.enabled(this.simStateStatusCardOne && !this.controllerMobileNetworkIsOn)
|
||||
|
||||
}.backgroundColor($r("sys.color.ohos_id_color_foreground_contrary"))
|
||||
.opacity((this.simStateStatusCardOne && !this.controllerMobileNetworkIsOn) ? 1 : 0.4)
|
||||
.margin({ top: 8, bottom: this.isSupport ? 5 : 11 })
|
||||
.onClick(() => {
|
||||
if ((this.simStateStatusCardOne && !this.controllerMobileNetworkIsOn)) {
|
||||
this.clickHandle(0)
|
||||
}
|
||||
})
|
||||
}
|
||||
.padding({
|
||||
left: 12,
|
||||
|
134
mobiledatasettings/src/main/ets/pages/networkStand.ets
Normal file
134
mobiledatasettings/src/main/ets/pages/networkStand.ets
Normal file
@ -0,0 +1,134 @@
|
||||
import NetworkStandItem from '../common/components/networkStandItem';
|
||||
import radio from '@ohos.telephony.radio';
|
||||
import HeadComponent from '../common/components/headComponent';
|
||||
import LogUtils from '../common/utils/LogUtils';
|
||||
|
||||
const TAG = 'NetworkStand';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct NetworkStand {
|
||||
@State @Watch('networkModeChanged') networkMode: number = 5
|
||||
@State slotId: number = 0;
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.getPreferredNetwork(this.slotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network mode
|
||||
*
|
||||
* @param {Object} slotId - call slotId
|
||||
*/
|
||||
async getPreferredNetwork(slotId) {
|
||||
|
||||
radio.getPreferredNetwork(slotId, (err, data: radio.PreferredNetworkMode) => {
|
||||
if (err) {
|
||||
LogUtils.e(TAG, 'getPreferredNetwork error, callback: data->' + JSON.stringify(err))
|
||||
return;
|
||||
}
|
||||
|
||||
this.networkMode = data
|
||||
LogUtils.i(TAG, 'getPreferredNetwork success, callback: data-> ' + JSON.stringify(data))
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
networkModeChanged() {
|
||||
LogUtils.i(TAG, 'networkMode Changed data-> ' + JSON.stringify(this.networkMode))
|
||||
try {
|
||||
radio.setPreferredNetwork(this.slotId, this.networkMode).then(() => {
|
||||
LogUtils.i(TAG, 'set 0 Preferred Network-> ' + JSON.stringify(this.networkMode) + ' success')
|
||||
}).catch((err) => {
|
||||
LogUtils.i(TAG, 'set 0 Preferred Network-> ' + JSON.stringify(this.networkMode) + ' failed' + JSON.stringify(err))
|
||||
});
|
||||
} catch (err) {
|
||||
LogUtils.i(TAG, 'set 0 Preferred Network-> ' + JSON.stringify(this.networkMode) + ' failed tryCatch ' + JSON.stringify(err))
|
||||
}
|
||||
}
|
||||
|
||||
build() {
|
||||
|
||||
Column() {
|
||||
HeadComponent({ title: $r('app.string.network_standard_select'), isTerminateSelf: false });
|
||||
Column() {
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_fiveAuto'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_NR_LTE_WCDMA_GSM//34
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_fourAuto'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_LTE_WCDMA_GSM //5
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_threeAuto'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_WCDMA_GSM//6
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_only_5g'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_NR//31
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_only_4g'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_LTE//3
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_only_3g'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_WCDMA//2
|
||||
})
|
||||
Divider()
|
||||
.strokeWidth(0.5)
|
||||
.color('#E3E3E3')
|
||||
.lineCap(LineCapStyle.Round)
|
||||
.margin({ left: '2%', right: '2%' })
|
||||
NetworkStandItem({
|
||||
networkMode: $networkMode,
|
||||
title: $r('app.string.mobile_data_2g'),
|
||||
thisNetworkMode: radio.PreferredNetworkMode.PREFERRED_NETWORK_MODE_GSM//1
|
||||
})
|
||||
}
|
||||
.padding({
|
||||
left: 4,
|
||||
right: 4,
|
||||
top: 4,
|
||||
bottom: 4
|
||||
})
|
||||
.width('90%')
|
||||
.borderRadius(16)
|
||||
.backgroundColor(Color.White)
|
||||
}.height('100%')
|
||||
.width('100%')
|
||||
.backgroundColor($r('sys.color.ohos_id_color_sub_background'))
|
||||
}
|
||||
}
|
@ -62,15 +62,15 @@
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_fiveAuto",
|
||||
"value": "5G/4G/3G/2G Auto Select"
|
||||
"value": "5G Network First"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_fourAuto",
|
||||
"value": "4G/3G/2G Auto Select"
|
||||
"value": "4G Network First"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_threeAuto",
|
||||
"value": "3G/2G Auto Select"
|
||||
"value": "3G Network First"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_twoOnly",
|
||||
@ -128,6 +128,18 @@
|
||||
"name": "mobile_data_3g",
|
||||
"value": "3G/2G automatic selection"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_5g",
|
||||
"value": "5G only"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_4g",
|
||||
"value": "4G only"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_3g",
|
||||
"value": "3G only"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_2g",
|
||||
"value": "2G only"
|
||||
@ -167,6 +179,14 @@
|
||||
{
|
||||
"name": "MANAGE_SECURE_SETTINGS",
|
||||
"value": "manage secure settings"
|
||||
},
|
||||
{
|
||||
"name": "network_standard",
|
||||
"value": "Network Standard"
|
||||
},
|
||||
{
|
||||
"name": "network_standard_select",
|
||||
"value": "Select The Network Type"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
@ -1,5 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/index"
|
||||
]
|
||||
"pages/index",
|
||||
"pages/networkStand" ]
|
||||
}
|
||||
|
@ -62,15 +62,15 @@
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_fiveAuto",
|
||||
"value": "5G/4G/3G/2G 自动选择"
|
||||
"value": "5G网络优先"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_fourAuto",
|
||||
"value": "4G/3G/2G 自动选择"
|
||||
"value": "4G网络优先"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_threeAuto",
|
||||
"value": "3G/2G 自动选择"
|
||||
"value": "3G网络优先"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_twoOnly",
|
||||
@ -128,9 +128,21 @@
|
||||
"name": "mobile_data_3g",
|
||||
"value": "3G/2G 自动选择"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_5g",
|
||||
"value": "仅使用5G网络"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_4g",
|
||||
"value": "仅使用4G网络"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_only_3g",
|
||||
"value": "仅使用3G网络"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_2g",
|
||||
"value": "仅 2G"
|
||||
"value": "仅使用2G网络"
|
||||
},
|
||||
{
|
||||
"name": "mobile_data_tips",
|
||||
@ -167,6 +179,14 @@
|
||||
{
|
||||
"name": "MANAGE_SECURE_SETTINGS",
|
||||
"value": "管理安全设置"
|
||||
},
|
||||
{
|
||||
"name": "network_standard",
|
||||
"value": "网络制式"
|
||||
},
|
||||
{
|
||||
"name": "network_standard_select",
|
||||
"value": "网络类型选择"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user