Skip to content

Instantly share code, notes, and snippets.

View cp-radhika-s's full-sized avatar
🎯
Focusing

Radhika canopas cp-radhika-s

🎯
Focusing
View GitHub Profile
@Composable
fun SpringRelease() {
val offsetY = remember { Animatable(0f) }
val scope = rememberCoroutineScope()
Box(
modifier = Modifier
.fillMaxSize()
.padding(20.dp),
contentAlignment = Alignment.TopCenter
@cp-radhika-s
cp-radhika-s / MainActivity.java
Last active April 7, 2023 11:17
Android - Connecting your app to a Wi-Fi connection which might not have internet
public class MainActivity extends AppCompatActivity implements WifiChangeBroadcastReceiver.WifiChangeBroadcastListener {
private WifiManager wifiManager;
private ConnectivityManager connectivityManager;
private WifiChangeBroadcastReceiver wifiStateChangeReceiver;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
@Composable
fun SpringAnimation() {
val scope = rememberCoroutineScope()
val offset = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) }
val offset2 = remember { Animatable(Offset(0f, 0f), Offset.VectorConverter) }
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextOverFlow() {
val textMeasure = rememberTextMeasurer()
Canvas(
onDraw = {
drawRect(color = Color.Black)
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextLayoutResult() {
val textMeasure = rememberTextMeasurer()
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }
Canvas(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
val textMeasure = rememberTextMeasurer()
var textLayoutResult by remember { mutableStateOf<TextLayoutResult?>(null) }
Canvas(
modifier = Modifier
.layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
textLayoutResult = textMeasure.measure(
AnnotatedString("Text on Canvas!"),
@ExperimentalTextApi
fun DrawScope.drawText(
textLayoutResult: TextLayoutResult,
color: Color = Color.Unspecified,
topLeft: Offset = Offset.Zero,
alpha: Float = Float.NaN,
shadow: Shadow? = null,
textDecoration: TextDecoration? = null
){}
@ExperimentalTextApi
@Composable
fun ExampleTextString() {
val textMeasure = rememberTextMeasurer()
Canvas(modifier = Modifier
.fillMaxWidth()
.height(100.dp), onDraw = {
drawRect(color = Color.Black)
@ExperimentalTextApi
fun DrawScope.drawText(
textMeasurer: TextMeasurer,
text: String,
// Other configuration
)
@OptIn(ExperimentalTextApi::class)
@Composable
fun ExampleTextAnnotatedString() {
val textMeasure = rememberTextMeasurer()
val text = buildAnnotatedString {
withStyle(
style = SpanStyle(
color = Color.White,