FreeRDP
AboutActivity.java
1 package com.freerdp.freerdpcore.presentation;
2 
3 import android.content.pm.PackageManager;
4 import android.content.res.Configuration;
5 import android.nfc.FormatException;
6 import android.os.Build;
7 import android.os.Bundle;
8 import androidx.core.text.TextUtilsCompat;
9 import androidx.appcompat.app.AppCompatActivity;
10 import android.util.Log;
11 import android.webkit.WebSettings;
12 import android.webkit.WebView;
13 
14 import com.freerdp.freerdpcore.R;
15 import com.freerdp.freerdpcore.services.LibFreeRDP;
16 
17 import java.io.BufferedReader;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.InputStreamReader;
21 import java.util.Formatter;
22 import java.util.IllegalFormatException;
23 import java.util.Locale;
24 
25 public class AboutActivity extends AppCompatActivity
26 {
27  private static final String TAG = AboutActivity.class.toString();
28  private WebView mWebView;
29 
30  @Override protected void onCreate(Bundle savedInstanceState)
31  {
32  super.onCreate(savedInstanceState);
33  setContentView(R.layout.activity_about);
34  mWebView = (WebView)findViewById(R.id.activity_about_webview);
35  }
36 
37  @Override protected void onResume()
38  {
39  populate();
40  super.onResume();
41  }
42 
43  private void populate()
44  {
45  StringBuilder total = new StringBuilder();
46 
47  String filename = "about_phone.html";
48  if ((getResources().getConfiguration().screenLayout &
49  Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE)
50  {
51  filename = "about.html";
52  }
53  Locale def = Locale.getDefault();
54  String prefix = def.getLanguage().toLowerCase(def);
55 
56  String dir = prefix + "_about_page/";
57  String file = dir + filename;
58  InputStream is;
59  try
60  {
61  is = getAssets().open(file);
62  is.close();
63  }
64  catch (IOException e)
65  {
66  Log.e(TAG, "Missing localized asset " + file, e);
67  dir = "about_page/";
68  file = dir + filename;
69  }
70 
71  try
72  {
73  try (BufferedReader r =
74  new BufferedReader(new InputStreamReader(getAssets().open(file))))
75  {
76  String line;
77  while ((line = r.readLine()) != null)
78  {
79  total.append(line);
80  total.append("\n");
81  }
82  }
83  }
84  catch (IOException e)
85  {
86  Log.e(TAG, "Could not read about page " + file, e);
87  }
88 
89  // append FreeRDP core version to app version
90  // get app version
91  String version;
92  try
93  {
94  version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
95  }
96  catch (PackageManager.NameNotFoundException e)
97  {
98  version = "unknown";
99  }
100  version = version + " (" + LibFreeRDP.getVersion() + ")";
101 
102  WebSettings settings = mWebView.getSettings();
103  settings.setDomStorageEnabled(true);
104  settings.setUseWideViewPort(true);
105  settings.setLoadWithOverviewMode(true);
106  settings.setSupportZoom(true);
107 
108  final String base = "file:///android_asset/" + dir;
109 
110  final String rawHtml = total.toString();
111  final String html = rawHtml.replaceAll("%AFREERDP_VERSION%", version)
112  .replaceAll("%SYSTEM_VERSION%", Build.VERSION.RELEASE)
113  .replaceAll("%DEVICE_MODEL%", Build.MODEL);
114 
115  mWebView.loadDataWithBaseURL(base, html, "text/html", null, "about:blank");
116  }
117 }