diff --git a/mobiledatasettings/src/main/ets/common/components/headComponent.ets b/mobiledatasettings/src/main/ets/common/components/headComponent.ets index 42700ea..be6d9e3 100644 --- a/mobiledatasettings/src/main/ets/common/components/headComponent.ets +++ b/mobiledatasettings/src/main/ets/common/components/headComponent.ets @@ -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) diff --git a/mobiledatasettings/src/main/ets/common/components/networkStandItem.ets b/mobiledatasettings/src/main/ets/common/components/networkStandItem.ets new file mode 100644 index 0000000..9f30ecf --- /dev/null +++ b/mobiledatasettings/src/main/ets/common/components/networkStandItem.ets @@ -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 + }) + } +} \ No newline at end of file diff --git a/mobiledatasettings/src/main/ets/pages/index.ets b/mobiledatasettings/src/main/ets/pages/index.ets index a59536e..71c9180 100644 --- a/mobiledatasettings/src/main/ets/pages/index.ets +++ b/mobiledatasettings/src/main/ets/pages/index.ets @@ -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, diff --git a/mobiledatasettings/src/main/ets/pages/networkStand.ets b/mobiledatasettings/src/main/ets/pages/networkStand.ets new file mode 100644 index 0000000..9523515 --- /dev/null +++ b/mobiledatasettings/src/main/ets/pages/networkStand.ets @@ -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')) + } +} \ No newline at end of file diff --git a/mobiledatasettings/src/main/resources/base/element/string.json b/mobiledatasettings/src/main/resources/base/element/string.json index 2892fb7..58bc26c 100644 --- a/mobiledatasettings/src/main/resources/base/element/string.json +++ b/mobiledatasettings/src/main/resources/base/element/string.json @@ -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" } ] } \ No newline at end of file diff --git a/mobiledatasettings/src/main/resources/base/media/ic_redio_check.png b/mobiledatasettings/src/main/resources/base/media/ic_redio_check.png new file mode 100644 index 0000000..ce8018d Binary files /dev/null and b/mobiledatasettings/src/main/resources/base/media/ic_redio_check.png differ diff --git a/mobiledatasettings/src/main/resources/base/profile/main_pages.json b/mobiledatasettings/src/main/resources/base/profile/main_pages.json index feec276..37c9665 100644 --- a/mobiledatasettings/src/main/resources/base/profile/main_pages.json +++ b/mobiledatasettings/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/index" - ] + "pages/index", + "pages/networkStand" ] } diff --git a/mobiledatasettings/src/main/resources/zh_CN/element/string.json b/mobiledatasettings/src/main/resources/zh_CN/element/string.json index afa9e8d..9f3a89a 100644 --- a/mobiledatasettings/src/main/resources/zh_CN/element/string.json +++ b/mobiledatasettings/src/main/resources/zh_CN/element/string.json @@ -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": "网络类型选择" } ] } \ No newline at end of file