From 5a3c5bfa57e42637f7b23ecbe9689ce7d9944e5e Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Mon, 29 Jun 2020 17:07:42 +0530 Subject: [PATCH 1/5] Add ic_launcher_foreground --- .../res/drawable/ic_launcher_foreground.xml | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file -- GitLab From 1628565e4f9cd9ebcba33f9133962b17bb98e524 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 30 Jun 2020 21:47:40 +0530 Subject: [PATCH 2/5] Add data to intent-filter --- app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e6ea6cf..727c79a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,8 +38,9 @@ android:exported="true"> - + + -- GitLab From 308c556660b48a63aa6fe39aac3bbeda4a302e6e Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Wed, 1 Jul 2020 11:58:09 +0530 Subject: [PATCH 3/5] Don't show settings as a separate icon in menu --- app/src/main/res/menu/home_menu.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/menu/home_menu.xml b/app/src/main/res/menu/home_menu.xml index e4ea5b1..56e8c5f 100644 --- a/app/src/main/res/menu/home_menu.xml +++ b/app/src/main/res/menu/home_menu.xml @@ -4,7 +4,7 @@ + app:showAsAction="never"/> Date: Mon, 27 Jul 2020 12:49:59 +0530 Subject: [PATCH 4/5] Set task description directly from PlayerActivity than modifying in android_frameworks. --- .../pwaplayer/ui/home/HomeRecyclerAdapter.kt | 13 +- .../e/pwaplayer/ui/player/PwaActivity.java | 104 --------------- .../e/pwaplayer/ui/player/PwaActivity.kt | 120 ++++++++++++++++++ .../foundation/e/pwaplayer/util/Extensions.kt | 10 ++ 4 files changed, 133 insertions(+), 114 deletions(-) delete mode 100644 app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.java create mode 100644 app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt create mode 100644 app/src/main/java/foundation/e/pwaplayer/util/Extensions.kt diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt index 0c625ab..a581661 100644 --- a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt +++ b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt @@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView import foundation.e.pwaplayer.R import foundation.e.pwaplayer.database.Pwa import foundation.e.pwaplayer.ui.player.PwaActivity +import foundation.e.pwaplayer.util.toBitmap class HomeRecyclerAdapter( private val context: Context, @@ -32,7 +33,8 @@ class HomeRecyclerAdapter( intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) intent.action = "foundation.e.blisslauncher.VIEW_PWA" intent.data = Uri.parse(items[adapterPosition].url) - intent.putExtra("PWA_NAME", items[adapterPosition].title) + intent.putExtra(PwaActivity.KEY_PWA_NAME, items[adapterPosition].title) + intent.putExtra(PwaActivity.KEY_PWA_ICON, items[adapterPosition].iconBlob) context.startActivity(intent) } } @@ -40,9 +42,6 @@ class HomeRecyclerAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PwaViewHolder { val view = LayoutInflater.from(context).inflate(R.layout.item_pwa, parent, false) - view.setOnClickListener { - - } return PwaViewHolder(view) } @@ -61,9 +60,3 @@ class HomeRecyclerAdapter( notifyDataSetChanged() } } - -private fun ByteArray.toBitmap(): Bitmap? { - return BitmapFactory.decodeByteArray( - this, 0, this.size - ) -} diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.java b/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.java deleted file mode 100644 index ac24614..0000000 --- a/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package foundation.e.pwaplayer.ui.player; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.view.KeyEvent; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -import foundation.e.apps.pwa.PwaWebChromeClient; -import foundation.e.pwaplayer.R; - -public class PwaActivity extends AppCompatActivity { - - public static final String KEY_PWA_NAME = "PWA_NAME"; - public static final String KEY_SCOPE = "pwa_scope"; - - private PwaWebChromeClient pwaWebChromeClient; - private WebView webView; - - private static final String TAG = "PwaActivity"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Intent intent = getIntent(); - if (intent == null) { - Toast.makeText(this, "URL can't be empty", Toast.LENGTH_SHORT).show(); - finish(); - } - String name = getIntent().getStringExtra(KEY_PWA_NAME); - setName(this, name); - setContentView(R.layout.activity_pwa); - - pwaWebChromeClient = new PwaWebChromeClient(this, name); - webView = (WebView) findViewById(R.id.webView); - setWebView(webView, pwaWebChromeClient); - - } - - private void setName(Activity activity, String name) { - if (!name.isEmpty()) { - activity.setTitle(name); - } - } - - @SuppressLint("SetJavaScriptEnabled") - private void setWebView(WebView webView, PwaWebChromeClient pwaWebChromeClient) { - WebSettings webSettings = webView.getSettings(); - webSettings.setJavaScriptEnabled(true); - webSettings.setAllowContentAccess(true); - webSettings.setLoadWithOverviewMode(true); - webSettings.setAllowFileAccess(true); - webSettings.setAllowUniversalAccessFromFileURLs(true); - webSettings.setAllowContentAccess(true); - webSettings.setAllowFileAccessFromFileURLs(true); - webSettings.setDomStorageEnabled(true); - String start_url = getIntent().getData().toString(); - String scope = getIntent().getStringExtra(KEY_SCOPE); - if(scope == null) scope = ""; - webView.setWebChromeClient(pwaWebChromeClient); - webView.setWebViewClient(new PwaWebViewClient(start_url, scope)); - webView.loadUrl(start_url); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - switch (requestCode) { - case PwaWebChromeClient.REQUEST_LOCATION_PERMISSION: { - if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - pwaWebChromeClient.locationPermissionGranted(); - } else { - pwaWebChromeClient.locationPermissionDenied(); - } - } - } - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK && webView != null && webView.canGoBack()) { - webView.goBack(); - return true; - } - return super.onKeyDown(keyCode, event); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - if (requestCode == PwaWebChromeClient.REQUEST_FILE_CHOOSER) { - pwaWebChromeClient.onActivityResult(resultCode, data); - } - super.onActivityResult(requestCode, resultCode, data); - - } -} diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt b/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt new file mode 100644 index 0000000..3f3e290 --- /dev/null +++ b/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt @@ -0,0 +1,120 @@ +package foundation.e.pwaplayer.ui.player + +import android.annotation.SuppressLint +import android.app.Activity +import android.app.ActivityManager.TaskDescription +import android.content.Intent +import android.content.pm.PackageManager +import android.os.Bundle +import android.view.KeyEvent +import android.view.View +import android.webkit.WebView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import foundation.e.apps.pwa.PwaWebChromeClient +import foundation.e.pwaplayer.R +import foundation.e.pwaplayer.util.toBitmap + +class PwaActivity : AppCompatActivity() { + private var pwaWebChromeClient: PwaWebChromeClient? = null + private var webView: WebView? = null + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val intent = intent + if (intent == null) { + Toast.makeText(this, "URL can't be empty", Toast.LENGTH_SHORT).show() + finish() + } + val name = getIntent().getStringExtra(KEY_PWA_NAME) + setPwaTaskInfo( + this, + name, + getIntent().getByteArrayExtra(KEY_PWA_ICON) + ) + setContentView(R.layout.activity_pwa) + pwaWebChromeClient = PwaWebChromeClient(this, name) + webView = findViewById(R.id.webView) as WebView + setWebView(webView, pwaWebChromeClient!!) + } + + private fun setPwaTaskInfo( + activity: Activity, + name: String?, + iconBytes: ByteArray? + ) { + if (name.isNullOrEmpty()) { + return + } + activity.title = name + val icon = iconBytes?.let { iconBytes.toBitmap() } + val taskDescription: TaskDescription + if (icon != null) { + taskDescription = TaskDescription(name, icon) + setTaskDescription(taskDescription) + } else { + taskDescription = TaskDescription(name) + } + setTaskDescription(taskDescription) + } + + @SuppressLint("SetJavaScriptEnabled") + private fun setWebView(webView: WebView?, pwaWebChromeClient: PwaWebChromeClient) { + val webSettings = webView!!.settings + webSettings.javaScriptEnabled = true + webSettings.allowContentAccess = true + webSettings.loadWithOverviewMode = true + webSettings.allowFileAccess = true + webSettings.allowUniversalAccessFromFileURLs = true + webSettings.allowContentAccess = true + webSettings.allowFileAccessFromFileURLs = true + webSettings.domStorageEnabled = true + val start_url = intent.data.toString() + var scope = intent.getStringExtra(KEY_SCOPE) + if (scope == null) scope = "" + webView.webChromeClient = pwaWebChromeClient + webView.webViewClient = PwaWebViewClient(start_url, scope) + webView.loadUrl(start_url) + } + + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { + when (requestCode) { + PwaWebChromeClient.REQUEST_LOCATION_PERMISSION -> { + if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + pwaWebChromeClient!!.locationPermissionGranted() + } else { + pwaWebChromeClient!!.locationPermissionDenied() + } + } + } + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { + if (keyCode == KeyEvent.KEYCODE_BACK && webView != null && webView!!.canGoBack()) { + webView!!.goBack() + return true + } + return super.onKeyDown(keyCode, event) + } + + override fun onActivityResult( + requestCode: Int, + resultCode: Int, + data: Intent? + ) { + if (requestCode == PwaWebChromeClient.REQUEST_FILE_CHOOSER) { + pwaWebChromeClient!!.onActivityResult(resultCode, data) + } + super.onActivityResult(requestCode, resultCode, data) + } + + companion object { + const val KEY_PWA_NAME = "PWA_NAME" + const val KEY_PWA_ICON = "PWA_ICON" + const val KEY_SCOPE = "pwa_scope" + private const val TAG = "PwaActivity" + } +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/pwaplayer/util/Extensions.kt b/app/src/main/java/foundation/e/pwaplayer/util/Extensions.kt new file mode 100644 index 0000000..0c8a616 --- /dev/null +++ b/app/src/main/java/foundation/e/pwaplayer/util/Extensions.kt @@ -0,0 +1,10 @@ +package foundation.e.pwaplayer.util + +import android.graphics.Bitmap +import android.graphics.BitmapFactory + +fun ByteArray.toBitmap(): Bitmap? { + return BitmapFactory.decodeByteArray( + this, 0, this.size + ) +} \ No newline at end of file -- GitLab From 2860c92e1fbdd0057d7cf3dcf48e2d47fbf2de03 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Mon, 27 Jul 2020 20:21:37 +0530 Subject: [PATCH 5/5] Following changes: Remove Launcher intent-filter Use content resolver to fetch app icon and name --- app/src/main/AndroidManifest.xml | 2 - .../foundation/e/pwaplayer/database/Pwa.kt | 1 + .../e/pwaplayer/provider/PwaProvider.kt | 6 +- .../e/pwaplayer/ui/home/HomeActivity.kt | 1 - .../pwaplayer/ui/home/HomeRecyclerAdapter.kt | 3 +- .../e/pwaplayer/ui/player/PwaActivity.kt | 61 +++++++++++++------ 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 727c79a..af5e84e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,8 +28,6 @@ - - diff --git a/app/src/main/java/foundation/e/pwaplayer/database/Pwa.kt b/app/src/main/java/foundation/e/pwaplayer/database/Pwa.kt index 86418e2..2c313be 100644 --- a/app/src/main/java/foundation/e/pwaplayer/database/Pwa.kt +++ b/app/src/main/java/foundation/e/pwaplayer/database/Pwa.kt @@ -26,6 +26,7 @@ data class Pwa( @ColumnInfo(name = PwaConstants.TITLE) val title: String, + @ColumnInfo(name = PwaConstants.ICON, typeAffinity = ColumnInfo.BLOB) val iconBlob: ByteArray ) { diff --git a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt index 7bcd98a..54dc564 100644 --- a/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt +++ b/app/src/main/java/foundation/e/pwaplayer/provider/PwaProvider.kt @@ -1,10 +1,12 @@ package foundation.e.pwaplayer.provider -import android.content.* +import android.content.ContentProvider +import android.content.ContentUris +import android.content.ContentValues +import android.content.UriMatcher import android.database.Cursor import android.net.Uri import android.util.Log -import androidx.core.content.contentValuesOf import foundation.e.pwaplayer.database.PwaDatabase import foundation.e.pwaplayer.database.mapToPwa import foundation.e.pwaplayer.provider.PwaConstants.Companion.TABLE_NAME diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeActivity.kt b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeActivity.kt index fb3757c..e0351e3 100644 --- a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeActivity.kt +++ b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeActivity.kt @@ -75,7 +75,6 @@ class HomeActivity : AppCompatActivity() { val cursor = contentResolver.query(CONTENT_URI, null, null, null, null) val data = ArrayList() if (cursor != null) { - Log.d(TAG, "loadData: ${cursor.count} ${cursor.columnCount}") if (cursor.moveToFirst()) { do { val pwa = cursor.mapToPwa() diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt index a581661..a0ef37e 100644 --- a/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt +++ b/app/src/main/java/foundation/e/pwaplayer/ui/home/HomeRecyclerAdapter.kt @@ -33,8 +33,7 @@ class HomeRecyclerAdapter( intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS) intent.action = "foundation.e.blisslauncher.VIEW_PWA" intent.data = Uri.parse(items[adapterPosition].url) - intent.putExtra(PwaActivity.KEY_PWA_NAME, items[adapterPosition].title) - intent.putExtra(PwaActivity.KEY_PWA_ICON, items[adapterPosition].iconBlob) + intent.putExtra(PwaActivity.KEY_PWA_ID, items[adapterPosition].id) context.startActivity(intent) } } diff --git a/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt b/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt index 3f3e290..00264da 100644 --- a/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt +++ b/app/src/main/java/foundation/e/pwaplayer/ui/player/PwaActivity.kt @@ -3,9 +3,14 @@ package foundation.e.pwaplayer.ui.player import android.annotation.SuppressLint import android.app.Activity import android.app.ActivityManager.TaskDescription +import android.content.ContentUris import android.content.Intent import android.content.pm.PackageManager +import android.graphics.Bitmap import android.os.Bundle +import android.os.Handler +import android.os.HandlerThread +import android.os.Looper import android.view.KeyEvent import android.view.View import android.webkit.WebView @@ -13,11 +18,19 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import foundation.e.apps.pwa.PwaWebChromeClient import foundation.e.pwaplayer.R +import foundation.e.pwaplayer.database.mapToPwa +import foundation.e.pwaplayer.provider.PwaConstants import foundation.e.pwaplayer.util.toBitmap class PwaActivity : AppCompatActivity() { + private var pwaWebChromeClient: PwaWebChromeClient? = null private var webView: WebView? = null + + private val workerThread: HandlerThread = HandlerThread("WORKER-THREAD") + private lateinit var workerHandler: Handler + private val uiHandler = Handler(Looper.getMainLooper()) + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val intent = intent @@ -25,28 +38,35 @@ class PwaActivity : AppCompatActivity() { Toast.makeText(this, "URL can't be empty", Toast.LENGTH_SHORT).show() finish() } - val name = getIntent().getStringExtra(KEY_PWA_NAME) - setPwaTaskInfo( - this, - name, - getIntent().getByteArrayExtra(KEY_PWA_ICON) - ) + + val id = getIntent().getLongExtra(KEY_PWA_ID, -1) + + workerThread.start() + workerHandler = Handler(workerThread.looper) + workerHandler.post { + setPwaTaskInfo( id) + } setContentView(R.layout.activity_pwa) - pwaWebChromeClient = PwaWebChromeClient(this, name) - webView = findViewById(R.id.webView) as WebView - setWebView(webView, pwaWebChromeClient!!) } - private fun setPwaTaskInfo( - activity: Activity, - name: String?, - iconBytes: ByteArray? - ) { - if (name.isNullOrEmpty()) { - return + private fun setPwaTaskInfo(id: Long) { + val cursor = contentResolver.query( + ContentUris.withAppendedId(PwaConstants.CONTENT_URI, id), + null, null, null, null + ) + if (cursor != null) { + if (cursor.moveToFirst()) { + val pwa = cursor.mapToPwa() + val icon = pwa.iconBlob?.toBitmap() + val name = pwa.title + uiHandler.post { updateTaskInfo(name, icon) } + } + cursor.close() } - activity.title = name - val icon = iconBytes?.let { iconBytes.toBitmap() } + } + + private fun updateTaskInfo(name: String, icon: Bitmap?) { + this.title = name val taskDescription: TaskDescription if (icon != null) { taskDescription = TaskDescription(name, icon) @@ -55,6 +75,10 @@ class PwaActivity : AppCompatActivity() { taskDescription = TaskDescription(name) } setTaskDescription(taskDescription) + + pwaWebChromeClient = PwaWebChromeClient(this, name) + webView = findViewById(R.id.webView) as WebView + setWebView(webView, pwaWebChromeClient!!) } @SuppressLint("SetJavaScriptEnabled") @@ -114,6 +138,7 @@ class PwaActivity : AppCompatActivity() { companion object { const val KEY_PWA_NAME = "PWA_NAME" const val KEY_PWA_ICON = "PWA_ICON" + const val KEY_PWA_ID = "PWA_ID" const val KEY_SCOPE = "pwa_scope" private const val TAG = "PwaActivity" } -- GitLab