Source:
private void toggleHtmlMode(final ToggleButton toggleButton) { if (!isAdded()) { return; } mEditorFragmentListener.onTrackableEvent(TrackableEvent.HTML_BUTTON_TAPPED); if (!mUploadingMedia.isEmpty() || isActionInProgress()) { toggleButton.setChecked(false); ToastUtils.showToast(getActivity(), R.string.alert_action_while_uploading, ToastUtils.Duration.LONG); return; } clearFormatBarButtons(); updateFormatBarEnabledState(true); if (toggleButton.isChecked()) { Thread thread = new Thread(new Runnable() { @Override public void run() { if (!isAdded()) { return; } try { getTitle(); getContent(); } catch (IllegalEditorStateException e) { AppLog.e(T.EDITOR, "toggleHtmlMode: unable to get title or content"); return; } getActivity().runOnUiThread(new Runnable() { @Override public void run() { mSourceViewTitle.setText(mTitle); SpannableString spannableContent = new SpannableString(mContentHtml); HtmlStyleUtils.styleHtmlForDisplay(spannableContent); mSourceViewContent.setText(spannableContent); mWebView.setVisibility(View.GONE); mSourceView.setVisibility(View.VISIBLE); mSourceViewContent.requestFocus(); mSourceViewContent.setSelection(0); InputMethodManager imm = ((InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE)); imm.showSoftInput(mSourceViewContent, InputMethodManager.SHOW_IMPLICIT); } }); } }); thread.start(); } else { mWebView.setVisibility(View.VISIBLE); mSourceView.setVisibility(View.GONE); mTitle = mSourceViewTitle.getText().toString(); mContentHtml = mSourceViewContent.getText().toString(); updateVisualEditorFields(); mWebView.execJavaScriptFromString("ZSSEditor.getFailedMedia();"); mWebView.execJavaScriptFromString("ZSSEditor.resetSelectionOnField('zss_field_content');"); } }

Target:
private void toggleHtmlMode(final ToggleButton toggleButton) { if (!isAdded()) { return; } mEditorFragmentListener.onTrackableEvent(TrackableEvent.HTML_BUTTON_TAPPED); if (!mUploadingMedia.isEmpty() || isActionInProgress()) { toggleButton.setChecked(false); ToastUtils.showToast(getActivity(), R.string.alert_action_while_uploading, ToastUtils.Duration.LONG); return; } clearFormatBarButtons(); updateFormatBarEnabledState(true); if (toggleButton.isChecked()) { Thread thread = new Thread(new Runnable() { @Override public void run() { if (!isAdded()) { return; } try { getTitle(); getContent(); } catch (IllegalEditorStateException e) { AppLog.e(T.EDITOR, "toggleHtmlMode: unable to get title or content"); getActivity().runOnUiThread(new Runnable() { @Override public void run() { toggleButton.setChecked(false); } }); return; } getActivity().runOnUiThread(new Runnable() { @Override public void run() { mSourceViewTitle.setText(mTitle); SpannableString spannableContent = new SpannableString(mContentHtml); HtmlStyleUtils.styleHtmlForDisplay(spannableContent); mSourceViewContent.setText(spannableContent); mWebView.setVisibility(View.GONE); mSourceView.setVisibility(View.VISIBLE); mSourceViewContent.requestFocus(); mSourceViewContent.setSelection(0); InputMethodManager imm = ((InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE)); imm.showSoftInput(mSourceViewContent, InputMethodManager.SHOW_IMPLICIT); } }); } }); thread.start(); } else { mWebView.setVisibility(View.VISIBLE); mSourceView.setVisibility(View.GONE); mTitle = mSourceViewTitle.getText().toString(); mContentHtml = mSourceViewContent.getText().toString(); updateVisualEditorFields(); mWebView.execJavaScriptFromString("ZSSEditor.getFailedMedia();"); mWebView.execJavaScriptFromString("ZSSEditor.resetSelectionOnField('zss_field_content');"); } }