use of androidx.webkit.WebViewAssetLoader in project MachEWidget by khpylon.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this.getApplicationContext();
// First thing, check logcat for a crash and save if so
String crashMessage = Utils.checkLogcat(context);
if (crashMessage != null) {
Toast.makeText(context, crashMessage, Toast.LENGTH_SHORT).show();
}
// Initialize preferences
PreferenceManager.setDefaultValues(this, R.xml.settings_preferences, false);
// Handle any changes to the app.
performUpdates(context);
// Initiate check for a new app version
UpdateReceiver.initiateAlarm(context);
// See if we need to notify user about battery optimizations
Notifications.batteryOptimization(context);
// Initiate update of the widget
Intent updateIntent = new Intent();
updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
context.sendBroadcast(updateIntent);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
ActivityCompat.requestPermissions(MainActivity.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1);
}
}
}
// If app has been running OK, try to initiate status updates
String userId = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getResources().getString(R.string.userId_key), null);
if (userId != null) {
new Thread(() -> {
InfoRepository info = new InfoRepository(context);
UserInfo userInfo = info.getUser();
if (userInfo != null && userInfo.getProgramState().equals(Constants.STATE_HAVE_TOKEN_AND_VIN)) {
StatusReceiver.initateAlarm(context);
}
}).start();
}
// Create the webview containing instruction for use.
WebView mWebView = findViewById(R.id.main_description);
int nightModeFlags = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
WebSettingsCompat.setForceDark(mWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
}
final WebViewAssetLoader assetLoader = new WebViewAssetLoader.Builder().addPathHandler("/assets/", new WebViewAssetLoader.AssetsPathHandler(this)).addPathHandler("/res/", new WebViewAssetLoader.ResourcesPathHandler(this)).build();
mWebView.setWebViewClient(new LocalContentWebViewClient(assetLoader));
String indexPage = "https://appassets.androidplatform.net/assets/index_mache.html";
// String VIN = PreferenceManager.getDefaultSharedPreferences(context).getString(context.getResources().getString(R.string.VIN_key), "");
// if (!VIN.equals("")) {
// if (Utils.isBronco(VIN)) {
// indexPage = "https://appassets.androidplatform.net/assets/index_bronco.html";
// } else if (Utils.isF150(VIN)) {
// indexPage = "https://appassets.androidplatform.net/assets/index_f150.html";
// } else if (Utils.isExplorer(VIN)) {
// indexPage = "https://appassets.androidplatform.net/assets/index_explorer.html";
// }
// }
mWebView.loadUrl(indexPage);
// Update the widget
updateWidget(context);
// Allow the app to display notifications
createNotificationChannel();
}
Aggregations