FreeRDP
Loading...
Searching...
No Matches
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
11package com.freerdp.freerdpcore.presentation;
12
13import android.content.res.Configuration;
14import android.os.Bundle;
15import android.util.Log;
16import android.webkit.WebSettings;
17import android.webkit.WebView;
18import android.webkit.WebViewClient;
19
20import androidx.appcompat.app.AppCompatActivity;
21
22import com.freerdp.freerdpcore.R;
23
24import java.io.IOException;
25import java.io.InputStream;
26import java.util.Locale;
27
28public class HelpActivity extends AppCompatActivity
29{
30 private static final String TAG = HelpActivity.class.toString();
31 private WebView mWebView;
32
33 @Override public void onCreate(Bundle savedInstanceState)
34 {
35 super.onCreate(savedInstanceState);
36 setContentView(R.layout.activity_help);
37
38 if (getSupportActionBar() != null)
39 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
40
41 mWebView = findViewById(R.id.activity_help_webview);
42
43 WebSettings settings = mWebView.getSettings();
44 settings.setDomStorageEnabled(true);
45 settings.setUseWideViewPort(true);
46 settings.setLoadWithOverviewMode(true);
47 settings.setSupportZoom(true);
48 settings.setJavaScriptEnabled(true);
49 settings.setAllowContentAccess(true);
50 settings.setAllowFileAccess(true);
51
52 mWebView.setWebViewClient(new WebViewClient() {
53 @Override public boolean shouldOverrideUrlLoading(WebView view, String url)
54 {
55 if (url.startsWith("file:///android_asset/"))
56 {
57 view.loadUrl(url);
58 return true;
59 }
60 return false;
61 }
62 });
63
64 populate();
65 }
66
67 @Override public boolean onSupportNavigateUp()
68 {
69 finish();
70 return true;
71 }
72
73 private void populate()
74 {
75 String filename;
76 if ((getResources().getConfiguration().screenLayout &
77 Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE)
78 filename = "gestures.html";
79 else
80 filename = "gestures_phone.html";
81
82 Locale def = Locale.getDefault();
83 String prefix = def.getLanguage().toLowerCase(def);
84 String dir = prefix + "_help_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 = "help_page/";
96 file = dir + filename;
97 }
98
99 mWebView.loadUrl("file:///android_asset/" + file);
100 }
101}