Java Code Examples for android.webkit.WebViewClient

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Android, under directory /app/src/main/java/com/github/mobile/util/.

Source file: SourceEditor.java

  21 
vote

/** 
 * Create source editor using given web view
 * @param view
 */
public SourceEditor(final WebView view){
  WebViewClient client=new WebViewClient(){
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      if (URL_PAGE.equals(url)) {
        view.loadUrl(url);
        return false;
      }
 else {
        Context context=view.getContext();
        Intent intent=new UrlLauncher(context).create(url);
        context.startActivity(intent);
        return true;
      }
    }
  }
;
  view.setWebViewClient(client);
  WebSettings settings=view.getSettings();
  settings.setJavaScriptEnabled(true);
  settings.setBuiltInZoomControls(true);
  view.addJavascriptInterface(this,"SourceEditor");
  this.view=view;
}
 

Example 2

From project androidquery, under directory /auth/com/androidquery/.

Source file: WebDialog.java

  21 
vote

private void setupWebView(RelativeLayout layout){
  wv=new WebView(getContext());
  wv.setVerticalScrollBarEnabled(false);
  wv.setHorizontalScrollBarEnabled(false);
  if (client == null)   client=new WebViewClient();
  wv.setWebViewClient(new DialogWebViewClient());
  WebSettings ws=wv.getSettings();
  ws.setJavaScriptEnabled(true);
  RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
  layout.addView(wv,lp);
}
 

Example 3

From project Cafe, under directory /webapp/src/org/openqa/selenium/android/.

Source file: WebDriverWebView.java

  21 
vote

public static WebView create(final AndroidWebDriver driver){
  WebChromeClient chromeClient=new ChromeClient(driver);
  WebViewClient viewClient=new ViewClient(driver);
  WebView view=new WebView(driver.getActivity());
  view.setWebChromeClient(chromeClient);
  view.setWebViewClient(viewClient);
  final float zoom=view.getScale();
  view.setOnFocusChangeListener(new View.OnFocusChangeListener(){
    public void onFocusChange(    View view,    boolean focused){
      if (!focused) {
        driver.setEditAreaHasFocus(true);
      }
    }
  }
);
  view.addJavascriptInterface(jsInterface,"webdriver");
  initWebViewSettings(view);
  return view;
}
 

Example 4

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/.

Source file: AppFinderActivity.java

  21 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mFeedUri=(Uri)getIntent().getParcelableExtra(Musubi.EXTRA_FEED_URI);
  setContentView(R.layout.appcorral);
  if (savedInstanceState != null) {
    mCurrentPage=savedInstanceState.getString(EXTRA_CURRENT_PAGE);
  }
 else   if (getIntent().getData() != null) {
    mCurrentPage=getIntent().getDataString();
  }
 else {
    mCurrentPage="http://musubi.us/apps";
  }
  WebViewClient webViewClient=new AppStoreWebViewClient();
  mWebView=(WebView)findViewById(R.id.webview);
  mWebView.getSettings().setJavaScriptEnabled(true);
  mWebView.setWebViewClient(webViewClient);
  mSocialKitJavascript=new SocialKitJavascript(this,mFeedUri);
  mWebView.addJavascriptInterface(mSocialKitJavascript,MUSUBI_JS);
  mWebView.loadUrl(mCurrentPage);
}
 

Example 5

From project madvertise-android-sdk, under directory /madvertiseSDK/src/de/madvertise/android/sdk/.

Source file: MadvertiseImageView.java

  21 
vote

public MadvertiseImageView(final Context context,final int newWidth,final int newHeight,final MadvertiseAd ad,final Handler loadingCompletedHandler,final AnimationEndListener animationListener){
  super(context);
  mAnimationListener=animationListener;
  mImageAd=ad;
  setVerticalScrollBarEnabled(false);
  setHorizontalScrollBarEnabled(false);
  setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
  setBackgroundColor(Color.TRANSPARENT);
  WebViewClient webViewClient=new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      if (loadingCompletedHandler != null) {
        loadingCompletedHandler.sendEmptyMessage(MadvertiseView.MAKE_VISIBLE);
      }
    }
  }
;
  setWebViewClient(webViewClient);
  StringBuilder content=new StringBuilder();
  content.append("<html><head><style>* {margin:0;padding:0;}</style></head><body>").append("<img src=\"" + mImageAd.getBannerUrl() + "\" height=\""+ newHeight+ "\" width=\""+ newWidth+ "\"/>"+ getImpressionTrackingTag()).append("</body></html>");
  MadvertiseUtil.logMessage(null,Log.DEBUG,"Loading ad : " + content.toString());
  loadDataWithBaseURL(null,content.toString(),"text/html","UTF-8",null);
}
 

Example 6

From project adg-android, under directory /src/com/analysedesgeeks/android/.

Source file: WebFragment.java

  20 
vote

@Override public View onCreateView(final LayoutInflater inflater,final ViewGroup container,final Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  final View v=inflater.inflate(R.layout.fragment_webview,container,false);
  webview=(WebView)v.findViewById(R.id.webview);
  final WebSettings settings=webview.getSettings();
  settings.setJavaScriptEnabled(true);
  settings.setDomStorageEnabled(true);
  settings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
  settings.setSupportZoom(true);
  settings.setBuiltInZoomControls(true);
  settings.setUserAgentString("Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
  final View loading=v.findViewById(R.id.loading);
  webview.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    final WebView view,    final String url){
      loading.setVisibility(View.GONE);
    }
  }
);
  webview.loadUrl(url);
  return v;
}
 

Example 7

From project Android-automation, under directory /TmtsApp/src/com/taobao/tmts/framework/app/.

Source file: WebViewActivity.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  getWindow().requestFeature(Window.FEATURE_PROGRESS);
  this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  Log.d("sysout","thread-->" + Thread.currentThread().getId());
  Log.d("sysout","activity-->" + Thread.currentThread().getName());
  setContentView(R.layout.webview_extend_layout);
  initWebView();
  final Activity activity=this;
  webview.setWebChromeClient(new WebChromeClient(){
    public void onProgressChanged(    WebView view,    int progress){
      activity.setProgress(progress * 1000);
    }
  }
);
  webview.setWebViewClient(new WebViewClient(){
    public void onReceivedError(    WebView view,    int errorCode,    String description,    String failingUrl){
      Toast.makeText(activity,"Oh no! " + description,Toast.LENGTH_LONG).show();
    }
    @Override public void onPageFinished(    WebView view,    String url){
      progressBar.setVisibility(View.GONE);
      button.setVisibility(View.VISIBLE);
    }
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      return super.shouldOverrideUrlLoading(view,url);
    }
  }
);
  webview.loadUrl(URL);
  webview.clearCache(true);
}
 

Example 8

From project android_7, under directory /src/org/immopoly/android/app/.

Source file: OauthLoginActivity.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.oauth_login_activity);
  Intent intent=getIntent();
  if (intent != null) {
    String url=intent.getExtras().getString("oauth_url");
    WebView webView=(WebView)findViewById(R.id.webview);
    webView.setWebViewClient(new WebViewClient(){
      @Override public void onPageStarted(      WebView view,      String url,      Bitmap favicon){
        super.onPageStarted(view,url,favicon);
        if (url.matches(".+?state=authorized")) {
          SharedPreferences shared=getSharedPreferences("oauth",0);
          SharedPreferences.Editor editor=shared.edit();
          Uri uri=Uri.parse(url);
          String access_token=uri.getQueryParameter("oauth_token");
          editor.putString("oauth_token",access_token);
          editor.commit();
          OAuthData.getInstance(OauthLoginActivity.this).accessToken=access_token;
          Intent i=new Intent(OauthLoginActivity.this,ImmopolyActivity.class);
          startActivity(i);
          finish();
        }
      }
    }
);
    webView.loadUrl(url);
  }
}
 

Example 9

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: SettingsSafetyLegalActivity.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  String userSafetylegalUrl=SystemProperties.get(PROPERTY_LSAFETYLEGAL_URL);
  final Configuration configuration=getResources().getConfiguration();
  final String language=configuration.locale.getLanguage();
  final String country=configuration.locale.getCountry();
  String loc=String.format("locale=%s-%s",language,country);
  userSafetylegalUrl=String.format("%s&%s",userSafetylegalUrl,loc);
  mWebView=new WebView(this);
  mWebView.getSettings().setJavaScriptEnabled(true);
  if (savedInstanceState == null) {
    mWebView.loadUrl(userSafetylegalUrl);
  }
 else {
    mWebView.restoreState(savedInstanceState);
  }
  mWebView.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      mAlert.setTitle(getString(R.string.settings_safetylegal_activity_title));
    }
    @Override public void onReceivedError(    WebView view,    int errorCode,    String description,    String failingUrl){
      showErrorAndFinish(failingUrl);
    }
  }
);
  final AlertController.AlertParams p=mAlertParams;
  p.mTitle=getString(R.string.settings_safetylegal_activity_loading);
  p.mView=mWebView;
  p.mForceInverseBackground=true;
  setupAlert();
}
 

Example 10

From project Binaural-Beats, under directory /src/com/ihunda/android/binauralbeat/.

Source file: Comments.java

  20 
vote

@Override protected void onCreate(Bundle icicle){
  super.onCreate(icicle);
  setTheme(android.R.style.Theme_Dialog);
  setContentView(R.layout.comments);
  setTitle(R.string.comments_title);
  WebView w=(WebView)findViewById(R.id.commentView);
  w.setWebViewClient(new WebViewClient(){
  }
);
  WebSettings ws=w.getSettings();
  ws.setJavaScriptEnabled(true);
  ws.setBlockNetworkLoads(false);
  ws.setLoadsImagesAutomatically(true);
  String page=readRawTextFile(R.raw.comment);
  w.loadData(page,"application/xhtml+xml",null);
  Button button=(Button)findViewById(R.id.CommentBack);
  button.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      Intent intent=getIntent();
      setResult(RESULT_OK,intent);
      finish();
    }
  }
);
}
 

Example 11

From project box-android-sdk, under directory /BoxAndroidLibrary/src/com/box/androidlib/activities/.

Source file: BoxAuthentication.java

  20 
vote

/** 
 * Load the login webview.
 * @param ticket Ticket from Box API action get_ticket
 */
private void loadLoginWebview(final String ticket){
  String loginUrl=BoxConstants.LOGIN_URL + ticket;
  mLoginWebView=(WebView)findViewById(R.id.loginWebView);
  mLoginWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  mLoginWebView.getSettings().setJavaScriptEnabled(true);
  mLoginWebView.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    final WebView view,    final String url){
      getAuthToken(ticket,0);
    }
    @Override public boolean shouldOverrideUrlLoading(    final WebView view,    final String url){
      if (url != null && url.startsWith("market://")) {
        try {
          view.getContext().startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse(url)));
          return true;
        }
 catch (        ActivityNotFoundException e) {
        }
      }
      return false;
    }
  }
);
  mLoginWebView.loadUrl(loginUrl);
}
 

Example 12

From project creamed_glacier_app_settings, under directory /src/com/android/settings/.

Source file: SettingsLicenseActivity.java

  20 
vote

private void showPageOfText(String text){
  AlertDialog.Builder builder=new AlertDialog.Builder(SettingsLicenseActivity.this);
  builder.setCancelable(true).setView(mWebView).setTitle(R.string.settings_license_activity_title);
  mTextDlg=builder.create();
  mTextDlg.setOnDismissListener(new OnDismissListener(){
    public void onDismiss(    DialogInterface dlgi){
      SettingsLicenseActivity.this.finish();
    }
  }
);
  mWebView.loadDataWithBaseURL(null,text,"text/html","utf-8",null);
  mWebView.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      mSpinnerDlg.dismiss();
      mTextDlg.show();
    }
  }
);
  mWebView=null;
}
 

Example 13

From project droid-comic-viewer, under directory /src/net/robotmedia/acv/ui/widget/.

Source file: ComicFrame.java

  20 
vote

public void showContent(ACVComic acv,int screenIndex,int frameIndex,boolean forward,LayoutMeasures imageMeasures){
  this.removeContent();
  final List<ACVContent> contents=acv.getContents(screenIndex,frameIndex);
  final String baseURL=acv.getContentBaseURL();
  final Context context=getContext();
  for (  final ACVContent content : contents) {
    final Rect rect=content.createRect(imageMeasures.width,imageMeasures.height);
    final WebView w=new WebView(context);
    final int x=rect.left - imageMeasures.scrollX + imageMeasures.left;
    final int y=rect.top - imageMeasures.scrollY + imageMeasures.top;
    w.setLayoutParams(new AbsoluteLayout.LayoutParams(rect.width(),rect.height(),x,y));
    w.setVerticalScrollBarEnabled(false);
    w.setHorizontalScrollBarEnabled(false);
    w.setBackgroundColor(Color.TRANSPARENT);
    w.setClickable(false);
    w.setLongClickable(false);
    final String html=acv.getContentFromSource(content);
    w.loadDataWithBaseURL(baseURL,html,"text/html","UTF-8",null);
    mContentContainer.addView(w);
    mContentViews.add(w);
    w.setWebViewClient(new WebViewClient(){
      @Override public void onPageFinished(      WebView view,      String url){
        final long transitionDuration=content.getTransitionDuration();
        if (transitionDuration > 0) {
          final Animation animation=AnimationUtils.loadAnimation(context,android.R.anim.fade_in);
          animation.setDuration(transitionDuration);
          view.startAnimation(animation);
        }
      }
      @Override public boolean shouldOverrideUrlLoading(      WebView view,      String url){
        IntentUtils.view(context,url);
        return true;
      }
    }
);
  }
}
 

Example 14

From project FlickrCity, under directory /src/com/FlickrCity/FlickrCityAndroid/Activities/.

Source file: FlickrOAuth.java

  20 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  Bundle extras=getIntent().getExtras();
  String authorizationURL=null;
  if (extras != null) {
    authorizationURL=extras.getString("authorizationUrl");
  }
 else   return;
  setContentView(R.layout.flickroauth);
  webView=(WebView)findViewById(R.id.webViewOAuth);
  webView.loadUrl(authorizationURL);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient(){
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      if (url.startsWith("oauth")) {
        Uri uri=Uri.parse(url);
        String verifier=uri.getQueryParameter("oauth_verifier");
        Intent i=new Intent();
        i.putExtra("verifier",verifier);
        setResult(RESULT_OK,i);
        finish();
        return true;
      }
      return super.shouldOverrideUrlLoading(view,url);
    }
  }
);
}
 

Example 15

From project groundhog-reader, under directory /src/main/java/com/almarsoft/GroundhogReader/.

Source file: HelpActivity.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.quickhelp);
  mContent=(WebView)this.findViewById(R.id.help_content);
  mWebSettings=mContent.getSettings();
  mWebSettings.setDefaultTextEncodingName("utf-8");
  mWebSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
  mWebSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
  mWebSettings.setJavaScriptEnabled(false);
  mWebSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
  mWebSettings.setSupportZoom(true);
  mButton_Close=(Button)this.findViewById(R.id.btn_close);
  mButton_Close.setOnClickListener(new OnClickListener(){
    public void onClick(    View arg0){
      finish();
    }
  }
);
  mButton_Close.setFocusable(false);
  mContent.requestFocus();
  this.showDialog(ID_DIALOG_LOADING);
  mContent.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      HelpActivity.this.dismissDialog(ID_DIALOG_LOADING);
    }
  }
);
  mContent.loadUrl(UsenetConstants.QUICKHELPURL);
}
 

Example 16

From project iosched_3, under directory /android/src/com/google/android/apps/iosched/ui/.

Source file: SessionLivestreamActivity.java

  20 
vote

@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  View view=inflater.inflate(R.layout.fragment_session_captions,null);
  mContainer=(FrameLayout)view.findViewById(R.id.session_caption_container);
  mNoCaptionsTextView=(TextView)view.findViewById(android.R.id.empty);
  mWebView=(WebView)view.findViewById(R.id.session_caption_area);
  mWebView.setOnLongClickListener(new View.OnLongClickListener(){
    @Override public boolean onLongClick(    View view){
      return true;
    }
  }
);
  mWebView.setWebViewClient(new WebViewClient(){
    @Override public void onReceivedError(    WebView view,    int errorCode,    String description,    String failingUrl){
      showNoCaptionsAvailable();
    }
  }
);
  updateViews();
  return view;
}
 

Example 17

From project MIT-Mobile-for-Android, under directory /src/edu/mit/mitmobile2/tour/.

Source file: TourIntroductionActivity.java

  20 
vote

@Override protected void onCreate(Bundle savedState){
  super.onCreate(savedState);
  setContentView(R.layout.boring_activity_layout);
  TourHeader header=TourModel.getTour(this).getHeader();
  TitleBar titleBar=(TitleBar)findViewById(R.id.boringLayoutTitleBar);
  titleBar.setTitle(header.getTitle());
  LinearLayout rootView=(LinearLayout)findViewById(R.id.boringLayoutRoot);
  WebView webView=new WebView(this);
  webView.getSettings().setJavaScriptEnabled(true);
  HashMap<String,String> content=new HashMap<String,String>();
  content.put("BODY-BEFORE-BUTTON",header.getDescriptionTop());
  content.put("BODY-AFTER-BUTTON",header.getDescriptionBottom());
  String html=StyledContentHTML.populateTemplate(this,"tour/intro_template.html",content);
  webView.loadDataWithBaseURL(null,html,"text/html","utf-8",null);
  rootView.addView(webView);
  webView.setWebViewClient(new WebViewClient(){
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      if (url.equals("select_start")) {
        showMap();
      }
 else {
        CommonActions.viewURL(TourIntroductionActivity.this,url);
      }
      return true;
    }
  }
);
}
 

Example 18

From project mixare, under directory /src/org/mixare/mgr/webcontent/.

Source file: WebPageMgrImpl.java

  20 
vote

public void loadWebPage(String url,Context context) throws Exception {
  WebView webview=new WebView(context);
  webview.getSettings().setJavaScriptEnabled(true);
  final Dialog d=new Dialog(context){
    public boolean onKeyDown(    int keyCode,    KeyEvent event){
      if (keyCode == KeyEvent.KEYCODE_BACK)       this.dismiss();
      return true;
    }
  }
;
  webview.setWebViewClient(new WebViewClient(){
    public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      view.loadUrl(url);
      return true;
    }
    @Override public void onPageFinished(    WebView view,    String url){
      if (url.endsWith("return")) {
        d.dismiss();
        mixContext.getActualMixView().repaint();
      }
 else {
        super.onPageFinished(view,url);
      }
    }
  }
);
  d.requestWindowFeature(Window.FEATURE_NO_TITLE);
  d.getWindow().setGravity(Gravity.BOTTOM);
  d.addContentView(webview,new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,Gravity.BOTTOM));
  if (!processUrl(url,mixContext.getActualMixView())) {
    d.show();
    webview.loadUrl(url);
  }
}
 

Example 19

From project MyExpenses, under directory /src/org/totschnig/myexpenses/.

Source file: Tutorial.java

  20 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tutorial);
  setTitle(getString(R.string.app_name) + " " + getString(R.string.tutorial));
  Bundle extras=getIntent().getExtras();
switch (extras.getInt("start")) {
case R.id.FAQ_COMMAND:
    startWith="faq";
  break;
default :
startWith="introduction";
}
wv=(WebView)findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient());
WebSettings settings=wv.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setBuiltInZoomControls(true);
String[] supportedLangs={"en","fr","de","it","es"};
String lang=Locale.getDefault().getLanguage();
if (!java.util.Arrays.asList(supportedLangs).contains(lang)) {
lang="en";
}
wv.loadUrl("http://myexpenses.totschnig.org/tutorial_r" + TUTORIAL_RELEASE_VERSION + "/"+ lang+ "/"+ startWith+ ".html");
}
 

Example 20

From project No-Pain-No-Game, under directory /src/edu/ucla/cs/nopainnogame/.

Source file: LearnActivity.java

  20 
vote

private void createWebView(){
  WebView webView=(WebView)findViewById(R.id.LearnWebView);
  webView.getSettings().setJavaScriptEnabled(true);
  final Activity activity=LearnActivity.this;
  webView.setWebChromeClient(new WebChromeClient(){
    public void onProgressChanged(    WebView view,    int progress){
      activity.setProgress(progress * 1000);
    }
  }
);
  webView.setWebViewClient(new WebViewClient(){
    public void onReceivedError(    WebView view,    int errorCode,    String description,    String failingUrl){
      Toast.makeText(activity,"Oh no! " + description,Toast.LENGTH_SHORT).show();
    }
  }
);
  if (isLoggedIn) {
    current_file=getCurrentFile(user);
    webView.loadData(fileSwitch(current_file),"text/html","utf-8");
    if (current_file < max_file) {
      current_file=(current_file + 1);
      setCurrentFile(current_file,user);
    }
 else {
      current_file=1;
      setCurrentFile(current_file,user);
    }
  }
 else {
    webView.loadData(fileSwitch(1),"text/html","utf-8");
  }
}
 

Example 21

From project platform_packages_apps_browser, under directory /src/com/android/browser/.

Source file: GoogleAccountLogin.java

  20 
vote

private GoogleAccountLogin(Activity activity,Account account,Runnable runnable){
  mActivity=activity;
  mAccount=account;
  mWebView=new WebView(mActivity);
  mRunnable=runnable;
  mUserAgent=mWebView.getSettings().getUserAgentString();
  CookieSyncManager.getInstance().startSync();
  WebViewTimersControl.getInstance().onBrowserActivityResume(mWebView);
  mWebView.setWebViewClient(new WebViewClient(){
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      return false;
    }
    @Override public void onPageFinished(    WebView view,    String url){
      done();
    }
  }
);
}
 

Example 22

From project platform_packages_apps_settings, under directory /src/com/android/settings/.

Source file: SettingsLicenseActivity.java

  20 
vote

private void showPageOfText(String text){
  AlertDialog.Builder builder=new AlertDialog.Builder(SettingsLicenseActivity.this);
  builder.setCancelable(true).setView(mWebView).setTitle(R.string.settings_license_activity_title);
  mTextDlg=builder.create();
  mTextDlg.setOnDismissListener(new OnDismissListener(){
    public void onDismiss(    DialogInterface dlgi){
      SettingsLicenseActivity.this.finish();
    }
  }
);
  mWebView.loadDataWithBaseURL(null,text,"text/html","utf-8",null);
  mWebView.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      mSpinnerDlg.dismiss();
      mTextDlg.show();
    }
  }
);
  mWebView=null;
}
 

Example 23

From project Racenet-for-Android, under directory /src/org/racenet/.

Source file: StartActivity.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  if (!isTaskRoot()) {
    final Intent intent=getIntent();
    final String intentAction=intent.getAction();
    if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
      finish();
      return;
    }
  }
  this.setContentView(R.layout.start);
  db=new Database(getApplicationContext());
  final ProgressDialog pd=new ProgressDialog(this);
  pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  pd.setMessage("Loading data...");
  pd.setCancelable(false);
  WebView ranking=(WebView)findViewById(R.id.ranking);
  ranking.setBackgroundColor(0x00000000);
  ranking.setWebViewClient(new WebViewClient(){
    @Override public void onPageFinished(    WebView view,    String url){
      pd.dismiss();
      String userID=db.get("user_id");
      String username=db.get("user_name");
      if (!userID.matches("")) {
        if (!IsServiceRunning.check("org.racenet.services.MQTTService",getApplicationContext())) {
          startService(new Intent(StartActivity.this,MQTTService.class));
        }
      }
    }
  }
);
  pd.show();
  ranking.loadUrl("http://www.warsow-race.net/ranking/android/num/100");
}
 

Example 24

From project rbb, under directory /src/com/btmura/android/reddit/app/.

Source file: LinkFragment.java

  20 
vote

@SuppressLint("SetJavaScriptEnabled") private void setupWebView(WebView webView){
  WebSettings settings=webView.getSettings();
  settings.setBuiltInZoomControls(true);
  settings.setDisplayZoomControls(false);
  settings.setJavaScriptEnabled(true);
  settings.setLoadWithOverviewMode(true);
  settings.setSupportZoom(true);
  settings.setPluginState(PluginState.ON_DEMAND);
  settings.setUseWideViewPort(true);
  webView.setWebViewClient(new WebViewClient(){
    @Override public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      super.onPageStarted(view,url,favicon);
      progress.setVisibility(View.VISIBLE);
    }
    @Override public void onPageFinished(    WebView view,    String url){
      super.onPageFinished(view,url);
      progress.setVisibility(View.GONE);
    }
  }
);
  webView.setWebChromeClient(new WebChromeClient(){
    @Override public void onProgressChanged(    WebView view,    int newProgress){
      super.onProgressChanged(view,newProgress);
      progress.setProgress(newProgress);
    }
  }
);
}
 

Example 25

From project SeriesGuide, under directory /SeriesGuide/src/com/battlelancer/seriesguide/getglueapi/.

Source file: GetGlueAuthActivity.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_PROGRESS);
  mWebview=new WebView(this);
  setContentView(mWebview);
  final ActionBar actionBar=getSupportActionBar();
  actionBar.setTitle(getString(R.string.oauthmessage));
  actionBar.setDisplayShowTitleEnabled(true);
  setSupportProgressBarVisibility(true);
  final SherlockFragmentActivity activity=this;
  mWebview.setWebChromeClient(new WebChromeClient(){
    public void onProgressChanged(    WebView view,    int progress){
      activity.setSupportProgress(progress * 1000);
    }
  }
);
  mWebview.setWebViewClient(new WebViewClient(){
    public void onReceivedError(    WebView view,    int errorCode,    String description,    String failingUrl){
      Toast.makeText(activity,getString(R.string.getglue_authfailed) + " " + description,Toast.LENGTH_LONG).show();
      finish();
    }
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      if (url.startsWith(GetGlue.OAUTH_CALLBACK_URL)) {
        Uri uri=Uri.parse(url);
        new RetrieveAccessTokenTask(mConsumer,mProvider,PreferenceManager.getDefaultSharedPreferences(activity)).execute(uri);
        finish();
        return true;
      }
      return false;
    }
  }
);
  Resources res=getResources();
  this.mConsumer=new DefaultOAuthConsumer(res.getString(R.string.getglue_consumer_key),res.getString(R.string.getglue_consumer_secret));
  this.mProvider=new DefaultOAuthProvider(GetGlue.REQUEST_URL,GetGlue.ACCESS_URL,GetGlue.AUTHORIZE_URL);
  Log.i(TAG,"Starting task to retrieve request token.");
  new OAuthRequestTokenTask(this,mConsumer,mProvider,mWebview).execute();
}
 

Example 26

From project simplefacebook, under directory /src/com/androidquery/simplefeed/fragments/.

Source file: DetailFragment.java

  20 
vote

private void initView(){
  aq.id(R.id.button_comment).clicked(this,"showAll");
  aq.id(R.id.button_expand).clicked(this,"showDetail");
  aq.id(R.id.button_full).clicked(this,"launch");
  aq.id(R.id.button_video).clicked(this,"launch");
  WebView wv=aq.id(R.id.web).getWebView();
  WebSettings ws=wv.getSettings();
  ws.setJavaScriptCanOpenWindowsAutomatically(false);
  ws.setJavaScriptEnabled(true);
  wv.setWebViewClient(new WebViewClient(){
    private long loaded=System.currentTimeMillis();
    @Override public void onPageStarted(    WebView view,    String url,    Bitmap favicon){
      loaded=System.currentTimeMillis();
    }
    @Override public boolean shouldOverrideUrlLoading(    WebView view,    String url){
      AQUtility.debug("trying to open",url);
      long now=System.currentTimeMillis();
      long diff=now - loaded;
      if (diff > 500) {
        IntentUtility.openBrowser(act,url);
        return true;
      }
      return false;
    }
  }
);
}
 

Example 27

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/vgood/.

Source file: BeintooRecomBannerHTML.java

  19 
vote

public void loadRecomm(){
  new Thread(new Runnable(){
    public void run(){
      try {
        webview.setVerticalScrollBarEnabled(false);
        webview.setHorizontalScrollBarEnabled(false);
        webview.setWebViewClient(new WebViewClient(){
          public void onReceivedError(          WebView view,          int errorCode,          String description,          String failingUrl){
          }
          public void onPageFinished(          WebView view,          String url){
            UIhandler.sendEmptyMessage(0);
          }
          public void onPageStarted(          WebView view,          String url,          Bitmap favicon){
          }
          public boolean shouldOverrideUrlLoading(          WebView view,          String url){
            Intent browserIntent=new Intent("android.intent.action.VIEW",Uri.parse(url));
            ctx.startActivity(browserIntent);
            return true;
          }
        }
);
        webview.loadDataWithBaseURL(null,vgood.getVgoods().get(0).getContent(),vgood.getVgoods().get(0).getContentType(),"UTF-8",null);
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
).start();
}
 

Example 28

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: DroidGap.java

  19 
vote

/** 
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable). The errorCode parameter corresponds to one of the ERROR_* constants.
 * @param errorCode    The error code corresponding to an ERROR_* value.
 * @param description  A String describing the error.
 * @param failingUrl   The url that failed to load.
 */
public void onReceivedError(final int errorCode,final String description,final String failingUrl){
  final DroidGap me=this;
  final String errorUrl=me.getStringProperty("errorUrl",null);
  if ((errorUrl != null) && (errorUrl.startsWith("file://") || errorUrl.indexOf(me.baseUrl) == 0 || this.appView.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) {
    me.runOnUiThread(new Runnable(){
      public void run(){
        me.spinnerStop();
        me.appView.showWebPage(errorUrl,false,true,null);
      }
    }
);
  }
 else {
    final boolean exit=!(errorCode == WebViewClient.ERROR_HOST_LOOKUP);
    me.runOnUiThread(new Runnable(){
      public void run(){
        if (exit) {
          me.appView.setVisibility(View.GONE);
          me.displayError("Application Error",description + " (" + failingUrl+ ")","OK",exit);
        }
      }
    }
);
  }
}
 

Example 29

From project titanium_modules, under directory /beintoosdk/mobile/android/src/com/beintoo/vgood/.

Source file: BeintooRecomBannerHTML.java

  19 
vote

public void loadRecomm(){
  new Thread(new Runnable(){
    public void run(){
      try {
        webview.setVerticalScrollBarEnabled(false);
        webview.setHorizontalScrollBarEnabled(false);
        webview.setFocusableInTouchMode(false);
        webview.setFocusable(false);
        webview.setWebViewClient(new WebViewClient(){
          public void onReceivedError(          WebView view,          int errorCode,          String description,          String failingUrl){
          }
          public void onPageFinished(          WebView view,          String url){
            UIhandler.sendEmptyMessage(0);
          }
          public void onPageStarted(          WebView view,          String url,          Bitmap favicon){
          }
          public boolean shouldOverrideUrlLoading(          WebView view,          String url){
            Intent browserIntent=new Intent("android.intent.action.VIEW",Uri.parse(url));
            ctx.startActivity(browserIntent);
            return true;
          }
        }
);
        webview.loadData(vgood.getVgoods().get(0).getContent(),vgood.getVgoods().get(0).getContentType(),"utf-8");
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
  }
).start();
}