Example usage for android.webkit WebView setBackgroundColor

List of usage examples for android.webkit WebView setBackgroundColor

Introduction

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

Prototype

@Override
    public void setBackgroundColor(int color) 

Source Link

Usage

From source file:org.ciasaboark.tacere.activity.AboutLicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_about_activity_license);
    // Show the Up button in the action bar.
    setupActionBar();//from  www  .  j a v a2s  .  co m

    WebView wv = (WebView) findViewById(R.id.webView1);

    String htmlData = "";
    try {
        BufferedReader br = new BufferedReader(new InputStreamReader(getAssets().open("license.html")));

        String line;
        while ((line = br.readLine()) != null) {
            htmlData += line;
        }
    } catch (FileNotFoundException e) {
        Log.e(TAG, e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    }

    int colorInt = getResources().getColor(R.color.link_color);
    String hexColor = String.format("#%06X", (0xFFFFFF & colorInt));
    while (htmlData.contains("LINKCOLOR")) {
        htmlData = htmlData.replace("LINKCOLOR", hexColor);
    }

    wv.loadData(htmlData, "text/html", "UTF8");

    // All links should open in the default browser, not this WebView
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        }
    });

    wv.setBackgroundColor(0x00000000);
    wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
}

From source file:org.ciasaboark.tacere.activity.fragment.AboutLicenseFragment.java

private void initViews() {
    // Show the Up button in the action bar.
    //        setupActionBar();

    WebView wv = (WebView) rootView.findViewById(R.id.webView1);

    String htmlData = "";
    try {/*www . j a  va 2  s .  c om*/
        BufferedReader br = new BufferedReader(new InputStreamReader(context.getAssets().open("license.html")));

        String line;
        while ((line = br.readLine()) != null) {
            htmlData += line;
        }
    } catch (FileNotFoundException e) {
        Log.e(TAG, e.getMessage());
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    }

    int colorInt = getResources().getColor(R.color.link_color);
    String hexColor = String.format("#%06X", (0xFFFFFF & colorInt));
    while (htmlData.contains("LINKCOLOR")) {
        htmlData = htmlData.replace("LINKCOLOR", hexColor);
    }

    wv.loadData(htmlData, "text/html", "UTF8");

    // All links should open in the default browser, not this WebView
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;
        }
    });

    wv.setBackgroundColor(0x00000000);
    wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
}

From source file:info.staticfree.android.units.Units.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ABOUT: {
        final Builder builder = new AlertDialog.Builder(this);

        builder.setTitle(R.string.dialog_about_title);
        builder.setIcon(R.drawable.icon);

        try {//from  w  w w.j a  va  2  s  .c o m
            final WebView wv = new WebView(this);
            final InputStream is = getAssets().open("README.xhtml");
            wv.loadDataWithBaseURL("file:///android_asset/", inputStreamToString(is), "application/xhtml+xml",
                    "utf-8", null);
            wv.setBackgroundColor(0);
            builder.setView(wv);
        } catch (final IOException e) {
            builder.setMessage(R.string.err_no_load_about);
            e.printStackTrace();
        }

        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                setResult(RESULT_OK);
            }
        });
        return builder.create();
    }

    case DIALOG_ALL_UNITS: {
        final Builder b = new Builder(Units.this);
        b.setTitle(R.string.dialog_all_units_title);
        final ExpandableListView unitExpandList = new ExpandableListView(Units.this);
        unitExpandList.setId(android.R.id.list);
        final String[] groupProjection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        // any selection below will select from the grouping description
        final Cursor cursor = managedQuery(UsageEntry.CONTENT_URI_CONFORM_TOP, groupProjection, null, null,
                UnitUsageDBHelper.USAGE_SORT);

        unitExpandList.setAdapter(new UnitsExpandableListAdapter(cursor, this,
                android.R.layout.simple_expandable_list_item_1, android.R.layout.simple_expandable_list_item_1,
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 },
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 }));
        unitExpandList.setCacheColorHint(0);
        unitExpandList.setOnChildClickListener(allUnitChildClickListener);
        b.setView(unitExpandList);
        return b.create();
    }

    case DIALOG_UNIT_CATEGORY: {
        final Builder b = new Builder(new ContextThemeWrapper(this, android.R.style.Theme_Black));
        final String[] from = { UsageEntry._UNIT };
        final int[] to = { android.R.id.text1 };
        b.setTitle("all units");
        final String[] projection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        final Cursor c = managedQuery(UsageEntry.CONTENT_URI, projection, null, null,
                UnitUsageDBHelper.USAGE_SORT);
        dialogUnitCategoryList = new SimpleCursorAdapter(this, android.R.layout.select_dialog_item, c, from,
                to);
        b.setAdapter(dialogUnitCategoryList, dialogUnitCategoryOnClickListener);

        return b.create();
    }

    case DIALOG_LOADING_UNITS: {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setIndeterminate(true);
        pd.setTitle(R.string.app_name);
        pd.setMessage(getText(R.string.dialog_loading_units));
        return pd;
    }

    default:
        throw new IllegalArgumentException("Unknown dialog ID:" + id);
    }
}

From source file:com.androzic.waypoint.WaypointInfo.java

@SuppressLint("NewApi")
private void updateWaypointInfo(double lat, double lon) {
    Androzic application = Androzic.getApplication();
    Activity activity = getActivity();//from w w w  . j a  v  a  2 s  . com
    Dialog dialog = getDialog();
    View view = getView();

    WebView description = (WebView) view.findViewById(R.id.description);

    if ("".equals(waypoint.description)) {
        description.setVisibility(View.GONE);
    } else {
        String descriptionHtml;
        try {
            TypedValue tv = new TypedValue();
            Theme theme = activity.getTheme();
            Resources resources = getResources();
            theme.resolveAttribute(android.R.attr.textColorSecondary, tv, true);
            int secondaryColor = resources.getColor(tv.resourceId);
            String css = String.format(
                    "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n",
                    (secondaryColor & 0x00FFFFFF));
            descriptionHtml = css + waypoint.description;
            description.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    view.setBackgroundColor(Color.TRANSPARENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
                }
            });
            description.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        } catch (Resources.NotFoundException e) {
            description.setBackgroundColor(Color.LTGRAY);
            descriptionHtml = waypoint.description;
        }

        WebSettings settings = description.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        settings.setAllowFileAccess(true);
        Uri baseUrl = Uri.fromFile(new File(application.dataPath));
        description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null);
    }

    String coords = StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude);
    ((TextView) view.findViewById(R.id.coordinates)).setText(coords);

    if (waypoint.altitude != Integer.MIN_VALUE) {
        ((TextView) view.findViewById(R.id.altitude)).setText(StringFormatter.elevationH(waypoint.altitude));
    }

    double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude);
    double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude);
    bearing = application.fixDeclination(bearing);
    String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    if (waypoint.date != null)
        ((TextView) view.findViewById(R.id.date))
                .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " "
                        + DateFormat.getTimeFormat(activity).format(waypoint.date));
    else
        ((TextView) view.findViewById(R.id.date)).setVisibility(View.GONE);

    dialog.setTitle(waypoint.name);
}

From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java

private void setWebView(final GalleryItemViewTag tag, final File file) {
    runOnUiThread(new Runnable() {
        private boolean oomFlag = false;

        private final ViewGroup.LayoutParams MATCH_PARAMS = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        private void prepareWebView(WebView webView) {
            webView.setBackgroundColor(Color.TRANSPARENT);
            webView.setInitialScale(100);
            webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
                CompatibilityImpl.setScrollbarFadingEnabled(webView, true);
            }// w ww.j  a v  a2  s  .c  o m

            WebSettings settings = webView.getSettings();
            settings.setBuiltInZoomControls(true);
            settings.setSupportZoom(true);
            settings.setAllowFileAccess(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
                CompatibilityImpl.setDefaultZoomFAR(settings);
                CompatibilityImpl.setLoadWithOverviewMode(settings, true);
            }
            settings.setUseWideViewPort(true);
            settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
                CompatibilityImpl.setBlockNetworkLoads(settings, true);
            }

            setScaleWebView(webView);
        }

        private void setScaleWebView(final WebView webView) {
            Runnable callSetScaleWebView = new Runnable() {
                @Override
                public void run() {
                    setPrivateScaleWebView(webView);
                }
            };

            Point resolution = new Point(tag.layout.getWidth(), tag.layout.getHeight());
            if (resolution.equals(0, 0)) {
                // wait until the view is measured and its size is known
                AppearanceUtils.callWhenLoaded(tag.layout, callSetScaleWebView);
            } else {
                callSetScaleWebView.run();
            }
        }

        private void setPrivateScaleWebView(WebView webView) {
            Point imageSize = getImageSize(file);
            Point resolution = new Point(tag.layout.getWidth(), tag.layout.getHeight());

            //Logger.d(TAG, "Resolution: "+resolution.x+"x"+resolution.y);
            double scaleX = (double) resolution.x / (double) imageSize.x;
            double scaleY = (double) resolution.y / (double) imageSize.y;
            int scale = (int) Math.round(Math.min(scaleX, scaleY) * 100d);
            scale = Math.max(scale, 1);
            //Logger.d(TAG, "Scale: "+(Math.min(scaleX, scaleY) * 100d));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
                double picdpi = (getResources().getDisplayMetrics().density * 160d) / scaleX;
                if (picdpi >= 240) {
                    CompatibilityImpl.setDefaultZoomFAR(webView.getSettings());
                } else if (picdpi <= 120) {
                    CompatibilityImpl.setDefaultZoomCLOSE(webView.getSettings());
                } else {
                    CompatibilityImpl.setDefaultZoomMEDIUM(webView.getSettings());
                }
            }

            webView.setInitialScale(scale);
            webView.setPadding(0, 0, 0, 0);
        }

        private Point getImageSize(File file) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(file.getAbsolutePath(), options);
            return new Point(options.outWidth, options.outHeight);
        }

        private boolean useFallback(File file) {
            String path = file.getPath().toLowerCase(Locale.US);
            if (path.endsWith(".png"))
                return false;
            if (path.endsWith(".jpg"))
                return false;
            if (path.endsWith(".gif"))
                return false;
            if (path.endsWith(".jpeg"))
                return false;
            if (path.endsWith(".webp") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                return false;
            return true;
        }

        @Override
        public void run() {
            try {
                recycleTag(tag, false);
                WebView webView = new WebViewFixed(GalleryActivity.this);
                webView.setLayoutParams(MATCH_PARAMS);
                tag.layout.addView(webView);
                if (settings.fallbackWebView() || useFallback(file)) {
                    prepareWebView(webView);
                    webView.loadUrl(Uri.fromFile(file).toString());
                } else {
                    JSWebView.setImage(webView, file);
                }
                tag.thumbnailView.setVisibility(View.GONE);
                tag.loadingView.setVisibility(View.GONE);
                tag.layout.setVisibility(View.VISIBLE);
            } catch (OutOfMemoryError oom) {
                System.gc();
                Logger.e(TAG, oom);
                if (!oomFlag) {
                    oomFlag = true;
                    run();
                } else
                    showError(tag, getString(R.string.error_out_of_memory));
            }
        }

    });
}

From source file:com.androzic.waypoint.WaypointDetails.java

@SuppressLint("NewApi")
private void updateWaypointDetails(double lat, double lon) {
    Androzic application = Androzic.getApplication();
    AppCompatActivity activity = (AppCompatActivity) getActivity();

    activity.getSupportActionBar().setTitle(waypoint.name);

    View view = getView();/* w  w w  .j  av  a 2s .  co m*/

    final TextView coordsView = (TextView) view.findViewById(R.id.coordinates);
    coordsView.requestFocus();
    coordsView.setTag(Integer.valueOf(StringFormatter.coordinateFormat));
    coordsView.setText(StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude));
    coordsView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int format = ((Integer) coordsView.getTag()).intValue() + 1;
            if (format == 5)
                format = 0;
            coordsView.setText(StringFormatter.coordinates(format, " ", waypoint.latitude, waypoint.longitude));
            coordsView.setTag(Integer.valueOf(format));
        }
    });

    if (waypoint.altitude != Integer.MIN_VALUE) {
        ((TextView) view.findViewById(R.id.altitude))
                .setText("\u2336 " + StringFormatter.elevationH(waypoint.altitude));
        view.findViewById(R.id.altitude).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.altitude).setVisibility(View.GONE);
    }

    if (waypoint.proximity > 0) {
        ((TextView) view.findViewById(R.id.proximity))
                .setText("~ " + StringFormatter.distanceH(waypoint.proximity));
        view.findViewById(R.id.proximity).setVisibility(View.VISIBLE);
    } else {
        view.findViewById(R.id.proximity).setVisibility(View.GONE);
    }

    double dist = Geo.distance(lat, lon, waypoint.latitude, waypoint.longitude);
    double bearing = Geo.bearing(lat, lon, waypoint.latitude, waypoint.longitude);
    bearing = application.fixDeclination(bearing);
    String distance = StringFormatter.distanceH(dist) + " " + StringFormatter.angleH(bearing);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    ((TextView) view.findViewById(R.id.waypointset)).setText(waypoint.set.name);

    if (waypoint.date != null) {
        view.findViewById(R.id.date_row).setVisibility(View.VISIBLE);
        ((TextView) view.findViewById(R.id.date))
                .setText(DateFormat.getDateFormat(activity).format(waypoint.date) + " "
                        + DateFormat.getTimeFormat(activity).format(waypoint.date));
    } else {
        view.findViewById(R.id.date_row).setVisibility(View.GONE);
    }

    if ("".equals(waypoint.description)) {
        view.findViewById(R.id.description_row).setVisibility(View.GONE);
    } else {
        WebView description = (WebView) view.findViewById(R.id.description);
        String descriptionHtml;
        try {
            TypedValue tv = new TypedValue();
            Theme theme = activity.getTheme();
            Resources resources = getResources();
            theme.resolveAttribute(android.R.attr.textColorPrimary, tv, true);
            int secondaryColor = resources.getColor(tv.resourceId);
            String css = String.format(
                    "<style type=\"text/css\">html,body{margin:0;background:transparent} *{color:#%06X}</style>\n",
                    (secondaryColor & 0x00FFFFFF));
            descriptionHtml = css + waypoint.description;
            description.setWebViewClient(new WebViewClient() {
                @SuppressLint("NewApi")
                @Override
                public void onPageFinished(WebView view, String url) {
                    view.setBackgroundColor(Color.TRANSPARENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                        view.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
                }
            });
            description.setBackgroundColor(Color.TRANSPARENT);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
                description.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
        } catch (Resources.NotFoundException e) {
            description.setBackgroundColor(Color.LTGRAY);
            descriptionHtml = waypoint.description;
        }

        WebSettings settings = description.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        settings.setAllowFileAccess(true);
        Uri baseUrl = Uri.fromFile(new File(application.dataPath));
        description.loadDataWithBaseURL(baseUrl.toString() + "/", descriptionHtml, "text/html", "utf-8", null);
        view.findViewById(R.id.description_row).setVisibility(View.VISIBLE);
    }
}

From source file:nya.miku.wishmaster.ui.GalleryActivity.java

private void setWebView(final GalleryItemViewTag tag, final File file) {
    runOnUiThread(new Runnable() {
        private boolean oomFlag = false;

        private final ViewGroup.LayoutParams MATCH_PARAMS = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        private void prepareWebView(WebView webView) {
            webView.setBackgroundColor(Color.TRANSPARENT);
            webView.setInitialScale(100);
            webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
                CompatibilityImpl.setScrollbarFadingEnabled(webView, true);
            }/*from  w  w w .j a va 2s .  co m*/

            WebSettings settings = webView.getSettings();
            settings.setBuiltInZoomControls(true);
            settings.setSupportZoom(true);
            settings.setAllowFileAccess(true);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
                CompatibilityImpl.setDefaultZoomFAR(settings);
                CompatibilityImpl.setLoadWithOverviewMode(settings, true);
            }
            settings.setUseWideViewPort(true);
            settings.setCacheMode(WebSettings.LOAD_NO_CACHE);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
                CompatibilityImpl.setBlockNetworkLoads(settings, true);
            }

            setScaleWebView(webView);
        }

        private void setScaleWebView(final WebView webView) {
            Runnable callSetScaleWebView = new Runnable() {
                @Override
                public void run() {
                    setPrivateScaleWebView(webView);
                }
            };

            Point resolution = new Point(tag.layout.getWidth(), tag.layout.getHeight());
            if (resolution.equals(0, 0)) {
                // wait until the view is measured and its size is known
                AppearanceUtils.callWhenLoaded(tag.layout, callSetScaleWebView);
            } else {
                callSetScaleWebView.run();
            }
        }

        private void setPrivateScaleWebView(WebView webView) {
            Point imageSize = getImageSize(file);
            Point resolution = new Point(tag.layout.getWidth(), tag.layout.getHeight());

            //Logger.d(TAG, "Resolution: "+resolution.x+"x"+resolution.y);
            double scaleX = (double) resolution.x / (double) imageSize.x;
            double scaleY = (double) resolution.y / (double) imageSize.y;
            int scale = (int) Math.round(Math.min(scaleX, scaleY) * 100d);
            scale = Math.max(scale, 1);
            //Logger.d(TAG, "Scale: "+(Math.min(scaleX, scaleY) * 100d));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
                double picdpi = (getResources().getDisplayMetrics().density * 160d) / scaleX;
                if (picdpi >= 240) {
                    CompatibilityImpl.setDefaultZoomFAR(webView.getSettings());
                } else if (picdpi <= 120) {
                    CompatibilityImpl.setDefaultZoomCLOSE(webView.getSettings());
                } else {
                    CompatibilityImpl.setDefaultZoomMEDIUM(webView.getSettings());
                }
            }

            webView.setInitialScale(scale);
            webView.setPadding(0, 0, 0, 0);
        }

        private Point getImageSize(File file) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(file.getAbsolutePath(), options);
            return new Point(options.outWidth, options.outHeight);
        }

        private boolean useFallback(File file) {
            String path = file.getPath().toLowerCase(Locale.US);
            if (path.endsWith(".png"))
                return false;
            if (path.endsWith(".jpg"))
                return false;
            if (path.endsWith(".gif"))
                return false;
            if (path.endsWith(".jpeg"))
                return false;
            if (path.endsWith(".webp") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
                return false;
            return true;
        }

        @Override
        public void run() {
            try {
                recycleTag(tag, false);
                WebView webView = new WebViewFixed(GalleryActivity.this);
                webView.setLayoutParams(MATCH_PARAMS);
                tag.layout.addView(webView);
                if (settings.fallbackWebView() || useFallback(file)) {
                    prepareWebView(webView);
                    webView.loadUrl(Uri.fromFile(file).toString());
                } else {
                    JSWebView.setImage(webView, file);
                }
                tag.thumbnailView.setVisibility(View.GONE);
                tag.loadingView.setVisibility(View.GONE);
                tag.layout.setVisibility(View.VISIBLE);
            } catch (OutOfMemoryError oom) {
                MainApplication.freeMemory();
                Logger.e(TAG, oom);
                if (!oomFlag) {
                    oomFlag = true;
                    run();
                } else
                    showError(tag, getString(R.string.error_out_of_memory));
            }
        }

    });
}

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.answer);//from   w ww .ja v  a  2  s  . co m

    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:cz.suhail.rainyday.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.";
    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  ww w  . j a v  a 2  s.c  o 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:cz.martykan.forecastie.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.";
    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 w w w .j  av a2  s . c  o 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();
}