• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.browser.preferences;
18 
19 import android.content.Context;
20 import android.text.TextUtils;
21 import android.util.AttributeSet;
22 import android.webkit.WebSettings;
23 
24 import com.android.browser.BrowserSettings;
25 import com.android.browser.WebViewProperties;
26 
27 public class InvertedContrastPreview extends WebViewPreview {
28 
29     static final String IMG_ROOT = "content://com.android.browser.home/res/raw/";
30     static final String[] THUMBS = new String[] {
31         "thumb_google",
32         "thumb_amazon",
33         "thumb_cnn",
34         "thumb_espn",
35         "", // break
36         "thumb_bbc",
37         "thumb_nytimes",
38         "thumb_weatherchannel",
39         "thumb_picasa",
40     };
41 
42     String mHtml;
43 
InvertedContrastPreview( Context context, AttributeSet attrs, int defStyle)44     public InvertedContrastPreview(
45             Context context, AttributeSet attrs, int defStyle) {
46         super(context, attrs, defStyle);
47     }
48 
InvertedContrastPreview(Context context, AttributeSet attrs)49     public InvertedContrastPreview(Context context, AttributeSet attrs) {
50         super(context, attrs);
51     }
52 
InvertedContrastPreview(Context context)53     public InvertedContrastPreview(Context context) {
54         super(context);
55     }
56 
57     @Override
init(Context context)58     protected void init(Context context) {
59         super.init(context);
60         StringBuilder builder = new StringBuilder("<html><body style=\"width: 1000px\">");
61         for (String thumb : THUMBS) {
62             if (TextUtils.isEmpty(thumb)) {
63                 builder.append("<br />");
64                 continue;
65             }
66             builder.append("<img src=\"");
67             builder.append(IMG_ROOT);
68             builder.append(thumb);
69             builder.append("\" />&nbsp;");
70         }
71         builder.append("</body></html>");
72         mHtml = builder.toString();
73     }
74 
75     @Override
updatePreview()76     protected void updatePreview() {
77         if (mWebView == null) return;
78 
79         WebSettings ws = mWebView.getSettings();
80         BrowserSettings bs = BrowserSettings.getInstance();
81         ws.setProperty(WebViewProperties.gfxInvertedScreen,
82                 bs.useInvertedRendering() ? "true" : "false");
83         ws.setProperty(WebViewProperties.gfxInvertedScreenContrast,
84                 Float.toString(bs.getInvertedContrast()));
85         mWebView.loadData(mHtml, "text/html", "utf-8");
86     }
87 
88 }
89