Skip to content

Commit

Permalink
Fix AppList dimen bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshine0523 committed Aug 29, 2023
1 parent ee8515f commit a84601d
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ dependencies {
implementation(libs.constraintlayout)
implementation(libs.room.runtime)
implementation(platform(libs.compose.bom))
implementation(platform(libs.compose.bom))
androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(platform(libs.compose.bom))
ksp(libs.room.compiler)
implementation(libs.room.ktx)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
android:supportsRtl="true"
android:theme="@style/Theme.MiFreeform"
tools:targetApi="31">
<activity
android:name=".ui.app_list.FreeformAppActivity"
android:exported="false"
android:label="@string/title_activity_freeform_app"
android:theme="@style/Theme.MiFreeform" />
<activity
android:name=".ui.app_list.AppListActivity"
android:exported="true"
android:taskAffinity=":applist"
android:label="@string/title_activity_app_list"
android:taskAffinity=":applist"
android:theme="@style/Theme.MiFreeform" />
<activity
android:name=".ui.floating.FloatingActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ object MiFreeformServiceManager {
}

fun createDisplay(componentName: ComponentName, userId: Int, width: Int, height: Int, densityDpi: Int) {
Log.i(TAG, "$width $height $densityDpi")
iMiFreeformService?.startAppInFreeform(
componentName,
userId,
1000,
1400,
320,
width,
height,
densityDpi,
120.0f,
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ fun AppListItem(appInfo: AppInfo, viewModel: AppListViewModel) {
MiFreeformServiceManager.createDisplay(
appInfo.componentName,
appInfo.userId,
viewModel.getIntSp("freeform_width", (viewModel.screenWidth * 0.8).roundToInt()),
viewModel.getIntSp("freeform_height", (viewModel.screenHeight * 0.5).roundToInt()),
// I think AppListActivity must open in Freeform.
// So this `screen` is Freeform. I do not need scale. 0.8x 0.5x
viewModel.getIntSp("freeform_width", viewModel.screenWidth),
viewModel.getIntSp("freeform_height", viewModel.screenHeight),
viewModel.getIntSp("freeform_dpi", viewModel.screenDensityDpi),
)
viewModel.closeActivity()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.sunshine.freeform.ui.app_list

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import com.sunshine.freeform.R
import com.sunshine.freeform.ui.theme.MiFreeformTheme

class FreeformAppActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)
val viewModel = AppListViewModel(application)

setContent {
MiFreeformTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
ScaffoldWidget(viewModel)
}
}
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ScaffoldWidget(viewModel: AppListViewModel) {
Scaffold(
topBar = {
TopBarWidget()
},
contentWindowInsets = WindowInsets(0.dp, 0.dp, 0.dp, 0.dp)
) {
Box(modifier = Modifier.padding(it)) {

}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TopBarWidget() {
TopAppBar(
title = {
Text(text = stringResource(id = R.string.title_activity_freeform_app))
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.sunshine.freeform.MiFreeformServiceManager
import com.sunshine.freeform.R
import com.sunshine.freeform.room.FreeFormAppsEntity
import com.sunshine.freeform.ui.app_list.FreeformAppActivity
import kotlin.math.roundToInt

/**
Expand Down Expand Up @@ -88,7 +89,13 @@ class ChooseAppFloatingAdapter(
holder.icon.setImageResource(R.drawable.ic_add)
holder.appName.text = context.getString(R.string.edit_apps)
holder.click.setOnClickListener {
//context.startActivity(Intent(context, ChooseAppsActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) })
MiFreeformServiceManager.createDisplay(
ComponentName("com.sunshine.freeform", "com.sunshine.freeform.ui.app_list.FreeformAppActivity"),
0,
viewModel.getIntSp("freeform_width", (viewModel.screenWidth * 0.8).roundToInt()),
viewModel.getIntSp("freeform_height", (viewModel.screenHeight * 0.5).roundToInt()),
viewModel.getIntSp("freeform_dpi", viewModel.screenDensityDpi),
)
callback.onClick()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FloatingViewModel(context: Context) {
}

fun getIntSp(name: String, defaultValue: Int): Int {
if (sp.contains(name).not()) sp.edit().putInt(name, defaultValue).apply()
return sp.getInt(name, defaultValue)
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="freeform_height">小窗高度</string>
<string name="freeform_dpi">小窗分辨率</string>
<string name="freeform_width_height_warn">小窗高度必须大于宽度</string>
<string name="title_activity_freeform_app">选择小窗应用</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
<string name="freeform_height">Freeform Height</string>
<string name="freeform_dpi">Freeform DPI</string>
<string name="freeform_width_height_warn">Freeform`s height must bigger than width</string>

<!--FreeformAppActivity-->
<string name="title_activity_freeform_app">Choose Freeform App</string>
</resources>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 01 16:03:44 CST 2023
#Mon Aug 28 17:33:47 CST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit a84601d

Please sign in to comment.