PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/talkback_preics/src/com/google/android/marvin/talkback/formatter/TalkBackWebContentHandler.java

http://eyes-free.googlecode.com/
Java | 42 lines | 25 code | 6 blank | 11 comment | 1 complexity | 72c2cee44d1a244631b022b8f7fd3d76 MD5 | raw file
 1// Copyright 2010 Google Inc. All Rights Reserved.
 2
 3package com.google.android.marvin.talkback.formatter;
 4
 5import com.google.android.marvin.talkback.R;
 6import android.content.res.Resources;
 7
 8import java.util.HashMap;
 9
10/**
11 * A wrapper for WebContentHandler containing Android-specific code for loading
12 * tag descriptions from resources.
13 *
14 * @author credo@google.com (Tim Credo)
15 */
16public class TalkBackWebContentHandler extends WebContentHandler {
17
18    public TalkBackWebContentHandler(Resources res) {
19        super(loadMapFromStringArrays(
20                res, R.array.html_input_to_desc_keys, R.array.html_input_to_desc_values),
21                loadMapFromStringArrays(
22                        res, R.array.html_role_to_desc_keys, R.array.html_role_to_desc_values),
23                loadMapFromStringArrays(
24                        res, R.array.html_tag_to_desc_keys, R.array.html_tag_to_desc_values));
25    }
26
27    /**
28     * Load a HashMap from resources. Keys and values are provided as two string
29     * arrays.
30     */
31    private static HashMap<String, String> loadMapFromStringArrays(
32            Resources res, int keysResource, int valuesResource) {
33        String[] keys = res.getStringArray(keysResource);
34        String[] values = res.getStringArray(valuesResource);
35        int maxIndex = Math.min(keys.length, values.length);
36        HashMap<String, String> map = new HashMap<String, String>();
37        for (int i = 0; i < maxIndex; i++) {
38            map.put(keys[i], values[i]);
39        }
40        return map;
41    }
42}