Example usage for android.webkit WebView WebView

List of usage examples for android.webkit WebView WebView

Introduction

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

Prototype

public WebView(Context context) 

Source Link

Document

Constructs a new WebView with an Activity Context object.

Usage

From source file:piuk.blockchain.android.ui.WalletActivity.java

@Override
protected Dialog onCreateDialog(final int id) {
    final WebView webView = new WebView(this);
    if (id == DIALOG_HELP)
        webView.loadUrl("file:///android_asset/help" + languagePrefix() + ".html");

    final Dialog dialog = new Dialog(WalletActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(webView);/*from   w  w  w.j  a va2s . c  o  m*/
    dialog.setCanceledOnTouchOutside(true);

    return dialog;
}

From source file:arc.noaa.weather.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Forecastie");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='mailto:t.martykan@gmail.com'>Tomas Martykan</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();//from   w w  w  . j a  v  a2  s.  com
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.userhook.view.UHMessageView.java

protected void loadWebViewContent(String html) {

    WebView webView = new WebView(getContext());
    webView.setWebViewClient(new MessageWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);

    // find dialog width in pixels
    final float scale = getResources().getDisplayMetrics().density;
    int width = (int) (dialogWidth * scale);

    LayoutParams layoutParams = new LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(CENTER_IN_PARENT);
    addView(webView, layoutParams);/*from w ww . j av a  2s  .com*/

    webView.loadData(html, "text/html", "utf-8");
    contentView = webView;

    contentLoaded = true;
}

From source file:ru.frostdev.weather.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("About");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='FrostDev:mrfrost2035@gmail.com'>FrostDev</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    if (darkTheme) {
        // Style text color for dark theme
        about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:white;\n" + "}\n"
                + "a:link {color:cyan}\n" + "</style>" + about;
    }/*from www.j av a2 s.  co m*/
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:com.guidewithme.ArticleInfoListFragment.java

private void showLicense() {
    final WebView wb = new WebView(getActivity());
    wb.loadUrl("file:///android_asset/license.html");

    final AlertDialog ad = new AlertDialog.Builder(getActivity()).setTitle(R.string.about).setCancelable(true)
            .create();//from  ww  w  .  j a  v  a2 s .c o  m
    ad.setCanceledOnTouchOutside(true);
    ad.setView(wb);
    ad.show();
}

From source file:com.phonegap.plugins.slaveBrowser.SlaveBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url       The url to load.// w  w  w  .  j  av  a2  s .  c om
 * @param jsonObject 
 */
public String showWebPage(final String url, JSONObject options, String myNewTitle) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }
    zeTitle = myNewTitle;

    // Create dialog in new thread 
    Runnable runnable = new Runnable() {
        public void run() {
            dialog = new Dialog(ctx.getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);
                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT, 1.0f);
            LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT);
            LinearLayout main = new LinearLayout(ctx.getContext());
            main.setOrientation(LinearLayout.VERTICAL);

            LinearLayout toolbar = new LinearLayout(ctx.getContext());
            toolbar.setOrientation(LinearLayout.HORIZONTAL);

            edittext = new TextView(ctx.getContext());
            edittext.setId(3);
            edittext.setSingleLine(true);
            edittext.setText(zeTitle);
            edittext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 24);
            edittext.setGravity(Gravity.CENTER);
            edittext.setTextColor(Color.DKGRAY);
            edittext.setTypeface(Typeface.DEFAULT_BOLD);
            edittext.setLayoutParams(editParams);

            webview = new WebView(ctx.getContext());
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setBuiltInZoomControls(true);

            // dda: intercept calls to console.log
            webview.setWebChromeClient(new WebChromeClient() {
                public boolean onConsoleMessage(ConsoleMessage cmsg) {
                    // check secret prefix
                    if (cmsg.message().startsWith("MAGICHTML")) {
                        String msg = cmsg.message().substring(9); // strip off prefix
                        /* process HTML */
                        try {
                            JSONObject obj = new JSONObject();
                            obj.put("type", PAGE_LOADED);
                            obj.put("html", msg);
                            sendUpdate(obj, true);
                        } catch (JSONException e) {
                            Log.d(LOG_TAG, "This should never happen");
                        }
                        return true;
                    }
                    return false;
                }
            });

            // dda: inject the JavaScript on page load
            webview.setWebViewClient(new SlaveBrowserClient(edittext) {
                public void onPageFinished(WebView view, String address) {
                    // have the page spill its guts, with a secret prefix
                    view.loadUrl(
                            "javascript:console.log('MAGICHTML'+document.getElementsByTagName('html')[0].innerHTML);");
                }
            });

            webview.loadUrl(url);
            webview.setId(5);
            webview.setInitialScale(0);
            webview.setLayoutParams(wvParams);
            webview.requestFocus();
            webview.requestFocusFromTouch();

            toolbar.addView(edittext);

            if (getShowLocationBar()) {
                main.addView(toolbar);
            }
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = ctx.getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.ctx.runOnUiThread(runnable);
    return "";
}

From source file:org.ednovo.goorusearchwidget.ResourcePlayer.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog = new ProgressDialog(this);
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    setContentViewLayout = new RelativeLayout(ResourcePlayer.this);
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);

    token = prefsPrivate.getString("token", "");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    Bundle extra = getIntent().getExtras();

    if (extra != null) {
        value = extra.getInt("key");
        gooruOID1 = extra.getStringArrayList("goor");

        searchkeyword = extra.getString("searchkey");
        limit = gooruOID1.size();//from   w w w . ja v a2s  . c om
        gooruOID = gooruOID1.get(value);
        resourceGooruId = gooruOID;

        if (!gooruOID.isEmpty() || !gooruOID.equalsIgnoreCase("") || gooruOID != null) {
            if (checkInternetConnection()) {
                dialog = new ProgressDialog(ResourcePlayer.this);
                dialog.setTitle("gooru");
                dialog.setMessage("Please wait while loading...");
                dialog.setCancelable(false);
                dialog.show();
                new getResourcesInfo().execute();
            } else {

                dialog = new ProgressDialog(ResourcePlayer.this);
                dialog.setTitle("gooru");
                dialog.setMessage("No internet connection");
                dialog.show();
            }

        }
    }
    Editor prefsPrivateEditor = prefsPrivate.edit();

    // Authentication details
    prefsPrivateEditor.putString("searchkeyword", searchkeyword);
    prefsPrivateEditor.commit();

    wvPlayer = new WebView(ResourcePlayer.this);
    wvPlayer.resumeTimers();
    wvPlayer.getSettings().setJavaScriptEnabled(true);
    wvPlayer.getSettings().setPluginState(PluginState.ON);
    wvPlayer.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    wvPlayer.setWebViewClient(new HelloWebViewClient());

    wvPlayer.setWebChromeClient(new MyWebChromeClient() {
    });
    wvPlayer.getSettings().setPluginsEnabled(true);
    new getResourcesInfo().execute();

    RelativeLayout temp = new RelativeLayout(ResourcePlayer.this);
    temp.setId(668);
    temp.setBackgroundColor(getResources().getColor(android.R.color.transparent));

    header = new RelativeLayout(ResourcePlayer.this);
    header.setId(1);

    header.setBackgroundDrawable(getResources().getDrawable(R.drawable.navbar));
    RelativeLayout.LayoutParams headerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, 53);
    headerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, -1);
    headerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, -1);

    ivCloseIcon = new ImageView(ResourcePlayer.this);
    ivCloseIcon.setId(130);
    ivCloseIcon.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams ivCloseIconIconParams = new RelativeLayout.LayoutParams(50, 50);
    ivCloseIconIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    ivCloseIconIconParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 1);
    ivCloseIcon.setPadding(0, 0, 0, 0);

    ivCloseIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            finish();

        }
    });

    ivCloseIcon.setBackgroundDrawable(getResources().getDrawable(R.drawable.close_corner));
    header.addView(ivCloseIcon, ivCloseIconIconParams);

    ivmoveforward = new ImageView(ResourcePlayer.this);
    ivmoveforward.setId(222);
    if (value == limit - 1) {
        ivmoveforward.setVisibility(View.GONE);
    }
    ivmoveforward.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams ivmoveforwardIconIconParams = new RelativeLayout.LayoutParams(21, 38);

    ivmoveforwardIconIconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, -1);
    ivmoveforwardIconIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    ivmoveforwardIconIconParams.setMargins(0, 0, 30, 0);

    imageshare = new ImageView(ResourcePlayer.this);
    imageshare.setId(440);
    imageshare.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams imageshareIconParams = new RelativeLayout.LayoutParams(50, 50);
    imageshareIconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, -1);
    imageshareIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    imageshareIconParams.setMargins(0, 10, 100, 0);
    tvDescriptionn = new TextView(ResourcePlayer.this);
    tvDescriptionn1 = new TextView(ResourcePlayer.this);
    edittext_copyurl = new EditText(ResourcePlayer.this);
    imageshare.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (desc == 0) {
                new getShortUrl().execute();

                imageshare.setBackgroundDrawable(getResources().getDrawable(R.drawable.share_selected));

                subheader.setVisibility(View.VISIBLE);
                subheader.removeAllViews();

                tvDescriptionn.setVisibility(View.VISIBLE);
                tvDescriptionn1.setVisibility(View.VISIBLE);
                edittext_copyurl.setVisibility(View.VISIBLE);
                tvDescriptionn.setText("Share this with other by copying and pasting these links");
                tvDescriptionn.setId(221);

                tvDescriptionn.setTextSize(18);
                tvDescriptionn.setTypeface(null, Typeface.BOLD);
                tvDescriptionn.setTextColor(getResources().getColor(android.R.color.white));
                RelativeLayout.LayoutParams tvDescriptionParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                tvDescriptionParams.setMargins(20, 10, 0, 20);
                subheader.addView(tvDescriptionn, tvDescriptionParams);

                tvDescriptionn1.setText("Collections");
                tvDescriptionn1.setId(226);

                tvDescriptionn1.setTextSize(18);
                tvDescriptionn1.setTypeface(null, Typeface.BOLD);
                tvDescriptionn1.setTextColor(getResources().getColor(android.R.color.white));
                RelativeLayout.LayoutParams tvDescriptionParams1 = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                tvDescriptionParams1.setMargins(20, 42, 0, 20);
                subheader.addView(tvDescriptionn1, tvDescriptionParams1);

                edittext_copyurl.setId(266);

                edittext_copyurl.setTextSize(18);
                edittext_copyurl.setTypeface(null, Typeface.BOLD);
                edittext_copyurl.setTextColor(getResources().getColor(android.R.color.white));
                RelativeLayout.LayoutParams tvDescriptionParams11 = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                tvDescriptionParams11.setMargins(130, 35, 0, 20);
                subheader.addView(edittext_copyurl, tvDescriptionParams11);
                desc = 1;
                flag = 0;

            } else {

                imageshare.setBackgroundDrawable(getResources().getDrawable(R.drawable.share_normal));
                subheader.removeAllViews();
                subheader.setVisibility(View.GONE);
                desc = 0;
            }
        }
    });

    imageshare.setBackgroundDrawable(getResources().getDrawable(R.drawable.share_normal));

    ivmoveforward.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (value < limit - 1) {
                Intent intentResPlayer = new Intent(getBaseContext(), ResourcePlayer.class);
                Bundle extras = new Bundle();
                // extras.putString("gooruOId",s);
                extras.putStringArrayList("goor", gooruOID1);
                value++;
                extras.putInt("key", value);
                intentResPlayer.putExtras(extras);
                urlcheck = 0;
                finish();
                startActivity(intentResPlayer);
            }

        }
    });

    ivmoveforward.setBackgroundDrawable(getResources().getDrawable(R.drawable.arrowright));

    ivmoveback = new ImageView(ResourcePlayer.this);
    ivmoveback.setId(220);
    if (value == 0) {
        ivmoveback.setVisibility(View.GONE);
    }
    ivmoveback.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams ivmovebackIconIconParams = new RelativeLayout.LayoutParams(21, 38);
    ivmovebackIconIconParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, -1);
    ivmovebackIconIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    ivmovebackIconIconParams.setMargins(55, 0, 0, 0);

    ivmoveback.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!(value <= 0)) {
                value--;
                Intent intentResPlayer = new Intent(getBaseContext(), ResourcePlayer.class);
                Bundle extras = new Bundle();
                extras.putStringArrayList("goor", gooruOID1);

                extras.putInt("key", value);
                intentResPlayer.putExtras(extras);
                urlcheck = 0;
                finish();
                startActivity(intentResPlayer);
            }

        }
    });

    ivmoveback.setBackgroundDrawable(getResources().getDrawable(R.drawable.left));

    webViewBack = new ImageView(ResourcePlayer.this);
    webViewBack.setId(323);
    webViewBack.setScaleType(ImageView.ScaleType.FIT_XY);

    RelativeLayout.LayoutParams webViewBackIconParams = new RelativeLayout.LayoutParams(25, 26);

    webViewBackIconParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, -1);
    webViewBackIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    webViewBackIconParams.setMargins(175, 0, 0, 0);

    webViewBack.setBackgroundDrawable(getResources().getDrawable(R.drawable.arrow_leftactive));
    webViewBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (wvPlayer.canGoBack()) {

                wvPlayer.goBack();

            }

        }
    });

    webViewRefresh = new ImageView(ResourcePlayer.this);
    webViewRefresh.setId(322);
    webViewRefresh.setScaleType(ImageView.ScaleType.FIT_XY);

    RelativeLayout.LayoutParams webViewRefreshIconParams = new RelativeLayout.LayoutParams(30, 30);

    webViewRefreshIconParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, -1);
    webViewRefreshIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    webViewRefreshIconParams.setMargins(305, 0, 0, 0);

    webViewRefresh.setBackgroundDrawable(getResources().getDrawable(R.drawable.refresh));
    webViewRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            wvPlayer.reload();
        }
    });

    webViewForward = new ImageView(ResourcePlayer.this);
    webViewForward.setId(321);
    webViewForward.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams webViewForwardIconParams = new RelativeLayout.LayoutParams(25, 26);

    webViewForwardIconParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, -1);
    webViewForwardIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    webViewForwardIconParams.setMargins(245, 0, 0, 0);
    webViewForward.setBackgroundDrawable(getResources().getDrawable(R.drawable.arrow_rightactive));
    webViewForward.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (wvPlayer.canGoForward()) {

                wvPlayer.goForward();

            }
        }
    });

    ivResourceIcon = new ImageView(ResourcePlayer.this);
    ivResourceIcon.setId(30);
    ivResourceIcon.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams ivResourceIconParams = new RelativeLayout.LayoutParams(50, 25);
    ivResourceIconParams.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    ivResourceIconParams.addRule(RelativeLayout.LEFT_OF, 130);
    ivResourceIcon.setPadding(50, 0, 0, 0);

    ivResourceIcon.setBackgroundDrawable(getResources().getDrawable(R.drawable.handouts));
    header.addView(ivResourceIcon, ivResourceIconParams);

    tvLearn = new TextView(this);
    tvLearn.setText("Learn More");
    tvLearn.setId(20);
    tvLearn.setPadding(100, 0, 0, 0);
    tvLearn.setTextSize(20);
    tvLearn.setTextColor(getResources().getColor(android.R.color.white));
    RelativeLayout.LayoutParams tvLearnParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tvLearnParams.addRule(RelativeLayout.CENTER_VERTICAL, 1);
    tvLearnParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 1);
    tvAbout = new ImageView(ResourcePlayer.this);
    tvAbout.setId(21);
    tvAbout.setScaleType(ImageView.ScaleType.FIT_XY);
    RelativeLayout.LayoutParams webViewForwardIconParamsa = new RelativeLayout.LayoutParams(32, 32);

    webViewForwardIconParamsa.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, -1);

    webViewForwardIconParamsa.addRule(RelativeLayout.CENTER_VERTICAL, -1);
    webViewForwardIconParamsa.setMargins(0, 0, 200, 0);

    tvAbout.setBackgroundDrawable(getResources().getDrawable(R.drawable.info));

    header.addView(tvAbout, webViewForwardIconParamsa);

    RelativeLayout fortvtitle = new RelativeLayout(this);
    RelativeLayout.LayoutParams tvTitleParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    tvTitleParams.addRule(RelativeLayout.CENTER_HORIZONTAL, 1);
    tvTitleParams.addRule(RelativeLayout.CENTER_VERTICAL, 1);
    tvTitleParams.addRule(RelativeLayout.RIGHT_OF, 322);
    tvTitleParams.addRule(RelativeLayout.LEFT_OF, 21);
    header.addView(fortvtitle, tvTitleParams);

    tvTitle = new TextView(this);
    tvTitle.setText("");
    tvTitle.setId(22);
    tvTitle.setPadding(0, 0, 0, 0);
    tvTitle.setTextSize(25);
    tvTitle.setSingleLine(true);
    tvTitle.setTextColor(getResources().getColor(android.R.color.white));
    RelativeLayout.LayoutParams tvTitleParamstv = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    tvTitleParamstv.addRule(RelativeLayout.CENTER_HORIZONTAL, 1);
    tvTitleParamstv.addRule(RelativeLayout.CENTER_VERTICAL, 1);

    fortvtitle.addView(tvTitle, tvTitleParamstv);

    tvViewsNLikes = new TextView(this);
    tvViewsNLikes.setText("");
    tvViewsNLikes.setId(23);
    tvViewsNLikes.setPadding(0, 0, 5, 5);
    tvViewsNLikes.setTextSize(18);
    tvViewsNLikes.setTextColor(getResources().getColor(android.R.color.white));
    RelativeLayout.LayoutParams tvViewsNLikesParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    tvViewsNLikesParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1);
    tvViewsNLikesParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);

    subheader = new RelativeLayout(ResourcePlayer.this);
    subheader.setId(100);
    subheader.setVisibility(View.GONE);
    subheader.setBackgroundDrawable(getResources().getDrawable(R.drawable.navbar));

    RelativeLayout.LayoutParams subheaderParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, 100);
    subheaderParams.addRule(RelativeLayout.BELOW, 1);
    subheaderParams.addRule(RelativeLayout.CENTER_IN_PARENT, 1);

    RelativeLayout.LayoutParams wvPlayerParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    wvPlayerParams.addRule(RelativeLayout.BELOW, 100);
    wvPlayerParams.addRule(RelativeLayout.CENTER_IN_PARENT, 100);

    LinearLayout videoLayout = new LinearLayout(this);
    videoLayout.setVisibility(View.GONE);

    header.addView(webViewBack, webViewBackIconParams);
    header.addView(webViewRefresh, webViewRefreshIconParams);
    header.addView(webViewForward, webViewForwardIconParams);
    header.addView(ivmoveforward, ivmoveforwardIconIconParams);
    header.addView(imageshare, imageshareIconParams);
    header.addView(ivmoveback, ivmovebackIconIconParams);
    temp.addView(header, headerParams);
    temp.addView(subheader, subheaderParams);
    temp.addView(wvPlayer, wvPlayerParams);
    temp.addView(videoLayout, wvPlayerParams);

    setContentViewLayout.addView(temp, layoutParams);

    setContentView(setContentViewLayout);
    tvDescription = new TextView(ResourcePlayer.this);
    tvDescription1 = new TextView(ResourcePlayer.this);
    tvAbout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (flag == 0) {
                subheader.setVisibility(View.VISIBLE);
                subheader.removeAllViews();
                // tvDescriptionn.setVisibility(View.INVISIBLE);
                tvDescription1.setVisibility(View.VISIBLE);
                tvDescription.setVisibility(View.VISIBLE);

                tvDescription.setText("Description");
                tvDescription.setId(221);

                tvDescription.setTextSize(18);
                tvDescription.setTypeface(null, Typeface.BOLD);
                tvDescription.setTextColor(getResources().getColor(android.R.color.white));
                RelativeLayout.LayoutParams tvDescriptionParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                tvDescriptionParams.setMargins(20, 10, 0, 20);
                tvDescriptionParams.addRule(RelativeLayout.BELOW, 220);

                tvDescription1.setText(description);
                tvDescription1.setLines(3);
                tvDescription1.setId(321);

                tvDescription1.setTextSize(15);
                tvDescription1.setTextColor(getResources().getColor(android.R.color.white));
                RelativeLayout.LayoutParams tvDescription1Params = new RelativeLayout.LayoutParams(1100, 100);
                tvDescription1Params.addRule(RelativeLayout.CENTER_IN_PARENT, -1);
                tvDescription1.setPadding(100, 20, 100, 0);
                subheader.addView(tvDescription1, tvDescription1Params);
                desc = 0;
                flag = 1;
                flag1 = 0;

            } else {
                subheader.removeAllViews();
                subheader.setVisibility(View.GONE);

                flag = 0;
            }
        }
    });

}

From source file:cz.suhail.Rainyday.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Rainyday");
    final WebView webView = new WebView(this);
    String about = "<p>A lightweight, opensource weather app.</p>"
            + "<p>Developed by <a href='https://www.suhailpurkar.io/'>Suhail Purkar</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();//from  w w  w  .jav a  2  s. c om
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:weathernotificationservice.wns.activities.MainActivity.java

private void aboutDialog() {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Weather Pop");
    final WebView webView = new WebView(this);
    String about = "<p>A weather app, created for you, that provides the functionality of secure mobile notifications connecting you with your family and friends at the touch of your fingertips.</p>"
            + "<p>Based on Forecatie developed by <a href='mailto:t.martykan@gmail.com'>Tomas Martykan</a></p>"
            + "<p>Data provided by <a href='http://openweathermap.org/'>OpenWeatherMap</a>, under the <a href='http://creativecommons.org/licenses/by-sa/2.0/'>Creative Commons license</a>"
            + "<p>Icons are <a href='https://erikflowers.github.io/weather-icons/'>Weather Icons</a>, by <a href='http://www.twitter.com/artill'>Lukas Bischoff</a> and <a href='http://www.twitter.com/Erik_UX'>Erik Flowers</a>, under the <a href='http://scripts.sil.org/OFL'>SIL OFL 1.1</a> licence.";
    ;/*from   w w  w  .  j a  va 2  s.  com*/
    TypedArray ta = obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary, R.attr.colorAccent });
    String textColor = String.format("#%06X", (0xFFFFFF & ta.getColor(0, Color.BLACK)));
    String accentColor = String.format("#%06X", (0xFFFFFF & ta.getColor(1, Color.BLUE)));
    ta.recycle();
    about = "<style media=\"screen\" type=\"text/css\">" + "body {\n" + "    color:" + textColor + ";\n" + "}\n"
            + "a:link {color:" + accentColor + "}\n" + "</style>" + about;
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.loadData(about, "text/html", "UTF-8");
    alert.setView(webView, 32, 0, 32, 0);
    alert.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });
    alert.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

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

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;//  w  w  w .jav a  2 s  . c  o  m

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}