Skip to content

Commit 5e9d00c

Browse files
committed
完善Demo
1 parent d07d8dd commit 5e9d00c

8 files changed

Lines changed: 175 additions & 19 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
<activity
2929
android:name=".activities.ExtendReaderActivity"
3030
android:theme="@style/NoActionTheme" />
31-
<activity android:name=".activities.CustomReaderActivity"></activity>
31+
<activity android:name=".activities.CustomReaderActivity" />
32+
<activity android:name=".activities.WebViewActivity"></activity>
3233
</application>
3334

3435
</manifest>

app/src/main/java/com/glong/sample/activities/CustomReaderActivity.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.glong.sample.activities;
22

3+
import android.content.Intent;
34
import android.os.Bundle;
45
import android.support.v7.app.AppCompatActivity;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.widget.Toast;
59

610
import com.glong.reader.widget.ReaderView;
711
import com.glong.sample.R;
@@ -62,7 +66,22 @@ public String obtainChapterContent(ChapterContentBean chapterContentBean) {
6266
return "曹操</p>" + "神龟虽寿,犹有竟时;</p>" + "腾蛇乘雾,终为土灰。</p>"
6367
+ "老骥伏枥,志在千里;</p>" + "烈士暮年,壮心不已。</p>"
6468
+ "盈缩之期,不但在天;</p>" + "养怡之福,可得永年。</p>"
65-
+ "幸甚至哉,歌以咏志。";
69+
+ "幸甚至哉,歌以咏志。</p>"
70+
+
71+
"曹操</p>" + "神龟虽寿,犹有竟时;</p>" + "腾蛇乘雾,终为土灰。</p>"
72+
+ "老骥伏枥,志在千里;</p>" + "烈士暮年,壮心不已。</p>"
73+
+ "盈缩之期,不但在天;</p>" + "养怡之福,可得永年。</p>"
74+
+ "幸甚至哉,歌以咏志。</p>"
75+
+
76+
"曹操</p>" + "神龟虽寿,犹有竟时;</p>" + "腾蛇乘雾,终为土灰。</p>"
77+
+ "老骥伏枥,志在千里;</p>" + "烈士暮年,壮心不已。</p>"
78+
+ "盈缩之期,不但在天;</p>" + "养怡之福,可得永年。</p>"
79+
+ "幸甚至哉,歌以咏志。</p>"
80+
+
81+
"曹操</p>" + "神龟虽寿,犹有竟时;</p>" + "腾蛇乘雾,终为土灰。</p>"
82+
+ "老骥伏枥,志在千里;</p>" + "烈士暮年,壮心不已。</p>"
83+
+ "盈缩之期,不但在天;</p>" + "养怡之福,可得永年。</p>"
84+
+ "幸甚至哉,歌以咏志。</p>";
6685
}
6786

6887
@Override
@@ -74,5 +93,23 @@ public ChapterContentBean downLoad(ChapterItemBean chapterItemBean) {
7493
mReaderView.setAdapter(mAdapter);
7594
readerManager.setCustomReaderResolve(new MyReaderResolve());
7695
mReaderView.setLineSpace(50);
96+
97+
View firstPageView = LayoutInflater.from(this).inflate(R.layout.first_page_view_layout, null);
98+
firstPageView.findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() {
99+
@Override
100+
public void onClick(View v) {
101+
Toast.makeText(CustomReaderActivity.this, "You clicked ImageView!", Toast.LENGTH_SHORT).show();
102+
}
103+
});
104+
mReaderView.addView(firstPageView, ReaderView.ChildInPage.FIRST_PAGE);
105+
106+
View lastPageView = LayoutInflater.from(this).inflate(R.layout.last_page_view_layout, null);
107+
lastPageView.findViewById(R.id.imageView2).setOnClickListener(new View.OnClickListener() {
108+
@Override
109+
public void onClick(View v) {
110+
startActivity(new Intent(CustomReaderActivity.this, WebViewActivity.class));
111+
}
112+
});
113+
mReaderView.addView(lastPageView, ReaderView.ChildInPage.LAST_PAGE);
77114
}
78115
}

app/src/main/java/com/glong/sample/activities/ExtendReaderActivity.java

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.glong.sample.activities;
22

3-
import android.annotation.SuppressLint;
43
import android.os.Bundle;
54
import android.support.annotation.NonNull;
65
import android.support.design.widget.NavigationView;
@@ -41,8 +40,9 @@
4140

4241
import java.util.List;
4342

43+
import io.reactivex.Observer;
4444
import io.reactivex.android.schedulers.AndroidSchedulers;
45-
import io.reactivex.functions.Consumer;
45+
import io.reactivex.disposables.Disposable;
4646
import io.reactivex.schedulers.Schedulers;
4747

4848
public class ExtendReaderActivity extends AppCompatActivity implements View.OnClickListener {
@@ -244,22 +244,46 @@ public TurnStatus toNextPage() {
244244
});
245245
}
246246

247-
@SuppressLint("CheckResult")
247+
private Disposable mDisposable;
248+
248249
private void initData() {
249250
Api.getInstance().getService(Service.class).catalog(Api.KEY)
250251
.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
251-
.subscribe(new Consumer<Result<List<ChapterItemBean>>>() {
252+
.subscribe(new Observer<Result<List<ChapterItemBean>>>() {
253+
@Override
254+
public void onSubscribe(Disposable d) {
255+
mDisposable = d;
256+
}
257+
252258
@Override
253-
public void accept(Result<List<ChapterItemBean>> listResult) throws Exception {
259+
public void onNext(Result<List<ChapterItemBean>> listResult) {
254260
List<ChapterItemBean> chapters = listResult.getResult();
255-
mAdapter.setChapterList(chapters);
256-
mAdapter.notifyDataSetChanged();
257-
mChapterSeekBar.setMax(chapters.size() - 1);
258-
mCatalogueAdapter.setList(chapters);
261+
if (chapters != null) {
262+
mAdapter.setChapterList(chapters);
263+
mAdapter.notifyDataSetChanged();
264+
mChapterSeekBar.setMax(chapters.size() - 1);
265+
mCatalogueAdapter.setList(chapters);
266+
}
267+
}
268+
269+
@Override
270+
public void onError(Throwable e) {
271+
}
272+
273+
@Override
274+
public void onComplete() {
259275
}
260276
});
261277
}
262278

279+
@Override
280+
protected void onDestroy() {
281+
super.onDestroy();
282+
if (mDisposable != null && !mDisposable.isDisposed()) {
283+
mDisposable.dispose();
284+
}
285+
}
286+
263287
private long mDownTime;
264288
private float mDownX;
265289

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
11
package com.glong.sample.activities;
22

3-
import android.support.v7.app.AppCompatActivity;
43
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.view.View;
6+
import android.webkit.WebChromeClient;
7+
import android.webkit.WebView;
8+
import android.widget.ProgressBar;
9+
10+
import com.glong.sample.R;
511

612
public class WebViewActivity extends AppCompatActivity {
713

814
@Override
915
protected void onCreate(Bundle savedInstanceState) {
1016
super.onCreate(savedInstanceState);
1117
setContentView(R.layout.activity_web_view);
18+
WebView webView = findViewById(R.id.web_view);
19+
final ProgressBar progressBar = findViewById(R.id.progressBar);
20+
21+
webView.loadUrl("https://github.com/GarrettLance/Reader");
22+
23+
webView.setWebChromeClient(new WebChromeClient() {
24+
@Override
25+
public void onProgressChanged(WebView view, int newProgress) {
26+
//显示进度条
27+
progressBar.setProgress(newProgress);
28+
if (newProgress == 100) {
29+
//加载完毕隐藏进度条
30+
progressBar.setVisibility(View.GONE);
31+
}
32+
super.onProgressChanged(view, newProgress);
33+
}
34+
});
1235
}
1336
}
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<selector xmlns:android="http://schemas.android.com/apk/res/android">
2+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@android:id/background">
4+
<shape>
5+
<corners android:radius="2dp" />
36

4-
</selector>
7+
<gradient
8+
android:angle="270"
9+
android:centerColor="#E3E3E3"
10+
android:endColor="#E6E6E6"
11+
android:startColor="#C8C8C8" />
12+
</shape>
13+
</item>
14+
<item android:id="@android:id/progress">
15+
<clip>
16+
<shape>
17+
<corners android:radius="2dp" />
18+
19+
<gradient
20+
android:centerColor="@android:color/holo_red_dark"
21+
android:endColor="@android:color/holo_red_dark"
22+
android:startColor="@android:color/holo_red_dark" />
23+
</shape>
24+
</clip>
25+
</item>
26+
</layer-list>

app/src/main/res/layout/activity_web_view.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,20 @@
66
android:layout_height="match_parent"
77
tools:context=".activities.WebViewActivity">
88

9+
<WebView
10+
android:id="@+id/web_view"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent">
13+
14+
</WebView>
15+
16+
<ProgressBar
17+
android:id="@+id/progressBar"
18+
style="?android:attr/progressBarStyleHorizontal"
19+
android:layout_width="fill_parent"
20+
android:layout_height="8dp"
21+
android:indeterminateOnly="false"
22+
android:max="100"
23+
android:progressDrawable="@drawable/progress_bar_states"/>
24+
925
</android.support.constraint.ConstraintLayout>

app/src/main/res/layout/first_page_view_layout.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
<TextView
2323
android:id="@+id/textView"
24-
android:layout_width="0dp"
24+
android:layout_width="wrap_content"
2525
android:layout_height="wrap_content"
26-
android:layout_marginBottom="8dp"
26+
android:background="@android:color/white"
27+
android:layout_marginBottom="@dimen/qb_px_100"
2728
android:gravity="center"
2829
android:text="这是放在第一页的View,点我试一试哦"
2930
android:textColor="@android:color/black"
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.constraint.ConstraintLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
4-
android:layout_height="match_parent">
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:layout_gravity="bottom"
8+
android:alpha="0.8">
59

10+
<ImageView
11+
android:id="@+id/imageView2"
12+
android:layout_width="match_parent"
13+
android:layout_height="@dimen/qb_px_500"
14+
android:layout_marginStart="@dimen/qb_px_40"
15+
android:layout_marginEnd="@dimen/qb_px_40"
16+
android:layout_marginBottom="@dimen/qb_px_70"
17+
android:scaleType="centerCrop"
18+
app:layout_constraintBottom_toBottomOf="parent"
19+
app:layout_constraintEnd_toEndOf="parent"
20+
app:layout_constraintStart_toStartOf="parent"
21+
app:srcCompat="@drawable/test1" />
22+
23+
<TextView
24+
android:id="@+id/textView2"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_marginBottom="@dimen/qb_px_100"
28+
android:background="@android:color/white"
29+
android:gravity="center"
30+
android:text="如果您觉得不错,给点动力支持一下吧,给个star!"
31+
android:textColor="@android:color/black"
32+
android:textSize="@dimen/qb_px_40"
33+
android:textStyle="bold"
34+
app:layout_constraintBottom_toBottomOf="@+id/imageView2"
35+
app:layout_constraintEnd_toEndOf="@+id/imageView2"
36+
app:layout_constraintStart_toStartOf="@+id/imageView2"
37+
app:layout_constraintTop_toTopOf="@+id/imageView2" />
638
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)