Skip to content

Instantly share code, notes, and snippets.

@Xiryl
Xiryl / appscript.json
Created January 5, 2022 15:27
addon - 1
{
"timeZone": "America/New_York",
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"addOns": {
"common": {
"name": "MY COOL APP",
"logoUrl": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/97/Wikipedia-logo-gv_%281%29.png/196px-Wikipedia-logo-gv_%281%29.png",
"useLocaleFromApp": true,
"homepageTrigger": {
@Xiryl
Xiryl / YourFragment.kt
Created August 29, 2021 10:03
fragmentcallback-3
class YourCustomFRagment(
var backPressedListener: OnFragmentCallback
) : Fragment(R.layout.xyz) {
override fun onCreateView() {}
// trigger the event!
override fun onDestroy() {
backPressedListener.onFragmentBackPressed()
}
@Xiryl
Xiryl / YourActivity.kt
Created August 29, 2021 09:59
fragmentcallback-2
override fun onCreate(savedInstanceState: Bundle?) {
showFragment()
}
// callback listener
private val fragmentBackPressedListener = object : OnFragmentCallback {
override fun onFragmentBackPressed() {
foo()
}
}
@Xiryl
Xiryl / OnFragmentCallbackListener.kt
Created August 29, 2021 09:52
fragmentcallback-1
interface OnFragmentCallbackListener.kt {
fun onFragmentBackPressed()
}
@Xiryl
Xiryl / BluetoothSDKService.kt
Created August 12, 2021 10:42
BluetoothSDK-Service3
private inner class ConnectedThread(private val mmSocket: BluetoothSocket) : Thread() {
private val mmInStream: InputStream = mmSocket.inputStream
private val mmOutStream: OutputStream = mmSocket.outputStream
private val mmBuffer: ByteArray = ByteArray(1024) // mmBuffer store for the stream
override fun run() {
var numBytes: Int // bytes returned from read()
// Keep listening to the InputStream until an exception occurs.
@Xiryl
Xiryl / BluetoothSDKService.kt
Created August 12, 2021 10:40
BluetoothSDK-Service2
/**
* Class used for the client Binder.
*/
inner class LocalBinder : Binder() {
/**
* Enable the discovery, registering a broadcastreceiver {@link discoveryBroadcastReceiver}
* The discovery filter by LABELER_SERVER_TOKEN_NAME
*/
public fun startDiscovery(context: Context) {
@Xiryl
Xiryl / BluetoothSDKService.kt
Created August 12, 2021 10:34
BluetoothSDK-Service1
class BluetoothSDKService : Service() {
// Service Binder
private val binder = LocalBinder()
// Bluetooth stuff
private lateinit var bluetoothAdapter: BluetoothAdapter
private lateinit var pairedDevices: MutableSet<BluetoothDevice>
private var connectedDevice: BluetoothDevice? = null
@Xiryl
Xiryl / CoolFragment.kt
Created August 12, 2021 10:22
BluetoothSDK-Fragment
class CoolFragment() : BottomSheetDialogFragment() {
private lateinit var mService: BluetoothSDKService
private lateinit var binding: FragmentPopupDiscoveredLabelerDeviceBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater,
@Xiryl
Xiryl / BluetoothSDKListenerHelper.kt
Last active August 12, 2021 09:34
BluetoothSDK-ListenerHelper
class BluetoothSDKListenerHelper {
companion object {
private var mBluetoothSDKBroadcastReceiver: BluetoothSDKBroadcastReceiver? = null
class BluetoothSDKBroadcastReceiver : BroadcastReceiver() {
private var mGlobalListener: IBluetoothSDKListener? = null
public fun setBluetoothSDKListener(listener: IBluetoothSDKListener) {
mGlobalListener = listener
@Xiryl
Xiryl / IBluetoothSDKListener.kt
Created August 12, 2021 09:19
BluetoothSDK-Interface
interface IBluetoothSDKListener {
/**
* from action BluetoothUtils.ACTION_DISCOVERY_STARTED
*/
fun onDiscoveryStarted()
/**
* from action BluetoothUtils.ACTION_DISCOVERY_STOPPED
*/
fun onDiscoveryStopped()