Skip to content

Instantly share code, notes, and snippets.

@andreymusth
andreymusth / MainActivity.kt
Created April 10, 2022 11:59
Dispatching amplitude values to view
class MainActivity : AppCompatActivity() {
private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val dynamic = findViewById<DynamicView>(R.id.dynamic1)
val button = findViewById<Button>(R.id.button)
@andreymusth
andreymusth / DynamicView.kt
Created April 10, 2022 11:37
Calculating next frame
class DynamicView
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private var lastUpdateTime: Long = System.currentTimeMillis()
// ..
@andreymusth
andreymusth / DynamicView.kt
Last active April 10, 2022 11:30
Updating amplitude
class DynamicView
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
private var animateToAmplitude = 0f
private var amplitude = 0f
private var deltaAmplitude = 0f
public class CustomView extends View {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// slightly change some value comparing to previous onDraw call
// do some actual drawing using canvas
invalidate();
}
}
public static boolean canBlurChat() {
return getDevicePerformanceClass() == PERFORMANCE_CLASS_HIGH;
}
private static int measureMaxParticlesCount() {
switch (SharedConfig.getDevicePerformanceClass()) {
default:
case SharedConfig.PERFORMANCE_CLASS_LOW:
case SharedConfig.PERFORMANCE_CLASS_AVERAGE:
return 100;
public class SharedConfig {
private static int devicePerformanceClass;
public final static int PERFORMANCE_CLASS_LOW = 0;
public final static int PERFORMANCE_CLASS_AVERAGE = 1;
public final static int PERFORMANCE_CLASS_HIGH = 2;
public static int getDevicePerformanceClass() {
if (devicePerformanceClass == -1) {
class DateFormatter {
private val cache = HashMap<Long, String>()
private val months = arrayOf(
"января",
"февраля",
"марта",
"апрель",
"мая",
class UserProfileActivity : AppCompatActivity(), View.OnClickListener, UserProfileView {
private val presenter: UserProfilePresenter = UserProfilePresenterImpl(this)
@Inject
lateinit var api: CardInfoApi
override fun onCreate(savedInstanceState: Bundle?) {
App.component.inject(this)
super.onCreate(savedInstanceState)
class User(val name: String)
fun main() {
val users = HashSet<User>()
for (i in 0 until 100) {
users.add(User("Bob))
}
}
// Сколько объектов будет в сете после выполнения цикла?