PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/TalkBack/src/com/google/android/marvin/talkback/speechrules/RuleSeekBar.java

http://eyes-free.googlecode.com/
Java | 58 lines | 28 code | 10 blank | 20 comment | 3 complexity | 9339abca001dca1ad286fed99f65b075 MD5 | raw file
 1/*
 2 * Copyright (C) 2011 The Android Open Source Project
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17package com.google.android.marvin.talkback.speechrules;
18
19import android.content.Context;
20import android.view.accessibility.AccessibilityEvent;
21import android.view.accessibility.AccessibilityNodeInfo;
22
23import com.google.android.marvin.talkback.AccessibilityNodeInfoUtils;
24import com.google.android.marvin.talkback.R;
25
26/**
27 * Formats speech for SeekBar widgets.
28 * 
29 * @author alanv@google.com (Alan Viverette)
30 */
31public class RuleSeekBar extends RuleDefault {
32    private static final String SEPARATOR = " ";
33
34    @Override
35    public boolean accept(AccessibilityNodeInfo node) {
36        return AccessibilityNodeInfoUtils
37                .nodeMatchesClassByType(node, android.widget.SeekBar.class);
38    }
39
40    @Override
41    public CharSequence
42            format(Context context, AccessibilityNodeInfo node, AccessibilityEvent event) {
43        final StringBuilder output = new StringBuilder();
44        final CharSequence text = super.format(context, node, event);
45
46        output.append(context.getString(R.string.template_seek_bar, text));
47        output.append(SEPARATOR);
48
49        if ((event != null) && (event.getItemCount() > 0)) {
50            final int percent = (100 * event.getCurrentItemIndex()) / event.getItemCount();
51
52            output.append(context.getString(R.string.template_percent, percent));
53            output.append(SEPARATOR);
54        }
55
56        return output;
57    }
58}