FreeRDP
Loading...
Searching...
No Matches
AboutActivity.java
1/*
2 Activity that displays the about page
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.presentation;
12
13import android.content.pm.PackageManager;
14import android.content.res.Configuration;
15import android.os.Build;
16import android.os.Bundle;
17import android.util.Log;
18import android.webkit.WebSettings;
19import android.webkit.WebView;
20import android.webkit.WebViewClient;
21
22import androidx.appcompat.app.AppCompatActivity;
23
24import com.freerdp.freerdpcore.R;
25import com.freerdp.freerdpcore.services.LibFreeRDP;
26
27import java.io.BufferedReader;
28import java.io.IOException;
29import java.io.InputStream;
30import java.io.InputStreamReader;
31import java.util.Locale;
32
33public class AboutActivity extends AppCompatActivity
34{
35 private static final String TAG = AboutActivity.class.toString();
36 private WebView mWebView;
37
38 @Override protected void onCreate(Bundle savedInstanceState)
39 {
40 super.onCreate(savedInstanceState);
41 setContentView(R.layout.activity_about);
42
43 if (getSupportActionBar() != null)
44 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
45
46 mWebView = findViewById(R.id.activity_about_webview);
47
48 WebSettings settings = mWebView.getSettings();
49 settings.setDomStorageEnabled(true);
50 settings.setUseWideViewPort(true);
51 settings.setLoadWithOverviewMode(true);
52 settings.setSupportZoom(true);
53
54 mWebView.setWebViewClient(new WebViewClient() {
55 @Override public boolean shouldOverrideUrlLoading(WebView view, String url)
56 {
57 if (url.startsWith("file:///android_asset/"))
58 {
59 view.loadUrl(url);
60 return true;
61 }
62 return false;
63 }
64 });
65
66 populate();
67 }
68
69 @Override public boolean onSupportNavigateUp()
70 {
71 finish();
72 return true;
73 }
74
75 private void populate()
76 {
77 String filename = "about_phone.html";
78 if ((getResources().getConfiguration().screenLayout &
79 Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE)
80 filename = "about.html";
81
82 Locale def = Locale.getDefault();
83 String prefix = def.getLanguage().toLowerCase(def);
84 String dir = prefix + "_about_page/";
85 String file = dir + filename;
86
87 try
88 {
89 InputStream is = getAssets().open(file);
90 is.close();
91 }
92 catch (IOException e)
93 {
94 Log.d(TAG, "No localized asset " + file + ", falling back to default");
95 dir = "about_page/";
96 file = dir + filename;
97 }
98
99 StringBuilder total = new StringBuilder();
100 try (BufferedReader r = new BufferedReader(new InputStreamReader(getAssets().open(file))))
101 {
102 String line;
103 while ((line = r.readLine()) != null)
104 {
105 total.append(line);
106 total.append("\n");
107 }
108 }
109 catch (IOException e)
110 {
111 Log.e(TAG, "Could not read about page " + file, e);
112 }
113
114 String version;
115 try
116 {
117 version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
118 }
119 catch (PackageManager.NameNotFoundException e)
120 {
121 version = "unknown";
122 }
123 version = version + " (" + LibFreeRDP.getVersion() + ")";
124
125 final String base = "file:///android_asset/" + dir;
126 final String html = total.toString()
127 .replaceAll("%AFREERDP_VERSION%", version)
128 .replaceAll("%SYSTEM_VERSION%", Build.VERSION.RELEASE)
129 .replaceAll("%DEVICE_MODEL%", Build.MODEL);
130
131 mWebView.loadDataWithBaseURL(base, html, "text/html", null, "about:blank");
132 }
133}