mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Convert then inline screeen capture in kotlin
This commit is contained in:
parent
eca14b8ffe
commit
7c06871649
2 changed files with 23 additions and 29 deletions
|
|
@ -5,7 +5,9 @@ import android.content.Intent
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
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.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.FileProvider
|
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.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.Locale
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -132,7 +133,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 = ScreenCaptureUtils.getScreenShot(rootView)
|
val screenShot = getScreenShot(rootView)
|
||||||
if (screenShot == null) {
|
if (screenShot == null) {
|
||||||
Log.e("ERROR", "ScreenShot is null")
|
Log.e("ERROR", "ScreenShot is null")
|
||||||
return false
|
return false
|
||||||
|
|
@ -211,6 +212,24 @@ class ProfileActivity : BaseActivity() {
|
||||||
binding.tabLayout.visibility = if (isVisible) View.VISIBLE else View.GONE
|
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 {
|
companion object {
|
||||||
const val KEY_USERNAME = "username"
|
const val KEY_USERNAME = "username"
|
||||||
const val KEY_SHOULD_SHOW_CONTRIBUTIONS = "shouldShowContributions"
|
const val KEY_SHOULD_SHOW_CONTRIBUTIONS = "shouldShowContributions"
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue