Browse Source

Added inline viewing of images and links

main
M66B 6 years ago
parent
commit
58adbf64c3
5 changed files with 147 additions and 1 deletions
  1. +8
    -0
      app/src/main/AndroidManifest.xml
  2. +1
    -0
      app/src/main/java/eu/faircode/email/ActivityView.java
  3. +38
    -1
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  4. +75
    -0
      app/src/main/java/eu/faircode/email/FragmentWebView.java
  5. +25
    -0
      app/src/main/res/layout/fragment_webview.xml

+ 8
- 0
app/src/main/AndroidManifest.xml View File

@ -17,6 +17,14 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppThemeLight"> android:theme="@style/AppThemeLight">
<!-- do not contact Google servers -->
<meta-data
android:name="android.webkit.WebView.MetricsOptOut"
android:value="true" />
<meta-data
android:name="android.webkit.WebView.EnableSafeBrowsing"
android:value="false" />
<activity android:name=".ActivitySetup" /> <activity android:name=".ActivitySetup" />
<activity android:name=".ActivityView"> <activity android:name=".ActivityView">


+ 1
- 0
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -77,6 +77,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view); setContentView(R.layout.activity_view);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);


+ 38
- 1
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -34,12 +34,16 @@ import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.Layout;
import android.text.Spannable;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -98,7 +102,40 @@ public class FragmentMessage extends Fragment {
grpReady = view.findViewById(R.id.grpReady); grpReady = view.findViewById(R.id.grpReady);
setHasOptionsMenu(true); setHasOptionsMenu(true);
tvBody.setMovementMethod(LinkMovementMethod.getInstance());
tvBody.setMovementMethod(new LinkMovementMethod() {
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_UP)
return super.onTouchEvent(widget, buffer, event);
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
URLSpan[] link = buffer.getSpans(off, off, URLSpan.class);
if (link.length != 0) {
Bundle args = new Bundle();
args.putString("link", link[0].getURL());
FragmentWebView fragment = new FragmentWebView();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("link");
fragmentTransaction.commit();
}
return true;
}
});
// Wire controls // Wire controls


+ 75
- 0
app/src/main/java/eu/faircode/email/FragmentWebView.java View File

@ -0,0 +1,75 @@
package eu.faircode.email;
/*
This file is part of Safe email.
Safe email 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.
NetGuard 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 NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
// https://developer.android.com/reference/android/webkit/WebView
public class FragmentWebView extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_webview, container, false);
final ProgressBar progressBar = view.findViewById(R.id.progressbar);
WebView webview = view.findViewById(R.id.webview);
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
//settings.setBuiltInZoomControls(true);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
if (progress == 100)
progressBar.setVisibility(View.GONE);
}
});
webview.loadUrl(getArguments().getString("link"));
return view;
}
}

+ 25
- 0
app/src/main/res/layout/fragment_webview.xml View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progressbar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progress="50"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/progressbar" />
</android.support.constraint.ConstraintLayout>

Loading…
Cancel
Save