Example usage for android.graphics Typeface MONOSPACE

List of usage examples for android.graphics Typeface MONOSPACE

Introduction

In this page you can find the example usage for android.graphics Typeface MONOSPACE.

Prototype

Typeface MONOSPACE

To view the source code for android.graphics Typeface MONOSPACE.

Click Source Link

Document

The NORMAL style of the default monospace typeface.

Usage

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void parseCodeText(Elements cds) {
    for (Element cd : cds)
        addText(cd.text().trim(), false, Typeface.MONOSPACE);
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    // This needs to be before super.onCreate, otherwise ActionbarSherlock
    // doesn't makes the background of the actionbar white when you're
    // in the dark theme.
    setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);

    Log.d(LOG, "onCreate:" + this);
    super.onCreate(savedInstanceState);

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Don't auto-launch if this fails.
    prefs.edit().remove(C.DICT_FILE).commit();

    setContentView(R.layout.dictionary_activity);

    application = (DictionaryApplication) getApplication();
    theme = application.getSelectedTheme();
    textColorFg = getResources().getColor(theme.tokenRowFgColor);

    final Intent intent = getIntent();
    String intentAction = intent.getAction();
    /**/*w  ww .  ja  v  a2 s . co m*/
     * @author Dominik Kppl Querying the Intent
     *         com.hughes.action.ACTION_SEARCH_DICT is the advanced query
     *         Arguments: SearchManager.QUERY -> the phrase to search from
     *         -> language in which the phrase is written to -> to which
     *         language shall be translated
     */
    if (intentAction != null && intentAction.equals("com.hughes.action.ACTION_SEARCH_DICT")) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        String from = intent.getStringExtra("from");
        if (from != null)
            from = from.toLowerCase(Locale.US);
        String to = intent.getStringExtra("to");
        if (to != null)
            to = to.toLowerCase(Locale.US);
        if (query != null) {
            getIntent().putExtra(C.SEARCH_TOKEN, query);
        }
        if (intent.getStringExtra(C.DICT_FILE) == null && (from != null || to != null)) {
            Log.d(LOG, "DictSearch: from: " + from + " to " + to);
            List<DictionaryInfo> dicts = application.getDictionariesOnDevice(null);
            for (DictionaryInfo info : dicts) {
                boolean hasFrom = from == null;
                boolean hasTo = to == null;
                for (IndexInfo index : info.indexInfos) {
                    if (!hasFrom && index.shortName.toLowerCase(Locale.US).equals(from))
                        hasFrom = true;
                    if (!hasTo && index.shortName.toLowerCase(Locale.US).equals(to))
                        hasTo = true;
                }
                if (hasFrom && hasTo) {
                    if (from != null) {
                        int which_index = 0;
                        for (; which_index < info.indexInfos.size(); ++which_index) {
                            if (info.indexInfos.get(which_index).shortName.toLowerCase(Locale.US).equals(from))
                                break;
                        }
                        intent.putExtra(C.INDEX_SHORT_NAME, info.indexInfos.get(which_index).shortName);

                    }
                    intent.putExtra(C.DICT_FILE, application.getPath(info.uncompressedFilename).toString());
                    break;
                }
            }

        }
    }
    /**
     * @author Dominik Kppl Querying the Intent Intent.ACTION_SEARCH is a
     *         simple query Arguments follow from android standard (see
     *         documentation)
     */
    if (intentAction != null && intentAction.equals(Intent.ACTION_SEARCH)) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        if (query != null)
            getIntent().putExtra(C.SEARCH_TOKEN, query);
    }
    /**
     * @author Dominik Kppl If no dictionary is chosen, use the default
     *         dictionary specified in the preferences If this step does
     *         fail (no default directory specified), show a toast and
     *         abort.
     */
    if (intent.getStringExtra(C.DICT_FILE) == null) {
        String dictfile = prefs.getString(getString(R.string.defaultDicKey), null);
        if (dictfile != null)
            intent.putExtra(C.DICT_FILE, application.getPath(dictfile).toString());
    }
    String dictFilename = intent.getStringExtra(C.DICT_FILE);

    if (dictFilename == null) {
        Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show();
        startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
        finish();
        return;
    }
    if (dictFilename != null)
        dictFile = new File(dictFilename);

    ttsReady = false;
    textToSpeech = new TextToSpeech(getApplicationContext(), new OnInitListener() {
        @Override
        public void onInit(int status) {
            ttsReady = true;
            updateTTSLanguage(indexIndex);
        }
    });

    try {
        final String name = application.getDictionaryName(dictFile.getName());
        this.setTitle("QuickDic: " + name);
        dictRaf = new RandomAccessFile(dictFile, "r");
        dictionary = new Dictionary(dictRaf);
    } catch (Exception e) {
        Log.e(LOG, "Unable to load dictionary.", e);
        if (dictRaf != null) {
            try {
                dictRaf.close();
            } catch (IOException e1) {
                Log.e(LOG, "Unable to close dictRaf.", e1);
            }
            dictRaf = null;
        }
        Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()), Toast.LENGTH_LONG)
                .show();
        startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
        finish();
        return;
    }
    String targetIndex = intent.getStringExtra(C.INDEX_SHORT_NAME);
    if (savedInstanceState != null && savedInstanceState.getString(C.INDEX_SHORT_NAME) != null) {
        targetIndex = savedInstanceState.getString(C.INDEX_SHORT_NAME);
    }
    indexIndex = 0;
    for (int i = 0; i < dictionary.indices.size(); ++i) {
        if (dictionary.indices.get(i).shortName.equals(targetIndex)) {
            indexIndex = i;
            break;
        }
    }
    Log.d(LOG, "Loading index " + indexIndex);
    index = dictionary.indices.get(indexIndex);
    setListAdapter(new IndexAdapter(index));

    // Pre-load the collators.
    new Thread(new Runnable() {
        public void run() {
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            final long startMillis = System.currentTimeMillis();
            try {
                TransliteratorManager.init(new TransliteratorManager.Callback() {
                    @Override
                    public void onTransliteratorReady() {
                        uiHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                onSearchTextChange(searchView.getQuery().toString());
                            }
                        });
                    }
                });

                for (final Index index : dictionary.indices) {
                    final String searchToken = index.sortedIndexEntries.get(0).token;
                    final IndexEntry entry = index.findExact(searchToken);
                    if (entry == null || !searchToken.equals(entry.token)) {
                        Log.e(LOG, "Couldn't find token: " + searchToken + ", "
                                + (entry == null ? "null" : entry.token));
                    }
                }
                indexPrepFinished = true;
            } catch (Exception e) {
                Log.w(LOG,
                        "Exception while prepping.  This can happen if dictionary is closed while search is happening.");
            }
            Log.d(LOG, "Prepping indices took:" + (System.currentTimeMillis() - startMillis));
        }
    }).start();

    String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.otf.jpg");
    if ("SYSTEM".equals(fontName)) {
        typeface = Typeface.DEFAULT;
    } else if ("SERIF".equals(fontName)) {
        typeface = Typeface.SERIF;
    } else if ("SANS_SERIF".equals(fontName)) {
        typeface = Typeface.SANS_SERIF;
    } else if ("MONOSPACE".equals(fontName)) {
        typeface = Typeface.MONOSPACE;
    } else {
        if ("FreeSerif.ttf.jpg".equals(fontName)) {
            fontName = "FreeSerif.otf.jpg";
        }
        try {
            typeface = Typeface.createFromAsset(getAssets(), fontName);
        } catch (Exception e) {
            Log.w(LOG, "Exception trying to use typeface, using default.", e);
            Toast.makeText(this, getString(R.string.fontFailure, e.getLocalizedMessage()), Toast.LENGTH_LONG)
                    .show();
        }
    }
    if (typeface == null) {
        Log.w(LOG, "Unable to create typeface, using default.");
        typeface = Typeface.DEFAULT;
    }
    final String fontSize = prefs.getString(getString(R.string.fontSizeKey), "14");
    try {
        fontSizeSp = Integer.parseInt(fontSize.trim());
    } catch (NumberFormatException e) {
        fontSizeSp = 14;
    }

    // ContextMenu.
    registerForContextMenu(getListView());

    // Cache some prefs.
    wordList = application.getWordListFile();
    saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false);
    clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey), false);
    Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry);

    onCreateSetupActionBarAndSearchView();

    // Set the search text from the intent, then the saved state.
    String text = getIntent().getStringExtra(C.SEARCH_TOKEN);
    if (savedInstanceState != null) {
        text = savedInstanceState.getString(C.SEARCH_TOKEN);
    }
    if (text == null) {
        text = "";
    }
    setSearchText(text, true);
    Log.d(LOG, "Trying to restore searchText=" + text);

    setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString());

    updateLangButton();
    searchView.requestFocus();

    // http://stackoverflow.com/questions/2833057/background-listview-becomes-black-when-scrolling
    //        getListView().setCacheColorHint(0);
}

From source file:jp.ksksue.app.terminal.AndroidUSBSerialMonitorLite.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_WORD_LIST_ACTIVITY) {
        if (resultCode == RESULT_OK) {
            try {
                String strWord = data.getStringExtra("word");
                etWrite.setText(strWord);
                // Set a cursor position last
                etWrite.setSelection(etWrite.getText().length());
            } catch (Exception e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
            }//  www .  j ava  2  s  . c  om
        }
    } else if (requestCode == REQUEST_PREFERENCE) {

        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

        String res = pref.getString("display_list", Integer.toString(DISP_CHAR));
        mDisplayType = Integer.valueOf(res);

        res = pref.getString("fontsize_list", Integer.toString(12));
        mTextFontSize = Integer.valueOf(res);
        mTvSerial.setTextSize(mTextFontSize);

        res = pref.getString("typeface_list", Integer.toString(3));
        switch (Integer.valueOf(res)) {
        case 0:
            mTextTypeface = Typeface.DEFAULT;
            break;
        case 1:
            mTextTypeface = Typeface.SANS_SERIF;
            break;
        case 2:
            mTextTypeface = Typeface.SERIF;
            break;
        case 3:
            mTextTypeface = Typeface.MONOSPACE;
            break;
        }
        mTvSerial.setTypeface(mTextTypeface);
        etWrite.setTypeface(mTextTypeface);

        res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
        mReadLinefeedCode = Integer.valueOf(res);

        res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
        mWriteLinefeedCode = Integer.valueOf(res);

        res = pref.getString("email_edittext", "@gmail.com");
        mEmailAddress = res;

        int intRes;

        res = pref.getString("baudrate_list", Integer.toString(9600));
        intRes = Integer.valueOf(res);
        if (mBaudrate != intRes) {
            mBaudrate = intRes;
            mSerial.setBaudrate(mBaudrate);
        }

        res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8));
        intRes = Integer.valueOf(res);
        if (mDataBits != intRes) {
            mDataBits = Integer.valueOf(res);
            mSerial.setDataBits(mDataBits);
        }

        res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE));
        intRes = Integer.valueOf(res);
        if (mParity != intRes) {
            mParity = intRes;
            mSerial.setParity(mParity);
        }

        res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1));
        intRes = Integer.valueOf(res);
        if (mStopBits != intRes) {
            mStopBits = intRes;
            mSerial.setStopBits(mStopBits);
        }

        res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF));
        intRes = Integer.valueOf(res);
        if (mFlowControl != intRes) {
            mFlowControl = intRes;
            if (mFlowControl == UartConfig.FLOW_CONTROL_ON) {
                mSerial.setDtrRts(true, true);
            } else {
                mSerial.setDtrRts(false, false);
            }
        }

        /*
        res = pref.getString("break_list", Integer.toString(FTDriver.FTDI_SET_NOBREAK));
        intRes = Integer.valueOf(res) << 14;
        if (mBreak != intRes) {
        mBreak = intRes;
        mSerial.setSerialPropertyBreak(mBreak, FTDriver.CH_A);
        mSerial.setSerialPropertyToChip(FTDriver.CH_A);
        }
        */

        res = pref.getString("play_interval", "3");
        intRes = Integer.valueOf(res);
        mPlayIntervalSeconds = intRes;
    }
}

From source file:com.mschlauch.comfortreader.FullscreenActivity.java

public void retreiveSavedOptions() {
    switchofallmenus = true;/*from   w  ww  . j  ava2 s .c o  m*/
    spinner.setVisibility(View.VISIBLE);
    String eins = "";
    new AsyncTask<String, Void, String>() {

        @Override
        protected String doInBackground(String... urlStr) {
            // do stuff on non-UI thread
            settingsload.reloadSelectedBook();

            wordsperminute = settingsload.getWordsPerMinute();
            segmenterObject.minblocksize = settingsload.getMinBlockSize();
            segmenterObject.maxblocksize = settingsload.getMaxBlockSize();
            segmenterObject.textcolor = settingsload.getTextColor();
            segmenterObject.emphasiscolor = settingsload.getFocusColor();
            segmenterObject.backgroundcolor = settingsload.getBackgroundColor();

            segmenterObject.maxcharactersperline = settingsload.getMaxBlockSize();
            segmenterObject.loadPreviewcolorString();

            int actual = settingsload.getGlobalPosition();
            segmenterObject.globalposition = actual;
            segmenterObject.globalpositionbefore = actual;
            //Load Content
            String text = settingsload.getTexttoRead() + "";
            String textdefault = getString(R.string.support_standarttext);
            Log.i("fullscreen", "text  is: " + text);

            segmenterObject.loadTexttoRead(textdefault);
            if (text.equals("standarttext")) {
                segmenterObject.loadTexttoRead(textdefault);
                segmenterObject.globalposition = 0;
                segmenterObject.emphasiscolor = Color.parseColor("#ffee00");
                segmenterObject.textcolor = Color.parseColor("#ffffff");
            } else {
                segmenterObject.loadTexttoRead(text);
            }

            if (text.length() > 16) {

            } else {
                //it is importanted that the default text is already segmentable.

            }
            Log.i("fullscreen 2", " real text  is: " + segmenterObject.texttoread);

            segmenterObject.loadallprehtmls();

            String out = "";
            return out;

        }

        @Override
        protected void onPostExecute(String htmlCode) {
            // do stuff on UI thread with the html

            contentView.setTextSize(settingsload.getFontSize());
            contentView.setBackgroundColor(settingsload.getBackgroundColor());

            String parole = settingsload.getOrientationMode();

            Log.i("Fullscreen", "orientation loading" + parole);
            if (parole.equals("1")) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
            } else if (parole.equals("2")) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
            } else if (parole.equals("0")) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
            }

            parole = settingsload.getFontName();

            Log.i("Fullscreen", "orientation loading" + parole);
            if (parole.equals("sans")) {
                contentView.setTypeface(Typeface.SANS_SERIF);
            } else if (parole.equals("serif")) {
                contentView.setTypeface(Typeface.SERIF);
            } else if (parole.equals("mono")) {
                contentView.setTypeface(Typeface.MONOSPACE);
            }

            spinner.setVisibility(View.GONE);

            switchofallmenus = false;
            previousButtonClicked(null);
            nextButtonClicked(null);

        }
    }.execute(eins);

    //Line Spacing...
    // contentView.setLineSpacing(0,(float) 1.28);

    //actual = retrieveNumber("maxlinelength");

    //settingsload.adjustGlobalPositionToPercentage(settingsload.getGlobalPositionSeekbarValue());

    //Log.i("fullscreen", "globalposition:" + actual);

    // get the seekbar etc right...

    //   startdialog();

}

From source file:com.jjoe64.graphview_demos.fragments.Home.java

void loadDefaultSettingValues() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String res = pref.getString("display_list", Integer.toString(DISP_CHAR));
    mDisplayType = Integer.valueOf(res);

    res = pref.getString("fontsize_list", Integer.toString(12));
    mTextFontSize = Integer.valueOf(res);

    res = pref.getString("typeface_list", Integer.toString(3));
    switch (Integer.valueOf(res)) {
    case 0:/*from   ww  w . j  av  a  2 s .c  om*/
        mTextTypeface = Typeface.DEFAULT;
        break;
    case 1:
        mTextTypeface = Typeface.SANS_SERIF;
        break;
    case 2:
        mTextTypeface = Typeface.SERIF;
        break;
    case 3:
        mTextTypeface = Typeface.MONOSPACE;
        break;
    }
    mTvSerial.setTypeface(mTextTypeface);
    //etWrite.setTypeface(mTextTypeface);

    res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
    mReadLinefeedCode = Integer.valueOf(res);

    res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
    mWriteLinefeedCode = Integer.valueOf(res);

    res = pref.getString("email_edittext", "@gmail.com");
    mEmailAddress = res;

    res = pref.getString("baudrate_list", Integer.toString(57600));
    mBaudrate = Integer.valueOf(res);

    res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8));
    mDataBits = Integer.valueOf(res);

    res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE));
    mParity = Integer.valueOf(res);

    res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1));
    mStopBits = Integer.valueOf(res);

    res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF));
    mFlowControl = Integer.valueOf(res);
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_moreMenu_license(final View anchor) {
    View v = UiHelper.inflateLayout(this, R.layout.info_dialog);
    TextView tv = ((TextView) v.findViewById(R.id.text));
    tv.setTypeface(Typeface.MONOSPACE);
    tv.setText(R.string.license_desc);/*from  w w w . j  ava 2  s .c o m*/
    AlertDialog.Builder bldr = new AlertDialog.Builder(this);
    bldr.setView(v);
    AlertDialog aDiag = bldr.create();
    aDiag.show();
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static Typeface toTypeface(final Context context, String fontFamily, String weight) {
    Typeface tf = Typeface.SANS_SERIF; // default
    if (weight != null) {
        if (fontFamily == null && weight != "regular") {
            fontFamily = "sans-serif-" + weight.toLowerCase();
        } else {//from w  ww. j  a va2s .  co  m
            fontFamily += "-" + weight.toLowerCase();
        }
    }
    if (fontFamily != null) {
        if ("monospace".equals(fontFamily)) {
            tf = Typeface.MONOSPACE;
        } else if ("serif".equals(fontFamily)) {
            tf = Typeface.SERIF;
        } else if ("sans-serif".equals(fontFamily)) {
            tf = Typeface.SANS_SERIF;
        } else {
            Typeface loadedTf = null;
            if (context != null) {
                try {
                    loadedTf = loadTypeface(context, fontFamily);

                } catch (Exception e) {
                    loadedTf = null;
                    Log.e(TAG, "Unable to load font " + fontFamily + ": " + e.getMessage());
                }
            }
            if (loadedTf == null) {
                Log.w(TAG, "Unsupported font: '" + fontFamily
                        + "' supported fonts are 'monospace', 'serif', 'sans-serif'.", Log.DEBUG_MODE);
            } else {
                tf = loadedTf;
            }
        }
    }
    return tf;
}

From source file:com.aujur.ebookreader.Configuration.java

private FontFamily getFontFamily(String fontKey, String defaultVal) {

    String fontFace = settings.getString(fontKey, defaultVal);

    if (!fontCache.containsKey(fontFace)) {

        if ("gen_book_bas".equals(fontFace)) {
            fontCache.put(fontFace, loadFamilyFromAssets(fontFace, "GentiumBookBasic"));
        } else if ("gen_bas".equals(fontFace)) {
            fontCache.put(fontFace, loadFamilyFromAssets(fontFace, "GentiumBasic"));
        } else if ("frankruehl".equalsIgnoreCase(fontFace)) {
            fontCache.put(fontFace, loadFamilyFromAssets(fontFace, "FrankRuehl"));
        } else {/*  w w w. j  a v a 2s.  co m*/

            Typeface face = Typeface.SANS_SERIF;
            if ("sans".equals(fontFace)) {
                face = Typeface.SANS_SERIF;
            } else if ("serif".equals(fontFace)) {
                face = Typeface.SERIF;
            } else if ("mono".equals(fontFace)) {
                face = Typeface.MONOSPACE;
            }

            fontCache.put(fontFace, new FontFamily(fontFace, face));
        }
    }

    return fontCache.get(fontFace);
}

From source file:com.slim.turboeditor.activity.MainActivity.java

void onPreferencesChanged(String key) {
    switch (key) {
    case SettingsProvider.EDITOR_WRAP_CONTENT:
        if (SettingsProvider.getBoolean(this, SettingsProvider.EDITOR_WRAP_CONTENT, false)) {
            mHorizontalScroll.removeView(mEditor);
            verticalScroll.removeView(mHorizontalScroll);
            verticalScroll.addView(mEditor);
        } else {//w  w w . ja va 2s  .c  om
            verticalScroll.removeView(mEditor);
            verticalScroll.addView(mHorizontalScroll);
            mHorizontalScroll.addView(mEditor);
        }
        break;
    case SettingsProvider.USE_MONOSPACE:
        if (SettingsProvider.getBoolean(this, SettingsProvider.USE_MONOSPACE, false)) {
            mEditor.setTypeface(Typeface.MONOSPACE);
        } else {
            mEditor.setTypeface(Typeface.DEFAULT);
        }
        break;
    case SettingsProvider.FONT_SIZE:
        mEditor.updatePadding();
        mEditor.setTextSize(SettingsProvider.getInt(this, SettingsProvider.FONT_SIZE, 16));
        break;
    case SettingsProvider.EDITOR_ENCODING:
        String oldEncoding, newEncoding;
        oldEncoding = currentEncoding;
        newEncoding = SettingsProvider.getString(this, SettingsProvider.EDITOR_ENCODING,
                Constant.DEFAULT_ENCODING);
        try {
            final byte[] oldText = mEditor.getText().toString().getBytes(oldEncoding);
            mEditor.disableTextChangedListener();
            mEditor.replaceTextKeepCursor(new String(oldText, newEncoding));
            mEditor.enableTextChangedListener();
            currentEncoding = newEncoding;
        } catch (UnsupportedEncodingException ignored) {
            try {
                final byte[] oldText = mEditor.getText().toString().getBytes(oldEncoding);
                mEditor.disableTextChangedListener();
                mEditor.replaceTextKeepCursor(new String(oldText, Constant.DEFAULT_ENCODING));
                mEditor.enableTextChangedListener();
            } catch (UnsupportedEncodingException ignored2) {
                // Ignored
            }
        }
        break;
    }
}

From source file:com.jjoe64.graphview_demos.fragments.CollectData.java

void loadDefaultSettingValues() {
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String res = pref.getString("display_list", Integer.toString(DISP_CHAR));
        mDisplayType = Integer.valueOf(res);

        res = pref.getString("fontsize_list", Integer.toString(12));
        mTextFontSize = Integer.valueOf(res);

        res = pref.getString("typeface_list", Integer.toString(3));
        switch (Integer.valueOf(res)) {
        case 0:/* w w  w.j a v a2 s. c o  m*/
            mTextTypeface = Typeface.DEFAULT;
            break;
        case 1:
            mTextTypeface = Typeface.SANS_SERIF;
            break;
        case 2:
            mTextTypeface = Typeface.SERIF;
            break;
        case 3:
            mTextTypeface = Typeface.MONOSPACE;
            break;
        }
        mTvSerial.setTypeface(mTextTypeface);
        //etWrite.setTypeface(mTextTypeface);

        res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
        mReadLinefeedCode = Integer.valueOf(res);

        res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF));
        mWriteLinefeedCode = Integer.valueOf(res);

        res = pref.getString("email_edittext", "@gmail.com");
        mEmailAddress = res;

        res = pref.getString("baudrate_list", Integer.toString(57600));
        mBaudrate = Integer.valueOf(res);

        res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8));
        mDataBits = Integer.valueOf(res);

        res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE));
        mParity = Integer.valueOf(res);

        res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1));
        mStopBits = Integer.valueOf(res);

        res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF));
        mFlowControl = Integer.valueOf(res);
    }