Skip to content

Commit 158ac3c

Browse files
committed
make png fallback configurable and improve share sheet
1 parent c604547 commit 158ac3c

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

app/src/main/java/com/fredhappyface/ewesticker/ImageKeyboard.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
5858
private var iconsPerX = 0
5959
private var iconSize = 0
6060
private var insensitiveSort = false
61+
private var isPngFallback = true
6162

6263
// Constants
6364
private lateinit var internalDir: File
@@ -127,6 +128,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
127128
this.scroll = this.backupSharedPreferences.getBoolean("scroll", false)
128129
this.vibrate = this.backupSharedPreferences.getBoolean("vibrate", true)
129130
this.insensitiveSort = this.backupSharedPreferences.getBoolean("insensitiveSort", false)
131+
this.isPngFallback = this.backupSharedPreferences.getBoolean("isPngFallback", true)
130132

131133
this.iconsPerX = this.backupSharedPreferences.getInt("iconsPerX", 3)
132134
this.totalIconPadding =
@@ -228,6 +230,7 @@ class ImageKeyboard : InputMethodService(), StickerClickListener {
228230
this.currentInputEditorInfo,
229231
this.compatCache,
230232
this.imageLoader,
233+
this.isPngFallback,
231234
)
232235
}
233236

app/src/main/java/com/fredhappyface/ewesticker/MainActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class MainActivity : AppCompatActivity() {
9191
toggle(findViewById(R.id.restoreOnClose), "restoreOnClose", false) {}
9292
toggle(findViewById(R.id.scroll), "scroll", false) {}
9393
toggle(findViewById(R.id.insensitive_sort), "insensitiveSort", false) {}
94+
toggle(findViewById(R.id.pngFallback), "isPngFallback", true) {}
9495

9596
val versionText: TextView = findViewById(R.id.versionText)
9697
var version = getString(R.string.version_text)

app/src/main/java/com/fredhappyface/ewesticker/utilities/StickerSender.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import java.io.IOException
3636
* @property compatCache: used to track previous x converted compat stickers
3737
* @property imageLoader: coil imageLoader object used to convert a sticker file to a drawable ready
3838
* for writing to a compat sticker
39+
* @property isPngFallback: is a png fallback enabled
3940
*/
4041
class StickerSender(
4142
private val context: Context,
@@ -45,6 +46,7 @@ class StickerSender(
4546
private val currentInputEditorInfo: EditorInfo?,
4647
private val compatCache: Cache,
4748
private val imageLoader: ImageLoader,
49+
private val isPngFallback: Boolean,
4850
) {
4951

5052
private val supportedMimes = this.currentInputEditorInfo?.contentMimeTypes ?: emptyArray()
@@ -175,7 +177,7 @@ class StickerSender(
175177
*/
176178
private suspend fun doFallbackCommitContent(mimeType: String, file: File) {
177179

178-
if ("image/png" in supportedMimes || "image/*" in supportedMimes) {
180+
if (isPngFallback && ("image/png" in supportedMimes || "image/*" in supportedMimes)) {
179181
val compatSticker = createCompatSticker(file)
180182
if (compatSticker != null) {
181183
if (!doCommitContent("image/png", compatSticker)) {
@@ -209,6 +211,7 @@ class StickerSender(
209211
}
210212

211213
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
214+
shareIntent.setPackage(packageName)
212215

213216
val chooserIntent = Intent.createChooser(shareIntent, "Share Sticker")
214217
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

app/src/main/res/layout/activity_main.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,20 @@
259259
android:text="@string/options_insensitive_sort" />
260260
</LinearLayout>
261261

262+
<LinearLayout
263+
style="@style/widthMatchHeightWrap"
264+
android:orientation="horizontal">
265+
266+
<CheckBox
267+
android:id="@+id/pngFallback"
268+
style="@style/checkbox" />
269+
270+
<TextView
271+
style="@style/body_text"
272+
android:paddingBottom="@dimen/content_margin"
273+
android:text="@string/options_png_fallback" />
274+
</LinearLayout>
275+
262276
<LinearLayout
263277
style="@style/widthMatchHeightWrap"
264278
android:orientation="horizontal">

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<string name="options_restore_on_close">Restore previous keyboard on keyboard close</string>
2727
<string name="options_scroll">Enable swipe between packs (perpendicular to scroll direction)</string>
2828
<string name="options_insensitive_sort">Enable case-insensitive pack sorting</string>
29+
<string name="options_png_fallback">Enable PNG sticker fallback if sticker format isn\'t supported</string>
2930
<string name="options_icons_per_x_lbl">"Number of Rows: "</string>
3031
<string name="options_icon_size_status_lbl">"Icon size: "</string>
3132
<!-- Info -->

0 commit comments

Comments
 (0)