Saturday 25 November 2017

Android MathView Example

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />

MainActivity.java
package com.mathviewandroid;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    String
tex = "This come from string. You can insert inline formula:" +
           
" \\(ax^2 + bx + c = 0\\) " +
           
"or displayed formula: $$\\sum_{i=0}^n i^2 = \\frac{(n^2+n)(2n+1)}{6}$$";

   
private WebView webView;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

       
webView = (WebView) findViewById(R.id.webView1);
       
webView.addJavascriptInterface(new WebAppInterface(this), "android");
        WebSettings ws =
webView.getSettings();
        ws.setJavaScriptEnabled(
true);
       
webView.setWebViewClient(new WebViewClient() {

           
public void onPageFinished(WebView view, String url){
                
// do your stuff here

           
}
        });

       
webView.loadDataWithBaseURL(null, "<style type=text/css>img{display: inline;height: auto;max-width: 100%;} @font-face{font-family: \"chantelli_antiqua\";src: url('file:///android_asset/fonts/MavenPro-Regular.ttf');}body{font-family: \"Chantelli_Antiqua\";}\n</style> <script type=\"text/javascript\"\n" +
               
"        src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG\">\n" +
               
"</script>" + tex, "text/html", "UTF-8", null);
    }

   
public class WebAppInterface {
        Context
mContext;

       
/** Instantiate the interface and set the context */
       
WebAppInterface(Context c) {
           
mContext = c;
        }

       
/** Show a toast from the web page */
       
@JavascriptInterface
       
public void showToast(String toast) {
            Toast.makeText(
mContext, toast, Toast.LENGTH_SHORT).show();
        }
    }
}

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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="com.mathviewandroid.MainActivity">



    <WebView

        xmlns:android="http://schemas.android.com/apk/res/android"

        android:id="@+id/webView1"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:visibility="visible"

        android:layout_margin="10dp"/>



</LinearLayout>

import android.content.Context;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.webkit.JavascriptInterface;

import android.webkit.WebSettings;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.ProgressBar;

import android.widget.Toast;



public class PDFViewActivity extends AppCompatActivity {



    WebView webView;

    String pdf_file = "http://integrityinitiative.com/wp-content/uploads/2017/06/Lorem-Ipsum.pdf";



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_pdfview);



        webView = (WebView)findViewById(R.id.webView1);

        WebSettings ws = webView.getSettings();

        ws.setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient() {



            public void onPageFinished(WebView view, String url){

                // do your stuff here

                webView.loadUrl("javascript:(function() { " +

                        "document.getElementsByClassName('ndfHFb-c4YZDc-GSQQnc-LgbsSe ndfHFb-c4YZDc-to915-LgbsSe VIpgJd-TzA9Ye-eEGnhe ndfHFb-c4YZDc-LgbsSe')[0].style.display='none'; })()");

            }

        });

        webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf_file);

    }

}


No comments:

Post a Comment

CCAvenue Payment Gateway Android Integration

CCAvenue Payment Gateway Android Integration CCAvenue payment gateway android integration using PHP RSA and Response Handling. An...