PageRenderTime 133ms CodeModel.GetById 81ms app.highlight 7ms RepoModel.GetById 43ms app.codeStats 1ms

/kakeyboard/src/org/herrlado/android/kakeyboard/LatinKeyboard.java

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