Skip to content

Commit ed2fa2b

Browse files
committed
fghjfjhfghj
1 parent b54fd40 commit ed2fa2b

File tree

14 files changed

+582
-2
lines changed

14 files changed

+582
-2
lines changed

app/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ dependencies {
205205
// https://developer.android.com/jetpack/androidx/releases/xr-compose
206206
implementation(libs.androidx.compose)
207207
testImplementation(libs.androidx.compose.testing)
208+
209+
// Glance Widget!!!!
210+
// https://youtu.be/bhrN7yFG0D4
211+
implementation(libs.androidx.glance)
212+
implementation(libs.androidx.glance.appwidget)
208213
}
209214

210215
//composeCompiler {

app/src/main/java/com/perkedel/htlauncher/HTUIState.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ data class HTUIState(
4545
// val themesList:MutableMap<String,ItemData> = LinkedHashMap<String,ItemData>(),
4646
// TODO: Medias, Shortcuts
4747
// val installedPackageInfo: MutableList<PackageInfo> = emptyList<PackageInfo>().toMutableList()
48-
val installedPackageInfo: MutableMap<String,SearchableApps> = LinkedHashMap<String,SearchableApps>()
48+
val installedPackageInfo: MutableMap<String,SearchableApps> = LinkedHashMap<String,SearchableApps>(),
49+
val standaloneWidgetIdSelected:Int = 1,
50+
val standaloneWidgetConfigMode:String = "",
4951
) {
5052
}

app/src/main/java/com/perkedel/htlauncher/HTViewModel.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,22 @@ class HTViewModel(
736736
}
737737
}
738738

739+
fun setStandaloneWidgetIdSelected(of: Int){
740+
_uiState.update {
741+
currentState -> currentState.copy(
742+
standaloneWidgetIdSelected = of
743+
)
744+
}
745+
}
746+
747+
fun setStandaloneWidgetConfigMode(of: String){
748+
_uiState.update {
749+
currentState -> currentState.copy(
750+
standaloneWidgetConfigMode = of
751+
)
752+
}
753+
}
754+
739755
fun getPageData(of:String = "", json:Json = Json{
740756
prettyPrint = true
741757
encodeDefaults = true
@@ -964,4 +980,6 @@ class HTViewModel(
964980
else -> R.drawable.open_a_page
965981
}
966982
}
983+
984+
967985
}

app/src/main/java/com/perkedel/htlauncher/MainActivity.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.activity.ComponentActivity
66
import androidx.activity.compose.setContent
77
import androidx.activity.enableEdgeToEdge
88
import android.content.Context;
9+
import android.content.Intent
910
import android.content.pm.PackageManager;
1011
import android.graphics.Color
1112
import android.os.Build
@@ -175,6 +176,11 @@ class MainActivity : ComponentActivity() {
175176

176177
}
177178

179+
180+
@Override
181+
fun onActivityResult(requestCode:Int, resultCode:Int, data:Intent){
182+
183+
}
178184
}
179185
}
180186

app/src/main/java/com/perkedel/htlauncher/Navigation.kt

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
package com.perkedel.htlauncher
44

55
import android.Manifest
6+
import android.app.Activity.RESULT_CANCELED
7+
import android.app.Activity.RESULT_OK
8+
import android.appwidget.AppWidgetHost
9+
import android.appwidget.AppWidgetManager
10+
import android.appwidget.AppWidgetProvider
11+
import android.appwidget.AppWidgetProviderInfo
612
import android.content.ActivityNotFoundException
713
import android.content.ComponentName
814
import android.content.ContentResolver
@@ -31,7 +37,9 @@ import android.view.SoundEffectConstants
3137
import android.view.View
3238
import android.widget.Toast
3339
import androidx.activity.ComponentActivity
40+
import androidx.activity.compose.ManagedActivityResultLauncher
3441
import androidx.activity.compose.rememberLauncherForActivityResult
42+
import androidx.activity.result.ActivityResult
3543
import androidx.activity.result.contract.ActivityResultContracts
3644
import androidx.compose.animation.AnimatedContentTransitionScope
3745
import androidx.compose.animation.ExperimentalSharedTransitionApi
@@ -134,6 +142,7 @@ import com.perkedel.htlauncher.ui.navigation.ItemsExplorer
134142
import com.perkedel.htlauncher.ui.navigation.LevelEditor
135143
import com.perkedel.htlauncher.ui.navigation.PurchaseScreen
136144
import com.perkedel.htlauncher.ui.navigation.StandalonePageScreen
145+
import com.perkedel.htlauncher.ui.navigation.StandaloneWidgetScreen
137146
import com.perkedel.htlauncher.ui.theme.HTLauncherTheme
138147
import com.perkedel.htlauncher.ui.theme.rememberColorScheme
139148
import com.perkedel.htlauncher.widgets.ChangeSaveDirDialog
@@ -149,6 +158,7 @@ import kotlinx.serialization.json.Json
149158
import java.io.BufferedReader
150159
import java.io.IOException
151160
import java.io.InputStreamReader
161+
import kotlin.math.log
152162

153163
@OptIn(ExperimentalMaterial3Api::class)
154164
@Composable
@@ -178,6 +188,10 @@ fun Navigation(
178188
prettyPrint = true
179189
encodeDefaults = true
180190
},
191+
appWidgetManager:AppWidgetManager = AppWidgetManager.getInstance(context),
192+
appWidgetId: Int = 1,
193+
appWidgetHost:AppWidgetHost = AppWidgetHost(context, appWidgetId),
194+
// appWidgetInfo: AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(appWidgetId),
181195
tts: MutableState<TextToSpeech?> = rememberTextToSpeech(),
182196
view: View = LocalView.current,
183197
inspectionMode:Boolean = LocalInspectionMode.current,
@@ -477,6 +491,70 @@ fun Navigation(
477491
println("No Test File Selected")
478492
}
479493
}
494+
// var eAppWidgetInfo : AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(appWidgetId+1)
495+
// var eAppWidgetInfo : AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(appWidgetId+1)
496+
var widgetSelectLauncher: ManagedActivityResultLauncher<Intent, ActivityResult> = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {activityResult ->
497+
Log.d("Widgeting","YOU ARE NOT SUPPOSED TO VIEW PROTOTYPE!")
498+
}
499+
widgetSelectLauncher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityResult ->
500+
// https://www.leonardofischer.com/hosting-android-widgets-my-appwidgethost-tutorial/
501+
val resultCode = activityResult.resultCode
502+
// val requestCode = activityResult.requestCode
503+
val intentData = activityResult.data
504+
val dataExtras = intentData?.extras
505+
val requestCode = dataExtras?.getString("requestCode","") ?: ""
506+
// val asdfasd = intentData.extras
507+
Log.d("Widgeting","datas Intent ${intentData.toString()}")
508+
Log.d("Widgeting", "Wants to ${requestCode} || ${htuiState.standaloneWidgetConfigMode}")
509+
Log.d("Widgeting", "Widget Selected: ${dataExtras.toString()}")
510+
var finalWidgetId:Int = dataExtras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) ?: -1
511+
Log.d("Widgeting","final id = ${finalWidgetId}")
512+
val internAppWidgetInfo : AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(finalWidgetId)
513+
Log.d("Widgeting","internAppWidgetInfo ${internAppWidgetInfo.toString()}")
514+
if(resultCode == RESULT_OK)
515+
{
516+
Log.d("Widgeting","Doing Result now")
517+
// if(finalWidgetId != -1)
518+
// anViewModel.setStandaloneWidgetIdSelected(finalWidgetId)
519+
if(requestCode == "REQUEST_PICK_APPWIDGET" || htuiState.standaloneWidgetConfigMode == "REQUEST_PICK_APPWIDGET")
520+
{
521+
// val internAppWidgetInfo : AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(finalWidgetId)
522+
Log.d("Widgeting","Config the widget?")
523+
if(internAppWidgetInfo.configure != null)
524+
{
525+
Log.d("Widgeting","Let's go config!")
526+
val configingIntent: Intent = Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE)
527+
configingIntent.setComponent(internAppWidgetInfo.configure)
528+
configingIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, finalWidgetId)
529+
anViewModel.setStandaloneWidgetConfigMode("REQUEST_CREATE_APPWIDGET")
530+
Log.d("Widgeting","Launch the congiruataefa!")
531+
widgetSelectLauncher.launch(configingIntent)
532+
} else {
533+
Log.d("Widgeting","No config! just create it!")
534+
// widgetSelectLauncher.launch(intentData)
535+
anViewModel.setStandaloneWidgetIdSelected(finalWidgetId)
536+
anViewModel.setStandaloneWidgetConfigMode("")
537+
}
538+
} else if (requestCode == "REQUEST_CREATE_APPWIDGET" || htuiState.standaloneWidgetConfigMode == "REQUEST_CREATE_APPWIDGET")
539+
{
540+
// val internAppWidgetInfo : AppWidgetProviderInfo = appWidgetManager.getAppWidgetInfo(finalWidgetId)
541+
Log.d("Widgeting","@@@ Create the widget!")
542+
anViewModel.setStandaloneWidgetIdSelected(finalWidgetId)
543+
anViewModel.setStandaloneWidgetConfigMode("")
544+
}
545+
}
546+
else if (resultCode == RESULT_CANCELED && intentData != null)
547+
{
548+
finalWidgetId = dataExtras?.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) ?: -1
549+
if (finalWidgetId == -1)
550+
{
551+
appWidgetHost.deleteAppWidgetId(finalWidgetId)
552+
553+
}
554+
anViewModel.setStandaloneWidgetConfigMode("")
555+
}
556+
// anViewModel.setStandaloneWidgetConfigMode("")
557+
}
480558

481559

482560

@@ -695,6 +773,7 @@ fun Navigation(
695773
color = when{
696774
currentScreen == Screen.HomeScreen.name -> Color.Transparent
697775
currentScreen == Screen.AllAppsScreen.name -> Color.Transparent
776+
currentScreen == Screen.WidgetTest.name -> Color.Transparent
698777
currentScreen.startsWith("${context.packageName}.data.PageData") -> Color.Transparent
699778
else -> colorScheme.background
700779
}
@@ -1113,6 +1192,81 @@ fun Navigation(
11131192
anViewModel = anViewModel
11141193
)
11151194
}
1195+
composable(route = Screen.WidgetTest.name,
1196+
enterTransition = {
1197+
slideIntoContainer(
1198+
towards = AnimatedContentTransitionScope.SlideDirection.Up,
1199+
animationSpec = tween(),
1200+
)
1201+
},
1202+
exitTransition = {
1203+
slideOutOfContainer(
1204+
towards = AnimatedContentTransitionScope.SlideDirection.Left,
1205+
animationSpec = tween(),
1206+
)
1207+
},
1208+
popEnterTransition = {
1209+
slideIntoContainer(
1210+
towards = AnimatedContentTransitionScope.SlideDirection.Right,
1211+
animationSpec = tween()
1212+
)
1213+
},
1214+
popExitTransition = {
1215+
slideOutOfContainer(
1216+
towards = AnimatedContentTransitionScope.SlideDirection.Down,
1217+
animationSpec = tween()
1218+
)
1219+
}
1220+
) {
1221+
LaunchedEffect(
1222+
htuiState.standaloneWidgetIdSelected
1223+
) {
1224+
Log.d("Widgeting", "Standalone Widget ID Selected: ${htuiState.standaloneWidgetIdSelected}")
1225+
}
1226+
StandaloneWidgetScreen(
1227+
onAllAppButtonClicked = {
1228+
navController.navigate(Screen.AllAppsScreen.name)
1229+
},
1230+
onMoreMenuButtonClicked = {
1231+
anViewModel.openTheMoreMenu(true)
1232+
1233+
},
1234+
context = context,
1235+
configuration = configuration,
1236+
colorScheme = colorScheme,
1237+
haptic = haptic,
1238+
// DONE: handover the homescreen file json
1239+
configFile = htuiState.coreConfigJson,
1240+
viewModel = anViewModel,
1241+
contentResolver = saveDirResolver,
1242+
systemUiController = systemUiController,
1243+
uiState = htuiState,
1244+
coroutineScope = coroutineScope,
1245+
isReady = htuiState.isReady,
1246+
tts = tts,
1247+
onLaunchOneOfAction = {
1248+
onLaunchAction(
1249+
data = it,
1250+
context = context,
1251+
coroutineScope = coroutineScope,
1252+
pm = pm,
1253+
snackbarHostState = snackbarHostState,
1254+
contentResolver = saveDirResolver,
1255+
navController = navController,
1256+
viewModel = anViewModel,
1257+
uiState = htuiState,
1258+
inspectionMode = inspectionMode,
1259+
handoverPagerState = homePagerState,
1260+
tts = tts,
1261+
)
1262+
},
1263+
widgetSelectLauncher = widgetSelectLauncher,
1264+
appWidgetManager = appWidgetManager,
1265+
appWidgetHost = appWidgetHost,
1266+
// appWidgetId = appWidgetId,
1267+
appWidgetId = htuiState.standaloneWidgetIdSelected,
1268+
)
1269+
}
11161270
composable(route = Screen.ConfigurationScreen.name,
11171271
enterTransition = {
11181272
slideIntoContainer(
@@ -1176,6 +1330,10 @@ fun Navigation(
11761330
navController.navigate(Screen.LevelEditor.name)
11771331
}
11781332
ConfigSelected.ItemsExplorer -> {}
1333+
ConfigSelected.StandaloneWidget -> {
1334+
// test widget
1335+
navController.navigate(Screen.WidgetTest.name)
1336+
}
11791337
else -> {}
11801338
}
11811339
},
@@ -2219,7 +2377,7 @@ fun onLaunchAction(
22192377

22202378
}
22212379
containAction == context.resources.getString(ActionInternalCommand.Gallery.id) -> {
2222-
2380+
//TODO: default app how do I get that?!
22232381
}
22242382
containAction == context.resources.getString(ActionInternalCommand.GoToPage.id) -> {
22252383
if(data[selectAction].args[0].isNotBlank()){
@@ -2303,6 +2461,16 @@ fun onLaunchAction(
23032461
}
23042462
}
23052463

2464+
fun configureWidget(intentData: Intent)
2465+
{
2466+
// https://www.leonardofischer.com/hosting-android-widgets-my-appwidgethost-tutorial/
2467+
}
2468+
2469+
fun createWidget(intentData: Intent)
2470+
{
2471+
2472+
}
2473+
23062474
@PreviewFontScale
23072475
@PreviewLightDark
23082476
@PreviewScreenSizes
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.perkedel.htlauncher.data
2+
3+
data class WidgetData(
4+
val type:String = "Widget",
5+
val name:String = "anWidget",
6+
val widgetPackage:String = "",
7+
)

app/src/main/java/com/perkedel/htlauncher/enumerations/ConfigSelected.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ enum class ConfigSelected(@StringRes val title: Int, val key:String = "") {
2121
Compatibility(title = R.string.default_screen, key = "compatibility"),
2222
RemoveDefault(title = R.string.default_screen, key = "remove_default"),
2323
UserManual(title = R.string.default_screen, key = "user_manual"),
24+
StandaloneWidget(title = R.string.default_screen, key = "standalone_widget"),
2425
}

app/src/main/java/com/perkedel/htlauncher/enumerations/Screen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum class Screen (@StringRes val title: Int){
2828
LevelEditor(title = R.string.editor_screen),
2929
ItemsExplorer(title = R.string.items_explorer_screen),
3030
OpenAPage(title = R.string.open_page_screen),
31+
WidgetTest(title = R.string.widget_test_screen),
3132
GetStarted(title = R.string.get_started_screen),
3233
PurchaseScreen(title = R.string.purchase_screen),
3334
}

0 commit comments

Comments
 (0)