diff --git a/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.kt b/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.kt index c9503e892..105cf1860 100644 --- a/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.kt +++ b/app/src/main/java/fr/free/nrw/commons/profile/ProfileActivity.kt @@ -5,7 +5,9 @@ import android.content.Intent import android.graphics.Bitmap import android.os.Bundle import android.util.Log -import android.view.* +import android.view.Menu +import android.view.MenuItem +import android.view.View import android.widget.ImageView import android.widget.TextView import androidx.core.content.FileProvider @@ -19,10 +21,9 @@ import fr.free.nrw.commons.profile.achievements.AchievementsFragment import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment import fr.free.nrw.commons.theme.BaseActivity import fr.free.nrw.commons.utils.DialogUtil -import fr.free.nrw.commons.utils.ScreenCaptureUtils import java.io.File import java.io.FileOutputStream -import java.util.* +import java.util.Locale import javax.inject.Inject /** @@ -132,7 +133,7 @@ class ProfileActivity : BaseActivity() { return when (item.itemId) { R.id.share_app_icon -> { val rootView = window.decorView.findViewById(android.R.id.content) - val screenShot = ScreenCaptureUtils.getScreenShot(rootView) + val screenShot = getScreenShot(rootView) if (screenShot == null) { Log.e("ERROR", "ScreenShot is null") return false @@ -211,6 +212,24 @@ class ProfileActivity : BaseActivity() { binding.tabLayout.visibility = if (isVisible) View.VISIBLE else View.GONE } + /** + * To take screenshot of the screen and return it in Bitmap format + * + * @param view + * @return + */ + fun getScreenShot(view: View): Bitmap? { + val screenView = view.rootView + screenView.isDrawingCacheEnabled = true + val drawingCache = screenView.drawingCache + if (drawingCache != null) { + val bitmap = Bitmap.createBitmap(drawingCache) + screenView.isDrawingCacheEnabled = false + return bitmap + } + return null + } + companion object { const val KEY_USERNAME = "username" const val KEY_SHOULD_SHOW_CONTRIBUTIONS = "shouldShowContributions" diff --git a/app/src/main/java/fr/free/nrw/commons/utils/ScreenCaptureUtils.java b/app/src/main/java/fr/free/nrw/commons/utils/ScreenCaptureUtils.java deleted file mode 100644 index 7f6aa8104..000000000 --- a/app/src/main/java/fr/free/nrw/commons/utils/ScreenCaptureUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -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; - } -}