Skip to content

Instantly share code, notes, and snippets.

@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 / OnFragmentCallbackListener.kt
Created August 29, 2021 09:52
fragmentcallback-1
interface OnFragmentCallbackListener.kt {
fun 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 / 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 / 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": {
/**
* Callback for rendering the homepage card.
* @return The card to show to the user.
*/
function onHomepage(e) {
return createHomeCard();
}
/**
* Build the home card
@Xiryl
Xiryl / code.gs
Created January 5, 2022 16:18
addon -3
const txtInsertId =
CardService.newTextParagraph().setText("<b>Bold text</b><br/> -Can you read this?");
const textInput = CardService.newTextInput()
.setFieldName("txt_input_id_to_process")
.setTitle("Write something here...");
const ico = CardService.newIconImage().setIconUrl(
"ico link"
);
function createHomeCard() {
const imgLogoUri = "http://your.home.page.image.link";
const imgLogo = CardService.newImage()
.setImageUrl(imgLogoUri)
.setAltText("Digit-Atoms");
const footer = CardService.newFixedFooter().setPrimaryButton(
CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
@Xiryl
Xiryl / build.gradle
Created February 11, 2023 10:42
driveapimedium-github
// ...
// coroutines
// Guava
implementation "com.google.guava:guava:24.1-jre"
// Guava fix
implementation "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"
//Drive
implementation('com.google.api-client:google-api-client-android:1.23.0') {
@Xiryl
Xiryl / Activity.kt
Created February 11, 2023 10:58
driveapimedium-github-1
val startForResult = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
val intent = result.data
if (result.data != null) {
val task: Task<GoogleSignInAccount> =
GoogleSignIn.getSignedInAccountFromIntent(intent)
/**
* handle [task] result
*/