Example usage for android.os SystemClock uptimeMillis

List of usage examples for android.os SystemClock uptimeMillis

Introduction

In this page you can find the example usage for android.os SystemClock uptimeMillis.

Prototype

@CriticalNative
native public static long uptimeMillis();

Source Link

Document

Returns milliseconds since boot, not counting time spent in deep sleep.

Usage

From source file:com.lanou.mirror.tool.VerticalViewPager.java

/**
 * Start a fake drag of the pager./*from   w  w w. j  a v  a  2 s .com*/
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 *
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 *
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    } /* end of if */
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    // XXX 
    mInitialMotionY = mLastMotionY = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    } /* end of if */
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 * Start a fake drag of the pager./*from ww  w.  j a  v a2 s .co m*/
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 *
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 *
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    } /* end of if */
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    // XXX 
    mInitialMotionY = mLastMotionY = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    } /* end of if */
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}

From source file:android.webkit.cts.WebViewTest.java

public void testRequestImageRef() throws Exception, Throwable {
    if (!NullWebViewUtils.isWebViewAvailable()) {
        return;//from   ww  w.j  a va2  s.c o  m
    }
    final class ImageLoaded {
        public boolean mImageLoaded;

        @JavascriptInterface
        public void loaded() {
            mImageLoaded = true;
        }
    }
    final ImageLoaded imageLoaded = new ImageLoaded();
    runTestOnUiThread(new Runnable() {
        public void run() {
            mOnUiThread.getSettings().setJavaScriptEnabled(true);
        }
    });
    mOnUiThread.addJavascriptInterface(imageLoaded, "imageLoaded");
    AssetManager assets = getActivity().getAssets();
    Bitmap bitmap = BitmapFactory.decodeStream(assets.open(TestHtmlConstants.LARGE_IMG_URL));
    int imgWidth = bitmap.getWidth();
    int imgHeight = bitmap.getHeight();

    startWebServer(false);
    final String imgUrl = mWebServer.getAssetUrl(TestHtmlConstants.LARGE_IMG_URL);
    mOnUiThread.loadDataAndWaitForCompletion(
            "<html><head><title>Title</title><style type=\"text/css\">"
                    + "#imgElement { -webkit-transform: translate3d(0,0,1); }"
                    + "#imgElement.finish { -webkit-transform: translate3d(0,0,0);"
                    + " -webkit-transition-duration: 1ms; }</style>"
                    + "<script type=\"text/javascript\">function imgLoad() {"
                    + "imgElement = document.getElementById('imgElement');"
                    + "imgElement.addEventListener('webkitTransitionEnd',"
                    + "function(e) { imageLoaded.loaded(); });" + "imgElement.className = 'finish';}</script>"
                    + "</head><body><img id=\"imgElement\" src=\"" + imgUrl + "\" width=\"" + imgWidth
                    + "\" height=\"" + imgHeight + "\" onLoad=\"imgLoad()\"/></body></html>",
            "text/html", null);
    new PollingCheck() {
        @Override
        protected boolean check() {
            return imageLoaded.mImageLoaded;
        }
    }.run();
    getInstrumentation().waitForIdleSync();

    final HrefCheckHandler handler = new HrefCheckHandler(mWebView.getHandler().getLooper());
    final Message msg = new Message();
    msg.setTarget(handler);

    // touch the image
    handler.reset();
    int[] location = mOnUiThread.getLocationOnScreen();

    long time = SystemClock.uptimeMillis();
    getInstrumentation().sendPointerSync(MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN,
            location[0] + imgWidth / 2, location[1] + imgHeight / 2, 0));
    getInstrumentation().waitForIdleSync();
    mOnUiThread.requestImageRef(msg);
    new PollingCheck() {
        @Override
        protected boolean check() {
            boolean done = false;
            if (handler.hasCalledHandleMessage()) {
                if (handler.mResultUrl != null) {
                    done = true;
                } else {
                    handler.reset();
                    Message newMsg = new Message();
                    newMsg.setTarget(handler);
                    mOnUiThread.requestImageRef(newMsg);
                }
            }
            return done;
        }
    }.run();
    assertEquals(imgUrl, handler.mResultUrl);
}

From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java

/**
 * Start a fake drag of the pager./* www.  ja  v a 2s.co m*/
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 *
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 *
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    } /* end of if */
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    // XXX ?
    mInitialMotionY = mLastMotionY = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    } /* end of if */
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}

From source file:org.mozilla.gecko.GeckoApp.java

private void initialize() {
    mInitialized = true;/*from   w w w  .j av  a 2s  .  c o  m*/

    Intent intent = getIntent();
    String args = intent.getStringExtra("args");
    if (args != null && args.contains("-profile")) {
        Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)");
        Matcher m = p.matcher(args);
        if (m.find()) {
            mProfile = GeckoProfile.get(this, m.group(1));
            mLastTitle = null;
            mLastViewport = null;
            mLastScreen = null;
        }
    }

    if (ACTION_UPDATE.equals(intent.getAction()) || args != null && args.contains("-alert update-app")) {
        Log.i(LOGTAG, "onCreate: Update request");
        checkAndLaunchUpdate();
    }

    mBrowserToolbar.init();
    mBrowserToolbar.setTitle(mLastTitle);

    String passedUri = null;
    String uri = getURIFromIntent(intent);
    if (uri != null && uri.length() > 0)
        passedUri = mLastTitle = uri;

    if (passedUri == null || passedUri.equals("about:home")) {
        // show about:home if we aren't restoring previous session
        if (!getProfile().hasSession()) {
            mBrowserToolbar.updateTabCount(1);
            showAboutHome();
        }
    } else {
        mBrowserToolbar.updateTabCount(1);
    }

    if (sGREDir == null)
        sGREDir = new File(this.getApplicationInfo().dataDir);

    Uri data = intent.getData();
    if (data != null && "http".equals(data.getScheme()) && isHostOnPrefetchWhitelist(data.getHost())) {
        Intent copy = new Intent(intent);
        copy.setAction(ACTION_LOAD);
        GeckoAppShell.getHandler().post(new RedirectorRunnable(copy));
        // We're going to handle this uri with the redirector, so setting
        // the action to MAIN and clearing the uri data prevents us from
        // loading it twice
        intent.setAction(Intent.ACTION_MAIN);
        intent.setData(null);
        passedUri = null;
    }

    sGeckoThread = new GeckoThread(intent, passedUri, mRestoreSession);
    if (!ACTION_DEBUG.equals(intent.getAction())
            && checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
        sGeckoThread.start();

    mFavicons = new Favicons(this);

    Tabs.getInstance().setContentResolver(getContentResolver());

    if (cameraView == null) {
        cameraView = new SurfaceView(this);
        cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    if (mLayerController == null) {
        /*
         * Create a layer client so that Gecko will have a buffer to draw into, but don't hook
         * it up to the layer controller yet.
         */
        mSoftwareLayerClient = new GeckoSoftwareLayerClient(this);

        /*
         * Hook a placeholder layer client up to the layer controller so that the user can pan
         * and zoom a cached screenshot of the previous page. This call will return null if
         * there is no cached screenshot; in that case, we have no choice but to display a
         * checkerboard.
         *
         * TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first-
         * run experience, perhaps?
         */
        mLayerController = new LayerController(this);
        mPlaceholderLayerClient = PlaceholderLayerClient.createInstance(this);
        mLayerController.setLayerClient(mPlaceholderLayerClient);

        mGeckoLayout.addView(mLayerController.getView(), 0);
    }

    mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);

    mDoorHangerPopup = new DoorHangerPopup(this);
    mAutoCompletePopup = (AutoCompletePopup) findViewById(R.id.autocomplete_popup);

    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");

    if (!sTryCatchAttached) {
        sTryCatchAttached = true;
        mMainHandler.post(new Runnable() {
            public void run() {
                try {
                    Looper.loop();
                } catch (Exception e) {
                    GeckoAppShell.reportJavaCrash(e);
                }
                // resetting this is kinda pointless, but oh well
                sTryCatchAttached = false;
            }
        });
    }

    //register for events
    GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
    GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);

    IntentFilter batteryFilter = new IntentFilter();
    batteryFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    mBatteryReceiver = new GeckoBatteryManager();
    registerReceiver(mBatteryReceiver, batteryFilter);

    if (SmsManager.getInstance() != null) {
        SmsManager.getInstance().start();
    }

    GeckoNetworkManager.getInstance().init();

    final GeckoApp self = this;

    GeckoAppShell.getHandler().postDelayed(new Runnable() {
        public void run() {
            Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");

            /*
              XXXX see bug 635342
               We want to disable this code if possible.  It is about 145ms in runtime
            SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
            String localeCode = settings.getString(getPackageName() + ".locale", "");
            if (localeCode != null && localeCode.length() > 0)
            GeckoAppShell.setSelectedLocale(localeCode);
            */

            if (!checkLaunchState(LaunchState.Launched)) {
                return;
            }

            checkMigrateProfile();
        }
    }, 50);
}

From source file:com.example.view.VerticalViewPager.java

/**
 * Start a fake drag of the pager./*  w  w w. j  ava2  s  . c  o m*/
 * 
 * <p>
 * A fake drag can be useful if you want to synchronize the motion of the
 * ViewPager with the touch scrolling of another view, while still letting
 * the ViewPager control the snapping motion and fling behavior. (e.g.
 * parallax-scrolling tabs.) Call {@link #fakeDragBy(float)} to simulate the
 * actual drag motion. Call {@link #endFakeDrag()} to complete the fake drag
 * and fling as necessary.
 * 
 * <p>
 * During a fake drag the ViewPager will ignore all touch events. If a real
 * drag is already in progress, this method will return false.
 * 
 * @return true if the fake drag began successfully, false if it could not
 *         be started.
 * 
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    } /* end of if */
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    // XXX
    mInitialMotionY = mLastMotionY = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    } /* end of if */
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

private void startVideoRecording() {
    shutterOff = true;//from w  w  w  .  j  a v a2 s.  c  o  m
    mRecordingStartTime = SystemClock.uptimeMillis();

    CameraController.stopCameraPreview();
    prepareMediaRecorder();
    if (CameraController.isUseCamera2())
        CameraController.startCameraPreview();

    try {
        if (preferenceVideoMuteMode)
            muteAllSounds();

        // Camera is available and unlocked, MediaRecorder is prepared,
        // now you can start recording
        mMediaRecorder.start();
        ApplicationScreen.getGUIManager().lockControls = true;

    } catch (Exception e) {
        Log.d("Video", "Exception preparing MediaRecorder: " + e.getMessage());
        releaseMediaRecorder();
        Toast.makeText(ApplicationScreen.instance, "Failed to start video recording", Toast.LENGTH_LONG).show();

        ApplicationScreen.getGUIManager().lockControls = false;
        PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
                ApplicationInterface.MSG_CONTROL_UNLOCKED);
        CameraController.lockCamera(); // take camera access back from MediaRecorder
        CameraController.stopCameraPreview();
        CameraController.startCameraPreview();

        if (preferenceVideoMuteMode)
            unmuteAllSounds();

        return;
    }

    // inform the user that recording has started
    isRecording = true;
    showRecordingUI(isRecording);
    if (onPause) {
        onPause = false;
        showRecordingUI(isRecording);
        onPause = true;
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    prefs.edit().putBoolean("videorecording", true).commit();

    new CountDownTimer(1000, 1000) {
        public void onTick(long millisUntilFinished) {
        }

        public void onFinish() {
            shutterOff = false;
            // ApplicationScreen.getGUIManager().lockControls = false;
        }
    }.start();
}

From source file:interactive.view.pagereader.VerticalViewPager.java

/**
 * Start a fake drag of the pager./*  w  ww .  j  a  v a 2s. c om*/
 * 
 * <p>
 * A fake drag can be useful if you want to synchronize the motion of the
 * ViewPager with the touch scrolling of another view, while still letting
 * the ViewPager control the snapping motion and fling behavior. (e.g.
 * parallax-scrolling tabs.) Call {@link #fakeDragBy(float)} to simulate the
 * actual drag motion. Call {@link #endFakeDrag()} to complete the fake drag
 * and fling as necessary.
 * 
 * <p>
 * During a fake drag the ViewPager will ignore all touch events. If a real
 * drag is already in progress, this method will return false.
 * 
 * @return true if the fake drag began successfully, false if it could not
 *         be started.
 * 
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    } /* end of if */
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    // XXX 
    mInitialMotionY = mLastMotionY = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    } /* end of if */
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
 *
 * @param yOffset Offset in pixels to drag by.
 * @see #beginFakeDrag()// w w w. j  ava 2 s. c o m
 * @see #endFakeDrag()
 */
public void fakeDragBy(float yOffset) {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    } /* end of if */

    mLastMotionY += yOffset;
    float scrollY = getScrollY() - yOffset;
    final int height = getHeight();
    final int heightWithMargin = height + mPageMargin;

    final float topBound = Math.max(0, (mCurItem - 1) * heightWithMargin);
    final float bottomBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * heightWithMargin;
    if (scrollY < topBound) {
        scrollY = topBound;
    } else if (scrollY > bottomBound) {
        scrollY = bottomBound;
    } /* end of if */
    // Don't lose the rounded component
    mLastMotionY += scrollY - (int) scrollY;
    scrollTo(getScrollX(), (int) scrollY);
    pageScrolled((int) scrollY);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0,
            mLastMotionY, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}

From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java

private void handleCharacter(final int primaryCode, final Keyboard.Key key, final int multiTapIndex,
        int[] nearByKeyCodes) {
    if (BuildConfig.DEBUG)
        Logger.d(TAG, "handleCharacter: %d, isPredictionOn: %s, mPredicting: %s", primaryCode, isPredictionOn(),
                TextEntryState.isPredicting());

    mExpectingSelectionUpdateBy = SystemClock.uptimeMillis() + MAX_TIME_TO_EXPECT_SELECTION_UPDATE;
    if (TextEntryState.isReadyToPredict() && isAlphabet(primaryCode) && !isCursorTouchingWord()) {
        TextEntryState.newSession(mPredictionOn);
        mUndoCommitCursorPosition = UNDO_COMMIT_NONE;
        mWord.reset();/*from   w  ww  .  j a  v  a  2  s. c  o  m*/
        mAutoCorrectOn = mAutoComplete;
        TextEntryState.typedCharacter((char) primaryCode, false);
        if (mShiftKeyState.isActive()) {
            mWord.setFirstCharCapitalized(true);
        }
    } else if (TextEntryState.isPredicting()) {
        TextEntryState.typedCharacter((char) primaryCode, false);
    }

    mLastCharacterWasShifted = (getInputView() != null) && getInputView().isShifted();

    if (TextEntryState.isPredicting()) {
        final InputConnection ic = getCurrentInputConnection();
        mWord.add(primaryCode, nearByKeyCodes);
        ChewbaccaOnTheDrums.onKeyTyped(mWord, getApplicationContext());

        if (ic != null) {
            final int cursorPosition;
            if (mWord.cursorPosition() != mWord.length()) {
                //Cursor is not at the end of the word. I'll need to reposition
                cursorPosition = mGlobalCursorPosition + 1/*adding the new character*/;
                ic.beginBatchEdit();
            } else {
                cursorPosition = -1;
            }

            ic.setComposingText(mWord.getTypedWord(), 1);
            if (cursorPosition > 0) {
                ic.setSelection(cursorPosition, cursorPosition);
                ic.endBatchEdit();
            }
        }
        // this should be done ONLY if the key is a letter, and not a inner
        // character (like ').
        if (isSuggestionAffectingCharacter(primaryCode)) {
            postUpdateSuggestions();
        } else {
            // just replace the typed word in the candidates view
            if (mCandidateView != null)
                mCandidateView.replaceTypedWord(mWord.getTypedWord());
        }
    } else {
        sendKeyChar((char) primaryCode);
    }
    mJustAutoAddedWord = false;
}