This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove some reflection usages in favor of official APIs on API 29
- Loading branch information
Showing
8 changed files
with
68 additions
and
40 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
androidApp/src/main/java/press/theme/EditTextSelectionHandleReflection.kt
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
package press.theme | ||
|
||
import android.graphics.drawable.Drawable | ||
import android.os.Build.VERSION | ||
import android.widget.TextView | ||
import androidx.appcompat.content.res.AppCompatResources.getDrawable | ||
import press.util.reflect | ||
|
||
object TextViewCompat { | ||
|
||
fun textSelectionHandles(view: TextView): Array<Drawable> { | ||
if (VERSION.SDK_INT >= 29) { | ||
return arrayOf(view.textSelectHandle!!, view.textSelectHandleLeft!!, view.textSelectHandleRight!!) | ||
|
||
} else { | ||
val centerDrawableResId = reflect(TextView::class, "mTextSelectHandleRes").getInt(view) | ||
val leftDrawableResId = reflect(TextView::class, "mTextSelectHandleLeftRes").getInt(view) | ||
val rightDrawableResId = reflect(TextView::class, "mTextSelectHandleRightRes").getInt(view) | ||
|
||
val editorField = reflect(TextView::class, "mEditor") | ||
val editor = editorField.get(view) | ||
|
||
val centerDrawable = getDrawable(view.context, centerDrawableResId)!! | ||
val leftDrawable = getDrawable(view.context, leftDrawableResId)!! | ||
val rightDrawable = getDrawable(view.context, rightDrawableResId)!! | ||
|
||
reflect(editor::class, "mSelectHandleCenter").set(editor, centerDrawable) | ||
reflect(editor::class, "mSelectHandleLeft").set(editor, leftDrawable) | ||
reflect(editor::class, "mSelectHandleRight").set(editor, rightDrawable) | ||
|
||
return arrayOf(centerDrawable, leftDrawable, rightDrawable) | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
androidApp/src/main/java/press/widgets/ScrollViewCompat.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,23 @@ | ||
package press.widgets | ||
|
||
import android.os.Build.VERSION | ||
import android.widget.EdgeEffect | ||
import android.widget.ScrollView | ||
import androidx.annotation.ColorInt | ||
import press.util.reflect | ||
|
||
object ScrollViewCompat { | ||
|
||
fun setEdgeEffectColor(view: ScrollView, @ColorInt color: Int) { | ||
if (VERSION.SDK_INT >= 29) { | ||
view.topEdgeEffectColor = color | ||
view.bottomEdgeEffectColor = color | ||
|
||
} else { | ||
val topEdge = reflect(ScrollView::class, "mEdgeGlowTop").get(view) as EdgeEffect | ||
val bottomEdge = reflect(ScrollView::class, "mEdgeGlowBottom").get(view) as EdgeEffect | ||
topEdge.color = color | ||
bottomEdge.color = color | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<!-- The user never sees this Drawable. See TintedCursorDrawableInterceptor. --> | ||
<size android:width="2dp" /> | ||
<solid android:color="#FF0000" /> | ||
</shape> |
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