mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Moved screen capture into its own util class
This commit is contained in:
parent
1fdc70cd9f
commit
181bd3dfa4
3 changed files with 27 additions and 22 deletions
|
|
@ -11,7 +11,6 @@ import android.widget.TextView
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import fr.free.nrw.commons.R
|
import fr.free.nrw.commons.R
|
||||||
import fr.free.nrw.commons.utils.Utils
|
|
||||||
import fr.free.nrw.commons.ViewPagerAdapter
|
import fr.free.nrw.commons.ViewPagerAdapter
|
||||||
import fr.free.nrw.commons.auth.SessionManager
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
import fr.free.nrw.commons.contributions.ContributionsFragment
|
import fr.free.nrw.commons.contributions.ContributionsFragment
|
||||||
|
|
@ -20,6 +19,7 @@ import fr.free.nrw.commons.profile.achievements.AchievementsFragment
|
||||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment
|
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment
|
||||||
import fr.free.nrw.commons.theme.BaseActivity
|
import fr.free.nrw.commons.theme.BaseActivity
|
||||||
import fr.free.nrw.commons.utils.DialogUtil
|
import fr.free.nrw.commons.utils.DialogUtil
|
||||||
|
import fr.free.nrw.commons.utils.ScreenCaptureUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
@ -132,7 +132,7 @@ class ProfileActivity : BaseActivity() {
|
||||||
return when (item.itemId) {
|
return when (item.itemId) {
|
||||||
R.id.share_app_icon -> {
|
R.id.share_app_icon -> {
|
||||||
val rootView = window.decorView.findViewById<View>(android.R.id.content)
|
val rootView = window.decorView.findViewById<View>(android.R.id.content)
|
||||||
val screenShot = Utils.getScreenShot(rootView)
|
val screenShot = ScreenCaptureUtils.getScreenShot(rootView)
|
||||||
if (screenShot == null) {
|
if (screenShot == null) {
|
||||||
Log.e("ERROR", "ScreenShot is null")
|
Log.e("ERROR", "ScreenShot is null")
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package fr.free.nrw.commons.utils;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public final class ScreenCaptureUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To take screenshot of the screen and return it in Bitmap format
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Bitmap getScreenShot(View view) {
|
||||||
|
View screenView = view.getRootView();
|
||||||
|
screenView.setDrawingCacheEnabled(true);
|
||||||
|
Bitmap drawingCache = screenView.getDrawingCache();
|
||||||
|
if (drawingCache != null) {
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(drawingCache);
|
||||||
|
screenView.setDrawingCacheEnabled(false);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,11 +4,9 @@ import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
import android.text.style.UnderlineSpan;
|
import android.text.style.UnderlineSpan;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||||
|
|
@ -76,24 +74,6 @@ public class Utils {
|
||||||
customTabsIntent.launchUrl(context, url);
|
customTabsIntent.launchUrl(context, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* To take screenshot of the screen and return it in Bitmap format
|
|
||||||
*
|
|
||||||
* @param view
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Bitmap getScreenShot(View view) {
|
|
||||||
View screenView = view.getRootView();
|
|
||||||
screenView.setDrawingCacheEnabled(true);
|
|
||||||
Bitmap drawingCache = screenView.getDrawingCache();
|
|
||||||
if (drawingCache != null) {
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(drawingCache);
|
|
||||||
screenView.setDrawingCacheEnabled(false);
|
|
||||||
return bitmap;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*Copies the content to the clipboard
|
*Copies the content to the clipboard
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue