├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── .DS_Store
│ │ ├── raw
│ │ │ ├── hzk16k
│ │ │ ├── hzk16s
│ │ │ ├── click_0.mp3
│ │ │ ├── click_1.mp3
│ │ │ └── click_2.mp3
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── styles.xml
│ │ │ └── attrs.xml
│ │ ├── mipmap-xxhdpi
│ │ │ ├── dot.png
│ │ │ ├── chicken.png
│ │ │ ├── dot_back.png
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── reikyz
│ │ └── flipdot
│ │ ├── utils
│ │ ├── BitmapUtils.java
│ │ └── FontUtils.java
│ │ ├── MainActivity.java
│ │ └── view
│ │ └── FlipDotView.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .DS_Store
├── 2016-09-01_17_43_11.gif
├── README.md
├── .gitignore
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/.DS_Store
--------------------------------------------------------------------------------
/2016-09-01_17_43_11.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/2016-09-01_17_43_11.gif
--------------------------------------------------------------------------------
/app/src/main/res/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/.DS_Store
--------------------------------------------------------------------------------
/app/src/main/res/raw/hzk16k:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/raw/hzk16k
--------------------------------------------------------------------------------
/app/src/main/res/raw/hzk16s:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/raw/hzk16s
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FlipDot
2 | intro
3 | http://www.jianshu.com/p/4fcbb593f427
4 |
5 | 
6 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/click_0.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/raw/click_0.mp3
--------------------------------------------------------------------------------
/app/src/main/res/raw/click_1.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/raw/click_1.mp3
--------------------------------------------------------------------------------
/app/src/main/res/raw/click_2.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/raw/click_2.mp3
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FlipDot
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/dot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xxhdpi/dot.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/chicken.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xxhdpi/chicken.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/dot_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xxhdpi/dot_back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ReikyZ/FlipDot/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 |
7 | defaultConfig {
8 | applicationId "com.reikyz.flipdot"
9 | minSdkVersion 15
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
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 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:24.1.0'
26 | }
27 |
--------------------------------------------------------------------------------
/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/reikyZ/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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/workspace.xml
40 |
41 | # Keystore files
42 | *.jks
43 |
44 | /app/build/
45 | /app/src/androidTest/
46 | /app/src/test/
47 | /gradle/
48 | /.idea/
49 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
27 |
28 |
32 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/reikyz/flipdot/utils/BitmapUtils.java:
--------------------------------------------------------------------------------
1 | package com.reikyz.flipdot.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Matrix;
7 |
8 | import java.io.InputStream;
9 |
10 | /**
11 | * Created by reikyZ on 16/9/1.
12 | */
13 | public class BitmapUtils {
14 |
15 |
16 | public static Bitmap zoomImage(Bitmap bgimage, double newWidth,
17 | double newHeight) {
18 | float width = bgimage.getWidth();
19 | float height = bgimage.getHeight();
20 | Matrix matrix = new Matrix();
21 | float scaleWidth = ((float) newWidth) / width;
22 | float scaleHeight = ((float) newHeight) / height;
23 | matrix.postScale(scaleWidth, scaleHeight);
24 | Bitmap bitmap = Bitmap.createBitmap(bgimage, 0, 0, (int) width,
25 | (int) height, matrix, true);
26 | return bitmap;
27 | }
28 |
29 |
30 | public static Bitmap readBitMap(Context context, int resId) {
31 | BitmapFactory.Options opt = new BitmapFactory.Options();
32 | opt.inPreferredConfig = Bitmap.Config.RGB_565;
33 | opt.inPurgeable = true;
34 | opt.inInputShareable = true;
35 | InputStream is = context.getResources().openRawResource(resId);
36 | return BitmapFactory.decodeStream(is, null, opt);
37 | }
38 |
39 | public static boolean[][] getBitmapArr(Bitmap bitmap, boolean[][] arr, int width, int height) {
40 |
41 | int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];//保存所有的像素的数组,图片宽×高
42 | bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
43 | int len = pixels.length;
44 | arr = new boolean[height][width];
45 | for (int i = 0; i < len; i++) {
46 | int clr = pixels[i];
47 | int red = (clr & 0x00ff0000) >> 16; //取高两位
48 | int green = (clr & 0x0000ff00) >> 8; //取中两位
49 | int blue = clr & 0x000000ff; //取低两位
50 |
51 | if (pixels[i] != 0)
52 | arr[i / width][i % width] = true;
53 | else
54 | arr[i / width][i % width] = false;
55 | }
56 | return arr;
57 |
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/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/com/reikyz/flipdot/utils/FontUtils.java:
--------------------------------------------------------------------------------
1 | package com.reikyz.flipdot.utils;
2 |
3 | import android.content.Context;
4 |
5 | import com.reikyz.flipdot.R;
6 |
7 | import java.io.InputStream;
8 |
9 | /**
10 | * Created by reikyZ on 16/8/31.
11 | */
12 | public class FontUtils {
13 |
14 |
15 | boolean[][] arr;
16 | int all_16_32 = 16;
17 | int all_2_4 = 2;
18 | int all_32_128 = 32;
19 |
20 | public boolean[][] drawString(Context context, String str) {
21 | byte[] data = null;
22 | int[] code = null;
23 | int byteCount;
24 | int lCount;
25 | arr = new boolean[all_16_32][all_16_32];
26 | for (int i = 0; i < str.length(); i++) {
27 | if (str.charAt(i) < 0x80) {
28 | continue;
29 | }
30 | code = getByteCode(str.substring(i, i + 1));
31 | data = read(context, code[0], code[1]);
32 | byteCount = 0;
33 | for (int line = 0; line < all_16_32; line++) {
34 | lCount = 0;
35 | for (int k = 0; k < all_2_4; k++) {
36 | for (int j = 0; j < 8; j++) {
37 | if (((data[byteCount] >> (7 - j)) & 0x1) == 1) {
38 | arr[line][lCount] = true;
39 | System.out.print("*");
40 | } else {
41 | System.out.print(" ");
42 | arr[line][lCount] = false;
43 | }
44 | lCount++;
45 | }
46 | byteCount++;
47 | }
48 | System.out.println();
49 | }
50 | }
51 | return arr;
52 | }
53 |
54 | protected byte[] read(Context context, int areaCode, int posCode) {
55 | byte[] data = null;
56 | try {
57 | int area = areaCode - 0xa0;
58 | int pos = posCode - 0xa0;
59 | InputStream in = context.getResources().openRawResource(R.raw.hzk16k);
60 | long offset = all_32_128 * ((area - 1) * 94 + pos - 1);
61 | in.skip(offset);
62 | data = new byte[all_32_128];
63 | in.read(data, 0, all_32_128);
64 | in.close();
65 | } catch (Exception ex) {
66 | System.err.println("SORRY,THE FILE CAN'T BE READ");
67 | }
68 | return data;
69 |
70 | }
71 |
72 | protected int[] getByteCode(String str) {
73 | int[] byteCode = new int[2];
74 | try {
75 | byte[] data = str.getBytes("GB2312");
76 | byteCode[0] = data[0] < 0 ? 256 + data[0] : data[0];
77 | byteCode[1] = data[1] < 0 ? 256 + data[1] : data[1];
78 | } catch (Exception ex) {
79 | ex.printStackTrace();
80 | }
81 | return byteCode;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/reikyz/flipdot/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.reikyz.flipdot;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.ActionBar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.ImageView;
10 | import android.widget.Toast;
11 |
12 | import com.reikyz.flipdot.utils.BitmapUtils;
13 | import com.reikyz.flipdot.utils.FontUtils;
14 | import com.reikyz.flipdot.view.FlipDotView;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 |
20 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
21 |
22 | FlipDotView fdv;
23 | ImageView iv;
24 | Button btn;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | ActionBar actionBar = getSupportActionBar();
32 | actionBar.hide();
33 |
34 | intiData();
35 |
36 | fdv = (FlipDotView) findViewById(R.id.fdv);
37 | iv = (ImageView) findViewById(R.id.iv);
38 | btn = (Button) findViewById(R.id.btn);
39 |
40 | fdv.setOnClickListener(this);
41 | iv.setOnClickListener(this);
42 | btn.setOnClickListener(this);
43 |
44 | }
45 |
46 |
47 | FontUtils font;
48 | String[] strs = {"年", "轻", "天", "真"};
49 |
50 | boolean[][] arr;
51 | boolean[][] arrStr;
52 | int offset = 0;
53 |
54 | private void intiData() {
55 | font = new FontUtils();
56 | arrStr = font.drawString(this, "哈");
57 | }
58 |
59 |
60 | @Override
61 | public void onClick(View view) {
62 | switch (view.getId()) {
63 | case R.id.fdv:
64 | Toast.makeText(this, "show Pattern", Toast.LENGTH_LONG).show();
65 | fdv.flipFromLeftTop(getPattern());
66 | offset++;
67 | break;
68 | case R.id.iv:
69 | Toast.makeText(this, "show Bitmap", Toast.LENGTH_LONG).show();
70 | flip(R.mipmap.chicken);
71 | break;
72 | case R.id.btn:
73 | Toast.makeText(this, "show Character", Toast.LENGTH_LONG).show();
74 | showChar();
75 | break;
76 | }
77 | }
78 |
79 | private List> getPattern() {
80 | List> list = new ArrayList<>();
81 |
82 | for (int i = 0; i < fdv.getmHeightNum(); i++) {
83 | List l = new ArrayList<>();
84 | l.clear();
85 | for (int j = 0; j < fdv.getmWidthNum(); j++) {
86 | if ((i + j + 1 + offset) % 3 == 0) {
87 | l.add(1);
88 | } else {
89 | l.add(0);
90 | }
91 | }
92 | list.add(l);
93 | }
94 | return list;
95 | }
96 |
97 |
98 | private void flip(int rsid) {
99 | int width = fdv.getmWidthNum();
100 | int height = fdv.getmHeightNum();
101 | Bitmap bitmap = BitmapUtils.zoomImage(BitmapUtils.readBitMap(this, rsid), width, height);
102 |
103 | arr = BitmapUtils.getBitmapArr(bitmap, arr, width, height);
104 | fdv.flipFromCenter(getBitmap(arr));
105 | }
106 |
107 | private List> getBitmap(boolean[][] array) {
108 | List> list = new ArrayList<>();
109 | for (int i = 0; i < fdv.getmHeightNum(); i++) {
110 | List l = new ArrayList<>();
111 | l.clear();
112 | for (int j = 0; j < fdv.getmWidthNum(); j++) {
113 | if (i < array.length &&
114 | j < array[i].length &&
115 | array[i][j]) {
116 | l.add(1);
117 | } else {
118 | l.add(0);
119 | }
120 | }
121 | list.add(l);
122 | }
123 | return list;
124 | }
125 |
126 | private void showChar() {
127 | fdv.flipFromLeftTop(getCharMap(arrStr));
128 | arrStr = font.drawString(MainActivity.this, strs[offset % strs.length]);
129 | offset++;
130 | }
131 |
132 | private List> getCharMap(boolean[][] array) {
133 | List> list = new ArrayList<>();
134 |
135 | for (int i = 0; i < fdv.getmHeightNum(); i++) {
136 | List l = new ArrayList<>();
137 | l.clear();
138 | for (int j = 0; j < fdv.getmWidthNum(); j++) {
139 | if (i < array.length &&
140 | j < array[i].length &&
141 | array[i][j]) {
142 | l.add(1);
143 | } else {
144 | l.add(0);
145 | }
146 | }
147 | list.add(l);
148 | }
149 | return list;
150 | }
151 |
152 | }
153 |
--------------------------------------------------------------------------------
/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/com/reikyz/flipdot/view/FlipDotView.java:
--------------------------------------------------------------------------------
1 | package com.reikyz.flipdot.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Camera;
6 | import android.graphics.Matrix;
7 | import android.graphics.drawable.Drawable;
8 | import android.media.AudioManager;
9 | import android.media.SoundPool;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.animation.Animation;
13 | import android.view.animation.Transformation;
14 | import android.widget.ImageView;
15 | import android.widget.LinearLayout;
16 |
17 | import com.reikyz.flipdot.R;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Random;
23 |
24 | /**
25 | * Created by reikyZ on 16/8/31.
26 | */
27 | public class FlipDotView extends LinearLayout {
28 |
29 | Context mContext;
30 |
31 | private float mDotSize;
32 | private float mDotPadding;
33 | private int mWidthNum;
34 | private int mHeightNum;
35 | private Drawable mDot;
36 | private Drawable mDotBack;
37 | private boolean mSoundOn;
38 |
39 | int duration = 50;
40 |
41 | List> oldList = new ArrayList<>();
42 |
43 | SoundPool soundPool = new SoundPool(40, AudioManager.STREAM_MUSIC, 0);
44 | HashMap soundPoolMap = new HashMap();
45 |
46 | public FlipDotView(Context context, AttributeSet attrs) {
47 | super(context, attrs);
48 | setOrientation(LinearLayout.VERTICAL);
49 | mContext = context;
50 |
51 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FlipDot);
52 |
53 | mDotSize = typedArray.getDimensionPixelSize(R.styleable.FlipDot_dotSize, 50);
54 | mDotPadding = typedArray.getDimensionPixelSize(R.styleable.FlipDot_dotPadding, 5);
55 | mWidthNum = typedArray.getInteger(R.styleable.FlipDot_widthNum, 1);
56 | mHeightNum = typedArray.getInteger(R.styleable.FlipDot_heightNum, 1);
57 | mDot = typedArray.getDrawable(R.styleable.FlipDot_dotDrawable);
58 | mDotBack = typedArray.getDrawable(R.styleable.FlipDot_dotBackDrawable);
59 | mSoundOn = typedArray.getBoolean(R.styleable.FlipDot_soundOn, true);
60 |
61 | typedArray.recycle();
62 |
63 | initStauts();
64 | initViews(context, attrs);
65 | initSound();
66 | }
67 |
68 | private void initStauts() {
69 | oldList.clear();
70 | for (int i = 0; i < mHeightNum; i++) {
71 | List subList = new ArrayList<>();
72 | subList.clear();
73 | for (int j = 0; j < mWidthNum; j++) {
74 | subList.add(1);
75 | }
76 | oldList.add(subList);
77 | }
78 | }
79 |
80 | private void initViews(Context context, AttributeSet attrs) {
81 | for (int i = 0; i < mHeightNum; i++) {
82 | LinearLayout ll = new LinearLayout(context);
83 | LayoutParams llParam = new LayoutParams((int) (mWidthNum * mDotSize), (int) mDotSize);
84 | ll.setLayoutParams(llParam);
85 |
86 | for (int j = 0; j < mWidthNum; j++) {
87 | ImageView iv = new ImageView(context);
88 | LayoutParams ivParam = new LayoutParams(
89 | Math.round(mDotSize),
90 | Math.round(mDotSize));
91 | iv.setLayoutParams(ivParam);
92 | int padding = (int) mDotPadding;
93 | iv.setPadding(padding, padding, padding, padding);
94 | iv.setImageDrawable(mDot);
95 | ll.addView(iv);
96 | }
97 | addView(ll);
98 | }
99 | }
100 |
101 | private void initSound() {
102 | soundPoolMap.put(0, soundPool.load(mContext, R.raw.click_0, 1));
103 | soundPoolMap.put(1, soundPool.load(mContext, R.raw.click_1, 2));
104 | soundPoolMap.put(2, soundPool.load(mContext, R.raw.click_2, 3));
105 | }
106 |
107 | public void flipFromCenter(final List> list) {
108 | Random random = new Random();
109 |
110 | int centerX = (mHeightNum - 1) / 2, centerY = (mWidthNum - 1) / 2;
111 |
112 | for (int i = 0; i < mHeightNum; i++) {
113 | int delay = 0;
114 | for (int j = 0; j < list.get(i).size(); j++) {
115 | delay = distance(centerX, centerY, i, j) * 300 + duration * random.nextInt(5);
116 |
117 | final ImageView iv = (ImageView) ((LinearLayout) getChildAt(i)).getChildAt(j);
118 | final int finalI = i;
119 | final int finalJ = j;
120 | if (!oldList.get(i).get(j).equals(list.get(i).get(j))) {
121 |
122 | iv.postDelayed(new Runnable() {
123 | @Override
124 | public void run() {
125 |
126 | Rotate3d rotate = new Rotate3d();
127 | rotate.setDuration(200);
128 | rotate.setAngle(180);
129 | iv.startAnimation(rotate);
130 |
131 | if (list.get(finalI).get(finalJ) == 1) {
132 | iv.setImageDrawable(mDot);
133 | } else if (list.get(finalI).get(finalJ) == 0) {
134 | iv.setImageDrawable(mDotBack);
135 | } else {
136 | Log.e("sssss", "ERROR");
137 | }
138 | if (mSoundOn)
139 | new Thread(new Runnable() {
140 | @Override
141 | public void run() {
142 | playSound(mContext, finalJ % soundPoolMap.size(), 0);
143 | }
144 | }).start();
145 | }
146 | }, delay);
147 | oldList.get(i).set(j, list.get(i).get(j));
148 | }
149 | }
150 | }
151 | }
152 |
153 | public void flipFromLeftTop(final List> list) {
154 | Random random = new Random();
155 | int start = 0;
156 |
157 | for (int i = 0; i < list.size(); i++) {
158 | start += random.nextInt(5) * duration + 50;
159 | int delay = 0;
160 | for (int j = 0; j < list.get(i).size(); j++) {
161 | delay += random.nextInt(5) * duration + 50;
162 | final ImageView iv = (ImageView) ((LinearLayout) getChildAt(i)).getChildAt(j);
163 | final int finalI = i;
164 | final int finalJ = j;
165 | if (!oldList.get(i).get(j).equals(list.get(i).get(j))) {
166 |
167 | iv.postDelayed(new Runnable() {
168 | @Override
169 | public void run() {
170 |
171 | Rotate3d rotate = new Rotate3d();
172 | rotate.setDuration(200);
173 | rotate.setAngle(180);
174 | iv.startAnimation(rotate);
175 |
176 |
177 | if (list.get(finalI).get(finalJ) == 1) {
178 | iv.setImageDrawable(mDot);
179 | } else if (list.get(finalI).get(finalJ) == 0) {
180 | iv.setImageDrawable(mDotBack);
181 | } else {
182 | Log.e("sssss", "ERROR");
183 | }
184 | if (mSoundOn)
185 | new Thread(new Runnable() {
186 | @Override
187 | public void run() {
188 | playSound(mContext, finalJ % soundPoolMap.size(), 0);
189 | }
190 | }).start();
191 | }
192 | }, start + delay);
193 | oldList.get(i).set(j, list.get(i).get(j));
194 | }
195 | }
196 | }
197 | System.gc();
198 | }
199 |
200 | public void flip(final List> list) {
201 | Random random = new Random();
202 | for (int i = 0; i < list.size(); i++) {
203 | for (int j = 0; j < list.get(i).size(); j++) {
204 | final ImageView iv = (ImageView) ((LinearLayout) getChildAt(i)).getChildAt(j);
205 | final int finalI = i;
206 | final int finalJ = j;
207 | if (!oldList.get(i).get(j).equals(list.get(i).get(j))) {
208 |
209 | iv.postDelayed(new Runnable() {
210 | @Override
211 | public void run() {
212 |
213 | Rotate3d rotate = new Rotate3d();
214 | rotate.setDuration(200);
215 | rotate.setAngle(180);
216 | iv.startAnimation(rotate);
217 |
218 |
219 | if (list.get(finalI).get(finalJ) == 1) {
220 | iv.setImageDrawable(mDot);
221 | } else if (list.get(finalI).get(finalJ) == 0) {
222 | iv.setImageDrawable(mDotBack);
223 | } else {
224 | Log.e("sssss", "ERROR");
225 | }
226 | if (mSoundOn)
227 | new Thread(new Runnable() {
228 | @Override
229 | public void run() {
230 | playSound(mContext, finalJ % soundPoolMap.size(), 0);
231 | }
232 | }).start();
233 | }
234 | }, random.nextInt(20) * duration);
235 | oldList.get(i).set(j, list.get(i).get(j));
236 | }
237 | }
238 | }
239 | System.gc();
240 | }
241 |
242 |
243 | private void playSound(Context mContext, int sound, int loop) {
244 | AudioManager mgr = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
245 | float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
246 | float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
247 | float volume = streamVolumeCurrent / streamVolumeMax;
248 | soundPool.play(soundPoolMap.get(sound), volume, volume, 1, loop, 1f);
249 | }
250 |
251 | public int getmWidthNum() {
252 | return mWidthNum;
253 | }
254 |
255 | public int getmHeightNum() {
256 | return mHeightNum;
257 | }
258 |
259 | public boolean ismSoundOn() {
260 | return mSoundOn;
261 | }
262 |
263 | public void setmSoundOn(boolean mSoundOn) {
264 | this.mSoundOn = mSoundOn;
265 | }
266 |
267 | private int distance(int x1, int y1, int x2, int y2) {
268 | int dis = (int) (Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)));
269 | return dis;
270 | }
271 |
272 | class Rotate3d extends Animation {
273 |
274 | int mAngle = 90;
275 |
276 | public void setAngle(int angle) {
277 | mAngle = angle;
278 | }
279 |
280 | @Override
281 | protected void applyTransformation(float interpolatedTime, Transformation t) {
282 | Matrix matrix = t.getMatrix();
283 | Camera camera = new Camera();
284 | camera.save();
285 | camera.rotateY(180 * interpolatedTime);
286 | camera.getMatrix(matrix);
287 | camera.restore();
288 | }
289 | }
290 | }
291 |
--------------------------------------------------------------------------------