Android Open Source - MYKey_SoftKeyboard String Key Handler






From Project

Back to project page MYKey_SoftKeyboard.

License

The source code is released under:

Apache License

If you think the Android project MYKey_SoftKeyboard listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package string_Key;
// ww w .ja v a 2 s .  c om
import java.util.ArrayList;

import key_process.*;
import korean_automata.*;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.android.mykey.*;
import com.android.mykey.LatinKeyboard.*;

public class StringKeyHandler extends SQLiteOpenHelper{
  private static StringKeyHandler instance = null;
  private static final String DB_NAME = "stringkey.db";
  
  private SQLiteDatabase db = null;
  

  public static StringKeyHandler getInstance(Context context){
    if(instance == null)
      instance = new StringKeyHandler(context);
    
    return instance;
  }
  
  
  
  private StringKeyHandler(Context context){
    super(context, DB_NAME, null, 1);
    
    db = this.getWritableDatabase();
    createTable();
    initDB();
  }
  
  private void createTable(){
    String sql = "CREATE TABLE IF NOT EXISTS key (keyCode TEXT PRIMARY KEY, keyLabel TEXT, keyText TEXT);";
    db.execSQL(sql);
  }
  
  private void initDB(){
    String sql = "SELECT count(*) FROM key;";
    Cursor c = db.rawQuery(sql, null);
    
    c.moveToFirst();
    
    int result = Integer.parseInt(c.getString(0));
    
    if(result == 0){
      KeyMap tmpKeyInfo = new KeyMap();
      ArrayList<String> tmpKeyCodeList = tmpKeyInfo.getStringCodeList();
      ArrayList<String> tmpKeyLabelList = tmpKeyInfo.getStringLabelList();
      
      for(int i = 0; i < tmpKeyCodeList.size(); i++){
        insertMember(tmpKeyCodeList.get(i), tmpKeyLabelList.get(i), "");
      }
      
    }
    
  }
  
  private void insertMember(String keyCode, String keyLabel, String keyText){
    ContentValues values = new ContentValues();
    values.put("keyCode", keyCode);
    values.put("keyLabel", keyLabel);
    values.put("keyText", keyText);
    
    db.insert("key", null, values);
  }
  
  public void setStringKeyInfo(ArrayList<LatinKey> strKeyArr){
    String sql = "SELECT * FROM key;";
    
    Cursor c = db.rawQuery(sql, null);
    c.moveToFirst();
    
    for(int i = 0; i < c.getCount(); i++){
      int keyCode = Integer.parseInt(c.getString(0));
      String keyText = c.getString(2);
      
      for(int j = 0; j < strKeyArr.size(); j++){
        LatinKey tmpKey = strKeyArr.get(j);
        
        if(tmpKey.codes[0] == keyCode){
          tmpKey.text = keyText;
          break;
        }
      }
      
      c.moveToNext();
    }
  }
  
  public void updateStringKeyInfo(StringKeyItem item){
    String sql = "UPDATE key SET keyText='" + item.getKeyText() + "' WHERE keyCode='" + item.getKeyCode() +"'";
    
    db.execSQL(sql);
  }
  
  
  public ArrayList<StringKeyItem> getItems(){
    String sql = "SELECT * FROM key;";
    Cursor c = db.rawQuery(sql, null);
    ArrayList<StringKeyItem> items = new ArrayList<StringKeyItem>();
    
    c.moveToFirst();
    
    for(int i = 0; i < c.getCount(); i++){
      String keyCode = c.getString(0);
      String keyLabel = c.getString(1);
      String keyText = c.getString(2);
      
      items.add(new StringKeyItem(keyCode, keyLabel, keyText));
      c.moveToNext();
    }
    
    return items;
  }



  @Override
  public void onCreate(SQLiteDatabase db) {
  }



  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  }
  
  
}




Java Source Code List

com.android.mykey.LatinKeyboardView.java
com.android.mykey.LatinKeyboard.java
com.android.mykey.SoftKeyboard.java
ime_preferences.ImePreferencesActivity.java
key_process.Buffer.java
key_process.FinalCombinationInfo.java
key_process.KeyInfo.java
key_process.KeyMap.java
key_process.KeyProcessor.java
korean_automata.CombinationState.java
korean_automata.KoreanAutomata.java
korean_automata.PhonemeCategoryConverter.java
korean_automata.Proc1.java
korean_automata.Proc2.java
korean_automata.Proc3.java
korean_automata.Proc4.java
korean_automata.StArea.java
korean_automata.StEmpty.java
korean_automata.StError.java
korean_automata.StFirstArea.java
korean_automata.StFirstVowelAndFirst.java
korean_automata.StFirstVowel.java
korean_automata.StFirst.java
korean_automata.StMultiFinal.java
korean_automata.StSingleFinalAndFirst.java
korean_automata.StSingleFinal.java
korean_automata.StVowel.java
korean_automata.VerifyComb.java
string_Key.StringKeyHandler.java
string_Key.StringKeyListAdapter.java
string_Key.StringKeyModifyActivity.java