Skip to content

Commit

Permalink
Modify notification shade collapse to android API call
Browse files Browse the repository at this point in the history
  • Loading branch information
vamsi3 committed Feb 11, 2023
1 parent efaed44 commit a6d334e
Show file tree
Hide file tree
Showing 54 changed files with 273 additions and 500 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Notice that using the Screen Translator app is much quicker than the traditional

1. When user touches the quick settings tile, an intent is sent by `ScreenTranslatorTileService::onClick` to trigger `ScreenTranslatorAccessibilityService::onStartCommand`
2. If the user didn't give accessibility permissions yet, they are <u>redirected to accessibility settings page</u>.
3. If the accessibility permissions are present, a <u>swipe up gesture is sent</u> to system uisng accessiblity service to collapse notification panel from which quick settings tile was triggered.
3. If the accessibility permissions are present, notification panel collapse request is send to system.
4. Finally, a <u>screenshot is taken</u> using accessiblity service and sent to Papago / Google Lens app for further translation inside their app's activity.
5. If Papago / Google Lens app is not installed in the system, user is notified of the same through a toast.

Expand Down
10 changes: 6 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {

defaultConfig {
applicationId = "com.vamsi3.android.screentranslator"
versionCode = 2
versionName = "0.0.3"
versionCode = 4
versionName = "0.0.4"
}

buildTypes {
Expand All @@ -26,10 +26,12 @@ android {
}

dependencies {
implementation(project(":core:design"))
implementation(project(":core:ui"))
implementation(project(":core:resource"))
implementation(project(":feature:settings"))
implementation(project(":feature:translate"))
implementation(project(":core:ui"))
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.compose.material.icons)
implementation(libs.androidx.core.splashscreen)
}
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
android:name=".ScreenTranslatorApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/Theme.ScreenTranslator">

Expand All @@ -37,12 +36,15 @@
<service
android:name=".feature.translate.ScreenTranslatorTileService"
android:exported="true"
android:icon="@drawable/ic_baseline_translate_24"
android:icon="@drawable/ic_translate_tile"
android:label="@string/app_name"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="false" />
</service>

<service
Expand All @@ -53,11 +55,11 @@
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>

<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.vamsi3.android.screentranslator.fileProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,75 @@
package com.vamsi3.android.screentranslator

import android.app.StatusBarManager
import android.content.ComponentName
import android.graphics.drawable.Icon
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.vamsi3.android.screentranslator.core.ui.HomeScreen
import com.vamsi3.android.screentranslator.feature.translate.ScreenTranslatorTileService
import com.vamsi3.android.screentranslator.core.resource.R
import com.vamsi3.android.screentranslator.feature.settings.SettingsUiState
import com.vamsi3.android.screentranslator.feature.settings.SettingsUiState.Loading
import com.vamsi3.android.screentranslator.feature.settings.SettingsUiState.Success
import com.vamsi3.android.screentranslator.feature.settings.SettingsViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

val viewModel: SettingsViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)

var uiState: SettingsUiState by mutableStateOf(Loading)

lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState
.collectLatest {
uiState = it
}
}
}

splashScreen.setKeepOnScreenCondition {
when (uiState) {
Loading -> true
is Success -> false
}
}

setContent {
HomeScreen()
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val statusBarManager = getSystemService(StatusBarManager::class.java)

statusBarManager.requestAddTileService(
ComponentName(
this,
ScreenTranslatorTileService::class.java,
),
getString(R.string.translate_tile_label),
Icon.createWithResource(this, R.drawable.ic_translate_tile),
{},
{}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class ScreenTranslatorApplication : Application() {}
class ScreenTranslatorApplication : Application()
30 changes: 0 additions & 30 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

170 changes: 0 additions & 170 deletions app/src/main/res/drawable/ic_launcher_background.xml

This file was deleted.

5 changes: 0 additions & 5 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

This file was deleted.

Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions app/src/main/res/values/strings.xml

This file was deleted.

7 changes: 0 additions & 7 deletions app/src/main/res/xml/accessibility_service_config.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
}

extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig {
Expand All @@ -20,5 +19,4 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
}
}
}

}
Loading

0 comments on commit a6d334e

Please sign in to comment.