Skip to content

Instantly share code, notes, and snippets.

View imandaliya's full-sized avatar
🐢

Rahul Mandaliya imandaliya

🐢
View GitHub Profile
@imandaliya
imandaliya / ViewEx.kt
Created October 16, 2025 06:09
Clip View By Rect
fun BottomAppBar.clipTopCorners() {
elevation = resources.getDimensionPixelSize(R.dimen.dp2).toFloat()
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.offset(0, resources.getDimensionPixelSize(R.dimen.dp24))
outline.setRoundRect(
0,
0,
view.width,
view.height + resources.getDimensionPixelSize(R.dimen.dp24),
@imandaliya
imandaliya / Truss.java
Created May 7, 2025 11:16 — forked from captswag/Truss.java
Rewrote Jake Wharton's wrapper of SpannableStringBuilder in Kotlin
import android.text.SpannableStringBuilder
import android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE
import java.util.ArrayDeque
import java.util.Deque
// https://gist.github.com/JakeWharton/11274467
public class Truss {
private val builder: SpannableStringBuilder = SpannableStringBuilder()
private val stack: Deque<Span> = ArrayDeque()
@imandaliya
imandaliya / Truss.java
Created May 7, 2025 11:16 — forked from JakeWharton/Truss.java
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;
adb shell 'date 122510002024.00 ; am broadcast -a android.intent.action.TIME_SET'
12 month
25 day
1000 time // not neseccory
2024 year
// Original Thread https://stackoverflow.com/questions/3257293/measuring-text-width-to-be-drawn-on-canvas-android
fun String.getWidth(fontSize: Float): Float {
val textPaint = TextPaint()
textPaint.textSize = fontSize
textPaint.typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
val texts = this.split("\n")
if (texts.size == 1) {
return textPaint.measureText(this)
// original link https://chrisbanes.me/posts/measuring-text/
public void drawTextOnCenterOfBounds() {
int mTextWidth, mTextHeight; // Our calculated text bounds
Paint mTextPaint = new Paint();
// Now lets calculate the size of the text
Rect textBounds = new Rect();
mTextPaint.getTextBounds(mText, 0, mText.length(), textBounds);
@imandaliya
imandaliya / DemoBubblesView.java
Created September 9, 2024 07:09 — forked from markusfisch/DemoBubblesView.java
Draw text in a given rectangle and automatically wrap lines on a Android Canvas
package de.markusfisch.android.textrect.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.View;
import de.markusfisch.android.textrect.graphics.TextRect;
@imandaliya
imandaliya / activity_layout.xml
Created July 30, 2024 12:55 — forked from iamnaran/activity_layout.xml
Layout And RecyclerView Animation Android (Made Simple with XML only)
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutAnimation="@anim/layout_animation"
android:orientation="vertical">
</ScrollView>
# this code for delete build directory from folder where file is run
# this will delete directory and more to Trash in MacOs
# WARNING : check directory before delete
import os
from send2trash import send2trash
def find_build_directories(root_dir):
build_dirs = []
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import android.view.View
class TransparentGridRectView @JvmOverloads constructor(