├── .gitignore
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── me
│ │ └── tatocaster
│ │ └── snowview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── me
│ │ │ └── tatocaster
│ │ │ └── snowview
│ │ │ ├── MainActivity.java
│ │ │ ├── SnowView
│ │ │ ├── SnowFlake.java
│ │ │ └── SnowView.java
│ │ │ ├── Utils.java
│ │ │ └── services
│ │ │ └── OverlayService.java
│ └── res
│ │ ├── drawable
│ │ └── rounded_view.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── overlay.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── me
│ └── tatocaster
│ └── snowview
│ └── ExampleUnitTest.java
├── art
├── all.gif
└── wiggle.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme.md
└── settings.gradle
/.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 | ### Gradle template
11 | .gradle
12 | /build/
13 |
14 | # Ignore Gradle GUI config
15 | gradle-app.setting
16 |
17 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
18 | !gradle-wrapper.jar
19 |
20 | # Cache of project
21 | .gradletasknamecache
22 |
23 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
24 | # gradle/wrapper/gradle-wrapper.properties
25 | ### Java template
26 | *.class
27 |
28 | # BlueJ files
29 | *.ctxt
30 |
31 | # Mobile Tools for Java (J2ME)
32 | .mtj.tmp/
33 |
34 | # Package Files #
35 | *.jar
36 | *.war
37 | *.ear
38 |
39 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
40 | hs_err_pid*
41 | ### Android template
42 | # Built application files
43 | *.apk
44 | *.ap_
45 |
46 | # Files for the ART/Dalvik VM
47 | *.dex
48 |
49 | # Java class files
50 | *.class
51 |
52 | # Generated files
53 | bin/
54 | gen/
55 | out/
56 |
57 | # Gradle files
58 | .gradle/
59 | build/
60 |
61 | # Local configuration file (sdk path, etc)
62 | local.properties
63 |
64 | # Proguard folder generated by Eclipse
65 | proguard/
66 |
67 | # Log Files
68 | *.log
69 |
70 | # Android Studio Navigation editor temp files
71 | .navigation/
72 |
73 | # Android Studio captures folder
74 | captures/
75 |
76 | # Intellij
77 | *.iml
78 | .idea/
79 |
80 | # Keystore files
81 | *.jks
82 |
83 | # External native build folder generated in Android Studio 2.2 and later
84 | .externalNativeBuild
85 | ### JetBrains template
86 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
87 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
88 |
89 | # User-specific stuff:
90 | .idea/workspace.xml
91 | .idea/tasks.xml
92 |
93 | # Sensitive or high-churn files:
94 | .idea/dataSources/
95 | .idea/dataSources.ids
96 | .idea/dataSources.xml
97 | .idea/dataSources.local.xml
98 | .idea/sqlDataSources.xml
99 | .idea/dynamic.xml
100 | .idea/uiDesigner.xml
101 |
102 | # Gradle:
103 | .idea/gradle.xml
104 | .idea/libraries
105 |
106 | # Mongo Explorer plugin:
107 | .idea/mongoSettings.xml
108 |
109 | ## File-based project format:
110 | *.iws
111 |
112 | ## Plugin-specific files:
113 |
114 | # IntelliJ
115 | /out/
116 |
117 | # mpeltonen/sbt-idea plugin
118 | .idea_modules/
119 |
120 | # JIRA plugin
121 | atlassian-ide-plugin.xml
122 |
123 | # Crashlytics plugin (for Android Studio and IntelliJ)
124 | com_crashlytics_export_strings.xml
125 | crashlytics.properties
126 | crashlytics-build.properties
127 | fabric.properties
128 | ### macOS template
129 | *.DS_Store
130 | .AppleDouble
131 | .LSOverride
132 |
133 | # Icon must end with two \r
134 | Icon
135 |
136 |
137 | # Thumbnails
138 | ._*
139 |
140 | # Files that might appear in the root of a volume
141 | .DocumentRevisions-V100
142 | .fseventsd
143 | .Spotlight-V100
144 | .TemporaryItems
145 | .Trashes
146 | .VolumeIcon.icns
147 | .com.apple.timemachine.donotpresent
148 |
149 | # Directories potentially created on remote AFP share
150 | .AppleDB
151 | .AppleDesktop
152 | Network Trash Folder
153 | Temporary Items
154 | .apdisk
155 |
156 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 | defaultConfig {
7 | applicationId "me.tatocaster.snowview"
8 | minSdkVersion rootProject.ext.minSdkVersion
9 | targetSdkVersion rootProject.ext.targetSdkVersion
10 | versionCode rootProject.ext.versionCode
11 | versionName rootProject.ext.versionName
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | jackOptions {
14 | enabled true
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled true
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 | }
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
32 | exclude group: 'com.android.support', module: 'support-annotations'
33 | })
34 |
35 | compile libraries.supportV7
36 | compile libraries.supportDesign
37 | compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
38 | compile libraries.facebookRebound
39 |
40 | testCompile libraries.jUnit
41 | }
42 |
--------------------------------------------------------------------------------
/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/tatocaster/Library/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/me/tatocaster/snowview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview;
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("me.tatocaster.snowview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/me/tatocaster/snowview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import me.tatocaster.snowview.services.OverlayService;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | private static final String TAG = "MainActivity";
11 | private static final int PERMISSION_REQUEST_CODE = 6666;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 |
18 | if (Utils.isSystemAlertPermissionGranted(this))
19 | startOverlayService();
20 | else
21 | Utils.requestSystemAlertPermission(this, null, PERMISSION_REQUEST_CODE);
22 | }
23 |
24 | @Override
25 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
26 | if (requestCode == PERMISSION_REQUEST_CODE && Utils.isSystemAlertPermissionGranted(this))
27 | startOverlayService();
28 |
29 | super.onActivityResult(requestCode, resultCode, data);
30 | }
31 |
32 | private void startOverlayService() {
33 | if (!Utils.isSnowOverlayingServiceIsRunning(this, OverlayService.class))
34 | startService(new Intent(MainActivity.this, OverlayService.class));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/me/tatocaster/snowview/SnowView/SnowFlake.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview.SnowView;
2 |
3 |
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Point;
7 |
8 | import java.util.Random;
9 |
10 | /**
11 | * Created by tatocaster on 1/1/17.
12 | */
13 |
14 | class SnowFlake {
15 | private static final String TAG = "SnowFlake";
16 | private static final int FLAKE_MAX_RADIUS = 6;
17 | // control this, will start from upper frame
18 | private static final int DIVISOR_CONTROL_FLAKE_START = 8;
19 |
20 | // wind direction and strength
21 | private static final int WIND = -10;
22 |
23 | private final Random mRandom;
24 | private double x;
25 | private double y;
26 | private Paint mPaint;
27 | private int width;
28 | private int height;
29 |
30 | SnowFlake(Point position, Paint paint, int width, int height) {
31 | this.x = position.x;
32 | this.y = position.y;
33 | this.mPaint = paint;
34 | this.width = width;
35 | this.height = height;
36 | mRandom = new Random();
37 | }
38 |
39 | private void move() {
40 | // x += WIND;
41 | y += 15;
42 | if (needsReset()) {
43 | reset();
44 | }
45 | }
46 |
47 | private void reset() {
48 | x = mRandom.nextInt(width);
49 | y = mRandom.nextInt(height / DIVISOR_CONTROL_FLAKE_START);
50 | }
51 |
52 | private boolean needsReset() {
53 | return y >= height;
54 | }
55 |
56 | void draw(Canvas canvas) {
57 | move();
58 | canvas.drawCircle((float) x, (float) y, mRandom.nextInt(FLAKE_MAX_RADIUS), mPaint);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/me/tatocaster/snowview/SnowView/SnowView.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview.SnowView;
2 |
3 |
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.PixelFormat;
9 | import android.graphics.Point;
10 | import android.util.AttributeSet;
11 | import android.view.Gravity;
12 | import android.view.LayoutInflater;
13 | import android.view.MotionEvent;
14 | import android.view.View;
15 | import android.view.WindowManager;
16 | import android.widget.FrameLayout;
17 |
18 | import com.facebook.rebound.SimpleSpringListener;
19 | import com.facebook.rebound.Spring;
20 | import com.facebook.rebound.SpringConfig;
21 | import com.facebook.rebound.SpringSystem;
22 | import com.facebook.rebound.SpringUtil;
23 |
24 | import java.util.Random;
25 |
26 | import me.tatocaster.snowview.R;
27 | import me.tatocaster.snowview.Utils;
28 |
29 | /**
30 | * Created by tatocaster on 1/1/17.
31 | */
32 |
33 | public class SnowView extends View implements View.OnTouchListener {
34 | private static final String TAG = "SnowView";
35 | private static final int NUM_SNOWFLAKES = 70;
36 | private static final long DELAY = 100L;
37 | private Context mContext;
38 | private WindowManager mWindowManager;
39 | private FrameLayout mFrameLayout;
40 | private SnowFlake[] mSnowFlakes;
41 | private static final int CANVAS_WIDTH = 200;
42 | private static final int CANVAS_HEIGHT = 200;
43 |
44 | private Spring mSpring;
45 | private Spring mSpringForFrameXPosition;
46 | private Spring mSpringForFrameYPosition;
47 | // sprint transition
48 | private static double TENSION = 300;
49 | private static double DAMPER = 16; //friction
50 |
51 |
52 | private WindowManager.LayoutParams mWindowLayoutParams; // Window Manager Params
53 | private int initX, initY;
54 | private int initTouchX, initTouchY;
55 | private int mScreenWidth;
56 | private int mScreenHeight;
57 |
58 | private Runnable mRunnable = this::invalidate;
59 |
60 | public SnowView(Context context) {
61 | super(context);
62 | init(context);
63 | }
64 |
65 | public SnowView(Context context, AttributeSet attrs) {
66 | super(context, attrs);
67 | init(context);
68 | }
69 |
70 | private void init(Context context) {
71 | mContext = context;
72 | Random random = new Random();
73 |
74 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
75 | paint.setColor(Color.WHITE);
76 | paint.setStyle(Paint.Style.FILL);
77 |
78 | mSnowFlakes = new SnowFlake[NUM_SNOWFLAKES];
79 | for (int i = 0; i < NUM_SNOWFLAKES; i++) {
80 | Point position = new Point(random.nextInt(CANVAS_WIDTH), random.nextInt(CANVAS_HEIGHT));
81 | mSnowFlakes[i] = new SnowFlake(position, paint, CANVAS_WIDTH, CANVAS_HEIGHT);
82 | }
83 | }
84 |
85 |
86 | @Override
87 | protected void onDraw(Canvas canvas) {
88 | for (SnowFlake snowFlake : mSnowFlakes) {
89 | snowFlake.draw(canvas);
90 | }
91 | getHandler().postDelayed(mRunnable, DELAY);
92 |
93 | }
94 |
95 | public void addToWindowManager() {
96 | mWindowLayoutParams = new WindowManager.LayoutParams(
97 | CANVAS_WIDTH,
98 | CANVAS_HEIGHT,
99 | WindowManager.LayoutParams.TYPE_PHONE,
100 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
101 | PixelFormat.TRANSLUCENT);
102 | mWindowLayoutParams.gravity = Gravity.LEFT;
103 |
104 | mFrameLayout = new FrameLayout(mContext);
105 | mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
106 |
107 | // set screen width and height variables
108 | mScreenHeight = Utils.getScreenHeight(mWindowManager);
109 | mScreenWidth = Utils.getScreenWidth(mWindowManager);
110 |
111 |
112 | mWindowManager.addView(mFrameLayout, mWindowLayoutParams);
113 |
114 | LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
115 |
116 | // Here is the place where you can inject whatever layout you want.
117 | layoutInflater.inflate(R.layout.overlay, mFrameLayout);
118 |
119 | addSpringSystem();
120 | springForXAxis();
121 | springForYAxis();
122 |
123 | mFrameLayout.setOnTouchListener(this);
124 | }
125 |
126 |
127 | @Override
128 | public boolean onTouch(View view, MotionEvent motionEvent) {
129 | int x = (int) motionEvent.getRawX();
130 | int y = (int) motionEvent.getRawY();
131 |
132 | switch (motionEvent.getAction()) {
133 | case MotionEvent.ACTION_DOWN:
134 | initX = mWindowLayoutParams.x;
135 | initY = mWindowLayoutParams.y;
136 | initTouchX = x;
137 | initTouchY = y;
138 | mSpring.setEndValue(1);
139 | return true;
140 |
141 | case MotionEvent.ACTION_UP:
142 | mSpring.setEndValue(0);
143 | return true;
144 |
145 | case MotionEvent.ACTION_MOVE:
146 | mWindowLayoutParams.x = initX + (x - initTouchX);
147 | mWindowLayoutParams.y = initY + (y - initTouchY);
148 |
149 | if (x > mScreenWidth / 2) {
150 | mWindowLayoutParams.x = mScreenWidth - CANVAS_WIDTH;
151 | } else {
152 | mWindowLayoutParams.x = 0;
153 | }
154 | mSpringForFrameXPosition.setEndValue(mWindowLayoutParams.x);
155 | mSpringForFrameYPosition.setEndValue(mWindowLayoutParams.y);
156 |
157 | // Invalidate layout
158 | // mWindowManager.updateViewLayout(mFrameLayout, mWindowLayoutParams);
159 | return true;
160 | }
161 | return false;
162 | }
163 |
164 | private void addSpringSystem() {
165 | SpringSystem springSystem = SpringSystem.create();
166 | mSpring = springSystem.createSpring();
167 |
168 | mSpring.addListener(new SimpleSpringListener() {
169 | @Override
170 | public void onSpringUpdate(Spring spring) {
171 | float value = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 0.5);
172 | mFrameLayout.setScaleX(value);
173 | mFrameLayout.setScaleY(value);
174 | }
175 | });
176 | }
177 |
178 | private void springForXAxis() {
179 | SpringSystem springSystem = SpringSystem.create();
180 | mSpringForFrameXPosition = springSystem.createSpring();
181 |
182 | SpringConfig config = new SpringConfig(TENSION, DAMPER);
183 | mSpringForFrameXPosition.setSpringConfig(config);
184 |
185 | mSpringForFrameXPosition.addListener(new SimpleSpringListener() {
186 | @Override
187 | public void onSpringUpdate(Spring spring) {
188 | float value = (float) spring.getCurrentValue();
189 | mWindowLayoutParams.x = (int) value;
190 | mWindowManager.updateViewLayout(mFrameLayout, mWindowLayoutParams);
191 | }
192 | });
193 | }
194 |
195 | private void springForYAxis() {
196 | SpringSystem springSystem = SpringSystem.create();
197 | mSpringForFrameYPosition = springSystem.createSpring();
198 |
199 | SpringConfig config = new SpringConfig(TENSION, DAMPER);
200 | mSpringForFrameYPosition.setSpringConfig(config);
201 |
202 | mSpringForFrameYPosition.addListener(new SimpleSpringListener() {
203 | @Override
204 | public void onSpringUpdate(Spring spring) {
205 | float value = (float) spring.getCurrentValue();
206 | mWindowLayoutParams.y = (int) value;
207 | mWindowManager.updateViewLayout(mFrameLayout, mWindowLayoutParams);
208 | }
209 | });
210 | }
211 |
212 |
213 | /**
214 | * Removes the view from window manager.
215 | */
216 | public void destroy() {
217 | mWindowManager.removeView(mFrameLayout);
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/app/src/main/java/me/tatocaster/snowview/Utils.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.app.ActivityManager;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.net.Uri;
9 | import android.os.Build;
10 | import android.provider.Settings;
11 | import android.support.v4.app.Fragment;
12 | import android.util.DisplayMetrics;
13 | import android.view.WindowManager;
14 |
15 | /**
16 | * Created by tatocaster on 1/2/17.
17 | */
18 |
19 | public class Utils {
20 |
21 | /**
22 | * @param context
23 | * @param fragment
24 | * @param requestCode
25 | */
26 | public static void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) {
27 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
28 | return;
29 | final String packageName = context == null ? fragment.getActivity().getPackageName() : context.getPackageName();
30 | final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));
31 | if (fragment != null)
32 | fragment.startActivityForResult(intent, requestCode);
33 | else
34 | context.startActivityForResult(intent, requestCode);
35 | }
36 |
37 | /**
38 | * @param context
39 | * @return
40 | */
41 | @TargetApi(Build.VERSION_CODES.M)
42 | public static boolean isSystemAlertPermissionGranted(Context context) {
43 | return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(context);
44 | }
45 |
46 | /**
47 | * @param context
48 | * @param serviceClass
49 | * @return
50 | */
51 | public static boolean isSnowOverlayingServiceIsRunning(Context context, Class> serviceClass) {
52 | ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
53 | for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
54 | if (serviceClass.getName().equals(service.service.getClassName())) {
55 | return true;
56 | }
57 | }
58 | return false;
59 | }
60 |
61 | /**
62 | * @param windowManager
63 | * @return
64 | */
65 | public static int getScreenWidth(WindowManager windowManager) {
66 | return getScreenMetrics(windowManager).widthPixels;
67 | }
68 |
69 | /**
70 | * @param windowManager
71 | * @return
72 | */
73 | public static int getScreenHeight(WindowManager windowManager) {
74 | return getScreenMetrics(windowManager).heightPixels;
75 | }
76 |
77 | /**
78 | * @param windowManager
79 | * @return
80 | */
81 | private static DisplayMetrics getScreenMetrics(WindowManager windowManager) {
82 | DisplayMetrics displaymetrics = new DisplayMetrics();
83 | windowManager.getDefaultDisplay().getMetrics(displaymetrics);
84 | return displaymetrics;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/me/tatocaster/snowview/services/OverlayService.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview.services;
2 |
3 |
4 | import android.app.Notification;
5 | import android.app.PendingIntent;
6 | import android.app.Service;
7 | import android.content.Intent;
8 | import android.os.IBinder;
9 | import android.support.annotation.Nullable;
10 | import android.widget.Toast;
11 |
12 | import me.tatocaster.snowview.MainActivity;
13 | import me.tatocaster.snowview.R;
14 | import me.tatocaster.snowview.SnowView.SnowView;
15 |
16 | /**
17 | * Created by tatocaster on 1/1/17.
18 | */
19 |
20 | public class OverlayService extends Service {
21 | private static final String TAG = "OverlayService";
22 | private static final int FOREGROUND_ID = 9998;
23 | private SnowView mSnowView;
24 |
25 | @Nullable
26 | @Override
27 | public IBinder onBind(Intent intent) {
28 | return null;
29 | }
30 |
31 | @Override
32 | public int onStartCommand(Intent intent, int flags, int startId) {
33 | Toast.makeText(this, "ServiceStarted", Toast.LENGTH_SHORT).show();
34 |
35 | mSnowView = new SnowView(this);
36 | mSnowView.addToWindowManager();
37 |
38 | // this needs to be here, because without the startForeground(), our view will not retain always
39 | startForeground(FOREGROUND_ID, createNotification());
40 |
41 | return START_STICKY;
42 | }
43 |
44 | @Override
45 | public void onDestroy() {
46 | Toast.makeText(this, "ServiceEnded", Toast.LENGTH_SHORT).show();
47 | mSnowView.destroy();
48 | super.onDestroy();
49 | }
50 |
51 |
52 | private Notification createNotification() {
53 |
54 | Intent intent = new Intent(this, MainActivity.class);
55 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
56 |
57 | return new Notification.Builder(this)
58 | .setContentTitle("Persistent Snow View")
59 | .setContentText("Content Text")
60 | .setSmallIcon(R.mipmap.ic_launcher)
61 | .setContentIntent(pendingIntent)
62 | .build();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rounded_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/overlay.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
16 |
17 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SnowView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/me/tatocaster/snowview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.tatocaster.snowview;
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 | }
--------------------------------------------------------------------------------
/art/all.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/art/all.gif
--------------------------------------------------------------------------------
/art/wiggle.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tatocaster/SnowViewChatHead/65b1569e19f25cacb61854dee9d84795dd3e706e/art/wiggle.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0-beta1'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
25 |
26 | ext {
27 | minSdkVersion = 16
28 | targetSdkVersion = 25
29 | compileSdkVersion = 25
30 | buildToolsVersion = '25.0.1'
31 | versionCode = 1
32 | versionName = '1.0'
33 |
34 | supportLibsVersion = '25.1.0'
35 | }
36 |
37 | ext.libraries = [
38 | supportV7 : 'com.android.support:appcompat-v7:' + supportLibsVersion,
39 | supportDesign : 'com.android.support:design:' + supportLibsVersion,
40 |
41 | rxJava : 'io.reactivex:rxandroid:1.2.1',
42 | rxAndroid : 'io.reactivex:rxjava:1.1.6',
43 |
44 | facebookRebound: 'com.facebook.rebound:rebound:0.3.8',
45 |
46 | jUnit : 'junit:junit:4.12',
47 | ]
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jan 02 17:08:24 GET 2017
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-3.2-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | #SnowViewChatHead
2 |
3 | Facebook Chat head like custom view with snow.
4 |
5 | - control over snowflake quantity
6 | - speed
7 | - wind direction
8 |
9 | **This is not a library yet, just a showcase**
10 |
11 | uses notification to stay on foreground.
12 |
13 | uses Facebook Spring Dynamics library [Rebound](http://facebook.github.io/rebound/) for X and Y points of system view.
14 |
15 |
16 | ***features***
17 | - control spring tension
18 | - control spring friction
19 | - wiggle effect on touch
20 |
21 | 
22 |
23 | 
24 |
25 |
26 | ### No Tests :|
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------