Skip to content

Commit c724042

Browse files
committed
优化、更新
1 parent bdb16f7 commit c724042

File tree

16 files changed

+664
-65
lines changed

16 files changed

+664
-65
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323

2424
<activity
2525
android:name=".LoginActivity"
26-
android:screenOrientation="portrait" />
26+
android:screenOrientation="portrait"
27+
android:theme="@style/NoTitlescreen"
28+
/>
2729

2830
<activity
2931
android:name=".SecondActivity"
3032
android:screenOrientation="portrait" />
3133

3234
<activity android:name=".FollowActivity"
3335
android:screenOrientation="portrait"
36+
android:theme="@style/NoTitlescreen"
3437
/>
3538
</application>
3639

app/src/main/java/com/lihang/mysmartloadingview/FollowActivity.java

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import android.os.Message;
66
import android.support.annotation.Nullable;
77
import android.support.v7.app.AppCompatActivity;
8-
import android.util.Log;
9-
import android.view.View;
108
import android.widget.Toast;
119

10+
import com.gyf.barlibrary.ImmersionBar;
1211
import com.lihang.smartloadview.SmartLoadingView;
1312

1413
/**
@@ -18,6 +17,9 @@
1817
public class FollowActivity extends AppCompatActivity {
1918
private SmartLoadingView animButton;
2019
private SmartLoadingView animButtonTwo;
20+
private SmartLoadingView animButtonThree;
21+
//沉浸式状态栏
22+
protected ImmersionBar mImmersionBar;
2123

2224
private Handler mhandler = new Handler() {
2325
@Override
@@ -32,13 +34,15 @@ public void animationOKFinish() {
3234
Toast.makeText(FollowActivity.this, "关注成功", Toast.LENGTH_SHORT).show();
3335
}
3436
});
35-
3637
break;
3738

38-
3939
case 12:
4040
animButtonTwo.netFaile("关注成功");
4141
break;
42+
43+
case 13:
44+
animButtonThree.netFaile("关注成功");
45+
break;
4246
}
4347
}
4448
};
@@ -47,45 +51,46 @@ public void animationOKFinish() {
4751
protected void onCreate(@Nullable Bundle savedInstanceState) {
4852
super.onCreate(savedInstanceState);
4953
setContentView(R.layout.activity_follow);
54+
mImmersionBar = ImmersionBar.with(this);
55+
mImmersionBar.init();
5056
animButton = findViewById(R.id.animButton);
5157
animButtonTwo = findViewById(R.id.animButtonTwo);
52-
animButton.setOnClickListener(new View.OnClickListener() {
53-
@Override
54-
public void onClick(View v) {
58+
animButtonThree = findViewById(R.id.animButtonThree);
5559

56-
if (!animButton.isAnimRuning()) {
57-
58-
if (!animButton.isCanRest()) {
59-
animButton.start();
60-
//这里是模拟联网情况
61-
mhandler.sendEmptyMessageDelayed(11, 1500);
62-
} else {
63-
animButton.reset();
64-
}
65-
66-
}
60+
animButton.setFollowClickListener(new SmartLoadingView.FollowClickListener() {
61+
@Override
62+
public void followClick() {
63+
//按钮点击后去进行联网操作
64+
//这里是模拟联网情况
65+
mhandler.sendEmptyMessageDelayed(11, 2000);
6766
}
6867
});
6968

70-
71-
animButtonTwo.setOnClickListener(new View.OnClickListener() {
69+
animButtonTwo.setFollowClickListener(new SmartLoadingView.FollowClickListener() {
7270
@Override
73-
public void onClick(View v) {
74-
75-
if (!animButtonTwo.isAnimRuning()) {
76-
77-
if (!animButtonTwo.isCanRest()) {
78-
animButtonTwo.start();
79-
//这里是模拟联网情况
80-
mhandler.sendEmptyMessageDelayed(12, 1500);
81-
} else {
82-
animButtonTwo.reset();
83-
}
71+
public void followClick() {
72+
//按钮点击后去进行联网操作
73+
//这里是模拟联网情况
74+
mhandler.sendEmptyMessageDelayed(12, 2000);
75+
}
76+
});
8477

85-
}
8678

79+
animButtonThree.setFollowClickListener(new SmartLoadingView.FollowClickListener() {
80+
@Override
81+
public void followClick() {
82+
//按钮点击后去进行联网操作
83+
//这里是模拟联网情况
84+
mhandler.sendEmptyMessageDelayed(13, 2000);
8785
}
8886
});
8987

88+
89+
}
90+
91+
@Override
92+
protected void onDestroy() {
93+
super.onDestroy();
94+
mImmersionBar.destroy();
9095
}
9196
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.lihang.mysmartloadingview;
2+
3+
/**
4+
* Created by lihang on 2017/9/13.
5+
*/
6+
7+
import android.content.Context;
8+
import android.view.MotionEvent;
9+
import android.view.View;
10+
import android.view.inputmethod.InputMethodManager;
11+
import android.widget.EditText;
12+
13+
/**
14+
* 打开或关闭软键盘
15+
*
16+
* @author zhy
17+
*
18+
*/
19+
public class KeyBoardUtils
20+
{
21+
/**
22+
* 打卡软键盘
23+
*
24+
* @param mEditText
25+
* 输入框
26+
* @param mContext
27+
* 上下文
28+
*/
29+
public static void openKeybord(EditText mEditText, Context mContext)
30+
{
31+
InputMethodManager imm = (InputMethodManager) mContext
32+
.getSystemService(Context.INPUT_METHOD_SERVICE);
33+
imm.showSoftInput(mEditText, InputMethodManager.RESULT_SHOWN);
34+
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
35+
InputMethodManager.HIDE_IMPLICIT_ONLY);
36+
}
37+
38+
/**
39+
* 关闭软键盘
40+
*
41+
* @param mEditText
42+
* 输入框
43+
* @param mContext
44+
* 上下文
45+
*/
46+
public static void closeKeybord(EditText mEditText, Context mContext)
47+
{
48+
InputMethodManager imm = (InputMethodManager) mContext
49+
.getSystemService(Context.INPUT_METHOD_SERVICE);
50+
51+
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
52+
}
53+
54+
55+
56+
/**
57+
* 判断当前点击屏幕的地方是否是软键盘:
58+
*
59+
* @param v
60+
* @param event
61+
* @return
62+
*/
63+
64+
public static boolean isShouldHideInput(View v, MotionEvent event) {
65+
if (v != null && (v instanceof EditText)) {
66+
int[] leftTop = {0, 0};
67+
v.getLocationInWindow(leftTop);
68+
int left = leftTop[0], top = leftTop[1], bottom = top + v.getHeight(), right = left
69+
+ v.getWidth();
70+
if (event.getX() > left && event.getX() < right
71+
&& event.getY() > top && event.getY() < bottom) {
72+
// 保留点击EditText的事件
73+
return false;
74+
} else {
75+
return true;
76+
}
77+
}
78+
return false;
79+
}
80+
81+
82+
}
Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,132 @@
11
package com.lihang.mysmartloadingview;
22

3+
import android.animation.Animator;
4+
import android.content.Intent;
35
import android.os.Bundle;
6+
import android.os.Handler;
7+
import android.os.Message;
48
import android.support.annotation.Nullable;
59
import android.support.v7.app.AppCompatActivity;
10+
import android.view.MotionEvent;
11+
import android.view.View;
12+
import android.widget.EditText;
13+
import android.widget.RelativeLayout;
14+
15+
import com.gyf.barlibrary.ImmersionBar;
16+
import com.lihang.smartloadview.SmartLoadingView;
617

718
/**
819
* Created by leo
920
* on 2019/5/27.
1021
*/
11-
public class LoginActivity extends AppCompatActivity {
22+
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
23+
private EditText edit_phone;
24+
//沉浸式状态栏
25+
protected ImmersionBar mImmersionBar;
26+
private SmartLoadingView animButton;
27+
private RelativeLayout relative_normal;
28+
private RelativeLayout relative_error;
29+
private boolean isNormalNet = true;
30+
31+
private Handler mhandler = new Handler() {
32+
@Override
33+
public void handleMessage(Message msg) {
34+
super.handleMessage(msg);
35+
switch (msg.what) {
36+
case 11:
37+
animButton.loginSuccess(new Animator.AnimatorListener() {
38+
@Override
39+
public void onAnimationStart(Animator animation) {
40+
41+
}
42+
43+
@Override
44+
public void onAnimationEnd(Animator animation) {
45+
startActivity(new Intent(LoginActivity.this, SecondActivity.class));
46+
finish();
47+
overridePendingTransition(R.anim.scale_test_home, R.anim.scale_test2);
48+
}
49+
50+
@Override
51+
public void onAnimationCancel(Animator animation) {
52+
53+
}
54+
55+
@Override
56+
public void onAnimationRepeat(Animator animation) {
57+
58+
}
59+
});
60+
break;
61+
62+
case 12:
63+
animButton.netFaile("登录失败");
64+
break;
65+
}
66+
}
67+
};
68+
1269
@Override
1370
protected void onCreate(@Nullable Bundle savedInstanceState) {
1471
super.onCreate(savedInstanceState);
1572
setContentView(R.layout.activity_login);
73+
animButton = findViewById(R.id.animButton);
74+
edit_phone = findViewById(R.id.edit_phone);
75+
relative_normal = findViewById(R.id.relative_normal);
76+
relative_normal.setOnClickListener(this);
77+
relative_error = findViewById(R.id.relative_error);
78+
relative_error.setOnClickListener(this);
79+
mImmersionBar = ImmersionBar.with(this);
80+
mImmersionBar.init();
81+
animButton.setLoginClickListener(new SmartLoadingView.LoginClickListener() {
82+
@Override
83+
public void click() {
84+
//按钮点击后去进行联网操作
85+
//这里模拟联网操作
86+
if (isNormalNet){
87+
mhandler.sendEmptyMessageDelayed(11, 2000);
88+
}else {
89+
mhandler.sendEmptyMessageDelayed(12, 2000);
90+
}
91+
}
92+
});
93+
94+
95+
}
96+
97+
@Override
98+
protected void onDestroy() {
99+
super.onDestroy();
100+
mImmersionBar.destroy();
101+
}
102+
103+
104+
@Override
105+
public boolean dispatchTouchEvent(MotionEvent ev) {
106+
//点击edittxt外,关闭软键盘
107+
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
108+
View v = getCurrentFocus();
109+
if (KeyBoardUtils.isShouldHideInput(v, ev)) {
110+
KeyBoardUtils.closeKeybord(edit_phone, LoginActivity.this);
111+
edit_phone.clearFocus();
112+
}
113+
}
114+
return super.dispatchTouchEvent(ev);
115+
}
116+
117+
@Override
118+
public void onClick(View v) {
119+
switch (v.getId()){
120+
case R.id.relative_normal:
121+
isNormalNet = true;
122+
relative_normal.setSelected(true);
123+
relative_error.setSelected(false);
124+
break;
125+
case R.id.relative_error:
126+
isNormalNet = false;
127+
relative_normal.setSelected(false);
128+
relative_error.setSelected(true);
129+
break;
130+
}
16131
}
17132
}

0 commit comments

Comments
 (0)