-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'standalone_keyboard_conversion'
- Loading branch information
Showing
42 changed files
with
458 additions
and
186 deletions.
There are no files selected for viewing
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
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
18 changes: 0 additions & 18 deletions
18
android/app/src/main/kotlin/com/drakota/bttvstickers/MainActivity.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 |
---|---|---|
@@ -1,24 +1,6 @@ | ||
package com.drakota.bttvstickers | ||
|
||
import android.content.Intent | ||
import android.util.Log | ||
import androidx.annotation.NonNull | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.plugin.common.MethodChannel | ||
|
||
class MainActivity: FlutterActivity() { | ||
private val CHANNEL = "com.drakota.bttvstickers/sticker_indexing_service" | ||
|
||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { | ||
call, result -> | ||
if (call.method == "generatePack") { | ||
val intent = Intent(baseContext, StickerIndexingService::class.java) | ||
intent.putExtra("emotes", call.arguments as ArrayList<HashMap<String, String>>) | ||
startService(intent) | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
android/app/src/main/kotlin/com/drakota/bttvstickers/PackAdapter.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,44 @@ | ||
package com.drakota.bttvstickers | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.BaseAdapter | ||
import android.widget.ImageView | ||
import com.bumptech.glide.Glide | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
|
||
|
||
class PackAdapter(var context: Context, var emotes: JSONArray, var commitContent: (emote: JSONObject) -> Unit) : BaseAdapter() { | ||
private val inflator: LayoutInflater = LayoutInflater.from(context) | ||
|
||
override fun getCount(): Int { | ||
return emotes.length() | ||
} | ||
|
||
override fun getItem(position: Int): JSONObject { | ||
return emotes.get(position) as JSONObject | ||
} | ||
|
||
override fun getItemId(position: Int): Long { | ||
return position.toLong() | ||
} | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||
val emote = emotes.get(position) as JSONObject | ||
val view = convertView ?: inflator.inflate(R.layout.emote, parent, false) | ||
|
||
view.setOnClickListener(View.OnClickListener { _ -> | ||
commitContent(emote) | ||
Utils.performHapticFeedback(context, 15) | ||
return@OnClickListener | ||
}) | ||
|
||
val imageView = view.findViewById<ImageView>(R.id.EmoteImage) | ||
val url = emote.getString("imageUrl") | ||
Glide.with(context).load(url).into(imageView) | ||
return view | ||
} | ||
} |
90 changes: 0 additions & 90 deletions
90
android/app/src/main/kotlin/com/drakota/bttvstickers/StickerIndexingService.kt
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
android/app/src/main/kotlin/com/drakota/bttvstickers/StickerInputMethod.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,83 @@ | ||
package com.drakota.bttvstickers | ||
|
||
import android.content.ClipDescription | ||
import android.content.res.Configuration | ||
import android.inputmethodservice.InputMethodService | ||
import android.net.Uri | ||
import android.os.Build | ||
import android.view.View | ||
import android.view.inputmethod.EditorInfo | ||
import android.widget.GridView | ||
import androidx.core.content.FileProvider | ||
import androidx.core.view.inputmethod.InputConnectionCompat | ||
import androidx.core.view.inputmethod.InputContentInfoCompat | ||
import com.bumptech.glide.Glide | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
import java.io.File | ||
|
||
|
||
class StickerInputMethod : InputMethodService() { | ||
private val PACK_PATH_PATTERN = "%s/app_flutter/pack.json" | ||
|
||
private fun commitImage(emote: JSONObject, contentUri: Uri) { | ||
val mimeType = "image/" + emote.getString("imageType") | ||
val inputContentInfo = InputContentInfoCompat( | ||
contentUri, | ||
ClipDescription(emote.getString("code"), arrayOf(mimeType)), | ||
null | ||
) | ||
val inputConnection = currentInputConnection | ||
val editorInfo = currentInputEditorInfo | ||
var flags = 0 | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { | ||
flags = flags or InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION | ||
} | ||
InputConnectionCompat.commitContent(inputConnection, editorInfo, inputContentInfo, flags, null) | ||
} | ||
|
||
private fun commitContent(emote: JSONObject) { | ||
val future = Glide | ||
.with(applicationContext) | ||
.downloadOnly() | ||
.load(emote.getString("imageUrl")) | ||
.submit() | ||
|
||
Thread { | ||
val temp = future.get() | ||
val cacheFile = File(applicationContext.externalCacheDir, "cached_sticker") | ||
temp.copyTo(cacheFile, true) | ||
|
||
val contentUri = if (Build.VERSION.SDK_INT >= 24) | ||
FileProvider.getUriForFile( | ||
applicationContext, | ||
applicationContext.packageName + ".fileProvider", | ||
cacheFile | ||
) | ||
else | ||
Uri.fromFile(cacheFile) | ||
|
||
commitImage(emote, contentUri) | ||
}.start() | ||
} | ||
|
||
override fun onStartInputView(info: EditorInfo?, restarting: Boolean) { | ||
setInputView(onCreateInputView()) | ||
} | ||
|
||
override fun onCreateInputView(): View? { | ||
val root: View = layoutInflater.inflate(R.layout.keyboard, null) | ||
val emoteList: GridView = root.findViewById(R.id.EmoteList) | ||
emoteList.numColumns = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) 4 else 8 | ||
val dataDir = applicationContext.packageManager.getPackageInfo(applicationContext.packageName, 0).applicationInfo.dataDir; | ||
val packFile = File(String.format(PACK_PATH_PATTERN, dataDir)) | ||
|
||
val emotes = if (packFile.exists()) { | ||
val pack = JSONObject(packFile.readText(Charsets.UTF_8)) | ||
pack.getJSONArray("emotes") | ||
} else JSONArray() | ||
|
||
emoteList.adapter = PackAdapter(applicationContext, emotes, this::commitContent) | ||
return root | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
android/app/src/main/kotlin/com/drakota/bttvstickers/Utils.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,22 @@ | ||
package com.drakota.bttvstickers | ||
|
||
import android.os.Build | ||
import android.os.VibrationEffect | ||
import android.os.Vibrator | ||
import android.content.Context | ||
|
||
class Utils { | ||
companion object { | ||
fun performHapticFeedback(context: Context, ms: Long) { | ||
val vibratorService = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator | ||
vibratorService.let { vs -> | ||
if (Build.VERSION.SDK_INT >= 26) { | ||
vs.vibrate(VibrationEffect.createOneShot(ms, VibrationEffect.DEFAULT_AMPLITUDE)) | ||
} else { | ||
@Suppress("DEPRECATION") | ||
vs.vibrate(ms) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.