애노테이션은 자바 소스 코드에 추가 할 수있는 메타 데이터의 한 형태입니다.
애노테이션 프로세서는 java 컴파일러의 플러그인의 일종입니다.
Annotation Processor는 실제로 javac 컴파일러의 일부이므로 모든 처리가 런타임보다는 컴파일시간에 발생합니다. Annotation Processor가 정말 빠른 이유입니다. // 마무리할것.
https://stackoverflow.com/a/53043911
Doing some changes on your binding does not mean that it will have an immediate effect on your View. Changing things in binding means that you're really scheduling those changes to be applied in the nearest future. This is for many reasons, performance being one of them.
Calling executePendingBindings means that you're essentially forcing the framework to do everything it needs to do so far on the binding, right at the moment of calling it.
private fun hideSystemUi() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.setDecorFitsSystemWindows(false)
window.insetsController?.let {
it.hide(WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars())
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
} else {
@Suppress("DEPRECATION")
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
}
}
val string = calendarDisplays.map { it.id }.joinToString(separator = ", ") { "\"$it\"" }
window?.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
@Suppress("SpellCheckingInspection")
@SuppressLint("Recycle")
fun instances(contentResolver: ContentResolver, eventId: String, DTSTART: Calendar, DTEND: Calendar): ArrayList<Event>? {
val events = arrayListOf<Event>()
val selection = "${CalendarContract.Instances.EVENT_ID} = ?"
val selectionArgs: Array<String> = arrayOf(eventId)
val builder: Uri.Builder = CalendarContract.Instances.CONTENT_URI.buildUpon()
ContentUris.appendId(builder, DTSTART.timeInMillis)
ContentUris.appendId(builder, DTEND.timeInMillis)
val cursor = contentResolver.query(
builder.build(),
Instances.projection,
selection,
selectionArgs,
null
) ?: return null
while (cursor.moveToNext()) {
val begin = cursor.getLongOrNull(Instances.Index.BEGIN) ?: 0L
val calendarDisplayName = cursor.getStringOrNull(Instances.Index.CALENDAR_DISPLAY_NAME) ?: BLANK
val calendarId = cursor.getLongOrNull(Instances.Index.CALENDAR_ID) ?: continue
val end = cursor.getLongOrNull(Instances.Index.END) ?: 0L
val id = cursor.getLongOrNull(Instances.Index.EVENT_ID) ?: continue
val rrule = cursor.getStringOrNull(Instances.Index.RRULE) ?: BLANK
val title = cursor.getStringOrNull(Instances.Index.TITLE) ?: BLANK
events.add(Event(
begin = begin,
calendarDisplayName = calendarDisplayName,
calendarId = calendarId,
end = end,
id = id,
rrule = rrule,
title = title
))
}
return events
}
@SuppressLint("Recycle")
fun events(contentResolver: ContentResolver, calendarDisplays: List<CalendarDisplay>): ArrayList<Event>? {
val events = arrayListOf<Event>()
@Suppress("LocalVariableName", "SpellCheckingInspection")
val DTSTART = Calendar.getInstance()
@Suppress("LocalVariableName", "SpellCheckingInspection")
val DTEND = Calendar.getInstance()
DTSTART.set(Calendar.HOUR_OF_DAY, 0)
DTSTART.set(Calendar.MINUTE, 0)
DTSTART.set(Calendar.SECOND, 0)
DTEND.set(Calendar.HOUR_OF_DAY, 0)
DTEND.set(Calendar.MINUTE, 0)
DTEND.set(Calendar.SECOND, 0)
DTEND.add(Calendar.DATE, 1)
val string = calendarDisplays.map { it.id }.joinToString(separator = ", ") { "\"$it\"" }
val selection = "(${CalendarContract.Events.CALENDAR_ID} IN ($string)) AND " +
"(${CalendarContract.Events.DELETED} = 0)"
val cursor = contentResolver.query(
CalendarContract.Events.CONTENT_URI,
Events.projection,
selection,
null,
null
) ?: return null
cursor.moveToFirst()
@Suppress("SpellCheckingInspection")
while (cursor.moveToNext()) {
@Suppress("LocalVariableName")
val _id = cursor.getLongOrNull(Events.Index._ID) ?: continue
val title = cursor.getStringOrNull(Events.Index.TITLE) ?: BLANK
Timber.d("events")
Timber.d("_id: $_id")
Timber.d("title: $title")
instances(contentResolver, _id.toString(), DTSTART, DTEND)?.let { instances ->
events.addAll(instances)
}
}
return events
}
val intent = Intent(applicationContext, HomeActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
finishAffinity()
ActivityCompat.finishAffinity(this)
try {
String pkg = "com.app.my";//your package name
Drawable icon = getContext().getPackageManager().getApplicationIcon(pkg);
imageView.setImageDrawable(icon);
} catch (PackageManager.NameNotFoundException ne) {
}
https://stackoverflow.com/a/34249752
add code block toolbar.setNavigationOnClickListener after setSupportActionBar(toolbar)
@ColorInt
private fun getDateTimeTextColor(@ColorInt colorInt: Int): Int {
var red = Color.red(colorInt) / 255.0
var green = Color.green(colorInt) / 255.0
var blue = Color.blue(colorInt) / 255.0
if (red <= 0.03928)
red /= 12.92
else
red = ((red + 0.055) / 1.055).pow(2.4)
if (green <= 0.03928)
green /= 12.92
else
green = ((green + 0.055) / 1.055).pow(2.4)
if (blue <= 0.03928)
blue /= 12.92
else
blue = ((red + 0.055) / 1.055).pow(2.4)
val y = 0.2126 * red + 0.7152 * green + 0.0722 * blue
return if (y > 0.179)
Color.BLACK
else
Color.WHITE
}
private fun wallpaper(): Bitmap {
val wallpaperManager = WallpaperManager.getInstance(this)
return wallpaperManager.drawable.toBitmap()
}
private fun wallpaper(): Bitmap? {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
val wallpaperManager = WallpaperManager.getInstance(this)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val wallpaperFile = wallpaperManager.getWallpaperFile(WallpaperManager.FLAG_LOCK) ?: wallpaperManager.getWallpaperFile(WallpaperManager.FLAG_SYSTEM)
wallpaperFile?.let {
val bitmap = BitmapFactory.decodeFileDescriptor(wallpaperFile.fileDescriptor)
try {
wallpaperFile.close()
} catch (e: IOException) {
e.printStackTrace()
}
return bitmap
}
}
return wallpaperManager.drawable.toBitmap()
}
return null
}
implementation 'androidx.palette:palette-ktx:1.0.0'
As is stated in the View class docs:
This class represents the basic building block for user interface components. A
Viewoccupies a rectangular area on the screen and is responsible for drawing and event handling.Viewis the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.).
The
ViewGroupsubclass is the base class for layouts, which are invisible containers that hold otherViews (or otherViewGroups) and define their layout properties.
Therefore a View is a base class for UI elements and a Widget is loosely defined as any ready to use View.
A View is a base class for all UI elements. It, therefore, covers many different classes and concepts, including widgets, ViewGroups and layouts. There is a root View attached to a Window instance which forms the basis of the View hierarchy. In general, the word View is usually used to describe UI elements in general, or to refer to abstract or base UI classes such as ViewGroups.
There are various definitions for this term, but most refer to a "ready to use" UI element, be it a Button, ImageView, EditText, etc. Note that some people consider widgets to be UI elements that are complete (not abstract) and are not containers (such as ViewGroups (layouts/ListViews)). It's also worth noting that "widget" is a package name (android.widget) where the docs mention the following:
The widget package contains (mostly visual) UI elements to use on your Application screen.
Therefore, it is reasonable to consider non-visual UI elements to also be widgets, as well as any class defined under the widget package. See here for a full list of classes in the widget package: http://developer.android.com/reference/android/widget/package-summary.html