Example usage for android.webkit WebView loadUrl

List of usage examples for android.webkit WebView loadUrl

Introduction

In this page you can find the example usage for android.webkit WebView loadUrl.

Prototype

public void loadUrl(String url) 

Source Link

Document

Loads the given URL.

Usage

From source file:org.liberty.android.fantastischmemo.downloader.google.GoogleOAuth2AccessCodeRetrievalFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final View v = inflater.inflate(R.layout.oauth_login_layout, container, false);
    final WebView webview = (WebView) v.findViewById(R.id.login_page);
    final View loadingText = v.findViewById(R.id.auth_page_load_text);
    final View progressDialog = v.findViewById(R.id.auth_page_load_progress);
    final LinearLayout ll = (LinearLayout) v.findViewById(R.id.ll);

    // We have to set up the dialog's webview size manually or the webview will be zero size.
    // This should be a bug of Android.
    Rect displayRectangle = new Rect();
    Window window = mActivity.getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle);

    ll.setMinimumWidth((int) (displayRectangle.width() * 0.9f));
    ll.setMinimumHeight((int) (displayRectangle.height() * 0.8f));

    webview.getSettings().setJavaScriptEnabled(true);
    try {/*from   w  w  w  .  j a v  a  2s  .c o  m*/
        String uri = String.format(
                "https://accounts.google.com/o/oauth2/auth?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s",
                URLEncoder.encode(AMEnv.GOOGLE_CLIENT_ID, "UTF-8"), URLEncoder.encode("code", "UTF-8"),
                URLEncoder.encode(AMEnv.GOOGLE_REDIRECT_URI, "UTF-8"),
                URLEncoder.encode(AMEnv.GDRIVE_SCOPE, "UTF-8"));
        webview.loadUrl(uri);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // This is workaround to show input on some android version.
    webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    webview.setWebViewClient(new WebViewClient() {
        private boolean authenticated = false;

        @Override
        public void onPageFinished(WebView view, String url) {
            loadingText.setVisibility(View.GONE);
            progressDialog.setVisibility(View.GONE);
            webview.setVisibility(View.VISIBLE);
            if (authenticated == true) {
                return;
            }
            String code = getAuthCodeFromUrl(url);
            String error = getErrorFromUrl(url);
            if (error != null) {
                authCodeReceiveListener.onAuthCodeError(error);
                authenticated = true;
                dismiss();
            }
            if (code != null) {
                authenticated = true;
                authCodeReceiveListener.onAuthCodeReceived(code);
                dismiss();
            }
        }
    });
    return v;
}

From source file:com.jiandanbaoxian.fragment.DialogFragmentCreater.java

/**
 * Dialog ???//from  w  ww.  ja v a  2  s. c  om
 * @param mContext
 * @return
 */
private Dialog showLicenseChoiceDialog(final Context mContext) {
    View convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_license_choice, null);
    final Dialog dialog = new Dialog(mContext, R.style.mystyle);

    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.layout_rule:
                if (isAgree) {
                    isAgree = false;
                    ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose);
                    //                            TextView textView = (TextView)v.findViewById(R.id.tv_rule);
                    imageView.setImageResource(R.drawable.icon_choose);
                    //                            textView.setBackgroundColor(getResources().getColor(R.color.bg_gray_color_level_0));
                    //                            textView.setTextColor(getResources().getColor(R.color.tv_gray_color_level_3));
                } else {
                    isAgree = true;
                    ImageView imageView = (ImageView) v.findViewById(R.id.iv_choose);
                    //                            TextView textView = (TextView)v.findViewById(R.id.tv_rule);
                    imageView.setImageResource(R.drawable.icon_choose_selected);
                    //                            textView.setBackgroundResource(R.drawable.btn_select_base_shape_0);
                    //                            textView.setTextColor(getResources().getColor(R.color.white_color));
                }
                break;
            }
            if (onLicenseDialogClickListener != null) {
                onLicenseDialogClickListener.onClick(v, isAgree);
            }
        }
    };

    TitleBar titleBar;
    SwipeRefreshLayout swipeLayout;
    final WebView webView;
    ProgressBar progressBar;
    LinearLayout layoutRule;
    LinearLayout layoutConfirm;

    titleBar = (TitleBar) convertView.findViewById(R.id.title_bar);
    swipeLayout = (SwipeRefreshLayout) convertView.findViewById(R.id.swipe_layout);
    webView = (WebView) convertView.findViewById(R.id.webView);
    progressBar = (ProgressBar) convertView.findViewById(R.id.progress_bar);
    layoutRule = (LinearLayout) convertView.findViewById(R.id.layout_rule);
    layoutConfirm = (LinearLayout) convertView.findViewById(R.id.layout_confirm);

    WebChromeClient client = new AppChromeWebClient(titleBar, progressBar, swipeLayout);
    webView.setWebChromeClient(client);
    webView.setWebViewClient(new AppWebClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(webViewURL);
    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
                    webView.goBack(); //?
                    return true; //?
                }
            }
            return false;
        }
    });

    titleBar.initTitleBarInfo("", R.drawable.arrow_left, -1, "", "");
    titleBar.setOnTitleBarClickListener(new TitleBar.OnTitleBarClickListener() {
        @Override
        public void onLeftButtonClick(View v) {
            if (webView.canGoBack()) {
                webView.goBack(); //?
                return; //?
            }

            if (onLicenseDialogClickListener != null) {
                onLicenseDialogClickListener.onClick(v, isAgree);
                dismiss();
            }
        }

        @Override
        public void onRightButtonClick(View v) {

        }
    });
    UIUtils.initSwipeRefreshLayout(swipeLayout);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            webView.reload();
        }
    });

    layoutConfirm.setOnClickListener(listener);
    layoutRule.setOnClickListener(listener);

    dialog.setContentView(convertView);
    dialog.getWindow().setWindowAnimations(R.style.dialog_right_control_style);
    return dialog;
}

From source file:com.battlelancer.seriesguide.getglueapi.GetGlueAuthActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    setupActionBar();//  ww  w .j  a  va 2  s .  c o  m

    WebView webview = (WebView) findViewById(R.id.webView);

    final FragmentActivity activity = this;
    webview.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(GetGlueCheckin.OAUTH_CALLBACK_URL)) {
                Uri uri = Uri.parse(url);

                new RetrieveAccessTokenTask(getApplicationContext()).execute(uri);

                finish();
                return true;
            }
            return false;
        }
    });

    // mWebview.getSettings().setJavaScriptEnabled(true);

    // make sure we start fresh
    webview.clearCache(true);

    Timber.d("Initiating authorization request...");
    Resources res = getResources();
    try {
        OAuthClientRequest request = com.uwetrottmann.getglue.GetGlue
                .getAuthorizationRequest(BuildConfig.TVTAG_CLIENT_ID, GetGlueCheckin.OAUTH_CALLBACK_URL);
        webview.loadUrl(request.getLocationUri());
    } catch (OAuthSystemException e) {
        Timber.e(e, "Auth request failed");
    }
}

From source file:org.zeroxlab.zeroxbenchmark.Benchmark.java

private void initViews() {
        /*/*from  ww  w .j ava  2  s .c o m*/
        mRun = (Button)findViewById(R.id.btn_run);
        mRun.setOnClickListener(this);
            
        mShow = (Button)findViewById(R.id.btn_show);
        mShow.setOnClickListener(this);
        mShow.setClickable(false);
            
        mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
        mMainView = (LinearLayout)findViewById(R.id.main_view);
            
        mBannerInfo = (TextView)findViewById(R.id.banner_info);
        mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
        */

        mTabHost = getTabHost();

        int length = mCases.size();
        mCheckList = new CheckBox[length];
        mDesc = new TextView[length];
        for (int i = 0; i < length; i++) {
            mCheckList[i] = new CheckBox(this);
            mCheckList[i].setText(mCases.get(i).getTitle());
            mDesc[i] = new TextView(this);
            mDesc[i].setText(mCases.get(i).getDescription());
            mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
            mDesc[i].setPadding(42, 0, 10, 10);
        }

        TabContentFactory mTCF = new TabContentFactory() {
            public View createTabContent(String tag) {
                ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.FILL_PARENT);
                ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
                LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                wrapContent.gravity = Gravity.CENTER;
                LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                weightedFillWrap.weight = 1;

                if (tag.equals(MAIN)) {
                    LinearLayout mMainView = new LinearLayout(Benchmark.this);
                    mMainView.setOrientation(1);
                    ScrollView mListScroll = new ScrollView(Benchmark.this);

                    LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this);
                    mMainViewContainer.setOrientation(1);
                    ImageView mIconView = new ImageView(Benchmark.this);
                    mIconView.setImageResource(R.drawable.icon);

                    TextView mBannerInfo = new TextView(Benchmark.this);
                    mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:");

                    d2CheckBox = new CheckBox(Benchmark.this);
                    d2CheckBox.setText(D2);
                    d2CheckBox.setOnClickListener(Benchmark.this);

                    d3CheckBox = new CheckBox(Benchmark.this);
                    d3CheckBox.setText(D3);
                    d3CheckBox.setOnClickListener(Benchmark.this);

                    mathCheckBox = new CheckBox(Benchmark.this);
                    mathCheckBox.setText(MATH);
                    mathCheckBox.setOnClickListener(Benchmark.this);

                    vmCheckBox = new CheckBox(Benchmark.this);
                    vmCheckBox.setText(VM);
                    vmCheckBox.setOnClickListener(Benchmark.this);

                    nativeCheckBox = new CheckBox(Benchmark.this);
                    nativeCheckBox.setText(NATIVE);
                    nativeCheckBox.setOnClickListener(Benchmark.this);

                    miscCheckBox = new CheckBox(Benchmark.this);
                    miscCheckBox.setText(MISC);
                    miscCheckBox.setOnClickListener(Benchmark.this);

                    TextView mWebInfo = new TextView(Benchmark.this);
                    mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com");

                    LinearLayout mButtonContainer = new LinearLayout(Benchmark.this);
                    mRun = new Button(Benchmark.this);
                    mShow = new Button(Benchmark.this);
                    mRun.setText("Run");
                    mShow.setText("Show");
                    mRun.setOnClickListener(Benchmark.this);
                    mShow.setOnClickListener(Benchmark.this);
                    mButtonContainer.addView(mRun, weightedFillWrap);
                    mButtonContainer.addView(mShow, weightedFillWrap);
                    WebView mTracker = new WebView(Benchmark.this);
                    mTracker.clearCache(true);
                    mTracker.setWebViewClient(new WebViewClient() {
                        public void onPageFinished(WebView view, String url) {
                            Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url);
                        }

                        public void onReceivedError(WebView view, int errorCode, String description,
                                String failingUrl) {
                            Log.e(TAG, "Track err: " + description);
                        }
                    });
                    mTracker.loadUrl(trackerUrl);
                    mMainViewContainer.addView(mIconView, wrapContent);
                    mMainViewContainer.addView(mBannerInfo);
                    mMainViewContainer.addView(mathCheckBox);
                    mMainViewContainer.addView(d2CheckBox);
                    mMainViewContainer.addView(d3CheckBox);
                    mMainViewContainer.addView(vmCheckBox);
                    mMainViewContainer.addView(nativeCheckBox);
                    mMainViewContainer.addView(miscCheckBox);
                    mMainViewContainer.addView(mWebInfo);
                    mMainViewContainer.addView(mButtonContainer, fillWrap);
                    mMainViewContainer.addView(mTracker, 0, 0);
                    mListScroll.addView(mMainViewContainer, fillParent);
                    mMainView.addView(mListScroll, fillWrap);

                    return mMainView;

                }

                LinearLayout mMainView = new LinearLayout(Benchmark.this);
                mMainView.setOrientation(1);
                ScrollView mListScroll = new ScrollView(Benchmark.this);
                LinearLayout mListContainer = new LinearLayout(Benchmark.this);
                mListContainer.setOrientation(1);
                mListScroll.addView(mListContainer, fillParent);
                mMainView.addView(mListScroll, fillWrap);

                boolean gray = true;
                int length = mCases.size();
                Log.i(TAG, "L: " + length);
                Log.i(TAG, "TCF: " + tag);
                for (int i = 0; i < length; i++) {
                    if (!mCategory.get(tag).contains(mCases.get(i)))
                        continue;
                    Log.i(TAG, "Add: " + i);
                    mListContainer.addView(mCheckList[i], fillWrap);
                    mListContainer.addView(mDesc[i], fillWrap);
                    if (gray) {
                        int color = 0xFF333333; //ARGB
                        mCheckList[i].setBackgroundColor(color);
                        mDesc[i].setBackgroundColor(color);
                    }
                    gray = !gray;
                }
                return mMainView;
            }
        };

        mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm))
                .setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(NATIVE)
                .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF));
        mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc))
                .setContent(mTCF));
    }

From source file:com.chatwingsdk.managers.CommunicationModeManager.java

private void subscribeToChatBoxChannels(WebView mWebView) {
    // Query for chat box keys
    Uri chatBoxesUri = ChatWingContentProvider.getChatBoxesUri();
    ArrayList<String> fayeChannels = new ArrayList<String>();
    Cursor c = null;/*  ww w. java 2 s  .  com*/
    try {
        c = mActivityDelegate.getActivity().getContentResolver().query(chatBoxesUri,
                new String[] { ChatBoxTable.FAYE_CHANNEL }, null, null, null);
        if (c.getCount() > 0 && c.moveToFirst()) {
            int fayeChannelIndex = c.getColumnIndex(ChatBoxTable.FAYE_CHANNEL);
            do {
                // We can subscribe to each chat box here,
                // but it can take a lot of time and holding the Cursor for
                // that long is not a good idea. So, to be safe,
                // let's get all chat box keys first and subscribe later.
                String fayeChannel = c.getString(fayeChannelIndex);
                fayeChannels.add(fayeChannel);
            } while (c.moveToNext());
        }
    } finally {
        if (c != null && !c.isClosed()) {
            c.close();
        }
    }

    // Subscribe to all of them
    for (String fayeChannel : fayeChannels) {
        String js = String.format("javascript:subscribe('%s')", fayeChannel);
        mWebView.loadUrl(js);
    }
}

From source file:it.angrydroids.epub3reader.BookView.java

@Override
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);

    // enable JavaScript for cool things to happen!
    view.getSettings().setJavaScriptEnabled(true);

    // ----- SWIPE PAGE
    view.setOnTouchListener(new OnTouchListener() {
        @Override// w  w w . j a v  a 2s .  com
        public boolean onTouch(View v, MotionEvent event) {

            if (state == ViewStateEnum.books)
                swipePage(v, event, 0);

            WebView view = (WebView) v;
            return view.onTouchEvent(event);
        }
    });

    // ----- NOTE & LINK
    view.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));
                    if (url != null)
                        navigator.setNote(url, index);
                }
            });
            view.requestFocusNodeHref(msg);

            return false;
        }
    });

    view.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
                navigator.setBookPage(url, index);
            } catch (Exception e) {
                errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
        }
    });

    view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE");
    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            view.loadUrl(
                    "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);");
        }
    });

    PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk);
    TopButton = (Button) getView().findViewById(R.id.btn_display_from_top);
    FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk);

    PreButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnPrevChunkOnClickListner(v);
        }
    });

    TopButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnDisplayTopOnClickListner(v);
        }
    });

    FwdButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            BtnFwdChunkOnClickListner(v);
        }
    });
    loadPage(viewedPage);
}

From source file:com.mario22gmail.license.nfc_project.NavigationDrawerActivity.java

public void OpenFacebook(String userName, String password) {
    WebView mWebview = (WebView) findViewById(R.id.webViewFb);
    String url = "https://www.facebook.com";
    js = "javascript:document.getElementsByName('email')[0].value = '" + userName
            + "';document.getElementsByName('pass')[0].value='" + password
            + "';document.getElementsByName('login')[0].click();";

    mWebview.loadUrl(url);
    WebSettings settings = mWebview.getSettings();
    settings.setJavaScriptEnabled(true);

    mWebview.setWebViewClient(new WebViewClient() {

        @Override//from  w  ww. j a  v  a2 s  .  c  o m
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            if (Build.VERSION.SDK_INT >= 19) {
                view.evaluateJavascript(js, new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String s) {

                    }
                });
            } else {
                view.loadUrl(js);
            }
        }
    });
}

From source file:org.zeroxlab.benchmark.Benchmark.java

private void initViews() {
    /*//from  w ww .j a v  a 2  s  .  c  o  m
    mRun = (Button)findViewById(R.id.btn_run);
    mRun.setOnClickListener(this);
            
    mShow = (Button)findViewById(R.id.btn_show);
    mShow.setOnClickListener(this);
    mShow.setClickable(false);
            
    mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
    mMainView = (LinearLayout)findViewById(R.id.main_view);
            
    mBannerInfo = (TextView)findViewById(R.id.banner_info);
    mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
    */

    mTabHost = getTabHost();

    int length = mCases.size();
    mCheckList = new CheckBox[length];
    mDesc = new TextView[length];
    for (int i = 0; i < length; i++) {
        mCheckList[i] = new CheckBox(this);
        mCheckList[i].setText(mCases.get(i).getTitle());
        mDesc[i] = new TextView(this);
        mDesc[i].setText(mCases.get(i).getDescription());
        mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
        mDesc[i].setPadding(42, 0, 10, 10);
    }

    TabContentFactory mTCF = new TabContentFactory() {
        public View createTabContent(String tag) {
            ViewGroup.LayoutParams fillParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.FILL_PARENT);
            ViewGroup.LayoutParams fillWrap = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wrapContent = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            wrapContent.gravity = Gravity.CENTER;
            LinearLayout.LayoutParams weightedFillWrap = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            weightedFillWrap.weight = 1;

            if (tag.equals(MAIN)) {
                LinearLayout mMainView = new LinearLayout(Benchmark.this);
                mMainView.setOrientation(1);
                ScrollView mListScroll = new ScrollView(Benchmark.this);

                LinearLayout mMainViewContainer = new LinearLayout(Benchmark.this);
                mMainViewContainer.setOrientation(1);
                ImageView mIconView = new ImageView(Benchmark.this);
                mIconView.setImageResource(R.drawable.icon);

                TextView mBannerInfo = new TextView(Benchmark.this);
                mBannerInfo.setText("0xbench\nSelect benchmarks in the tabs,\nor batch select:");

                d2CheckBox = new CheckBox(Benchmark.this);
                d2CheckBox.setText(D2);
                d2CheckBox.setOnClickListener(Benchmark.this);

                d2HWCheckBox = new CheckBox(Benchmark.this);
                d2HWCheckBox.setText(D2HW);
                d2HWCheckBox.setOnClickListener(Benchmark.this);

                d2SW1CheckBox = new CheckBox(Benchmark.this);
                d2SW1CheckBox.setText(D2SW1);
                d2SW1CheckBox.setOnClickListener(Benchmark.this);

                d2SW2CheckBox = new CheckBox(Benchmark.this);
                d2SW2CheckBox.setText(D2SW2);
                d2SW2CheckBox.setOnClickListener(Benchmark.this);

                d3CheckBox = new CheckBox(Benchmark.this);
                d3CheckBox.setText(D3);
                d3CheckBox.setOnClickListener(Benchmark.this);

                mathCheckBox = new CheckBox(Benchmark.this);
                mathCheckBox.setText(MATH);
                mathCheckBox.setOnClickListener(Benchmark.this);

                vmCheckBox = new CheckBox(Benchmark.this);
                vmCheckBox.setText(VM);
                vmCheckBox.setOnClickListener(Benchmark.this);

                nativeCheckBox = new CheckBox(Benchmark.this);
                nativeCheckBox.setText(NATIVE);
                nativeCheckBox.setOnClickListener(Benchmark.this);

                miscCheckBox = new CheckBox(Benchmark.this);
                miscCheckBox.setText(MISC);
                miscCheckBox.setOnClickListener(Benchmark.this);

                filterBitmapCheckBox = new CheckBox(Benchmark.this);
                filterBitmapCheckBox.setText("Filter Bitmap in Draw Image");
                filterBitmapCheckBox.setOnClickListener(Benchmark.this);

                useGradientCheckBox = new CheckBox(Benchmark.this);
                useGradientCheckBox.setText("Use Gradient in Draw Canvas/Circle/Rect/Arc");
                useGradientCheckBox.setOnClickListener(Benchmark.this);

                useTextureCheckBox = new CheckBox(Benchmark.this);
                useTextureCheckBox.setText("Use Texture in Draw Canvas/Circle/Rect/Arc");
                useTextureCheckBox.setOnClickListener(Benchmark.this);

                TextView mWebInfo = new TextView(Benchmark.this);
                mWebInfo.setText("Uploaded results:\nhttp://0xbenchmark.appspot.com");

                LinearLayout mButtonContainer = new LinearLayout(Benchmark.this);
                mRun = new Button(Benchmark.this);
                mShow = new Button(Benchmark.this);
                mRun.setText("Run");
                mShow.setText("Show");
                mRun.setOnClickListener(Benchmark.this);
                mShow.setOnClickListener(Benchmark.this);
                mButtonContainer.addView(mRun, weightedFillWrap);
                mButtonContainer.addView(mShow, weightedFillWrap);
                WebView mTracker = new WebView(Benchmark.this);
                mTracker.clearCache(true);
                mTracker.setWebViewClient(new WebViewClient() {
                    public void onPageFinished(WebView view, String url) {
                        Log.i(TAG, "Tracker: " + view.getTitle() + " -> " + url);
                    }

                    public void onReceivedError(WebView view, int errorCode, String description,
                            String failingUrl) {
                        Log.e(TAG, "Track err: " + description);
                    }
                });
                mTracker.loadUrl(trackerUrl);
                mMainViewContainer.addView(mIconView, wrapContent);
                mMainViewContainer.addView(mBannerInfo);
                mMainViewContainer.addView(mathCheckBox);
                mMainViewContainer.addView(d2CheckBox);
                mMainViewContainer.addView(d2HWCheckBox);
                mMainViewContainer.addView(d2SW1CheckBox);
                mMainViewContainer.addView(d2SW2CheckBox);
                mMainViewContainer.addView(d3CheckBox);
                mMainViewContainer.addView(vmCheckBox);
                mMainViewContainer.addView(nativeCheckBox);
                mMainViewContainer.addView(miscCheckBox);
                mMainViewContainer.addView(filterBitmapCheckBox);
                mMainViewContainer.addView(useGradientCheckBox);
                mMainViewContainer.addView(useTextureCheckBox);
                mMainViewContainer.addView(mWebInfo);
                mMainViewContainer.addView(mButtonContainer, fillWrap);
                mMainViewContainer.addView(mTracker, 0, 0);
                mListScroll.addView(mMainViewContainer, fillParent);
                mMainView.addView(mListScroll, fillWrap);

                return mMainView;

            }

            LinearLayout mMainView = new LinearLayout(Benchmark.this);
            mMainView.setOrientation(1);
            ScrollView mListScroll = new ScrollView(Benchmark.this);
            LinearLayout mListContainer = new LinearLayout(Benchmark.this);
            mListContainer.setOrientation(1);
            mListScroll.addView(mListContainer, fillParent);
            mMainView.addView(mListScroll, fillWrap);

            boolean gray = true;
            int length = mCases.size();
            Log.i(TAG, "L: " + length);
            Log.i(TAG, "TCF: " + tag);
            for (int i = 0; i < length; i++) {
                if (!mCategory.get(tag).contains(mCases.get(i)))
                    continue;
                Log.i(TAG, "Add: " + i);
                mListContainer.addView(mCheckList[i], fillWrap);
                mListContainer.addView(mDesc[i], fillWrap);
                if (gray) {
                    int color = 0xFF333333; //ARGB
                    mCheckList[i].setBackgroundColor(color);
                    mDesc[i].setBackgroundColor(color);
                }
                gray = !gray;
            }
            return mMainView;
        }
    };

    mTabHost.addTab(mTabHost.newTabSpec(MAIN).setIndicator(MAIN, getResources().getDrawable(R.drawable.ic_eye))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2).setIndicator(D2, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2HW).setIndicator(D2HW, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2SW1).setIndicator(D2SW1, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D2SW2).setIndicator(D2SW2, getResources().getDrawable(R.drawable.ic_2d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(D3).setIndicator(D3, getResources().getDrawable(R.drawable.ic_3d))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(MATH).setIndicator(MATH, getResources().getDrawable(R.drawable.ic_pi))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(VM).setIndicator(VM, getResources().getDrawable(R.drawable.ic_vm))
            .setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(NATIVE)
            .setIndicator(NATIVE, getResources().getDrawable(R.drawable.ic_c)).setContent(mTCF));
    mTabHost.addTab(mTabHost.newTabSpec(MISC).setIndicator(MISC, getResources().getDrawable(R.drawable.ic_misc))
            .setContent(mTCF));
}

From source file:com.wpi.assistments.HomeTabbedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_webview);

    final ProgressDialog pd = ProgressDialog.show(this, "", "Loading...", true);

    isTeacher = false;//from  w  w w.  j  a  v  a 2 s. c om
    toggle = true;
    logoutFlag = false;

    homeWebView = (WebView) findViewById(R.id.homeWebView);
    homeWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            Log.i("test", view.getUrl());
            if (view.getUrl().equals("https://www.assistments.org/account/login") && !logoutFlag) {

                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                intent.putExtra("showPopup", "true");
                startActivity(intent);
                finish();
            } else if (view.getUrl().equals("https://www.assistments.org/teacher")) {
                isTeacher = true;
            } else if (view.getUrl().equals("https://www.assistments.org/account/login") && logoutFlag) {
                Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
                startActivity(intent);
            }

            if (!homeWebView.canGoBack()) {
                btnBack.setEnabled(false);
            } else {
                btnBack.setEnabled(true);
            }

            if (!homeWebView.canGoForward()) {
                btnForward.setEnabled(false);
            } else {
                btnForward.setEnabled(true);
            }

            if (pd.isShowing() && pd != null) {
                pd.dismiss();
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            pd.show();
            view.loadUrl(url);
            return true;
        }
    });
    homeWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
            new AlertDialog.Builder(webviewContext).setTitle("ASSISTments").setMessage(message)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            logoutFlag = true;
                            result.confirm();
                        }
                    }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            result.cancel();
                        }
                    }).create().show();

            return true;
        }
    });

    if (savedInstanceState != null) {
        homeWebView.restoreState(savedInstanceState);
    } else {
        /** Scaling, replaced by overview mode and wide view port
        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        if (size.x <= 780) {
           int scaleRate = (int) ((size.x) / 7.8);
           Log.i("test", Integer.toString(size.x));
           homeWebView.setInitialScale(scaleRate);
        }
        */

        Intent intent = getIntent();

        if (intent.getStringExtra("username").equals("") && intent.getStringExtra("password").equals("")) {
            homeWebView.loadUrl("https://www.assistments.org/signup");

        } else {
            String username = intent.getStringExtra("username");
            String password = intent.getStringExtra("password");

            String postData = "login=" + username + "&password=" + password + "&commit=Log in";
            homeWebView.postUrl("https://www.assistments.org/account/login",
                    EncodingUtils.getBytes(postData, "BASE64"));
        }

    }

    WebSettings settings = homeWebView.getSettings();
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setDisplayZoomControls(false);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setSupportMultipleWindows(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setAppCacheEnabled(false);
    settings.setDomStorageEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setUseWideViewPort(false);
    settings.setLoadWithOverviewMode(true);
    homeWebView.clearCache(true);
    homeWebView.setPadding(0, 0, 0, 0);
    homeWebView.setInitialScale(getScale());

    btnBack = (Button) findViewById(R.id.btnBack);
    btnBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            homeWebView.goBack();
        }
    });

    btnRefresh = (Button) findViewById(R.id.btnRefresh);
    btnRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //homeWebView.zoomOut();
            homeWebView.scrollTo(1000, 0);
            Log.i("test", "111");
            //homeWebView.reload();
        }
    });

    btnForward = (Button) findViewById(R.id.btnForward);
    btnForward.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            homeWebView.goForward();
        }
    });

    btnOffline = (Button) findViewById(R.id.btnOffline);
    btnOffline.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (toggle) {
                homeWebView.loadUrl(
                        "https://www.assistments.org/assistments/student/index.html#offlineUserAssignmentList/");
                btnOffline.setText("Home");
                toggle = false;
            } else {
                if (isTeacher) {
                    homeWebView.loadUrl("https://www.assistments.org/teacher");
                } else {
                    homeWebView.loadUrl("https://www.assistments.org/tutor");
                }
                btnOffline.setText("Offline");
                toggle = true;
            }

        }
    });
}

From source file:com.juick.android.Utils.java

public static void setupWebView(final WebView wv, String content) {
    try {/*  w  ww.  ja  va  2  s.c  om*/
        if (skipWeb)
            return;
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(wv.getContext());
        File file = new File(wv.getContext().getCacheDir(), "temp.html");
        String PREFIX = "#prefs.checked.";
        while (true) {
            int ix = content.indexOf(PREFIX);
            if (ix == -1)
                break;
            int ix2 = content.indexOf("#", ix + 1);
            if (ix2 == -1)
                break;
            String key = content.substring(ix + PREFIX.length(), ix2);
            boolean def = false;
            if (key.endsWith("!")) {
                def = true;
                key = key.substring(0, key.length() - 1);
            }
            boolean checked = sp.getBoolean(key, def);
            content = content.substring(0, ix) + (checked ? "checked" : "") + content.substring(ix2 + 1);
        }
        FileWriter fileWriter = new FileWriter(file);
        fileWriter.write(content);
        fileWriter.close();
        wv.getSettings().setJavaScriptEnabled(true);
        //            wv.getSettings().setBlockNetworkImage(false);
        //            wv.getSettings().setBlockNetworkLoads(false);
        wv.getSettings().setLoadsImagesAutomatically(true);
        Uri uri = Uri.fromFile(file);
        wv.addJavascriptInterface(new Object() {
            public void onFormData(String str) {
                wv.setTag(str);
            }
        }, "EXT");
        wv.loadUrl(uri.toString());
    } catch (IOException e) {
        //
    }

}