-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Refactor some of the setting to also work other places.
- Loading branch information
1 parent
7d04c20
commit 72f212e
Showing
11 changed files
with
175 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/github/droidworksstudio/launcher/helper/AppExtensions.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.github.droidworksstudio.launcher.helper | ||
|
||
import android.app.SearchManager | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.pm.LauncherApps | ||
import android.net.Uri | ||
import android.os.UserHandle | ||
import android.util.Log | ||
import android.view.View | ||
import android.view.inputmethod.InputMethodManager | ||
import android.widget.EditText | ||
import com.github.droidworksstudio.launcher.Constants | ||
|
||
fun View.hideKeyboard() { | ||
this.clearFocus() | ||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
imm.hideSoftInputFromWindow(windowToken, 0) | ||
} | ||
|
||
fun View.showKeyboard(show: Boolean = true) { | ||
if (show.not()) return | ||
if (this.requestFocus()) | ||
this.postDelayed({ | ||
this.findViewById<EditText>(androidx.appcompat.R.id.search_src_text).apply { | ||
textSize = 28f | ||
isCursorVisible = false | ||
} | ||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
@Suppress("DEPRECATION") | ||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY) | ||
}, 100) | ||
} | ||
|
||
fun Context.openSearch(query: String? = null) { | ||
val intent = Intent(Intent.ACTION_WEB_SEARCH) | ||
intent.putExtra(SearchManager.QUERY, query ?: "") | ||
startActivity(intent) | ||
} | ||
|
||
fun Context.openUrl(url: String) { | ||
if (url.isEmpty()) return | ||
val intent = Intent(Intent.ACTION_VIEW) | ||
intent.data = Uri.parse(url) | ||
startActivity(intent) | ||
} | ||
|
||
fun Context.searchOnPlayStore(query: String? = null): Boolean { | ||
return try { | ||
val playStoreIntent = Intent(Intent.ACTION_VIEW) | ||
playStoreIntent.data = Uri.parse("${Constants.APP_GOOGLE_PLAY_STORE}=$query") | ||
|
||
// Check if the Play Store app is installed | ||
if (playStoreIntent.resolveActivity(packageManager) != null) { | ||
startActivity(playStoreIntent) | ||
} else { | ||
// If Play Store app is not installed, open Play Store website in browser | ||
playStoreIntent.data = Uri.parse("${Constants.URL_GOOGLE_PLAY_STORE}=$query") | ||
startActivity(playStoreIntent) | ||
} | ||
true | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
false | ||
} | ||
} | ||
|
||
fun Context.searchCustomSearchEngine(searchQuery: String? = null): Boolean { | ||
val searchUrl = Constants.URL_GOOGLE_SEARCH | ||
val encodedQuery = Uri.encode(searchQuery) | ||
val fullUrl = "$searchUrl$encodedQuery" | ||
Log.d("fullUrl", fullUrl) | ||
openUrl(fullUrl) | ||
return true | ||
} | ||
|
||
fun Context.isPackageInstalled(packageName: String, userHandle: UserHandle = android.os.Process.myUserHandle()): Boolean { | ||
val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps | ||
val activityInfo = launcher.getActivityList(packageName, userHandle) | ||
return activityInfo.size > 0 | ||
} |
This file contains 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
This file contains 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
This file contains 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
17 changes: 16 additions & 1 deletion
17
app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawViewHolder.kt
This file contains 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
This file contains 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
Oops, something went wrong.