Android Open Source - ivotingverification Help Activity






From Project

Back to project page ivotingverification.

License

The source code is released under:

GNU General Public License

If you think the Android project ivotingverification listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright (C) 2013 Eesti Vabariigi Valimiskomisjon 
 * (Estonian National Electoral Committee), www.vvk.ee
 *//from  ww w.  jav a  2  s .  com
 * Written in 2013 by AS Finestmedia, www.finestmedia.ee
 * 
 * Vote-verification application for Estonian Internet voting system
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 **/
 
package ee.vvk.ivotingverification;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.webkit.GeolocationPermissions;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import ee.vvk.ivotingverification.dialog.LoadingSpinner;
import ee.vvk.ivotingverification.util.C;
import ee.vvk.ivotingverification.util.Util;

/**
 * Help activity. Web view.
 * 
 * @version 13.05.2013
 */
public class HelpActivity extends Activity {

  private WebView wv;
  private AlertDialog alert;
  private LoadingSpinner mLoadingSpinner;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.help_activity);
    init(savedInstanceState);

    mLoadingSpinner = Util.startSpinner(HelpActivity.this, false);
  }

  private void init(Bundle savedInstanceState) {
    wv = (WebView) findViewById(R.id.webView);
    wv.setWebViewClient(new InsideWebViewClient());
    wv.setWebChromeClient(new WebChromeClient() {
      @Override
      public boolean onJsAlert(WebView view, String url, String message,
          final JsResult result) {
        alert = new AlertDialog.Builder(HelpActivity.this)
            .setTitle("VVK:")
            .setMessage(message)
            .setPositiveButton(android.R.string.ok,
                new AlertDialog.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                      int which) {
                    result.confirm();
                  }
                })
            .setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {
                    result.cancel();
                  }
                }).setCancelable(true).create();
        alert.show();

        return true;
      };

      @Override
      public boolean onJsConfirm(WebView view, String url,
          String message, final JsResult result) {
        alert = new AlertDialog.Builder(HelpActivity.this)
            .setTitle("VVK:")
            .setMessage(message)
            .setCancelable(true)
            .setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                      int which) {
                    result.confirm();
                  }
                })
            .setNegativeButton(android.R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                      int which) {
                    result.cancel();
                  }
                })
            .setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {
                    result.cancel();
                  }
                }).create();
        alert.show();

        return true;
      };

      @Override
      public void onGeolocationPermissionsShowPrompt(String origin,
          GeolocationPermissions.Callback callback) {
        callback.invoke(origin, false, false);
      }

      @Override
      public boolean onJsPrompt(WebView view, String url, String message,
          String defaultValue, final JsPromptResult result) {

        alert = new AlertDialog.Builder(HelpActivity.this)
            .setTitle("VVK:")
            .setMessage(message)
            .setCancelable(true)
            .setPositiveButton(android.R.string.ok,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                      int whichButton) {
                    result.confirm();
                  }
                })
            .setNegativeButton(android.R.string.cancel,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                      int whichButton) {
                    result.cancel();
                  }
                })
            .setOnCancelListener(
                new DialogInterface.OnCancelListener() {
                  public void onCancel(DialogInterface dialog) {
                    result.cancel();
                  }
                }).create();
        alert.show();

        return true;
      };

    });

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_UP:
          if (!v.hasFocus()) {
            v.requestFocus();
          }
          break;
        }
        return false;
      }
    });

    wv.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
    WebSettings webSettings = wv.getSettings();

    wv.getSettings().setGeolocationEnabled(false);
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
    wv.getSettings().setSupportMultipleWindows(false);
    wv.getSettings().setAllowFileAccess(false);
    wv.getSettings().setPluginState(PluginState.ON_DEMAND);
    wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    String uaString = webSettings.getUserAgentString();
    try {
      uaString += " VVK/"
          + this.getPackageManager().getPackageInfo(
              this.getPackageName(), 0).versionName;
      webSettings.setUserAgentString(uaString);
    } catch (NameNotFoundException e) {
      if (Util.DEBUGGABLE) {
        Log.e("Error getting app version", "" + e.getMessage());
      }
    }
    if (C.helpURL.length() > 0) {
      wv.loadUrl(C.helpURL);
    }
  }

  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
  }

  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
      wv.goBack();
      return true;
    }
    return super.onKeyDown(keyCode, event);
  }

  @Override
  protected void onSaveInstanceState(Bundle outState) {
    wv.saveState(outState);
  }

  private class InsideWebViewClient extends WebViewClient {

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
      super.onPageStarted(view, url, favicon);
    }

    @Override
    public void onPageFinished(WebView view, String url) {
      super.onPageFinished(view, url);
      Util.stopSpinner(mLoadingSpinner);
    }

    @Override
    public void onReceivedError(WebView view, int errorCode,
        String description, String failingUrl) {
      super.onReceivedError(view, errorCode, description, failingUrl);
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler,
        SslError error) {
      handler.proceed();
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

      if (url != null)
        view.loadUrl(url);

      return true;
    }
  }
}




Java Source Code List

ee.vvk.ivotingverification.BruteForceActivity.java
ee.vvk.ivotingverification.ErrorActivity.java
ee.vvk.ivotingverification.HelpActivity.java
ee.vvk.ivotingverification.MainActivity.java
ee.vvk.ivotingverification.QRScannerActivity.java
ee.vvk.ivotingverification.VoteActivity.java
ee.vvk.ivotingverification.VoteDownloadActivity.java
ee.vvk.ivotingverification.adapter.CandidatesListAdapter.java
ee.vvk.ivotingverification.dialog.LoadingSpinner.java
ee.vvk.ivotingverification.model.Vote.java
ee.vvk.ivotingverification.qr.AutoFocusCallback.java
ee.vvk.ivotingverification.qr.CameraConfigurationManager.java
ee.vvk.ivotingverification.qr.CameraManager.java
ee.vvk.ivotingverification.qr.CaptureActivityHandler.java
ee.vvk.ivotingverification.qr.DecodeFormatManager.java
ee.vvk.ivotingverification.qr.DecodeHandler.java
ee.vvk.ivotingverification.qr.DecodeThread.java
ee.vvk.ivotingverification.qr.FinishListener.java
ee.vvk.ivotingverification.qr.InactivityTimer.java
ee.vvk.ivotingverification.qr.Intents.java
ee.vvk.ivotingverification.qr.PlanarYUVLuminanceSource.java
ee.vvk.ivotingverification.qr.PreferencesActivity.java
ee.vvk.ivotingverification.qr.PreviewCallback.java
ee.vvk.ivotingverification.qr.ViewfinderResultPointCallback.java
ee.vvk.ivotingverification.qr.ViewfinderView.java
ee.vvk.ivotingverification.util.C.java
ee.vvk.ivotingverification.util.Crypto.java
ee.vvk.ivotingverification.util.CustomHttpsClient.java
ee.vvk.ivotingverification.util.HttpRequest.java
ee.vvk.ivotingverification.util.JSONParser.java
ee.vvk.ivotingverification.util.RegexMatcher.java
ee.vvk.ivotingverification.util.SecureRandomWrapper.java
ee.vvk.ivotingverification.util.TriangleView.java
ee.vvk.ivotingverification.util.Util.java