Repository: Muddz/PixelShot
Branch: master
Commit: 78be91b6090a
Files: 46
Total size: 20.1 MB
Directory structure:
gitextract_gz5q28u9/
├── .gitignore
├── QuickShotDemo.apk
├── build.gradle
├── demo/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── io/
│ │ └── github/
│ │ └── muddz/
│ │ └── quickshot/
│ │ └── demo/
│ │ ├── DrawingBoardView.java
│ │ ├── MainActivity.java
│ │ ├── NonSwipeViewPager.java
│ │ ├── ViewPagerAdapter.java
│ │ └── fragments/
│ │ ├── BaseFragment.java
│ │ ├── SurfaceViewFragment.java
│ │ ├── TextureViewFragment.java
│ │ └── ViewFragment.java
│ └── res/
│ ├── drawable/
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_save_black_24dp.xml
│ │ └── ic_select.xml
│ ├── drawable-v24/
│ │ └── ic_launcher_foreground.xml
│ ├── layout/
│ │ ├── activity_main.xml
│ │ ├── surface_fragment.xml
│ │ ├── texture_fragment.xml
│ │ └── view_fragment.xml
│ ├── menu/
│ │ └── menu_toolbar.xml
│ ├── mipmap-anydpi-v26/
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ └── values/
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── license
├── quickshot/
│ ├── .gitignore
│ ├── build.gradle
│ ├── consumer-rules.pro
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── io/
│ │ └── github/
│ │ └── muddz/
│ │ └── quickshot/
│ │ └── QuickShotTest.java
│ └── main/
│ ├── AndroidManifest.xml
│ └── java/
│ └── io/
│ └── github/
│ └── muddz/
│ └── quickshot/
│ ├── PixelCopyHelper.java
│ ├── QuickShot.java
│ └── QuickShotUtils.java
├── readme.md
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
================================================
FILE: QuickShotDemo.apk
================================================
[File too large to display: 20.0 MB]
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.5.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.17.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
plugins.withId("com.vanniktech.maven.publish") {
mavenPublish {
sonatypeHost = "S01"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: demo/.gitignore
================================================
/build
================================================
FILE: demo/build.gradle
================================================
plugins {
id 'com.android.application'
}
android {
compileSdk 30
defaultConfig {
applicationId "io.github.muddz.quickshot.demo"
minSdk 19
targetSdk 30
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
// implementation 'io.github.muddz:quickshot:1.4.0'
implementation project(':quickshot')
}
================================================
FILE: demo/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: demo/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="io.github.muddz.quickshot.demo">
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning,MissingApplicationIcon">
<activity
android:name="io.github.muddz.quickshot.demo.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/DrawingBoardView.java
================================================
package io.github.muddz.quickshot.demo;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import androidx.annotation.Nullable;
public class DrawingBoardView extends View {
private OnDrawingListener listener;
private Paint drawingPaint;
private Path path = new Path();
public DrawingBoardView(Context context) {
super(context);
setup();
}
public DrawingBoardView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setup();
}
private void setup() {
setFocusableInTouchMode(true);
setFocusable(true);
drawingPaint = new Paint();
drawingPaint.setColor(Color.BLACK);
drawingPaint.setAntiAlias(true);
drawingPaint.setStrokeWidth(convertToDP(5));
drawingPaint.setStyle(Paint.Style.STROKE);
drawingPaint.setStrokeJoin(Paint.Join.ROUND);
drawingPaint.setStrokeCap(Paint.Cap.ROUND);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, drawingPaint);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
float xTouchPos = event.getX();
float yTouchPos = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(xTouchPos, yTouchPos);
path.lineTo(xTouchPos, yTouchPos);
if (listener != null) {
listener.onDrawingStarted();
}
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(xTouchPos, yTouchPos);
break;
default:
return false;
}
postInvalidate();
return true;
}
public void setOnDrawingListener(OnDrawingListener listener) {
this.listener = listener;
}
private float convertToDP(int value) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
}
public interface OnDrawingListener {
void onDrawingStarted();
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/MainActivity.java
================================================
package io.github.muddz.quickshot.demo;
import android.Manifest;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.PermissionChecker;
import com.google.android.material.tabs.TabLayout;
import io.github.muddz.quickshot.QuickShot;
import io.github.muddz.quickshot.demo.fragments.BaseFragment;
public class MainActivity extends AppCompatActivity implements QuickShot.QuickShotListener {
private NonSwipeViewPager viewPager;
private ViewPagerAdapter viewPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
askPermissions();
setupToolbar();
setupViewPager();
}
private void setupToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_save_black_24dp));
setSupportActionBar(toolbar);
}
private void setupViewPager() {
viewPager = findViewById(R.id.viewpager);
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(viewPagerAdapter);
viewPager.setOffscreenPageLimit(0);
TabLayout tabLayout = findViewById(R.id.tablayout);
tabLayout.setupWithViewPager(viewPager);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_toolbar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_jpg:
QuickShot.of(getTargetView()).setFilename("QuickShotJPG").setResultListener(this).toJPG().save();
break;
case R.id.menu_pgn:
QuickShot.of(getTargetView()).setResultListener(this).toPNG().enableLogging().save();
break;
case R.id.menu_nomedia:
QuickShot.of(getTargetView()).setResultListener(this).toNomedia().save();
break;
}
return true;
}
private View getTargetView() {
int currentItem = viewPager.getCurrentItem();
BaseFragment fragment = (BaseFragment) viewPagerAdapter.getItem(currentItem);
return fragment.getTargetView();
}
@Override
public void onQuickShotSuccess(String path) {
Toast.makeText(this, "Image saved at: " + path, Toast.LENGTH_LONG).show();
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
Toast.makeText(this, errorMsg, Toast.LENGTH_LONG).show();
}
private void askPermissions() {
int requestCode = 232;
String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(this, permission) != PermissionChecker.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, permissions, requestCode);
}
}
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/NonSwipeViewPager.java
================================================
package io.github.muddz.quickshot.demo;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
public class NonSwipeViewPager extends ViewPager {
public NonSwipeViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/ViewPagerAdapter.java
================================================
package io.github.muddz.quickshot.demo;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import io.github.muddz.quickshot.demo.fragments.SurfaceViewFragment;
import io.github.muddz.quickshot.demo.fragments.TextureViewFragment;
import io.github.muddz.quickshot.demo.fragments.ViewFragment;
public class ViewPagerAdapter extends FragmentPagerAdapter {
private String[] titles = {"View", "SurfaceView", "TextureView"};
private Fragment[] fragments = {new ViewFragment(), new SurfaceViewFragment(), new TextureViewFragment()};
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
@NonNull
@Override
public Fragment getItem(int position) {
return fragments[position];
}
@Override
public int getCount() {
return fragments.length;
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/BaseFragment.java
================================================
package io.github.muddz.quickshot.demo.fragments;
import android.view.View;
import androidx.fragment.app.Fragment;
public abstract class BaseFragment extends Fragment {
/**
* @return The View we want to save as an image.
*/
public abstract View getTargetView();
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/SurfaceViewFragment.java
================================================
package io.github.muddz.quickshot.demo.fragments;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.github.muddz.quickshot.demo.R;
/**
* Created by Muddz on 23-08-2017.
*/
public class SurfaceViewFragment extends BaseFragment implements SurfaceHolder.Callback {
private SurfaceView surfaceView;
private MediaPlayer mediaPlayer;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.surface_fragment, container, false);
surfaceView = v.findViewById(R.id.surfaceview);
surfaceView.getHolder().addCallback(this);
Uri uri = Uri.parse("android.resource://" + getActivity().getApplicationContext().getPackageName() + "/raw/" + "numbers");
mediaPlayer = MediaPlayer.create(getContext(), uri);
return v;
}
@Override
public View getTargetView() {
return surfaceView;
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
mediaPlayer.setSurface(holder.getSurface());
mediaPlayer.setLooping(true);
mediaPlayer.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/TextureViewFragment.java
================================================
package io.github.muddz.quickshot.demo.fragments;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.IOException;
import java.util.List;
import io.github.muddz.quickshot.demo.R;
/**
* Created by Muddz on 23-08-2017.
*/
public class TextureViewFragment extends BaseFragment implements TextureView.SurfaceTextureListener {
private Camera camera;
private TextureView textureView;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.texture_fragment, container, false);
textureView = v.findViewById(R.id.textureview);
textureView.setSurfaceTextureListener(this);
return v;
}
@Override
public View getTargetView() {
return textureView;
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
camera = Camera.open();
camera.setDisplayOrientation(90);
Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
Camera.Size cameraSize = getOptimalPreviewSize(previewSizes, width, height);
if (isAutoFocusSupported(camera)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
parameters.setPreviewSize(cameraSize.width, cameraSize.height);
camera.setParameters(parameters);
try {
camera.setPreviewTexture(surface);
camera.startPreview();
} catch (IOException e) {
e.printStackTrace();
}
}
/*
Solution credit: https://stackoverflow.com/a/19592492/9591909
*/
private boolean isAutoFocusSupported(Camera camera) {
if (camera != null) {
for (String supportedMode : camera.getParameters().getSupportedFocusModes()) {
if (supportedMode.equals(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
return true;
}
}
}
return false;
}
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio = (double) h / w;
if (sizes == null) return null;
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - h) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - h);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - h) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - h);
}
}
}
return optimalSize;
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
camera.stopPreview();
camera.release();
return true;
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
}
================================================
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/ViewFragment.java
================================================
package io.github.muddz.quickshot.demo.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.github.muddz.quickshot.demo.DrawingBoardView;
import io.github.muddz.quickshot.demo.R;
/**
* Created by Muddz on 23-08-2017.
*/
public class ViewFragment extends BaseFragment implements DrawingBoardView.OnDrawingListener {
private DrawingBoardView drawingBoardView;
private LinearLayout drawHint;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.view_fragment, container, false);
drawingBoardView = v.findViewById(R.id.drawingview);
drawingBoardView.setOnDrawingListener(this);
drawHint = v.findViewById(R.id.drawhint);
return v;
}
@Override
public View getTargetView() {
return drawingBoardView;
}
@Override
public void onDrawingStarted() {
drawHint.setVisibility(View.GONE);
}
}
================================================
FILE: demo/src/main/res/drawable/ic_launcher_background.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
================================================
FILE: demo/src/main/res/drawable/ic_save_black_24dp.xml
================================================
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="30dp"
android:height="30dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
</vector>
================================================
FILE: demo/src/main/res/drawable/ic_select.xml
================================================
<vector android:height="24dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M416,149.333c-8.768,0 -16.939,2.667 -23.723,7.211C386.432,139.947 370.581,128 352,128c-8.768,0 -16.939,2.667 -23.723,7.211c-5.845,-16.597 -21.696,-28.544 -40.277,-28.544c-7.765,0 -15.061,2.091 -21.333,5.739V42.667C266.667,19.136 247.531,0 224,0s-42.667,19.136 -42.667,42.667v249.408l-58.645,-29.333C113.856,258.325 103.957,256 94.08,256c-22.485,0 -40.747,18.283 -40.747,40.875c0,10.901 4.245,21.12 11.947,28.821l137.941,137.941C234.389,494.827 275.883,512 320,512c76.459,0 138.667,-62.208 138.667,-138.667V192C458.667,168.469 439.531,149.333 416,149.333zM437.333,373.333c0,64.704 -52.651,117.333 -117.355,117.333c-38.421,0 -74.517,-14.955 -101.653,-42.133L80.363,310.592c-3.669,-3.648 -5.696,-8.533 -5.696,-13.845c0,-10.709 8.704,-19.413 19.413,-19.413c6.592,0 13.163,1.557 19.072,4.501l74.091,37.035c3.307,1.643 7.253,1.472 10.368,-0.469c3.136,-1.941 5.056,-5.376 5.056,-9.067V42.667c0,-11.755 9.557,-21.333 21.333,-21.333s21.333,9.579 21.333,21.333v202.667c0,5.888 4.779,10.667 10.667,10.667c5.888,0 10.667,-4.779 10.667,-10.667v-96c0,-11.755 9.557,-21.333 21.333,-21.333s21.333,9.579 21.333,21.333v96c0,5.888 4.779,10.667 10.667,10.667s10.667,-4.779 10.667,-10.667v-74.667c0,-11.755 9.557,-21.333 21.333,-21.333s21.333,9.579 21.333,21.333v74.667c0,5.888 4.779,10.667 10.667,10.667c5.888,0 10.667,-4.779 10.667,-10.667V192c0,-11.755 9.557,-21.333 21.333,-21.333s21.333,9.579 21.333,21.333V373.333z"/>
</vector>
================================================
FILE: demo/src/main/res/drawable-v24/ic_launcher_foreground.xml
================================================
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
================================================
FILE: demo/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
app:title="@string/app_name" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f4f3f3"
app:tabMode="fixed" />
<com.muddzdev.quickshot.demo.NonSwipeViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/tablayout"
android:layout_below="@id/toolbar" />
</RelativeLayout>
================================================
FILE: demo/src/main/res/layout/surface_fragment.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
================================================
FILE: demo/src/main/res/layout/texture_fragment.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextureView
android:id="@+id/textureview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
================================================
FILE: demo/src/main/res/layout/view_fragment.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.muddzdev.quickshot.demo.DrawingBoardView
android:id="@+id/drawingview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe522" />
<LinearLayout
android:id="@+id/drawhint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="30dp"
android:minWidth="30dp"
android:src="@drawable/ic_select" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Draw on the screen"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout>
</FrameLayout>
================================================
FILE: demo/src/main/res/menu/menu_toolbar.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_jpg"
android:title="JPG"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/menu_pgn"
android:title="PNG"
app:showAsAction="collapseActionView" />
<item
android:id="@+id/menu_nomedia"
android:title="NOMEDIA"
app:showAsAction="collapseActionView" />
</menu>
================================================
FILE: demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
================================================
FILE: demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
================================================
FILE: demo/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#8f8f8f</color>
</resources>
================================================
FILE: demo/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">QuickShot demo</string>
</resources>
================================================
FILE: demo/src/main/res/values/styles.xml
================================================
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Sun Aug 01 22:32:07 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
================================================
FILE: gradle.properties
================================================
android.enableJetifier=true
android.useAndroidX=true
#MavenCentral publish informations
#Publish plugin: https://github.com/vanniktech/gradle-maven-publish-plugin
GROUP=io.github.muddz
POM_ARTIFACT_ID=quickshot
VERSION_NAME=1.4.0
POM_NAME=quickshot
POM_DESCRIPTION=Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.
POM_INCEPTION_YEAR=2021
POM_URL=https://github.com/Muddz/QuickShot
POM_LICENSE_NAME=The Apache Software License, Version 2.0
POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENSE_DIST=repo
POM_SCM_URL=https://github.com/Muddz/Quickshot
POM_SCM_CONNECTION=scm:git:git://github.com/Muddz/Quickshot.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/Muddz/Quickshot.git
POM_DEVELOPER_ID=Muddz
POM_DEVELOPER_NAME=Muddi Walid
================================================
FILE: gradlew
================================================
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"
================================================
FILE: gradlew.bat
================================================
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: license
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2018 Muddi Walid.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: quickshot/.gitignore
================================================
/build
================================================
FILE: quickshot/build.gradle
================================================
plugins {
id 'com.android.library'
id 'com.vanniktech.maven.publish'
}
android {
compileSdk 30
defaultConfig {
minSdk 19
targetSdk 30
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:rules:1.4.0'
}
================================================
FILE: quickshot/consumer-rules.pro
================================================
================================================
FILE: quickshot/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: quickshot/src/androidTest/java/io/github/muddz/quickshot/QuickShotTest.java
================================================
package io.github.muddz.quickshot;
import static android.view.View.MeasureSpec.EXACTLY;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.io.File;
@RunWith(AndroidJUnit4.class)
public class QuickShotTest {
private Context context;
private View testView;
@Before
public void setup() {
testView = generateTestView();
context = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getContext();
}
@Test
public void testCallbackPathNotNull() {
QuickShot.of(testView).setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
Assert.assertNotNull(path);
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
@Test
public void testIfSavedInJPG() {
QuickShot.of(testView).setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
Assert.assertTrue(path.contains(".jpg"));
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
@Test
public void testIfSavedInPNG() {
QuickShot.of(testView).toPNG().setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
Assert.assertTrue(path.contains(".png"));
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
@Test
public void testIfSavedInNomedia() {
QuickShot.of(testView).toNomedia().setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
Assert.assertTrue(path.contains(".nomedia"));
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
@Test
public void testIfDirectoryWasCreated() {
QuickShot.of(testView).setPath("QuickShotTestDirectory").setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
if (QuickShotUtils.isAboveAPI29()) {
Assert.assertTrue(path.contains("QuickShotTestDirectory"));
} else {
File file = new File(path);
File directory = new File(file.getParent());
boolean isDirectory = directory.exists() && directory.isDirectory();
Assert.assertTrue(isDirectory);
}
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
@Test
public void testIfFileExist() {
QuickShot.of(testView).setPath("QuickShotTestDirectory").setResultListener(new QuickShot.QuickShotListener() {
@Override
public void onQuickShotSuccess(String path) {
if (QuickShotUtils.isAboveAPI29()) {
Assert.assertTrue(path != null && path.length() > 0);
} else {
File file = new File(path);
Assert.assertTrue(file.exists());
}
}
@Override
public void onQuickShotFailed(String path, String errorMsg) {
}
}).save();
sleepThread();
}
private View generateTestView() {
int width = 950;
int height = 950;
int widthMS = View.MeasureSpec.makeMeasureSpec(width, EXACTLY);
int heightMS = View.MeasureSpec.makeMeasureSpec(height, EXACTLY);
View view = new View(InstrumentationRegistry.getTargetContext());
view.measure(widthMS, heightMS);
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.setBackgroundColor(Color.GRAY);
return view;
}
private void sleepThread() {
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
================================================
FILE: quickshot/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.github.muddz.quickshot">
<!--The permission must be added here for Instrumental tests purposes-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
================================================
FILE: quickshot/src/main/java/io/github/muddz/quickshot/PixelCopyHelper.java
================================================
package io.github.muddz.quickshot;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.view.PixelCopy;
import android.view.SurfaceView;
import androidx.annotation.NonNull;
class PixelCopyHelper {
static void getSurfaceBitmap(@NonNull SurfaceView surfaceView, @NonNull final PixelCopyListener listener) {
final Bitmap bitmap = Bitmap.createBitmap(surfaceView.getWidth(), surfaceView.getHeight(), Bitmap.Config.ARGB_8888);
final HandlerThread handlerThread = new HandlerThread(PixelCopyHelper.class.getSimpleName());
handlerThread.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PixelCopy.request(surfaceView, bitmap, new PixelCopy.OnPixelCopyFinishedListener() {
@Override
public void onPixelCopyFinished(int copyResult) {
if (copyResult == PixelCopy.SUCCESS) {
listener.onSurfaceBitmapReady(bitmap);
} else {
listener.onSurfaceBitmapError("Couldn't create bitmap of the SurfaceView");
}
handlerThread.quitSafely();
}
}, new Handler(handlerThread.getLooper()));
} else {
listener.onSurfaceBitmapError("Saving an image of a SurfaceView is only supported for API 24 and above");
}
}
interface PixelCopyListener {
void onSurfaceBitmapReady(Bitmap bitmap);
void onSurfaceBitmapError(String errorMsg);
}
}
================================================
FILE: quickshot/src/main/java/io/github/muddz/quickshot/QuickShot.java
================================================
package io.github.muddz.quickshot;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.provider.MediaStore;
import android.util.Log;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import static android.os.Environment.DIRECTORY_PICTURES;
public class QuickShot {
private static final String EXTENSION_JPG = ".jpg";
private static final String EXTENSION_PNG = ".png";
private static final String EXTENSION_NOMEDIA = ".nomedia";
private static final int JPG_MAX_QUALITY = 100;
private boolean printStackTrace;
private int jpgQuality = JPG_MAX_QUALITY;
private String fileExtension = EXTENSION_JPG;
private String filename = String.valueOf(System.currentTimeMillis());
private String path;
private Bitmap bitmap;
private View view;
private Context context;
private QuickShotListener listener;
private QuickShot(@NonNull View view) {
this.view = view;
this.context = view.getContext();
}
private QuickShot(@NonNull Bitmap bitmap, @NonNull Context context) {
this.bitmap = bitmap;
this.context = context;
}
public static QuickShot of(@NonNull View view) {
return new QuickShot(view);
}
public static QuickShot of(@NonNull Bitmap bitmap, @NonNull Context context) {
return new QuickShot(bitmap, context);
}
/**
* @param filename if not set, filename defaults to a timestamp from {@link System#currentTimeMillis}
*/
public QuickShot setFilename(String filename) {
this.filename = filename;
return this;
}
/**
* <i>NOTE: For devices running Android 10 (+API 29) and above image files will now be saved relative to /Internal storage/Pictures/ due to 'Scoped storage'</i><br><br>
* <p>Directories which don't already exist will be automatically created.</p>
*
* @param path if not set, path defaults to /Pictures/ regardless of any API level
*/
public QuickShot setPath(String path) {
this.path = path;
return this;
}
private void setFileExtension(String fileExtension) {
this.fileExtension = fileExtension;
}
/**
* Save as .jpg format in highest quality
* default is .jpg
*/
public QuickShot toJPG() {
jpgQuality = JPG_MAX_QUALITY;
setFileExtension(EXTENSION_JPG);
return this;
}
/**
* Save as .jpg format in a custom quality between 0-100
* default is 100
*/
public QuickShot toJPG(int jpgQuality) {
this.jpgQuality = jpgQuality;
setFileExtension(EXTENSION_JPG);
return this;
}
/**
* Save as .png format for lossless compression
* default is .jpg
*/
public QuickShot toPNG() {
setFileExtension(EXTENSION_PNG);
return this;
}
/**
* Save as .nomedia for making the picture invisible for photo viewer apps and galleries.
*/
public QuickShot toNomedia() {
setFileExtension(EXTENSION_NOMEDIA);
return this;
}
/**
* Enable QuickShot to log and print exception stacks
*/
public QuickShot enableLogging() {
printStackTrace = true;
return this;
}
/**
* Listen for successive or failure results when calling save()
*/
public QuickShot setResultListener(@NonNull QuickShotListener listener) {
this.listener = listener;
if (listener == null) {
throw new NullPointerException("QuickShot.setResultListener() was provided with a null object reference");
}
return this;
}
private Context getContext() {
if (context == null) {
throw new NullPointerException("Attempt to save the picture failed: View or Context was null");
}
return context;
}
private Bitmap getBitmap() {
if (bitmap != null) {
return bitmap;
} else if (view instanceof TextureView) {
bitmap = ((TextureView) view).getBitmap();
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
canvas.setBitmap(null);
return bitmap;
} else {
bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
canvas.setBitmap(null);
return bitmap;
}
}
/**
* save() runs in a asynchronous thread
*
* @throws NullPointerException if View is null.
*/
public void save() throws NullPointerException {
if (view instanceof SurfaceView) {
PixelCopyHelper.getSurfaceBitmap((SurfaceView) view, new PixelCopyHelper.PixelCopyListener() {
@Override
public void onSurfaceBitmapReady(Bitmap surfaceBitmap) {
new BitmapSaver(getContext(), surfaceBitmap, printStackTrace, path, filename, fileExtension, jpgQuality, listener).execute();
}
@Override
public void onSurfaceBitmapError(String errorMsg) {
listener.onQuickShotFailed(path, errorMsg);
}
});
} else {
new BitmapSaver(getContext(), getBitmap(), printStackTrace, path, filename, fileExtension, jpgQuality, listener).execute();
}
}
public interface QuickShotListener {
void onQuickShotSuccess(String path);
void onQuickShotFailed(String path, String errorMsg);
}
static class BitmapSaver extends AsyncTask<Void, Void, Void> {
private final WeakReference<Context> weakContext;
private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
private boolean printStacktrace;
private int jpgQuality;
private String errorMsg;
private String path;
private String filename;
private String fileExtension;
private Bitmap bitmap;
private File file;
private QuickShotListener listener;
BitmapSaver(Context context, Bitmap bitmap, boolean printStacktrace, String path, String filename, String fileExtension, int jpgQuality, QuickShotListener listener) {
this.weakContext = new WeakReference<>(context);
this.bitmap = bitmap;
this.printStacktrace = printStacktrace;
this.path = path;
this.filename = filename;
this.fileExtension = fileExtension;
this.jpgQuality = jpgQuality;
this.listener = listener;
}
/**
* @deprecated
*/
private void saveLegacy() {
if (path == null) {
path = Environment.getExternalStorageDirectory() + File.separator + DIRECTORY_PICTURES;
}
File directory = new File(path);
directory.mkdirs();
file = new File(directory, filename + fileExtension);
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
switch (fileExtension) {
case EXTENSION_JPG:
bitmap.compress(Bitmap.CompressFormat.JPEG, jpgQuality, out);
break;
case EXTENSION_PNG:
bitmap.compress(Bitmap.CompressFormat.PNG, 0, out);
break;
}
} catch (Exception e) {
if (printStacktrace) {
e.printStackTrace();
}
errorMsg = e.toString();
cancel(true);
} finally {
bitmap = null;
}
}
@RequiresApi(Build.VERSION_CODES.Q)
private void saveScopedStorage() {
path = path != null ? (DIRECTORY_PICTURES + File.separator + path) : DIRECTORY_PICTURES;
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, filename);
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, path);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, QuickShotUtils.getMimeType(fileExtension));
ContentResolver resolver = weakContext.get().getContentResolver();
Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
if (imageUri == null) {
errorMsg = String.format("Couldn't insert ContentValues with data: [%s] into the ContentResolver", contentValues.toString());
cancel(true);
return;
}
try (OutputStream out = resolver.openOutputStream(imageUri)) {
switch (fileExtension) {
case EXTENSION_JPG:
bitmap.compress(Bitmap.CompressFormat.JPEG, jpgQuality, out);
break;
case EXTENSION_PNG:
bitmap.compress(Bitmap.CompressFormat.PNG, 0, out);
break;
}
file = new File(path, filename + fileExtension);
} catch (Exception e) {
if (printStacktrace) {
e.printStackTrace();
}
errorMsg = e.toString();
resolver.delete(imageUri, null, null);
cancel(true);
} finally {
bitmap = null;
}
}
@Override
protected Void doInBackground(Void... voids) {
if (QuickShotUtils.isAboveAPI29()) {
saveScopedStorage();
} else {
saveLegacy();
}
return null;
}
@Override
protected void onPostExecute(Void v) {
listener.onQuickShotSuccess(file.getAbsolutePath());
if (!QuickShotUtils.isAboveAPI29()) {
MediaScannerConnection.scanFile(weakContext.get(), new String[]{file.getAbsolutePath()}, null, null);
}
}
@Override
protected void onCancelled() {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
listener.onQuickShotFailed(file.getAbsolutePath(), errorMsg);
}
});
}
}
}
================================================
FILE: quickshot/src/main/java/io/github/muddz/quickshot/QuickShotUtils.java
================================================
package io.github.muddz.quickshot;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import java.io.File;
class QuickShotUtils {
static String getMimeType(String src) {
src = src.substring(1);
if (src.equals("jpg")) {
src = "jpeg";
}
return "image" + File.separator + src;
}
static boolean isAboveAPI29() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
}
private Bitmap generateLongBitmap(RecyclerView recyclerView) {
int itemCount = recyclerView.getAdapter().getItemCount();
RecyclerView.ViewHolder viewHolder = recyclerView.getAdapter().createViewHolder(recyclerView, 0);
//Measure the sizes of list item views to find out how big itemView should be
viewHolder.itemView.measure(View.MeasureSpec.makeMeasureSpec(recyclerView.getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
// Define measured widths/heights
int measuredItemHeight = viewHolder.itemView.getMeasuredHeight();
int measuredItemWidth = viewHolder.itemView.getMeasuredWidth();
//Set width/height of list item views
viewHolder.itemView.layout(0, 0, measuredItemWidth, measuredItemHeight);
//Create the Bitmap and Canvas to draw on
Bitmap recyclerViewBitmap = Bitmap.createBitmap(recyclerView.getMeasuredWidth(), measuredItemHeight * itemCount, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(recyclerViewBitmap);
//Draw RecyclerView Background:
if (recyclerView.getBackground() != null) {
Drawable drawable = recyclerView.getBackground().mutate();
drawable.setBounds(measuredItemWidth, measuredItemHeight * itemCount, 0, 0);
drawable.draw(canvas);
}
//Draw all list item views
int viewHolderTopPadding = 0;
for (int i = 0; i < itemCount; i++) {
recyclerView.getAdapter().onBindViewHolder(viewHolder, i);
viewHolder.itemView.setDrawingCacheEnabled(true);
viewHolder.itemView.buildDrawingCache();
canvas.drawBitmap(viewHolder.itemView.getDrawingCache(), 0f, viewHolderTopPadding, null);
viewHolderTopPadding += measuredItemHeight;
viewHolder.itemView.setDrawingCacheEnabled(false);
viewHolder.itemView.destroyDrawingCache();
// //TODO This should work but doesn't
// recyclerView.getAdapter().onBindViewHolder(viewHolder, i);
// viewHolder.itemView.draw(canvas);
// canvas.drawBitmap(recyclerViewBitmap, 0f, viewHolderTopPadding, null);
// viewHolderTopPadding += measuredItemHeight;
}
return recyclerViewBitmap;
}
}
================================================
FILE: readme.md
================================================
# QuickShot
[](https://android-arsenal.com/api?level=19)
[](https://github.com/Muddz/QuickShot/blob/master/QuickShotDemo.apk?raw=true)
An Android library that saves any `View`, `SurfaceView` or `Bitmap` as an image in `JPG`,`PNG` or `.nomedia`.
The library works on a asynchronous thread and handles errors and memory for you.
### Features
- Support for Android API 29+ and scoped storage
- Save in `JPG`,`PNG` or `.nomedia`.
- Save `Bitmap`, `View` or `SurfaceView` objects as images
- Set a path and filename for your captures or resort to auto defaults
- Asynchronous saving
## Example of simplest usage with defaults
<i>You can use a simple one-liner and let QuickShot set default values like in the following example:</i>
Filename defaults to a timestamp.
Path defaults to `/Pictures` in internal storage.
Image format defaults to `.JPG`
```java
QuickShot.of(view).setResultListener(this).save();
```
## Example of a detailed usage
```java
QuickShot.of(view).setResultListener(this)
.enableLogging()
.setFilename("QuickShot")
.setPath("MyApp")
.toPNG()
.save();
```
## Installation
Add the dependency in your `build.gradle`
```groovy
dependencies {
implementation 'io.github.muddz:quickshot:1.4.0'
}
```
----
## License
Copyright 2018 Muddi Walid
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: settings.gradle
================================================
include ':demo', ':quickshot'
gitextract_gz5q28u9/ ├── .gitignore ├── QuickShotDemo.apk ├── build.gradle ├── demo/ │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── io/ │ │ └── github/ │ │ └── muddz/ │ │ └── quickshot/ │ │ └── demo/ │ │ ├── DrawingBoardView.java │ │ ├── MainActivity.java │ │ ├── NonSwipeViewPager.java │ │ ├── ViewPagerAdapter.java │ │ └── fragments/ │ │ ├── BaseFragment.java │ │ ├── SurfaceViewFragment.java │ │ ├── TextureViewFragment.java │ │ └── ViewFragment.java │ └── res/ │ ├── drawable/ │ │ ├── ic_launcher_background.xml │ │ ├── ic_save_black_24dp.xml │ │ └── ic_select.xml │ ├── drawable-v24/ │ │ └── ic_launcher_foreground.xml │ ├── layout/ │ │ ├── activity_main.xml │ │ ├── surface_fragment.xml │ │ ├── texture_fragment.xml │ │ └── view_fragment.xml │ ├── menu/ │ │ └── menu_toolbar.xml │ ├── mipmap-anydpi-v26/ │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ └── values/ │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── license ├── quickshot/ │ ├── .gitignore │ ├── build.gradle │ ├── consumer-rules.pro │ ├── proguard-rules.pro │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── io/ │ │ └── github/ │ │ └── muddz/ │ │ └── quickshot/ │ │ └── QuickShotTest.java │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── io/ │ └── github/ │ └── muddz/ │ └── quickshot/ │ ├── PixelCopyHelper.java │ ├── QuickShot.java │ └── QuickShotUtils.java ├── readme.md └── settings.gradle
SYMBOL INDEX (96 symbols across 12 files)
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/DrawingBoardView.java
class DrawingBoardView (line 17) | public class DrawingBoardView extends View {
method DrawingBoardView (line 23) | public DrawingBoardView(Context context) {
method DrawingBoardView (line 28) | public DrawingBoardView(Context context, @Nullable AttributeSet attrs) {
method setup (line 33) | private void setup() {
method onDraw (line 45) | @Override
method onTouchEvent (line 50) | @SuppressLint("ClickableViewAccessibility")
method setOnDrawingListener (line 75) | public void setOnDrawingListener(OnDrawingListener listener) {
method convertToDP (line 79) | private float convertToDP(int value) {
type OnDrawingListener (line 83) | public interface OnDrawingListener {
method onDrawingStarted (line 84) | void onDrawingStarted();
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/MainActivity.java
class MainActivity (line 22) | public class MainActivity extends AppCompatActivity implements QuickShot...
method onCreate (line 27) | @Override
method setupToolbar (line 36) | private void setupToolbar() {
method setupViewPager (line 42) | private void setupViewPager() {
method onCreateOptionsMenu (line 51) | @Override
method onOptionsItemSelected (line 57) | @Override
method getTargetView (line 73) | private View getTargetView() {
method onQuickShotSuccess (line 79) | @Override
method onQuickShotFailed (line 84) | @Override
method askPermissions (line 89) | private void askPermissions() {
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/NonSwipeViewPager.java
class NonSwipeViewPager (line 11) | public class NonSwipeViewPager extends ViewPager {
method NonSwipeViewPager (line 13) | public NonSwipeViewPager(@NonNull Context context, @Nullable Attribute...
method onTouchEvent (line 17) | @Override
method onInterceptTouchEvent (line 22) | @Override
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/ViewPagerAdapter.java
class ViewPagerAdapter (line 12) | public class ViewPagerAdapter extends FragmentPagerAdapter {
method ViewPagerAdapter (line 17) | public ViewPagerAdapter(FragmentManager fm) {
method getPageTitle (line 21) | @Override
method getItem (line 26) | @NonNull
method getCount (line 32) | @Override
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/BaseFragment.java
class BaseFragment (line 7) | public abstract class BaseFragment extends Fragment {
method getTargetView (line 12) | public abstract View getTargetView();
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/SurfaceViewFragment.java
class SurfaceViewFragment (line 22) | public class SurfaceViewFragment extends BaseFragment implements Surface...
method onCreateView (line 27) | @Nullable
method getTargetView (line 38) | @Override
method surfaceCreated (line 43) | @Override
method surfaceChanged (line 50) | @Override
method surfaceDestroyed (line 54) | @Override
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/TextureViewFragment.java
class TextureViewFragment (line 23) | public class TextureViewFragment extends BaseFragment implements Texture...
method onCreateView (line 29) | @Nullable
method getTargetView (line 38) | @Override
method onSurfaceTextureAvailable (line 44) | @Override
method isAutoFocusSupported (line 73) | private boolean isAutoFocusSupported(Camera camera) {
method getOptimalPreviewSize (line 84) | private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int...
method onSurfaceTextureDestroyed (line 114) | @Override
method onSurfaceTextureSizeChanged (line 121) | @Override
method onSurfaceTextureUpdated (line 126) | @Override
FILE: demo/src/main/java/io/github/muddz/quickshot/demo/fragments/ViewFragment.java
class ViewFragment (line 20) | public class ViewFragment extends BaseFragment implements DrawingBoardVi...
method onCreateView (line 25) | @Nullable
method getTargetView (line 36) | @Override
method onDrawingStarted (line 41) | @Override
FILE: quickshot/src/androidTest/java/io/github/muddz/quickshot/QuickShotTest.java
class QuickShotTest (line 20) | @RunWith(AndroidJUnit4.class)
method setup (line 26) | @Before
method testCallbackPathNotNull (line 33) | @Test
method testIfSavedInJPG (line 50) | @Test
method testIfSavedInPNG (line 67) | @Test
method testIfSavedInNomedia (line 83) | @Test
method testIfDirectoryWasCreated (line 100) | @Test
method testIfFileExist (line 124) | @Test
method generateTestView (line 145) | private View generateTestView() {
method sleepThread (line 160) | private void sleepThread() {
FILE: quickshot/src/main/java/io/github/muddz/quickshot/PixelCopyHelper.java
class PixelCopyHelper (line 12) | class PixelCopyHelper {
method getSurfaceBitmap (line 14) | static void getSurfaceBitmap(@NonNull SurfaceView surfaceView, @NonNul...
type PixelCopyListener (line 36) | interface PixelCopyListener {
method onSurfaceBitmapReady (line 37) | void onSurfaceBitmapReady(Bitmap bitmap);
method onSurfaceBitmapError (line 39) | void onSurfaceBitmapError(String errorMsg);
FILE: quickshot/src/main/java/io/github/muddz/quickshot/QuickShot.java
class QuickShot (line 32) | public class QuickShot {
method QuickShot (line 50) | private QuickShot(@NonNull View view) {
method QuickShot (line 55) | private QuickShot(@NonNull Bitmap bitmap, @NonNull Context context) {
method of (line 60) | public static QuickShot of(@NonNull View view) {
method of (line 64) | public static QuickShot of(@NonNull Bitmap bitmap, @NonNull Context co...
method setFilename (line 71) | public QuickShot setFilename(String filename) {
method setPath (line 82) | public QuickShot setPath(String path) {
method setFileExtension (line 87) | private void setFileExtension(String fileExtension) {
method toJPG (line 95) | public QuickShot toJPG() {
method toJPG (line 105) | public QuickShot toJPG(int jpgQuality) {
method toPNG (line 115) | public QuickShot toPNG() {
method toNomedia (line 123) | public QuickShot toNomedia() {
method enableLogging (line 131) | public QuickShot enableLogging() {
method setResultListener (line 139) | public QuickShot setResultListener(@NonNull QuickShotListener listener) {
method getContext (line 147) | private Context getContext() {
method getBitmap (line 154) | private Bitmap getBitmap() {
method save (line 178) | public void save() throws NullPointerException {
type QuickShotListener (line 196) | public interface QuickShotListener {
method onQuickShotSuccess (line 197) | void onQuickShotSuccess(String path);
method onQuickShotFailed (line 199) | void onQuickShotFailed(String path, String errorMsg);
class BitmapSaver (line 202) | static class BitmapSaver extends AsyncTask<Void, Void, Void> {
method BitmapSaver (line 216) | BitmapSaver(Context context, Bitmap bitmap, boolean printStacktrace,...
method saveLegacy (line 230) | private void saveLegacy() {
method saveScopedStorage (line 257) | @RequiresApi(Build.VERSION_CODES.Q)
method doInBackground (line 293) | @Override
method onPostExecute (line 303) | @Override
method onCancelled (line 311) | @Override
FILE: quickshot/src/main/java/io/github/muddz/quickshot/QuickShotUtils.java
class QuickShotUtils (line 13) | class QuickShotUtils {
method getMimeType (line 15) | static String getMimeType(String src) {
method isAboveAPI29 (line 23) | static boolean isAboveAPI29() {
method generateLongBitmap (line 28) | private Bitmap generateLongBitmap(RecyclerView recyclerView) {
Condensed preview — 46 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (83K chars).
[
{
"path": ".gitignore",
"chars": 108,
"preview": "*.iml\n.gradle\n/local.properties\n.idea\n.DS_Store\n/build\n/captures\n.externalNativeBuild\n.cxx\nlocal.properties\n"
},
{
"path": "build.gradle",
"chars": 670,
"preview": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n r"
},
{
"path": "demo/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "demo/build.gradle",
"chars": 666,
"preview": "plugins {\n id 'com.android.application'\n}\n\nandroid {\n compileSdk 30\n\n defaultConfig {\n applicationId \"io"
},
{
"path": "demo/proguard-rules.pro",
"chars": 751,
"preview": "# Add project specific ProGuard rules here.\n# You can control the set of applied configuration files using the\n# proguar"
},
{
"path": "demo/src/main/AndroidManifest.xml",
"chars": 1092,
"preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:tools=\"http://schemas.android.com/tools\"\n"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/DrawingBoardView.java",
"chars": 2418,
"preview": "package io.github.muddz.quickshot.demo;\n\nimport android.annotation.SuppressLint;\nimport android.content.Context;\nimport "
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/MainActivity.java",
"chars": 3373,
"preview": "package io.github.muddz.quickshot.demo;\n\nimport android.Manifest;\nimport android.os.Bundle;\nimport android.view.Menu;\nim"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/NonSwipeViewPager.java",
"chars": 634,
"preview": "package io.github.muddz.quickshot.demo;\n\nimport android.content.Context;\nimport android.util.AttributeSet;\nimport androi"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/ViewPagerAdapter.java",
"chars": 1041,
"preview": "package io.github.muddz.quickshot.demo;\n\nimport androidx.annotation.NonNull;\nimport androidx.fragment.app.Fragment;\nimpo"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/fragments/BaseFragment.java",
"chars": 287,
"preview": "package io.github.muddz.quickshot.demo.fragments;\n\nimport android.view.View;\n\nimport androidx.fragment.app.Fragment;\n\npu"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/fragments/SurfaceViewFragment.java",
"chars": 1658,
"preview": "package io.github.muddz.quickshot.demo.fragments;\n\nimport android.media.MediaPlayer;\nimport android.net.Uri;\nimport andr"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/fragments/TextureViewFragment.java",
"chars": 3799,
"preview": "package io.github.muddz.quickshot.demo.fragments;\n\nimport android.graphics.SurfaceTexture;\nimport android.hardware.Camer"
},
{
"path": "demo/src/main/java/io/github/muddz/quickshot/demo/fragments/ViewFragment.java",
"chars": 1221,
"preview": "package io.github.muddz.quickshot.demo.fragments;\n\nimport android.os.Bundle;\nimport android.view.LayoutInflater;\nimport "
},
{
"path": "demo/src/main/res/drawable/ic_launcher_background.xml",
"chars": 5606,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:wi"
},
{
"path": "demo/src/main/res/drawable/ic_save_black_24dp.xml",
"chars": 458,
"preview": "<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:width=\"30dp\"\n android:height=\""
},
{
"path": "demo/src/main/res/drawable/ic_select.xml",
"chars": 1643,
"preview": "<vector android:height=\"24dp\" android:viewportHeight=\"512\"\n android:viewportWidth=\"512\" android:width=\"24dp\" xmlns:an"
},
{
"path": "demo/src/main/res/drawable-v24/ic_launcher_foreground.xml",
"chars": 1880,
"preview": "<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:aapt=\"http://schemas.android.com/aapt\"\n "
},
{
"path": "demo/src/main/res/layout/activity_main.xml",
"chars": 1077,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xm"
},
{
"path": "demo/src/main/res/layout/surface_fragment.xml",
"chars": 393,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andr"
},
{
"path": "demo/src/main/res/layout/texture_fragment.xml",
"chars": 355,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andro"
},
{
"path": "demo/src/main/res/layout/view_fragment.xml",
"chars": 1179,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n andro"
},
{
"path": "demo/src/main/res/menu/menu_toolbar.xml",
"chars": 543,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<menu xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:app=\"h"
},
{
"path": "demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml",
"chars": 272,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adaptive-icon xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <b"
},
{
"path": "demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml",
"chars": 272,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adaptive-icon xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <b"
},
{
"path": "demo/src/main/res/values/colors.xml",
"chars": 208,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorPrimary\">#3F51B5</color>\n <color name=\"color"
},
{
"path": "demo/src/main/res/values/strings.xml",
"chars": 77,
"preview": "<resources>\n <string name=\"app_name\">QuickShot demo</string>\n</resources>\n"
},
{
"path": "demo/src/main/res/values/styles.xml",
"chars": 381,
"preview": "<resources>\n\n <!-- Base application theme. -->\n <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.NoActionBar\">"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 233,
"preview": "#Sun Aug 01 22:32:07 CEST 2021\ndistributionBase=GRADLE_USER_HOME\ndistributionUrl=https\\://services.gradle.org/distributi"
},
{
"path": "gradle.properties",
"chars": 843,
"preview": "android.enableJetifier=true\nandroid.useAndroidX=true\n\n#MavenCentral publish informations\n#Publish plugin: https://github"
},
{
"path": "gradlew",
"chars": 5766,
"preview": "#!/usr/bin/env sh\n\n#\n# Copyright 2015 the original author or authors.\n#\n# Licensed under the Apache License, Version 2.0"
},
{
"path": "gradlew.bat",
"chars": 2674,
"preview": "@rem\n@rem Copyright 2015 the original author or authors.\n@rem\n@rem Licensed under the Apache License, Version 2.0 (the \""
},
{
"path": "license",
"chars": 10757,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "quickshot/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "quickshot/build.gradle",
"chars": 618,
"preview": "plugins {\n id 'com.android.library'\n id 'com.vanniktech.maven.publish'\n}\nandroid {\n compileSdk 30\n\n defaultC"
},
{
"path": "quickshot/consumer-rules.pro",
"chars": 0,
"preview": ""
},
{
"path": "quickshot/proguard-rules.pro",
"chars": 751,
"preview": "# Add project specific ProGuard rules here.\n# You can control the set of applied configuration files using the\n# proguar"
},
{
"path": "quickshot/src/androidTest/java/io/github/muddz/quickshot/QuickShotTest.java",
"chars": 4740,
"preview": "package io.github.muddz.quickshot;\n\nimport static android.view.View.MeasureSpec.EXACTLY;\n\nimport android.content.Context"
},
{
"path": "quickshot/src/main/AndroidManifest.xml",
"chars": 281,
"preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"io.github.muddz.quickshot\">\n\n <!--T"
},
{
"path": "quickshot/src/main/java/io/github/muddz/quickshot/PixelCopyHelper.java",
"chars": 1594,
"preview": "package io.github.muddz.quickshot;\n\nimport android.graphics.Bitmap;\nimport android.os.Build;\nimport android.os.Handler;\n"
},
{
"path": "quickshot/src/main/java/io/github/muddz/quickshot/QuickShot.java",
"chars": 10991,
"preview": "package io.github.muddz.quickshot;\n\nimport android.content.ContentResolver;\nimport android.content.ContentValues;\nimport"
},
{
"path": "quickshot/src/main/java/io/github/muddz/quickshot/QuickShotUtils.java",
"chars": 2934,
"preview": "package io.github.muddz.quickshot;\n\nimport android.graphics.Bitmap;\nimport android.graphics.Canvas;\nimport android.graph"
},
{
"path": "readme.md",
"chars": 2090,
"preview": "# QuickShot\n[](https://android-arsenal.com/api?lev"
},
{
"path": "settings.gradle",
"chars": 30,
"preview": "include ':demo', ':quickshot'\n"
}
]
// ... and 2 more files (download for full content)
About this extraction
This page contains the full source code of the Muddz/PixelShot GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 46 files (20.1 MB), approximately 19.7k tokens, and a symbol index with 96 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.