Example usage for android.webkit WebView getSettings

List of usage examples for android.webkit WebView getSettings

Introduction

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

Prototype

public WebSettings getSettings() 

Source Link

Document

Gets the WebSettings object used to control the settings for this WebView.

Usage

From source file:com.azure.webapi.LoginManager.java

/**
 * Creates the UI for the interactive authentication process
 * //w ww .  j  a v a  2s . co m
 * @param provider
 *            The provider used for the authentication process
 * @param startUrl
 *            The initial URL for the authentication process
 * @param endUrl
 *            The final URL for the authentication process
 * @param context
 *            The context used to create the authentication dialog
 * @param callback
 *            Callback to invoke when the authentication process finishes
 */
protected void showLoginUI(MobileServiceAuthenticationProvider provider, final String startUrl,
        final String endUrl, final Context context, LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
        throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
        throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
        throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setTitle("Connecting to a service");
    builder.setCancelable(true);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
        }
    });

    // Set cancel button's action
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (externalCallback != null) {
                externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
            wv.destroy();
        }
    });

    wv.getSettings().setJavaScriptEnabled(true);

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
                if (!view.hasFocus()) {
                    view.requestFocus();
                }
            }

            return false;
        }
    });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(url, null);
                }

                dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
        }

        // Checks if the given URL matches with the final URL's format
        private boolean isFinalUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(endUrl);
        }

        // Checks if the given URL matches with the start URL's format
        private boolean isStartUrl(String url) {
            if (url == null) {
                return false;
            }

            return url.startsWith(startUrl);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
                if (externalCallback != null) {
                    externalCallback.onCompleted(null, new MobileServiceException(
                            "Logging in with the selected authentication provider is not enabled"));
                }

                dialog.dismiss();
            }
        }
    });

    wv.loadUrl(startUrl);
    dialog.show();
}

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

/**
 * Dialog ???//  w  ww.  j  av a  2  s  .c  o m
 * @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:im.vector.adapters.VectorMediasViewerAdapter.java

/**
 * Download the high res image//  ww  w  . j ava  2 s. co  m
 * @param view the slider page view
 * @param position the item position
 */
private void downloadHighResPict(final View view, final int position) {
    final WebView webView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    final SlidableMediaInfo imageInfo = mMediasMessagesList.get(position);
    final String viewportContent = "width=640";
    final String loadingUri = imageInfo.mMediaUrl;
    final String downloadId = mMediasCache.loadBitmap(mContext, mSession.getHomeserverConfig(), loadingUri,
            imageInfo.mRotationAngle, imageInfo.mOrientation, imageInfo.mMimeType);

    webView.getSettings().setDisplayZoomControls(false);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(downloadId)) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(downloadId)) {
                    pieFractionView.setVisibility(View.GONE);
                    final File mediaFile = mMediasCache.mediaCacheFile(loadingUri, imageInfo.mMimeType);

                    if (null != mediaFile) {
                        mHighResMediaIndex.add(position);

                        Uri uri = Uri.fromFile(mediaFile);
                        final String newHighResUri = uri.toString();

                        webView.post(new Runnable() {
                            @Override
                            public void run() {
                                Uri mediaUri = Uri.parse(newHighResUri);
                                // refresh the UI
                                loadImage(webView, mediaUri, viewportContent,
                                        computeCss(newHighResUri, VectorMediasViewerAdapter.this.mMaxImageWidth,
                                                VectorMediasViewerAdapter.this.mMaxImageHeight,
                                                imageInfo.mRotationAngle));
                            }
                        });
                    }
                }
            }
        });
    }
}

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

/**
 * Download the high res image/*ww  w  . j av a  2  s  . c  o  m*/
 * @param view the slider page view
 * @param position the item position
 */
private void downloadHighResPict(final View view, final int position) {
    final WebView webView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    final SlidableMediaInfo imageInfo = mMediasMessagesList.get(position);
    final String viewportContent = "width=640";
    final String loadingUri = imageInfo.mMediaUrl;
    final String downloadId = mMediasCache.loadBitmap(mContext, mSession.getHomeserverConfig(), loadingUri,
            imageInfo.mRotationAngle, imageInfo.mOrientation, imageInfo.mMimeType,
            imageInfo.mEncryptedFileInfo);

    webView.getSettings().setDisplayZoomControls(false);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(downloadId)) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(downloadId)) {
                    pieFractionView.setVisibility(View.GONE);
                    final File mediaFile = mMediasCache.mediaCacheFile(loadingUri, imageInfo.mMimeType);

                    if (null != mediaFile) {
                        mHighResMediaIndex.add(position);

                        Uri uri = Uri.fromFile(mediaFile);
                        final String newHighResUri = uri.toString();

                        webView.post(new Runnable() {
                            @Override
                            public void run() {
                                Uri mediaUri = Uri.parse(newHighResUri);
                                // refresh the UI
                                loadImage(webView, mediaUri, viewportContent,
                                        computeCss(newHighResUri, VectorMediasViewerAdapter.this.mMaxImageWidth,
                                                VectorMediasViewerAdapter.this.mMaxImageHeight,
                                                imageInfo.mRotationAngle));
                            }
                        });
                    }
                }
            }
        });
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.main_menu_add) {
        addFieldMapView();/*from   w ww  .  j  a  v  a2 s  .c o m*/
        return true;
    } else if (item.getItemId() == R.id.main_menu_current_location) {
        Location myLoc = map.getMyLocation();
        if (myLoc == null) {
            Toast.makeText(this, "Still searching for your location", 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));
        }
        return true;
    } else if (item.getItemId() == R.id.main_menu_list_view) {
        /*if(sliderIsShowing == 0){
           showSlider(true);
        } else {
           hideSlider(true);
        }
        if (mCurrentState == STATE_LIST_VIEW) {
           // Show map view
           Log.d("MainActivity", "Showing map view");
           setState(STATE_DEFAULT);
           //item.setIcon(R.drawable.list_view);
        } else {
           // Show list view
           Log.d("MainActivity", "Showing list view");
           setState(STATE_LIST_VIEW);
           //item.setIcon(R.drawable.map_view);
        }*/
        return true;
    } else if (item.getItemId() == R.id.main_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.getSettings().setSupportZoom(true);
        wv.getSettings().setBuiltInZoomControls(true);
        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();
        return true;
    } else if (item.getItemId() == R.id.main_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();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.lemon.lime.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getBatteryPercentage();//from w  w w . j a  v a2 s  .  c o  m
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    mWebView = (ObservableWebView) findViewById(R.id.activity_main_webview);
    mWebView.setScrollViewCallbacks(this);
    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflator.inflate(R.layout.bar, null);
    getSupportActionBar().setCustomView(v);

    WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh);
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mWebView.reload();
        }
    });
    swipeLayout.setColorSchemeResources(R.color.lili, R.color.colorPrimary, R.color.red);

    window = getWindow();
    favicon = (ImageView) findViewById(R.id.favicon);
    editurl = (EditText) findViewById(R.id.editurl);
    mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {

            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }

    });

    favicon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (lili == 5) {
                lilimode();
                lili = 0;
                lilimode = true;
            } else {
                lili = lili + 1;
            }
        }
    });

    editurl.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                if (event.getAction() == KeyEvent.ACTION_UP) {
                    if (editurl.getText().toString().contains("file:///")) {
                        filemgr();
                    } else if (editurl.getText().toString().contains("gaymode")) {
                        gaymode();
                    } else if (editurl.getText().toString().contains("exitapp")) {
                        finish();
                    } else if (editurl.getText().toString().contains("light")) {
                        flash();
                    }

                    if (isconnected()) {
                        if (editurl.getText().toString().contains("http://")
                                || editurl.getText().toString().contains("https://")) {
                            mWebView.loadUrl(editurl.getText().toString());

                        } else if (editurl.getText().toString().contains(".com")
                                || editurl.getText().toString().contains(".net")
                                || editurl.getText().toString().contains(".org")
                                || editurl.getText().toString().contains(".gov")
                                || editurl.getText().toString().contains(".hu")
                                || editurl.getText().toString().contains(".sk")
                                || editurl.getText().toString().contains(".co.uk")
                                || editurl.getText().toString().contains(".co.in")
                                || editurl.getText().toString().contains(".cn")
                                || editurl.getText().toString().contains(".it")
                                || editurl.getText().toString().contains(".de")
                                || editurl.getText().toString().contains(".aus")
                                || editurl.getText().toString().contains(".hr")
                                || editurl.getText().toString().contains(".cz")
                                || editurl.getText().toString().contains(".xyz")
                                || editurl.getText().toString().contains(".pl")
                                || editurl.getText().toString().contains(".io")) {
                            mWebView.loadUrl("http://" + editurl.getText().toString());

                            InputMethodManager imm = (InputMethodManager) getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0);

                        } else {
                            mWebView.loadUrl("https://www.google.com/search?q=" + editurl.getText().toString());

                            InputMethodManager imm = (InputMethodManager) getSystemService(
                                    Context.INPUT_METHOD_SERVICE);
                            imm.hideSoftInputFromWindow(editurl.getWindowToken(), 0);
                        }
                    }
                    return true;
                }
                return false;
            }

            return true;
        }
    });
    // Enable Javascript
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setSupportMultipleWindows(true);

    if (isconnected()) {
        mWebView.loadUrl("http://google.com");
    } else {

        final View coordinatorLayoutView = findViewById(R.id.snackbarPosition);
        mWebView.loadUrl("file:///android_asset/nonet.html");
        Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.offline, Snackbar.LENGTH_LONG);
        snackbar.show();

    }

    mWebView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onReceivedIcon(WebView mWebView, Bitmap icon) {
            super.onReceivedIcon(mWebView, icon);
            favicon.setImageBitmap(icon);
        }

        public void onProgressChanged(WebView view, int progress) {
            activity.setProgress(progress * 100);
            int a = progress;
            if (lilimode) {
                editurl.setText("Liling: " + Integer.toString(a) + "?");
            } else
                editurl.setText("Liming: " + Integer.toString(a) + "%");
            if (progress == 100) {

                editurl.setHint(view.getTitle());
                activity.setTitle(view.getTitle());
                editurl.setText(view.getUrl());

                fav();

                //battery
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if (level <= 20) {
                        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                        window.setNavigationBarColor(Color.RED);
                        window.setStatusBarColor(Color.RED);
                        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.RED));
                    }
                }
            }
        }
    });

    mWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView mWebView, String url) {
            swipeLayout.setRefreshing(false);
        }
    });

}

From source file:com.github.longkai.zhihu.ui.AnswerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.answer);//from ww  w .  j a v a2s . c om

    final TextView title = (TextView) findViewById(android.R.id.title);
    final WebView desc = (WebView) findViewById(R.id.description);
    final TextView nick = (TextView) findViewById(R.id.nick);
    final ImageView avatar = (ImageView) findViewById(R.id.avatar);
    final TextView status = (TextView) findViewById(R.id.status);
    final WebView answer = (WebView) findViewById(R.id.content);
    final TextView last_alter_date = (TextView) findViewById(R.id.last_alter_date);

    id = getIntent().getLongExtra(ANSWER_ID, 0);
    new AsyncQueryHandler(getContentResolver()) {
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            if (cursor.moveToNext()) {
                // 
                aid = cursor.getLong(cursor.getColumnIndex(ANSWER_ID));
                qid = cursor.getLong(cursor.getColumnIndex(QUESTION_ID));
                questionTitle = cursor.getString(cursor.getColumnIndex(TITLE));
                title.setText(questionTitle);
                String description = cursor.getString(cursor.getColumnIndex(DESCRIPTION));
                if (TextUtils.isEmpty(description)) {
                    desc.setVisibility(View.GONE);
                } else {
                    desc.loadDataWithBaseURL(null, description, "text/html", "utf-8", null);
                    desc.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                    desc.setBackgroundColor(getResources().getColor(R.color.bgcolor));
                }

                // 
                uid = cursor.getString(cursor.getColumnIndex(UID));
                nick.setText(cursor.getString(cursor.getColumnIndex(NICK)));
                String src = cursor.getString(cursor.getColumnIndex(AVATAR));
                ZhihuApp.getImageLoader().get(src,
                        ImageLoader.getImageListener(avatar, R.drawable.ic_launcher, R.drawable.ic_launcher));
                status.setText(cursor.getString(cursor.getColumnIndex(STATUS)));

                // 
                String content = cursor.getString(cursor.getColumnIndex(ANSWER));
                answerDigest = content.length() > 50 ? content.substring(0, 50) : content;
                answer.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
                answer.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                answer.setBackgroundColor(getResources().getColor(R.color.bgcolor));

                last_alter_date.setText(DateUtils
                        .getRelativeTimeSpanString(cursor.getLong(cursor.getColumnIndex(LAST_ALTER_DATE))));

                cursor.close();
            }
        }
    }.startQuery(0, null, Uri.parse(ZhihuProvider.BASE_URI + Constants.ITEMS + "/" + id), ITEM_PROJECTION, null,
            null, null);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*w  ww . jav  a 2s .co  m*/
public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);
    view.getSettings().setTextZoom(textSize);

    mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(),
            new ScaleGestureDetector.OnScaleGestureListener() {
                @Override
                public void onScaleEnd(ScaleGestureDetector detector) {
                }

                @Override
                public boolean onScaleBegin(ScaleGestureDetector detector) {
                    return true;
                }

                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor());
                    return false;
                }

            });

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

    // ----- SWIPE PAGE
    view.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            /*   if (state == ViewStateEnum.books)
                  swipePage(v, event, 0);
               //int fontSize, newFont;*/
            WebView view = (WebView) v;

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                x1 = event.getX();
                break;
            case MotionEvent.ACTION_UP:
                if (mode != ZOOM && swipeFlag) {
                    //if (state == ViewStateEnum.books)
                    //swipePage(v, event, 0);

                }
                break;
            case MotionEvent.ACTION_POINTER_DOWN:
                oldDist = spacing(event);
                if (oldDist > 10f) {
                    mode = ZOOM;
                }
                break;
            case MotionEvent.ACTION_POINTER_UP:
                mode = NONE;
                break;

            case MotionEvent.ACTION_MOVE:

                if (mode == ZOOM) {
                    float newDist = spacing(event);
                    if (newDist > 10f) {
                        float scale = newDist / oldDist;
                        if (scale > 1) {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize + 15;
                            view.getSettings().setTextZoom(textSize);

                            mode = NONE;
                            swipeFlag = false;
                        } else {
                            int currentTextSize = view.getSettings().getTextZoom();
                            textSize = currentTextSize - 15;
                            view.getSettings().setTextZoom(textSize);
                            mode = NONE;
                            swipeFlag = false;
                        }
                    }
                }
                break;

            }
            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;
        }
    });

    loadPage(viewedPage);
}

From source file:RhodesService.java

@Override
public void onCreate() {
    Logger.D(TAG, "onCreate");

    sInstance = this;

    Context context = this;

    mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    LocalFileProvider.revokeUriPermissions(this);

    Logger.I("Rhodes", "Loading...");
    RhodesApplication.create();/*from  w  w w  .ja  v a 2 s  .  c  o  m*/

    RhodesActivity ra = RhodesActivity.getInstance();
    if (ra != null) {
        // Show splash screen only if we have active activity
        SplashScreen splashScreen = ra.getSplashScreen();
        splashScreen.start();

        // Increase WebView rendering priority
        WebView w = new WebView(context);
        WebSettings webSettings = w.getSettings();
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    }

    initForegroundServiceApi();

    // Register custom uri handlers here
    mUriHandlers.addElement(new ExternalHttpHandler(context));
    mUriHandlers.addElement(new LocalFileHandler(context));
    mUriHandlers.addElement(new MailUriHandler(context));
    mUriHandlers.addElement(new TelUriHandler(context));
    mUriHandlers.addElement(new SmsUriHandler(context));
    mUriHandlers.addElement(new VideoUriHandler(context));

    mConnectionChangeReceiver = new ConnectionChangeReceiver();
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mConnectionChangeReceiver, filter);

    RhodesApplication.start();

    if (BaseActivity.getActivitiesCount() > 0)
        handleAppActivation();
}

From source file:org.safegees.safegees.gui.view.MainActivity.java

private void start() {
    if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
            && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length() > 0) {
        shareDataWithServer();/*from w  ww . j  a  v  a 2 s  .  c o m*/
    } else {

        /* TEST
        if(DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)).length()>0){
        launchMainActivity();
        }else{
        //Start the loggin for result
        Intent loginInt = new Intent(this, LoginActivity.class);
        startActivityForResult(loginInt, 1);
        }*/

        if (Connectivity.isNetworkAvaiable(this) || StoredDataQuequesManager.getAppUsersMap(this).size() != 0) {

            final MainActivity mainActivity = this;

            //Download data
            this.adviceUser.setText(getResources().getString(R.string.splash_advice_download_info_hub));

            //Test
            //Not here at final
            final WebView webView = (WebView) this.findViewById(R.id.webview_info_pre_cache);
            final ArrayList<String> infoWebUrls = WebViewInfoWebDownloadController.getInfoUrlsArrayList();
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (infoWebUrls.size() > 0) {
                        String nextUrl = infoWebUrls.get(0);
                        infoWebUrls.remove(nextUrl);
                        webView.loadUrl(nextUrl);
                    } else {
                        //Only one time
                        DATA_STORAGE.putBoolean(mainActivity.getResources().getString(R.string.KEY_INFO_WEB),
                                true);
                        //Start the loggin for result
                        Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                        startActivityForResult(loginInt, 1);
                    }
                }
            });

            String nextUrl = infoWebUrls.get(0);
            infoWebUrls.remove(nextUrl);
            webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebChromeClient(new WebChromeClient());

            if (StoredDataQuequesManager.getAppUsersMap(mainActivity).size() == 0
                    && !DATA_STORAGE.getBoolean(getResources().getString(R.string.KEY_INFO_WEB))) {
                webView.loadUrl(nextUrl);
            } else {
                if (DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL)) != null
                        && DATA_STORAGE.getString(getResources().getString(R.string.KEY_USER_MAIL))
                                .length() > 0) {
                    launchMainActivity();
                } else {
                    //Start the loggin for result
                    Intent loginInt = new Intent(mainActivity, LoginActivity.class);
                    startActivityForResult(loginInt, 1);
                }
            }

        } else {
            setNoInternetAdvice(this);
        }
    }
}