Skip to content

Commit 55790d5

Browse files
Hugh GreenbergHugh Greenberg
authored andcommitted
Initial commit
1 parent 491d2e7 commit 55790d5

File tree

120 files changed

+2927
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+2927
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
# launchy
22
An Android Tv Launcher
3+
4+
Playstore link: https://play.google.com/store/apps/details?id=com.hugegreenbug.launchy
5+
6+
#Unsplash API
7+
My unsplash API key has been removed from UnsplashActivity.kt. It has the format of:
8+
9+
clientId = "clientId:api_key"
10+
11+
where api_key is your api key from Unsplash.com

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
}
5+
6+
apply plugin: 'kotlin-kapt'
7+
8+
android {
9+
signingConfigs {
10+
'default' {
11+
storeFile file('/Users/hugh/Documents/androidkeystore/Keystore')
12+
}
13+
}
14+
compileSdk 31
15+
16+
defaultConfig {
17+
applicationId "com.hugegreenbug.launchy"
18+
minSdk 26
19+
targetSdk 31
20+
versionCode 8
21+
versionName "1.0.5"
22+
}
23+
24+
buildTypes {
25+
release {
26+
minifyEnabled true
27+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28+
}
29+
}
30+
buildFeatures {
31+
viewBinding true
32+
}
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
kotlinOptions {
38+
jvmTarget = '1.8'
39+
}
40+
}
41+
42+
dependencies {
43+
implementation("androidx.leanback:leanback:1.2.0-alpha01")
44+
// leanback-preference is an add-on that provides a settings UI for TV apps.
45+
implementation("androidx.leanback:leanback-preference:1.2.0-alpha01")
46+
47+
implementation 'androidx.core:core-ktx:1.6.0'
48+
implementation 'androidx.appcompat:appcompat:1.3.1'
49+
implementation 'androidx.appcompat:appcompat-resources:1.3.1'
50+
implementation "androidx.room:room-runtime:2.3.0"
51+
implementation "com.anggrayudi:storage:0.13.0"
52+
implementation 'com.google.android.material:material:1.4.0'
53+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
54+
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
55+
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
56+
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
57+
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
58+
implementation 'androidx.preference:preference:1.1.1'
59+
implementation 'com.beust:klaxon:5.5'
60+
61+
kapt "androidx.room:room-compiler:2.3.0"
62+
63+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/release/app-release.aab

12.3 MB
Binary file not shown.

app/release/app-release.apk

12.2 MB
Binary file not shown.

app/release/output-metadata.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "com.hugegreenbug.launchy",
8+
"variantName": "release",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 7,
15+
"versionName": "1.0.4",
16+
"outputFile": "app-release.apk"
17+
}
18+
],
19+
"elementType": "File"
20+
}

app/src/main/AndroidManifest.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.hugegreenbug.launchy"
5+
android:versionCode="8"
6+
android:versionName="1.0.5">
7+
8+
<uses-feature
9+
android:name="android.software.leanback"
10+
android:required="true" />
11+
<uses-feature
12+
android:name="android.hardware.touchscreen"
13+
android:required="false" />
14+
15+
<uses-permission android:name="android.permission.SET_WALLPAPER" />
16+
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
17+
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
18+
tools:ignore="QueryAllPackagesPermission" />
19+
<uses-permission android:name="android.permission.INTERNET" />
20+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
21+
22+
<application
23+
android:allowBackup="true"
24+
android:banner="@mipmap/launchy_banner"
25+
android:icon="@mipmap/launchy_icon"
26+
android:label="@string/app_name"
27+
android:roundIcon="@mipmap/launchy_icon_round"
28+
android:supportsRtl="true"
29+
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
30+
<activity
31+
android:name="com.hugegreenbug.launchy.UnsplashWebview"
32+
android:theme="@style/Theme.TvPartyLauncher"
33+
android:launchMode="singleTask"
34+
android:exported="false"
35+
android:excludeFromRecents="true"
36+
>
37+
</activity>
38+
<activity
39+
android:name="com.hugegreenbug.launchy.UnsplashActivity"
40+
android:theme="@style/Theme.UnsplashList"
41+
android:launchMode="singleTask"
42+
android:exported="false"
43+
android:excludeFromRecents="true"
44+
>
45+
</activity>
46+
<activity android:name=".OnboardingActivity"
47+
android:enabled="true"
48+
android:excludeFromRecents="true"
49+
android:exported="false"
50+
android:theme="@style/Theme.Leanback.Onboarding" />
51+
<activity
52+
android:name="com.hugegreenbug.launchy.MainActivity"
53+
android:excludeFromRecents="true"
54+
android:exported="true"
55+
android:launchMode="singleTask"
56+
android:stateNotNeeded="true"
57+
android:theme="@style/Theme.TvPartyLauncher">
58+
<intent-filter>
59+
<action android:name="android.intent.action.MAIN" />
60+
61+
<category android:name="android.intent.category.LAUNCHER" />
62+
<category android:name="android.intent.category.LAUNCHER_APP" />
63+
<category android:name="android.intent.category.LEANBACK" />
64+
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
65+
<category android:name="android.intent.category.DEFAULT" />
66+
<category android:name="android.intent.category.HOME" />
67+
<category android:name="android.intent.category.MONKEY" />
68+
</intent-filter>
69+
</activity>
70+
</application>
71+
72+
</manifest>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.hugegreenbug.launchy
2+
3+
import android.annotation.SuppressLint
4+
import android.content.Context
5+
import android.content.Intent
6+
import android.content.pm.ComponentInfo
7+
import android.content.pm.PackageManager.MATCH_ALL
8+
import android.graphics.drawable.Drawable
9+
import android.util.ArrayMap
10+
11+
class AppManager(private val context: Context) {
12+
private val cachesize = 400
13+
private val appIconCache = ArrayMap<String, Drawable>(cachesize)
14+
private val packageManager = context.packageManager
15+
16+
@SuppressLint("QueryPermissionsNeeded")
17+
fun getLaunchableApps(): List<App> {
18+
val intent = Intent(Intent.ACTION_MAIN, null)
19+
intent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER)
20+
var list = packageManager.queryIntentActivities(intent, MATCH_ALL)
21+
.map { it.activityInfo }
22+
.map { App(it.packageName, it.loadLabel(packageManager).toString(), it, false) }
23+
val listIter = list.iterator()
24+
while (listIter.hasNext()) {
25+
val app = listIter.next()
26+
val drawable = getAppIcon(app.componentInfo)
27+
if (drawable == null) {
28+
list = list.filterIndexed { _, element ->
29+
element.packageName != app.packageName
30+
}
31+
}
32+
}
33+
34+
return list
35+
}
36+
37+
fun startApp(app: App) {
38+
val intent = packageManager.getLeanbackLaunchIntentForPackage(app.packageName)
39+
context.startActivity(intent)
40+
}
41+
42+
fun getAppIcon(componentInfo: ComponentInfo): Drawable?
43+
= appIconCache[componentInfo.packageName] ?: loadAppIcon(componentInfo)
44+
45+
private fun loadAppIcon(componentInfo: ComponentInfo): Drawable? {
46+
return try {
47+
val drawable = componentInfo.loadBanner(packageManager) ?: return null
48+
49+
drawable
50+
} catch (e: SecurityException) {
51+
null
52+
}
53+
}
54+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.hugegreenbug.launchy
2+
3+
import android.annotation.SuppressLint
4+
import android.app.Activity
5+
import android.app.WallpaperManager
6+
import android.graphics.Bitmap
7+
import android.graphics.Canvas
8+
import android.graphics.Matrix
9+
import android.graphics.Paint
10+
import android.graphics.drawable.BitmapDrawable
11+
import android.graphics.drawable.Drawable
12+
import java.io.IOException
13+
import android.util.DisplayMetrics
14+
import kotlin.concurrent.thread
15+
16+
class BitmapUtils {
17+
companion object {
18+
private fun returnBitmap(displayMetrics: DisplayMetrics, originalImage: Bitmap, width: Int, height: Int): Bitmap? {
19+
val background = Bitmap.createBitmap(displayMetrics, width, height, Bitmap.Config.ARGB_8888)
20+
val originalCopy = originalImage.copy(Bitmap.Config.ARGB_8888, true)
21+
val originalWidth = originalCopy.width.toFloat()
22+
val originalHeight = originalCopy.height.toFloat()
23+
val canvas = Canvas(background)
24+
val scale = width / originalWidth
25+
val xTranslation = 0.0f
26+
val yTranslation = (height - originalHeight * scale) / 2.0f
27+
val transformation = Matrix()
28+
transformation.postTranslate(xTranslation, yTranslation)
29+
transformation.preScale(scale, scale)
30+
val paint = Paint()
31+
paint.isFilterBitmap = true
32+
canvas.drawBitmap(originalCopy, transformation, paint)
33+
return background
34+
}
35+
36+
fun toBitmap(drawable:Drawable): Bitmap {
37+
if (drawable is BitmapDrawable) {
38+
return drawable.bitmap
39+
}
40+
41+
val width = if (drawable.bounds.isEmpty) drawable.intrinsicWidth else drawable.bounds.width()
42+
val height = if (drawable.bounds.isEmpty) drawable.intrinsicHeight else drawable.bounds.height()
43+
44+
return Bitmap.createBitmap(width.nonZero(), height.nonZero(), Bitmap.Config.ARGB_8888)
45+
.also {
46+
val canvas = Canvas(it)
47+
drawable.setBounds(0, 0, canvas.width, canvas.height)
48+
drawable.draw(canvas)
49+
}
50+
}
51+
52+
@SuppressLint("ResourceType")
53+
fun setWallpaper(drawable:Drawable, activity: Activity) {
54+
thread {
55+
val wallpaperManager = WallpaperManager.getInstance(activity.applicationContext)
56+
try {
57+
val displayMetrics: DisplayMetrics = activity.applicationContext.resources.displayMetrics
58+
val wallWidth = displayMetrics.widthPixels
59+
val wallHeight = displayMetrics.heightPixels
60+
wallpaperManager.suggestDesiredDimensions(wallWidth, wallHeight)
61+
val bitmap = toBitmap(drawable)
62+
val newBmap = returnBitmap(displayMetrics, bitmap, wallWidth, wallHeight)
63+
if (newBmap != null) {
64+
wallpaperManager.setBitmap(newBmap)
65+
}
66+
bitmap.recycle()
67+
} catch (e: IOException) {
68+
e.printStackTrace()
69+
}
70+
}
71+
}
72+
private fun Int.nonZero() = if (this <= 0) 1 else this
73+
}
74+
}

0 commit comments

Comments
 (0)