FreeRDP
HelpActivity.java
1 /*
2  Activity that displays the help pages
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 
11 package com.freerdp.freerdpcore.presentation;
12 
13 import android.content.res.Configuration;
14 import android.os.Bundle;
15 import androidx.appcompat.app.AppCompatActivity;
16 import android.util.Log;
17 import android.webkit.WebSettings;
18 import android.webkit.WebView;
19 
20 import java.io.BufferedReader;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.InputStreamReader;
24 import java.util.Locale;
25 
26 public class HelpActivity extends AppCompatActivity
27 {
28 
29  private static final String TAG = HelpActivity.class.toString();
30 
31  @Override public void onCreate(Bundle savedInstanceState)
32  {
33  super.onCreate(savedInstanceState);
34 
35  WebView webview = new WebView(this);
36  setContentView(webview);
37 
38  String filename;
39  if ((getResources().getConfiguration().screenLayout &
40  Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE)
41  filename = "gestures.html";
42  else
43  filename = "gestures_phone.html";
44 
45  WebSettings settings = webview.getSettings();
46  settings.setDomStorageEnabled(true);
47  settings.setUseWideViewPort(true);
48  settings.setLoadWithOverviewMode(true);
49  settings.setSupportZoom(true);
50  settings.setJavaScriptEnabled(true);
51 
52  settings.setAllowContentAccess(true);
53  settings.setAllowFileAccess(true);
54 
55  final Locale def = Locale.getDefault();
56  final String prefix = def.getLanguage().toLowerCase(def);
57 
58  final String base = "file:///android_asset/";
59  final String baseName = "help_page";
60  String dir = prefix + "_" + baseName + "/";
61  String file = dir + filename;
62  InputStream is;
63  try
64  {
65  is = getAssets().open(file);
66  is.close();
67  }
68  catch (IOException e)
69  {
70  Log.e(TAG, "Missing localized asset " + file, e);
71  dir = baseName + "/";
72  file = dir + filename;
73  }
74 
75  webview.loadUrl(base + file);
76  }
77 }