33
33
import com .orhanobut .logger .LogLevel ;
34
34
import com .orhanobut .logger .Logger ;
35
35
36
+ import java .text .SimpleDateFormat ;
36
37
import java .util .ArrayList ;
38
+ import java .util .Date ;
39
+ import java .util .Locale ;
37
40
import java .util .concurrent .TimeUnit ;
38
41
39
42
import rx .Observable ;
52
55
* 创建时间:15-11-10.
53
56
* 备注:
54
57
*/
55
- public class MainActivity extends Activity {
58
+ public class MainActivity extends Activity {
56
59
private static final String TAG = "MainActivity" ;
57
60
private static final String TAG_FOR_LOGGER = "MainActivity_I_LOVE_RXJAVA" ;
58
61
private static final String JPG = ".jpg" ;
@@ -62,7 +65,7 @@ public class MainActivity extends Activity{
62
65
private Canvas mCanvas = null ;
63
66
private ProgressBar mProgressBar ;
64
67
private ScalpelFrameLayout mScalpelFrameLayout ;
65
- private boolean mIsOpenScalpel = false ;
68
+ private boolean mIsOpenScalpel = false ;
66
69
67
70
@ Override
68
71
protected void onCreate (Bundle savedInstanceState ) {
@@ -72,7 +75,7 @@ protected void onCreate(Bundle savedInstanceState) {
72
75
initView ();
73
76
// miZhiSuoJinAndNestedLoopAndCallbackHell();//演示谜之缩进--嵌套循环--回调地狱
74
77
rxJavaSolveMiZhiSuoJinAndNestedLoopAndCallbackHell ();//使用RxJava解决问题
75
- // testFuncation(16 );//RxJava基础概念的练习
78
+ // testFuncation(1 );//RxJava基础概念的练习
76
79
}
77
80
78
81
/**
@@ -81,6 +84,11 @@ protected void onCreate(Bundle savedInstanceState) {
81
84
private void initializeLogAndDeviceInfo () {
82
85
Logger .init (TAG_FOR_LOGGER ).logLevel (LogLevel .FULL );//Use LogLevel.NONE for the release versions.
83
86
DeviceInfo .getInstance ().initializeScreenInfo (this );
87
+ int bitmapSize = ImageUtils .getBitmapSize (ImageUtils .getLocalBitmapFromResFolder (getApplicationContext (),R .mipmap .ic_launcher ));
88
+ Logger .d ("size:" +bitmapSize );
89
+ Logger .d ("" +DeviceInfo .screenWidthForPortrait +"x" +DeviceInfo .screenHeightForPortrait );
90
+ Logger .d ("mDensity--> " + DeviceInfo .mDensity );
91
+ Logger .d ("mDensityDpi--> " + DeviceInfo .mDensityDpi );
84
92
}
85
93
86
94
/**
@@ -110,6 +118,8 @@ private void setContentViewLayout(boolean isOpenScalpe) {
110
118
private void initView () {
111
119
mImageView = (AvoidRecoveredAppearErrorImageView ) findViewById (R .id .iv_image );
112
120
mProgressBar = (ProgressBar ) findViewById (R .id .progressbar );
121
+
122
+ method16 ();
113
123
}
114
124
115
125
@@ -723,9 +733,9 @@ private void method8() {
723
733
int size = students .size ();
724
734
for (int i = 0 ; i < size ; i ++) {
725
735
Logger .d ("姓名:" + students .get (i ).name );
726
- int sizeCourses = students .get (i ).courses .size ();
736
+ int sizeCourses = students .get (i ).courses .size ();
727
737
for (int j = 0 ; j < sizeCourses ; j ++) {
728
- Logger .d ("课程:" + students .get (i ).courses .get (j ).name );
738
+ Logger .d ("课程:" + students .get (i ).courses .get (j ).name );
729
739
}
730
740
}
731
741
}
@@ -865,7 +875,7 @@ public void onNext(Student student) {
865
875
* 输出每一个学生选修的课程
866
876
* 对method12的简化
867
877
* {@link #method12()}
868
- *
878
+ * <p>
869
879
* Student->ArrayList<Course>
870
880
*/
871
881
private void method13 () {
@@ -928,22 +938,21 @@ public void call(Course course) {
928
938
* 举个设置点击监听的例子。使用 RxBinding ,可以把事件监听用这样的方法来设置:
929
939
* throttleFirst() ,用于去抖动,也就是消除手抖导致的快速连环点击:
930
940
*/
931
- private void method15 (){
932
- RxView .clicks (mImageView )
933
- .throttleFirst (500 , TimeUnit .MILLISECONDS )
934
- .subscribe (new Action1 <Void >() {
935
- @ Override
936
- public void call (Void aVoid ) {
937
-
938
- Toast .makeText (MainActivity .this , "click" , Toast .LENGTH_SHORT ).show ();
939
- }
940
- });
941
- }
941
+ private void method15 () {
942
+ RxView .clicks (mImageView )
943
+ .throttleFirst (500 , TimeUnit .MILLISECONDS )
944
+ .subscribe (new Action1 <Void >() {
945
+ @ Override
946
+ public void call (Void aVoid ) {
947
+ Toast .makeText (MainActivity .this , "click" , Toast .LENGTH_SHORT ).show ();
948
+ }
949
+ });
950
+ }
942
951
943
952
/**
944
953
* RxBinding
945
954
*/
946
- private void method16 (){
955
+ private void method16 () {
947
956
RxView .longClicks (mImageView )
948
957
.throttleFirst (500 , TimeUnit .MILLISECONDS )
949
958
.subscribe (new Action1 <Void >() {
@@ -956,8 +965,94 @@ public void call(Void aVoid) {
956
965
});
957
966
}
958
967
968
+ /**
969
+ * 三、Defer、Just
970
+ */
971
+ //操作符号 Range操作符根据出入的初始值n和数目m发射一系列大于等于n的m个值
972
+ //例如:实现:输出1,2,3,4,5
973
+ // 其使用也非常方便,仅仅制定初始值和数目就可以了,不用自己去实现对Subscriber的调用
974
+
975
+ private void method17 () {
976
+ Observable .range (1 , 5 )
977
+ .subscribeOn (Schedulers .io ())
978
+ .observeOn (AndroidSchedulers .mainThread ())
979
+ .subscribe (new Action1 <Integer >() {
980
+ @ Override
981
+ public void call (Integer integer ) {
982
+ Logger .d (integer .toString () + "" );
983
+ }
984
+ });
985
+ }
986
+
987
+
988
+ private static final int COUNT = 10 ;
989
+ private static final int TIME_ALL =5000 ;
990
+ private ArrayList <Long > timeList = new ArrayList <Long >();
991
+ private void method18 () {
992
+
993
+ int COUNT = 5 ;
994
+ int TIME_ALL =3000 ;
995
+ ArrayList <Long > timeList = new ArrayList <Long >();
996
+ ArrayList <Long > allList = new ArrayList <Long >();
997
+
998
+ RxView .clicks (findViewById (R .id .iv_image ))
999
+ .map (new Func1 <Void , Long >() {
1000
+ @ Override
1001
+ public Long call (Void aVoid ) {
1002
+ return System .currentTimeMillis ();
1003
+ }
1004
+ })
1005
+ .map (new Func1 <Long , Boolean >() {
1006
+ @ Override
1007
+ public Boolean call (Long nowTime ) {
1008
+ allList .add (nowTime );
1009
+ timeList .add (nowTime );
1010
+
1011
+ boolean isOver = false ;
1012
+ Log .d (TAG , "timeList.size():" + timeList .size ());
1013
+ if (timeList .size () >= COUNT ) {
1014
+
1015
+ if (nowTime - timeList .get (0 ) < TIME_ALL ) {
1016
+ isOver = true ;
1017
+ } else {
1018
+ isOver = false ;
1019
+ }
1020
+ timeList .clear ();
1021
+ }
1022
+ return isOver ;
1023
+ }
1024
+ }).subscribe (new Action1 <Boolean >() {
1025
+ @ Override
1026
+ public void call (Boolean aBoolean ) {
1027
+ if (aBoolean ) {
1028
+ Toast .makeText (MainActivity .this , "3秒内点击超过了" + allList .size (), Toast .LENGTH_SHORT ).show ();
1029
+ allList .clear ();
1030
+ } else {
1031
+ // Toast.makeText(MainActivity.this, "ok "+timeList.size(), Toast.LENGTH_SHORT).show();
1032
+ }
1033
+ }
1034
+ });
1035
+ }
1036
+
1037
+ public static String timeLongToString (long data ) {
1038
+ Date date = new Date (data );
1039
+ SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" , Locale .getDefault ());
1040
+ return formatter .format (date );
1041
+ }
1042
+
1043
+
1044
+ private void log (final String str ) {
1045
+ runOnUiThread (new Runnable () {
1046
+ @ Override
1047
+ public void run () {
1048
+ Log .d (TAG , str );
1049
+ }
1050
+ });
1051
+ }
1052
+
959
1053
/**
960
1054
* 测试这些每个知识点的功能
1055
+ *
961
1056
* @param number
962
1057
*/
963
1058
private void testFuncation (int number ) {
@@ -1045,6 +1140,17 @@ private void testFuncation(int number) {
1045
1140
method16 ();
1046
1141
break ;
1047
1142
}
1143
+
1144
+ case 17 : {
1145
+ method17 ();
1146
+ break ;
1147
+ }
1148
+
1149
+ case 18 : {
1150
+ method18 ();
1151
+ break ;
1152
+ }
1153
+
1048
1154
default : {
1049
1155
1050
1156
break ;
@@ -1154,16 +1260,28 @@ public boolean onOptionsItemSelected(MenuItem item) {
1154
1260
int id = item .getItemId ();
1155
1261
1156
1262
//noinspection SimplifiableIfStatement
1157
- if (id == R .id .action_settings_open_scalpel ) {
1158
- mIsOpenScalpel = true ;
1159
- mScalpelFrameLayout .setLayerInteractionEnabled (mIsOpenScalpel );
1160
- return true ;
1161
- }else if (id == R .id .action_settings_close_scalpel ){
1162
- mIsOpenScalpel = false ;
1163
- mScalpelFrameLayout .setLayerInteractionEnabled (mIsOpenScalpel );
1164
- return true ;
1263
+ if (id ==R .id .action_settings_open_scalpel ||id == R .id .action_settings_close_scalpel ){
1264
+ clickEvent (id );
1165
1265
}
1166
-
1167
1266
return super .onOptionsItemSelected (item );
1168
1267
}
1268
+ private boolean clickEvent (int id ) {
1269
+ boolean is = false ;
1270
+ switch (id ) {
1271
+ case R .id .action_settings_open_scalpel : {
1272
+ mIsOpenScalpel = true ;
1273
+ mScalpelFrameLayout .setLayerInteractionEnabled (mIsOpenScalpel );
1274
+ is = true ;
1275
+ break ;
1276
+ }
1277
+ case R .id .action_settings_close_scalpel : {
1278
+ mIsOpenScalpel = false ;
1279
+ mScalpelFrameLayout .setLayerInteractionEnabled (mIsOpenScalpel );
1280
+ is = true ;
1281
+ break ;
1282
+ }
1283
+ }
1284
+ return is ;
1285
+
1286
+ }
1169
1287
}
0 commit comments