編輯:Android開發實例
我在網上看了很多篇這個程序的解析,感覺都不錯但是不夠詳細,於是我自己費了幾天的時間解讀了一遍,注釋上去。今天寫在這裡,占個空,此外怕那天丟了還有個備份,如果能對和我一樣的菜鳥們有點幫助最好。
1.LatinKeyBoard.java
- /*
- * Copyright (C) 2008-2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
- package com.example.android.softkeyboard;
- import android.content.Context;
- import android.content.res.Resources;
- import android.content.res.XmlResourceParser;
- import android.inputmethodservice.Keyboard;
- import android.inputmethodservice.Keyboard.Key;
- import android.inputmethodservice.Keyboard.Row;
- import android.view.inputmethod.EditorInfo;
- public class LatinKeyboard extends Keyboard {
- private Key mEnterKey;
- public LatinKeyboard(Context context, int xmlLayoutResId) {
- super(context, xmlLayoutResId);
- }
- public LatinKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
- super(context, layoutTemplateResId, characters, columns, horizontalPadding);
- }
- @Override
- protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
- //描繪鍵盤時候自動調用??是不是在此類的構造函數中就使用了?肯定是自己的函數調用這個函數。
- Key key = new LatinKey(res, parent, x, y, parser);
- if (key.codes[0] == 10) { //重載的目的,好像僅僅是為了記錄回車鍵的值而已(以Key型記錄)然後下一個函數要用到
- mEnterKey = key; //無非就是想對回車鍵做改觀
- }
- return key;
- }
- /**
- * This looks at the ime options given by the current editor, to set the
- * appropriate label on the keyboard's enter key (if it has one).
- */
- void setImeOptions(Resources res, int options) {
- //在SoftKeyboard的StartInput函數最後用到了
- //傳入了EditorInfo.imeOptions類型的options參數。此變量地位與EditorInfo.inputType類似。但作用截然不同
- if (mEnterKey == null) {
- return;
- }
- //驚爆:只要加載了EditorInfo的包,就可以使用其中的常量,所熟知的TextView類中的常量,經過試驗也是可以任意使用的,猜測這些都是靜態變量
- switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
- //難道後面兩個或的天生就是為了聯接在一起跟別人與?
- case EditorInfo.IME_ACTION_GO:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null; //把圖片設為空,並不代表就是空,只是下面的Lable可以代替之
- mEnterKey.label = res.getText(R.string.label_go_key);
- break;
- case EditorInfo.IME_ACTION_NEXT:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_next_key);
- break;
- case EditorInfo.IME_ACTION_SEARCH:
- mEnterKey.icon = res.getDrawable(
- R.drawable.sym_keyboard_search);
- mEnterKey.label = null;
- break;
- case EditorInfo.IME_ACTION_SEND:
- mEnterKey.iconPreview = null;
- mEnterKey.icon = null;
- mEnterKey.label = res.getText(R.string.label_send_key);
- break;
- default:
- mEnterKey.icon = res.getDrawable(
- R.drawable.sym_keyboard_return);
- mEnterKey.label = null;
- break;
- }
- }
- static class LatinKey extends Keyboard.Key {
- public LatinKey(Resources res, Keyboard.Row parent, int x, int y, XmlResourceParser parser) {
- super(res, parent, x, y, parser);//用的是老一輩的構造函數
- }
- /**
- * Overriding this method so that we can reduce the target area for the key that
- * closes the keyboard.
- */
- @Override
- public boolean isInside(int x, int y) {
- return super.isInside(x, codes[0] == KEYCODE_CANCEL ? y -10: y);
- //只有一個左下角cancel鍵跟super的此函數不一樣,其余相同
- //僅僅為了防止錯誤的點擊?將cancel鍵的作用范圍減小了10,其余的,如果作用到位,都返回true
- }
- }
- }
首先來看一下使用Java語言編寫的Android應用程序從源碼到安裝包的整個過程,示意圖如下,其中包含編譯、鏈接和簽名等: (1)使用aapt工具生成R.jav
本文實例講述了Android編程使WebView支持HTML5 Video全屏播放的解決方法。分享給大家供大家參考,具體如下: 1)需要在AndroidManif
登錄應用程序的屏幕,詢問憑據登錄到一些特定的應用。可能需要登錄到Facebook,微博等本章介紹了,如何創建一個登錄界面,以及如何管理安全問題和錯誤嘗試。首先,必須定義兩
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用