├── app
├── .gitignore
├── libs
│ └── jsoup-1.10.3.jar
├── src
│ ├── main
│ │ ├── assets
│ │ │ ├── ASC16
│ │ │ ├── HZK16
│ │ │ └── test.lrc
│ │ ├── res
│ │ │ ├── raw
│ │ │ │ └── czt.mp3
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── bcd.jpg
│ │ │ │ ├── back.png
│ │ │ │ ├── bcd2.jpg
│ │ │ │ ├── bubble.png
│ │ │ │ ├── compass.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── lcd1602bac.jpg
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── simple_player_center_pause.png
│ │ │ │ └── simple_player_center_play.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── attrs.xml
│ │ │ ├── xml
│ │ │ │ └── backup_descriptor.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_level.xml
│ │ │ │ ├── activity_compass.xml
│ │ │ │ ├── activity_rotationled.xml
│ │ │ │ ├── activity_time.xml
│ │ │ │ ├── activity_weather.xml
│ │ │ │ ├── listitem.xml
│ │ │ │ ├── activity_datetime.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_lrc.xml
│ │ │ │ ├── activity_sms.xml
│ │ │ │ └── activity_lcd1602.xml
│ │ │ └── layout-hdpi
│ │ │ │ ├── activity_bcd.xml
│ │ │ │ ├── activity_7400.xml
│ │ │ │ ├── activity_74138.xml
│ │ │ │ └── activity_74151.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── supets
│ │ │ │ └── pet
│ │ │ │ ├── lcd
│ │ │ │ ├── ZiMo.java
│ │ │ │ ├── RGB.java
│ │ │ │ ├── ILCD.java
│ │ │ │ ├── LCD1602.java
│ │ │ │ ├── ZiMoUtuls.java
│ │ │ │ └── LCD1602A.java
│ │ │ │ ├── module
│ │ │ │ ├── ttl
│ │ │ │ │ ├── D74.java
│ │ │ │ │ ├── D74151.java
│ │ │ │ │ ├── D74138.java
│ │ │ │ │ ├── D7400.java
│ │ │ │ │ ├── D74Adapter.java
│ │ │ │ │ ├── D7400Activity.java
│ │ │ │ │ ├── D74107.java
│ │ │ │ │ ├── D74151Activity.java
│ │ │ │ │ ├── D74Activity.java
│ │ │ │ │ └── D74138Activity.java
│ │ │ │ ├── led
│ │ │ │ │ ├── DateTimeActivity.java
│ │ │ │ │ ├── WeatherInfoActivity.java
│ │ │ │ │ ├── MainAdapter.java
│ │ │ │ │ ├── TimeActivity.java
│ │ │ │ │ ├── BusActivity.java
│ │ │ │ │ ├── LCD1602Activity.java
│ │ │ │ │ └── SmsActivity.java
│ │ │ │ ├── sensor
│ │ │ │ │ ├── CompassActivity.java
│ │ │ │ │ ├── BaseShakeActivity.java
│ │ │ │ │ ├── BaseOrientationActivity.java
│ │ │ │ │ ├── RotationLedActivity.java
│ │ │ │ │ ├── BaseSmsActivity.java
│ │ │ │ │ ├── LightActivity.java
│ │ │ │ │ └── LevelVialActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── lrc
│ │ │ │ ├── LyricContent.java
│ │ │ │ ├── MusicBox.java
│ │ │ │ ├── LrcRead.java
│ │ │ │ └── LrcMainActivity.java
│ │ │ │ ├── sensor
│ │ │ │ ├── ledPref.java
│ │ │ │ ├── BasePref.java
│ │ │ │ ├── LevelVialView.java
│ │ │ │ └── ShakeEngine.java
│ │ │ │ ├── MyApplication.java
│ │ │ │ ├── bcd
│ │ │ │ ├── GraphicesActivity.java
│ │ │ │ ├── BCD.java
│ │ │ │ ├── MyView.java
│ │ │ │ └── MyView2.java
│ │ │ │ ├── bus
│ │ │ │ ├── BusInfo.java
│ │ │ │ └── BusUtils.java
│ │ │ │ ├── view
│ │ │ │ ├── WakeScreenUtils.java
│ │ │ │ ├── DateLedTextView.java
│ │ │ │ ├── ChatUtils.java
│ │ │ │ └── LedTextView.java
│ │ │ │ ├── weather
│ │ │ │ ├── WeatherInfo.java
│ │ │ │ └── WeatherApi.java
│ │ │ │ ├── sms
│ │ │ │ └── SmsRecerver.java
│ │ │ │ └── utils
│ │ │ │ └── JSonUtil.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── supets
│ │ │ └── pet
│ │ │ └── ledview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── supets
│ │ └── pet
│ │ └── ledview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── doc
├── 1.png
├── 2.gif
├── czt.mp3
├── doc.rar
├── 字库+代码.zip
└── TestAscii.zip
├── .idea
├── caches
│ ├── gradle_models.ser
│ └── build_file_checksums.ser
├── encodings.xml
├── vcs.xml
├── compiler.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
└── misc.xml
├── 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 |
--------------------------------------------------------------------------------
/doc/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/1.png
--------------------------------------------------------------------------------
/doc/2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/2.gif
--------------------------------------------------------------------------------
/doc/czt.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/czt.mp3
--------------------------------------------------------------------------------
/doc/doc.rar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/doc.rar
--------------------------------------------------------------------------------
/doc/字库+代码.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/字库+代码.zip
--------------------------------------------------------------------------------
/doc/TestAscii.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/doc/TestAscii.zip
--------------------------------------------------------------------------------
/app/libs/jsoup-1.10.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/libs/jsoup-1.10.3.jar
--------------------------------------------------------------------------------
/app/src/main/assets/ASC16:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/assets/ASC16
--------------------------------------------------------------------------------
/app/src/main/assets/HZK16:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/assets/HZK16
--------------------------------------------------------------------------------
/app/src/main/res/raw/czt.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/raw/czt.mp3
--------------------------------------------------------------------------------
/.idea/caches/gradle_models.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/.idea/caches/gradle_models.ser
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bcd.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/bcd.jpg
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bcd2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/bcd2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/bubble.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/bubble.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/compass.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/compass.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/lcd1602bac.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/lcd1602bac.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/simple_player_center_pause.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/simple_player_center_pause.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/simple_player_center_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/supets-open/LedView/HEAD/app/src/main/res/mipmap-hdpi/simple_player_center_play.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/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LedView
2 | LED点阵屏显示,示例,短消息提示插件
3 |
4 | # 演示
5 | 
6 | 
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/ZiMo.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 | public class ZiMo {
4 | public RGB[][] pdata;
5 |
6 | public ZiMo(RGB[][] data) {
7 | this.pdata = data;
8 | }
9 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #b9bda6
4 | #423e55
5 | #ff0000
6 |
7 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Aug 18 13:24:12 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http://localhost:8082/nexus/content/groups/public/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/RGB.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 | public class RGB{
4 | public int color;
5 | public boolean light;
6 |
7 | public RGB(int color, boolean light) {
8 | this.color = color;
9 | this.light = light;
10 | }
11 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 点阵时钟
3 |
4 | 圆形
5 | 正方形
6 | 长方形
7 | 椭圆形
8 | 三角形
9 | 梯形
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | public class D74 {
4 |
5 | public int type = 0;
6 |
7 | public String name;
8 |
9 | public String function;
10 |
11 | public D74(int type, String name, String function) {
12 | this.type = type;
13 | this.name = name;
14 | this.function = function;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return name+" "+function;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_level.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/supets/pet/ledview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.ledview;
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/src/main/res/layout/activity_compass.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/ILCD.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 | /**
4 | * LedView
5 | *
6 | * @user lihongjiang
7 | * @description
8 | * @date 2017/8/30
9 | * @updatetime 2017/8/30
10 | */
11 |
12 | public interface ILCD {
13 |
14 | void closeScreen();
15 | void openScreen();
16 |
17 | void moveRam(int leftOrRight);
18 | void clearRam();
19 |
20 | void writeCGROM(int x,int y,char str );
21 | void writeDDROM(int x,int y,char str );
22 | void setDramLength(int length);
23 | void setcgramLength(int length);
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lrc/LyricContent.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lrc;
2 |
3 | public class LyricContent {
4 |
5 |
6 | private String mLyricContent;
7 | private int mLyricTime;
8 |
9 | public void setLyric(String lyricContent) {
10 | this.mLyricContent = lyricContent;
11 | }
12 |
13 | public String getLyricContent() {
14 | return mLyricContent;
15 | }
16 |
17 | public int getLyricTime() {
18 | return mLyricTime;
19 | }
20 |
21 | public void setLyricTime(int lyricTime) {
22 | this.mLyricTime = lyricTime;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-hdpi/activity_bcd.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_rotationled.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_time.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_weather.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_datetime.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/sensor/ledPref.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.sensor;
2 |
3 | import android.content.SharedPreferences;
4 | import android.content.SharedPreferences.Editor;
5 |
6 | public class ledPref extends BasePref {
7 |
8 | private static final String Name="weibo_config";
9 |
10 | private static final String LED_XUANZHUAN="LED_XUANZHUAN";
11 |
12 | public static int getTime() {
13 | SharedPreferences preferences = getPref(Name);
14 | return preferences.getInt(LED_XUANZHUAN, 10);
15 | }
16 |
17 | public static void saveTime(int time) {
18 | Editor editor = edit(Name);
19 | editor = editor.putInt(LED_XUANZHUAN, time);
20 | editor.commit();
21 | }
22 |
23 | public static void clear() {
24 | BasePref.clear(Name);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/MyApplication.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet;
2 |
3 | import android.app.Application;
4 |
5 | import com.zhy.http.okhttp.OkHttpUtils;
6 |
7 | import java.util.concurrent.TimeUnit;
8 |
9 | import okhttp3.OkHttpClient;
10 |
11 | public class MyApplication extends Application {
12 |
13 | public static MyApplication instance;
14 |
15 | @Override
16 | public void onCreate() {
17 | super.onCreate();
18 |
19 | instance=this;
20 |
21 | OkHttpClient okHttpClient = new OkHttpClient.Builder()
22 | .connectTimeout(10000L, TimeUnit.MILLISECONDS)
23 | .readTimeout(10000L, TimeUnit.MILLISECONDS)
24 | .build();
25 | OkHttpUtils.initClient(okHttpClient);
26 | }
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/sensor/BasePref.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.sensor;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.text.TextUtils;
6 |
7 | import com.supets.pet.MyApplication;
8 |
9 | class BasePref {
10 |
11 | protected static SharedPreferences getPref(String name) {
12 | if (TextUtils.isEmpty(name)) {
13 | throw new NullPointerException("Shared preferences name is null or empty");
14 | }
15 | return MyApplication.instance.getSharedPreferences(name, Context.MODE_PRIVATE);
16 | }
17 |
18 | protected static SharedPreferences.Editor edit(String name) {
19 | return getPref(name).edit();
20 | }
21 |
22 | public static void clear(String name) {
23 | edit(name).clear().commit();
24 | }
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/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/com/supets/pet/module/led/DateTimeActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.supets.pet.ledview.R;
7 | import com.supets.pet.view.DateLedTextView;
8 | import com.supets.pet.view.WakeScreenUtils;
9 |
10 | public class DateTimeActivity extends Activity {
11 |
12 |
13 | private DateLedTextView date_led;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | WakeScreenUtils.keepScreen(this);
19 | setContentView(R.layout.activity_datetime);
20 | date_led = findViewById(R.id.date_led);
21 | }
22 |
23 | @Override
24 | protected void onDestroy() {
25 | super.onDestroy();
26 | date_led.stopScroll();
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/supets/pet/ledview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.ledview;
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("com.supets.pet.ledview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
17 |
18 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74151.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * java实现----------数据选择器功能
8 | */
9 | public class D74151 {
10 |
11 | private boolean enable = false;
12 | private int channel = 0;
13 | private List output = new ArrayList<>();
14 |
15 | public void setChannel(int channel) {
16 | this.channel = channel;
17 | }
18 |
19 | public String getResult() {
20 | if (enable) {
21 | if (output != null && (output.size() > channel)) {
22 | return output.get(channel);
23 | }
24 | }
25 | return null;
26 | }
27 |
28 | public void setEnable(boolean enable) {
29 | this.enable = enable;
30 | }
31 |
32 | public void setInputData(int index, String data) {
33 | output.add(index, data);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/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 C:\studio\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/main/java/com/supets/pet/module/ttl/D74138.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * java实现----------译码器功能
8 | */
9 | public class D74138 {
10 |
11 | private boolean enable = false;
12 | private List output = new ArrayList<>();
13 |
14 | public void setEnable(boolean enable) {
15 | this.enable = enable;
16 | }
17 |
18 | public void setInput(int input) {
19 | if (enable) {
20 | if (output != null
21 | && (output.size() > input)
22 | && output.get(input) != null) {
23 | output.get(input).resultCallBack(input);
24 | }
25 | }
26 | }
27 |
28 |
29 | public void setOutPutResult(int index, OutputResultCallBack listener) {
30 | output.add(index, listener);
31 | }
32 |
33 | public void onDestroy() {
34 | output.clear();
35 | }
36 |
37 | public interface OutputResultCallBack {
38 | void resultCallBack(int input);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "com.supets.pet.ledview"
8 | minSdkVersion 16
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.6"
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:26.+'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 |
30 | compile 'com.zhy:okhttputils:2.6.2'
31 | compile 'com.google.code.gson:gson:2.8.1'
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bcd/GraphicesActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bcd;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 |
8 | import com.supets.pet.ledview.R;
9 |
10 | public class GraphicesActivity extends Activity {
11 |
12 | MyView2 lcd1602A;
13 | Handler handler;
14 |
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_bcd);
19 |
20 | lcd1602A = findViewById(R.id.lcd1602);
21 |
22 |
23 | handler = new Handler(new Handler.Callback() {
24 | @Override
25 | public boolean handleMessage(Message message) {
26 | lcd1602A.updateData();
27 | handler.sendEmptyMessageDelayed(0, 1000);
28 | return false;
29 | }
30 | });
31 | handler.sendEmptyMessageDelayed(0, 1000);
32 | }
33 |
34 | @Override
35 | protected void onDestroy() {
36 | super.onDestroy();
37 | handler.removeMessages(0);
38 | }
39 |
40 |
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bus/BusInfo.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bus;
2 |
3 | import java.security.PublicKey;
4 |
5 | /**
6 | * LedView
7 | *
8 | * @user lihongjiang
9 | * @description
10 | * @date 2017/8/23
11 | * @updatetime 2017/8/23
12 | */
13 |
14 | public class BusInfo {
15 |
16 | public String lineNumber;
17 | public String name;
18 | public boolean isStop;
19 |
20 | public BusInfo() {
21 | }
22 |
23 | public String getLineNumber() {
24 | return lineNumber;
25 | }
26 |
27 | public void setLineNumber(String lineNumber) {
28 | this.lineNumber = lineNumber;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public void setName(String name) {
36 | this.name = name;
37 | }
38 |
39 | public boolean isStop() {
40 | return isStop;
41 | }
42 |
43 | public void setStop(boolean stop) {
44 | isStop = stop;
45 | }
46 |
47 | public BusInfo(String lineNumber, String name, boolean isStop) {
48 | this.lineNumber = lineNumber;
49 | this.name = name;
50 | this.isStop = isStop;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/view/WakeScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.view;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.PowerManager;
6 | import android.provider.SyncStateContract;
7 | import android.view.WindowManager;
8 |
9 | /**
10 | * LedView
11 | *
12 | * @user lihongjiang
13 | * @description
14 | * @date 2017/8/21
15 | * @updatetime 2017/8/21
16 | */
17 |
18 | public class WakeScreenUtils {
19 |
20 |
21 | private PowerManager.WakeLock wakeLock;
22 |
23 | public void stop() {
24 | if (wakeLock != null) {
25 | wakeLock.release();
26 | wakeLock = null;
27 | }
28 | }
29 |
30 | //加权限:
31 | public void keep(Context mContext) {
32 | PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
33 | wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG");
34 | wakeLock.acquire();
35 | }
36 |
37 | public static void keepScreen(Activity activity){
38 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/sensor/LevelVialView.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.sensor;
2 |
3 | import android.content.Context;
4 | import android.content.pm.ProviderInfo;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import com.supets.pet.ledview.R;
12 |
13 | public class LevelVialView extends View {
14 | // 定义水平仪仪表盘图片
15 | public Bitmap back;
16 | // 定义水平仪中的气泡图标
17 | public Bitmap bubble;
18 | // 定义水平仪中气泡 的X、Y座标
19 | public int bubbleX, bubbleY;
20 |
21 | public LevelVialView(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | // 加载水平仪图片和气泡图片
24 | back = BitmapFactory.decodeResource(getResources(), R.mipmap.back);
25 | bubble = BitmapFactory
26 | .decodeResource(getResources(), R.mipmap.bubble);
27 | }
28 |
29 | @Override
30 | protected void onDraw(Canvas canvas) {
31 | super.onDraw(canvas);
32 | // 绘制水平仪表盘图片
33 | canvas.drawBitmap(back, 0, 0, null);
34 | // 根据气泡座标绘制气泡
35 | canvas.drawBitmap(bubble, bubbleX, bubbleY, null);
36 | }
37 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/CompassActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.animation.Animation;
6 | import android.view.animation.RotateAnimation;
7 | import android.widget.ImageView;
8 |
9 | import com.supets.pet.ledview.R;
10 |
11 | public class CompassActivity extends BaseOrientationActivity {
12 |
13 | private ImageView mImageView;
14 | private int predegree = 0;
15 |
16 | @Override
17 | public void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_compass);
20 | mImageView = findViewById(R.id.imageView);
21 | mImageView.setKeepScreenOn(true);//屏幕高亮
22 | }
23 |
24 | @Override
25 | protected void onOrientationDegree(int degreeX, int degreeY, int degreeZ) {
26 |
27 | RotateAnimation animation = new RotateAnimation(predegree, degreeX,
28 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
29 | animation.setDuration(200);
30 | mImageView.startAnimation(animation);
31 | predegree = -degreeX;
32 | Log.v("角度X:", "" + degreeX);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/WeatherInfoActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 |
6 | import com.supets.pet.ledview.R;
7 | import com.supets.pet.view.LedTextView;
8 | import com.supets.pet.view.WakeScreenUtils;
9 | import com.supets.pet.weather.WeatherApi;
10 | import com.supets.pet.weather.WeatherInfo;
11 |
12 |
13 | public class WeatherInfoActivity extends Activity {
14 |
15 |
16 | private LedTextView time_led;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | WakeScreenUtils.keepScreen(this);
22 | setContentView(R.layout.activity_weather);
23 |
24 | time_led = findViewById(R.id.time_led);
25 | time_led.startScroll();
26 | time_led.ForceupdateText("获取天气信息中...");
27 |
28 | WeatherApi.requestWeather("北京", new WeatherApi.WeatherCallBack() {
29 | @Override
30 | public void onSuccess(WeatherInfo info) {
31 | time_led.ForceupdateText(info.toString());
32 | }
33 |
34 | @Override
35 | public void onFaill() {
36 | time_led.ForceupdateText("-->获取失败!");
37 | }
38 | });
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/BaseShakeActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 |
7 | import com.supets.pet.sensor.ShakeEngine;
8 |
9 | /**
10 | * LedView
11 | *
12 | * @user lihongjiang
13 | * @description
14 | * @date 2017/8/23
15 | * @updatetime 2017/8/23
16 | */
17 |
18 | public class BaseShakeActivity extends Activity implements ShakeEngine.OnShakeListener {
19 |
20 | private ShakeEngine mShakeEngine;
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | initShakeEngine();
26 | }
27 |
28 | private void initShakeEngine() {
29 | mShakeEngine = new ShakeEngine(this);
30 | mShakeEngine.setOnShakeListener(this);
31 | }
32 |
33 |
34 | @Override
35 | protected void onResume() {
36 | super.onResume();
37 | mShakeEngine.setEnable(true);
38 | mShakeEngine.startSensor(this);
39 | }
40 |
41 | @Override
42 | protected void onPause() {
43 | super.onPause();
44 | mShakeEngine.setEnable(false);
45 | mShakeEngine.stopSensor();
46 | }
47 |
48 | @Override
49 | public void onShake() {
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D7400.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.os.Handler;
4 |
5 | /**
6 | * java实现----------与非门
7 | */
8 | public class D7400 implements Runnable {
9 |
10 | private Handler handler = new Handler();
11 | private D7400CallBack mCallBack;
12 |
13 | public D7400(D7400CallBack mCallBack) {
14 | this.mCallBack = mCallBack;
15 | }
16 |
17 | public void seCallBack(D7400CallBack mCallBack) {
18 | this.mCallBack = mCallBack;
19 | }
20 |
21 | private boolean pinA;
22 | private boolean pinB;
23 |
24 | private boolean pinY;
25 |
26 | public void setPinA(boolean pinA) {
27 | this.pinA = pinA;
28 | andnon();
29 | }
30 |
31 | public void setPinB(boolean pinB) {
32 | this.pinB = pinB;
33 | andnon();
34 | }
35 |
36 | private void andnon() {
37 | pinY = !(pinA & pinB);
38 | handler.post(this);
39 | }
40 |
41 | @Override
42 | public void run() {
43 | if (mCallBack != null) {
44 | mCallBack.outputY(pinY);
45 | }
46 | }
47 |
48 | public boolean getPinA() {
49 | return pinA;
50 | }
51 |
52 | public boolean getPinB() {
53 | return pinB;
54 | }
55 |
56 | interface D7400CallBack {
57 | void outputY(boolean y);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/MainAdapter.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.TextView;
8 |
9 | import com.supets.pet.ledview.R;
10 |
11 | import java.util.ArrayList;
12 |
13 | public class MainAdapter extends BaseAdapter {
14 |
15 | private ArrayList data = new ArrayList<>();
16 |
17 | public void setData(ArrayList data) {
18 | if (data != null) {
19 | this.data.addAll(data);
20 | }
21 | }
22 |
23 | @Override
24 | public int getCount() {
25 | return data.size();
26 | }
27 |
28 | @Override
29 | public Object getItem(int position) {
30 | return data.get(position);
31 | }
32 |
33 | @Override
34 | public long getItemId(int position) {
35 | return position;
36 | }
37 |
38 | @Override
39 | public View getView(int position, View view, ViewGroup viewGroup) {
40 |
41 | if (view == null) {
42 | view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.listitem, viewGroup, false);
43 | }
44 |
45 | TextView name = view.findViewById(R.id.text);
46 | name.setText(position+1+" "+data.get(position));
47 | return view;
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74Adapter.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.TextView;
8 |
9 | import com.supets.pet.ledview.R;
10 |
11 | import java.util.ArrayList;
12 |
13 | public class D74Adapter extends BaseAdapter {
14 |
15 | private ArrayList data = new ArrayList<>();
16 |
17 | public void setData(ArrayList data) {
18 | if (data != null) {
19 | this.data.addAll(data);
20 | }
21 | }
22 |
23 | @Override
24 | public int getCount() {
25 | return data.size();
26 | }
27 |
28 | @Override
29 | public Object getItem(int position) {
30 | return data.get(position);
31 | }
32 |
33 | @Override
34 | public long getItemId(int position) {
35 | return position;
36 | }
37 |
38 | @Override
39 | public View getView(int position, View view, ViewGroup viewGroup) {
40 |
41 | if (view == null) {
42 | view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.listitem, viewGroup, false);
43 | }
44 |
45 | TextView name = view.findViewById(R.id.text);
46 | name.setText(position+1+" "+data.get(position).toString());
47 | return view;
48 | }
49 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/view/DateLedTextView.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.view;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 |
10 | public class DateLedTextView extends LedTextView {
11 |
12 | public DateLedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
13 | super(context, attrs, defStyleAttr);
14 | }
15 |
16 | public DateLedTextView(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | public DateLedTextView(Context context) {
21 | super(context);
22 | }
23 |
24 | public String changeContent() {
25 | Date currentTime = new Date();
26 | @SuppressLint("SimpleDateFormat") SimpleDateFormat formatter =
27 | new SimpleDateFormat(" yyyy年MM月dd日 EEEE ");
28 | this.text = formatter.format(currentTime);
29 | if (1 == scrollDirection) {
30 | text = reverseString(text);
31 | }
32 | return text;
33 | }
34 |
35 | @Override
36 | public void onScrollEnd() {
37 | long s = System.currentTimeMillis();
38 | updateCacheMatrix(ChatUtils.convert(changeContent(), getContext()));
39 | System.out.println("time:" + (System.currentTimeMillis() - s));
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/LCD1602.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 |
4 | /**
5 | * LCD1602 字符型显示器(
6 | *
7 | * @user lihongjiang
8 | * @description 2X16个字符,不能显示汉字
9 | * @date 2017/8/30
10 | * @updatetime 2017/8/30
11 | */
12 | public class LCD1602 implements ILCD {
13 |
14 | private static final int DDRAM_HANG_MAX_BYTE = 40;
15 | private static final int DDRAM_HANG_NUM = 2;
16 | private static final int DDRAM_HANG_BYTE = 16;
17 | private static final int CGRAM_LENGTH = 8;//自定义存储RAM
18 |
19 | private int cursor_postion = 0;//光标位置
20 |
21 | private ZiMo[][] ddram = new ZiMo[DDRAM_HANG_NUM][DDRAM_HANG_MAX_BYTE];
22 |
23 | private static RGB[][] display = new RGB[DDRAM_HANG_NUM][DDRAM_HANG_MAX_BYTE];
24 | private static char[] cgram = new char[CGRAM_LENGTH];
25 |
26 |
27 | @Override
28 | public void closeScreen() {
29 |
30 | }
31 |
32 | @Override
33 | public void openScreen() {
34 |
35 | }
36 |
37 | @Override
38 | public void moveRam(int leftOrRight) {
39 |
40 | }
41 |
42 | @Override
43 | public void clearRam() {
44 |
45 | }
46 |
47 | @Override
48 | public void writeCGROM(int x, int y, char str) {
49 |
50 | }
51 |
52 | @Override
53 | public void writeDDROM(int x, int y, char str) {
54 |
55 | }
56 |
57 | @Override
58 | public void setDramLength(int length) {
59 |
60 | }
61 |
62 | @Override
63 | public void setcgramLength(int length) {
64 |
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/assets/test.lrc:
--------------------------------------------------------------------------------
1 | [ti:我不知道爱是什么]
2 | [ar:艾怡良]
3 | [al:电视剧《16个夏天》插曲]
4 | [by:珍妮]
5 | [00:00.00]我爱歌词网 www.5ilrc.com
6 | [00:00.40]我不知道爱是什么 - 艾怡良
7 | [00:09.49]电视剧《16个夏天》插曲
8 | [00:12.49]词:艾怡良
9 | [00:15.86]曲:金贵晟
10 | [00:18.96]
11 | [00:32.85]坦白来说
12 | [00:35.56]我不知道爱是什么
13 | [00:40.57]爱不爱你 多爱你
14 | [00:47.71]诸如此类的这些话
15 | [00:52.11]我都不知道是什么
16 | [00:55.72]所以不要与我交谈
17 | [00:59.28]不要揣测过头
18 | [01:03.63]如果这些都模糊了
19 | [01:06.81]你的基本认知
20 | [01:11.10]如果对你来说不够隽永
21 | [01:18.08]那么欢迎来到我的脑中
22 | [01:23.38]这里对爱没有解释
23 | [01:26.75]只有一些细微的撩动
24 | [01:32.70]
25 | [01:33.62]例如 我直视你的眼神
26 | [01:37.77]与她不同
27 | [01:41.17]我走过你身边的角度
28 | [01:45.76]与她不同
29 | [01:48.89]我开口跟你说话的时机
30 | [01:53.46]与她不同
31 | [01:56.45]我用的词汇艰涩
32 | [02:01.01]与她不同
33 | [02:04.15]
34 | [02:21.18]坦白来说
35 | [02:24.07]我不知道爱是什么
36 | [02:28.91]爱不爱你 多爱你
37 | [02:36.40]诸如此类的这些话
38 | [02:40.50]我都不知道是什么
39 | [02:44.08]所以不要与我交谈
40 | [02:47.70]不要揣测过头
41 | [02:51.67]如果这些都模糊了
42 | [02:55.25]你的基本认知
43 | [02:59.55]如果对你来说不够隽永
44 | [03:06.46]那么欢迎来到我的脑中
45 | [03:11.74]这里对爱没有解释
46 | [03:14.84]只有一些细微的撩动
47 | [03:20.65]
48 | [03:25.49]例如 我直视你的眼神
49 | [03:30.16]与她不同
50 | [03:33.31]我走过你身边的角度
51 | [03:37.84]与她不同
52 | [03:41.41]我开口跟你说话的时机
53 | [03:45.75]与她不同
54 | [03:49.02]我用的词汇艰涩
55 | [03:53.29]与她不同
56 | [03:56.87]例如 我真的在乎
57 | [04:00.13]否则不会沉默
58 | [04:04.38]一如以往面无表情
59 | [04:08.73]却更汹涌
60 | [04:12.19]还期待或许是坏了规则
61 | [04:16.54]要的太多
62 | [04:20.40]或许爱是这样吧
63 | [04:24.42]那我不懂
64 | [04:27.70]
65 | [04:29.15]我是独一无二的
66 | [04:32.02]你懂不懂
67 | [04:35.80]我的爱是什么
68 | [04:39.04]你得自己感受
69 | [04:45.38]Lrc By:珍妮 QQ:929964514
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D7400Activity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.supets.pet.ledview.R;
10 |
11 |
12 | public class D7400Activity extends Activity implements D7400.D7400CallBack, View.OnClickListener {
13 |
14 | private TextView result;
15 | private D7400 mSelector = new D7400(this);
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_7400);
21 |
22 | result = findViewById(R.id.result);
23 |
24 | findViewById(R.id.btn0).setOnClickListener(this);
25 | findViewById(R.id.btn1).setOnClickListener(this);
26 | findViewById(R.id.btn2).setOnClickListener(this);
27 | findViewById(R.id.btn3).setOnClickListener(this);
28 |
29 | }
30 |
31 | @Override
32 | public void onClick(View view) {
33 | if (view.getId() == R.id.btn0) {
34 | mSelector.setPinA(true);
35 | } else if (view.getId() == R.id.btn1) {
36 | mSelector.setPinA(false);
37 | } else if (view.getId() == R.id.btn2) {
38 | mSelector.setPinB(true);
39 | } else if (view.getId() == R.id.btn3) {
40 | mSelector.setPinB(false);
41 | }
42 | }
43 |
44 |
45 | @Override
46 | public void outputY(boolean y) {
47 | result.setText("A=" + (mSelector.getPinA() ? 1 : 0)
48 | + " B=" + (mSelector.getPinB() ? 1 : 0)
49 | + " Y=" + (y ? 1 : 0));
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74107.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.os.Handler;
4 |
5 | /**
6 | * java实现----------主从下降沿JK触发器
7 | */
8 | public class D74107 implements Runnable {
9 |
10 | private int J, K;
11 | private int Q;
12 | private int CLK;//1代表高电平 0-下降沿
13 | private int CLR;
14 |
15 |
16 | //复位 输出永远为0
17 | public void clear() {
18 | CLR = 0;
19 | Q=0;
20 | }
21 | //保持态 Q不确定
22 | public void setNoChange2() {
23 | CLR = 1;
24 | CLK = 1;
25 | }
26 | //保持态,Q不确定
27 | public void setNoChange3() {
28 | CLR = 1;
29 | J = 1;
30 | K = 1;
31 | }
32 |
33 | //稳态 Q=J CLK触发不起作用--Q随J变化,频率不改变
34 | public void setQ() {
35 | CLR = 1;
36 | J = 1;
37 | K = 0;
38 | Q = 1;
39 | }
40 |
41 | //稳态 Q=J CLK触发不起作用--Q随J变化,频率不改变
42 | public void setQ2() {
43 | CLR = 1;
44 | J = 0;
45 | K = 1;
46 |
47 | Q = 0;
48 | }
49 | //触发态 Q=J CLK触发---分频器
50 | public void toggle() {
51 | CLR = 1;
52 | J = 1;
53 | K = 1;
54 | Q = (Q == 1 ? 0 : 1);
55 | }
56 |
57 |
58 | private Handler handler = new Handler();
59 | private D7400CallBack mCallBack;
60 |
61 | public D74107(D7400CallBack mCallBack) {
62 | this.mCallBack = mCallBack;
63 | }
64 |
65 | public void seCallBack(D7400CallBack mCallBack) {
66 | this.mCallBack = mCallBack;
67 | }
68 |
69 |
70 | @Override
71 | public void run() {
72 | if (mCallBack != null) {
73 | // mCallBack.outputY(Q);
74 | }
75 | }
76 |
77 | interface D7400CallBack {
78 | void outputY(boolean y);
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/TimeActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 |
8 | import com.supets.pet.ledview.R;
9 | import com.supets.pet.view.LedTextView;
10 | import com.supets.pet.view.WakeScreenUtils;
11 |
12 | import java.text.SimpleDateFormat;
13 | import java.util.Date;
14 |
15 | public class TimeActivity extends Activity {
16 |
17 |
18 | private LedTextView time_led;
19 |
20 | private Handler handler;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | WakeScreenUtils.keepScreen(this);
26 | setContentView(R.layout.activity_time);
27 |
28 | time_led = findViewById(R.id.time_led);
29 | time_led.updateText("88:88");
30 |
31 | handler = new Handler(new Handler.Callback() {
32 | @Override
33 | public boolean handleMessage(Message message) {
34 | time_led.updateText(getStringDate());
35 | handler.sendEmptyMessageDelayed(0, 1000);
36 | return false;
37 | }
38 | });
39 |
40 | handler.sendEmptyMessageDelayed(0, 1000);
41 | }
42 |
43 | @Override
44 | protected void onDestroy() {
45 | super.onDestroy();
46 | handler.removeMessages(0);
47 | }
48 |
49 | private boolean isShan = false;
50 |
51 | public String getStringDate() {
52 | Date currentTime = new Date();
53 | SimpleDateFormat formatter = new SimpleDateFormat(isShan ? "HH mm" : "HH:mm");
54 | isShan = !isShan;
55 | String dateString = formatter.format(currentTime);
56 | return dateString;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-hdpi/activity_7400.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
17 |
29 |
30 |
31 |
36 |
37 |
42 |
43 |
48 |
49 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-hdpi/activity_74138.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
17 |
29 |
30 |
37 |
38 |
43 |
44 |
49 |
50 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/weather/WeatherInfo.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.weather;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * LedView
7 | *
8 | * @user lihongjiang
9 | * @description
10 | * @date 2017/8/22
11 | * @updatetime 2017/8/22
12 | */
13 |
14 | public class WeatherInfo {
15 |
16 | public String message;
17 | public int status;
18 | public String city;
19 | public int count;
20 |
21 | public Weather data;
22 |
23 |
24 | @Override
25 | public String toString() {
26 | return " 【" + city + "天气预报】 " + data.toString();
27 | }
28 |
29 | public static class Weather {
30 |
31 | public String shidu;//84%
32 | public String pm25;// 70
33 | public String pm10;//95
34 | public String quality;//良
35 | public String wendu;// 28
36 | public String ganmao;//极少数敏感人群应减少户外活动
37 |
38 | public WeatherDay yesterday;
39 | public ArrayList forecast;
40 |
41 |
42 | @Override
43 | public String toString() {
44 | String data = " 温度:" + wendu
45 | + " pm2.5:" + pm25
46 | + " 湿度:" + shidu;
47 | for (WeatherDay temp : forecast
48 | ) {
49 | data += (temp.date + " "
50 | + temp.type
51 | + " " + temp.fx + temp.fl);
52 | }
53 | return data;
54 |
55 | }
56 | }
57 |
58 |
59 | public static class WeatherDay {
60 | public String date;//21日星期一",
61 | public String sunrise;//05:30",
62 | public String high;//高温 32.0℃
63 | public String low;//低温 24.0℃
64 | public String sunset;//19:04
65 | public String aqi;//106,
66 | public String fx;//南风
67 | public String fl;//<3级
68 | public String type;//多云
69 | public String notice;//今日多云,骑上单车去看看世界吧"
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-hdpi/activity_74151.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
27 |
28 |
36 |
37 |
42 |
43 |
48 |
49 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bus/BusUtils.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bus;
2 |
3 |
4 | import org.jsoup.Jsoup;
5 | import org.jsoup.nodes.Document;
6 | import org.jsoup.nodes.Element;
7 | import org.jsoup.select.Elements;
8 |
9 | import java.io.IOException;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | /**
14 | * LedView
15 | *
16 | * @user lihongjiang
17 | * @description
18 | * @date 2017/8/23
19 | * @updatetime 2017/8/23
20 | */
21 |
22 | public class BusUtils {
23 |
24 | public static void main(String[] args) {
25 | String url = "http://map.baidu.com/mobile/webapp/search/search/qt=inf&uid=229abe20df4728442ad7ab79/?third_party=webapp-aladdin";
26 | getListPic(url);
27 | }
28 |
29 | public static List getListPic(String url) {
30 | List map = new ArrayList<>();
31 | Document doc;
32 | try {
33 | doc = Jsoup.connect(url).get();
34 | Elements ListDiv = doc.getElementsByAttributeValue("class", "bustop-list-info");
35 | for (Element element : ListDiv) {
36 |
37 | BusInfo info = new BusInfo();
38 |
39 | Elements links = element.getElementsByAttributeValue("class", "list-icon detail-line-no -ft-small");
40 | for (Element element1 : links) {
41 | info.setLineNumber(element1.text().trim());
42 | }
43 | Elements links2 = element.getElementsByAttributeValue("class", "-ft-middle linename");
44 | for (Element element1 : links2) {
45 | info.setName(element1.text().trim());
46 | }
47 | Elements links3 = element.getElementsByAttributeValue("class", "icon -bus rticon");
48 | for (Element element1 : links3) {
49 | info.setStop(true);
50 | }
51 | map.add(info);
52 |
53 | }
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 | return map;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74151Activity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.CheckBox;
8 | import android.widget.TextView;
9 |
10 | import com.supets.pet.ledview.R;
11 |
12 |
13 |
14 | public class D74151Activity extends Activity implements View.OnClickListener {
15 |
16 | private TextView result;
17 | private CheckBox enable;
18 |
19 | private D74151 mSelector = new D74151();
20 |
21 | @Override
22 | protected void onCreate(@Nullable Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_74151);
25 |
26 | mSelector.setInputData(0, "输出D0数据");
27 | mSelector.setInputData(1, "输出D1数据");
28 | mSelector.setInputData(2, "输出D2数据");
29 |
30 | mSelector.setEnable(true);
31 |
32 | result = findViewById(R.id.result);
33 | enable = findViewById(R.id.enable);
34 |
35 | findViewById(R.id.btn0).setOnClickListener(this);
36 | findViewById(R.id.btn1).setOnClickListener(this);
37 | findViewById(R.id.btn2).setOnClickListener(this);
38 |
39 | enable.setOnClickListener(new View.OnClickListener() {
40 | @Override
41 | public void onClick(View view) {
42 | if (enable.isChecked()) {
43 | result.setText("打开输出");
44 | } else {
45 | result.setText("关闭输出");
46 | }
47 | mSelector.setEnable(enable.isChecked());
48 | }
49 | });
50 |
51 | }
52 |
53 |
54 | @Override
55 | public void onClick(View view) {
56 | if (view.getId() == R.id.btn0) {
57 | mSelector.setChannel(0);
58 | result.setText(mSelector.getResult());
59 | } else if (view.getId() == R.id.btn1) {
60 | mSelector.setChannel(1);
61 | result.setText(mSelector.getResult());
62 | } else if (view.getId() == R.id.btn2) {
63 | mSelector.setChannel(2);
64 | result.setText(mSelector.getResult());
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/BaseOrientationActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.hardware.Sensor;
6 | import android.hardware.SensorEvent;
7 | import android.hardware.SensorEventListener;
8 | import android.hardware.SensorManager;
9 | import android.os.Bundle;
10 | import android.support.annotation.Nullable;
11 | import android.util.Log;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * LedView
17 | *
18 | * @user lihongjiang
19 | * @description
20 | * @date 2017/8/23
21 | * @updatetime 2017/8/23
22 | */
23 |
24 | public class BaseOrientationActivity extends Activity {
25 |
26 |
27 | private SensorManager manager;
28 | private SensorListener listener = new SensorListener();
29 |
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 |
35 | manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
36 | List list = manager.getSensorList(Sensor.TYPE_ALL); //获取传感器的集合
37 | for (Sensor sensor : list) {
38 | Log.v("支持传感器:", sensor.getName());
39 | }
40 | }
41 |
42 | @Override
43 | protected void onResume() {
44 | Sensor sensor = manager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
45 | //应用在前台时候注册监听器
46 | manager.registerListener(listener, sensor,
47 | SensorManager.SENSOR_DELAY_GAME);
48 | super.onResume();
49 | }
50 |
51 |
52 | @Override
53 | protected void onPause() {
54 | //应用不在前台时候销毁掉监听器
55 | manager.unregisterListener(listener);
56 | super.onPause();
57 | }
58 |
59 | private final class SensorListener implements SensorEventListener {
60 |
61 | @Override
62 | public void onSensorChanged(SensorEvent event) {
63 | onOrientationDegree((int) event.values[0],(int) event.values[1],(int) event.values[2]);
64 | }
65 |
66 | @Override
67 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
68 |
69 | }
70 |
71 | }
72 |
73 | protected void onOrientationDegree(int degreeX, int degreeY, int degreeZ) {
74 |
75 | }
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/ZiMoUtuls.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 | import android.content.Context;
4 |
5 | import com.supets.pet.view.ChatUtils;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * LedView
11 | *
12 | * @user lihongjiang
13 | * @description
14 | * @date 2017/8/30
15 | * @updatetime 2017/8/30
16 | */
17 |
18 | public class ZiMoUtuls {
19 |
20 | public static RGB[][] getDisplayCache(ArrayList list, int SCALE) {
21 |
22 | int totalDots = 0;//每行点数=字宽之和
23 | for (byte[] temp : list) {
24 | totalDots += (temp.length/2);
25 | }
26 |
27 | RGB[][] matrix = new RGB[16 * SCALE][totalDots * SCALE];
28 |
29 | for (int num = 0; num < list.size(); num++) {//显示字数
30 | byte[] word = list.get(num);
31 | for (int i = 0; i < 16; i++) {//字符高度16
32 | int wordWidth = word.length / 16;
33 | for (int j1 = 0; j1 < wordWidth; j1++) {//一个字节行循环
34 | byte tmp = word[i * wordWidth + j1];
35 | for (int j2 = 0; j2 < 8; j2++) {
36 |
37 | //起始点X 坐标
38 | int length = 0;
39 | for (int x = 0; x < num; x++) {
40 | length += (list.get(x).length / 16) * 8;
41 | }
42 |
43 | if (((tmp >> (7 - j2)) & 1) == 1) {
44 | for (int m = 0; m < SCALE; m++) {
45 | for (int n = 0; n < SCALE; n++) {
46 | matrix[i * SCALE + m][(length+ j1 * 8 + j2) * SCALE + n] =new RGB(0,true);
47 | }
48 | }
49 | } else {
50 | for (int m = 0; m < SCALE; m++) {
51 | for (int n = 0; n < SCALE; n++) {
52 | matrix[i * SCALE + m][(length + j1 * 8 + j2) * SCALE + n] =new RGB(0,false);
53 | }
54 | }
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
61 | return matrix;
62 |
63 | }
64 |
65 |
66 | public static RGB[][] convert(String auto, Context context){
67 | return getDisplayCache(ChatUtils.auto(context,auto),1);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/ttl/D74Activity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.AdapterView;
8 | import android.widget.ListView;
9 | import android.widget.TextView;
10 |
11 | import com.supets.pet.ledview.R;
12 | import com.supets.pet.module.sensor.BaseOrientationActivity;
13 |
14 | import java.util.ArrayList;
15 |
16 |
17 | public class D74Activity extends BaseOrientationActivity {
18 |
19 | private D74Adapter adapter;
20 | private ListView listView;
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 |
27 | TextView title = findViewById(R.id.title);
28 | title.setText("模拟74系列数字电路");
29 |
30 | listView = findViewById(R.id.list);
31 | adapter = new D74Adapter();
32 | ArrayList d = new ArrayList<>();
33 | d.add(new D74(7400, "7400", "2输入端四与非门"));
34 | d.add(new D74(74138, "74138", "3-8线译码器/复工器"));
35 | d.add(new D74(74151, "74151", "8选1数据选择器"));
36 |
37 | adapter.setData(d);
38 | listView.setAdapter(adapter);
39 |
40 |
41 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
42 | @Override
43 | public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
44 | doWithButton((D74) adapterView.getItemAtPosition(position));
45 | }
46 | });
47 |
48 |
49 | }
50 |
51 | private void doWithButton(D74 data) {
52 | switch (data.type) {
53 | case 74138: {
54 | Intent intent = new Intent(D74Activity.this, D74138Activity.class);
55 | startActivity(intent);
56 | }
57 | break;
58 | case 74151: {
59 | Intent intent = new Intent(D74Activity.this, D74151Activity.class);
60 | startActivity(intent);
61 | }
62 | break;
63 | case 7400: {
64 | Intent intent = new Intent(D74Activity.this, D7400Activity.class);
65 | startActivity(intent);
66 | }
67 | break;
68 | default:
69 | break;
70 | }
71 | }
72 |
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bcd/BCD.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bcd;
2 |
3 | import android.graphics.Path;
4 |
5 | /**
6 | * LedView
7 | *
8 | * @user lihongjiang
9 | * @description
10 | * @date 2017/9/2
11 | * @updatetime 2017/9/2
12 | */
13 |
14 | public class BCD {
15 |
16 | public static final byte[] bcd = new byte[]{
17 | 0X3F, 0X06, 0X5B, 0X4F, 0X66,
18 | 0X6D, 0X7D, 0X07, 0X7F, 0X6F
19 | };
20 |
21 |
22 | public static boolean isBitLight(byte data, int bit) {
23 | return ((data >> bit) & 1) == 1;
24 | }
25 |
26 | public static byte getNum(int num) {
27 | return bcd[num];
28 | }
29 |
30 | public static byte am(byte data, boolean am) {
31 | return (byte) (data | (am ? 0x80 : 0x00));
32 | }
33 |
34 | public static byte dian(byte data, boolean dian) {
35 | return (byte) (data | (dian ? 0x80 : 0x00));
36 | }
37 |
38 |
39 | //宽22个单位 高6个单位 以宽为基准
40 | //字宽W+2H 字高3h+2W W=4H 关系。
41 | //字宽本来占3个单位==》H=1/44W0单位 W=1/11W0
42 | public static Path[] buildBCD(int width, int x0, int y0) {
43 |
44 | Path[] paths = new Path[7];
45 |
46 | int w = width / 11;
47 | int h = width / 44;
48 |
49 | paths[0] = getHBCD(w, h, x0 + h/2, y0 + h / 2);//A
50 | paths[3] = getHBCD(w, h, x0 + h/2, y0 +w+h+w+h+ h / 2);//D
51 | paths[6] = getHBCD(w, h, x0 + h/2, y0 + h / 2 + w + h);//G
52 |
53 | paths[1] = getLBCD(w, h, x0 + w + h / 2, y0 + h);//B
54 | paths[2] = getLBCD(w, h, x0 + w + h / 2, y0 + w + h + h);//C
55 | paths[4] = getLBCD(w, h, x0 + h / 2, y0 + w + h + h);//E
56 | paths[5] = getLBCD(w, h, x0 + h /2, y0 + h);//F
57 |
58 |
59 | return paths;
60 |
61 | }
62 |
63 |
64 | private static Path getHBCD(int w, int h, int x, int y) {
65 | Path path = new Path();
66 | path.moveTo(x, y);
67 | path.lineTo(x + h / 2, y + h / 2);
68 | path.lineTo(x + w - h / 2, y + h / 2);
69 | path.lineTo(x + w, y);
70 | path.lineTo(x + w - h / 2, y - h / 2);
71 | path.lineTo(x + h / 2, y - h / 2);
72 | path.close();
73 | return path;
74 | }
75 |
76 | private static Path getLBCD(int w, int h, int x, int y) {
77 | Path path = new Path();
78 | path.moveTo(x, y);
79 | path.lineTo(x - h / 2, y + h / 2);
80 | path.lineTo(x - h / 2, y + w - h / 2);
81 | path.lineTo(x, y + w);
82 | path.lineTo(x + h / 2, y + w - h / 2);
83 | path.lineTo(x + h / 2, y + h / 2);
84 | path.close();
85 | return path;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/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/supets/pet/module/ttl/D74138Activity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.ttl;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.CheckBox;
8 | import android.widget.TextView;
9 |
10 | import com.supets.pet.ledview.R;
11 |
12 | /**
13 | * LedView
14 | *
15 | * @user lihongjiang
16 | * @description
17 | * @date 2017/9/1
18 | * @updatetime 2017/9/1
19 | */
20 |
21 | public class D74138Activity extends Activity implements D74138.OutputResultCallBack, View.OnClickListener {
22 |
23 | private TextView result;
24 | private CheckBox enable;
25 |
26 | private D74138 mSelector = new D74138();
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_74138);
32 |
33 | mSelector.setOutPutResult(0, this);
34 | mSelector.setOutPutResult(1, this);
35 | mSelector.setOutPutResult(2, this);
36 | mSelector.setEnable(true);
37 |
38 | result = findViewById(R.id.result);
39 | enable = findViewById(R.id.enable);
40 |
41 | findViewById(R.id.btn0).setOnClickListener(this);
42 | findViewById(R.id.btn1).setOnClickListener(this);
43 | findViewById(R.id.btn2).setOnClickListener(this);
44 |
45 | enable.setOnClickListener(new View.OnClickListener() {
46 | @Override
47 | public void onClick(View view) {
48 | if (enable.isChecked()) {
49 | result.setText("打开输出");
50 | } else {
51 | result.setText("关闭输出");
52 | }
53 | mSelector.setEnable(enable.isChecked());
54 | }
55 | });
56 | }
57 |
58 | @Override
59 | public void resultCallBack(int input) {
60 | String data="";
61 | for (int i=7;i>=0;i--){
62 | if (i==input){
63 | data+="1";
64 | }else{
65 | data+="0";
66 | }
67 | }
68 | result.setText("D7~D0:"+data);
69 | }
70 |
71 | @Override
72 | public void onClick(View view) {
73 | if (view.getId() == R.id.btn0) {
74 | mSelector.setInput(0);
75 | } else if (view.getId() == R.id.btn1) {
76 | mSelector.setInput(1);
77 | } else if (view.getId() == R.id.btn2) {
78 | mSelector.setInput(2);
79 | }
80 | }
81 |
82 |
83 | @Override
84 | protected void onDestroy() {
85 | super.onDestroy();
86 | mSelector.onDestroy();
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/BusActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.supets.pet.bus.BusInfo;
10 | import com.supets.pet.bus.BusUtils;
11 | import com.supets.pet.ledview.R;
12 | import com.supets.pet.lrc.LrcRead;
13 | import com.supets.pet.lrc.LyricContent;
14 | import com.supets.pet.view.LedTextView;
15 |
16 | import java.util.List;
17 |
18 | public class BusActivity extends Activity {
19 |
20 |
21 | LedTextView time_led;
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_weather);
27 |
28 | boolean isDitie = getIntent().getBooleanExtra("status", true);
29 |
30 | String url = isDitie ?
31 | "http://map.baidu.com/mobile/webapp/search/search/qt=inf&uid=229abe20df4728442ad7ab79/?third_party=webapp-aladdin" :
32 | "http://map.baidu.com/mobile/webapp/search/search/qt=inf&uid=bbca8d0458ee9582601c67b7/?third_party=webapp-aladdin";
33 | time_led = findViewById(R.id.time_led);
34 | time_led.startScroll();
35 | requestData(url);
36 | }
37 |
38 | @SuppressLint("StaticFieldLeak")
39 | public void requestData(String url) {
40 | new AsyncTask>() {
41 |
42 | @Override
43 | protected List doInBackground(String... params) {
44 | return BusUtils.getListPic(params[0]);
45 | }
46 |
47 | @Override
48 | protected void onPostExecute(List result) {
49 | StringBuilder sb = new StringBuilder();
50 | sb.append(" 车已经到达:");
51 | for (BusInfo info : result) {
52 | if (info.isStop) {
53 | sb.append(" " + info.getLineNumber() + " " + info.getName());
54 | }
55 | }
56 | time_led.ForceupdateText(sb.toString());
57 | try {
58 | LrcRead read = new LrcRead();
59 | read.Read(getAssets().open("test.lrc"));
60 | sb.setLength(0);
61 | for (LyricContent lyricContent : read.GetLyricContent()) {
62 | sb.append(lyricContent.getLyricContent());
63 | }
64 | time_led.ForceupdateText(sb.toString());
65 | } catch (Exception e) {
66 | e.printStackTrace();
67 | }
68 |
69 |
70 | }
71 | }.execute(url);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/RotationLedActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 |
8 | import com.supets.pet.ledview.R;
9 | import com.supets.pet.sensor.ledPref;
10 | import com.supets.pet.view.ChatUtils;
11 | import com.supets.pet.view.LedTextView;
12 | import com.supets.pet.view.WakeScreenUtils;
13 |
14 | public class RotationLedActivity extends Activity {
15 | private LedTextView time_led;
16 |
17 | private Handler handler;
18 |
19 | private boolean[][] data;
20 |
21 | private int m = 0;
22 |
23 | public static final int MAX_DOTS = 128;//0.05-0.2
24 | private int delay = 10;//12个汉字
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | WakeScreenUtils.keepScreen(this);
30 | setContentView(R.layout.activity_rotationled);
31 |
32 | delay = ledPref.getTime() / 160;
33 | delay = delay < 10 ? 10 : delay;
34 |
35 | data = ChatUtils.convert("李洪江", this);
36 | time_led = findViewById(R.id.time_led);
37 | time_led.ForceupdateText(getLineData(m));
38 |
39 | handler = new Handler(new Handler.Callback() {
40 | @Override
41 | public boolean handleMessage(Message message) {
42 | time_led.ForceupdateText(getLineData(m));
43 | return false;
44 | }
45 | });
46 |
47 |
48 | new Thread(new Runnable() {
49 | @Override
50 | public void run() {
51 | while (runflag) {
52 | m++;
53 | if (m >= MAX_DOTS) {
54 | m = 0;
55 | }
56 | try {
57 | Thread.sleep(delay);
58 | } catch (InterruptedException e) {
59 | e.printStackTrace();
60 | }
61 | handler.sendEmptyMessage(0);
62 | }
63 | handler.removeMessages(0);
64 | }
65 | }).start();
66 |
67 | }
68 |
69 |
70 | private boolean runflag = true;
71 |
72 | private boolean[][] getLineData(int m) {
73 |
74 | boolean[][] temp = new boolean[16][1];
75 | for (int i = 0; i < 16; i++) {
76 | if (m > data[0].length - 1) {
77 | temp[i][0] = false;
78 | } else {
79 | temp[i][0] = data[i][m];
80 | }
81 | }
82 |
83 |
84 | return temp;
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | super.onDestroy();
90 | runflag = false;
91 | handler.removeMessages(0);
92 | }
93 |
94 |
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/sms/SmsRecerver.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.sms;
2 |
3 |
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 |
9 | import android.telephony.SmsMessage;
10 |
11 | import com.supets.pet.module.led.SmsActivity;
12 |
13 | public class SmsRecerver extends BroadcastReceiver {
14 |
15 | // private static final String regix = "led-sms:";
16 | private static final String regix = "";
17 |
18 | private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
19 |
20 | @Override
21 | public void onReceive(Context context, Intent arg1) {
22 | // 判断当前广播是不是系统接收到短信后发出的广播ACTION
23 | if (arg1.getAction().equals(ACTION)) {
24 | // 获取bundle内容
25 | Bundle bundle = arg1.getExtras();
26 | if (bundle != null && bundle.size() > 0) {
27 | // 获取短信内容
28 | Object[] pdus = (Object[]) bundle.get("pdus");
29 | for (Object obj : pdus) {
30 | // 转化成短信对象
31 | SmsMessage message = SmsMessage.createFromPdu((byte[]) obj);
32 | // 获取短信内容
33 | String content = message.getMessageBody();
34 | // 获取源地址
35 | String phone = message.getOriginatingAddress();
36 | // 判断短信内容
37 | System.out.println(content);
38 | /**
39 | * 接收方短信处理,在后台服务中处理
40 | */
41 | if (content.startsWith(regix)) {
42 | // 启动短信服务程序
43 | Intent intent = new Intent(context, SmsActivity.class);
44 | intent.putExtra("phone", phone);
45 | intent.putExtra("message", content.substring(regix.length()));
46 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
47 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
48 | intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
49 | // 使用这种方法启动服务,二者之间没有联系
50 | // 广播宿主线程销毁,服务还在
51 | // 采用广播启动子线程来完成耗时操作,虽然广播接收器消失,线程还在,
52 | // 但由于是没有活动的空线程,虽时杀死,此时线程也被一起杀死,在广播接收器中开启子线程不安全.
53 | // 一般只在activity中开启子线程
54 | // 一般在广播中开启服务
55 | context.startActivity(intent);
56 | // 停止广播,不向后面广播
57 | // 就不会再消息栏显示,是因为没人处理广播了,才会提示出来
58 | // 处理了不停止,还会继续广播下去
59 | abortBroadcast();
60 | // 因为优先级最高,得到该广播后先处理了,并停止广播了
61 | // 所以在系统用户收件箱处理不了改短信息了
62 | }
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/BaseSmsActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.app.PendingIntent;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.content.IntentFilter;
9 | import android.os.Bundle;
10 | import android.support.annotation.Nullable;
11 | import android.telephony.SmsManager;
12 | import android.widget.Toast;
13 |
14 | /**
15 | * LedView
16 | *
17 | * @user lihongjiang
18 | * @description
19 | * @date 2017/8/21
20 | * @updatetime 2017/8/21
21 | */
22 |
23 | public class BaseSmsActivity extends Activity {
24 |
25 | public void sendSms(String receiverPhone, String msg) {
26 | // 使用短信管理类提供的静态方法创建一个默认的短信管理实例
27 | SmsManager smsmanager = SmsManager.getDefault();
28 | // 第一个参数是收信方的电话号码
29 | // 第二个参数是短信服务中心号码
30 | // 第三个参数是短信内容
31 | // 第四个参数是发送信息的描述意图pending服务,如果发送成功,会广播出去
32 | // 第五个参数是信息反馈的描述意图pending服务,如果传送成功,会广播出去
33 | PendingIntent pisend = PendingIntent.getBroadcast(
34 | this, 0, new Intent(
35 | "MY_SMS_SEND"), 0);
36 | PendingIntent piDeliver = PendingIntent.getBroadcast(
37 | this, 0, new Intent(
38 | "MY_SMS_DELIVER"), 0);
39 | smsmanager.sendTextMessage(receiverPhone, null,
40 | "led-sms:"+msg, pisend, piDeliver);
41 | }
42 |
43 |
44 | @Override
45 | protected void onDestroy() {
46 | super.onDestroy();
47 | unregisterReceiver(mSms);
48 | }
49 |
50 | @Override
51 | protected void onCreate(@Nullable Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 | registerReceiver(mSms, new IntentFilter("MY_SMS_DELIVER"));
54 | }
55 |
56 | private BroadcastReceiver mSms = new BroadcastReceiver() {
57 | @Override
58 | public void onReceive(Context context, Intent intent) {
59 | String message = null;
60 | switch (getResultCode()) {
61 | case Activity.RESULT_OK:
62 | message = "Message sent!";
63 | break;
64 | case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
65 | message = "Error.";
66 | break;
67 | case SmsManager.RESULT_ERROR_NO_SERVICE:
68 | message = "Error: No service.";
69 | break;
70 | case SmsManager.RESULT_ERROR_NULL_PDU:
71 | message = "Error: Null PDU.";
72 | break;
73 | case SmsManager.RESULT_ERROR_RADIO_OFF:
74 | message = "Error: Radio off.";
75 | break;
76 | }
77 | Toast.makeText(context, message, Toast.LENGTH_SHORT)
78 | .show();
79 | }
80 | };
81 |
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/LCD1602Activity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 |
8 | import com.supets.pet.lcd.LCD1602A;
9 | import com.supets.pet.ledview.R;
10 | import com.supets.pet.view.WakeScreenUtils;
11 |
12 | import java.util.Calendar;
13 | import java.util.Date;
14 |
15 | public class LCD1602Activity extends Activity {
16 |
17 | private boolean isShan = false;
18 |
19 | private LCD1602A lcd1602A;
20 |
21 | private Handler handler;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | WakeScreenUtils.keepScreen(this);
27 | setContentView(R.layout.activity_lcd1602);
28 |
29 | lcd1602A = findViewById(R.id.lcd1602);
30 |
31 |
32 | lcd1602A.setRam(1, 5, "L");
33 | lcd1602A.setRam(1, 6, "C");
34 | lcd1602A.setRam(1, 7, "D");
35 | lcd1602A.setRam(1, 8, "1");
36 | lcd1602A.setRam(1, 9, "6");
37 | lcd1602A.setRam(1, 10, "0");
38 | lcd1602A.setRam(1, 11, "2");
39 |
40 | lcd1602A.setRam(2, 3, "l");
41 | lcd1602A.setRam(2, 4, "o");
42 | lcd1602A.setRam(2, 5, "a");
43 | lcd1602A.setRam(2, 6, "d");
44 | lcd1602A.setRam(2, 7, "i");
45 | lcd1602A.setRam(2, 8, "n");
46 | lcd1602A.setRam(2, 9, "g");
47 | lcd1602A.setRam(2, 10, ".");
48 | lcd1602A.setRam(2, 11, ".");
49 | lcd1602A.setRam(2, 12, ".");
50 |
51 | lcd1602A.refreshView();
52 |
53 | handler = new Handler(new Handler.Callback() {
54 | @Override
55 | public boolean handleMessage(Message message) {
56 | isShan = !isShan;
57 | Calendar calendar = Calendar.getInstance();
58 | calendar.setTime(new Date());
59 | int shi = calendar.get(Calendar.HOUR);
60 | int miao = calendar.get(Calendar.SECOND);
61 |
62 | lcd1602A.setRam(2, 3, "T");
63 | lcd1602A.setRam(2, 4, "I");
64 | lcd1602A.setRam(2, 5, "M");
65 | lcd1602A.setRam(2, 6, "E");
66 | lcd1602A.setRam(2, 7, " ");
67 |
68 | lcd1602A.setRam(2, 8, shi / 10 + "");
69 | lcd1602A.setRam(2, 9, shi % 10 + "");
70 | lcd1602A.setRam(2, 10, isShan ? ":" : "");
71 | lcd1602A.setRam(2, 11, miao / 10 + "");
72 | lcd1602A.setRam(2, 12, miao % 10 + "");
73 |
74 | lcd1602A.refreshView();
75 |
76 | handler.sendEmptyMessageDelayed(0, 1000);
77 | return false;
78 | }
79 | });
80 | handler.sendEmptyMessageDelayed(0, 1000);
81 | }
82 |
83 | @Override
84 | protected void onDestroy() {
85 | super.onDestroy();
86 | handler.removeMessages(0);
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/utils/JSonUtil.java:
--------------------------------------------------------------------------------
1 | //
2 | // Source code recreated from a .class file by IntelliJ IDEA
3 | // (powered by Fernflower decompiler)
4 | //
5 |
6 | package com.supets.pet.utils;
7 |
8 | import android.text.TextUtils;
9 | import com.google.gson.ExclusionStrategy;
10 | import com.google.gson.Gson;
11 | import com.google.gson.GsonBuilder;
12 | import java.lang.reflect.Type;
13 | import java.util.ArrayList;
14 | import java.util.HashMap;
15 | import java.util.Map;
16 |
17 | public class JSonUtil {
18 | public JSonUtil() {
19 | }
20 |
21 | public static Gson getGsonExcludeFields(ExclusionStrategy exclusion) {
22 | GsonBuilder builder = (new GsonBuilder()).excludeFieldsWithModifiers(new int[]{138});
23 | return exclusion == null?builder.create():builder.setExclusionStrategies(new ExclusionStrategy[]{exclusion}).create();
24 | }
25 |
26 | public static String toJson(Object src) {
27 | Gson gson = getGsonExcludeFields((ExclusionStrategy)null);
28 | return gson.toJson(src);
29 | }
30 |
31 | public static T fromJson(String json, Class clazz) {
32 | if(TextUtils.isEmpty(json)) {
33 | return null;
34 | } else {
35 | try {
36 | return getGsonExcludeFields((ExclusionStrategy)null).fromJson(json, clazz);
37 | } catch (Exception var3) {
38 | var3.printStackTrace();
39 | return fromJson2(json, clazz);
40 | }
41 | }
42 | }
43 |
44 | private static T fromJson2(String json, Class clazz) {
45 | if(TextUtils.isEmpty(json)) {
46 | return null;
47 | } else {
48 | try {
49 | String e = json.replaceAll("((?<=\\{)\"\\w+\":\"\",|,*\"\\w+\":\"\"|(?<=\\{)\"\\w+\":\\[\\],|,*\"\\w+\":\\[\\])", "");
50 | return getGsonExcludeFields((ExclusionStrategy)null).fromJson(e, clazz);
51 | } catch (Exception var3) {
52 | var3.printStackTrace();
53 | return null;
54 | }
55 | }
56 | }
57 |
58 | public static T fromJson(String json, Type clazz) {
59 | if(TextUtils.isEmpty(json)) {
60 | return null;
61 | } else {
62 | try {
63 | return getGsonExcludeFields((ExclusionStrategy)null).fromJson(json, clazz);
64 | } catch (Exception var3) {
65 | var3.printStackTrace();
66 | return null;
67 | }
68 | }
69 | }
70 |
71 | public static String createJson(Map map) {
72 | return toJson(map);
73 | }
74 |
75 | public static String createArrayJson(ArrayList> array) {
76 | return toJson(array);
77 | }
78 |
79 | public static String createArrayJson(String key, ArrayList> array) {
80 | Gson gson = getGsonExcludeFields((ExclusionStrategy)null);
81 | HashMap map = new HashMap();
82 | map.put(key, array);
83 | String text = gson.toJson(map);
84 | return text;
85 | }
86 |
87 | public static String filterJson(String json) {
88 | return json.replaceAll("((?<=\\{)\"\\w+\":\"\",|,*\"\\w+\":\"\"|(?<=\\{)\"\\w+\":\\[\\],|,*\"\\w+\":\\[\\])", "");
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lrc/MusicBox.java:
--------------------------------------------------------------------------------
1 | //package com.supets.pet.lrc;
2 | //
3 | //import android.app.Activity;
4 | //import android.content.res.AssetFileDescriptor;
5 | //import android.content.res.AssetManager;
6 | //import android.media.MediaPlayer;
7 | //import android.os.Bundle;
8 | //import android.support.annotation.Nullable;
9 | //import android.util.Log;
10 | //import android.view.View;
11 | //import android.widget.Button;
12 | //
13 | //import com.supets.pet.ledview.R;
14 | //
15 | //import java.io.IOException;
16 | //
17 | //public class MusicBox extends Activity implements View.OnClickListener {
18 | // private Button openAssetMusic;
19 | // private AssetManager assetManager;
20 | // private MediaPlayer mediaPlayer;
21 | // private Button pause;
22 | // private Button openRawMusic;
23 | // private Button pauseRawMusic;
24 | // private MediaPlayer mediaPlayer1;
25 | //
26 | //
27 | // @Override
28 | // protected void onCreate(@Nullable Bundle savedInstanceState) {
29 | // super.onCreate(savedInstanceState);
30 | // setContentView(R.layout.musicbox);
31 | // initView();
32 | // }
33 | //
34 | // private void initView() {
35 | // openAssetMusic = (Button) findViewById(R.id.openAssetMusic);
36 | //
37 | // openAssetMusic.setOnClickListener(this);
38 | // pause = (Button) findViewById(R.id.pause);
39 | // pause.setOnClickListener(this);
40 | // openRawMusic = (Button) findViewById(R.id.openRawMusic);
41 | // openRawMusic.setOnClickListener(this);
42 | // pauseRawMusic = (Button) findViewById(R.id.pauseRawMusic);
43 | // pauseRawMusic.setOnClickListener(this);
44 | // }
45 | //
46 | // @Override
47 | // public void onClick(View v) {
48 | // switch (v.getId()) {
49 | // case R.id.openAssetMusic: //开始播放
50 | // openAssetMusics();
51 | // break;
52 | // case R.id.pause: //暂停播放
53 | // mediaPlayer.pause();
54 | // break;
55 | // case R.id.openRawMusic: //开始播放
56 | // openRawMusicS();
57 | // break;
58 | // case R.id.pauseRawMusic: //暂停播放
59 | // mediaPlayer1.pause();
60 | // break;
61 | // }
62 | // }
63 | //
64 | // /**
65 | // * 打开raw目录下的音乐mp3文件
66 | // */
67 | // private void openRawMusicS() {
68 | // mediaPlayer1 = MediaPlayer.create(this, R.raw.raw_mp3);
69 | // //用prepare方法,会报错误java.lang.IllegalStateExceptio
70 | // //mediaPlayer1.prepare();
71 | // mediaPlayer1.start();
72 | // }
73 | //
74 | // /**
75 | // * 打开assets下的音乐mp3文件
76 | // */
77 | // private void openAssetMusics() { //打开Asset目录
78 | // assetManager = getAssets();
79 | // mediaPlayer = new MediaPlayer();
80 | // try { //打开音乐文件shot.mp3
81 | // AssetFileDescriptor assetFileDescriptor = assetManager.openFd("shot.mp3");
82 | // mediaPlayer.reset();
83 | // //设置媒体播放器的数据资源
84 | // mediaPlayer.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
85 | // mediaPlayer.prepare();
86 | // mediaPlayer.start();
87 | // } catch (IOException e) {
88 | // e.printStackTrace();
89 | // Log.d("GsonUtils", "IOException" + e.toString());
90 | // }
91 | // }
92 | //}
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lrc.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
18 |
19 |
25 |
26 |
27 |
33 |
34 |
43 |
44 |
51 |
52 |
58 |
59 |
68 |
69 |
77 |
78 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/sensor/ShakeEngine.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.sensor;
2 |
3 | import android.content.Context;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 | import android.os.Vibrator;
9 | import android.util.Log;
10 | import android.widget.Toast;
11 |
12 | import com.supets.pet.ledview.R;
13 |
14 | public class ShakeEngine implements SensorEventListener {
15 |
16 | // 检测的时间间隔
17 | private static final int UPDATE_INTERVAL = 100;
18 |
19 | // 摇晃检测阈值,决定了对摇晃的敏感程度,越小越敏感
20 | private static final int SHAKE_THRESHOLD = 1500;
21 |
22 | private OnShakeListener listener;
23 | private SensorManager mSensorManager;
24 | private long mLastUpdateTime;
25 | private float mLastX;
26 | private float mLastY;
27 | private float mLastZ;
28 | private boolean mEnable;
29 |
30 | //private Vibrator mVibrator;
31 |
32 | private Context mContext;
33 |
34 | public ShakeEngine(Context context) {
35 | mContext=context;
36 | }
37 |
38 | public void setOnShakeListener(OnShakeListener listener) {
39 | this.listener = listener;
40 | }
41 |
42 | public boolean isEnable() {
43 | return mEnable;
44 | }
45 |
46 | public void setEnable(boolean enable) {
47 | mEnable = enable;
48 | }
49 |
50 | public void startSensor(Context context) {
51 | mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
52 | if (mSensorManager == null) {
53 | showUnsupportedTip();
54 | return;
55 | }
56 | Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
57 | if (sensor == null) {
58 | showUnsupportedTip();
59 | return;
60 | }
61 | boolean success = mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
62 | if (!success) {
63 | showUnsupportedTip();
64 | return;
65 | }
66 |
67 | //mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
68 | }
69 |
70 | private void showUnsupportedTip() {
71 | Toast.makeText(mContext,R.string.shake_not_support_sensor,Toast.LENGTH_SHORT).show();
72 | }
73 |
74 | public void stopSensor() {
75 | if (mSensorManager != null) {
76 | mSensorManager.unregisterListener(this);
77 | mSensorManager = null;
78 | }
79 | }
80 |
81 | public void onSensorChanged(SensorEvent event) {
82 | long currentTime = System.currentTimeMillis();
83 | long diffTime = currentTime - mLastUpdateTime;
84 | if (diffTime > UPDATE_INTERVAL) {
85 | if (mLastUpdateTime != 0) {
86 | float x = event.values[0];
87 | float y = event.values[1];
88 | float z = event.values[2];
89 | float deltaX = x - mLastX;
90 | float deltaY = y - mLastY;
91 | float deltaZ = z - mLastZ;
92 | float delta = (float) (Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / diffTime * 10000);
93 | if (delta > SHAKE_THRESHOLD) {
94 | onShake();
95 | }
96 | mLastX = x;
97 | mLastY = y;
98 | mLastZ = z;
99 | Log.v("加速度传感器","x="+x+" y="+y+" z="+z);
100 | Log.v("加速度传感器2","deltaX="+deltaX+" deltaY="+deltaY+" deltaZ="+deltaZ);
101 | }
102 | mLastUpdateTime = currentTime;
103 | }
104 | }
105 |
106 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
107 |
108 | }
109 |
110 | private void onShake() {
111 | if (mEnable && listener != null) {
112 | //doVibrate();
113 | listener.onShake();
114 | }
115 | }
116 |
117 | // private void doVibrate() {
118 | // if (mVibrator == null) {
119 | // return;
120 | // }
121 | // mVibrator.vibrate(new long[] {200, 300, 300, 300}, -1);
122 | // }
123 |
124 | public static interface OnShakeListener {
125 | public void onShake();
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lrc/LrcRead.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lrc;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileNotFoundException;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.InputStreamReader;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class LrcRead {
14 |
15 | private List LyricList;// 歌词内容列表 (包括歌词和时间)
16 | private LyricContent mLyricContent;// 歌词内容 (包括歌词和时间)
17 |
18 | public LrcRead() {
19 | mLyricContent = new LyricContent();//歌词内容和时间的实体类对象
20 | LyricList = new ArrayList<>();//歌词内容和时间是实体类对象列表
21 | }
22 |
23 | public void Read(String file) throws FileNotFoundException, IOException {
24 | String Lrc_data = "";
25 | File mFile = new File(file);// /mnt/sdcard/我不知道爱是什么.lrc
26 | FileInputStream mFileInputStream = new FileInputStream(mFile);
27 | InputStreamReader mInputStreamReader = new InputStreamReader(mFileInputStream, "GB2312");
28 | BufferedReader mBufferedReader = new BufferedReader(mInputStreamReader);
29 | while ((Lrc_data = mBufferedReader.readLine()) != null) {//[ti:我不知道爱是什么] ar:艾怡良]
30 | Lrc_data = Lrc_data.replace("[", "");// ti:我不知道爱是什么]
31 | Lrc_data = Lrc_data.replace("]", "@");// ti:我不知道爱是什么@
32 | String splitLrc_data[] = Lrc_data.split("@");// [00:00.00, 我爱歌词网 www.5ilrc.com]split是去掉@并在此处用逗号分隔成两个字符串。最后放到一个数组里。
33 | if (splitLrc_data.length > 1) {
34 | mLyricContent.setLyric(splitLrc_data[1]);// [00:00.00, 我爱歌词网 www.5ilrc.com],取数组里面的第2个数据作为歌词。
35 | int LyricTime = TimeStr(splitLrc_data[0]);// 取数组里面的第1个数据,放到TimeStr里都转成秒为单位后出来作为歌词时间。0 400 9490 12490 15860 15860 35560
36 | mLyricContent.setLyricTime(LyricTime);
37 | LyricList.add(mLyricContent);
38 | mLyricContent = new LyricContent();
39 | }
40 | }
41 | mBufferedReader.close();
42 | mInputStreamReader.close();
43 | }
44 |
45 | public void Read(InputStream mFileInputStream) throws FileNotFoundException, IOException {
46 | String Lrc_data = "";
47 | InputStreamReader mInputStreamReader = new InputStreamReader(mFileInputStream, "UTF-8");
48 | BufferedReader mBufferedReader = new BufferedReader(mInputStreamReader);
49 | while ((Lrc_data = mBufferedReader.readLine()) != null) {//[ti:我不知道爱是什么] ar:艾怡良]
50 | Lrc_data = Lrc_data.replace("[", "");// ti:我不知道爱是什么]
51 | Lrc_data = Lrc_data.replace("]", "@");// ti:我不知道爱是什么@
52 | String splitLrc_data[] = Lrc_data.split("@");// [00:00.00, 我爱歌词网 www.5ilrc.com]split是去掉@并在此处用逗号分隔成两个字符串。最后放到一个数组里。
53 | if (splitLrc_data.length > 1) {
54 | mLyricContent.setLyric(splitLrc_data[1]);// [00:00.00, 我爱歌词网 www.5ilrc.com],取数组里面的第2个数据作为歌词。
55 | int LyricTime = TimeStr(splitLrc_data[0]);// 取数组里面的第1个数据,放到TimeStr里都转成秒为单位后出来作为歌词时间。0 400 9490 12490 15860 15860 35560
56 | mLyricContent.setLyricTime(LyricTime);
57 | LyricList.add(mLyricContent);
58 | mLyricContent = new LyricContent();
59 | }
60 | }
61 | mBufferedReader.close();
62 | mInputStreamReader.close();
63 | }
64 |
65 | private int TimeStr(String timeStr) {// 00:40.57
66 | timeStr = timeStr.replace(":", ".");//00.40.57
67 | timeStr = timeStr.replace(".", "@");//00@40@57
68 | String timeData[] = timeStr.split("@");//[00, 40, 57]
69 | int minute = Integer.parseInt(timeData[0]);//数组里的第1个数据是分0
70 | int second = Integer.parseInt(timeData[1]);//数组里的第2个数据是秒40
71 | int millisecond = Integer.parseInt(timeData[2]);//数组里的第3个数据是秒57
72 | return (((minute * 60) + second) * 1000) + (millisecond * 10);
73 | }
74 |
75 | public List GetLyricContent() {
76 | return LyricList;
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sms.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
25 |
26 |
36 |
37 |
38 |
39 |
44 |
45 |
55 |
56 |
66 |
67 |
68 |
69 |
70 |
71 |
76 |
77 |
82 |
83 |
90 |
91 |
98 |
99 |
100 |
105 |
106 |
107 |
108 |
109 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/led/SmsActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.led;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.view.View;
8 | import android.widget.EditText;
9 |
10 | import com.supets.pet.ledview.R;
11 | import com.supets.pet.module.sensor.BaseSmsActivity;
12 | import com.supets.pet.view.DateLedTextView;
13 | import com.supets.pet.view.LedTextView;
14 |
15 | import java.text.SimpleDateFormat;
16 | import java.util.Calendar;
17 | import java.util.Date;
18 |
19 | public class SmsActivity extends BaseSmsActivity {
20 |
21 |
22 | private DateLedTextView date_led;
23 | private LedTextView scroll_led;
24 | private LedTextView scroll_led1;
25 | private LedTextView time_led;
26 |
27 | private Handler handler;
28 |
29 | private EditText phone;
30 | private EditText msg;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_sms);
36 |
37 | date_led = findViewById(R.id.date_led);
38 | scroll_led = findViewById(R.id.scroll_led);
39 | scroll_led1 = findViewById(R.id.scroll_led1);
40 |
41 | msg(getIntent());
42 |
43 | time_led = findViewById(R.id.time_led);
44 | time_led.updateText("88:88");
45 |
46 | handler = new Handler(new Handler.Callback() {
47 | @Override
48 | public boolean handleMessage(Message message) {
49 | time_led.updateText(getStringDate());
50 | handler.sendEmptyMessageDelayed(0, 1000);
51 | return false;
52 | }
53 | });
54 |
55 | handler.sendEmptyMessageDelayed(0, 1000);
56 |
57 | phone = findViewById(R.id.phone);
58 | msg = findViewById(R.id.msg);
59 |
60 | findViewById(R.id.send).setOnClickListener(new View.OnClickListener() {
61 | @Override
62 | public void onClick(View view) {
63 | view.setEnabled(false);
64 | sendSms(phone.getText().toString(), msg.getText().toString());
65 | view.setEnabled(true);
66 | }
67 | });
68 |
69 | }
70 |
71 | private void msg(Intent intent) {
72 | String message = intent.getStringExtra("message");
73 | String phone = intent.getStringExtra("phone");
74 | if (message != null) {
75 | scroll_led1.updateText("from:" + phone);
76 | scroll_led.ForceupdateText(message);
77 | }
78 | }
79 |
80 | @Override
81 | protected void onNewIntent(Intent intent) {
82 | super.onNewIntent(intent);
83 | msg(intent);
84 | }
85 |
86 | @Override
87 | protected void onDestroy() {
88 | super.onDestroy();
89 | date_led.stopScroll();
90 | scroll_led.stopScroll();
91 | handler.removeMessages(0);
92 | }
93 |
94 | private boolean isShan = false;
95 |
96 | public String getStringDate() {
97 | Date currentTime = new Date();
98 | SimpleDateFormat formatter = new SimpleDateFormat(isShan ? "HH mm" : "HH:mm");
99 | isShan = !isShan;
100 | String dateString = formatter.format(currentTime);
101 | return dateString;
102 | }
103 |
104 | public String getAPM() {
105 | long time = System.currentTimeMillis();
106 | final Calendar mCalendar = Calendar.getInstance();
107 | mCalendar.setTimeInMillis(time);
108 | int apm = mCalendar.get(Calendar.AM_PM);
109 | return apm == 0 ? "AM" : "PM";
110 | }
111 |
112 | public String getMS() {
113 | Date currentTime = new Date();
114 | SimpleDateFormat formatter = new SimpleDateFormat("SSS");
115 | String dateString = formatter.format(currentTime);
116 | return dateString;
117 | }
118 |
119 | public static String getWeekOfDate(Date dt) {
120 | String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
121 | Calendar cal = Calendar.getInstance();
122 | cal.setTime(dt);
123 | int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
124 | if (w < 0)
125 | w = 0;
126 | return weekDays[w];
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lcd/LCD1602A.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lcd;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 |
10 | import com.supets.pet.ledview.R;
11 |
12 | public class LCD1602A extends android.support.v7.widget.AppCompatTextView {
13 |
14 |
15 | private static final int HANG=2;
16 | private static final int FONT_WIDTH=8;
17 | private static final int FONT_HEIGHT=16;
18 |
19 | private int dots = FONT_HEIGHT*HANG; //行数
20 | private float spacing = 0;//点阵之间的距离
21 | private float radius;//点阵中点的半径
22 |
23 | private Paint normalPaint;
24 | private Paint selectPaint;
25 |
26 | public String text;//显示文本
27 |
28 | private int paintColor = Color.GREEN;
29 |
30 | private ZiMo[][] ddram = new ZiMo[2][16];
31 |
32 | public LCD1602A(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LedTextView);
35 | int n = typedArray.getIndexCount();
36 | for (int i = 0; i < n; i++) {
37 | int attr = typedArray.getIndex(i);
38 | switch (attr) {
39 | case R.styleable.LedTextView_textColor:
40 | paintColor = typedArray.getColor(R.styleable.LedTextView_textColor, Color.GREEN);
41 | break;
42 | case R.styleable.LedTextView_spacing:
43 | spacing = typedArray.getDimension(R.styleable.LedTextView_spacing, 10);
44 | break;
45 | }
46 | }
47 | typedArray.recycle();
48 | selectPaint = new Paint();
49 | selectPaint.setStyle(Paint.Style.FILL);
50 | selectPaint.setColor(paintColor);
51 |
52 | normalPaint = new Paint();
53 | normalPaint.setStyle(Paint.Style.STROKE);
54 | normalPaint.setColor(Color.BLACK);
55 | }
56 |
57 |
58 | public LCD1602A(Context context, AttributeSet attrs) {
59 | this(context, attrs, 0);
60 | }
61 |
62 | public LCD1602A(Context context) {
63 | this(context, null, 0);
64 | }
65 |
66 | private void drawText(Canvas canvas, int xoffset, int yoffset, RGB[][] matrix) {
67 | radius = (getHeight() - (dots + 1) * spacing) / (2 * dots);
68 | // 行
69 | int row = 0;
70 | // 列
71 | int column = 0;
72 | while (getYPosition(row, yoffset) < getHeight()) {
73 | while (getXPosition(column, xoffset) < getWidth()) {
74 | // just draw
75 | if (row < matrix.length && column < matrix[0].length && matrix[row][column].light) {
76 | canvas.drawCircle(getXPosition(column, xoffset), getYPosition(row, yoffset), radius, selectPaint);
77 | }
78 | column++;
79 | }
80 | row++;
81 | column = 0;
82 | }
83 | }
84 |
85 | private float getXPosition(int column, int xoffset) {
86 | return spacing + radius + (spacing + 2 * radius) * (column + xoffset);
87 | }
88 |
89 | private float getYPosition(int row, int yoffset) {
90 | return spacing + radius + (spacing + 2 * radius) * (row + yoffset);
91 | }
92 |
93 | @Override
94 | protected void onDraw(Canvas canvas) {
95 | super.onDraw(canvas);
96 | for (int i = 0; i < ddram.length; i++) {
97 | for (int j = 0; j < ddram[0].length; j++) {
98 | ZiMo ziMo = ddram[i][j];
99 | if (ziMo != null && ziMo.pdata != null) {
100 | drawText(canvas, j * FONT_WIDTH, FONT_HEIGHT * i, ziMo.pdata);
101 | }
102 | }
103 | }
104 | }
105 |
106 |
107 | /**
108 | * 穿入传入单个字符
109 | *
110 | * @param line
111 | * @param column
112 | * @param str
113 | */
114 | public void setRam(int line, int column, String str) {
115 |
116 | if (line > 2 || column > 16 || column < 1 || line < 1) {
117 | return;
118 | }
119 | ddram[line - 1][column - 1] = new ZiMo(ZiMoUtuls.convert(str, getContext()));
120 |
121 | }
122 |
123 | public void refreshView() {
124 | postInvalidate();
125 | }
126 |
127 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bcd/MyView.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bcd;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.LinearGradient;
7 | import android.graphics.Paint;
8 | import android.graphics.Path;
9 | import android.graphics.RectF;
10 | import android.graphics.Shader;
11 | import android.view.View;
12 |
13 | import com.supets.pet.ledview.R;
14 |
15 | /* 自定义继承View 的MyView*/
16 | public class MyView extends View {
17 | public MyView(Context context) {
18 | super(context);
19 | }
20 |
21 | /*重写onDraw()*/
22 | @Override
23 | protected void onDraw(Canvas canvas) {
24 | super.onDraw(canvas);
25 | /*设置背景为白色*/
26 | canvas.drawColor(Color.WHITE);
27 | Paint paint = new Paint();
28 | /*去锯齿*/
29 | paint.setAntiAlias(true);
30 | /*设置paint的颜色*/
31 | paint.setColor(Color.RED);
32 | /*设置paint的 style 为STROKE:空心*/
33 | paint.setStyle(Paint.Style.STROKE);
34 | /*设置paint的外框宽度*/
35 | paint.setStrokeWidth(3);
36 | /*画一个空心圆形*/
37 | canvas.drawCircle(40, 40, 30, paint);
38 | /*画一个空心正方形*/
39 | canvas.drawRect(10, 90, 70, 150, paint);
40 | /*画一个空心长方形*/
41 | canvas.drawRect(10, 170, 70, 200, paint);
42 | /*画一个空心椭圆形*/
43 | RectF re = new RectF(10, 220, 70, 250);
44 | canvas.drawOval(re, paint);
45 | /*画一个空心三角形*/
46 | Path path = new Path();
47 | path.moveTo(10, 330);
48 | path.lineTo(70, 330);
49 | path.lineTo(40, 270);
50 | path.close();
51 | canvas.drawPath(path, paint);
52 | /*画一个空心梯形*/
53 | Path path1 = new Path();
54 | path1.moveTo(10, 410);
55 | path1.lineTo(70, 410);
56 | path1.lineTo(55, 350);
57 | path1.lineTo(25, 350);
58 | path1.close();
59 | canvas.drawPath(path1, paint);
60 |
61 | /*设置paint 的style为 FILL:实心*/
62 | paint.setStyle(Paint.Style.FILL);
63 | /*设置paint的颜色*/
64 | paint.setColor(Color.BLUE);
65 | /*画一个实心圆*/
66 | canvas.drawCircle(120, 40, 30, paint);
67 | /*画一个实心正方形*/
68 | canvas.drawRect(90, 90, 150, 150, paint);
69 | /*画一个实心长方形*/
70 | canvas.drawRect(90, 170, 150, 200, paint);
71 | /*画一个实心椭圆*/
72 | RectF re2 = new RectF(90, 220, 150, 250);
73 | canvas.drawOval(re2, paint);
74 | /*画一个实心三角形*/
75 | Path path2 = new Path();
76 | path2.moveTo(90, 330);
77 | path2.lineTo(150, 330);
78 | path2.lineTo(120, 270);
79 | path2.close();
80 | canvas.drawPath(path2, paint);
81 | /*画一个实心梯形*/
82 | Path path3 = new Path();
83 | path3.moveTo(90, 410);
84 | path3.lineTo(150, 410);
85 | path3.lineTo(135, 350);
86 | path3.lineTo(105, 350);
87 | path3.close();
88 | canvas.drawPath(path3, paint);
89 | /*设置渐变色*/
90 | Shader mShader = new LinearGradient(0, 0, 100, 100,
91 | new int[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW},
92 | null, Shader.TileMode.REPEAT);
93 | paint.setShader(mShader);
94 |
95 | /*画一个渐变色圆*/
96 | canvas.drawCircle(200, 40, 30, paint);
97 | /*画一个渐变色正方形*/
98 | canvas.drawRect(170, 90, 230, 150, paint);
99 | /*画一个渐变色长方形*/
100 | canvas.drawRect(170, 170, 230, 200, paint);
101 | /*画一个渐变色椭圆*/
102 | RectF re3 = new RectF(170, 220, 230, 250);
103 | canvas.drawOval(re3, paint);
104 | /*画一个渐变色三角形*/
105 | Path path4 = new Path();
106 | path4.moveTo(170, 330);
107 | path4.lineTo(230, 330);
108 | path4.lineTo(200, 270);
109 | path4.close();
110 | canvas.drawPath(path4, paint);
111 | /*画一个渐变色梯形*/
112 | Path path5 = new Path();
113 | path5.moveTo(170, 410);
114 | path5.lineTo(230, 410);
115 | path5.lineTo(215, 350);
116 | path5.lineTo(185, 350);
117 | path5.close();
118 | canvas.drawPath(path5, paint);
119 |
120 | /*写字*/
121 | paint.setTextSize(24);
122 | canvas.drawText(getResources().getString(R.string.str_text1), 240, 50, paint);
123 | canvas.drawText(getResources().getString(R.string.str_text2), 240, 120, paint);
124 | canvas.drawText(getResources().getString(R.string.str_text3), 240, 190, paint);
125 | canvas.drawText(getResources().getString(R.string.str_text4), 240, 250, paint);
126 | canvas.drawText(getResources().getString(R.string.str_text5), 240, 320, paint);
127 | canvas.drawText(getResources().getString(R.string.str_text6), 240, 390, paint);
128 | }
129 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.view.View;
7 | import android.widget.AdapterView;
8 | import android.widget.ListView;
9 |
10 | import com.supets.pet.bcd.GraphicesActivity;
11 | import com.supets.pet.ledview.R;
12 | import com.supets.pet.module.led.BusActivity;
13 | import com.supets.pet.module.led.DateTimeActivity;
14 | import com.supets.pet.module.led.LCD1602Activity;
15 | import com.supets.pet.module.led.MainAdapter;
16 | import com.supets.pet.module.led.SmsActivity;
17 | import com.supets.pet.module.led.TimeActivity;
18 | import com.supets.pet.module.led.WeatherInfoActivity;
19 | import com.supets.pet.module.sensor.BaseOrientationActivity;
20 | import com.supets.pet.module.sensor.CompassActivity;
21 | import com.supets.pet.module.sensor.LevelVialActivity;
22 | import com.supets.pet.module.sensor.LightActivity;
23 | import com.supets.pet.module.sensor.RotationLedActivity;
24 | import com.supets.pet.module.ttl.D74Activity;
25 |
26 | import java.util.ArrayList;
27 |
28 |
29 | public class MainActivity extends BaseOrientationActivity {
30 |
31 | private MainAdapter adapter;
32 | private ListView listView;
33 |
34 | @Override
35 | protected void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_main);
38 |
39 | listView = findViewById(R.id.list);
40 | adapter = new MainAdapter();
41 | ArrayList d = new ArrayList<>();
42 | d.add("时间");
43 | d.add("日期");
44 | d.add("短消息");
45 |
46 | d.add("北京天气");
47 | d.add("方向传感器-指南针");
48 | d.add("方向传感器-水平仪");
49 |
50 | d.add("光线传感器-旋转LED");
51 | d.add("光线/距离传感器-测量时间");
52 |
53 | d.add("428公交线路-天通北苑");
54 | d.add("428公交线路-龙泽地铁");
55 |
56 | d.add("LCD1602A");
57 | d.add("数字电路功能模拟");
58 |
59 | d.add("画不同形状");
60 |
61 | adapter.setData(d);
62 |
63 | listView.setAdapter(adapter);
64 |
65 |
66 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
67 | @Override
68 | public void onItemClick(AdapterView> adapterView, View view, int position, long id) {
69 | doWithButton(position);
70 | }
71 | });
72 |
73 |
74 | }
75 |
76 | private void doWithButton(int position) {
77 | switch (position + 1) {
78 | case 1:
79 | startActivity(new Intent(MainActivity.this, TimeActivity.class));
80 | break;
81 | case 2:
82 | startActivity(new Intent(MainActivity.this, DateTimeActivity.class));
83 | break;
84 | case 3:
85 | startActivity(new Intent(MainActivity.this, SmsActivity.class));
86 | break;
87 | case 4:
88 | startActivity(new Intent(MainActivity.this, WeatherInfoActivity.class));
89 | break;
90 | case 5:
91 | startActivity(new Intent(MainActivity.this, CompassActivity.class));
92 | break;
93 | case 6:
94 | startActivity(new Intent(MainActivity.this, LevelVialActivity.class));
95 | break;
96 | case 7:
97 | startActivity(new Intent(MainActivity.this, RotationLedActivity.class));
98 | break;
99 | case 8:
100 | startActivity(new Intent(MainActivity.this, LightActivity.class));
101 | break;
102 | case 9: {
103 | Intent intent = new Intent(MainActivity.this, BusActivity.class);
104 | intent.putExtra("status", false);
105 | startActivity(intent);
106 | }
107 | break;
108 | case 10: {
109 | Intent intent = new Intent(MainActivity.this, BusActivity.class);
110 | intent.putExtra("status", true);
111 | startActivity(intent);
112 | }
113 | break;
114 | case 11: {
115 | Intent intent = new Intent(MainActivity.this, LCD1602Activity.class);
116 | startActivity(intent);
117 | }
118 | break;
119 | case 12: {
120 | Intent intent = new Intent(MainActivity.this, D74Activity.class);
121 | startActivity(intent);
122 | }
123 | break;
124 | case 13: {
125 | Intent intent = new Intent(MainActivity.this, GraphicesActivity.class);
126 | startActivity(intent);
127 | }
128 | break;
129 | default:
130 | break;
131 | }
132 | }
133 |
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/LightActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 | import android.os.Bundle;
9 | import android.util.Log;
10 |
11 | import com.supets.pet.ledview.R;
12 | import com.supets.pet.sensor.ledPref;
13 | import com.supets.pet.view.LedTextView;
14 |
15 | public class LightActivity extends Activity implements SensorEventListener {
16 | private LedTextView time_led;
17 | private SensorManager mSensorManager;
18 |
19 | @Override
20 | public void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_weather);
23 | // 获取水平仪的主组件
24 | time_led = findViewById(R.id.time_led);
25 | // 获取传感器管理服务
26 | mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
27 | }
28 |
29 | @Override
30 | public void onResume() {
31 | super.onResume();
32 | // 为系统的方向传感器注册监听器
33 | mSensorManager.registerListener(this,
34 | mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY),
35 | SensorManager.SENSOR_DELAY_GAME);
36 | }
37 |
38 | @Override
39 | protected void onPause() {
40 | // 取消注册
41 | mSensorManager.unregisterListener(this);
42 | super.onPause();
43 | }
44 |
45 | @Override
46 | protected void onStop() {
47 | // 取消注册
48 | mSensorManager.unregisterListener(this);
49 | super.onStop();
50 | }
51 |
52 | private float fanzhi = 100;
53 |
54 | private long startTime = 0;
55 | private int H = 1;
56 | private int HOLD = 1;
57 | private int cha = 0;
58 |
59 | @Override
60 | public void onSensorChanged(SensorEvent sensorEvent) {
61 | dolight(sensorEvent);
62 | doJuli(sensorEvent);
63 | }
64 |
65 | public void doJuli(SensorEvent sensorEvent) {
66 | float[] its = sensorEvent.values;
67 | if (its != null && sensorEvent.sensor.getType() == Sensor.TYPE_PROXIMITY) {
68 | H = its[0] > 0 ? 1 : 0;
69 | if (HOLD != H) {
70 | if (HOLD == 1 && H == 0) {
71 | final long end = System.currentTimeMillis();
72 | if (startTime > 0) {
73 | if (cha > 0) {
74 |
75 | time_led.post(new Runnable() {
76 | @Override
77 | public void run() {
78 | time_led.ForceupdateText("T:" + (end - startTime));
79 | }
80 | });
81 | // time_led.ForceupdateText("T:" + (cha + end - startTime) / 2);
82 | cha = (int) ((cha + end - startTime) / 2);
83 | } else {
84 | cha = (int) (end - startTime);
85 | time_led.post(new Runnable() {
86 | @Override
87 | public void run() {
88 | time_led.ForceupdateText("T:" + (end - startTime));
89 | }
90 | });
91 | }
92 | ledPref.saveTime(cha);
93 | }
94 | startTime = end;
95 | }
96 | HOLD = H;
97 | Log.v("light", HOLD == 1 ? "H" : "L");
98 | }
99 | }
100 | }
101 |
102 |
103 | private void dolight(SensorEvent sensorEvent) {
104 | //获取精度
105 | float acc = sensorEvent.accuracy;
106 | //获取光线强度
107 | float lux = sensorEvent.values[0];
108 |
109 | H = lux > fanzhi ? 1 : 0;
110 |
111 | if (HOLD != H) {
112 | if (HOLD == 1 && H == 0) {
113 | long end = System.currentTimeMillis();
114 | if (startTime > 0) {
115 | if (cha > 0) {
116 | time_led.ForceupdateText("T:" + (end - startTime));
117 | // time_led.ForceupdateText("T:" + (cha + end - startTime) / 2);
118 | cha = (int) ((cha + end - startTime) / 2);
119 | } else {
120 | cha = (int) (end - startTime);
121 | time_led.ForceupdateText("T:" + (end - startTime));
122 | }
123 | }
124 | startTime = end;
125 | }
126 | HOLD = H;
127 | Log.v("light", HOLD == 1 ? "H" : "L");
128 | }
129 | }
130 |
131 | @Override
132 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
133 | }
134 |
135 |
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/module/sensor/LevelVialActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.module.sensor;
2 |
3 | import android.app.Activity;
4 | import android.hardware.Sensor;
5 | import android.hardware.SensorEvent;
6 | import android.hardware.SensorEventListener;
7 | import android.hardware.SensorManager;
8 | import android.os.Bundle;
9 |
10 | import com.supets.pet.ledview.R;
11 | import com.supets.pet.sensor.LevelVialView;
12 |
13 | public class LevelVialActivity extends Activity implements SensorEventListener {
14 | // 定义水平仪的仪表盘
15 | private LevelVialView show;
16 | // 定义水平仪能处理的最大倾斜角,超过该角度,气泡将直接在位于边界。
17 | private int MAX_ANGLE = 30;
18 | // 定义Sensor管理器
19 | SensorManager mSensorManager;
20 |
21 | @Override
22 | public void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_level);
25 | // 获取水平仪的主组件
26 | show = findViewById(R.id.show);
27 | // 获取传感器管理服务
28 | mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
29 | }
30 |
31 | @Override
32 | public void onResume() {
33 | super.onResume();
34 | // 为系统的方向传感器注册监听器
35 | mSensorManager.registerListener(this,
36 | mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
37 | SensorManager.SENSOR_DELAY_GAME);
38 | }
39 |
40 | @Override
41 | protected void onPause() {
42 | // 取消注册
43 | mSensorManager.unregisterListener(this);
44 | super.onPause();
45 | }
46 |
47 | @Override
48 | protected void onStop() {
49 | // 取消注册
50 | mSensorManager.unregisterListener(this);
51 | super.onStop();
52 | }
53 |
54 |
55 | @Override
56 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
57 | }
58 |
59 | // 计算x、y点的气泡是否处于水平仪的仪表盘内
60 | private boolean isContain(int x, int y) {
61 | // 计算气泡的圆心座标X、Y
62 | int bubbleCx = x + show.bubble.getWidth() / 2;
63 | int bubbleCy = y + show.bubble.getWidth() / 2;
64 | // 计算水平仪仪表盘的圆心座标X、Y
65 | int backCx = show.back.getWidth() / 2;
66 | int backCy = show.back.getWidth() / 2;
67 | // 计算气泡的圆心与水平仪仪表盘的圆心之间的距离。
68 | double distance = Math.sqrt((bubbleCx - backCx) * (bubbleCx - backCx)
69 | + (bubbleCy - backCy) * (bubbleCy - backCy));
70 | // 若两个圆心的距离小于它们的半径差,即可认为处于该点的气泡依然位于仪表盘内
71 | if (distance < (show.back.getWidth() - show.bubble.getWidth()) / 2) {
72 | return true;
73 | } else {
74 | return false;
75 | }
76 | }
77 |
78 | @Override
79 | public void onSensorChanged(SensorEvent event) {
80 | float[] values = event.values;
81 | // 获取触发event的传感器类型
82 | int sensorType = event.sensor.getType();
83 | switch (sensorType) {
84 | case Sensor.TYPE_ORIENTATION:
85 | // 获取与Y轴的夹角
86 | float yAngle = values[1];
87 | // 获取与Z轴的夹角
88 | float zAngle = values[2];
89 | // 气泡位于中间时(水平仪完全水平),气泡的X、Y座标
90 | int x = (show.back.getWidth() - show.bubble.getWidth()) / 2;
91 | int y = (show.back.getHeight() - show.bubble.getHeight()) / 2;
92 | // 如果与Z轴的倾斜角还在最大角度之内
93 | if (Math.abs(zAngle) <= MAX_ANGLE) {
94 | // 根据与Z轴的倾斜角度计算X座标的变化值(倾斜角度越大,X座标变化越大)
95 | int deltaX = (int) ((show.back.getWidth() - show.bubble
96 | .getWidth()) / 2 * zAngle / MAX_ANGLE);
97 | x += deltaX;
98 | }
99 | // 如果与Z轴的倾斜角已经大于MAX_ANGLE,气泡应到最左边
100 | else if (zAngle > MAX_ANGLE) {
101 | x = 0;
102 | }
103 | // 如果与Z轴的倾斜角已经小于负的MAX_ANGLE,气泡应到最右边
104 | else {
105 | x = show.back.getWidth() - show.bubble.getWidth();
106 | }
107 | // 如果与Y轴的倾斜角还在最大角度之内
108 | if (Math.abs(yAngle) <= MAX_ANGLE) {
109 | // 根据与Y轴的倾斜角度计算Y座标的变化值(倾斜角度越大,Y座标变化越大)
110 | int deltaY = (int) ((show.back.getHeight() - show.bubble
111 | .getHeight()) / 2 * yAngle / MAX_ANGLE);
112 | y += deltaY;
113 | }
114 | // 如果与Y轴的倾斜角已经大于MAX_ANGLE,气泡应到最下边
115 | else if (yAngle > MAX_ANGLE) {
116 | y = show.back.getHeight() - show.bubble.getHeight();
117 | }
118 | // 如果与Y轴的倾斜角已经小于负的MAX_ANGLE,气泡应到最右边
119 | else {
120 | y = 0;
121 | }
122 | // 如果计算出来的X、Y座标还位于水平仪的仪表盘内,更新水平仪的气泡座标
123 | if (isContain(x, y)) {
124 | show.bubbleX = x;
125 | show.bubbleY = y;
126 | }
127 | // 通知系统重回MyView组件
128 | show.postInvalidate();
129 | break;
130 | }
131 | }
132 |
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/bcd/MyView2.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.bcd;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.graphics.Path;
7 | import android.graphics.Point;
8 | import android.os.Build;
9 | import android.support.annotation.Nullable;
10 | import android.support.annotation.RequiresApi;
11 | import android.util.AttributeSet;
12 | import android.view.View;
13 |
14 | import com.supets.pet.ledview.R;
15 |
16 | import java.util.Calendar;
17 | import java.util.Date;
18 |
19 | /* 自定义继承View 的MyView*/
20 | public class MyView2 extends View {
21 |
22 |
23 | private int fontcolor = getContext().getResources().getColor(R.color.bcd_color);
24 | private int fontbackcolor = getContext().getResources().getColor(R.color.bcd_backcolor);
25 |
26 |
27 | public MyView2(Context context) {
28 | super(context);
29 | }
30 |
31 | public MyView2(Context context, @Nullable AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | public MyView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | }
38 |
39 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
40 | public MyView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
41 | super(context, attrs, defStyleAttr, defStyleRes);
42 | }
43 |
44 | @Override
45 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
46 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
47 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), (int) (MeasureSpec.getSize(widthMeasureSpec) * 6f / 22));
48 | }
49 |
50 | @Override
51 | protected void onDraw(Canvas canvas) {
52 | super.onDraw(canvas);
53 |
54 | // canvas.drawColor(fontbackcolor);
55 |
56 | Paint paint = new Paint();
57 | paint.setAntiAlias(true);
58 | paint.setStrokeWidth(3);
59 |
60 | int P = getWidth() / 22;
61 |
62 | drawBCD(canvas, paint,P);
63 | drawampm(canvas, paint, P);
64 | drawdian(canvas, paint, P);
65 | }
66 |
67 | private void drawampm(Canvas canvas, Paint paint, int p) {
68 | paint.setTextSize(p);
69 | paint.setColor(fontcolor);
70 |
71 | if (ampm==0) {
72 | canvas.drawText("AM", (float) (0.5 * p), p + p / 2, paint);
73 | } else if (ampm==1){
74 | canvas.drawText("PM", (float) (0.5 * p), p + 4 * p, paint);
75 | }else {
76 | canvas.drawText("PM", (float) (0.5 * p), p + 4 * p, paint);
77 | canvas.drawText("AM", (float) (0.5 * p), p + p / 2, paint);
78 | }
79 | }
80 |
81 | private void drawdian(Canvas canvas, Paint paint, int p) {
82 | if (dian) {
83 | paint.setColor(fontcolor);
84 | paint.setStyle(Paint.Style.FILL);
85 | canvas.drawCircle(13 * p, (float) (1.5 * p), (float) (0.5 * p), paint);
86 | canvas.drawCircle(13 * p, (float) (4.5 * p), (float) (0.5 * p), paint);
87 | }else if (isshowKong){
88 | paint.setColor(fontcolor);
89 | paint.setStyle(Paint.Style.STROKE);
90 | canvas.drawCircle(13 * p, (float) (1.5 * p), (float) (0.5 * p), paint);
91 | canvas.drawCircle(13 * p, (float) (4.5 * p), (float) (0.5 * p), paint);
92 | }
93 | }
94 |
95 | private void drawBCD(Canvas canvas, Paint paint,int P) {
96 |
97 | Point[] xy = new Point[]{
98 | new Point(4 * P, (int) (0.4 * P)),
99 | new Point((int) (8.5 * P), (int) (0.4 * P)),
100 | new Point((int) (14.5 * P), (int) (0.4 * P)),
101 | new Point(19 * P, (int) (0.4 * P)),
102 | };
103 |
104 |
105 | for (int j = 0; j < 4; j++) {
106 | Point point = xy[j];
107 | Path[] path2 = BCD.buildBCD(getWidth(), point.x, point.y);
108 | for (int i = 0; i < 7; i++) {
109 | Path d = path2[i];
110 | boolean is = BCD.isBitLight(BCD.getNum(rom[j]), i);
111 | if (is ) {
112 | paint.setStyle(Paint.Style.FILL);
113 | paint.setColor(fontcolor);
114 | canvas.drawPath(d, paint);
115 | } else if (isshowKong){
116 | paint.setStyle(Paint.Style.STROKE);
117 | paint.setColor(fontcolor);
118 | canvas.drawPath(d, paint);
119 |
120 | }
121 | }
122 | }
123 | }
124 |
125 |
126 | private int[] rom = new int[]{8, 8, 8, 8};
127 | private boolean dian = true;
128 | private int ampm = 2;
129 |
130 | private boolean isshowKong=false;
131 |
132 |
133 | public void updateData() {
134 | Calendar calendar = Calendar.getInstance();
135 | calendar.setTime(new Date());
136 | int shi = calendar.get(Calendar.HOUR);
137 | int miao = calendar.get(Calendar.MINUTE);
138 |
139 | dian = !dian;
140 |
141 | rom[0] = shi / 10;
142 | rom[1] = shi % 10;
143 | rom[2] = miao / 10;
144 | rom[3] = miao % 10;
145 |
146 | ampm = calendar.get(Calendar.AM_PM);
147 |
148 | postInvalidate();
149 | }
150 |
151 |
152 | }
--------------------------------------------------------------------------------
/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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
49 |
53 |
57 |
60 |
63 |
66 |
70 |
74 |
77 |
80 |
84 |
87 |
90 |
93 |
96 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/weather/WeatherApi.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.weather;
2 |
3 | import com.supets.pet.utils.JSonUtil;
4 | import com.zhy.http.okhttp.OkHttpUtils;
5 | import com.zhy.http.okhttp.callback.StringCallback;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import okhttp3.Call;
11 |
12 | /**
13 | * LedView
14 | *
15 | * @user lihongjiang
16 | * @description
17 | * @date 2017/8/22
18 | * @updatetime 2017/8/22
19 | */
20 |
21 | public class WeatherApi {
22 |
23 | public static List weatherData = new ArrayList<>();
24 |
25 | public static String city = "北京:101010100朝阳:101010300顺义:101010400怀柔:101010500通州:101010600昌平:101010700延庆:101010800丰台:101010900石景山:101011000大兴:101011100房山:101011200密云:101011300门头沟:101011400平谷:101011500八达岭:101011600佛爷顶:101011700汤河口:101011800密云上甸子:101011900斋堂:101012000霞云岭:101012100北京城区:101012200海淀:101010200天津:101030100宝坻:101030300东丽:101030400西青:101030500北辰:101030600蓟县:101031400汉沽:101030800静海:101030900津南:101031000塘沽:101031100大港:101031200武清:101030200宁河:101030700上海:101020100宝山:101020300嘉定:101020500南汇:101020600浦东:101021300青浦:101020800松江:101020900奉贤:101021000崇明:101021100徐家汇:101021200闵行:101020200金山:101020700石家庄:101090101张家口:101090301承德:101090402唐山:101090501秦皇岛:101091101沧州:101090701衡水:101090801邢台:101090901邯郸:101091001保定:101090201廊坊:101090601郑州:101180101新乡:101180301许昌:101180401平顶山:101180501信阳:101180601南阳:101180701开封:101180801洛阳:101180901商丘:101181001焦作:101181101鹤壁:101181201濮阳:101181301周口:101181401漯河:101181501驻马店:101181601三门峡:101181701济源:101181801安阳:101180201合肥:101220101芜湖:101220301淮南:101220401马鞍山:101220501安庆:101220601宿州:101220701阜阳:101220801亳州:101220901黄山:101221001滁州:101221101淮北:101221201铜陵:101221301宣城:101221401六安:101221501巢湖:101221601池州:101221701蚌埠:101220201杭州:101210101舟山:101211101湖州:101210201嘉兴:101210301金华:101210901绍兴:101210501台州:101210601温州:101210701丽水:101210801衢州:101211001宁波:101210401重庆:101040100合川:101040300南川:101040400江津:101040500万盛:101040600渝北:101040700北碚:101040800巴南:101040900长寿:101041000黔江:101041100万州天城:101041200万州龙宝:101041300涪陵:101041400开县:101041500城口:101041600云阳:101041700巫溪:101041800奉节:101041900巫山:101042000潼南:101042100垫江:101042200梁平:101042300忠县:101042400石柱:101042500大足:101042600荣昌:101042700铜梁:101042800璧山:101042900丰都:101043000武隆:101043100彭水:101043200綦江:101043300酉阳:101043400秀山:101043600沙坪坝:101043700永川:101040200福州:101230101泉州:101230501漳州:101230601龙岩:101230701晋江:101230509南平:101230901厦门:101230201宁德:101230301莆田:101230401三明:101230801兰州:101160101平凉:101160301庆阳:101160401武威:101160501金昌:101160601嘉峪关:101161401酒泉:101160801天水:101160901武都:101161001临夏:101161101合作:101161201白银:101161301定西:101160201张掖:101160701广州:101280101惠州:101280301梅州:101280401汕头:101280501深圳:101280601珠海:101280701佛山:101280800肇庆:101280901湛江:101281001江门:101281101河源:101281201清远:101281301云浮:101281401潮州:101281501东莞:101281601中山:101281701阳江:101281801揭阳:101281901茂名:101282001汕尾:101282101韶关:101280201南宁:101300101柳州:101300301来宾:101300401桂林:101300501梧州:101300601防城港:101301401贵港:101300801玉林:101300901百色:101301001钦州:101301101河池:101301201北海:101301301崇左:101300201贺州:101300701贵阳:101260101安顺:101260301都匀:101260401兴义:101260906铜仁:101260601毕节:101260701六盘水:101260801遵义:101260201凯里:101260501昆明:101290101红河:101290301文山:101290601玉溪:101290701楚雄:101290801普洱:101290901昭通:101291001临沧:101291101怒江:101291201香格里拉:101291301丽江:101291401德宏:101291501景洪:101291601大理:101290201曲靖:101290401保山:101290501呼和浩特:101080101乌海:101080301集宁:101080401通辽:101080501阿拉善左旗:101081201鄂尔多斯:101080701临河:101080801锡林浩特:101080901呼伦贝尔:101081000乌兰浩特:101081101包头:101080201赤峰:101080601南昌:101240101上饶:101240301抚州:101240401宜春:101240501鹰潭:101241101赣州:101240701景德镇:101240801萍乡:101240901新余:101241001九江:101240201吉安:101240601武汉:101200101黄冈:101200501荆州:101200801宜昌:101200901恩施:101201001十堰:101201101神农架:101201201随州:101201301荆门:101201401天门:101201501仙桃:101201601潜江:101201701襄樊:101200201鄂州:101200301孝感:101200401黄石:101200601咸宁:101200701成都:101270101自贡:101270301绵阳:101270401南充:101270501达州:101270601遂宁:101270701广安:101270801巴中:101270901泸州:101271001宜宾:101271101内江:101271201资阳:101271301乐山:101271401眉山:101271501凉山:101271601雅安:101271701甘孜:101271801阿坝:101271901德阳:101272001广元:101272101攀枝花:101270201银川:101170101中卫:101170501固原:101170401石嘴山:101170201吴忠:101170301西宁:101150101黄南:101150301海北:101150801果洛:101150501玉树:101150601海西:101150701海东:101150201海南:101150401济南:101120101潍坊:101120601临沂:101120901菏泽:101121001滨州:101121101东营:101121201威海:101121301枣庄:101121401日照:101121501莱芜:101121601聊城:101121701青岛:101120201淄博:101120301德州:101120401烟台:101120501济宁:101120701泰安:101120801西安:101110101延安:101110300榆林:101110401铜川:101111001商洛:101110601安康:101110701汉中:101110801宝鸡:101110901咸阳:101110200渭南:101110501太原:101100101临汾:101100701运城:101100801朔州:101100901忻州:101101001长治:101100501大同:101100201阳泉:101100301晋中:101100401晋城:101100601吕梁:101101100乌鲁木齐:101130101石河子:101130301昌吉:101130401吐鲁番:101130501库尔勒:101130601阿拉尔:101130701阿克苏:101130801喀什:101130901伊宁:101131001塔城:101131101哈密:101131201和田:101131301阿勒泰:101131401阿图什:101131501博乐:101131601克拉玛依:101130201拉萨:101140101山南:101140301阿里:101140701昌都:101140501那曲:101140601日喀则:101140201林芝:101140401台北县:101340101高雄:101340201台中:101340401海口:101310101三亚:101310201东方:101310202临高:101310203澄迈:101310204儋州:101310205昌江:101310206白沙:101310207琼中:101310208定安:101310209屯昌:101310210琼海:101310211文昌:101310212保亭:101310214万宁:101310215陵水:101310216西沙:101310217南沙岛:101310220乐东:101310221五指山:101310222琼山:101310102长沙:101250101株洲:101250301衡阳:101250401郴州:101250501常德:101250601益阳:101250700娄底:101250801邵阳:101250901岳阳:101251001张家界:101251101怀化:101251201黔阳:101251301永州:101251401吉首:101251501湘潭:101250201南京:101190101镇江:101190301苏州:101190401南通:101190501扬州:101190601宿迁:101191301徐州:101190801淮安:101190901连云港:101191001常州:101191101泰州:101191201无锡:101190201盐城:101190701哈尔滨:101050101牡丹江:101050301佳木斯:101050401绥化:101050501黑河:101050601双鸭山:101051301伊春:101050801大庆:101050901七台河:101051002鸡西:101051101鹤岗:101051201齐齐哈尔:101050201大兴安岭:101050701长春:101060101延吉:101060301四平:101060401白山:101060901白城:101060601辽源:101060701松原:101060801吉林:101060201通化:101060501沈阳:101070101鞍山:101070301抚顺:101070401本溪:101070501丹东:101070601葫芦岛:101071401营口:101070801阜新:101070901辽阳:101071001铁岭:101071101朝阳:101071201盘锦:101071301大连:101070201锦州:101070701";
26 |
27 | {
28 | while (city.indexOf(":") != -1) {
29 | String sub = city.substring(0, city.indexOf(":") + 10);
30 | weatherData.add(sub);
31 | System.out.println(sub);
32 | city = city.replace(sub, "");
33 | }
34 | }
35 |
36 |
37 | public static void main(String[] args) {
38 | System.out.print(WeatherApi.weatherData.size() + "");
39 | }
40 |
41 | public static void requestWeather(String city, final WeatherCallBack callBack) {
42 | String url = "http://www.sojson.com/open/api/weather/json.shtml?city=" + city ;
43 | OkHttpUtils.get().url(url)
44 | .build()
45 | .execute(new StringCallback() {
46 | @Override
47 | public void onError(Call call, Exception e, int i) {
48 | callBack.onFaill();
49 | }
50 |
51 | @Override
52 | public void onResponse(String s, int i) {
53 | WeatherInfo info = JSonUtil.fromJson(s, WeatherInfo.class);
54 | if (info!=null&&info.status==200){
55 | callBack.onSuccess(info);
56 | }else{
57 | callBack.onFaill();
58 | }
59 | }
60 | });
61 | }
62 |
63 | public interface WeatherCallBack {
64 | void onSuccess(WeatherInfo info);
65 |
66 | void onFaill();
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_lcd1602.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
22 |
23 |
29 |
30 |
34 |
35 |
43 |
44 |
52 |
53 |
61 |
62 |
63 |
67 |
68 |
76 |
77 |
85 |
86 |
94 |
95 |
96 |
100 |
101 |
109 |
110 |
118 |
119 |
127 |
128 |
129 |
130 |
136 |
137 |
141 |
142 |
150 |
151 |
152 |
156 |
157 |
165 |
166 |
167 |
171 |
172 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/view/ChatUtils.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.view;
2 |
3 | import android.content.Context;
4 | import android.os.Build;
5 | import android.support.annotation.RequiresApi;
6 |
7 | import java.io.InputStream;
8 | import java.io.UnsupportedEncodingException;
9 | import java.util.ArrayList;
10 |
11 | public class ChatUtils {
12 |
13 | public static void main(String[] args) {
14 | String[] strArr = new String[]{
15 | "www.micmiu.com",
16 | "!@#$%^&*()_+{}[]|\"'?/:;<>,.",
17 | "!¥……()——:;“”‘’《》,。?、",
18 | "不要啊",
19 | "やめて",
20 | "韩佳人",
21 | "???"};
22 | for (String str : strArr) {
23 | char[] ch = str.toCharArray();
24 | for (int i = 0; i < ch.length; i++) {
25 | char c = ch[i];
26 | System.out.println("ASCII判断结果 :" + (isAscii(c) ? "是" : "否"));
27 | System.out.println("Unicode判断结果 :" + (isChinese(c) ? "是" : "否"));
28 | }
29 | }
30 | }
31 |
32 | // 根据Unicode编码完美的判断中文汉字和符号
33 | private static boolean isChinese(char c) {
34 | Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
35 | if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
36 | || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
37 | || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
38 | || ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B
39 | || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
40 | || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
41 | || ub == Character.UnicodeBlock.GENERAL_PUNCTUATION) {
42 | return true;
43 | }
44 | return false;
45 | }
46 |
47 | // 根据Unicode编码完美的判断英文和ASCII
48 | private static boolean isAscii(char c) {
49 | Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
50 | if (ub == Character.UnicodeBlock.BASIC_LATIN
51 | || ub == Character.UnicodeBlock.LATIN_1_SUPPLEMENT) {
52 | return true;
53 | }
54 | return false;
55 | }
56 |
57 | // 完整的判断中文汉字和符号
58 | public static boolean isChinese(String strName) {
59 | char[] ch = strName.toCharArray();
60 | for (int i = 0; i < ch.length; i++) {
61 | char c = ch[i];
62 | if (isChinese(c)) {
63 | return true;
64 | }
65 | }
66 | return false;
67 | }
68 |
69 | @RequiresApi(api = Build.VERSION_CODES.KITKAT)
70 | private static boolean isChinesePuctuation(char c) {
71 | Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
72 | if (ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
73 | || ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
74 | || ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS
75 | || ub == Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS
76 | || ub == Character.UnicodeBlock.VERTICAL_FORMS) {//jdk1.7
77 | return true;
78 | }
79 | return false;
80 | }
81 |
82 | @RequiresApi(api = Build.VERSION_CODES.N)
83 | private static boolean isChineseByScript(char c) {
84 | Character.UnicodeScript sc = Character.UnicodeScript.of(c);
85 | if (sc == Character.UnicodeScript.HAN) {
86 | return true;
87 | }
88 | return false;
89 | }
90 |
91 | public static ArrayList auto(Context context, String input) {
92 |
93 | ArrayList sparseArray = new ArrayList<>();
94 |
95 | char[] ch = input.toCharArray();
96 | for (int i = 0; i < ch.length; i++) {
97 | char c = ch[i];
98 | // System.out.println("ASCII判断结果 :" + (isAscii(c) ? "是" : "否"));
99 | // System.out.println("Unicode判断结果 :" + (isChinese(c) ? "是" : "否"));
100 | if (isAscii(c)) {
101 | byte[] temp = readAscii(context, c);
102 | if (temp != null) {
103 | sparseArray.add(temp);
104 | }
105 | }
106 | if (isChinese(c)) {
107 |
108 | try {
109 | byte[] bytes = String.valueOf(c).getBytes("GB2312");
110 | int areacode = bytes[0] < 0 ? 256 + bytes[0] : bytes[0];//区码
111 | int poscode = bytes[1] < 0 ? 256 + bytes[1] : bytes[1];//位码
112 | byte[] temp = readHan(context, areacode, poscode);
113 | if (temp != null) {
114 | sparseArray.add(temp);
115 | }
116 | } catch (UnsupportedEncodingException e) {
117 | e.printStackTrace();
118 | }
119 |
120 | // byte[] bytes = charToByte(c);
121 |
122 | }
123 | }
124 | return sparseArray;
125 | }
126 |
127 | private static byte[] charToByte(char c) {
128 | byte[] b = new byte[2];
129 | b[0] = (byte) ((c & 0xFF00) >> 8);
130 | b[1] = (byte) (c & 0xFF);
131 | return b;
132 | }
133 |
134 | private static byte[] readAscii(Context context, char ascii) {
135 | byte[] data = null;
136 | try {
137 | InputStream in = context.getResources().getAssets().open("ASC16");
138 | int offset = ascii * 16;
139 | in.skip(offset);
140 | data = new byte[16];
141 | in.read(data);
142 | in.close();
143 | } catch (Exception ex) {
144 | ex.printStackTrace();
145 | }
146 | return data;
147 | }
148 |
149 | private static byte[] readHan(Context context, int areaCode, int posCode) {
150 | byte[] data = null;
151 | try {
152 | int area = areaCode - 0xa0;
153 | int pos = posCode - 0xa0;
154 | InputStream in = context.getResources().getAssets().open("HZK16");
155 | long offset = 32 * ((area - 1) * 94 + pos - 1);
156 | in.skip(offset);
157 | data = new byte[32];
158 | in.read(data, 0, 32);
159 | in.close();
160 | } catch (Exception ex) {
161 | ex.printStackTrace();
162 | }
163 | return data;
164 | }
165 |
166 | public static boolean[][] getDisplayCache(ArrayList list, int SCALE) {
167 |
168 | int totalDots = 0;//每行点数=字宽之和
169 | for (byte[] temp : list) {
170 | totalDots += (temp.length/2);
171 | }
172 |
173 | boolean[][] matrix = new boolean[16 * SCALE][totalDots * SCALE];
174 |
175 | for (int num = 0; num < list.size(); num++) {//显示字数
176 | byte[] word = list.get(num);
177 | for (int i = 0; i < 16; i++) {//字符高度16
178 | int wordWidth = word.length / 16;
179 | for (int j1 = 0; j1 < wordWidth; j1++) {//一个字节行循环
180 | byte tmp = word[i * wordWidth + j1];
181 | for (int j2 = 0; j2 < 8; j2++) {
182 |
183 | //起始点X 坐标
184 | int length = 0;
185 | for (int x = 0; x < num; x++) {
186 | length += (list.get(x).length / 16) * 8;
187 | }
188 |
189 | if (((tmp >> (7 - j2)) & 1) == 1) {
190 | for (int m = 0; m < SCALE; m++) {
191 | for (int n = 0; n < SCALE; n++) {
192 | matrix[i * SCALE + m][(length+ j1 * 8 + j2) * SCALE + n] = true;
193 | }
194 | }
195 | } else {
196 | for (int m = 0; m < SCALE; m++) {
197 | for (int n = 0; n < SCALE; n++) {
198 | matrix[i * SCALE + m][(length + j1 * 8 + j2) * SCALE + n] = false;
199 | }
200 | }
201 | }
202 | }
203 | }
204 | }
205 | }
206 |
207 | return matrix;
208 |
209 | }
210 |
211 | public static boolean[][] convert(String auto,Context context){
212 | return getDisplayCache(auto(context,auto),1);
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/lrc/LrcMainActivity.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.lrc;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.media.MediaPlayer;
6 | import android.net.Uri;
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.util.Log;
11 | import android.view.View;
12 | import android.widget.Button;
13 | import android.widget.FrameLayout;
14 | import android.widget.ImageView;
15 | import android.widget.RelativeLayout;
16 | import android.widget.SeekBar;
17 | import android.widget.TextView;
18 |
19 | import com.supets.pet.ledview.R;
20 |
21 | import java.io.IOException;
22 | import java.util.Timer;
23 | import java.util.TimerTask;
24 |
25 | public class LrcMainActivity extends Activity { //播放状态 暂定或正在播放
26 | private boolean isPlay = false; //播放按钮 屏幕下方控制栏中
27 | private Button mPlayBtn; //播放进度 屏幕下方控制栏中
28 | private SeekBar mPlaySeekBar; //点击事件
29 | private MyOnClickListener myOnClickListener = new MyOnClickListener(); //MediaPlayer
30 | private MediaPlayer mMediaPlayer; //mp3链接 修改成可以播放的就行
31 | private String mP3Url = "https://raw.githubusercontent.com/supets-open/LedView/master/app/src/main/res/raw/czt.mp3";
32 | private Uri uri = null; //定时器 由于功能中有付费播放功能,需要定时器来判断
33 | private Timer mTimer = null;
34 | private TimerTask mTimerTask = null; //互斥变量,防止定时器与SeekBar拖动时进度冲突
35 | private boolean isChanging = false; //当前播放时间与总时间
36 | private TextView mNowText, mTotalText; //下方控制栏
37 | private RelativeLayout mControlLayout; //上方标题栏 显示mp3标题
38 | private RelativeLayout mTitleLayout; //试看结束提示
39 | private TextView mWarnText; //刚开始显示播放按钮 屏幕中间的播放按钮
40 | private ImageView mPlayImg; //整个屏幕
41 | private FrameLayout mFrame; //控制栏与标题栏是否显示 默认不显示
42 | private boolean isShow = false; //试看时间 三分钟
43 | private static int TRY_TIME = 3 * 60 * 1000; //Handler用来控制时间与播放
44 | @SuppressLint("HandlerLeak")
45 | private Handler mHandler = new Handler() {
46 | @Override
47 | public void handleMessage(Message msg) {
48 | super.handleMessage(msg);
49 | switch (msg.what) {
50 | case 0: //如果大于试看时间 停止播放,控制栏与标题栏隐藏,屏幕不让点击(防止弹出控制栏与标题栏)提示试看结束。
51 | if (mMediaPlayer.getCurrentPosition() >= TRY_TIME) {
52 | if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
53 | mMediaPlayer.stop();
54 | mFrame.setEnabled(false);
55 | isShow = false;
56 | mControlLayout.setVisibility(View.GONE);
57 | mTitleLayout.setVisibility(View.GONE);
58 | mWarnText.setVisibility(View.VISIBLE);
59 | }
60 | } //设置当前播放进度
61 | mNowText.setText(generateTime(mMediaPlayer.getCurrentPosition()) + "/");
62 | break;
63 | case 1: //当用户点击屏幕时 标题栏与控制栏显示,并在无操作的三秒后消失。
64 | mControlLayout.setVisibility(View.GONE);
65 | mTitleLayout.setVisibility(View.GONE);
66 | isShow = false;
67 | break;
68 | }
69 | }
70 | };
71 |
72 | @Override
73 | protected void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 | setContentView(R.layout.activity_lrc);
76 | mMediaPlayer = new MediaPlayer();
77 | mPlayBtn = (Button) findViewById(R.id.player_button);
78 | mPlayBtn.setOnClickListener(myOnClickListener);
79 | mPlaySeekBar = (SeekBar) findViewById(R.id.player_seek);
80 | mPlaySeekBar.setOnSeekBarChangeListener(new MySeekbar());
81 | mNowText = (TextView) findViewById(R.id.player_left);
82 | mTotalText = (TextView) findViewById(R.id.player_right);
83 | mWarnText = (TextView) findViewById(R.id.player_warn);
84 | mControlLayout = (RelativeLayout) findViewById(R.id.player_control);
85 | mTitleLayout = (RelativeLayout) findViewById(R.id.player_title);
86 | mPlayImg = (ImageView) findViewById(R.id.player_img2);
87 | mPlayImg.setOnClickListener(myOnClickListener); //点击屏幕 显示底部
88 | mFrame = (FrameLayout) findViewById(R.id.player_frame);
89 | mFrame.setOnClickListener(myOnClickListener);
90 | mPlayImg.setEnabled(false);
91 | uri = Uri.parse(mP3Url); //准备播放
92 | play(uri); //播放完成事件
93 | mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
94 | @Override
95 | public void onCompletion(MediaPlayer mediaPlayer) { //进度归零
96 | mediaPlayer.seekTo(0); //进度条归零 mPlaySeekBar.setProgress(0); //控制栏中的播放按钮显示暂停状态
97 | mPlayBtn.setBackground(getResources().getDrawable(R.mipmap.simple_player_center_play));
98 | isPlay = false; //重置并准备重新播放
99 | mediaPlayer.reset();
100 | play(uri);
101 | }
102 | }); //异步准备(准备完成),准备到准备完成期间可以显示进度条之类的东西。
103 | mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
104 | @Override
105 | public void onPrepared(MediaPlayer mediaPlayer) {
106 | mPlaySeekBar.setProgress(0);
107 | mPlayImg.setEnabled(true);
108 | mNowText.setText("00:00/");
109 | mTotalText.setText(generateTime(mMediaPlayer.getDuration() + 1000));
110 | mPlaySeekBar.setMax(mMediaPlayer.getDuration() + 1000);//设置进度条
111 | }
112 | });
113 | }
114 |
115 | public void play(Uri uri) {
116 | try {
117 | mMediaPlayer.setDataSource(LrcMainActivity.this, uri); //采用异步准备,使用prepare方法时,用户进入该界面需要等待几秒,如同死机一般,,,
118 | mMediaPlayer.prepareAsync();
119 | } catch (IOException e) {
120 | e.printStackTrace();
121 | }
122 | } //进度条的进度变化事件
123 |
124 | class MySeekbar implements SeekBar.OnSeekBarChangeListener { //当进度条变化时触发
125 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
126 | } //开始拖拽进度条
127 |
128 | public void onStartTrackingTouch(SeekBar seekBar) {
129 | isChanging = true;
130 | } //停止拖拽进度条
131 |
132 | public void onStopTrackingTouch(SeekBar seekBar) {
133 | mMediaPlayer.seekTo(mPlaySeekBar.getProgress());
134 | mNowText.setText(generateTime(mMediaPlayer.getCurrentPosition()) + "/");
135 | isChanging = false;
136 | if (mMediaPlayer.getCurrentPosition() >= TRY_TIME) { //大于试看时间 停止播放
137 | if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
138 | mMediaPlayer.stop();
139 | mFrame.setEnabled(false);
140 | isShow = false;
141 | mControlLayout.setVisibility(View.GONE);
142 | mTitleLayout.setVisibility(View.GONE);
143 | mWarnText.setVisibility(View.VISIBLE);
144 | }
145 | } else {
146 | mWarnText.setVisibility(View.GONE);
147 | }
148 | }
149 | }
150 |
151 | @Override
152 | protected void onPause() {
153 | super.onPause();
154 | Log.d("tag", "暂停");
155 | }
156 |
157 | @Override
158 | protected void onStop() {
159 | super.onStop();
160 | Log.d("tag", "停止");
161 | }
162 |
163 | class MyOnClickListener implements View.OnClickListener {
164 | @Override
165 | public void onClick(View view) {
166 | switch (view.getId()) { //当点击屏幕中间的播放按钮时
167 | case R.id.player_button:
168 | if (isPlay) { //如果当前正在播放 停止播放 更改控制栏播放状态 mPlayImg.setVisibility(View.VISIBLE);
169 | if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
170 | mMediaPlayer.pause();
171 | mPlayBtn.setBackground(getResources().getDrawable(R.mipmap.simple_player_center_play));
172 | }
173 | } else {
174 | //如果当前停止播放 继续播放 更改控制栏状态
175 | if (mMediaPlayer != null) {
176 | mPlayImg.setVisibility(View.GONE);
177 | mPlayBtn.setBackground(getResources().getDrawable(R.mipmap.simple_player_center_pause));
178 | mMediaPlayer.start(); //定时器 更新进度
179 | if (mTimer == null) {
180 | mTimer = new Timer();
181 | mTimerTask = new TimerTask() {
182 | @Override
183 | public void run() {
184 | if (isChanging == true) {
185 | return;
186 | }
187 | if (isPlay) {
188 | mHandler.sendEmptyMessage(0);
189 | mPlaySeekBar.setProgress(mMediaPlayer.getCurrentPosition());
190 | }
191 | }
192 | };
193 | mTimer.schedule(mTimerTask, 0, 1000);
194 | }
195 | }
196 | }
197 | isPlay = !isPlay;
198 | break;
199 | case R.id.player_img2:
200 | if (mMediaPlayer != null) {
201 | mPlayBtn.setBackground(getResources().getDrawable(R.mipmap.simple_player_center_pause));
202 | mMediaPlayer.start();
203 | if (mTimer == null) {
204 | mTimer = new Timer();
205 | mTimerTask = new TimerTask() {
206 | @Override
207 | public void run() {
208 | if (isChanging == true) {
209 | return;
210 | }
211 | if (isPlay) {
212 | mHandler.sendEmptyMessage(0);
213 | mPlaySeekBar.setProgress(mMediaPlayer.getCurrentPosition());
214 | }
215 | }
216 | };
217 | mTimer.schedule(mTimerTask, 0, 1000);
218 | }
219 | isPlay = true;
220 | mPlayImg.setVisibility(View.GONE);
221 | }
222 | break;
223 | case R.id.player_frame: //点击屏幕时 控制 控制栏的显示与隐藏
224 | if (!isShow) {
225 | mControlLayout.setVisibility(View.VISIBLE);
226 | mTitleLayout.setVisibility(View.VISIBLE);
227 | mHandler.sendEmptyMessageDelayed(1, 3000);
228 | } else {
229 | mHandler.removeMessages(1);
230 | mControlLayout.setVisibility(View.GONE);
231 | mTitleLayout.setVisibility(View.GONE);
232 | }
233 | isShow = !isShow;
234 | break;
235 | }
236 | }
237 | } //界面销毁时,释放mediaplayer与定时器
238 |
239 | @Override
240 | protected void onDestroy() {
241 | super.onDestroy();
242 | Log.d("tag", "onDestroy");
243 | if (mTimer != null) {
244 | mTimer.cancel();
245 | mTimer = null;
246 | mTimerTask = null;
247 | }
248 | if (mMediaPlayer != null) {
249 | if (mMediaPlayer.isPlaying()) {
250 | mMediaPlayer.stop();
251 | }
252 | mMediaPlayer.release();
253 | }
254 | }
255 |
256 | /**
257 | * 格式化显示的时间
258 | */
259 | private String generateTime(long time) {
260 | int totalSeconds = (int) (time / 1000);
261 | int seconds = totalSeconds % 60;
262 | int minutes = (totalSeconds / 60) % 60;
263 | int hours = totalSeconds / 3600;
264 | return hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, seconds) : String.format("%02d:%02d", minutes, seconds);
265 | }
266 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/supets/pet/view/LedTextView.java:
--------------------------------------------------------------------------------
1 | package com.supets.pet.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.os.Handler;
9 | import android.os.Message;
10 | import android.text.TextUtils;
11 | import android.util.AttributeSet;
12 |
13 | import com.supets.pet.ledview.R;
14 |
15 | import java.util.Random;
16 |
17 | public class LedTextView extends android.support.v7.widget.AppCompatTextView {
18 |
19 | private int xdots = 40;//X点数
20 | private int dots = (int) (xdots * (72f / 128)); //Y点数=行数
21 | private int centeroffset = (dots - 16) / 2;//Y偏移
22 | private int centerxoffset = (xdots % 8) / 2;//X偏移
23 |
24 | private float spacing = 0;//点阵之间的距离
25 | private float radius;//点阵中点的半径
26 |
27 | private Paint normalPaint;
28 | private Paint selectPaint;
29 |
30 | public String text;//显示文本
31 |
32 |
33 | private int paintColor = Color.GREEN;
34 |
35 | /*
36 | * 滚动的text
37 | */
38 | private volatile boolean scrollText = false;
39 | /*
40 | * 用来调整滚动速度
41 | */
42 | private static int maxsleep = 500;
43 | private static int minsleep = 100;
44 |
45 | private int sleepTime = minsleep;
46 |
47 | /*
48 | * 滚动方向,默认0向左
49 | */
50 | public int scrollDirection = 0;
51 |
52 | /*
53 | * 汉字对应的点阵矩阵
54 | */
55 | private boolean[][] matrix;
56 | private Handler handler;
57 | private boolean isCircle = true;
58 |
59 | public LedTextView(Context context, AttributeSet attrs, int defStyleAttr) {
60 | super(context, attrs, defStyleAttr);
61 |
62 | boolean scroll = false;
63 |
64 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.LedTextView);
65 | int n = typedArray.getIndexCount();
66 | for (int i = 0; i < n; i++) {
67 | int attr = typedArray.getIndex(i);
68 | switch (attr) {
69 | case R.styleable.LedTextView_textColor:
70 | paintColor = typedArray.getColor(R.styleable.LedTextView_textColor, Color.GREEN);
71 | break;
72 | case R.styleable.LedTextView_spacing:
73 | spacing = typedArray.getDimension(R.styleable.LedTextView_spacing, 10);
74 | break;
75 | case R.styleable.LedTextView_scroll:
76 | scroll = typedArray.getBoolean(R.styleable.LedTextView_scroll, true);
77 | break;
78 | case R.styleable.LedTextView_speed:
79 | int speed = typedArray.getInt(R.styleable.LedTextView_speed, 0);
80 | if (0 == speed) {
81 | sleepTime = minsleep;
82 | } else {
83 | sleepTime = maxsleep;
84 | }
85 | break;
86 | case R.styleable.LedTextView_scrollDirection:
87 | scrollDirection = typedArray.getInt(R.styleable.LedTextView_scrollDirection, 0);
88 | break;
89 | case R.styleable.LedTextView_xdots:
90 | xdots = typedArray.getInt(R.styleable.LedTextView_xdots, 40);
91 | dots = (int) (xdots * (72f / 128)); //Y点数=行数
92 | centeroffset = (dots - 16) / 2;//Y偏移
93 | centerxoffset = (xdots % 8) / 2;//X偏移
94 | break;
95 | case R.styleable.LedTextView_dotcolormode:
96 | mode = typedArray.getInt(R.styleable.LedTextView_dotcolormode, 1);
97 | break;
98 | }
99 | }
100 | typedArray.recycle();
101 | selectPaint = new Paint();
102 | selectPaint.setStyle(Paint.Style.FILL);
103 | selectPaint.setColor(paintColor);
104 |
105 | //随机色
106 | if (mode==2) {
107 | selectPaint.setColor(Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1)));
108 | }
109 | normalPaint = new Paint();
110 | normalPaint.setStyle(Paint.Style.STROKE);
111 | normalPaint.setColor(Color.BLACK);
112 |
113 | text = getText().toString();
114 | if (TextUtils.isEmpty(text)) {
115 | text = "Welcome To You!";
116 | }
117 | if (1 == scrollDirection) {
118 | text = reverseString(text);
119 | }
120 |
121 | matrix = ChatUtils.convert(text, getContext());
122 |
123 | handler = new Handler(new Handler.Callback() {
124 | @Override
125 | public boolean handleMessage(Message message) {
126 | postInvalidate();
127 | return false;
128 | }
129 | });
130 |
131 | if (scroll) {
132 | startScroll();
133 | }
134 |
135 | color[0]= Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1));
136 | color[1]= Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1));
137 | color[2]= Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1));
138 | color[3]= Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1));
139 | color[4]= Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1));
140 | }
141 |
142 | private int[] color=new int[5];
143 |
144 | public void startScroll() {
145 | scrollText = true;
146 | Thread thread = new ScrollThread();
147 | thread.start();
148 | }
149 |
150 |
151 | public void stopScroll() {
152 | scrollText = false;
153 | }
154 |
155 |
156 | public LedTextView(Context context, AttributeSet attrs) {
157 | this(context, attrs, 0);
158 | }
159 |
160 | public LedTextView(Context context) {
161 | this(context, null, 0);
162 | }
163 |
164 | /**
165 | * 翻转字符串,当设置享有滚动时调用
166 | *
167 | * @param str
168 | * @return
169 | */
170 | public String reverseString(String str) {
171 | StringBuffer sb = new StringBuffer(str);
172 | sb = sb.reverse();
173 | return sb.toString();
174 | }
175 |
176 | /*
177 | * 用于控制滚动,仅在开启滚动时启动。
178 | */
179 | private class ScrollThread extends Thread {
180 | @Override
181 | public void run() {
182 |
183 | int m = 0;
184 | while (scrollText) {
185 |
186 | if (m == matrix[0].length) {
187 | m = 0;
188 | onScrollEnd();
189 | }
190 | try {
191 | Thread.sleep(sleepTime);
192 | } catch (InterruptedException e) {
193 | e.printStackTrace();
194 | }
195 | if (0 == scrollDirection) {
196 | matrixLeftMove(matrix);
197 | } else {
198 | matrixRightMove(matrix);
199 | }
200 | m++;
201 |
202 | handler.sendEmptyMessage(0);
203 | }
204 | matrix = ChatUtils.convert(changeContent(), getContext());
205 | handler.sendEmptyMessage(0);
206 | }
207 | }
208 |
209 | public void updateCacheMatrix(boolean[][] matrix) {
210 | this.matrix = matrix;
211 | }
212 |
213 | //滚动一次结束自动更新数据
214 | public void onScrollEnd() {
215 |
216 | }
217 |
218 | /**
219 | * 向左滚动时调用,列循环左移
220 | *
221 | * @param matrix
222 | */
223 | public void matrixLeftMove(boolean[][] matrix) {
224 | for (int i = 0; i < matrix.length; i++) {
225 | boolean tmp = matrix[i][0];
226 | System.arraycopy(matrix[i], 1, matrix[i], 0, matrix[0].length - 1);
227 | matrix[i][matrix[0].length - 1] = tmp;
228 | }
229 | }
230 |
231 | /**
232 | * 向右滚动时调用,列循环右移
233 | *
234 | * @param matrix
235 | */
236 | private void matrixRightMove(boolean[][] matrix) {
237 | for (int i = 0; i < matrix.length; i++) {
238 | boolean tmp = matrix[i][matrix[0].length - 1];
239 | System.arraycopy(matrix[i], 0, matrix[i], 1, matrix[0].length - 1);
240 | matrix[i][0] = tmp;
241 | }
242 | }
243 |
244 | /**
245 | * 主要是想处理AT_MOST的情况,我觉得View默认的情况就挺好的,由于继承自TextView,而TextView重
246 | * 写了onMeasure,因此这里参考View#onMeasure函数的写法即可
247 | */
248 | @Override
249 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
250 | setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec),
251 | getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec));
252 | }
253 |
254 |
255 | private void drawText(Canvas canvas, int xoffset, int yoffset, boolean[][] matrix) {
256 | radius = (getHeight() - (dots + 1) * spacing) / (2 * dots);
257 | //随机色
258 | if (mode==5) {
259 | selectPaint.setColor(Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1)));
260 | }
261 | // 行
262 | int row = 0;
263 | // 列
264 | int column = 0;
265 | while (getYPosition(row, yoffset) < getHeight()) {
266 | while (getXPosition(column, xoffset) < getWidth()) {
267 | if (row < matrix.length && column < matrix[0].length && matrix[row][column]) {
268 | //随机色
269 | if (mode==3) {
270 | selectPaint.setColor(Color.rgb((int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1), (int) (Math.random() * 255 + 1)));
271 | }
272 | if (isCircle) {
273 | canvas.drawCircle(getXPosition(column, xoffset), getYPosition(row, yoffset), radius, selectPaint);
274 | } else {
275 | canvas.drawRect(getXPosition(column, xoffset), getYPosition(row, yoffset), getXPosition(column, xoffset) + 2 * radius, getYPosition(row, yoffset) + 2 * radius, selectPaint);
276 | }
277 | }
278 | // else {
279 | // if (isCircle) {
280 | // canvas.drawCircle(getXPosition(column, xoffset), getYPosition(row, yoffset), radius, normalPaint);
281 | // } else {
282 | // canvas.drawRect(getXPosition(column, xoffset), getYPosition(row, yoffset), getXPosition(column, xoffset) + 2 * radius, getYPosition(row, yoffset) + 2 * radius, normalPaint);
283 | // }
284 | // }
285 | column++;
286 | }
287 | row++;
288 | column = 0;
289 | }
290 | }
291 |
292 | /**
293 | * 获取绘制第column列的点的X坐标
294 | *
295 | * @param column
296 | * @return
297 | */
298 | private float getXPosition(int column, int xoffset) {
299 | if (isCircle) {
300 | return spacing + radius + (spacing + 2 * radius) * (column + xoffset);
301 | } else {
302 | return spacing + (spacing + 2 * radius) * (column + xoffset);
303 | }
304 | }
305 |
306 | /**
307 | * 获取绘制第row行的点的Y坐标
308 | *
309 | * @param row
310 | * @return
311 | */
312 | private float getYPosition(int row, int yoffset) {
313 | if (isCircle) {
314 | return spacing + radius + (spacing + 2 * radius) * (row + yoffset);
315 | } else {
316 | return spacing + (spacing + 2 * radius) * (row + yoffset);
317 | }
318 | }
319 |
320 | @Override
321 | protected void onDetachedFromWindow() {
322 | stopScroll();
323 | handler.removeMessages(0);
324 | super.onDetachedFromWindow();
325 | }
326 |
327 | @Override
328 | protected void onDraw(Canvas canvas) {
329 | drawText(canvas, centerxoffset, centeroffset, matrix);
330 | }
331 |
332 | //测试画点阵
333 | private void drawBackGround(Canvas canvas) {
334 | radius = (getHeight() - (dots + 1) * spacing) / (2 * dots);
335 | // 行
336 | int row = 0;
337 | // 列
338 | int column = 0;
339 | while (getYPosition(row, 0) < getHeight()) {
340 | while (getXPosition(column, 0) < getWidth()) {
341 | // just draw
342 | if (isCircle) {
343 | canvas.drawCircle(getXPosition(column, 0), getYPosition(row, 0), radius, normalPaint);
344 | } else {
345 | canvas.drawRect(getXPosition(column, 0), getYPosition(row, 0), getXPosition(column, 0) + 2 * radius, getYPosition(row, 0) + 2 * radius, normalPaint);
346 | }
347 | column++;
348 | }
349 | row++;
350 | column = 0;
351 | }
352 | }
353 |
354 | //手动更新数据
355 | public void updateText(String text) {
356 | this.text = text;
357 | if (1 == scrollDirection) {
358 | this.text = reverseString(text);
359 | }
360 | if (!scrollText) {
361 | matrix = ChatUtils.convert(this.text, getContext());
362 | postInvalidate();
363 | }
364 | }
365 |
366 | public String changeContent() {
367 | return text;
368 | }
369 |
370 |
371 | public void ForceupdateText(String text) {
372 | this.text = text;
373 | if (1 == scrollDirection) {
374 | this.text = reverseString(text);
375 | }
376 | matrix = ChatUtils.convert(this.text, getContext());
377 | postInvalidate();
378 | }
379 |
380 | public void ForceupdateText(boolean[][] text) {
381 | matrix = text;
382 | postInvalidate();
383 | }
384 |
385 |
386 | private int mode=1;//1 固定色 2 随机色 3 随机点色 4 随机数字 5 每次随机色
387 |
388 | public void setColorMode(int mode){
389 | this.mode=mode;
390 | }
391 |
392 | }
--------------------------------------------------------------------------------