Skip to content

Instantly share code, notes, and snippets.

@aqua30
aqua30 / CurvedContainer.kt
Last active March 6, 2022 18:54
Custom Layout
class CurvedContainer @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
): LinearLayout(context, attrs, defStyleAttr) {
/* paint object for coloring the canvas */
private val mPaint = Paint()
/* path that will be drawn to achieve the shape */
private val path = Path()
@aqua30
aqua30 / onSizeChanged.kt
Created March 6, 2022 19:15
Function of view class
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
/* curve from P1 to P2 */
leftArc.set(
0f,
0f,
xAxisOffset,
yAxisOffset
)
path.addArc(leftArc, 180f, 90f)
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
canvas?.drawPath(path, mPaint)
}
<style name="TransparentBackgroundDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:colorBackground">@android:color/transparent</item>
</style>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(STYLE_NORMAL, R.style.TransparentBackgroundDialog)
}
@aqua30
aqua30 / ScrollParallaxActivity.java
Last active May 9, 2022 05:34
Simplest ScrollView Parallax technique in Android. No library required and just with 4 lines of code, you can easily create parallax effect.
/**
* Created by Saurabh(aqua) in 2017.
*/
public class ParallaxActivity extends BaseActivity {
/* view binding */
@BindView(R.id.scrollView)ScrollView scrollView;
@BindView(R.id.parallax_image)ImageView parallaxImage;
@BindView(R.id.tv_perhour)TextView textView;
@aqua30
aqua30 / settings.gradle
Created May 21, 2022 15:11
Version Catalog
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
versionCatalogs {
libs {
version('compose','1.4.0')
version('composeui','1.1.1')
@aqua30
aqua30 / TimerScreen.kt
Created May 27, 2022 18:22
Animation section for selection screen.
AnimatedContent(
targetState = timerContent,
transitionSpec = {
if(targetState == TimerContent.SELECTION) {
slideInVertically { height -> height } + fadeIn() with
slideOutVertically { height -> -height } + fadeOut()
} else {
slideInVertically { height -> -height } + fadeIn() with
slideOutVertically { height -> height } + fadeOut()
}
data class TimeData(
val hours: TimeUnit = TimeUnit(),
val mins: TimeUnit = TimeUnit(),
val secs: TimeUnit = TimeUnit(),
) {
fun isDataFull() = hours.leftDigit > 0
fun isDataEmpty() =
hours.leftDigit == 0 && hours.rightDigit == 0
&& mins.leftDigit == 0 && mins.rightDigit == 0
@Composable
fun TimeDisplay(
time: TimeData = TimeData(),
) {
val timeUnitColor = if (time.isDataEmpty()) GRAY_TEXT else BLUE_LIGHT
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {