Skip to content

Commit b749391

Browse files
author
sds100
committed
Merge branch 'release/1.1.0'
2 parents cf6fc69 + 9e1f17c commit b749391

37 files changed

+770
-385
lines changed

app/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "io.github.sds100.keymapper"
1313
minSdkVersion 19
1414
targetSdkVersion 28
15-
versionCode 14
16-
versionName "1.1.0-beta.6"
15+
versionCode 15
16+
versionName "1.1.0-beta.7"
1717
vectorDrawables.useSupportLibrary = true
1818
}
1919

@@ -40,6 +40,7 @@ dependencies {
4040
implementation 'com.github.salomonbrys.kotson:kotson:2.5.0'
4141
implementation 'com.hannesdorfmann:adapterdelegates4:4.0.0'
4242
implementation 'com.github.mukeshsolanki:MarkdownView-Android:1.0.8'
43+
implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
4344

4445
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
4546
implementation 'androidx.core:core-ktx:1.0.2'

app/src/main/java/io/github/sds100/keymapper/activity/HomeActivity.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ import io.github.sds100.keymapper.service.MyAccessibilityService
4040
import io.github.sds100.keymapper.service.MyIMEService
4141
import io.github.sds100.keymapper.util.*
4242
import io.github.sds100.keymapper.view.BottomSheetMenu
43+
import io.github.sds100.keymapper.view.StatusLayout
4344
import io.github.sds100.keymapper.viewmodel.HomeViewModel
4445
import kotlinx.android.synthetic.main.activity_home.*
4546
import kotlinx.android.synthetic.main.bottom_sheet_home.view.*
4647
import kotlinx.android.synthetic.main.content_home.*
48+
import kotlinx.android.synthetic.main.home_collapsed_status_layouts.*
49+
import kotlinx.android.synthetic.main.home_expanded_status_layouts.*
4750
import org.jetbrains.anko.*
4851

4952
class HomeActivity : AppCompatActivity(), SelectionCallback, OnItemClickListener<KeymapAdapterModel> {
@@ -72,6 +75,16 @@ class HomeActivity : AppCompatActivity(), SelectionCallback, OnItemClickListener
7275
private val mKeymapAdapter: KeymapAdapter = KeymapAdapter(this)
7376
private val mBottomSheetView by lazy { BottomSheetMenu.create(R.layout.bottom_sheet_home) }
7477

78+
private val mStatusLayouts
79+
get() = sequence {
80+
yield(accessibilityServiceStatusLayout)
81+
yield(imeServiceStatusLayout)
82+
83+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
84+
yield(dndAccessStatusLayout)
85+
}
86+
}.toList()
87+
7588
private var mActionModeActive = false
7689
set(value) {
7790
field = value
@@ -268,15 +281,24 @@ class HomeActivity : AppCompatActivity(), SelectionCallback, OnItemClickListener
268281
if (MyIMEService.isServiceEnabled(this)) {
269282
imeServiceStatusLayout.changeToFixedState()
270283
} else {
271-
imeServiceStatusLayout.changeToErrorState()
284+
imeServiceStatusLayout.changeToWarningState()
272285
}
273286

274287
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
275288
if (accessNotificationPolicyGranted) {
276289
dndAccessStatusLayout.changeToFixedState()
277290
} else {
278-
dndAccessStatusLayout.changeToErrorState()
291+
dndAccessStatusLayout.changeToWarningState()
292+
}
293+
}
294+
295+
when {
296+
mStatusLayouts.all { it.state == StatusLayout.State.FIXED } -> collapsedStatusLayout.changeToFixedState()
297+
mStatusLayouts.any { it.state == StatusLayout.State.ERROR } -> {
298+
collapsedStatusLayout.changeToErrorState()
299+
cardViewStatus.expanded = true
279300
}
301+
mStatusLayouts.any { it.state == StatusLayout.State.WARN } -> collapsedStatusLayout.changeToWarningState()
280302
}
281303
}
282304

app/src/main/java/io/github/sds100/keymapper/activity/LogActivity.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import io.github.sds100.keymapper.R
77
import io.github.sds100.keymapper.fragment.LogFragment
88
import io.github.sds100.keymapper.util.FeedbackUtils
99
import io.github.sds100.keymapper.util.Logger
10+
import org.jetbrains.anko.alert
11+
import org.jetbrains.anko.okButton
1012

1113
/**
1214
* Created by sds100 on 11/05/2019.
@@ -16,7 +18,6 @@ class LogActivity : SimpleFragmentActivity() {
1618
override val fragmentToShow: Fragment
1719
get() = LogFragment()
1820

19-
2021
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
2122
menuInflater.inflate(R.menu.menu_log, menu)
2223

@@ -25,10 +26,19 @@ class LogActivity : SimpleFragmentActivity() {
2526

2627
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
2728
when (item?.itemId) {
28-
R.id.action_delete_log -> Logger.deleteLog(this)
29+
R.id.action_delete_log -> Logger.delete(this)
2930

3031
R.id.action_send_log -> {
31-
FeedbackUtils.sendFeedback(this, "\n\nHere is a log:\n${Logger.getLogText(this)}")
32+
alert {
33+
messageResource = R.string.dialog_message_describe_your_issue_in_the_email
34+
okButton {
35+
FeedbackUtils.sendFeedback(
36+
this@LogActivity,
37+
"Can you please describe your issue here:\n\n" +
38+
"Here is a log:\n${Logger.read(this@LogActivity)}"
39+
)
40+
}
41+
}.show()
3242
}
3343
}
3444

app/src/main/java/io/github/sds100/keymapper/adapter/KeymapAdapter.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import android.view.ViewGroup
66
import android.widget.CheckBox
77
import androidx.recyclerview.widget.LinearLayoutManager
88
import com.google.android.material.chip.Chip
9-
import io.github.sds100.keymapper.interfaces.OnItemClickListener
109
import io.github.sds100.keymapper.KeyMap
1110
import io.github.sds100.keymapper.KeymapAdapterModel
1211
import io.github.sds100.keymapper.R
12+
import io.github.sds100.keymapper.interfaces.OnItemClickListener
13+
import io.github.sds100.keymapper.onSuccess
1314
import io.github.sds100.keymapper.selection.SelectionCallback
1415
import io.github.sds100.keymapper.selection.SelectionEvent
1516
import io.github.sds100.keymapper.selection.SelectionProvider
1617
import io.github.sds100.keymapper.util.FlagUtils
1718
import io.github.sds100.keymapper.util.str
1819
import io.github.sds100.keymapper.viewholder.SelectableViewHolder
19-
import io.github.sds100.keymapper.onSuccess
2020
import kotlinx.android.synthetic.main.keymap_adapter_item.view.*
2121

2222
/**
@@ -43,13 +43,13 @@ class KeymapAdapter(private val mOnItemClickListener: OnItemClickListener<Keymap
4343
iSelectionProvider.subscribeToSelectionEvents(this)
4444
}
4545

46-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KeymapAdapter.ViewHolder {
46+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
4747
val inflater = LayoutInflater.from(parent.context)
4848

4949
return ViewHolder(inflater.inflate(R.layout.keymap_adapter_item, parent, false))
5050
}
5151

52-
override fun onBindViewHolder(holder: KeymapAdapter.ViewHolder, position: Int) {
52+
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
5353
super.onBindViewHolder(holder, position)
5454

5555
val model = itemList[position]

app/src/main/java/io/github/sds100/keymapper/fragment/LogFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LogFragment : Fragment(), ShowTextFromUrlDelegate {
4545
}
4646

4747
private fun updateText() {
48-
val text = Logger.getLogText(context!!)
48+
val text = Logger.read(context!!)
4949

5050
(view as MarkdownView).let { markDownView ->
5151
markDownView.setMarkDownText(text)

app/src/main/java/io/github/sds100/keymapper/service/MyAccessibilityService.kt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
5858
const val ACTION_ON_STOP = "$PACKAGE_NAME.ON_STOP_ACCESSIBILITY_SERVICE"
5959

6060
/**
61-
* How long should the accessibility service record a trigger. In milliseconds.
61+
* How long should the accessibility service record a trigger in ms.
6262
*/
6363
private const val RECORD_TRIGGER_TIMER_LENGTH = 5000L
6464

6565
/**
6666
* The time in ms between repeating an action while holding down.
6767
*/
68-
private const val REPEAT_DELAY = 5L
68+
private const val REPEAT_DELAY = 50L
6969

7070
/**
7171
* How long a key should be held down to repeatedly perform an action in ms.
@@ -176,7 +176,12 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
176176
val jsonString = intent.getStringExtra(EXTRA_KEYMAP_CACHE_JSON)
177177

178178
if (jsonString != null) {
179-
mKeyMapListCache = Gson().fromJson(jsonString)
179+
/* app can crash if it can't deserialize the JSON. I don't know how to handle the try-catch in a
180+
* meaningful way */
181+
try {
182+
mKeyMapListCache = Gson().fromJson(jsonString)
183+
} catch (e: Exception) {
184+
}
180185
}
181186
}
182187

@@ -298,6 +303,8 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
298303

299304
WidgetsManager.onEvent(ctx, EVENT_SERVICE_START)
300305
sendBroadcast(Intent(ACTION_ON_START))
306+
307+
Logger.write(ctx, title = "Service Started", message = "Accessibility Service started")
301308
}
302309

303310
override fun onInterrupt() {}
@@ -309,15 +316,17 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
309316
mLifecycleRegistry.markState(Lifecycle.State.DESTROYED)
310317
unregisterReceiver(mBroadcastReceiver)
311318
sendBroadcast(Intent(ACTION_ON_STOP))
319+
320+
Logger.write(ctx, title = "Service Destroyed", message = "Accessibility Service destroyed")
312321
}
313322

314323
override fun onAccessibilityEvent(event: AccessibilityEvent?) {}
315324

316325
override fun onKeyEvent(event: KeyEvent?): Boolean {
317326
when {
318-
event?.action == KeyEvent.ACTION_DOWN -> Logger.log(ctx, "Down Key Event", event.toString())
319-
event?.action == KeyEvent.ACTION_UP -> Logger.log(ctx, "Up Key Event", event.toString())
320-
else -> Logger.log(ctx, "Other Key Event", event.toString())
327+
event?.action == KeyEvent.ACTION_DOWN -> Logger.write(ctx, "Down Key Event", event.toString())
328+
event?.action == KeyEvent.ACTION_UP -> Logger.write(ctx, "Up Key Event", event.toString())
329+
else -> Logger.write(ctx, "Other Key Event", event.toString())
321330
}
322331

323332
if (event == null) return super.onKeyEvent(event)
@@ -495,10 +504,12 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
495504
}
496505

497506
} catch (e: Exception) {
498-
Logger.log(ctx, "Exception in onKeyEvent()", e.stackTrace.toString())
507+
Logger.write(ctx,
508+
isError = true,
509+
title = "Exception in onKeyEvent()",
510+
message = e.stackTrace.toString())
499511

500512
if (BuildConfig.DEBUG) {
501-
toast(R.string.exception_accessibility_service)
502513
Log.e(this::class.java.simpleName, "ONKEYEVENT CRASH")
503514
e.printStackTrace()
504515
}
@@ -512,7 +523,7 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
512523
private fun performAction(action: Action, flags: Int) {
513524
mActionPerformerDelegate.performAction(action, flags)
514525

515-
Logger.log(ctx, "Performed Action", "${action.type} ${action.data} ${action.extras}")
526+
Logger.write(ctx, "Performed Action", "${action.type} ${action.data} ${action.extras}")
516527

517528
mPressedTriggerKeys.forEach {
518529
if (KEYS_TO_CONSUME_UP_EVENT.contains(it)) {
@@ -555,9 +566,9 @@ class MyAccessibilityService : AccessibilityService(), IContext, IPerformGlobalA
555566

556567
private fun logConsumedKeyEvent(event: KeyEvent) {
557568
if (event.action == KeyEvent.ACTION_DOWN) {
558-
Logger.log(ctx, "Consumed Down", event.toString())
569+
Logger.write(ctx, "Consumed Down", event.toString())
559570
} else if (event.action == KeyEvent.ACTION_UP) {
560-
Logger.log(ctx, "Consumed Up", event.toString())
571+
Logger.write(ctx, "Consumed Up", event.toString())
561572
}
562573

563574
Log.i(this::class.java.simpleName, "Consumed key event ${event.keyCode} ${event.action}")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.github.sds100.keymapper.util
2+
3+
/**
4+
* Created by sds100 on 22/05/2019.
5+
*/
6+
7+
fun Boolean?.isNotNullAndTrue(): Boolean {
8+
return this != null && this == true
9+
}

app/src/main/java/io/github/sds100/keymapper/util/BrightnessUtils.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.sds100.keymapper.util
22

33
import android.content.Context
4-
import android.provider.Settings
54
import android.provider.Settings.System.*
65
import androidx.annotation.IntDef
76

@@ -10,8 +9,8 @@ import androidx.annotation.IntDef
109
*/
1110
object BrightnessUtils {
1211
@IntDef(value = [
13-
Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC,
14-
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
12+
SCREEN_BRIGHTNESS_MODE_AUTOMATIC,
13+
SCREEN_BRIGHTNESS_MODE_MANUAL
1514
])
1615
@Retention(AnnotationRetention.SOURCE)
1716
annotation class BrightnessMode
@@ -25,40 +24,42 @@ object BrightnessUtils {
2524
//auto-brightness must be disabled
2625
setBrightnessMode(ctx, SCREEN_BRIGHTNESS_MODE_MANUAL)
2726

28-
val currentBrightness = Settings.System.getInt(ctx.contentResolver, SCREEN_BRIGHTNESS)
29-
var newBrightness = currentBrightness + BRIGHTNESS_CHANGE_STEP
27+
ctx.getSystemSetting<Int>(SCREEN_BRIGHTNESS)?.let { currentBrightness ->
3028

31-
//the brightness must be between 0 and 255
32-
if (newBrightness > 255) newBrightness = 255
29+
var newBrightness = currentBrightness + BRIGHTNESS_CHANGE_STEP
3330

34-
Settings.System.putInt(ctx.contentResolver, SCREEN_BRIGHTNESS, newBrightness)
31+
//the brightness must be between 0 and 255
32+
if (newBrightness > 255) newBrightness = 255
33+
34+
ctx.putSystemSetting(SCREEN_BRIGHTNESS, newBrightness)
35+
}
3536
}
3637

3738
fun decreaseBrightness(ctx: Context) {
3839
//auto-brightness must be disabled
3940
setBrightnessMode(ctx, SCREEN_BRIGHTNESS_MODE_MANUAL)
4041

41-
val currentBrightness = Settings.System.getInt(ctx.contentResolver, SCREEN_BRIGHTNESS)
42+
ctx.getSystemSetting<Int>(SCREEN_BRIGHTNESS)?.let { currentBrightness ->
4243

43-
var newBrightness = currentBrightness - BRIGHTNESS_CHANGE_STEP
44+
var newBrightness = currentBrightness - BRIGHTNESS_CHANGE_STEP
4445

45-
//the brightness must be between 0 and 255
46-
if (newBrightness < 0) newBrightness = 0
46+
//the brightness must be between 0 and 255
47+
if (newBrightness < 0) newBrightness = 0
4748

48-
Settings.System.putInt(ctx.contentResolver, SCREEN_BRIGHTNESS, newBrightness)
49+
ctx.putSystemSetting(SCREEN_BRIGHTNESS, newBrightness)
50+
}
4951
}
5052

5153
fun setBrightnessMode(ctx: Context, @BrightnessMode mode: Int) {
5254
if (!ctx.haveWriteSettingsPermission) return
5355

54-
Settings.System.putInt(ctx.contentResolver, SCREEN_BRIGHTNESS_MODE, mode)
56+
ctx.putSystemSetting(SCREEN_BRIGHTNESS_MODE, mode)
5557
}
5658

5759
fun toggleAutoBrightness(ctx: Context) {
5860
if (!ctx.haveWriteSettingsPermission) return
5961

60-
val currentBrightnessMode =
61-
Settings.System.getInt(ctx.contentResolver, SCREEN_BRIGHTNESS_MODE)
62+
val currentBrightnessMode = ctx.getSystemSetting<Int>(SCREEN_BRIGHTNESS_MODE)
6263

6364
if (currentBrightnessMode == SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
6465
setBrightnessMode(ctx, SCREEN_BRIGHTNESS_MODE_MANUAL)

0 commit comments

Comments
 (0)