1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package de.danoeh.antennapod.activity;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* Displays the 'about' screen
*/
public class AboutActivity extends ActionBarActivity {
private static final String TAG = AboutActivity.class.getSimpleName();
private WebView webview;
private LinearLayout webviewContainer;
private Subscription subscription;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(UserPreferences.getTheme());
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.about);
webviewContainer = (LinearLayout) findViewById(R.id.webvContainer);
webview = (WebView) findViewById(R.id.webvAbout);
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
if (Build.VERSION.SDK_INT >= 11
&& Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
webview.setBackgroundColor(Color.TRANSPARENT);
}
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
subscription = Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
InputStream input = null;
try {
TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes(
new int[] { android.R.attr.textColorPrimary });
int colorResource = res.getColor(0, 0);
String colorString = String.format("#%06X", 0xFFFFFF & colorResource);
res.recycle();
input = getAssets().open("about.html");
String webViewData = IOUtils.toString(input, Charset.defaultCharset());
webViewData = String.format(webViewData, colorString);
subscriber.onNext(webViewData);
} catch (IOException e) {
subscriber.onError(e);
} finally {
IOUtils.closeQuietly(input);
}
subscriber.onCompleted();
}
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(webviewData -> {
webview.loadDataWithBaseURL(null, webviewData, "text/html", "utf-8", "about:blank");
}, error -> {
Log.e(TAG, Log.getStackTraceString(error));
});
}
@Override
protected void onDestroy() {
super.onDestroy();
if(subscription != null) {
subscription.unsubscribe();
}
if (webviewContainer != null && webview != null) {
webviewContainer.removeAllViews();
webview.destroy();
}
}
}
|