diff options
Diffstat (limited to 'org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java')
-rwxr-xr-x | org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java index 9461e6a5..3a177813 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java @@ -17,6 +17,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.database.sqlite.SQLiteDatabase; +import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -32,7 +33,20 @@ import android.view.Display; import android.view.View; import android.widget.CheckBox; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.browser.customtabs.CustomTabsCallback; +import androidx.browser.customtabs.CustomTabsClient; +import androidx.browser.customtabs.CustomTabsIntent; +import androidx.browser.customtabs.CustomTabsServiceConnection; +import androidx.browser.customtabs.CustomTabsSession; +import androidx.core.app.JobIntentService; +import androidx.core.content.FileProvider; + import com.bumptech.glide.Glide; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.SimpleTarget; import com.google.android.material.snackbar.Snackbar; import com.livefront.bridge.Bridge; @@ -43,18 +57,12 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; +import java.io.File; +import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.app.AppCompatDelegate; -import androidx.browser.customtabs.CustomTabsCallback; -import androidx.browser.customtabs.CustomTabsClient; -import androidx.browser.customtabs.CustomTabsIntent; -import androidx.browser.customtabs.CustomTabsServiceConnection; -import androidx.browser.customtabs.CustomTabsSession; -import androidx.core.app.JobIntentService; import icepick.State; public class CommonActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -396,6 +404,52 @@ public class CommonActivity extends AppCompatActivity implements SharedPreferenc startActivity(Intent.createChooser(getShareIntent(text, subject), text)); } + protected void shareImageFromUri(String url) { + Glide.with(this) + .load(url) + .asBitmap() + .skipMemoryCache(false) + .diskCacheStrategy(DiskCacheStrategy.ALL) + .into(new SimpleTarget<Bitmap>() { + @Override + public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { + Log.d(TAG, "image resource ready: " + resource); + + if (resource != null) { + File shareFolder = new File(getCacheDir(), "shared"); + + try { + shareFolder.mkdirs(); + + File file = new File(shareFolder, "shared.png"); + + FileOutputStream stream = new FileOutputStream(file); + resource.compress(Bitmap.CompressFormat.PNG, 90, stream); + stream.flush(); + stream.close(); + + Uri shareUri = FileProvider.getUriForFile(CommonActivity.this, + "org.fox.ttrss.SharedFileProvider", file); + + Intent intent = new Intent(android.content.Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_STREAM, shareUri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setType("image/png"); + + startActivity(intent); + + } catch (Exception e) { + e.printStackTrace(); + toast(e.getMessage()); + } + + } else { + toast("Failed to load image for sharing"); + } + } + }); + } + private void openUriWithCustomTab(Uri uri) { if (m_customTabClient != null) { TypedValue tvBackground = new TypedValue(); |