Home | History | Annotate | Download | only in preferences
      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.content.res.Resources;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.webkit.WebSettings;
     24 import android.webkit.WebView;
     25 
     26 import com.android.browser.BrowserSettings;
     27 import com.android.browser.R;
     28 
     29 public class FontSizePreview extends WebViewPreview {
     30 
     31     static final String HTML_FORMAT = "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><style type=\"text/css\">p { margin: 2px auto;}</style><body><p style=\"font-size: 4pt\">%s</p><p style=\"font-size: 8pt\">%s</p><p style=\"font-size: 10pt\">%s</p><p style=\"font-size: 14pt\">%s</p><p style=\"font-size: 18pt\">%s</p></body></html>";
     32 
     33     String mHtml;
     34 
     35     public FontSizePreview(
     36             Context context, AttributeSet attrs, int defStyle) {
     37         super(context, attrs, defStyle);
     38     }
     39 
     40     public FontSizePreview(Context context, AttributeSet attrs) {
     41         super(context, attrs);
     42     }
     43 
     44     public FontSizePreview(Context context) {
     45         super(context);
     46     }
     47 
     48     @Override
     49     protected void init(Context context) {
     50         super.init(context);
     51         Resources res = context.getResources();
     52         Object[] visualNames = res.getStringArray(R.array.pref_text_size_choices);
     53         mHtml = String.format(HTML_FORMAT, visualNames);
     54     }
     55 
     56     @Override
     57     protected void updatePreview(boolean forceReload) {
     58         if (mWebView == null) return;
     59 
     60         WebSettings ws = mWebView.getSettings();
     61         BrowserSettings bs = BrowserSettings.getInstance();
     62         ws.setMinimumFontSize(bs.getMinimumFontSize());
     63         ws.setTextZoom(bs.getTextZoom());
     64         mWebView.loadDataWithBaseURL(null, mHtml, "text/html", "utf-8", null);
     65     }
     66 
     67     @Override
     68     protected void setupWebView(WebView view) {
     69         super.setupWebView(view);
     70         view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
     71     }
     72 
     73 }
     74