..
This commit is contained in:
@@ -5,7 +5,7 @@ plugins {
|
||||
|
||||
android {
|
||||
namespace = "kr.lunaticbum.helpers"
|
||||
compileSdk = 35
|
||||
compileSdk = 36
|
||||
defaultConfig {
|
||||
minSdk = 26
|
||||
// targetSdk = 34
|
||||
|
||||
@@ -1,49 +1,49 @@
|
||||
package kr.lunaticbum
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.AssetManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.content.res.Resources.Theme
|
||||
import android.util.DisplayMetrics
|
||||
|
||||
/**
|
||||
* Base helps to get [Context], [Resources], [AssetManager], [Configuration] and [DisplayMetrics] in any class.
|
||||
*
|
||||
* @author Leonardo Taehwan Kim
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
object Base {
|
||||
private var context: Context? = null
|
||||
|
||||
fun initialize(context: Context) {
|
||||
Base.context = context
|
||||
}
|
||||
|
||||
fun getContext(): Context {
|
||||
synchronized(Base::class.java) {
|
||||
if (context == null) throw NullPointerException("Call Base.initialize(context) within your Application onCreate() method.")
|
||||
return context!!.applicationContext
|
||||
}
|
||||
}
|
||||
|
||||
val resources: Resources
|
||||
get() = getContext().resources
|
||||
|
||||
val theme: Theme
|
||||
get() = getContext().theme
|
||||
|
||||
val assets: AssetManager
|
||||
get() = getContext().assets
|
||||
|
||||
val configuration: Configuration
|
||||
get() = resources.configuration
|
||||
|
||||
val displayMetrics: DisplayMetrics
|
||||
get() = resources.displayMetrics
|
||||
} // TODO: Thread safety
|
||||
// TODO: ripple, bitmap, time, contact list, picture list, video list, connectivity, wake lock, screen lock/off/on, get attributes, cookie, audio
|
||||
// TODO: keystore
|
||||
// TODO: http://jo.centis1504.net/?p=1189
|
||||
// TODO: Test codes
|
||||
//package kr.lunaticbum
|
||||
//
|
||||
//import android.annotation.SuppressLint
|
||||
//import android.content.Context
|
||||
//import android.content.res.AssetManager
|
||||
//import android.content.res.Configuration
|
||||
//import android.content.res.Resources
|
||||
//import android.content.res.Resources.Theme
|
||||
//import android.util.DisplayMetrics
|
||||
//
|
||||
///**
|
||||
// * Base helps to get [Context], [Resources], [AssetManager], [Configuration] and [DisplayMetrics] in any class.
|
||||
// *
|
||||
// * @author Leonardo Taehwan Kim
|
||||
// */
|
||||
//@SuppressLint("StaticFieldLeak")
|
||||
//object Base {
|
||||
// private var context: Context? = null
|
||||
//
|
||||
// fun initialize(context: Context) {
|
||||
// Base.context = context
|
||||
// }
|
||||
//
|
||||
// fun getContext(): Context {
|
||||
// synchronized(Base::class.java) {
|
||||
// if (context == null) throw NullPointerException("Call Base.initialize(context) within your Application onCreate() method.")
|
||||
// return context!!.applicationContext
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val resources: Resources
|
||||
// get() = getContext().resources
|
||||
//
|
||||
// val theme: Theme
|
||||
// get() = getContext().theme
|
||||
//
|
||||
// val assets: AssetManager
|
||||
// get() = getContext().assets
|
||||
//
|
||||
// val configuration: Configuration
|
||||
// get() = resources.configuration
|
||||
//
|
||||
// val displayMetrics: DisplayMetrics
|
||||
// get() = resources.displayMetrics
|
||||
//} // TODO: Thread safety
|
||||
//// TODO: ripple, bitmap, time, contact list, picture list, video list, connectivity, wake lock, screen lock/off/on, get attributes, cookie, audio
|
||||
//// TODO: keystore
|
||||
//// TODO: http://jo.centis1504.net/?p=1189
|
||||
//// TODO: Test codes
|
||||
Reference in New Issue
Block a user