Skip to content

Instantly share code, notes, and snippets.

View Mercandj's full-sized avatar
😀
Working on Android Apps

Jonathan Mercandalli Mercandj

😀
Working on Android Apps
View GitHub Profile
import UIKit
import SwiftUI // <-- Add SwiftUI import
class HelloWorldView: UIView {
// UIView code here
struct HelloWorldView_Preview: PreviewProvider { // <-- Add the preview definition
static var previews: some View {
Preview()
@Mercandj
Mercandj / HelloWorldView.swift
Last active January 7, 2023 17:01
swiftui_preview_with_ui_view
import UIKit
class HelloWorldView: UIView {
private lazy var title = createTitle()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(title)
}
@Mercandj
Mercandj / MainActivity.kt
Last active December 9, 2022 17:49
Memory leak medium article
class MainActivity : AppCompatActivity() {
private val listener = Manager.Listener {
Log.d("memory_leak", "Use largeObject to avoid compiler opti $largeObject")
}
private var largeObject = (0..4_000).map {
Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888)
}
override fun onCreate(savedInstanceState: Bundle?) {
@Mercandj
Mercandj / android_drawing_stylus_performance.md
Last active November 23, 2022 12:57
How to improve stylus performances on Android using AndroidX

Android drawing stylus performance

Goal, increase stylus performances on Android: mobile, tablet, Chromebooks...

AndroidX.graphics

Requirements: OpenGL architecture must let you draw "incrementally" (delta) or "fully"

Dependency

buildscript {
repositories {
jcenter()
}
dependencies {
classpath(kotlin("gradle-plugin", version = "1.6.21"))
}
}
allprojects {
package com.medium
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Android: Memory leak

Java and the JVM may leak objects.

Leaking an object on Java (or Kotlin) is done when a reference direct or indirect (via transitivity) is kept so that the Garbage Collector cannot release the memory.

What Meaning in this snippet
live Means, cannot be garbage collected
died Means, is garbage collected

Fail fast

One goal of mobile apps or any dev project, is to not have crash or wrong behavior.

I. Example and "safe" implementation

Imagine a car with a car.setAccelerationPercent(Float).

For example, the client using the car can

  • shut off the acceleration with car.setAccelerationPercent(0f)
@Mercandj
Mercandj / programmation_test.md
Last active March 11, 2022 08:10
[Dev] Tests from a Mobile Developer point of view

Tests from a Mobile Developer point of view

Hi 👋, I'm Jonathan, Android Lead at MWM. "You should write tests", that something we can hear on the mobile / tech industry. But the question is Why?. Let's find out if writing tests is something you should invest on.


"Be sure you test the tests written" 🙃. Romain Guy and Chet Haase.

Android developer: Principles

Description

Please, first, checkout Developer: Principles. These Android developer principles are the "implementation details" of developer principles on the Android world.

The following advices are very opinionated. Before saying "bullshit", please read the why below in the Details section. One of the main ability of developer is to understand the why. (This advice apply to myself of course. Every tool I'm criticising exist because of a why that I consider less important than the alternative. But for sure, you can disagree).

The goal of this document is more to start a reflection than make you think twice of your code.