List of usage examples for android.webkit WebView setMinimumWidth
public void setMinimumWidth(int minWidth)
From source file:com.concentricsky.android.khanacademy.app.ShowProfileActivity.java
/** * Get the current user, and fail if there is none. */// w w w.j a v a2 s .c om @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); destroyed = false; this.webViewTimeoutPromptDialog = new AlertDialog.Builder(this) .setMessage("The page is taking a long time to respond. Stop loading?") .setPositiveButton("Stop", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (webView != null) { webView.stopLoading(); finish(); } } }).setNegativeButton("Wait", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { stopWebViewLoadTimeout(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { startWebViewLoadTimeout(); } }).create(); getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.profile); setTitle(getString(R.string.profile_title)); webView = (WebView) findViewById(R.id.web_view); webView.setMinimumWidth(800); enableJavascript(webView); webView.getSettings().setDefaultZoom(ZoomDensity.FAR); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { Log.d(LOG_TAG, "shouldOverrideUrlLoading: " + url); URL parsed = null; try { parsed = new URL(url); } catch (MalformedURLException e) { // Let the webview figure that one out. return false; } // Only ka links will load in this webview. if (parsed.getHost().equals("www.khanacademy.org")) { // Video urls should link into video detail. See below for another video url format. if (parsed.getPath().equals("/video")) { String query = parsed.getQuery(); if (query != null && query.length() > 0) { String[] items = query.split("&"); String videoId = null; for (String item : items) { String[] parts = item.split("=", 2); if (parts.length > 1) { if ("v".equals(parts[0])) { videoId = parts[1]; break; } } } if (videoId != null) { String[] ids = normalizeVideoAndTopicId(videoId, ""); if (ids != null) { launchVideoDetailActivity(ids[0], ids[1]); return true; } } } // There was no ?v= or something weird is going on. Allow the page // load, which should hit KA's nice "no video found" page. showSpinner(); startWebViewLoadTimeout(); return false; } if (parsed.getPath().startsWith("/profile")) { // navigation within the profile makes sense here. showSpinner(); startWebViewLoadTimeout(); return false; } // Embedded logout option (in upper left menu) can be intercepted and cause the app to be logged out as well. if (parsed.getPath().equals("/logout")) { if (dataService != null) { dataService.getAPIAdapter().logout(); } finish(); return false; // try to let the webview hit logout to get the cookies cleared as we exit } // There is a new kind of video url now.. thanks guys.. // http://www.khanacademy.org/video/subtraction-2 // redirects to // http://www.khanacademy.org/math/arithmetic/addition-subtraction/two_dig_add_sub/v/subtraction-2 String[] path = parsed.getPath().split("/"); List<String> parts = Arrays.asList(path); if (parts.contains("v")) { String videoId = null; String topicId = null; for (int i = path.length - 1; i >= 0; --i) { if (path[i].equals("v")) { continue; } if (videoId == null) { videoId = path[i]; } else if (topicId == null) { topicId = path[i]; } else { break; } } if (videoId != null && topicId != null && dataService != null) { // Looks like a video url. Double check that we have the topic and video before launching detail activity. Log.d(LOG_TAG, "video and topic ids found; looks like a video url."); String[] ids = normalizeVideoAndTopicId(videoId, topicId); if (ids != null) { launchVideoDetailActivity(ids[0], ids[1]); return true; } } } else if (parsed.getPath().startsWith("/video")) { String videoId = path[path.length - 1]; String[] ids = normalizeVideoAndTopicId(videoId, ""); if (ids != null) { launchVideoDetailActivity(ids[0], ids[1]); return true; } } // showSpinner(); // startWebViewLoadTimeout(); // return false; } // All other urls should launch in the browser instead of here, except hash changes if we can distinguish. loadInBrowser(url); return true; } @Override public void onPageFinished(WebView view, String url) { Log.d(LOG_TAG, "onPageFinished"); stopWebViewLoadTimeout(); if (!destroyed) { hideSpinner(); } } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { Log.d(LOG_TAG, "onPageStarted"); stopWebViewLoadTimeout(); // view.loadUrl("javascript:document.addEventListener( 'DOMContentLoaded',function() {AndroidApplication.jqueryReady()} );"); // handler.postDelayed(new Runnable() { // @Override // public void run() { // if (!destroyed) { // hijack(); // } // } // }, 100); } }); // webView.addJavascriptInterface(new Object() { // public void log(String msg) { // Log.d(LOG_TAG, "JSLOG: " + msg); // } // public void jqueryReady() { // Log.d(LOG_TAG, "javascript: jqueryReady"); // hijack(); // } // }, "AndroidApplication"); // showSpinner(); requestDataService(new ObjectCallback<KADataService>() { @Override public void call(KADataService service) { dataService = service; api = service.getAPIAdapter(); String[] credentials = getCurrentLoginCredentials(); loginUser(credentials[0], credentials[1]); } }); }