import android.widget.EditText;
import android.widget.ProgressBar;
-import java.net.URL;
-
-
public class Webview extends AppCompatActivity {
static String formattedUrlString;
progressBar = (ProgressBar) findViewById(R.id.progressBar);
// setWebViewClient makes this WebView the default handler for URLs inside the app, so that links are not kicked out to other apps.
- // Save the URL to urlTextBox before loading mainWebView.
+ // Save the URL to formattedUrlString and update urlTextBox before loading mainWebView.
mainWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
- urlTextBox.setText(url);
+ formattedUrlString=url;
+ urlTextBox.setText(formattedUrlString);
mainWebView.loadUrl(url);
return true;
}
final Intent intent = getIntent();
if (intent.getData() != null) {
- // Get the intent data.
+ // Get the intent data and convert it to a string.
final Uri intentUriData = intent.getData();
-
- // Try to parse the intent data and store it in urlData.
- URL urlData = null;
- try {
- urlData = new URL(intentUriData.getScheme(), intentUriData.getHost(), intentUriData.getPath());
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- Webview.formattedUrlString = urlData.toString();
+ Webview.formattedUrlString = intentUriData.toString();
}
// If formattedUrlString is null assign the homepage to it.
int menuItemId = menuItem.getItemId();
final WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
- // Use the menu items to go forward or back.
+ // Sets the commands that relate to the menu entries.
switch (menuItemId) {
+ case R.id.home:
+ mainWebView.loadUrl(homepage);
+ break;
case R.id.back:
mainWebView.goBack();
break;