Skip to content

Instantly share code, notes, and snippets.

View omkar-tenkale's full-sized avatar
☸️
Planning

Omkar Tenkale omkar-tenkale

☸️
Planning
View GitHub Profile
@omkar-tenkale
omkar-tenkale / AndroidManifest.xml
Last active November 20, 2022 23:33
android FileUriExposedException fix view file intent crash with fileprovider approach
<provider
android:name=".GenericFileProvider"
android:authorities="${applicationId}"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
@gmk57
gmk57 / Sending events to UI.kt
Last active February 13, 2024 15:17
Sending events to UI with Channel/Flow + custom collector (see my first comment for reasons behind it)
/**
* Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop.
* This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case
* the coroutine is just suspended on stop.
*/
inline fun <reified T> Flow<T>.collectWhileStarted(
lifecycleOwner: LifecycleOwner,
noinline action: suspend (T) -> Unit
) {
object : DefaultLifecycleObserver {

Android Interview Questions

Q1: Explain activity lifecycle ☆☆

Answer: As a user navigates through, out of, and back to your app, the Activity instances in your app transition through different states in their lifecycle.

To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). The system invokes each of these callbacks as an activity enters a new state.

Interview Questions

Kotlin

Q1: What is a primary constructor in Kotlin? ☆☆

Answer: The primary constructor is part of the class header. Unlike Java, you don't need to declare a constructor in the body of the class. Here's an example:

@ozgurg
ozgurg / PlayPauseView.java
Last active September 1, 2023 02:39
Android Animated Play Pause Button by using AnimatedVectorDrawable
public class PlayPauseView extends AppCompatImageView {
public static final int STATE_PLAY = 1;
public static final int STATE_PAUSE = 2;
private AnimatedVectorDrawableCompat mPlayToPauseAnim, mPauseToPlay;
private Animation mFadeOutAnim, mFadeInAnim;
public PlayPauseView(Context context) {
super(context);
Init(context);
@IARI
IARI / AudioUtils.kt
Created March 15, 2019 23:32
get the length of a vorbis/ogg file
//4 bytes for "OggS", 2 unused bytes, 8 bytes for length
private const val OGG_OFFSET = 8 + 2 + 4
private val OGGS_BYTES = "OggS".map(Char::toByte).toByteArray()
private val VORBIS_BYTES = "vorbis".map(Char::toByte).toByteArray()
fun ByteArray.slice(start: Int, len: Int) = copyOfRange(start, start + len)
@Throws(IOException::class)
fun calculateOggDuration(oggFile: File): Pair<Int, Int> {
var rate = -1
var length = -1
@sidneys
sidneys / youtube_format_code_itag_list.md
Created January 20, 2018 11:12
YouTube video stream format codes itags

YouTube video stream format codes

Comprehensive list of YouTube format code itags

itag Code Container Content Resolution Bitrate Range VR / 3D
5 flv audio/video 240p - - -
6 flv audio/video 270p - - -
17 3gp audio/video 144p - - -
18 mp4 audio/video 360p - - -
22 mp4 audio/video 720p - - -
package com.github.irshulx.glitchtext;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
@rnagarajanmca
rnagarajanmca / apk install from windows context menu.md
Last active October 24, 2023 18:07
Register windows context menu entry to install apk with adb
@yanngx
yanngx / FragmentArgumentDelegate.kt
Last active January 19, 2023 09:26
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created