mirror of https://github.com/M66B/FairEmail.git
parent
2fbe0904cd
commit
3f59ddfd46
@ -0,0 +1,155 @@
|
|||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.constraintlayout.widget.Group;
|
||||||
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class ActivityAMP extends ActivityBase {
|
||||||
|
private WebView wvAmp;
|
||||||
|
private ContentLoadingProgressBar pbWait;
|
||||||
|
private Group grpReady;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getSupportActionBar().setIcon(R.drawable.twotone_bolt_24);
|
||||||
|
getSupportActionBar().setSubtitle("AMP");
|
||||||
|
|
||||||
|
View view = LayoutInflater.from(this).inflate(R.layout.activity_amp, null);
|
||||||
|
setContentView(view);
|
||||||
|
|
||||||
|
wvAmp = findViewById(R.id.wvAmp);
|
||||||
|
pbWait = findViewById(R.id.pbWait);
|
||||||
|
grpReady = findViewById(R.id.grpReady);
|
||||||
|
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
boolean safe_browsing = prefs.getBoolean("safe_browsing", false);
|
||||||
|
|
||||||
|
WebSettings settings = wvAmp.getSettings();
|
||||||
|
settings.setUserAgentString(WebViewEx.getUserAgent(this, wvAmp));
|
||||||
|
settings.setUseWideViewPort(true);
|
||||||
|
settings.setLoadWithOverviewMode(true);
|
||||||
|
|
||||||
|
settings.setBuiltInZoomControls(true);
|
||||||
|
settings.setDisplayZoomControls(false);
|
||||||
|
|
||||||
|
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
|
||||||
|
|
||||||
|
settings.setAllowFileAccess(false);
|
||||||
|
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
|
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
|
settings.setSafeBrowsingEnabled(safe_browsing);
|
||||||
|
|
||||||
|
settings.setLoadsImagesAutomatically(true);
|
||||||
|
settings.setBlockNetworkLoads(false);
|
||||||
|
settings.setBlockNetworkImage(false);
|
||||||
|
settings.setJavaScriptEnabled(true);
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
grpReady.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
setIntent(intent);
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
|
Uri uri = getIntent().getData();
|
||||||
|
Log.i("AMP uri=" + uri);
|
||||||
|
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable("uri", uri);
|
||||||
|
|
||||||
|
new SimpleTask<String>() {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute(Bundle args) {
|
||||||
|
pbWait.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Bundle args) {
|
||||||
|
pbWait.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
Uri uri = args.getParcelable("uri");
|
||||||
|
|
||||||
|
if (uri == null)
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
|
||||||
|
if (!"content".equals(uri.getScheme()) &&
|
||||||
|
!Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) {
|
||||||
|
Log.w("AMP uri=" + uri);
|
||||||
|
throw new IllegalArgumentException(context.getString(R.string.title_no_stream));
|
||||||
|
}
|
||||||
|
|
||||||
|
ContentResolver resolver = context.getContentResolver();
|
||||||
|
try (InputStream is = resolver.openInputStream(uri)) {
|
||||||
|
return Helper.readStream(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, String amp) {
|
||||||
|
wvAmp.loadDataWithBaseURL(null, amp, "text/html", StandardCharsets.UTF_8.name(), null);
|
||||||
|
grpReady.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, @NonNull Throwable ex) {
|
||||||
|
if (ex instanceof IllegalArgumentException)
|
||||||
|
Snackbar.make(findViewById(android.R.id.content), ex.getMessage(), Snackbar.LENGTH_LONG)
|
||||||
|
.setGestureInsetBottomIgnored(true).show();
|
||||||
|
else
|
||||||
|
Log.unexpectedError(getSupportFragmentManager(), ex, false);
|
||||||
|
}
|
||||||
|
}.execute(this, args, "amp:decode");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context="eu.faircode.email.ActivityAMP">
|
||||||
|
|
||||||
|
<WebView
|
||||||
|
android:id="@+id/wvAmp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<eu.faircode.email.ContentLoadingProgressBar
|
||||||
|
android:id="@+id/pbWait"
|
||||||
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.Group
|
||||||
|
android:id="@+id/grpReady"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
app:constraint_referenced_ids="wvAmp" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in new issue