Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show QR code vendor tags in Android app #1491

Merged
merged 3 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/android/CHIPTool/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path file('CMakeLists.txt')
}
}
ndkVersion '21.3.6528147'

configurations.all {
resolutionStrategy.eachDependency {DependencyResolveDetails details ->
Expand All @@ -46,7 +40,7 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation fileTree(dir: "libs", include: ["*.jar", "*.so"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation "com.google.android.gms:play-services-vision:20.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,19 @@ class BarcodeFragment : Fragment(), CHIPBarcodeProcessor.BarcodeDetectionListene
stopCamera()

val payload = SetupPayloadParser().parseQrCode(barcode.displayValue)

val optionalQrCodeInfo = payload.optionalQRCodeInfo
val qrCodeInfoMap = HashMap<Int, QrCodeInfo>()
optionalQrCodeInfo.forEach { (i, info) ->
qrCodeInfoMap[i] = QrCodeInfo(info.tag, info.type, info.data, info.int32)
}

val deviceInfo = CHIPDeviceInfo(
payload.version,
payload.vendorId,
payload.productId,
payload.setupPinCode
payload.setupPinCode,
qrCodeInfoMap
)
FragmentUtil.getHost(this, Callback::class.java)?.onCHIPDeviceInfoReceived(deviceInfo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.google.chip.chiptool.R
import kotlinx.android.synthetic.main.chip_device_info_fragment.view.*

/** Show the [CHIPDeviceInfo]. */
class CHIPDeviceDetailsFragment : Fragment() {
Expand All @@ -41,12 +42,25 @@ class CHIPDeviceDetailsFragment : Fragment() {
return inflater.inflate(R.layout.chip_device_info_fragment, container, false).apply {

// Display CHIP setup code info to user for manual connect to soft AP
findViewById<TextView>(R.id.version_tv).apply { text = "${deviceInfo.version}" }
findViewById<TextView>(R.id.vendor_id_tv).apply { text = "${deviceInfo.vendorId}" }
findViewById<TextView>(R.id.product_id_tv).apply { text = "${deviceInfo.productId}" }
findViewById<TextView>(R.id.setup_code_tv).apply { text = "${deviceInfo.setupPinCode}" }
versionTv.text = "${deviceInfo.version}"
vendorIdTv.text = "${deviceInfo.vendorId}"
productIdTv.text = "${deviceInfo.productId}"
setupCodeTv.text = "${deviceInfo.setupPinCode}"

// TODO : Extract vendor tags for IP and SOFT AP SSID and display them here
if (deviceInfo.optionalQrCodeInfoMap.isEmpty()) {
vendorTagsLabelTv.visibility = View.GONE
vendorTagsContainer.visibility = View.GONE
} else {
vendorTagsLabelTv.visibility = View.VISIBLE
vendorTagsContainer.visibility = View.VISIBLE

deviceInfo.optionalQrCodeInfoMap.forEach { (_, qrCodeInfo) ->
val tv = inflater.inflate(R.layout.barcode_vendor_tag, null, false) as TextView
val info = "${qrCodeInfo.tag}. ${qrCodeInfo.data}, ${qrCodeInfo.intDataValue}"
tv.text = info
vendorTagsContainer.addView(tv)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ import kotlinx.android.parcel.Parcelize
val version: Int,
val vendorId: Int,
val productId: Int,
val setupPinCode: Long
val setupPinCode: Long,
val optionalQrCodeInfoMap: Map<Int, QrCodeInfo>
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.google.chip.chiptool.setuppayloadscanner

import android.os.Parcelable
import chip.setuppayload.OptionalQRCodeInfo.OptionalQRCodeInfoType
import kotlinx.android.parcel.Parcelize

@Parcelize data class QrCodeInfo(
val tag: Int,
val type: OptionalQRCodeInfoType,
val data: String,
val intDataValue: Int
) : Parcelable
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<TableRow xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
</TableRow>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:textSize="20sp"/>
Original file line number Diff line number Diff line change
@@ -1,105 +1,125 @@
<RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp">
android:layout_height="match_parent">

<TextView
android:id="@+id/title_tv"
android:text="@string/chip_device_info_title"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_alignParentTop="true"
android:textSize="20sp"/>
android:layout_margin="16dp">

<TextView
android:id="@+id/subtitle_tv"
android:text="@string/chip_device_info_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/title_tv"
android:textSize="20sp"/>
<TextView
android:id="@+id/titleTv"
android:text="@string/chip_device_info_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_alignParentTop="true"
android:textSize="20sp"/>

<TextView
android:id="@+id/version_label_tv"
android:text="@string/chip_device_info_version_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/subtitle_tv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/version_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/subtitle_tv"
android:layout_toEndOf="@id/version_label_tv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/subtitleTv"
android:text="@string/chip_device_info_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/titleTv"
android:textSize="20sp"/>

<TextView
android:id="@+id/vendor_label_tv"
android:text="@string/chip_device_info_vendor_id_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/version_label_tv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/vendor_id_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/version_label_tv"
android:layout_toEndOf="@id/vendor_label_tv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/versionLabelTv"
android:text="@string/chip_device_info_version_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/subtitleTv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/versionTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/subtitleTv"
android:layout_toEndOf="@id/versionLabelTv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>

<TextView
android:id="@+id/product_id_label_tv"
android:text="@string/chip_device_info_product_id_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/vendor_label_tv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/product_id_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/vendor_label_tv"
android:layout_toEndOf="@id/product_id_label_tv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/vendorLabelTv"
android:text="@string/chip_device_info_vendor_id_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/versionLabelTv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/vendorIdTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/versionLabelTv"
android:layout_toEndOf="@id/vendorLabelTv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>

<TextView
android:id="@+id/setup_code_label_tv"
android:text="@string/chip_device_info_setup_code_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/product_id_label_tv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/setup_code_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/product_id_label_tv"
android:layout_toEndOf="@id/setup_code_label_tv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>
</RelativeLayout>
<TextView
android:id="@+id/productIdLabelTv"
android:text="@string/chip_device_info_product_id_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/vendorLabelTv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/productIdTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/vendorLabelTv"
android:layout_toEndOf="@id/productIdLabelTv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>

<TextView
android:id="@+id/setupCodeLabelTv"
android:text="@string/chip_device_info_setup_code_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/productIdLabelTv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<TextView
android:id="@+id/setupCodeTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="8dp"
android:layout_below="@id/productIdLabelTv"
android:layout_toEndOf="@id/setupCodeLabelTv"
android:layout_alignParentEnd="true"
android:textSize="20sp"/>

<TextView
android:id="@+id/vendorTagsLabelTv"
android:text="@string/chip_device_info_optional_vendor_tags_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_below="@id/setupCodeLabelTv"
android:layout_alignParentStart="true"
android:textSize="20sp"/>
<LinearLayout
android:id="@+id/vendorTagsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/vendorTagsLabelTv"/>
</RelativeLayout>
</ScrollView>
1 change: 1 addition & 0 deletions src/android/CHIPTool/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string name="chip_device_info_vendor_id_label">Vendor ID:</string>
<string name="chip_device_info_product_id_label">Product ID:</string>
<string name="chip_device_info_setup_code_label">Setup PIN Code:</string>
<string name="chip_device_info_optional_vendor_tags_label">Optional Vendor tags:</string>
<string name="camera_permission_missing_alert_title">Camera permission missing</string>
<string name="camera_permission_missing_alert_subtitle">Camera permission required to be able to scan the QR code.</string>
<string name="camera_permission_missing_alert_try_again">Try again</string>
Expand Down
Loading