-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathMainActivity.java
More file actions
78 lines (68 loc) · 2.32 KB
/
MainActivity.java
File metadata and controls
78 lines (68 loc) · 2.32 KB
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
package at.xtools.pwawrapper;
import android.content.Intent;
import android.net.Uri;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import at.xtools.pwawrapper.ui.UIManager;
import at.xtools.pwawrapper.webview.WebViewHelper;
public class MainActivity extends AppCompatActivity {
private WebViewHelper webViewHelper;
private boolean intentHandled = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Setup Theme
setTheme(R.style.AppTheme_NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Setup Helpers
// Globals
UIManager uiManager = new UIManager(this);
webViewHelper = new WebViewHelper(this, uiManager);
// Setup App
webViewHelper.setupWebView();
uiManager.changeRecentAppsIcon();
// Check for Intents
try {
Intent i = getIntent();
String intentAction = i.getAction();
// Handle URLs opened in Browser
if (!intentHandled && intentAction != null && intentAction.equals(Intent.ACTION_VIEW)){
Uri intentUri = i.getData();
String intentText = "";
if (intentUri != null){
intentText = intentUri.toString();
}
// Load up the URL specified in the Intent
if (!intentText.equals("")) {
intentHandled = true;
webViewHelper.loadIntentUrl(intentText);
}
} else {
// Load up the Web App
webViewHelper.loadHome();
}
} catch (Exception e) {
// Load up the Web App
webViewHelper.loadHome();
}
}
@Override
protected void onPause() {
webViewHelper.onPause();
super.onPause();
}
@Override
protected void onResume() {
webViewHelper.onResume();
// retrieve content from cache primarily if not connected
webViewHelper.forceCacheIfOffline();
super.onResume();
}
// Handle back-press in browser
@Override
public void onBackPressed() {
if (!webViewHelper.goBack()) {
super.onBackPressed();
}
}
}