tags | type | categorie | ||||||
---|---|---|---|---|---|---|---|---|
|
note |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Cast [value] to specified type [T] or throw [ClassCastException] with [msg]. | |
*/ | |
inline fun <reified T : Any> requireType(value: Any?, msg: () -> String): T { | |
return value as? T ?: throw ClassCastException(msg()) | |
} | |
/** | |
* Cast [value] to specified type [T] or throw [ClassCastException]. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
amen = commit --amend | |
co = checkout | |
ci = commit | |
st = status | |
br = branch | |
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short | |
hi7 = log --all --pretty=format:\"%h %cd %s (%an)\" --since='7 days ago' | |
type = cat-file -t | |
dump = cat-file -p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDownloadManager { | |
fun downloadByUrl(context: Context, url: String) { | |
val fileName = url.substring(url.lastIndexOf('/') + 1) | |
val request = DownloadManager.Request(Uri.parse(url)).apply { | |
setTitle("image $fileName") | |
setDescription("From CatGallery") | |
setNotificationVisibility(VISIBILITY_VISIBLE_NOTIFY_COMPLETED) | |
setDestinationInExternalPublicDir(DIRECTORY_DOWNLOADS, fileName) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.some.site.dialpad | |
import android.content.Context | |
import android.os.Bundle | |
import android.view.KeyEvent | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.activity.result.contract.ActivityResultContracts | |
import androidx.fragment.app.Fragment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onAppBackgrounded() { | |
val startIntent = Intent(this, ForegroundService::class.java) | |
startIntent.putExtra(COMMAND_ID, COMMAND_START) | |
startIntent.putExtra(STARTED_TIMER_TIME_MS, startTime) | |
startService(startIntent) | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onAppForegrounded() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ForegroundService : Service() { | |
private var isServiceStarted = false | |
private var notificationManager: NotificationManager? = null | |
private var job: Job? = null | |
private val builder by lazy { | |
NotificationCompat.Builder(this, CHANNEL_ID) | |
.setContentTitle("Simple Timer") | |
.setGroup("Timer") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), LifecycleObserver { | |
private lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
ProcessLifecycleOwner.get().lifecycle.addObserver(this) | |
binding = ActivityMainBinding.inflate(layoutInflater) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private lateinit var binding: ActivityMainBinding | |
private var startTime = 0L | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<com.example.customview.CustomView | |
android:id="@+id/custom_view_one" |
NewerOlder