Example usage for android.inputmethodservice Keyboard setShifted

List of usage examples for android.inputmethodservice Keyboard setShifted

Introduction

In this page you can find the example usage for android.inputmethodservice Keyboard setShifted.

Prototype

public boolean setShifted(boolean shiftState) 

Source Link

Usage

From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java

public void onKey(int primaryCode, int[] keyCodes) {
    /*String tap_file_name;
    String currentmood = "-99";//from w w  w .  ja  va  2s.c  om
    boolean esm_event=false,esm_signal=false,esm_time=false;
            
    //SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd__HH:mm:ss.SSS");
    SimpleDateFormat sdf = new SimpleDateFormat(getResources().getString(R.string.time_format));
    String currentDateandTime = sdf.format(new Date());
    //boolean mood_rdy_to_record;
            
    //Store the timestamp in SharedPref
    //SharedPreferences prefs = getApplicationContext().getSharedPreferences(getResources().getString(R.string.sharedpref_file), Context.MODE_WORLD_READABLE);
    SharedPreferences prefs = getApplicationContext().getSharedPreferences(getApplicationContext().getResources().getString(R.string.sharedpref_file), Context.MODE_WORLD_READABLE);
            
    //currentDateandTime1=prefs.getString("TimeStamp", "No Data");
    //System.out.println("[TimeStamp:"+currentDateandTime1+"]");
            
    //SharedPreferences.Editor editor = prefs.edit();
    SharedPreferences.Editor seditor =prefs.edit();
    seditor.putString(getResources().getString(R.string.sharedpref_tstamp), currentDateandTime);
    seditor.putString(getResources().getString(R.string.sharedpref_last_app_name), getAppName());
    seditor.putBoolean(getResources().getString(R.string.sharedpref_mood_rdy_to_record), true);
    //seditor.putString(getResources().getString(R.string.sharedpref_last_app_name), getAppName());
    //editor.apply();
    seditor.apply();
    seditor.commit();
            
    //System.out.println("Current Mood to Record:"+prefs.getBoolean(getResources().getString(R.string.sharedpref_mood_rdy_to_record),false));
            
    //Retrieve current mood from sharedpref
            
    try {
            
    Context con = getApplicationContext().createPackageContext(getResources().getString(R.string.moodrecorder_pkg), Context.CONTEXT_IGNORE_SECURITY);
    SharedPreferences mood_pref = con.getSharedPreferences(getResources().getString(R.string.tap_mood_sharedpref_file), Context.MODE_MULTI_PROCESS);
            
    currentmood = mood_pref.getString(getResources().getString(R.string.sharedpref_current_mood), "-99");
    esm_event = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_event),false);
    esm_signal = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_signal),false);
    esm_time = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_time),false);
    System.out.println("Current Mood:" + currentmood);
    }
    catch (Exception e) {
    e.printStackTrace();
    }*/

    SimpleDateFormat sdf = new SimpleDateFormat(getResources().getString(R.string.time_format));
    String currentDateandTime = sdf.format(new Date());

    ContentValues values = new ContentValues();
    values.put(KbTouchEvent.TouchEntry.TE_APP_NAME, getAppName());
    values.put(KbTouchEvent.TouchEntry.TE_TIMESTAMP, currentDateandTime);
    //values.put(TouchEvent.TouchEntry.TE_KEY, String.valueOf((char)primaryCode));
    values.put(KbTouchEvent.TouchEntry.TE_KEY, primaryCode);
    Uri uri = getContentResolver().insert(KbContentProvider.CONTENT_URI, values);

    //End of retrieving current mood from sharedpref

    //currentDateandTime1=prefs.getString("TimeStamp", "No Data");
    //System.out.println("[TimeStamp:"+currentDateandTime1+"]");

    String keypress = String.valueOf((char) primaryCode);
    Log.d("Key Pressed", keypress);
    System.out.println("Ascii value:" + (int) keypress.charAt(0));

    /*if(Character.va >=){
            
    }*/
    //System.out.println("Alternate way key pressed:"+Character.toChars(primaryCode)[0]);

    /*String string_t;
    //string_t = currentDateandTime+ "  ---->  " + "X = " + x_Coordinate + ", Y =  "+y_Coordinate+ "\n";
    //string_t = getAppName() + "," + currentDateandTime+ "," + keypress + "\n";
            
    string_t = getAppName() + "," + currentDateandTime + "," + currentmood + "," + esm_event + "," + esm_signal + "," + esm_time + "\n";
            
    //tap_file_name = imei_no + getResources().getString(R.string.tap_file_postfix);
            
    tap_file_name = imei_no + "_" + tap_ctr + getResources().getString(R.string.tap_file_postfix);
    File tap_file = new File(dataDir, tap_file_name);
            
    try{
       //String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath();
       //String FILENAME = "keylogger.txt";
            
      //File outfile = new File(SDCARD+File.separator+FILENAME);
      FileOutputStream fos = new FileOutputStream(tap_file,true);
      fos.write(string_t.getBytes());
      fos.close();
    }catch(Exception e) {
      Log.d("EXCEPTION",e.getMessage());
    }
            
    //Checks file size and move to ToBeUploaded folder
    int tap_file_size = Integer.parseInt(String.valueOf(tap_file.length() / 1024));
    //mood_file_size = mood_file_size /4;
    int tap_file_size_threshold = Integer.parseInt(getResources().getString(R.string.tap_file_size_limit));
    System.out.println("Tap File Size:" + tap_file_size + ", Tap File Threshold:" + tap_file_size_threshold );
            
    if (tap_file_size > tap_file_size_threshold) {
    int ctr = Integer.parseInt(tap_ctr) + 1;
    tap_ctr=String.valueOf(ctr);
    tap_ctr=String.format("%06d", Integer.parseInt(tap_ctr));
    //String.format("%05d", Integer.parseInt(mood_ctr));
    move_file(tap_file_name);
    }*/

    /********************************************************important edit edit 6****************************************/
    InputConnection ic = getCurrentInputConnection();
    // playClick(primaryCode)
    String suggested_string = "";
    /***********************************************************check edit***********************************************/
    if (isWordSeparator(primaryCode)) {
        // Handle separator
        if (mComposing.length() > 0) {
            commitTyped(getCurrentInputConnection());
            swipe = "";
        }
        sendKey(primaryCode);
        updateShiftKeyState(getCurrentInputEditorInfo());
    } else if (primaryCode == Keyboard.KEYCODE_DELETE) {
        handleBackspace();
    } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
        handleShift();
    } else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
        handleClose();
        return;
    } else if (primaryCode == KbLatinKeyboardView.KEYCODE_OPTIONS) {
        // Show a menu or somethin'
    } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) {
        Keyboard current = mInputView.getKeyboard();
        if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {

            current = mQwertyKeyboard;
        } else {
            current = mSymbolsKeyboard;
        }
        mInputView.setKeyboard(current);
        if (current == mSymbolsKeyboard) {
            current.setShifted(false);
        }
    } else {

        /****************************************************************8default handling******************************************/
        char code = (char) primaryCode;
        if (swipe2.length() != 0 && code != swipe2.charAt(swipe2.length() - 1)) {
            swipe2 += "+" + code;
        }
        if (frequent_char == 0 || frequent_char == code || frequent_char == test.charAt(0))
            test += ".*" + code;
        else
            test += ".*" + frequent_char + ".*" + code;
        Log.d("Pattern", test);
        if (Character.isLetter(code) && mCapsLock) {
            code = Character.toUpperCase(code);
        }
        if (swipe2.length() < 3) {
            ic.commitText(String.valueOf(code), 1);
            swipe = "";
            swipe2 = "";
        } else {
            suggested_string = strings_matched(test);
            suggested_string += " ";
            if (suggested_string.length() <= 1) {
                ic.commitText(String.valueOf(code), 1);
            } else
                ic.commitText(suggested_string, suggested_string.length());

            //handleCharacter(primaryCode, keyCodes);
        }
    }
}