Skip to content

Commit 67dc4b0

Browse files
committed
#1562 feat: Key Mapper can open .zip and .json files as default and import key maps
1 parent 0eff815 commit 67dc4b0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
android:exported="true"
9494
android:relinquishTaskIdentity="true"
9595
android:theme="@style/Theme.App.Starting"
96+
android:launchMode="singleInstance"
9697
android:windowSoftInputMode="adjustResize">
9798
<!-- IMPORTANT! windowSoftInputMode is needed for IME padding to work
9899
properly in the ChooseActionScreen search bar for example. -->
@@ -110,6 +111,22 @@
110111
<!-- Set as default so the Assistant Trigger app isn't opened by default. -->
111112
<category android:name="android.intent.category.DEFAULT" />
112113
</intent-filter>
114+
115+
<intent-filter>
116+
<action android:name="android.intent.action.VIEW" />
117+
118+
<category android:name="android.intent.category.DEFAULT" />
119+
<category android:name="android.intent.category.BROWSABLE" />
120+
121+
<data
122+
android:mimeType="application/zip"
123+
android:scheme="content" />
124+
125+
<data
126+
android:mimeType="application/json"
127+
android:scheme="content" />
128+
129+
</intent-filter>
113130
</activity>
114131

115132
<!-- Use a different task affinity so this activity doesn't close other activities -->

app/src/main/java/io/github/sds100/keymapper/BaseMainActivity.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ import com.anggrayudi.storage.extension.toDocumentFile
2929
import io.github.sds100.keymapper.Constants.PACKAGE_NAME
3030
import io.github.sds100.keymapper.compose.ComposeColors
3131
import io.github.sds100.keymapper.databinding.ActivityMainBinding
32+
import io.github.sds100.keymapper.home.HomeViewModel
3233
import io.github.sds100.keymapper.mappings.keymaps.trigger.RecordTriggerController
3334
import io.github.sds100.keymapper.system.accessibility.AccessibilityServiceAdapter
3435
import io.github.sds100.keymapper.system.files.FileUtils
3536
import io.github.sds100.keymapper.system.inputevents.MyMotionEvent
3637
import io.github.sds100.keymapper.system.permissions.AndroidPermissionAdapter
3738
import io.github.sds100.keymapper.system.permissions.RequestPermissionDelegate
39+
import io.github.sds100.keymapper.util.Inject
3840
import io.github.sds100.keymapper.util.launchRepeatOnLifecycle
3941
import io.github.sds100.keymapper.util.ui.showPopups
4042
import kotlinx.coroutines.Dispatchers
@@ -72,6 +74,10 @@ abstract class BaseMainActivity : AppCompatActivity() {
7274
ActivityViewModel.Factory(ServiceLocator.resourceProvider(this))
7375
}
7476

77+
val homeViewModel by viewModels<HomeViewModel> {
78+
Inject.homeViewModel(this)
79+
}
80+
7581
private val currentNightMode: Int
7682
get() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
7783

@@ -179,6 +185,8 @@ abstract class BaseMainActivity : AppCompatActivity() {
179185
ContextCompat.RECEIVER_EXPORTED,
180186
)
181187
}
188+
189+
importKeyMaps(intent)
182190
}
183191

184192
override fun onResume() {
@@ -200,6 +208,12 @@ abstract class BaseMainActivity : AppCompatActivity() {
200208
super.onDestroy()
201209
}
202210

211+
override fun onNewIntent(intent: Intent) {
212+
super.onNewIntent(intent)
213+
214+
importKeyMaps(intent)
215+
}
216+
203217
override fun onGenericMotionEvent(event: MotionEvent?): Boolean {
204218
event ?: return super.onGenericMotionEvent(event)
205219

@@ -214,6 +228,14 @@ abstract class BaseMainActivity : AppCompatActivity() {
214228
}
215229
}
216230

231+
private fun importKeyMaps(intent: Intent) {
232+
if (intent.action == Intent.ACTION_VIEW) {
233+
intent.data?.let {
234+
homeViewModel.onChooseImportFile(it.toString())
235+
}
236+
}
237+
}
238+
217239
private fun saveFile(originalFile: Uri, targetFile: Uri) {
218240
lifecycleScope.launch(Dispatchers.IO) {
219241
targetFile.openOutputStream(this@BaseMainActivity)?.use { output ->

0 commit comments

Comments
 (0)