11package com .demo .icarbox .blereceiver ;
22
33import android .Manifest ;
4+ import android .annotation .SuppressLint ;
45import android .content .ContentResolver ;
56import android .content .Context ;
7+ import android .content .Intent ;
8+ import android .content .pm .PackageInfo ;
69import android .content .pm .PackageManager ;
710import android .database .ContentObserver ;
811import android .database .Cursor ;
12+ import android .graphics .Point ;
13+ import android .location .Location ;
14+ import android .location .LocationListener ;
15+ import android .location .LocationManager ;
916import android .net .Uri ;
17+ import android .os .Build ;
1018import android .os .Handler ;
1119import android .support .annotation .NonNull ;
12- import android .support .design . widget . Snackbar ;
20+ import android .support .annotation . RequiresApi ;
1321import android .support .v4 .app .ActivityCompat ;
22+ import android .support .v4 .app .NotificationManagerCompat ;
1423import android .support .v4 .content .ContextCompat ;
1524import android .support .v7 .app .AppCompatActivity ;
1625import android .os .Bundle ;
17- import android .text .Editable ;
26+ import android .telecom .TelecomManager ;
27+ import android .telephony .CarrierConfigManager ;
28+ import android .telephony .TelephonyManager ;
29+ import android .telephony .cdma .CdmaCellLocation ;
30+ import android .telephony .gsm .GsmCellLocation ;
1831import android .text .InputType ;
19- import android .text .method .KeyListener ;
20- import android .text .method .NumberKeyListener ;
32+ import android .util .DisplayMetrics ;
2133import android .util .Log ;
22- import android .view .KeyEvent ;
2334import android .view .View ;
35+ import android .view .WindowManager ;
2436import android .widget .Button ;
2537import android .widget .EditText ;
38+ import android .widget .TextView ;
39+ import android .widget .Toast ;
2640
41+ import com .google .gson .Gson ;
2742import com .icarbonx .smartdevice .account .Apis ;
43+ import com .icarbonx .smartdevice .account .ApisOld ;
2844import com .icarbonx .smartdevice .account .BaseResponse ;
2945import com .icarbonx .smartdevice .account .LoginResponse ;
46+ import com .icarbonx .smartdevice .account .UserAccountHttpService ;
3047import com .icarbonx .smartdevice .http .AbstractObserver ;
48+ import com .icarbonx .smartdevice .utils .LocationUtil ;
49+ import com .icarbonx .smartdevice .utils .PhoneInfoUtil ;
3150import com .jakewharton .rxbinding2 .view .RxView ;
3251
52+ import java .util .Date ;
53+ import java .util .List ;
3354import java .util .concurrent .TimeUnit ;
3455
35- import io .reactivex .Observer ;
36- import io .reactivex .Scheduler ;
3756import io .reactivex .android .schedulers .AndroidSchedulers ;
38- import io .reactivex .disposables .Disposable ;
39- import io .reactivex .functions .Consumer ;
4057import io .reactivex .schedulers .Schedulers ;
4158
4259import static android .content .pm .PackageManager .PERMISSION_GRANTED ;
@@ -45,8 +62,10 @@ public class UserLoginActivity extends AppCompatActivity {
4562
4663 EditText mPhoneNumber , mVerifyCode ;
4764 Button mLogin ;
65+ TextView show ;
4866
49- SmsObserver smsObserver ;
67+ LocationUtil mLocationUtil ;
68+ PhoneInfoUtil mPhoneInfoUtil ;
5069
5170 @ Override
5271 protected void onCreate (Bundle savedInstanceState ) {
@@ -56,31 +75,32 @@ protected void onCreate(Bundle savedInstanceState) {
5675 mPhoneNumber = findViewById (R .id .email );
5776 mVerifyCode = findViewById (R .id .password );
5877 mLogin = findViewById (R .id .email_sign_in_button );
78+ show = findViewById (R .id .test );
5979
6080 mPhoneNumber .setKeyListener (new NumberKeys ());
6181 mPhoneNumber .setInputType (InputType .TYPE_CLASS_NUMBER );
62- findViewById (R .id .verifyCod ).setOnClickListener (
63- new View .OnClickListener () {
64- @ Override
65- public void onClick (View v ) {
6682
6783
68- // RxView.clicks(findViewById(R.id.verifyCod))
69- // .throttleFirst(60, TimeUnit.SECONDS)
70- // .subscribe(new AbstractObserver<Object>() {
71- // @Override
72- // public void onSuccess(Object o) {
73- if (!checkPhoneNumber ()) return ;
84+ RxView .clicks (findViewById (R .id .verifyCod ))
85+ .throttleFirst (30 , TimeUnit .SECONDS )
86+ .subscribe (new AbstractObserver <Object >() {
87+ @ Override
88+ public void onSuccess (Object o ) {
89+ Log .e ("phone info." , mPhoneInfoUtil .getBrand () + "\n "
90+ + mPhoneInfoUtil .getDeviceId () + "\n "
91+ + mPhoneInfoUtil .getDisplay () + "\n "
92+ + mPhoneInfoUtil .getManufacturer () + "\n " );
7493
75- Apis .getInstance ().getUserAccountService ()
94+ if (!checkPhoneNumber ()) return ;
95+ ApisOld .getInstance ().getUserAccountService ()
7696 .getVerifyCode (mPhoneNumber .getText ().toString (), 1 )
77- .subscribeOn (Schedulers .io ())
78- // .observeOn(AndroidSchedulers.mainThread())
97+ .subscribeOn (Schedulers .single ())
98+ .observeOn (AndroidSchedulers .mainThread ())
7999 .subscribe (new AbstractObserver <BaseResponse >() {
80100 @ Override
81101 public void onSuccess (BaseResponse baseResponse ) {
82102 if (baseResponse .getErrorCode () == 0 ) {
83- Log .e ("ss1" ,baseResponse .toJson ());
103+ Log .e ("ss1" , baseResponse .toJson ());
84104 }//请求失败,尝试
85105 else {
86106
@@ -92,11 +112,14 @@ public void onFailure(Throwable throwable) {
92112 //获取验证码失败,尝试
93113 }
94114 });
95- // }
96- // });
115+
97116 }
98- }
99- );
117+
118+ @ Override
119+ public void onFailure (Throwable throwable ) {
120+ Log .e ("ss" , "failure click" );
121+ }
122+ });
100123 RxView .clicks (mLogin )
101124 .throttleFirst (2 , TimeUnit .SECONDS )
102125 .subscribe (new AbstractObserver <Object >() {
@@ -105,17 +128,20 @@ public void onSuccess(Object o) {
105128 //Login in check
106129 if (!checkPhoneNumber ()) return ;
107130 if (!checkVerifyCode ()) return ;
108- Apis .getInstance ().getUserAccountService ()
131+ ApisOld .getInstance ().getUserAccountService ()
109132 .login (mPhoneNumber .getText ().toString ().trim (),
110133 mVerifyCode .getText ().toString ().trim ())
111- .subscribeOn (Schedulers .io ())
112- // .observeOn(AndroidSchedulers.mainThread())
134+ .subscribeOn (Schedulers .single ())
135+ .observeOn (AndroidSchedulers .mainThread ())
113136 .subscribe (new AbstractObserver <LoginResponse >() {
114137 @ Override
115138 public void onSuccess (LoginResponse loginResponse ) {
116139 //to next page
117140 if (loginResponse .getErrorCode () == 0 ) {
118- Log .e ("ss2" ,loginResponse .toJson ());
141+ Log .e ("ss2" , loginResponse .toJson ());
142+ startActivity (new Intent ().setClass (UserLoginActivity .this ,UserAskerActivity .class ));
143+ // show.setText(loginResponse.toJson());
144+ finish ();
119145 }//toast err msg
120146 else {
121147 Log .e ("err" , "[" + loginResponse .getErrorCode () + "]"
@@ -131,37 +157,36 @@ public void onFailure(Throwable throwable) {
131157 }
132158 });
133159
134- smsObserver = new SmsObserver (this , smsHandler );
135- getContentResolver ().registerContentObserver (SMS_INBOX , true ,
136- smsObserver );
160+ mPhoneNumber .setText ("18923889519" );
161+ mLocationUtil = new LocationUtil (this , new LocationUtil .LocationRequestListener () {
162+ @ Override
163+ public void onFail () {
164+
165+ }
166+
167+ @ Override
168+ public void onSuccess (double lat , double lon ) {
169+
170+ }
171+ });
172+ mPhoneInfoUtil = new PhoneInfoUtil (this );
173+ mLocationUtil .checkPermission ();
174+ mPhoneInfoUtil .checkPermission ();
137175
138- checkSMSPermission ();
139- }
140176
141- private void checkSMSPermission () {
142- if (ContextCompat .checkSelfPermission (UserLoginActivity .this , Manifest .permission .READ_SMS )
143- != PERMISSION_GRANTED ) {
144- ActivityCompat .requestPermissions (UserLoginActivity .this , new String []{Manifest .permission .READ_SMS }, 1 );
145- }
146177 }
147178
148179 @ Override
149180 public void onRequestPermissionsResult (int requestCode , @ NonNull String [] permissions , @ NonNull int [] grantResults ) {
150- if (1 == requestCode && permissions .length == 1 ) {
151- if (grantResults [0 ] == PERMISSION_GRANTED ) {
152- //授权读取短信
153- }//授权失败
154- else {
181+ mLocationUtil .permisssionGranted (requestCode );
182+ mPhoneInfoUtil .permisssionGranted (requestCode );
155183
156- }
157- }
158184 super .onRequestPermissionsResult (requestCode , permissions , grantResults );
159185 }
160186
161- public Handler smsHandler = new Handler () {
162- };
163-
164187 boolean checkPhoneNumber () {
188+ Log .e ("sms" , "check number:" + mPhoneNumber .getText ().toString ());
189+
165190 String number = mPhoneNumber .getText ().toString ();
166191 if (number .length () == 11 || number .length () == 14 ) {
167192 return true ;
@@ -180,49 +205,4 @@ boolean checkVerifyCode() {
180205 }
181206
182207
183- private Uri SMS_INBOX = Uri .parse ("content://sms/inbox" );
184-
185- public void getSmsFromPhone () {
186- ContentResolver cr = getContentResolver ();
187- String [] projection = new String []{"body" , "address" };//"_id", "address", "person",, "date", "type
188- String where = " date > "
189- + (System .currentTimeMillis () - 60 * 1000 );
190- Cursor cur = cr .query (SMS_INBOX , projection , where , null , "date desc" );
191- // if (null == cur)
192- // return;
193- // if (cur.moveToFirst()) {
194- // String number = cur.getString(cur.getColumnIndex("address"));//手机号
195- // String body = cur.getString(cur.getColumnIndex("body"));
196- //
197- // }
198-
199- Cursor cursor = getContentResolver ().query (
200- Uri .parse ("content://sms" ),
201- new String []{"_id" , "address" , "body" , "date" },
202- where , null , "date desc" ); //
203- if (cursor != null ) {
204- // String body = "";
205- while (cursor .moveToNext ()) {
206- String number = cur .getString (cur .getColumnIndex ("address" ));//手机号
207- String body = cur .getString (cur .getColumnIndex ("body" ));
208- //-----------------写自己的逻辑
209-
210- }
211-
212- }
213- }
214-
215- class SmsObserver extends ContentObserver {
216-
217- public SmsObserver (Context context , Handler handler ) {
218- super (handler );
219- }
220-
221- @ Override
222- public void onChange (boolean selfChange ) {
223- super .onChange (selfChange );
224- //每当有新短信到来时,使用我们获取短消息的方法
225- getSmsFromPhone ();
226- }
227- }
228208}
0 commit comments