-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb483ed
commit 7977a3b
Showing
7 changed files
with
141 additions
and
7 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
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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/sunshine/freeform/receiver/BootReceiver.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,22 @@ | ||
package com.sunshine.freeform.receiver | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.sunshine.freeform.MiFreeform | ||
import com.sunshine.freeform.service.SidebarService | ||
|
||
/** | ||
* @author KindBrave | ||
* @since 2023/9/19 | ||
*/ | ||
class BootReceiver : BroadcastReceiver() { | ||
companion object { | ||
private const val BOOT = "android.intent.action.BOOT_COMPLETED" | ||
} | ||
override fun onReceive(context: Context, intent: Intent) { | ||
if (intent.action == BOOT) { | ||
context.startService(Intent(context, SidebarService::class.java)) | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/sunshine/freeform/receiver/StartFreeformReceiver.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,40 @@ | ||
package com.sunshine.freeform.receiver | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.sunshine.freeform.MiFreeform | ||
import com.sunshine.freeform.MiFreeformServiceManager | ||
import kotlin.math.roundToInt | ||
|
||
/** | ||
* @author KindBrave | ||
* @since 2023/9/19 | ||
*/ | ||
class StartFreeformReceiver : BroadcastReceiver() { | ||
companion object { | ||
private const val ACTION = "com.sunshine.freeform.start_freeform" | ||
} | ||
override fun onReceive(context: Context, intent: Intent) { | ||
if (intent.action == ACTION) { | ||
val packageName = intent.getStringExtra("packageName") | ||
val activityName = intent.getStringExtra("activityName") | ||
val userId = intent.getIntExtra("userId", 0) | ||
|
||
if (packageName != null && activityName != null) { | ||
val sp = context.getSharedPreferences(MiFreeform.CONFIG, Context.MODE_PRIVATE) | ||
val screenWidth = context.resources.displayMetrics.widthPixels | ||
val screenHeight = context.resources.displayMetrics.heightPixels | ||
val screenDensityDpi = context.resources.displayMetrics.densityDpi | ||
MiFreeformServiceManager.createWindow( | ||
packageName, | ||
activityName, | ||
userId, | ||
sp.getInt("freeform_width", (screenWidth * 0.8).roundToInt()), | ||
sp.getInt("freeform_height", (screenHeight * 0.5).roundToInt()), | ||
sp.getInt("freeform_dpi", screenDensityDpi), | ||
) | ||
} | ||
} | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/sunshine/freeform/service/SidebarService.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,48 @@ | ||
package com.sunshine.freeform.service | ||
|
||
import android.app.Service | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.PixelFormat | ||
import android.os.IBinder | ||
import android.view.WindowManager | ||
import android.view.WindowManagerHidden | ||
|
||
class SidebarService : Service() { | ||
|
||
private lateinit var viewModel: ServiceViewModel | ||
private val layoutParams = WindowManagerHidden.LayoutParams() | ||
private lateinit var windowManager: WindowManager | ||
|
||
override fun onBind(intent: Intent): IBinder? { | ||
return null | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
viewModel = ServiceViewModel(application) | ||
windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager | ||
if (viewModel.getBooleanSp("sideline", false)) initSideLine() | ||
return START_STICKY | ||
} | ||
|
||
/** | ||
* 启动侧边条 | ||
*/ | ||
private fun initSideLine() { | ||
// val screenWidth = resources.displayMetrics.widthPixels | ||
// val isLeft = viewModel.getBooleanSp() | ||
// layoutParams.apply { | ||
// type = 2026 | ||
// width = 100 | ||
// height = screenHeight / 5 | ||
// x = -screenWidth / 2 | ||
// y = -screenHeight / 6 | ||
// flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or | ||
// WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or | ||
// WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or | ||
// WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | ||
// privateFlags = WindowManagerHidden.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS or WindowManagerHidden.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY or WindowManagerHidden.LayoutParams.PRIVATE_FLAG_USE_BLAST or WindowManagerHidden.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY | ||
// format = PixelFormat.RGBA_8888 | ||
// } | ||
} | ||
} |
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