....
This commit is contained in:
parent
4e26fab27c
commit
20a41d27e1
@ -19,10 +19,10 @@
|
|||||||
package rasel.lunar.launcher.apps
|
package rasel.lunar.launcher.apps
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.ContentUris
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.ResolveInfo
|
import android.content.pm.ResolveInfo
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -72,7 +72,7 @@ internal class AppDrawer : Fragment() {
|
|||||||
private var contactAdapter : ContactAdapter? = null
|
private var contactAdapter : ContactAdapter? = null
|
||||||
private var packageInfoList: MutableList<ResolveInfo> = mutableListOf()
|
private var packageInfoList: MutableList<ResolveInfo> = mutableListOf()
|
||||||
private var packageList = mutableListOf<Packages>()
|
private var packageList = mutableListOf<Packages>()
|
||||||
|
private var oringinPackageList = mutableListOf<Packages>()
|
||||||
// private val numberPattern = Pattern.compile("[0-9]")
|
// private val numberPattern = Pattern.compile("[0-9]")
|
||||||
// private val alphabetPattern = Pattern.compile("[A-Z]")
|
// private val alphabetPattern = Pattern.compile("[A-Z]")
|
||||||
@JvmStatic var settingsPrefs: SharedPreferences? = null
|
@JvmStatic var settingsPrefs: SharedPreferences? = null
|
||||||
@ -91,6 +91,22 @@ internal class AppDrawer : Fragment() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getCategory(category : Int) : String {
|
||||||
|
return when(category) {
|
||||||
|
ApplicationInfo.CATEGORY_UNDEFINED -> "UNDEFINED"
|
||||||
|
ApplicationInfo.CATEGORY_GAME -> "GAME"
|
||||||
|
ApplicationInfo.CATEGORY_AUDIO -> "AUDIO"
|
||||||
|
ApplicationInfo.CATEGORY_VIDEO -> "VIDEO"
|
||||||
|
ApplicationInfo.CATEGORY_IMAGE -> "IMAGE"
|
||||||
|
ApplicationInfo.CATEGORY_SOCIAL -> "SOCIAL"
|
||||||
|
ApplicationInfo.CATEGORY_NEWS -> "NEWS"
|
||||||
|
ApplicationInfo.CATEGORY_MAPS -> "MAPS"
|
||||||
|
ApplicationInfo.CATEGORY_PRODUCTIVITY -> "PRODUCTIVITY"
|
||||||
|
ApplicationInfo.CATEGORY_ACCESSIBILITY -> "ACCESSIBILITY"
|
||||||
|
else -> {"UNKNOWN"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
fun getInputText() = binding.searchInput.text.toString()
|
fun getInputText() = binding.searchInput.text.toString()
|
||||||
|
|
||||||
@ -127,6 +143,10 @@ internal class AppDrawer : Fragment() {
|
|||||||
binding.searchNamuwiki.setOnClickListener {
|
binding.searchNamuwiki.setOnClickListener {
|
||||||
openSearchApps("https://namu.wiki/Search?q=${getInputText()}")
|
openSearchApps("https://namu.wiki/Search?q=${getInputText()}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.searchTranslate.setOnClickListener {
|
||||||
|
openSearchApps("https://translate.google.com/?hl=ko&sl=ko&tl=en&text=${getInputText()}&op=translate","com.android.chrome")
|
||||||
|
}
|
||||||
setLayout()
|
setLayout()
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
@ -249,40 +269,62 @@ internal class AppDrawer : Fragment() {
|
|||||||
|
|
||||||
/* update app list with app and package name */
|
/* update app list with app and package name */
|
||||||
fun fetchApps() {
|
fun fetchApps() {
|
||||||
GlobalScope.launch {
|
if (oringinPackageList.size > 0) {
|
||||||
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
||||||
packageManager?.queryIntentActivities(
|
|
||||||
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER),
|
|
||||||
PackageManager.ResolveInfoFlags.of(0)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(packageManager?.queryIntentActivities(
|
|
||||||
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0
|
|
||||||
))
|
|
||||||
})?.apply {
|
|
||||||
removeIf { it.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID) }
|
|
||||||
sortedBy {
|
|
||||||
appName(it)
|
|
||||||
}
|
|
||||||
}!!
|
|
||||||
|
|
||||||
/* add package and app names to the list */
|
|
||||||
packageList.clear()
|
packageList.clear()
|
||||||
var edit = appNamesPrefs?.edit()
|
for(pkg in oringinPackageList) {
|
||||||
for (resolver in packageInfoList) {
|
packageList.add(pkg)
|
||||||
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
packageList.clear()
|
||||||
|
oringinPackageList.clear()
|
||||||
|
GlobalScope.launch {
|
||||||
|
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
packageManager?.queryIntentActivities(
|
||||||
|
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER),
|
||||||
|
PackageManager.ResolveInfoFlags.of(0)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(packageManager?.queryIntentActivities(
|
||||||
|
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0
|
||||||
|
))
|
||||||
|
})?.apply {
|
||||||
|
removeIf { it.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID) }
|
||||||
|
|
||||||
|
forEach {
|
||||||
|
oringinPackageList.add(
|
||||||
|
Packages(
|
||||||
|
it.activityInfo.packageName,
|
||||||
|
appName(it),
|
||||||
|
getCategory(it.activityInfo.applicationInfo.category)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
packageList.add(
|
||||||
|
Packages(
|
||||||
|
it.activityInfo.packageName,
|
||||||
|
appName(it),
|
||||||
|
getCategory(it.activityInfo.applicationInfo.category)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}!!
|
||||||
|
}
|
||||||
|
/* add package and app names to the list */
|
||||||
|
|
||||||
|
// var edit = appNamesPrefs?.edit()
|
||||||
|
// for (resolver in packageInfoList) {
|
||||||
|
// packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
|
||||||
|
// }
|
||||||
|
}
|
||||||
// when {
|
// when {
|
||||||
// packageList.size < 1 -> return
|
// packageList.size < 1 -> return
|
||||||
// else -> {
|
// else -> {
|
||||||
if (packageList.size > 0) {
|
if (packageList.size > 0) {
|
||||||
MainScope().launch {
|
MainScope().launch {
|
||||||
appsAdapter?.updateData(packageList)
|
appsAdapter?.updateData(packageList)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAlphabetItems() {
|
private fun getAlphabetItems() {
|
||||||
@ -317,14 +359,10 @@ internal class AppDrawer : Fragment() {
|
|||||||
if (lastSearchStringLength > 0 && (lastSearchStringLength != searchString.length || lastSearchString.equals(searchString) == false)) {
|
if (lastSearchStringLength > 0 && (lastSearchStringLength != searchString.length || lastSearchString.equals(searchString) == false)) {
|
||||||
BLog.LOGE("START FILTER")
|
BLog.LOGE("START FILTER")
|
||||||
packageList.clear()
|
packageList.clear()
|
||||||
for (resolver in packageInfoList) {
|
for (pkg in oringinPackageList) {
|
||||||
appName(resolver).let {
|
if (pkg.appName.contains(searchString,true) || pkg.category.contains(searchString,true) || pkg.packageName.contains(searchString,true)) {
|
||||||
// BLog.LOGE("searchString >>> ${searchString} , normalize(it) ${normalize(it)} ${normalize(it).contains(normalize(searchString), false)}")
|
BLog.LOGE("pkg >>> ${pkg.category} , ${pkg.appName}")
|
||||||
if (normalize(it).contains(normalize(searchString), false)) {
|
packageList.add(pkg)
|
||||||
packageList.add(Packages(resolver.activityInfo.packageName, it))
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BLog.LOGE("MIDDLE FILTER")
|
BLog.LOGE("MIDDLE FILTER")
|
||||||
@ -364,8 +402,8 @@ internal class AppDrawer : Fragment() {
|
|||||||
contactList.add(item)
|
contactList.add(item)
|
||||||
}
|
}
|
||||||
packageList.clear()
|
packageList.clear()
|
||||||
for (resolver in packageInfoList) {
|
for (resolver in oringinPackageList) {
|
||||||
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
|
packageList.add(resolver)
|
||||||
}
|
}
|
||||||
appsAdapter?.updateData(packageList)
|
appsAdapter?.updateData(packageList)
|
||||||
contactAdapter?.updateData(contactList)
|
contactAdapter?.updateData(contactList)
|
||||||
|
|||||||
@ -122,9 +122,10 @@ internal class AppsAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal data class Packages (
|
data class Packages (
|
||||||
val packageName: String,
|
val packageName: String,
|
||||||
val appName: String
|
val appName: String,
|
||||||
|
val category : String
|
||||||
)
|
)
|
||||||
|
|
||||||
internal class AppsDiffUtil(
|
internal class AppsDiffUtil(
|
||||||
|
|||||||
@ -38,8 +38,10 @@ import org.xmlpull.v1.XmlPullParserFactory
|
|||||||
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
|
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
|
||||||
import rasel.lunar.launcher.helpers.Constants.Companion.DEFAULT_ICON_PACK
|
import rasel.lunar.launcher.helpers.Constants.Companion.DEFAULT_ICON_PACK
|
||||||
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_PACK
|
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_PACK
|
||||||
|
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_PKGICS
|
||||||
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_SETTINGS
|
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_SETTINGS
|
||||||
import rasel.lunar.launcher.utils.BLog
|
import rasel.lunar.launcher.utils.BLog
|
||||||
|
import rasel.lunar.launcher.utils.ImageUtils
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
@ -50,6 +52,7 @@ internal class IconPackManager {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val settingsPrefs = lActivity!!.getSharedPreferences(PREFS_SETTINGS, 0)
|
private val settingsPrefs = lActivity!!.getSharedPreferences(PREFS_SETTINGS, 0)
|
||||||
|
private val icsPrefs = lActivity!!.getSharedPreferences(PREFS_PKGICS,0)
|
||||||
private val packageName = settingsPrefs.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK)
|
private val packageName = settingsPrefs.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK)
|
||||||
private var loaded = false
|
private var loaded = false
|
||||||
private val packagesDrawables = HashMap<String?, String?>()
|
private val packagesDrawables = HashMap<String?, String?>()
|
||||||
@ -139,6 +142,11 @@ internal class IconPackManager {
|
|||||||
private fun loadBitmap(drawableName: String): Bitmap? {
|
private fun loadBitmap(drawableName: String): Bitmap? {
|
||||||
if (packageName != null && packageName.length > 0) {
|
if (packageName != null && packageName.length > 0) {
|
||||||
var bm = bitmapCache.get(packageName)
|
var bm = bitmapCache.get(packageName)
|
||||||
|
GlobalScope.async {
|
||||||
|
bm?.let { ImageUtils.bitmapToBase64String(it)?.let {
|
||||||
|
icsPrefs.contains(packageName)
|
||||||
|
} }
|
||||||
|
}
|
||||||
if (bm != null) return bm
|
if (bm != null) return bm
|
||||||
}
|
}
|
||||||
iconPackRes!!.getIdentifier(drawableName, "drawable", packageName).let { id ->
|
iconPackRes!!.getIdentifier(drawableName, "drawable", packageName).let { id ->
|
||||||
@ -166,6 +174,13 @@ internal class IconPackManager {
|
|||||||
fun putAfterReturn(packages: String, drawable : Drawable?) : Drawable? {
|
fun putAfterReturn(packages: String, drawable : Drawable?) : Drawable? {
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
appPackageIconDrawables.put(packages, drawable)
|
appPackageIconDrawables.put(packages, drawable)
|
||||||
|
(drawable as? BitmapDrawable)?.let {
|
||||||
|
if(icsPrefs.contains(packageName)) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
icsPrefs.edit().putString(packageName, ImageUtils.bitmapToBase64String(it.bitmap)).apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return drawable
|
return drawable
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,9 @@ internal class Constants {
|
|||||||
const val KEY_WIDGET_IDS = "widget_ids"
|
const val KEY_WIDGET_IDS = "widget_ids"
|
||||||
const val KEY_WIDGET_HEIGHTS = "widget_heights"
|
const val KEY_WIDGET_HEIGHTS = "widget_heights"
|
||||||
|
|
||||||
|
const val PREFS_PKGICS = "rasel.lunar.launcher.Icons"
|
||||||
|
|
||||||
|
|
||||||
/* settings */
|
/* settings */
|
||||||
const val PREFS_SETTINGS = "rasel.lunar.launcher.SETTINGS"
|
const val PREFS_SETTINGS = "rasel.lunar.launcher.SETTINGS"
|
||||||
const val KEY_TIME_FORMAT = "time_format"
|
const val KEY_TIME_FORMAT = "time_format"
|
||||||
|
|||||||
34
app/src/main/kotlin/rasel/lunar/launcher/utils/ImageUtils.kt
Normal file
34
app/src/main/kotlin/rasel/lunar/launcher/utils/ImageUtils.kt
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package rasel.lunar.launcher.utils
|
||||||
|
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.BitmapFactory
|
||||||
|
import android.graphics.drawable.Icon
|
||||||
|
import android.util.Base64
|
||||||
|
import androidx.core.content.pm.ShortcutInfoCompat
|
||||||
|
import androidx.core.graphics.drawable.IconCompat
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
|
object ImageUtils {
|
||||||
|
|
||||||
|
fun bitmapToBase64String(resource : Bitmap) : String? {
|
||||||
|
val baos = ByteArrayOutputStream()
|
||||||
|
resource.compress(Bitmap.CompressFormat.PNG, 100, baos)
|
||||||
|
val iconArray = baos.toByteArray()
|
||||||
|
|
||||||
|
return if (iconArray != null && iconArray.size > 0) {
|
||||||
|
Base64.encodeToString(iconArray, Base64.DEFAULT)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stringToBitmap(src : String) : Bitmap? {
|
||||||
|
val iconArray = Base64.decode(src?.toByteArray(), Base64.DEFAULT)
|
||||||
|
return if (iconArray != null && iconArray.size > 0) {
|
||||||
|
BitmapFactory.decodeByteArray(iconArray, 0, iconArray.size)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11221
app/src/main/kotlin/rasel/lunar/launcher/utils/KoreanTrans.kt
Normal file
11221
app/src/main/kotlin/rasel/lunar/launcher/utils/KoreanTrans.kt
Normal file
File diff suppressed because it is too large
Load Diff
BIN
app/src/main/res/drawable/translate.png
Normal file
BIN
app/src/main/res/drawable/translate.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
@ -90,6 +90,10 @@
|
|||||||
android:src="@drawable/tmap"
|
android:src="@drawable/tmap"
|
||||||
style="@style/SearchIcons"
|
style="@style/SearchIcons"
|
||||||
android:id="@+id/search_tmap"/>
|
android:id="@+id/search_tmap"/>
|
||||||
|
<rasel.lunar.launcher.view.CircleImageView
|
||||||
|
android:src="@drawable/translate"
|
||||||
|
style="@style/SearchIcons"
|
||||||
|
android:id="@+id/search_translate"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<TextView
|
<TextView
|
||||||
android:paddingLeft="15dp"
|
android:paddingLeft="15dp"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user