├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── raw
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── cn
│ │ │ └── gavinliu
│ │ │ └── simpleonestep
│ │ │ ├── widget
│ │ │ ├── DropView.java
│ │ │ ├── DragDropHelper.java
│ │ │ └── DragView.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── cn
│ │ │ └── gavinliu
│ │ │ └── simpleonestep
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── cn
│ │ └── gavinliu
│ │ └── simpleonestep
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshots.gif
├── screenshots2.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshots.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/screenshots.gif
--------------------------------------------------------------------------------
/screenshots2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/screenshots2.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SimpleOneStep
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/raw/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/raw/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gavinliu/SimpleOneStep/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | .idea/
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SimpleOneStep
2 |
3 | The SimpleOneStep is like ``OneStep`` about ``Smartisan OS 3``.
4 |
5 | ### Feature
6 |
7 | * Drag & drop UX
8 | * Share Image to wechat
9 |
10 | ### Screenshots
11 |
12 |  
13 |
14 | -------
15 |
16 | ### 功能
17 |
18 | * 拖拽 & 放下 的交互
19 | * 分享至微信朋友圈
20 |
21 | ### 小贴士
22 |
23 | 上图截取的锤子的``OneStep``中,图库多选实现方式可参见:https://github.com/gavinliu/Android-AbsListView-Drag-And-Drop
24 |
25 | * http://www.smartisan.com/os/#/os-3
26 |
--------------------------------------------------------------------------------
/app/src/test/java/cn/gavinliu/simpleonestep/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Gavin/Develop/android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/gavinliu/simpleonestep/widget/DropView.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep.widget;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by Gavin on 2016/10/19.
7 | */
8 |
9 | public class DropView {
10 |
11 | private View targetView;
12 | private int x, y, w, h;
13 |
14 | public DropView(View targetView) {
15 | this.targetView = targetView;
16 | }
17 |
18 | public boolean isContains(float touchX, float touchY) {
19 | int[] position = new int[2];
20 | targetView.getLocationOnScreen(position);
21 | this.x = position[0];
22 | this.y = position[1];
23 | this.w = targetView.getWidth();
24 | this.h = targetView.getHeight();
25 |
26 | return touchX > x && touchX < x + w && touchY > y && touchY < y + h;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/cn/gavinliu/simpleonestep/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("cn.gavinliu.simpleonestep", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.2"
6 | defaultConfig {
7 | applicationId "cn.gavinliu.simpleonestep"
8 | minSdkVersion 18
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:24.2.1'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
26 |
27 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/gavinliu/simpleonestep/widget/DragDropHelper.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep.widget;
2 |
3 | import android.graphics.Bitmap;
4 | import android.view.MotionEvent;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by Gavin on 2016/10/21.
9 | */
10 | public class DragDropHelper {
11 |
12 | private float mMotionDownX, mMotionDownY;
13 | private boolean isInit = false;
14 |
15 | private DragView mDragView;
16 | private DropView mDropView;
17 |
18 | private OnDropedListener mOnDropedListener;
19 |
20 | public void setDropView(View dropView) {
21 | mDropView = new DropView(dropView);
22 | }
23 |
24 | public void setOnDropedListener(OnDropedListener onDropedListener) {
25 | mOnDropedListener = onDropedListener;
26 | }
27 |
28 | public void startDrag(View v) {
29 | isInit = true;
30 | mDragView = new DragView(v.getContext(), v);
31 | mDragView.setImageBitmap(getViewBitmap(v));
32 | mDragView.dragStart();
33 | }
34 |
35 | public boolean onTouchEvent(MotionEvent event) {
36 | switch (event.getAction()) {
37 | case MotionEvent.ACTION_DOWN:
38 | mMotionDownX = event.getRawX();
39 | mMotionDownY = event.getRawY();
40 | break;
41 |
42 | case MotionEvent.ACTION_MOVE:
43 | if(!isInit) return false;
44 | int moveX = (int) (mMotionDownX - event.getRawX());
45 | int moveY = (int) (mMotionDownY - event.getRawY());
46 |
47 | if (mDragView != null) {
48 | mDragView.move(moveX, moveY);
49 | mDragView.setTouchPosition((int) event.getRawX(), (int) event.getRawY());
50 | }
51 | break;
52 |
53 | case MotionEvent.ACTION_UP:
54 | case MotionEvent.ACTION_CANCEL:
55 | if (mDropView != null) {
56 | if (mDropView.isContains(event.getRawX(), event.getRawY())) {
57 | mDragView.drop();
58 | if (mOnDropedListener != null) {
59 | mOnDropedListener.onDroped();
60 | }
61 | } else if (mDragView != null) {
62 | mDragView.dragEnd();
63 | mDragView = null;
64 | }
65 | isInit = false;
66 | }
67 | break;
68 | }
69 | return true;
70 | }
71 |
72 |
73 | private Bitmap getViewBitmap(View v) {
74 | v.clearFocus();
75 | v.setPressed(false);
76 |
77 | boolean willNotCache = v.willNotCacheDrawing();
78 | v.setWillNotCacheDrawing(false);
79 |
80 | int color = v.getDrawingCacheBackgroundColor();
81 | v.setDrawingCacheBackgroundColor(0);
82 |
83 | if (color != 0) {
84 | v.destroyDrawingCache();
85 | }
86 | v.buildDrawingCache();
87 | Bitmap cacheBitmap = v.getDrawingCache();
88 | if (cacheBitmap == null) {
89 | return null;
90 | }
91 |
92 | Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
93 |
94 | v.destroyDrawingCache();
95 | v.setWillNotCacheDrawing(willNotCache);
96 | v.setDrawingCacheBackgroundColor(color);
97 |
98 | return bitmap;
99 | }
100 |
101 | public interface OnDropedListener {
102 | void onDroped();
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/gavinliu/simpleonestep/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep;
2 |
3 | import android.content.ComponentName;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.pm.PackageManager;
7 | import android.content.pm.ResolveInfo;
8 | import android.net.Uri;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.os.Bundle;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.widget.ImageView;
14 |
15 | import java.io.FileNotFoundException;
16 | import java.io.FileOutputStream;
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.util.List;
20 |
21 | import cn.gavinliu.simpleonestep.widget.DragDropHelper;
22 |
23 | public class MainActivity extends AppCompatActivity {
24 |
25 | private static final String SHARED_FILE_NAME = "shared.png";
26 |
27 | private DragDropHelper mDragDropHelper;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 | copyPrivateRawResuorceToPubliclyAccessibleFile();
34 |
35 | mDragDropHelper = new DragDropHelper();
36 | mDragDropHelper.setOnDropedListener(new DragDropHelper.OnDropedListener() {
37 | @Override
38 | public void onDroped() {
39 | share(pkgName, className);
40 | }
41 | });
42 |
43 | ImageView imageView = (ImageView) findViewById(R.id.icon);
44 |
45 | mDragDropHelper.setDropView(imageView);
46 |
47 | findViewById(R.id.text).setOnLongClickListener(new View.OnLongClickListener() {
48 |
49 | @Override
50 | public boolean onLongClick(View v) {
51 | mDragDropHelper.startDrag(v);
52 | return true;
53 | }
54 | });
55 |
56 | findViewById(R.id.text).setOnTouchListener(new View.OnTouchListener() {
57 |
58 | @Override
59 | public boolean onTouch(View v, MotionEvent event) {
60 | mDragDropHelper.onTouchEvent(event);
61 | return false;
62 | }
63 | });
64 |
65 | Intent intent = new Intent(Intent.ACTION_SEND, null);
66 | intent.addCategory(Intent.CATEGORY_DEFAULT);
67 | intent.setType("image/*");
68 | PackageManager packageManager = getPackageManager();
69 | List mApps = packageManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
70 |
71 | for (ResolveInfo info : mApps) {
72 | if ("com.tencent.mm.ui.tools.ShareToTimeLineUI".equals(info.activityInfo.name)) {
73 | imageView.setImageDrawable(info.loadIcon(packageManager));
74 | pkgName = info.activityInfo.packageName;
75 | className = info.activityInfo.name;
76 | }
77 | }
78 | }
79 |
80 | private String pkgName;
81 | private String className;
82 |
83 | public void share(String pkgName, String classname) {
84 | Intent shareIntent = new Intent(Intent.ACTION_SEND);
85 | shareIntent.setComponent(new ComponentName(pkgName, classname));
86 | shareIntent.setType("image/*");
87 | Uri uri = Uri.fromFile(getFileStreamPath(SHARED_FILE_NAME));
88 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
89 | startActivity(shareIntent);
90 | }
91 |
92 |
93 | private void copyPrivateRawResuorceToPubliclyAccessibleFile() {
94 | InputStream inputStream = null;
95 | FileOutputStream outputStream = null;
96 | try {
97 | inputStream = getResources().openRawResource(R.raw.ic_launcher);
98 | outputStream = openFileOutput(SHARED_FILE_NAME, Context.MODE_WORLD_READABLE | Context.MODE_APPEND);
99 | byte[] buffer = new byte[1024];
100 | int length = 0;
101 | try {
102 | while ((length = inputStream.read(buffer)) > 0) {
103 | outputStream.write(buffer, 0, length);
104 | }
105 | } catch (IOException ioe) {
106 | /* ignore */
107 | }
108 | } catch (FileNotFoundException fnfe) {
109 | /* ignore */
110 | } finally {
111 | try {
112 | inputStream.close();
113 | } catch (IOException ioe) {
114 | /* ignore */
115 | }
116 | try {
117 | outputStream.close();
118 | } catch (IOException ioe) {
119 | /* ignore */
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/gavinliu/simpleonestep/widget/DragView.java:
--------------------------------------------------------------------------------
1 | package cn.gavinliu.simpleonestep.widget;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.content.Context;
7 | import android.graphics.Bitmap;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.drawable.BitmapDrawable;
10 | import android.graphics.drawable.Drawable;
11 | import android.util.DisplayMetrics;
12 | import android.view.Gravity;
13 | import android.view.View;
14 | import android.view.WindowManager;
15 | import android.view.animation.DecelerateInterpolator;
16 | import android.widget.FrameLayout;
17 | import android.widget.ImageView;
18 |
19 | /**
20 | * Created by Gavin on 2016/10/19.
21 | */
22 |
23 | public class DragView extends ImageView {
24 |
25 | private int mTouchX, mTouchY;
26 | private int mCreateX, mCreateY;
27 |
28 | private int layoutWidth, layoutHeight;
29 |
30 | private WindowManager mWindowManager;
31 | private WindowManager.LayoutParams mLayoutParams;
32 |
33 | private View mTargetView;
34 |
35 | private FrameLayout layout;
36 |
37 | @Deprecated
38 | public DragView(Context context) {
39 | super(context);
40 | }
41 |
42 | public DragView(Context context, View targetView) {
43 | super(context);
44 | this.mTargetView = targetView;
45 | init();
46 | }
47 |
48 | @Override
49 | public void setScaleX(float scaleX) {
50 | super.setScaleX(scaleX);
51 | }
52 |
53 | private void init() {
54 | mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
55 |
56 | int[] position = new int[2];
57 | mTargetView.getLocationOnScreen(position);
58 | int x = position[0];
59 | int y = position[1];
60 |
61 | mCreateX = x;
62 | mCreateY = y;
63 | layoutWidth = mTargetView.getWidth();
64 | layoutHeight = mTargetView.getHeight();
65 | }
66 |
67 | public void dragStart() {
68 | show();
69 | setBackgroundColor(0xDCFFFFFF);
70 | }
71 |
72 | public void dragEnd() {
73 | ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "x", getX(), mCreateX);
74 | ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "y", getY(), mCreateY);
75 |
76 | AnimatorSet animatorSet = new AnimatorSet();
77 | animatorSet.setDuration(550);
78 | animatorSet.setInterpolator(new DecelerateInterpolator());
79 | animatorSet.play(animatorX).with(animatorY);
80 | animatorSet.addListener(animatorListener);
81 | animatorSet.start();
82 | }
83 |
84 | public void drop() {
85 | ObjectAnimator animatorX = ObjectAnimator.ofFloat(this, "x", getX(), mTouchX - layoutWidth / 2);
86 | ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "y", getY(), mTouchY - layoutHeight / 2);
87 | ObjectAnimator animatorWidth = ObjectAnimator.ofFloat(this, "scaleX", 1f, 0f);
88 | ObjectAnimator animatorHeight = ObjectAnimator.ofFloat(this, "scaleY", 1f, 0f);
89 |
90 | AnimatorSet animatorSet = new AnimatorSet();
91 | animatorSet.setDuration(450);
92 | animatorSet.setInterpolator(new DecelerateInterpolator());
93 | animatorSet.play(animatorX).with(animatorY).with(animatorWidth).with(animatorHeight);
94 | animatorSet.addListener(animatorListener);
95 | animatorSet.start();
96 |
97 | mTargetView.setVisibility(VISIBLE);
98 | }
99 |
100 | Animator.AnimatorListener animatorListener = new Animator.AnimatorListener() {
101 |
102 | @Override
103 | public void onAnimationStart(Animator animation) {
104 |
105 | }
106 |
107 | @Override
108 | public void onAnimationEnd(Animator animation) {
109 | remove();
110 | }
111 |
112 | @Override
113 | public void onAnimationCancel(Animator animation) {
114 |
115 | }
116 |
117 | @Override
118 | public void onAnimationRepeat(Animator animation) {
119 |
120 | }
121 | };
122 |
123 | private void show() {
124 | mLayoutParams = new WindowManager.LayoutParams();
125 | mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
126 | mLayoutParams.format = PixelFormat.RGBA_8888;
127 | mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
128 | mLayoutParams.flags = mLayoutParams.flags | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
129 | mLayoutParams.flags = mLayoutParams.flags | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
130 | mLayoutParams.gravity = Gravity.START | Gravity.TOP;
131 |
132 | mLayoutParams.x = 0;
133 | mLayoutParams.y = 0;
134 |
135 | DisplayMetrics dm = new DisplayMetrics();
136 | WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
137 | manager.getDefaultDisplay().getMetrics(dm);
138 |
139 | mLayoutParams.width = dm.widthPixels;
140 | mLayoutParams.height = dm.heightPixels;
141 | layout = new FrameLayout(getContext());
142 | mWindowManager.addView(layout, mLayoutParams);
143 |
144 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(layoutWidth, layoutHeight);
145 | setX(mCreateX);
146 | setY(mCreateY);
147 | layout.addView(this, params);
148 |
149 | mTargetView.setVisibility(INVISIBLE);
150 | }
151 |
152 | public void move(int offsetX, int offsetY) {
153 | setX(mCreateX - offsetX);
154 | setY(mCreateY - offsetY);
155 | }
156 |
157 | private void remove() {
158 | this.setVisibility(View.GONE);
159 | layout.setVisibility(View.GONE);
160 | mWindowManager.removeView(layout);
161 |
162 | recycleBitmap();
163 |
164 | mTargetView.setVisibility(VISIBLE);
165 | }
166 |
167 | public void setTouchPosition(int touchX, int touchY) {
168 | mTouchX = touchX;
169 | mTouchY = touchY;
170 | }
171 |
172 | private void recycleBitmap() {
173 | Drawable drawable = getDrawable();
174 | if (drawable != null && drawable instanceof BitmapDrawable) {
175 | BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
176 | Bitmap bitmap = bitmapDrawable.getBitmap();
177 | if (bitmap != null && !bitmap.isRecycled()) {
178 | bitmap.recycle();
179 | }
180 | }
181 | }
182 |
183 | }
184 |
--------------------------------------------------------------------------------