[
  {
    "path": ".github/workflows/android.yml",
    "content": "# if gitlab action running occur a error such as 'No toolchains found in the NDK toolchains folder\n# for ABI with prefix: mips64el-linux-android', might you need to change 'distributionUrl' of gradle zip and 'classpath'.\n\nname: Build & Publish Debug APK\n\non:\n push:\n  branches:\n   - master\n   \njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v1\n    - name: set up JDK 1.8\n      uses: actions/setup-java@v1\n      with:\n        java-version: 1.8\n    - name: Make Gradle executable\n      run: chmod +x ./gradlew\n    - name: Build with Gradle\n      run: ./gradlew build\n    - name: Build Debug APK\n      run: ./gradlew assembleDebug\n#    - name: Releasing using Hub\n#      uses: ShaunLWM/action-release-debugapk@master  # this value is not any user,it is a pedestal,\n#      env:\n#       GITHUB_TOKEN: ${{ secrets.TOKEN }}\n#       APP_FOLDER: app\n#       RELEASE_TITLE: New Build\n\n"
  },
  {
    "path": ".gitignore",
    "content": "*.iml\n.gradle\n/local.properties\n/.idea/workspace.xml\n/.idea/libraries\n.DS_Store\n/build\n/captures\n### Android template\n# Built application files\n*.apk\n*.ap_\n\n# Files for the ART/Dalvik VM\n*.dex\n\n# Java class files\n*.class\n\n# Generated files\nbin/\ngen/\nout/\n\n# Gradle files\n.gradle/\nbuild/\n\n# Local configuration file (sdk path, etc)\nlocal.properties\n\n# Proguard folder generated by Eclipse\nproguard/\n\n# Log Files\n*.log\n\n# Android Studio Navigation editor temp files\n.navigation/\n\n# Android Studio captures folder\ncaptures/\n\n# Intellij\n*.iml\n.idea/workspace.xml\n.idea/\n\n# Keystore files\n*.jks\n\n"
  },
  {
    "path": "README.md",
    "content": "# AndroidScreenShot_SysApi\n这是一个例子，以非常优雅的方案实现屏幕截图。 实现原理为 利用android 5.0 之后的录屏API获取一帧画面，来实现截屏。\n\n## Special Features\n\n 1. 打破老旧的截屏方案，不能截状态栏的问题。\n\n 2. 截图其他app.\n\n## Usage\n\n**使用Shotter**\n\n    请查阅代码 onClickReqPermission()\n\n**使用ScreenShotActivity**\n\n    请查阅代码 onClickShot(),该方法可以截图其他app\n\n    \n### 更多拓展：\n   \n   > 因为ScreenShotActivity是一个透明并隐藏的activity，玩法有很多:\n    \n   a. 截图桌面;\n   \n   b. 对其他app进行截图:你自己试着调整shotter的delay时间为3秒，然后start截图，再切换到其他app里，等toast截图成功。\n"
  },
  {
    "path": "app/.gitignore",
    "content": "/build\n"
  },
  {
    "path": "app/build.gradle",
    "content": "apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion 25\n    buildToolsVersion '25.0.0'\n\n    defaultConfig {\n        applicationId \"com.androidyuan.androidscreenshot_sysapi\"\n        minSdkVersion 15\n        targetSdkVersion 25\n        versionCode 1\n        versionName \"1.0\"\n    }\n\n    lintOptions {\n        abortOnError false\n    }\n\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n        }\n        debug{\n            minifyEnabled false\n        }\n    }\n}\n\ndependencies {\n    compile fileTree(dir: 'libs', include: ['*.jar'])\n    compile project(':libshot')\n    testCompile 'junit:junit:4.12'\n    compile 'com.android.support:appcompat-v7:25.0.1'\n}\n"
  },
  {
    "path": "app/proguard-rules.pro",
    "content": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /home/wei/文档/tools/android-sdk-linux/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "app/src/androidTest/java/com/androidyuan/androidscreenshot_sysapi/ApplicationTest.java",
    "content": "package com.androidyuan.androidscreenshot_sysapi;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <a href=\"http://d.android.com/tools/testing/testing_android.html\">Testing Fundamentals</a>\n */\npublic class ApplicationTest extends ApplicationTestCase<Application> {\n    public ApplicationTest() {\n        super(Application.class);\n    }\n}"
  },
  {
    "path": "app/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    package=\"com.androidyuan.androidscreenshot_sysapi\">\n\n    <!--it is necessary-->\n    <uses-sdk tools:overrideLibrary=\"com.androidyuan.lib\"/>\n\n    <application\n        android:allowBackup=\"true\"\n        android:icon=\"@mipmap/ic_launcher\"\n        android:label=\"@string/app_name\"\n        android:supportsRtl=\"true\"\n        tools:overrideLibrary=\"com.androidyuan.lib\"\n        android:theme=\"@style/AppTheme\">\n        <activity android:name=\".ExampleActivity\">\n            <intent-filter>\n                <action android:name=\"android.intent.action.MAIN\" />\n                <category android:name=\"android.intent.category.LAUNCHER\" />\n            </intent-filter>\n        </activity>\n\n\n    </application>\n\n</manifest>"
  },
  {
    "path": "app/src/main/java/com/androidyuan/androidscreenshot_sysapi/ExampleActivity.java",
    "content": "package com.androidyuan.androidscreenshot_sysapi;\n\nimport android.content.Intent;\nimport android.media.projection.MediaProjectionManager;\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.os.SystemClock;\nimport android.support.annotation.RequiresApi;\nimport android.support.v7.app.AppCompatActivity;\nimport android.view.View;\nimport android.widget.Toast;\n\nimport com.androidyuan.lib.screenshot.ScreenShotActivity;\nimport com.androidyuan.lib.screenshot.Shooter;\n\n/**\n * This class is a demo to show you how to use Shooter.\n */\npublic class ExampleActivity extends AppCompatActivity {\n\n    private static final int REQ_CODE_PER = 0x2304;\n    private static final int REQ_CODE_ACT = 0x2305;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n    }\n\n    /**\n     * This is an example for using Shooter.\n     * This method will request permission and take screenshot on this Activity.\n     */\n    public void onClickReqPermission(View view) {\n        if (Build.VERSION.SDK_INT >= 21) {\n            startActivityForResult(createScreenCaptureIntent(), REQ_CODE_PER);\n        }\n    }\n\n    /**\n     * using {@see ScreenShotActivity} to take screenshot on current Activity directly.\n     * If you press home it will take screenshot on another app.\n     * @param view\n     */\n    public void onClickShot(View view) {\n        startActivityForResult(ScreenShotActivity.createIntent(this, null,0), REQ_CODE_ACT);\n        toast(\"Press home key,open another app.\");//if you want to take screenshot on another app.\n    }\n\n\n    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)\n    private Intent createScreenCaptureIntent() {\n        //Here using media_projection instead of Context.MEDIA_PROJECTION_SERVICE to  make it successfully build on low api.\n        return ((MediaProjectionManager) getSystemService(\"media_projection\")).createScreenCaptureIntent();\n    }\n\n    private String getSavedPath() {\n        return getExternalFilesDir(\"screenshot\").getAbsoluteFile() + \"/\"\n                + SystemClock.currentThreadTimeMillis() + \".png\";\n    }\n\n    protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n        super.onActivityResult(requestCode, resultCode, data);\n        switch (requestCode) {\n\n            case REQ_CODE_ACT: {\n                if (resultCode == RESULT_OK && data != null) {\n                    toast(\"Screenshot saved at \" + data.getData().toString());\n                }\n                else{\n                    toast(\"You got wrong.\");\n                }\n            }\n            break;\n            case REQ_CODE_PER: {\n                if (resultCode == RESULT_OK && data != null) {\n                    Shooter shooter = new Shooter(ExampleActivity.this, resultCode, data);\n                    shooter.startScreenShot(getSavedPath(), new Shooter.OnShotListener() {\n                                @Override\n                                public void onFinish(String path) {\n                                    //here is done status.\n                                    toast(\"Screenshot saved at \" + path);\n                                }\n\n                                @Override\n                                public void onError() {\n                                    toast(\"You got wrong.\");\n                                }\n                            }\n                    );\n                } else if (resultCode == RESULT_CANCELED) {\n                    //user canceled.\n                } else {\n\n                }\n            }\n        }\n    }\n\n\n    private void toast(String str) {\n        Toast.makeText(ExampleActivity.this, str, Toast.LENGTH_LONG).show();\n    }\n\n    private void goBackground() {\n        Intent startMain = new Intent(Intent.ACTION_MAIN);\n        startMain.addCategory(Intent.CATEGORY_HOME);\n        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\n        startActivity(startMain);\n    }\n\n}\n"
  },
  {
    "path": "app/src/main/res/layout/activity_main.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<LinearLayout\n    xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:paddingBottom=\"@dimen/activity_vertical_margin\"\n    android:paddingLeft=\"@dimen/activity_horizontal_margin\"\n    android:paddingRight=\"@dimen/activity_horizontal_margin\"\n    android:paddingTop=\"@dimen/activity_vertical_margin\"\n    android:orientation=\"vertical\"\n    tools:context=\"com.androidyuan.androidscreenshot_sysapi.ExampleActivity\">\n\n    <Button\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:onClick=\"onClickReqPermission\"\n        android:text=\"Using Shooter class\" />\n\n    <Button\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"\n        android:onClick=\"onClickShot\"\n        android:text=\"Using Activity\"/>\n\n\n\n</LinearLayout>\n"
  },
  {
    "path": "app/src/main/res/values/colors.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <color name=\"colorPrimary\">#3F51B5</color>\n    <color name=\"colorPrimaryDark\">#303F9F</color>\n    <color name=\"colorAccent\">#FF4081</color>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/dimens.xml",
    "content": "<resources>\n    <!-- Default screen margins, per the Android Design guidelines. -->\n    <dimen name=\"activity_horizontal_margin\">16dp</dimen>\n    <dimen name=\"activity_vertical_margin\">16dp</dimen>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/strings.xml",
    "content": "<resources>\n    <string name=\"app_name\">AndroidScreenShot_SysApi</string>\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values/styles.xml",
    "content": "<resources>\n\n    <!-- Base application theme. -->\n    <style name=\"AppTheme\" parent=\"Theme.AppCompat.Light.DarkActionBar\">\n        <!-- Customize your theme here. -->\n        <item name=\"colorPrimary\">@color/colorPrimary</item>\n        <item name=\"colorPrimaryDark\">@color/colorPrimaryDark</item>\n        <item name=\"colorAccent\">@color/colorAccent</item>\n    </style>\n\n</resources>\n"
  },
  {
    "path": "app/src/main/res/values-w820dp/dimens.xml",
    "content": "<resources>\n    <!-- Example customization of dimensions originally defined in res/values/dimens.xml\n         (such as screen margins) for screens with more than 820dp of available width. This\n         would include 7\" and 10\" devices in landscape (~960dp and ~1280dp respectively). -->\n    <dimen name=\"activity_horizontal_margin\">64dp</dimen>\n</resources>\n"
  },
  {
    "path": "app/src/test/java/com/androidyuan/androidscreenshot_sysapi/ExampleUnitTest.java",
    "content": "package com.androidyuan.androidscreenshot_sysapi;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * To work on unit tests, switch the Test Artifact in the Build Variants view.\n */\npublic class ExampleUnitTest {\n    @Test\n    public void addition_isCorrect() throws Exception {\n        assertEquals(4, 2 + 2);\n    }\n}"
  },
  {
    "path": "build.gradle",
    "content": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    repositories {\n        maven { url \"http://maven.aliyun.com/nexus/content/groups/public/\" }\n        maven { url \"https://jitpack.io\" }\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:3.1.2'\n\n        // NOTE: Do not place your application dependencies here; they belong\n        // in the individual module build.gradle files\n    }\n}\n\nallprojects {\n    repositories {\n        maven { url \"http://maven.aliyun.com/nexus/content/groups/public/\" }\n        maven { url \"https://jitpack.io\" }\n        jcenter()\n    }\n}\n\ntask clean(type: Delete) {\n    delete rootProject.buildDir\n}\n\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Thu Aug 10 14:12:44 CST 2017\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-4.4-all.zip\n"
  },
  {
    "path": "gradle.properties",
    "content": "# Project-wide Gradle settings.\n\n# IDE (e.g. Android Studio) users:\n# Gradle settings configured through the IDE *will override*\n# any settings specified in this file.\n\n# For more details on how to configure your build environment visit\n# http://www.gradle.org/docs/current/userguide/build_environment.html\n\n# Specifies the JVM arguments used for the daemon process.\n# The setting is particularly useful for tweaking memory settings.\n# Default value: -Xmx10248m -XX:MaxPermSize=256m\n# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8\n\n# When configured, Gradle will run in incubating parallel mode.\n# This option should only be used with decoupled projects. More details, visit\n# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects\n# org.gradle.parallel=true"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\nesac\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >/dev/null\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >/dev/null\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n    JAVACMD=`cygpath --unix \"$JAVACMD\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem  Gradle startup script for Windows\n@rem\n@rem ##########################################################################\n\n@rem Set local scope for the variables with windows NT shell\nif \"%OS%\"==\"Windows_NT\" setlocal\n\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nset DEFAULT_JVM_OPTS=\n\nset DIRNAME=%~dp0\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\nset APP_BASE_NAME=%~n0\nset APP_HOME=%DIRNAME%\n\n@rem Find java.exe\nif defined JAVA_HOME goto findJavaFromJavaHome\n\nset JAVA_EXE=java.exe\n%JAVA_EXE% -version >NUL 2>&1\nif \"%ERRORLEVEL%\" == \"0\" goto init\n\necho.\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:findJavaFromJavaHome\nset JAVA_HOME=%JAVA_HOME:\"=%\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\n\nif exist \"%JAVA_EXE%\" goto init\n\necho.\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:init\n@rem Get command-line arguments, handling Windowz variants\n\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\n\n:win9xME_args\n@rem Slurp the command line arguments.\nset CMD_LINE_ARGS=\nset _SKIP=2\n\n:win9xME_args_slurp\nif \"x%~1\" == \"x\" goto execute\n\nset CMD_LINE_ARGS=%*\ngoto execute\n\n:4NT_args\n@rem Get arguments from the 4NT Shell from JP Software\nset CMD_LINE_ARGS=%$\n\n:execute\n@rem Setup the command line\n\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\n\n@rem Execute Gradle\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\n\n:end\n@rem End local scope for the variables with windows NT shell\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\n\n:fail\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\nrem the _cmd.exe /c_ return code!\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\nexit /b 1\n\n:mainEnd\nif \"%OS%\"==\"Windows_NT\" endlocal\n\n:omega\n"
  },
  {
    "path": "libshot/.gitignore",
    "content": "/build\n"
  },
  {
    "path": "libshot/build.gradle",
    "content": "apply plugin: 'com.android.library'\n\nandroid {\n    compileSdkVersion 25\n    buildToolsVersion '25.0.0'\n\n    defaultConfig {\n        minSdkVersion 21\n        targetSdkVersion 21\n        versionCode 1\n        versionName \"1.0\"\n    }\n    buildTypes {\n        release {\n            minifyEnabled false\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\n        }\n    }\n    lintOptions {\n        abortOnError false\n    }\n}\n\ndependencies {\n    compile fileTree(dir: 'libs', include: ['*.jar'])\n    testCompile 'junit:junit:4.12'\n    compile 'com.android.support:appcompat-v7:25.4.0'\n}"
  },
  {
    "path": "libshot/proguard-rules.pro",
    "content": "# Add project specific ProGuard rules here.\n# By default, the flags in this file are appended to flags specified\n# in /home/wei/文档/tools/android-sdk-linux/tools/proguard/proguard-android.txt\n# You can edit the include path and order by changing the proguardFiles\n# directive in build.gradle.\n#\n# For more details, see\n#   http://developer.android.com/guide/developing/tools/proguard.html\n\n# Add any project specific keep options here:\n\n# If your project uses WebView with JS, uncomment the following\n# and specify the fully qualified class name to the JavaScript interface\n# class:\n#-keepclassmembers class fqcn.of.javascript.interface.for.webview {\n#   public *;\n#}\n"
  },
  {
    "path": "libshot/src/androidTest/java/com/androidyuan/lib/ApplicationTest.java",
    "content": "package com.androidyuan.lib;\n\nimport android.app.Application;\nimport android.test.ApplicationTestCase;\n\n/**\n * <a href=\"http://d.android.com/tools/testing/testing_android.html\">Testing Fundamentals</a>\n */\npublic class ApplicationTest extends ApplicationTestCase<Application> {\n    public ApplicationTest() {\n        super(Application.class);\n    }\n}"
  },
  {
    "path": "libshot/src/main/AndroidManifest.xml",
    "content": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    package=\"com.androidyuan.lib\">\n\n    <application\n        android:allowBackup=\"true\"\n        android:label=\"@string/app_name\"\n        android:supportsRtl=\"true\">\n        <activity\n            android:name=\"com.androidyuan.lib.screenshot.ScreenShotActivity\"\n            android:exported=\"true\"\n            android:launchMode=\"singleTask\"\n            android:theme=\"@android:style/Theme.Dialog\">\n            <intent-filter>\n                <action android:name=\"androidyuan.shooter\"></action>\n                <category android:name=\"android.intent.category.DEFAULT\" />\n            </intent-filter>\n        </activity>\n    </application>\n\n</manifest>\n"
  },
  {
    "path": "libshot/src/main/java/com/androidyuan/lib/screenshot/ScreenShotActivity.java",
    "content": "package com.androidyuan.lib.screenshot;\n\n\nimport android.app.Activity;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.graphics.drawable.ColorDrawable;\nimport android.media.projection.MediaProjectionManager;\nimport android.net.Uri;\nimport android.os.Build;\nimport android.os.Bundle;\nimport android.view.Window;\n\n/**\n * Created by wei on 16-9-18.\n * <p>\n * There is totally transparent activity,only has a record permission dialog.\n * If you want to screenshot on other applications,might you need to use this activity to take screenshot.\n */\npublic class ScreenShotActivity extends Activity {\n\n    public static final String KEY_PATH = \"path\";\n    public static final String KEY_DELAY = \"delay_time\";\n\n    public static final int REQUEST_MEDIA_PROJECTION = 0x2304;\n    public static final String ACTION_SHOTER = \"androidyuan.shooter\";\n\n    private String savedPath;\n    private long delay;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n\n//        setTheme(android.R.style.Theme_Dialog);//this line cause a problem, activity background wasn't transparent but black.\n        super.onCreate(savedInstanceState);\n\n        //here is a transparent activity,and previous activity will not be called Activity#onPause().\n        requestWindowFeature(Window.FEATURE_NO_TITLE);\n        getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));\n        getWindow().setDimAmount(0f);\n        savedPath = getIntent().getStringExtra(KEY_PATH);\n        delay = getIntent().getLongExtra(KEY_DELAY,0);\n        requestScreenShotPermission();\n    }\n\n    public static Intent createIntent(Context context, String path,long delay) {\n        Intent intent = new Intent(context, ScreenShotActivity.class);\n        intent.putExtra(KEY_PATH, path);\n        intent.putExtra(KEY_DELAY, delay);\n        return intent;\n    }\n\n\n    public void requestScreenShotPermission() {\n        if (Build.VERSION.SDK_INT >= 21) {\n            startActivityForResult(createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION);\n        }\n    }\n\n    private Intent createScreenCaptureIntent() {\n        //here used media_projection instead of Context.MEDIA_PROJECTION_SERVICE to  make it successfully build on low api.\n        return ((MediaProjectionManager) getSystemService(\"media_projection\")).createScreenCaptureIntent();\n    }\n\n\n    protected void onActivityResult(int requestCode, final int resultCode, final Intent data) {\n        super.onActivityResult(requestCode, resultCode, data);\n        switch (requestCode) {\n            case REQUEST_MEDIA_PROJECTION: {\n                if (resultCode == RESULT_OK && data != null) {\n\n                    getWindow().getDecorView().postDelayed(new Runnable() {\n                        @Override\n                        public void run() {\n                            Shooter shooter = new Shooter(ScreenShotActivity.this, resultCode, data);\n                            shooter.startScreenShot(savedPath, new Shooter.OnShotListener() {\n                                @Override\n                                public void onFinish(String path) {\n                                    Intent intent = new Intent();\n                                    intent.setData(Uri.parse(path));\n                                    setResult(RESULT_OK, intent);\n                                    finish(); // don't forget finish activity\n                                }\n\n                                @Override\n                                public void onError() {\n                                    setResult(RESULT_CANCELED);\n                                    finish();\n                                }\n                            });\n                        }\n                    },delay);\n                } else if (resultCode == RESULT_CANCELED) {\n                    setResult(RESULT_CANCELED);\n                    finish();\n                } else {\n                    setResult(RESULT_CANCELED);\n                    finish();\n                }\n            }\n        }\n    }\n\n\n}"
  },
  {
    "path": "libshot/src/main/java/com/androidyuan/lib/screenshot/Shooter.java",
    "content": "package com.androidyuan.lib.screenshot;\n\nimport android.annotation.TargetApi;\nimport android.content.Context;\nimport android.content.Intent;\nimport android.content.res.Resources;\nimport android.graphics.Bitmap;\nimport android.graphics.PixelFormat;\nimport android.hardware.display.DisplayManager;\nimport android.hardware.display.VirtualDisplay;\nimport android.media.Image;\nimport android.media.ImageReader;\nimport android.media.projection.MediaProjection;\nimport android.media.projection.MediaProjectionManager;\nimport android.os.AsyncTask;\nimport android.os.Build;\nimport android.os.Handler;\nimport android.os.SystemClock;\nimport android.text.TextUtils;\nimport android.util.DisplayMetrics;\nimport android.view.Display;\nimport android.view.WindowManager;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.lang.ref.SoftReference;\nimport java.nio.ByteBuffer;\n\n/**\n * Created by wei on 16-12-1.\n * <p>\n * Remind:\n * Run this class after you got record permission.\n */\npublic class Shooter {\n\n    public static boolean hasPermission;\n\n    private final SoftReference<Context> mRefContext;\n    private ImageReader mImageReader;\n\n    private MediaProjection mMediaProjection;\n    private VirtualDisplay mVirtualDisplay;\n\n    private String mLocalUrl = \"\";\n\n    private OnShotListener mOnShotListener;\n    private int mHeight;\n    private int mWidth;\n\n    //using a default path.\n    private String getSavedPath() {\n        if (TextUtils.isEmpty(mLocalUrl)) {\n            mLocalUrl = getContext().getExternalFilesDir(\"screenshot\").getAbsoluteFile() + \"/\"\n                    + SystemClock.currentThreadTimeMillis() + \".png\";\n        }\n        return mLocalUrl;\n    }\n\n\n    public Shooter(Context context, int reqCode, Intent data) {\n        this.mRefContext = new SoftReference<>(context);\n\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n\n            mMediaProjection = getMediaProjectionManager().getMediaProjection(reqCode, data);\n\n            WindowManager window = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);\n            Display mDisplay = window.getDefaultDisplay();\n            DisplayMetrics metrics = new DisplayMetrics();\n            mDisplay.getRealMetrics(metrics);\n            mWidth = metrics.widthPixels;//size.x;\n            mHeight = metrics.heightPixels;//size.y;\n\n            mImageReader = ImageReader.newInstance(\n                    mWidth,\n                    mHeight,\n                    PixelFormat.RGBA_8888,//this is necessary to equal buffer format in #copyPixelsFromBuffer.\n                    1);\n        }\n    }\n\n\n    @TargetApi(Build.VERSION_CODES.LOLLIPOP)\n    private void virtualDisplay() {\n\n        mVirtualDisplay = mMediaProjection.createVirtualDisplay(\n                \"screen-mirror\",\n                mWidth,\n                mHeight,\n                Resources.getSystem().getDisplayMetrics().densityDpi,\n                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,\n                mImageReader.getSurface(), null, null\n        );\n\n    }\n\n    /**\n     * @param onShotListener\n     * @param savedPath\n     */\n    public void startScreenShot(String savedPath, OnShotListener onShotListener) {\n        mLocalUrl = savedPath;\n        startScreenShot(onShotListener);\n    }\n\n\n    /**\n     * This method will using {@link #getSavedPath} to save.\n     * @param onShotListener\n     */\n    @TargetApi(Build.VERSION_CODES.KITKAT)\n    public void startScreenShot(OnShotListener onShotListener) {\n        hasPermission = true;\n        mOnShotListener = onShotListener;\n\n        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n            virtualDisplay();\n            Handler handler = new Handler();\n            handler.postDelayed(new Runnable() {\n                                    @Override\n                                    public void run() {\n                                        Image image = mImageReader.acquireLatestImage();\n                                        new SaveTask().doInBackground(image);\n                                    }\n                                },\n                    800);\n            //this is a delay due to that record screen permission dialog has not dismissed on some devices cause take dialog graphic in screenshot\n            //.@see<a href=\"https://github.com/weizongwei5/AndroidScreenShot_SysApi/issues/4\">issues</a>\n        }\n\n    }\n\n\n    public class SaveTask extends AsyncTask<Image, Void, Bitmap> {\n\n        @TargetApi(Build.VERSION_CODES.KITKAT)\n        @Override\n        protected Bitmap doInBackground(Image... params) {\n            if (params == null || params.length < 1 || params[0] == null) {\n                return null;\n            }\n\n            Image image = params[0];\n\n            int width = image.getWidth();\n            int height = image.getHeight();\n            final Image.Plane[] planes = image.getPlanes();\n            final ByteBuffer buffer = planes[0].getBuffer();\n            //每个像素的间距\n            int pixelStride = planes[0].getPixelStride();\n            //总的间距\n            int rowStride = planes[0].getRowStride();\n            int rowPadding = rowStride - pixelStride * width;\n            Bitmap bitmap = Bitmap.createBitmap(width + rowPadding / pixelStride, height,\n                    Bitmap.Config.ARGB_8888);//even though ARGB8888 will consume more memory,it has better compatibility on device.\n            bitmap.copyPixelsFromBuffer(buffer);\n            bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height);\n            image.close();\n            File fileImage = null;\n            if (bitmap != null) {\n                try {\n                    fileImage = new File(getSavedPath());\n\n                    if (!fileImage.exists()) {\n                        fileImage.createNewFile();\n                    }\n                    FileOutputStream out = new FileOutputStream(fileImage);\n                    if (out != null) {\n                        bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);\n                        out.flush();\n                        out.close();\n                    }\n\n                } catch (FileNotFoundException e) {\n                    e.printStackTrace();\n                    if (mOnShotListener != null) mOnShotListener.onError();\n                    release();\n                    return null;\n                } catch (IOException e) {\n                    e.printStackTrace();\n                    if (mOnShotListener != null) mOnShotListener.onError();\n\n                    release();\n                    return null;\n                }\n            }\n\n            if (bitmap != null && !bitmap.isRecycled()) {\n                bitmap.recycle();\n            }\n\n            if (mVirtualDisplay != null) {\n                mVirtualDisplay.release();\n            }\n            if (mMediaProjection != null) {\n                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n                    mMediaProjection.stop();\n                }\n            }\n\n            if (mOnShotListener != null) {\n                mOnShotListener.onFinish(getSavedPath());\n            }\n\n            return null;\n        }\n\n        @TargetApi(Build.VERSION_CODES.KITKAT)\n        @Override\n        protected void onPostExecute(Bitmap bitmap) {\n            super.onPostExecute(bitmap);\n        }\n    }\n\n    public void release(){\n        if (mVirtualDisplay != null) {\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {\n                mVirtualDisplay.release();\n            }\n        }\n        if (mMediaProjection != null) {\n            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {\n                mMediaProjection.stop();\n            }\n        }\n    }\n\n\n    @TargetApi(Build.VERSION_CODES.LOLLIPOP)\n    private MediaProjectionManager getMediaProjectionManager() {\n\n        return (MediaProjectionManager) getContext().getSystemService(\n                Context.MEDIA_PROJECTION_SERVICE);\n    }\n\n    private Context getContext() {\n        return mRefContext.get();\n    }\n\n    public interface OnShotListener {\n        void onFinish(String path);\n        void onError();\n    }\n}\n"
  },
  {
    "path": "libshot/src/main/res/values/strings.xml",
    "content": "<resources>\n    <string name=\"app_name\">lib</string>\n</resources>\n"
  },
  {
    "path": "libshot/src/test/java/com/androidyuan/lib/ExampleUnitTest.java",
    "content": "package com.androidyuan.lib;\n\nimport org.junit.Test;\n\nimport static org.junit.Assert.*;\n\n/**\n * To work on unit tests, switch the Test Artifact in the Build Variants view.\n */\npublic class ExampleUnitTest {\n    @Test\n    public void addition_isCorrect() throws Exception {\n        assertEquals(4, 2 + 2);\n    }\n}"
  },
  {
    "path": "settings.gradle",
    "content": "include ':app', ':libshot'\n"
  }
]