Example usage for android.media ToneGenerator TONE_CDMA_SOFT_ERROR_LITE

List of usage examples for android.media ToneGenerator TONE_CDMA_SOFT_ERROR_LITE

Introduction

In this page you can find the example usage for android.media ToneGenerator TONE_CDMA_SOFT_ERROR_LITE.

Prototype

int TONE_CDMA_SOFT_ERROR_LITE

To view the source code for android.media ToneGenerator TONE_CDMA_SOFT_ERROR_LITE.

Click Source Link

Document

CDMA SOFT ERROR LITE tone: 1047Hz 125ms ON, 370Hz 125ms

Usage

From source file:cl.gisred.android.RepartoActivity.java

private void alertFail() {
    ToneGenerator tgFail = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
    tgFail.startTone(ToneGenerator.TONE_CDMA_SOFT_ERROR_LITE, 200);

    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);// w w w  . ja  v  a 2 s  . c  om
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Manages actual input into the editor. Here we:
 * implement our injection algorithm as required
 * store data relating to the key press/*from ww w. j  ava 2  s.  co m*/
 * initiate any spell checking as required
 */
public void onKey(int primaryCode, int[] keyCodes) {

    // touches all done, add the chars to the event and then the event to the session       
    currentEvent.keyCode = primaryCode;

    if (errorInjection && primaryCode >= 32) {
        //give a n% chance of the key being modified
        Random r = new Random();
        int res = r.nextInt(100);
        if (res <= errorInjectionThreshold) //%n chance of key being modified
        {
            //Log.i("OnKey", "Will modify");
            try {
                //for each combination in the model, find the eucleidian distance and the replacement freq
                JSONObject targetObj = suspectReplacementDistribution
                        .getJSONObject(Integer.toString(primaryCode));
                Iterator<?> keys = targetObj.keys();
                ArrayList<Character> list = new ArrayList();
                while (keys.hasNext()) {
                    String key = (String) keys.next();
                    int freq = targetObj.getInt(key);
                    //if the frequency is 0, add the suspect as a replacement candidate
                    double dist = keyModel.distance2(primaryCode, Integer.parseInt(key));

                    if (dist > 0) {
                        if (dist > 2.0) //fix it so that only nearby keys have a chance of being elected
                            dist = 100;
                        //add to the list of candidates as many times as required if specific freq>0;
                        int sfreq = (int) Math.round(freq / dist);
                        //Log.i("Test", "Freq/Dist to "+key+": "+freq+"/"+dist+" final prob: "+sfreq);

                        if (sfreq == 0) //add the suspect as a replacement candidate
                        {
                            list.add(Character.toChars(primaryCode)[0]);
                        } else //add the other replacement candidates as required
                        {
                            for (int x = 0; x < targetObj.getInt(key); x++) {
                                list.add(Character.toChars(Integer.parseInt(key))[0]);

                            }
                        }
                    }
                }
                //Log.i("OnKey", "Replace list size: "+list.size());

                Random x = new Random();
                int sel = x.nextInt(list.size());

                //if the replacement eventually happens
                if ((int) list.get(sel) != primaryCode) {

                    if (errorInjectionSound) {
                        final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
                        tg.startTone(ToneGenerator.TONE_CDMA_SOFT_ERROR_LITE);
                    }
                    //primaryCode = (int)list.get(sel);

                    //Log.w("OnKey", "Replace "+Character.toChars(primaryCode)[0]+" with "+list.get(sel));
                    errorMap.put(mComposing.length(), (char) (int) list.get(sel)); //put in our current position and the replacement
                    //nInjections++;      
                } else
                    Log.i("OnKey", "Replacement will not happen, same key selected");

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            //Log.i("OnKey", "Will not modify, r="+res);
        }
    }
    //switch adaptxt language if necessary
    if (coreEngine != null) {
        switch (mInputView.currentKeyboard) {
        case KeyboardViews.QWERTY_EL:
            coreEngine.activateLanguageKeymap(131092, null);
            coreEngine.setDictionaryPriority(131092, 0);
            break;
        case KeyboardViews.QWERTY_EN:
            coreEngine.activateLanguageKeymap(131081, null);
            coreEngine.setDictionaryPriority(131092, 1);
            break;
        }
    }

    //get the full inputted text
    extr = ic.getExtractedText(new ExtractedTextRequest(), 0);

    if (currentEvent != null && captureData == true) {

        //Log.i("OnKey", "OK to capture data!");
        currentEvent.user = userid;

        if (primaryCode > 0)
            currentEvent.keyChar = (char) primaryCode;

        //handle the booleans
        if (currentSession.events.get(currentSession.events.size() - 1).keyChar == ' ') //space
        {
            currentEvent.followsSpace = true;
        }

        if (currentEvent.keyCode == Keyboard.KEYCODE_DELETE) {
            System.out.println("Backspace Pressed!");

            //if a delete is pressed after another delete
            //and its cursor position is not -1 from the previous delete
            //we must commit the previous deletion as a suspect character.
            if (currentSession.events.get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE
                    && extr.selectionStart != lastDeletedPos - 1) {
                currentSession.suspects.add(lastDeleted);
                //System.out.println("Suspect = "+lastDeleted);
            }

            //get all the text before the backspace press and the current cursor position
            if (extr.selectionStart > 0) {
                lastDeleted = extr.text.charAt(extr.selectionStart - 1);
                lastDeletedPos = extr.selectionStart;
                //System.out.println("Deleted = "+lastDeleted+"\nCursor Position = "+extr.selectionStart);
            }
        }

        //if the current key is NOT a backspace but the previous one was
        if (currentEvent.keyCode != Keyboard.KEYCODE_DELETE && currentSession.events
                .get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE) {
            currentSession.suspects.add(lastDeleted);
            //System.out.println("Suspect = "+lastDeleted);

        }

    }

    //do the handling     
    if (isWordSeparator(primaryCode)) {
        // Handle separator
        //System.out.println("Detected a word separator \""+primaryCode+"\"");
        if (primaryCode != 32) {
            shouldInsertSpace = false;
            if (extr.text.length() > 0) {
                //Log.i("On Key ", "last letter after separator was ["+extr.text.charAt(extr.selectionStart-1)+"]");
                //check if the previous char was a space, if so delete it.
                if (extr.text.charAt(extr.selectionStart - 1) == ' ' && !isSpecialSeparator(primaryCode)) //detecting if the current char is not part of a smiley face
                {
                    onKey(-5, null);
                }
            }
        }

        //clear the touch history
        clearDots();

        //ensure spell checker is using correct language          
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

        Editor ed = prefs.edit();
        if (captureData) {
            if (mInputView.currentLang == 1) //english
            {
                ed.putString("available_dicts", "en");
                ed.commit();
                if (mScs != null)
                    mScs.close();
                String lang = prefs.getString("available_dicts", "jam");
                Log.i("OnKey", "Spellcheck lang set to " + lang);
                Locale english = new Locale("en", "GB");
                mScs = tsm.newSpellCheckerSession(null, english, this, false);
                if (mScs == null)
                    Log.e("OnKey", "Failed to obtain spell-checker session");
            } else {
                ed.putString("available_dicts", "el");
                ed.commit();
                if (mScs != null)
                    mScs.close();
                String lang = prefs.getString("available_dicts", "jam");
                Log.i("OnKey", "Spellcheck lang set to " + lang);
                Locale greek = new Locale("el", "GR");
                mScs = tsm.newSpellCheckerSession(null, greek, this, false);
                if (mScs == null)
                    Log.e("OnKey", "Failed to obtain spell-checker session");
            }
        }

        //handle space for Adaptxt
        if (Character.isSpaceChar(primaryCode)) {
            if (coreEngine != null) {
                //Log.i("Handle Character", "Space pressed");
                coreEngine.resetCoreString();
                //Log.i("Space Pressed", "Word is "+mComposing+" ");
                coreEngine.insertText(mComposing.toString() + " ");
                updateCandidates();
            }
        }

        if (!firstWordSet && mComposing.length() > 1) {
            if (captureData)
                currentSession.firstWord = mComposing.toString();
            else
                currentSession.firstWord = "$$$$";

            firstWordSet = true;
            //System.out.println("First Word\""+mComposing.toString()+"\"");
        }

        //effect any injections as required
        if (mComposing.length() > 0) {
            //commitTyped(getCurrentInputConnection());
            //check the errormap for any replacements 
            if (errorMap.size() > 0) {

                //restrict the errormap to the 25% of word length cap

                int replacementstodelete = errorMap.size() - (int) Math.round(mComposing.length() * 0.25); //total replacements - those to keep
                if (replacementstodelete < 0)
                    replacementstodelete = 0;
                //allow at least one
                if (errorMap.size() == replacementstodelete)
                    replacementstodelete = errorMap.size() - 1;

                if (replacementstodelete > 0) {
                    List<Integer> keys = new ArrayList<Integer>(errorMap.keySet());

                    for (int z = 0; z < replacementstodelete; z++) {
                        Random random = new Random();
                        int listposition = random.nextInt(keys.size());
                        int randomKey = keys.get(listposition);
                        //remove this from the error map and the list
                        errorMap.remove(randomKey);
                        keys.remove(listposition);

                    }
                }

                //effect the injections
                String oldmComposing = mComposing.toString();
                Iterator it = errorMap.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pair = (Map.Entry) it.next();
                    mComposing.replace((Integer) pair.getKey(), (Integer) pair.getKey() + 1,
                            "" + (Character) pair.getValue());
                    //it.remove(); // avoids a ConcurrentModificationException
                }
                nInjections += errorMap.size();
                currentSession.nInjections = nInjections;
                //Log.i("Injections", "Will replace "+oldmComposing+" with "+mComposing+", nInjections="+nInjections);
                errorMap.clear();
            }

            wordSeparatorKeyCode = primaryCode;
            if (captureData)
                commitTyped(ic, isWordSeparator(primaryCode));
            else {
                if (primaryCode != Keyboard.KEYCODE_DONE && primaryCode != 10) //done and go/enter
                    handleCharacter(primaryCode, keyCodes);
                else
                    sendKey(primaryCode);
                commitTyped(ic);
            }
        } else {
            sendKey(primaryCode);
        }

        updateShiftKeyState(getCurrentInputEditorInfo());

    } else if (primaryCode == Keyboard.KEYCODE_DELETE) {
        if (errorMap.get(mComposing.length() - 1) != null) {
            //Log.i("Injection", "Delete from map pos="+(mComposing.length()-1)+", char="+errorMap.get(mComposing.length()-1));
            errorMap.remove(mComposing.length() - 1);
        }

        handleBackspace();
    } else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
        handleShift();
    } else if (primaryCode == Keyboard.KEYCODE_CANCEL) { //keyboard hiding button
        //override this for settings activity
        //handleClose();
        Intent intent = new Intent(this, LoggingIMESettings.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return;
    } else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) {
        // Show a menu or somethin'
    } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) {
        //Keyboard current = mInputView.getKeyboard();

        if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS
                || mInputView.currentKeyboard == KeyboardViews.SYMBOLS_SHIFTED) {
            //mInputView.currentKeyboard = KeyboardViews.QWERTY_EN;
            mInputView.currentKeyboard = lastKeyboardView;
        } else { //about to change to symbols
            lastKeyboardView = mInputView.currentKeyboard; //keep track of where we came from
            mInputView.currentKeyboard = KeyboardViews.SYMBOLS;
        }
        mInputView.switchKeyboard();
        if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS) {
            mInputView.getKeyboard().setShifted(false);
        }
    } else {
        handleCharacter(primaryCode, keyCodes);
    }
}