PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/CircleIME/src/com/marvin/circleime/LatinKeyboard.java

http://eyes-free.googlecode.com/
Java | 101 lines | 65 code | 13 blank | 23 comment | 6 complexity | cafb5a8bdc7a524c41aa75540199d6d7 MD5 | raw file
  1/*
  2 * Copyright (C) 2008-2009 Google Inc.
  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.marvin.circleime;
 18
 19import android.content.Context;
 20import android.content.res.Resources;
 21import android.content.res.XmlResourceParser;
 22import android.inputmethodservice.Keyboard;
 23import android.inputmethodservice.Keyboard.Key;
 24import android.inputmethodservice.Keyboard.Row;
 25import android.view.inputmethod.EditorInfo;
 26
 27public class LatinKeyboard extends Keyboard {
 28
 29    private Key mEnterKey;
 30
 31    public LatinKeyboard(Context context, int xmlLayoutResId) {
 32        super(context, xmlLayoutResId);
 33    }
 34
 35    public LatinKeyboard(Context context, int layoutTemplateResId, CharSequence characters,
 36            int columns, int horizontalPadding) {
 37        super(context, layoutTemplateResId, characters, columns, horizontalPadding);
 38    }
 39
 40    @Override
 41    protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
 42        Key key = new LatinKey(res, parent, x, y, parser);
 43        if (key.codes[0] == 10) {
 44            mEnterKey = key;
 45        }
 46        return key;
 47    }
 48
 49    /**
 50     * This looks at the ime options given by the current editor, to set the
 51     * appropriate label on the keyboard's enter key (if it has one).
 52     */
 53    void setImeOptions(Resources res, int options) {
 54        if (mEnterKey == null) {
 55            return;
 56        }
 57
 58        switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
 59            case EditorInfo.IME_ACTION_GO:
 60                mEnterKey.iconPreview = null;
 61                mEnterKey.icon = null;
 62                mEnterKey.label = res.getText(R.string.label_go_key);
 63                break;
 64            case EditorInfo.IME_ACTION_NEXT:
 65                mEnterKey.iconPreview = null;
 66                mEnterKey.icon = null;
 67                mEnterKey.label = res.getText(R.string.label_next_key);
 68                break;
 69            case EditorInfo.IME_ACTION_SEARCH:
 70                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
 71                mEnterKey.label = null;
 72                break;
 73            case EditorInfo.IME_ACTION_SEND:
 74                mEnterKey.iconPreview = null;
 75                mEnterKey.icon = null;
 76                mEnterKey.label = res.getText(R.string.label_send_key);
 77                break;
 78            default:
 79                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
 80                mEnterKey.label = null;
 81                break;
 82        }
 83    }
 84
 85    static class LatinKey extends Keyboard.Key {
 86
 87        public LatinKey(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser) {
 88            super(res, parent, x, y, parser);
 89        }
 90
 91        /**
 92         * Overriding this method so that we can reduce the target area for the
 93         * key that closes the keyboard.
 94         */
 95        @Override
 96        public boolean isInside(int x, int y) {
 97            return super.isInside(x, codes[0] == KEYCODE_CANCEL ? y - 10 : y);
 98        }
 99    }
100
101}