Skip to content

Instantly share code, notes, and snippets.

View cbeyls's full-sized avatar

Christophe Beyls cbeyls

View GitHub Profile
@stevdza-san
stevdza-san / HyperlinkText.kt
Last active April 7, 2024 22:59
Embedd a Hyperlink within a Text using Jetpack Compose.
import androidx.compose.foundation.text.ClickableText
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.TextUnit
inline fun <reified T : Parcelable> createParcel(
crossinline createFromParcel: (Parcel) -> T?): Parcelable.Creator<T> =
object : Parcelable.Creator<T> {
override fun createFromParcel(source: Parcel): T? = createFromParcel(source)
override fun newArray(size: Int): Array<out T?> = arrayOfNulls(size)
}
@lisawray
lisawray / MainActivity.java
Last active March 26, 2023 11:57
Vector drawables from XML with the Android support library 23.3.0
package com.xwray.vectorbinding;
import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
@fkrauthan
fkrauthan / TLSSocketFactory.java
Last active January 7, 2023 04:09
Custom SSLSocketFactory Implementation to enable tls 1.1 and tls 1.2 for android 4.1 (16+)
package net.cogindo.ssl;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
@ianhanniballake
ianhanniballake / PlayerService.java
Created July 12, 2015 18:57
Minimal MediaSessionCompat needed to get RemoteControlClient to appear
package com.example.remotecontrolclient;
import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.IBinder;
import android.support.v4.media.MediaMetadataCompat;
@mpost
mpost / colors.xml
Last active January 8, 2020 02:09
This gist demonstrates how to create an animated pause/resume media playback button for Android. It uses animated vector drawables and state transitions to orchestrate the effect. Some background: https://plus.google.com/u/0/+MoritzPost/posts/3EFF8uC7jXv
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="action_pause">#FF8F00</color>
<color name="action_resume">#43A047</color>
</resources>
@jaredrummler
jaredrummler / MenuTint.java
Last active April 13, 2022 03:58
Helper class to set the color and transparency for menu icons in an ActionBar or Toolbar.
/*
* Copyright (C) 2015. Jared Rummler <jared.rummler@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@chrisbanes
chrisbanes / CollapsingTitleLayout.java
Last active March 26, 2023 11:58
CollapsingTitleLayout
/*
* Copyright 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@chrisbanes
chrisbanes / SystemUiHelper.java
Last active March 2, 2024 18:57
SystemUiHelper
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@JakeWharton
JakeWharton / Truss.java
Last active June 9, 2023 07:35
Extremely simple wrapper around SpannableStringBuilder to make the API more logical and less awful. Apache 2 licensed.
import android.text.SpannableStringBuilder;
import java.util.ArrayDeque;
import java.util.Deque;
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */
public class Truss {
private final SpannableStringBuilder builder;
private final Deque<Span> stack;