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:me.piebridge.prevent.ui.UserGuideActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);/*from  w  w w  . j a  v  a  2 s.  c  o m*/
    ThemeUtils.fixSmartBar(this);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    if ("zh".equals(Locale.getDefault().getLanguage())) {
        webView.loadUrl("file:///android_asset/about.zh.html");
    } else {
        webView.loadUrl("file:///android_asset/about.en.html");
    }
    setView(R.id.alipay, "com.eg.android.AlipayGphone");
    if (hasPermission()) {
        setView(R.id.wechat, "com.tencent.mm");
    } else {
        findViewById(R.id.wechat).setVisibility(View.GONE);
    }
    if (!setView(R.id.paypal, "com.paypal.android.p2pmobile")) {
        TextView paypal = (TextView) findViewById(R.id.paypal);
        paypal.setClickable(true);
        paypal.setOnClickListener(this);
        paypal.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(paypal.getCompoundDrawables()[1]),
                null, null);
    }
    if (setView(R.id.play, "com.android.vending")) {
        findViewById(R.id.play).setVisibility(View.GONE);
        checkDonate();
    }
    donateView = findViewById(R.id.donate);
    if (BuildConfig.DONATE && TextUtils.isEmpty(LicenseUtils.getLicense(this))) {
        donateView.setVisibility(View.VISIBLE);
    } else {
        donateView.setVisibility(View.GONE);
    }
    retrieveInfo();
}

From source file:eu.focusnet.app.ui.activity.ProjectsListingActivity.java

/**
 * Do any UI operation that do not imply creating and including a new Fragment in the UI.
 * The following is performed depending on which menu item is selected:
 * - if projects or bookmarks listing: highlight the appropriate menu item
 * - if About, then display a dialog with the information about the app
 * - If Logout, then reset the application
 * <p/>//w w w.jav  a 2s .c  o m
 * See {@link super#applyUiChanges()}.
 */
@Override
protected void doInPageUiOperations() {
    switch (this.sectionToRender) {
    case Constant.Navigation.UI_MENU_ENTRY_PROJECTS_LISTING:
    case Constant.Navigation.UI_MENU_ENTRY_BOOKMARK:
        highlightSelectedMenuItem(this.sectionToRender);
        break;
    case Constant.Navigation.UI_MENU_ENTRY_ABOUT:
        LayoutInflater inflater = LayoutInflater.from(this);
        // FIXME set a better Context than null
        final WebView dialogContent = (WebView) inflater.inflate(R.layout.dialog_content_about, null);
        dialogContent.loadUrl("file:///android_asset/" + Constant.AppConfig.ASSETS_ABOUT_PAGE);
        final FocusDialogBuilder builder = new FocusDialogBuilder(this).removeNeutralButton()
                .removeNegativeButton().removePositiveButton().setCancelable(true).insertContent(dialogContent)
                .setTitle(getString(R.string.about_focus_title));
        AlertDialog dialog = builder.create();
        dialog.show();
        break;
    case Constant.Navigation.UI_MENU_ENTRY_LOGOUT:
        final Thread logoutThread = new Thread() {
            public void run() {
                // reset all when logging out
                FocusAppLogic.getInstance().reset();
                // redirect to the EntryPointActivity
                try {
                    Intent i = new Intent(ProjectsListingActivity.this, EntryPointActivity.class);
                    i.putExtra(Constant.Extra.UI_EXTRA_LOADING_INFO_TEXT,
                            getString(R.string.wiping_user_data_logout_msg));
                    startActivity(i);
                } finally {
                    finish();
                }
            }
        };
        logoutThread.start();
        break;
    default:
        break;
    }

    // close the drawer and cleanup
    if (this.sectionToRender != 0) {
        drawerLayout.closeDrawer(this.drawerListMenu);

        // do not keep selection on the current item
        switch (this.sectionToRender) {
        case Constant.Navigation.UI_MENU_ENTRY_ABOUT:
            highlightSelectedMenuItem(this.previouslySelectedSectionToRender);
            break;
        }
    }
}

From source file:com.github.jobs.ui.fragment.EditTemplateFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // init argument fields
    Bundle arguments = getArguments();/*from   w w w .  j a va  2 s  . c  om*/
    mTemplateId = arguments.getLong(ARG_TEMPLATE_ID, -1);

    mShowEditor = mShowEditor || mTemplateId == -1;

    // prepare ui
    View root = getView();
    mViewSwitcher = (ViewSwitcher) root.findViewById(R.id.switcher_edit_mode);
    if (!mShowEditor) {
        showEditor(mShowEditor);
    }

    WebView templatePreview = (WebView) root.findViewById(R.id.lbl_cover_letter_preview);
    AppUtils.setupWebView(templatePreview);
    mJavascriptInterface = new GithubJobsJavascriptInterface(getActivity(), templatePreview, null);
    templatePreview.addJavascriptInterface(mJavascriptInterface, JS_INTERFACE);
    templatePreview.loadUrl(PREVIEW_TEMPLATE_URL);

    mTemplateName = (EditText) root.findViewById(R.id.edit_cover_letter_name);
    mTemplateContent = (EditText) root.findViewById(R.id.edit_cover_letter_content);
    mTemplateContent.addTextChangedListener(mTextWatcher);

    if (mTemplateId != -1) {
        // retrieve template from database
        Template template = new Template();
        template.setId(mTemplateId);
        template = adapter.findFirst(template);
        ArrayList<TemplateService> templateServices = new ArrayList<TemplateService>(
                template.getTemplateServices());
        for (TemplateService savedService : mTemplateServices) {
            if (!templateServices.contains(savedService)) {
                templateServices.add(savedService);
            }
        }
        mTemplateServices = templateServices;

        // set name and raw content
        mTemplateName.setText(template.getName());
        getActivity().setTitle(template.getName());
        String content = template.getContent();
        mTemplateContent.setText(content);
        updatePreview();
    }
}

From source file:net.basov.ticketinfo.UI.java

public void displayHelpScreen(String title, final WebView wv) {

    setHelp("h_header", title);
    setHelp("h_storage", FileIO.getFilesDir(wv.getContext()).getAbsolutePath());

    wv.setWebViewClient(new MyWebViewClient() {
        @Override/*from  w w  w  . j  a va 2  s .  com*/
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(wv, url);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                view.evaluateJavascript("javascript:jreplace('" + help_json.toString() + "')", null);
            } else {
                view.loadUrl("javascript:jreplace('" + help_json.toString() + "')");
            }
            wv.clearCache(true);
        }
    });
    Context c = wv.getContext();
    wv.loadUrl("file:///android_asset/" + c.getString(R.string.help_ui_file));

}

From source file:com.example.ruby.mygetgps.ui.activities.MainActivity.java

private void setupWebView() {
    WebView webview = (WebView) findViewById(R.id.webview);
    webview.setWebChromeClient(new WebChromeClient() {
        public void onGeolocationPermissionsShowPrompt(String origin,
                GeolocationPermissions.Callback callback) {
            callback.invoke(origin, true, false);
        }//from w  ww.  j a  va2  s  .  c om
    });
    webview.setWebViewClient(new WebViewClient());
    webview.clearCache(true);
    webview.clearHistory();
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webview.loadUrl("https://getgpsserverrails-0.herokuapp.com/summaries");
}

From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java

@Override
public void update(boolean doUpdate) {
    if (getView() == null)
        return;/*from  w w  w . j a va2  s . c o m*/

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

    FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity());
    String url = currentServer.getUrl();
    try {
        if (url != null) {
            String host = new URL(currentServer.getUrl()).getHost();
            String username = currentServer.getUsername();
            String password = currentServer.getPassword();

            if (username != null && password != null) {
                webView.setHttpAuthUsernamePassword(host, "", username, password);
            }
        }

        webView.loadUrl(getLoadUrl());
    } catch (MalformedURLException e) {
        Intent intent = new Intent(Actions.SHOW_TOAST);
        intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection);
        getActivity().sendBroadcast(intent);
        LOG.error("malformed URL: " + url, e);
    }
}

From source file:com.cw.litenote.note.Note_adapter.java

@Override
public void setPrimaryItem(final ViewGroup container, int position, Object object) {
    // set primary item only
    if (mLastPosition != position) {
        System.out.println("Note_adapter / _setPrimaryItem / mLastPosition = " + mLastPosition);
        System.out.println("Note_adapter / _setPrimaryItem / position = " + position);

        String lastPictureStr = null;
        String lastLinkUri = null;
        String lastAudioUri = null;

        if (mLastPosition != -1) {
            lastPictureStr = db_page.getNotePictureUri(mLastPosition, true);
            lastLinkUri = db_page.getNoteLinkUri(mLastPosition, true);
            lastAudioUri = db_page.getNoteAudioUri(mLastPosition, true);
        }/*from  w  w w  .jav  a  2 s.  co m*/

        String pictureStr = db_page.getNotePictureUri(position, true);
        String linkUri = db_page.getNoteLinkUri(position, true);
        String audioUri = db_page.getNoteAudioUri(position, true);

        // remove last text web view
        if (!Note.isPictureMode()) {
            String tag = "current" + mLastPosition + "textWebView";
            CustomWebView textWebView = (CustomWebView) pager.findViewWithTag(tag);
            if (textWebView != null) {
                textWebView.onPause();
                textWebView.onResume();
            }
        }

        // for web view
        if (!UtilImage.hasImageExtension(pictureStr, act) && !UtilVideo.hasVideoExtension(pictureStr, act)) {
            // remove last link web view
            if (!UtilImage.hasImageExtension(lastPictureStr, act)
                    && !UtilVideo.hasVideoExtension(lastPictureStr, act)
                    && !UtilAudio.hasAudioExtension(lastAudioUri) && !Util.isYouTubeLink(lastLinkUri)) {
                String tag = "current" + mLastPosition + "linkWebView";
                CustomWebView lastLinkWebView = (CustomWebView) pager.findViewWithTag(tag);

                if (lastLinkWebView != null) {
                    CustomWebView.pauseWebView(lastLinkWebView);
                    CustomWebView.blankWebView(lastLinkWebView);
                }
            }

            // set current link web view in case no picture Uri
            if (Util.isEmptyString(pictureStr) && !Util.isYouTubeLink(linkUri) && linkUri.startsWith("http")
                    && !Note.isTextMode()) {
                if (Note.isViewAllMode()) {
                    String tagStr = "current" + position + "linkWebView";
                    CustomWebView linkWebView = (CustomWebView) pager.findViewWithTag(tagStr);
                    linkWebView.setVisibility(View.VISIBLE);
                    setWebView(linkWebView, object, CustomWebView.LINK_VIEW);
                    System.out.println("Note_adapter / _setPrimaryItem / load linkUri = " + linkUri);
                    linkWebView.loadUrl(linkUri);

                    //Add for non-stop showing of full screen web view
                    linkWebView.setWebViewClient(new WebViewClient() {
                        @Override
                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
                            view.loadUrl(url);
                            return true;
                        }
                    });

                    //cf. https://stackoverflow.com/questions/13576153/how-to-get-text-from-a-webview
                    //                  linkWebView.addJavascriptInterface(new JavaScriptInterface(act), "Android");
                } else if (Note.isPictureMode()) {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUri));
                    act.startActivity(i);
                }
            }
        }

        // for video view
        if (!Note.isTextMode()) {

            // stop last video view running
            if (mLastPosition != -1) {
                String tagVideoStr = "current" + mLastPosition + "videoView";
                VideoViewCustom lastVideoView = (VideoViewCustom) pager.findViewWithTag(tagVideoStr);
                lastVideoView.stopPlayback();
            }

            // Show picture view UI
            if (Note.isViewAllMode() || Note.isPictureMode()) {
                NoteUi.cancel_UI_callbacks();
                picUI_primary = new NoteUi(act, pager, position);
                picUI_primary.tempShow_picViewUI(5002, pictureStr);
            }

            // Set video view
            if (UtilVideo.hasVideoExtension(pictureStr, act) && !UtilImage.hasImageExtension(pictureStr, act)) {
                // update current pager view
                UtilVideo.mCurrentPagerView = (View) object;

                // for view mode change
                if (Note.mIsViewModeChanged && (Note.mPlayVideoPositionOfInstance == 0)) {
                    UtilVideo.mPlayVideoPosition = Note.mPositionOfChangeView;
                    UtilVideo.setVideoViewLayout(pictureStr);

                    if (UtilVideo.mPlayVideoPosition > 0)
                        UtilVideo.playOrPauseVideo(pager, pictureStr);
                } else {
                    // for key protect
                    if (Note.mPlayVideoPositionOfInstance > 0) {
                        UtilVideo.setVideoState(UtilVideo.VIDEO_AT_PAUSE);
                        UtilVideo.setVideoViewLayout(pictureStr);

                        if (!UtilVideo.hasMediaControlWidget) {
                            NoteUi.updateVideoPlayButtonState(pager, NoteUi.getFocus_notePos());
                            picUI_primary.tempShow_picViewUI(5003, pictureStr);
                        }

                        UtilVideo.playOrPauseVideo(pager, pictureStr);
                    } else {
                        if (UtilVideo.hasMediaControlWidget)
                            UtilVideo.setVideoState(UtilVideo.VIDEO_AT_PLAY);
                        else
                            UtilVideo.setVideoState(UtilVideo.VIDEO_AT_STOP);

                        UtilVideo.mPlayVideoPosition = 0; // make sure play video position is 0 after page is changed
                        UtilVideo.initVideoView(pager, pictureStr, act, position);
                    }
                }

                UtilVideo.currentPicturePath = pictureStr;
            }
        }

        ViewGroup audioBlock = (ViewGroup) act.findViewById(R.id.audioGroup);
        audioBlock.setVisibility(View.VISIBLE);

        // init audio block of pager
        if (UtilAudio.hasAudioExtension(audioUri)
                || UtilAudio.hasAudioExtension(Util.getDisplayNameByUriString(audioUri, act))) {
            AudioUi_note.initAudioProgress(act, audioUri, pager);

            if (Audio_manager.getAudioPlayMode() == Audio_manager.NOTE_PLAY_MODE) {
                if (Audio_manager.getPlayerState() != Audio_manager.PLAYER_AT_STOP)
                    AudioUi_note.updateAudioProgress(act);
            }

            AudioUi_note.updateAudioPlayState(act);
        } else
            audioBlock.setVisibility(View.GONE);
    }
    mLastPosition = position;

}

From source file:com.plusapp.pocketbiceps.app.MainActivity.java

private void displayImpressumAlertDialog() {
    WebView view = (WebView) LayoutInflater.from(this).inflate(R.layout.dialog_licenses, null);
    view.loadUrl("file:///android_asset/impressum.html");
    AlertDialog mAlertDialog;/*from  w w w .ja v  a  2 s . c o m*/
    mAlertDialog = new AlertDialog.Builder(this, R.style.Theme_AppCompat_Light_Dialog_Alert).setView(view)
            .setPositiveButton(android.R.string.ok, null).show();
}

From source file:ca.bitwit.postcard.PostcardAdaptor.java

/**
 * Cordova Plugin Overrides//w  w w  . ja  v  a  2 s.com
 */

public PostcardAdaptor(Activity activity, WebView webView) {
    Log.d("PostcardApplication", "Initialized");
    NetworksManager.INSTANCE.adaptor = this;
    this.activity = activity;
    this.webView = webView;

    Context context = activity.getApplicationContext();

    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.addJavascriptInterface(this, "PostcardApplication");
    webView.loadUrl("file:///android_asset/www/index.html");

    this.properties = new Properties();
    String propFileName = "postcard.properties";

    try {
        InputStream inputStream = context.getAssets().open(propFileName);
        if (inputStream != null) {
            this.properties.load(inputStream);
        } else {
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.networkAccountDataSource = new NetworkAccountDataSource(context);
    this.networkAccountDataSource.open();

    this.personDataSource = new PersonDataSource(context);
    this.personDataSource.open();

    this.tagDataSource = new TagDataSource(context);
    this.tagDataSource.open();
}

From source file:com.openatk.rockapp.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean result = false;

    switch (item.getItemId()) {
    case R.id.add:
        addRock();/* w  ww .jav a2  s . c  o  m*/
        result = true;
        break;

    case R.id.gps:
        Location myLoc = map.getMyLocation();
        if (myLoc == null) {
            Toast.makeText(this, R.string.location_wait, Toast.LENGTH_SHORT).show();
        } else {
            CameraPosition oldPos = map.getCameraPosition();
            CameraPosition newPos = new CameraPosition(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()),
                    map.getMaxZoomLevel(), oldPos.tilt, oldPos.bearing);
            map.animateCamera(CameraUpdateFactory.newCameraPosition(newPos));
        }
        result = true;
        break;

    case R.id.all_rocks:
        // set the new showHide, update the map, and update the action bar
        changeRockTypeShowHide(STATE_ROCKS_BOTH);
        result = true;
        break;

    case R.id.not_picked_rocks:
        // set the new showHide, update the map, and update the action bar
        changeRockTypeShowHide(STATE_ROCKS_NOT_PICKED_UP);
        result = true;
        break;

    case R.id.picked_rocks:
        // set the new showHide, update the map, and update the action bar
        changeRockTypeShowHide(STATE_ROCKS_PICKED_UP);
        result = true;
        break;

    case R.id.list:
        // showRockList();
        result = true;
        break;

    case R.id.rock_delete:
        showConfirmRockDeleteAlert();
        result = true;
        break;

    case R.id.rock_undo_move:
        undoRockMove();
        result = true;
        break;

    case R.id.sync:
        //Tell trello app to sync
        TrelloContentProvider.Sync(this.getApplicationContext().getPackageName());
        result = true;
        break;
    case R.id.menu_help:
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Help");
        WebView wv = new WebView(this);
        wv.loadUrl("file:///android_asset/Help.html");
        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        alert.setView(wv);
        alert.setNegativeButton("Close", null);
        alert.show();
        break;
    case R.id.menu_legal:
        CharSequence licence = "The MIT License (MIT)\n" + "\n" + "Copyright (c) 2013 Purdue University\n"
                + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy "
                + "of this software and associated documentation files (the \"Software\"), to deal "
                + "in the Software without restriction, including without limitation the rights "
                + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell "
                + "copies of the Software, and to permit persons to whom the Software is "
                + "furnished to do so, subject to the following conditions:" + "\n"
                + "The above copyright notice and this permission notice shall be included in "
                + "all copies or substantial portions of the Software.\n" + "\n"
                + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR "
                + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, "
                + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE "
                + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER "
                + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, "
                + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN "
                + "THE SOFTWARE.\n";
        new AlertDialog.Builder(this).setTitle("Legal").setMessage(licence)
                .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton("Close", null).show();
        break;
    }

    // If we didn't handle, let the super version try
    return result | super.onOptionsItemSelected(item);
}