/BALI-Demo

Demo to show ongoing notification on Huawei P50 Pocket

Primary LanguageKotlin

Bali Demo

Demo code to show different ongoing notification types on the Huawei P50 Pocket external screen.

Currently the external screen provides THREE different templates

Add a bundle to your on going notification with a Json template:

val bundle = Bundle()
val resJson = gson.toJson(templateDemo)
bundle.putString("res_id", resJson)
bundle.putInt("notification_index", templateIndex.ordinal) //0, 1, 2
bundle.putParcelable("extra_icon", Icon.createWithResource(this, iconRes))
. . .
notificationBuilder.setExtras(bundle)

Template 0 (Navigation Scenario):

gif_navigation

{
  "contentColor": 0,
  "disColor": -16776961,
  "disColorContent": "Arrive",
  "secondlyColor": -1,
  "templateContent": "Arrive at Cloud Park, Longgang District, Shenzhen City, Guangdong Province",
  "titleColor": -1
}

navigation

Template 1 (Taxi Order Scenario):

gif_taxi

{
  "templateBottom": {
    "disContents": [
      {
        "disContent": "2km",
        "disContentColor": -1
      },
      {
        "disContent": "2min",
        "disContentColor": -1
      }
    ],
    "oriContent": "Distance: 2km, 2min",
    "oriContentColor": -5592406
  },
  "templateContentFirst": {
    "disContents": [],
    "oriContent": "BD51-SMR",
    "oriContentColor": -1
  },
  "templateContentSecondly": {
    "disContents": [],
    "oriContent": "Audi A3 - White",
    "oriContentColor": -5592406
  },
  "templateTitle": "Driver on the way",
  "titleColor": -246245
}

taxi_order

Icon is from Freepik: Taxi icons created by Freepik - Flaticon

Template 2 (Sport Scenario):

gif_steps

{
  "bottomContent": "934m",
  "bottomContentColor": -1711276033,
  "midContent": "1.315",
  "midContentBigSize": true,
  "midContentColor": -419430401,
  "progress": 66,
  "progressBgColor": -13816018,
  "progressColor": -15292417,
  "templateTitle": "Steps",
  "titleColor": -419430401
}

steps_counter

Icon is from Freepik: Step icons created by Freepik - Flaticon

Make sure to update the notification every time the phone is folded

val listener = object : FoldableStateListener {
    override fun onStateChange(bundle: Bundle?) {
        val foldableState : Int = bundle?.getInt(EXTRA_FOLD_STATE, 0) ?: 0

        if(foldableState == FOLD_STATE_FOLDED) {
            notificationManager.notify(NOTIFICATION_ID, notification)
        }
    }
}
registerFoldStateListener(listener)

Proguard

Make sure to exclude the JSON model object and com.huawei.android.fsm classes

-keep class com.minkiapps.balidemo.domain.**{*;}
-keep class com.huawei.android.fsm.**{*;}

How to make screenshot from external screen

adb shell screencap -p -d 1 /sdcard/sc.png
adb pull /sdcard/sc.png ~/Desktop