Android Open Source - android-test-demo Web View Activity






From Project

Back to project page android-test-demo.

License

The source code is released under:

MIT License

If you think the Android project android-test-demo 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 org.andydyer.androidtestdemo.ui;
// w  w w  . j a v  a2s.c om
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import org.andydyer.androidtestdemo.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by andy on 8/23/14.
 */
public class WebViewActivity extends ActionBarActivity {

    public static final String EXTRA_URL = "url";
    public static final String EXTRA_TITLE = "title";

    @InjectView(R.id.webview) WebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        ButterKnife.inject(this);
        getSupportActionBar().setTitle(getIntent().getStringExtra(EXTRA_TITLE));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        loadUrl();
    }

    private void loadUrl() {
        String url = getIntent().getStringExtra(EXTRA_URL);
        webview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
        webview.loadUrl(url);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}




Java Source Code List

org.andydyer.androidtestdemo.ApplicationTest.java
org.andydyer.androidtestdemo.DemoApplication.java
org.andydyer.androidtestdemo.LoginActivityTest.java
org.andydyer.androidtestdemo.MainActivityTest.java
org.andydyer.androidtestdemo.Modules.java
org.andydyer.androidtestdemo.Modules.java
org.andydyer.androidtestdemo.api.Actor.java
org.andydyer.androidtestdemo.api.ApiServiceModule.java
org.andydyer.androidtestdemo.api.ApiServiceTest.java
org.andydyer.androidtestdemo.api.ApiService.java
org.andydyer.androidtestdemo.api.AuthenticationService.java
org.andydyer.androidtestdemo.api.Event.java
org.andydyer.androidtestdemo.api.Events.java
org.andydyer.androidtestdemo.api.MockApiServiceModule.java
org.andydyer.androidtestdemo.api.MockApiService.java
org.andydyer.androidtestdemo.api.Repo.java
org.andydyer.androidtestdemo.ui.LoginActivity.java
org.andydyer.androidtestdemo.ui.MainActivity.java
org.andydyer.androidtestdemo.ui.WebViewActivity.java
org.andydyer.androidtestdemo.ui.fragments.EventListFragment.java
org.andydyer.androidtestdemo.ui.widgets.SimpleDividerItemDecoration.java