Android Open Source - TumblifeForAndroid T L Web View Client






From Project

Back to project page TumblifeForAndroid.

License

The source code is released under:

GNU General Public License

If you think the Android project TumblifeForAndroid 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

package jp.mitukiii.tumblife.ui;
//from   w w  w .java  2 s. com
import jp.mitukiii.tumblife.R;
import jp.mitukiii.tumblife.model.TLSetting;
import jp.mitukiii.tumblife.util.TLLog;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.net.Uri;
import android.os.Handler;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class TLWebViewClient extends WebViewClient
{
  protected TLWebViewClientDelegate delegate;
  protected Context                 context;
  protected Handler                 handler;

  protected TLSetting               setting;

  public TLWebViewClient(TLWebViewClientDelegate delegate, Context context, Handler handler)
  {
    this.delegate = delegate;
    this.context = context;
    this.handler = handler;
    setting = TLSetting.getSharedInstance(context);
  }

  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    TLLog.v("TLMain / WebViewClient / shouldOverrideUrlLoading : url / " + url);
    if (url.matches("^https?://.+?")) {
      switch (setting.getSendTo()) {
        case Confirmation:
          alertSendTo(url);
          break;
        case Browser:
          sendToView(url);
          break;
        case Share:
          sendToShare(url);
          break;
      }
      return true;
    }
    return super.shouldOverrideUrlLoading(view, url);
  }

  protected void alertSendTo(final String url)
  {
    TLLog.d("TLWebViewClient / alertSendTo : url / " + url);

    new AlertDialog.Builder(context)
    .setTitle(R.string.sendto_title)
    .setItems(context.getResources().getStringArray(R.array.sendto_items), new OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        switch (TLSetting.SEND_TO.valueOf(which)) {
          case Browser:
            sendToView(url);
            break;
          case Share:
            sendToShare(url);
            break;
          default:
            sendToView(url);
            break;
        }
      }
    })
    .show();
  }

  protected void sendToView(String url)
  {
    TLLog.d("TLWebViewClient / sendToView : url / " + url);

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);
  }

  protected void sendToShare(String url)
  {
    TLLog.d("TLWebViewClient / sendToShare : url / " + url);

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, url);    
    startActivity(intent);
  }

  protected void startActivity(Intent intent)
  {
    try {
      context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
      TLLog.i("TLWebViewClient / startActivity", e);
      handler.post(new Runnable() { public void run() { delegate.startActivityFailure(); } });
    }
  }
}




Java Source Code List

jp.mitukiii.tumblife.App.java
jp.mitukiii.tumblife.HardkeySetting.java
jp.mitukiii.tumblife.KeyCodeMap.java
jp.mitukiii.tumblife.Main.java
jp.mitukiii.tumblife.Setting.java
jp.mitukiii.tumblife.exeption.TLAuthenticationFailureException.java
jp.mitukiii.tumblife.exeption.TLFailureException.java
jp.mitukiii.tumblife.exeption.TLParserException.java
jp.mitukiii.tumblife.exeption.TLSDCardNotFoundException.java
jp.mitukiii.tumblife.model.TLModel.java
jp.mitukiii.tumblife.model.TLPost.java
jp.mitukiii.tumblife.model.TLSetting.java
jp.mitukiii.tumblife.model.TLTumblelog.java
jp.mitukiii.tumblife.model.TLUser.java
jp.mitukiii.tumblife.parser.TLParser.java
jp.mitukiii.tumblife.parser.TLPostParser.java
jp.mitukiii.tumblife.parser.TLUserParser.java
jp.mitukiii.tumblife.tumblr.TLDashboardDelegate.java
jp.mitukiii.tumblife.tumblr.TLDashboardInterface.java
jp.mitukiii.tumblife.tumblr.TLDashboard.java
jp.mitukiii.tumblife.ui.TLWebViewClientDelegate.java
jp.mitukiii.tumblife.ui.TLWebViewClient.java
jp.mitukiii.tumblife.util.TLBrowser.java
jp.mitukiii.tumblife.util.TLConnection.java
jp.mitukiii.tumblife.util.TLExplorer.java
jp.mitukiii.tumblife.util.TLLog.java
jp.mitukiii.tumblife.util.TLPostFactory.java