Skip to content

Commit f34c0a4

Browse files
committed
1:本来想给这个APP弄点干活,结果”干货集中营“的API调不通了,先上传代码吧
1 parent e5fc5aa commit f34c0a4

35 files changed

Lines changed: 880 additions & 9 deletions

‎app/src/main/java/com/guiying/androidmodulepattern/MainActivity.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package com.guiying.androidmodulepattern;
22

33
import android.os.Bundle;
4+
import android.support.design.widget.Snackbar;
5+
import android.view.KeyEvent;
46
import android.view.View;
57
import android.widget.Button;
68

79
import com.github.mzule.activityrouter.router.Routers;
810
import com.guiying.common.base.BaseActivity;
11+
import com.guiying.common.base.BaseApplication;
912

1013
public class MainActivity extends BaseActivity implements View.OnClickListener {
1114

15+
16+
private long exitTime = 0;
17+
1218
protected Button newsButton;
1319
protected Button girlsButton;
1420

@@ -31,4 +37,20 @@ public void onClick(View view) {
3137
}
3238
}
3339

40+
41+
@Override
42+
public boolean onKeyDown(int keyCode, KeyEvent event) {
43+
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
44+
//两秒之内按返回键就会退出
45+
if ((System.currentTimeMillis() - exitTime) > 2000) {
46+
Snackbar.make(girlsButton, getString(R.string.app_exit_hint), Snackbar.LENGTH_LONG).show();
47+
exitTime = System.currentTimeMillis();
48+
} else {
49+
BaseApplication.getIns().exitApp(this);
50+
}
51+
return true;
52+
}
53+
return super.onKeyDown(keyCode, event);
54+
}
55+
3456
}

‎app/src/main/java/com/guiying/androidmodulepattern/MyApplication.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.github.mzule.activityrouter.annotation.Modules;
44
import com.guiying.common.base.BaseApplication;
5+
import com.guiying.common.http.HttpClient;
6+
import com.guiying.common.http.OnResultListener;
7+
import com.orhanobut.logger.Logger;
58

69
/**
710
* <p>类说明</p>
@@ -13,8 +16,34 @@
1316
@Modules({"app", "girls", "news"})
1417
public class MyApplication extends BaseApplication {
1518

19+
String GAN_HUO_API = "http://gank.io/";
20+
1621
@Override
1722
public void onCreate() {
1823
super.onCreate();
24+
HttpClient client = new HttpClient.Builder()
25+
.baseUrl(GAN_HUO_API)
26+
.url("api/data")
27+
.params("type", "福利")
28+
.params("count", String.valueOf(20))
29+
.params("page", String.valueOf(1))
30+
.build();
31+
client.post(new OnResultListener<String>() {
32+
33+
@Override
34+
public void onSuccess(String result) {
35+
Logger.e(result);
36+
}
37+
38+
@Override
39+
public void onError(int code, String message) {
40+
Logger.e(message);
41+
}
42+
43+
@Override
44+
public void onFailure(String message) {
45+
Logger.e(message);
46+
}
47+
});
1948
}
2049
}

‎app/src/main/res/values/strings.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@
22
<string name="app_name">AndroidModulePattern</string>
33

44
<string name="global_scheme">module</string>
5+
6+
<string name="app_exit_hint">再按一次退出程序哦~</string>
7+
58
</resources>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<corners android:radius="4dp" />
4+
<solid android:color="@color/gray_66" />
5+
</shape>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--easyrecyclerview库的公用布局-->
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="horizontal"
4+
android:layout_width="match_parent"
5+
android:layout_height="48dp">
6+
7+
<TextView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:gravity="center"
11+
android:text="@string/load_error_resume" />
12+
</LinearLayout>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--easyrecyclerview库的公用布局-->
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="horizontal"
4+
android:gravity="center"
5+
android:padding="8dp"
6+
android:layout_width="match_parent"
7+
android:layout_height="50dp">
8+
9+
<ProgressBar
10+
android:layout_width="20dp"
11+
android:layout_height="20dp" />
12+
13+
<TextView
14+
android:text="@string/more_loading"
15+
android:textSize="14sp"
16+
android:layout_marginLeft="3dp"
17+
android:layout_marginStart="3dp"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content" />
20+
21+
</LinearLayout>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--easyrecyclerview库的公用布局-->
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="horizontal"
4+
android:layout_width="match_parent"
5+
android:layout_height="48dp">
6+
7+
<TextView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:gravity="center"
11+
android:text="@string/no_more" />
12+
</LinearLayout>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--easyrecyclerview库的公用布局-->
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<ProgressBar
8+
android:layout_gravity="center"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content" />
11+
12+
</FrameLayout>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?><!--easyrecyclerview库的公用布局-->
2+
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="wrap_content"
4+
android:layout_height="wrap_content"
5+
android:layout_gravity="center"
6+
android:text="@string/no_data"
7+
android:textSize="18sp" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="wrap_content"
4+
android:layout_height="wrap_content"
5+
android:layout_gravity="center"
6+
android:background="@drawable/shape_loading_bg"
7+
android:gravity="center"
8+
android:minHeight="@dimen/size_64dp"
9+
android:minWidth="@dimen/size_110dp"
10+
android:orientation="vertical"
11+
android:padding="@dimen/size_10dp">
12+
13+
<ProgressBar
14+
android:id="@+id/progress_bar"
15+
android:layout_width="@dimen/size_30dp"
16+
android:layout_height="@dimen/size_30dp" />
17+
18+
<TextView
19+
android:id="@+id/tipTextView"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="@dimen/size_10dp"
23+
android:text="@string/loading"
24+
android:textColor="@android:color/darker_gray"
25+
android:textSize="@dimen/text_size_15sp" />
26+
27+
</LinearLayout>

0 commit comments

Comments
 (0)