This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun close() { | |
| try { | |
| isRunning = false | |
| receiveJob?.cancel() | |
| subSocket?.close() | |
| pubSocket?.close() | |
| context?.close() | |
| Log.d(TAG, "Disconnected from server") | |
| CoroutineScope(Dispatchers.Main).launch { onConnectionChanged?.invoke(false) } | |
| } catch (e: Exception) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun sendMessage(message: String) { | |
| if (!isRunning || pubSocket == null) { | |
| Log.e(TAG, "Cannot send message, client not connected") | |
| return | |
| } | |
| try { | |
| pubSocket?.send(message) | |
| Log.d(TAG, "Sent message to server: $message") | |
| } catch (e: ZMQException) { | |
| Log.e(TAG, "Error sending message or receiving response: ${e.message}", e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun startReceiving() { | |
| receiveJob = CoroutineScope(Dispatchers.IO).launch { | |
| try { | |
| while (isRunning && subSocket != null) { | |
| val message = subSocket?.recvStr() | |
| if (message != null) { | |
| Log.d(TAG, "Server received message: $message") | |
| messageCallback?.invoke(message) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun connect() { | |
| if (isRunning) return | |
| CoroutineScope(Dispatchers.IO).launch { | |
| try { | |
| context = ZContext() | |
| subPort?.let { | |
| subSocket = context?.createSocket(SocketType.SUB) | |
| subSocket?.subscribe("".toByteArray()) | |
| subSocket?.connect("tcp://127.0.0.1:$subPort") | |
| Log.d(TAG, "Subbing to $subPort") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import kotlinx.coroutines.CoroutineScope | |
| import kotlinx.coroutines.Dispatchers | |
| import kotlinx.coroutines.Job | |
| import kotlinx.coroutines.launch | |
| import org.zeromq.SocketType | |
| import org.zeromq.ZContext | |
| import org.zeromq.ZMQ | |
| import org.zeromq.ZMQException | |
| import java.io.Closeable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <service | |
| android:name=".service.QuickstartComplicationService" | |
| android:exported="true" | |
| android:label="@string/app_name" | |
| android:icon="@drawable/app_icon" | |
| android:permission="com.google.android.wearable.permission.BIND_COMPLICATION_PROVIDER"> | |
| <intent-filter> | |
| <action android:name="android.support.wearable.complications.ACTION_COMPLICATION_UPDATE_REQUEST" /> | |
| </intent-filter> | |
| <!-- Supported types should be comma-separated e.g. SHORT_TEXT,SMALL_IMAGE --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| return SmallImageComplicationData | |
| .Builder( | |
| SmallImage.Builder( | |
| icon, | |
| SmallImageType.ICON | |
| ).build(), | |
| PlainComplicationText.Builder(appName).build() | |
| ) | |
| .setTapAction(pendingIntent) | |
| .build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val launchIntent = packageManager.getLaunchIntentForPackage(packageName) | |
| val pendingIntent = PendingIntent.getActivity( | |
| this, | |
| 0, | |
| launchIntent, | |
| PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class QuickstartComplicationService: ComplicationDataSourceService() { | |
| override fun onComplicationRequest( | |
| request: ComplicationRequest, | |
| listener: ComplicationRequestListener | |
| ) { | |
| listener.onComplicationData(getComplicationData()) | |
| } | |
| override fun getPreviewData(type: ComplicationType): ComplicationData? { | |
| return getComplicationData() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <network-security-config> | |
| <!-- Disallow user-added CAs, use only system certs --> | |
| <base-config cleartextTrafficPermitted="false"> | |
| <trust-anchors> | |
| <certificates src="system" /> | |
| <!-- No user certs in secure profile --> | |
| </trust-anchors> | |
| </base-config> | |
| <!-- Allow user CAs only for debug builds to facilitate MITM demos --> | |
| <debug-overrides> |
NewerOlder