Example usage for android.os Bundle putCharArray

List of usage examples for android.os Bundle putCharArray

Introduction

In this page you can find the example usage for android.os Bundle putCharArray.

Prototype

@Override
public void putCharArray(@Nullable String key, @Nullable char[] value) 

Source Link

Document

Inserts a char array value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:Main.java

/**
 * Create a Parcelable Bundle containing a char[] for transport to the test package engine.
 * The char[] message is stored via Bundle.putCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item. 
 * The original intent here is to store Java Properties in the Bundle that were serialized via 
 * the Java Properties.store method.<br>
 * NOTE: This has not yet been tested!/*from   ww  w.j  a v  a  2s  .c  om*/
 * @param char[] (Properties) to send across processes.
 * @return Parcelable Bundle
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static Parcelable setParcelableProps(char[] bytes) {
    Bundle bundle = new Bundle();
    bundle.putCharArray(BUNDLE_PROPERTIES, bytes);
    bundle.setClassLoader(Bundle.class.getClassLoader());
    return bundle;
}

From source file:com.facebook.LegacyTokenCacheTest.java

private static void putCharArray(String key, Bundle bundle) {
    bundle.putCharArray(key, getCharArray());
}

From source file:Main.java

/**
 * Concatenate two Parcelable Bundles containing char[] to form one Parcelable.<br>
 * The char[] message is stored via Bundle.putCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item.<br>
 *  /*from   www .ja  v a  2 s.c o m*/
 * @param one       Parcelable Bundle, containing char[] message
 * @param another    Parcelable Bundle, containing char[] message
 * @return Parcelable Bundle, including Parcelable one and another.
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static Parcelable assembleParcelProps(Parcelable one, Parcelable another) {
    Bundle bundle = new Bundle();
    char[] characters = null;
    char[] characters1 = null;
    char[] characters2 = null;
    int length = 0;

    if (one != null) {
        characters1 = ((Bundle) one).getCharArray(BUNDLE_PROPERTIES);
        if (characters1 != null)
            length += characters1.length;
    }
    if (another != null) {
        characters2 = ((Bundle) another).getCharArray(BUNDLE_PROPERTIES);
        if (characters2 != null)
            length += characters2.length;
    }

    characters = new char[length];

    if (characters1 != null && characters2 != null) {
        System.arraycopy(characters1, 0, characters, 0, characters1.length);
        System.arraycopy(characters2, 0, characters, characters1.length, characters2.length);
    } else if (characters1 != null && characters2 == null) {
        System.arraycopy(characters1, 0, characters, 0, characters1.length);
    } else if (characters1 == null && characters2 != null) {
        System.arraycopy(characters2, 0, characters, 0, characters2.length);
    }

    bundle.putCharArray(BUNDLE_PROPERTIES, characters);
    bundle.setClassLoader(Bundle.class.getClassLoader());
    return bundle;
}

From source file:com.mplayer_remote.SettingsForAPP.java

/**
 * Metoda wywoywana przez system Android przed zniszczeniem aktywnoci, suy do zapamitywania stanu aktywnoci. Tu do zapamitania hasa aplikacji pomidzy restartami aktywnoci.  
 * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
 *///from   w w w.j ava2 s .c  o  m
@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putCharArray("appPasswordcharArray", appPasswordcharArray);
}

From source file:com.facebook.appevents.AppEventsLoggerTests.java

public void testSimpleCall() throws InterruptedException {
    AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY);

    AccessToken accessToken1 = getAccessTokenForSharedUser();
    AccessToken accessToken2 = getAccessTokenForSharedUser(SECOND_TEST_USER_TAG);

    AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), accessToken1);
    AppEventsLogger logger2 = AppEventsLogger.newLogger(getActivity(), accessToken2);

    final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver();
    waitForBroadcastReceiver.incrementExpectCount();

    final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());

    try {//from  ww  w  .j  a  v  a 2  s. c o  m
        // Need to get notifications on another thread so we can wait for them.
        runOnBlockerThread(new Runnable() {
            @Override
            public void run() {
                broadcastManager.registerReceiver(waitForBroadcastReceiver,
                        new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED));
            }
        }, true);

        logger1.logEvent("an_event");
        logger2.logEvent("another_event");

        // test illegal event name and event key, should not crash in non-debug environment.
        logger1.logEvent("$illegal_event_name");
        Bundle params = new Bundle();
        params.putString("illegal%key", "good_value");
        logger1.logEvent("legal_event_name", params);
        char[] val = { 'b', 'a', 'd' };
        params.putCharArray("legal_key", val);
        logger1.logEvent("legal_event", params);

        logger1.flush();

        waitForBroadcastReceiver.waitForExpectedCalls();

        closeBlockerAndAssertSuccess();
    } finally {
        broadcastManager.unregisterReceiver(waitForBroadcastReceiver);
    }
}

From source file:me.xiaopan.android.inject.sample.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    listView = new ListView(getBaseContext());
    setContentView(listView);// w w w  .  j  a v a  2  s  . c  o  m

    // SharedPreferences?
    PreferenceUtils.putBoolean(getBaseContext(), KEY_BOOLEAN, true);
    PreferenceUtils.putFloat(getBaseContext(), KEY_FLOAT, 10000f);
    PreferenceUtils.putInt(getBaseContext(), KEY_INT, 2000);
    PreferenceUtils.putLong(getBaseContext(), KEY_LONG, 50000);
    PreferenceUtils.putString(getBaseContext(), KEY_STRING, "Preference String");
    Set<String> stringSet = new HashSet<String>();
    stringSet.add("String Set 1");
    stringSet.add("String Set 2");
    stringSet.add("String Set 3");
    stringSet.add("String Set 4");
    PreferenceUtils.putStringSet(getBaseContext(), KEY_STRING_SET, stringSet);
    MyBean bean2 = new MyBean();
    bean2.setEmail("sky@xiaopan.me2");
    bean2.setName("?2");
    bean2.setSex("2");
    PreferenceUtils.putObject(getBaseContext(), KEY_JSON, bean2);
    PreferenceUtils.putString(getBaseContext(), KEY_ENUM, Sex.WOMAN.name());

    // ??
    String[] items = new String[] { "", "?", "FragmentDialog",
            "InjectAdapter", "InjectExpandableListAdapter" };
    listView.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,
            android.R.id.text1, items));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position <= 2) {
                Bundle bundle = new Bundle();
                bundle.putBoolean(MainActivity.PARAM_BOOLEAN, true);
                bundle.putBooleanArray(MainActivity.PARAM_BOOLEAN_ARRAY, new boolean[] { true, false, true });
                bundle.putByte(MainActivity.PARAM_BYTE, (byte) 110);
                bundle.putByteArray(MainActivity.PARAM_BYTE_ARRAY, new byte[] { 111, 112, 113 });
                bundle.putChar(MainActivity.PARAM_CHAR, 'R');
                bundle.putCharArray(MainActivity.PARAM_CHAR_ARRAY, new char[] { 'c', 'h', 'a', 'r' });
                bundle.putCharSequence(MainActivity.PARAM_CHAR_SEQUENCE, "CharSequence");
                bundle.putCharSequenceArray(MainActivity.PARAM_CHAR_SEQUENCE_ARRAY,
                        new CharSequence[] { "Char", " ", "Sequence" });
                bundle.putDouble(MainActivity.PARAM_DOUBLE, 12.00d);
                bundle.putDoubleArray(MainActivity.PARAM_DOUBLE_ARRAY, new double[] { 12.01d, 12.02d, 12.03d });
                bundle.putFloat(MainActivity.PARAM_FLOAT, 13.00f);
                bundle.putFloatArray(MainActivity.PARAM_FLOAT_ARRAY, new float[] { 13.01f, 13.02f, 13.03f });
                bundle.putInt(MainActivity.PARAM_INT, 120);
                bundle.putIntArray(MainActivity.PARAM_INT_ARRAY, new int[] { 121, 122, 123, });
                bundle.putLong(MainActivity.PARAM_LONG, 12345);
                bundle.putLongArray(MainActivity.PARAM_LONG_ARRAY, new long[] { 12346, 12347, 12348 });
                bundle.putShort(MainActivity.PARAM_SHORT, (short) 2);
                bundle.putShortArray(MainActivity.PARAM_SHORT_ARRAY, new short[] { 3, 4, 5 });
                bundle.putString(MainActivity.PARAM_STRING, "String");
                bundle.putStringArray(MainActivity.PARAM_STRING_ARRAY,
                        new String[] { "String1", "String2", "String3" });

                // ??JSONBundle
                MyBean bean = new MyBean();
                bean.setEmail("sky@xiaopan.me");
                bean.setName("?");
                bean.setSex("");
                bundle.putString(PARAM_STRING_JSON, new Gson().toJson(bean));

                bundle.putString(MainActivity.PARAM_STRING_ENUM, Sex.WOMAN.name());

                // 
                ArrayList<String> stringList = new ArrayList<String>();
                stringList.add("ArrayList String 1");
                stringList.add("ArrayList String 2");
                stringList.add("ArrayList String 3");
                bundle.putStringArrayList(MainActivity.PARAM_STRING_ARRAY_LIST, stringList);
                switch (position) {
                case 0:
                    Second.SECOND_CHRONOGRAPH.lap();
                    Intent intent = new Intent(getBaseContext(), InjectTestActivity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    break;
                case 1:
                    Second.SECOND_CHRONOGRAPH.lap();
                    Intent intent2 = new Intent(getBaseContext(), NormalActivity.class);
                    intent2.putExtras(bundle);
                    startActivity(intent2);
                    break;
                case 2:
                    Second.SECOND_CHRONOGRAPH.lap();
                    new TestDialogFragment().show(getSupportFragmentManager(), "");
                    break;
                }
            } else {
                Class<?> targetClass = null;
                if (position == 3) {
                    targetClass = InjectAdapterActivity.class;
                } else if (position == 4) {
                    targetClass = InjectExpandableListAdapterActivity.class;
                }
                if (targetClass != null) {
                    startActivity(new Intent(getBaseContext(), targetClass));
                }
            }
        }
    });
}

From source file:com.haibison.android.lockpattern.LockPatternFragment.java

/**
 * Finishes activity with {@link Activity#RESULT_OK}.
 *
 * @param pattern/*from  w  ww  .  j a v a 2 s. c  o m*/
 *            the pattern, if getActivity() is in mode creating pattern. In any
 *            cases, it can be set to {@code null}.
 */
private void finishWithResultOk(char[] pattern) {
    if (ACTION_CREATE_PATTERN.equals(fa.getIntent().getAction()))
        mIntentResult.putExtra(EXTRA_PATTERN, pattern);
    else {
        /*
         * If the user was "logging in", minimum try count can not be zero.
         */
        mIntentResult.putExtra(EXTRA_RETRY_COUNT, mRetryCount + 1);
    }

    fa.setResult(fa.RESULT_OK, mIntentResult);

    /*
     * ResultReceiver
     */
    ResultReceiver receiver = fa.getIntent().getParcelableExtra(EXTRA_RESULT_RECEIVER);
    if (receiver != null) {
        Bundle bundle = new Bundle();
        if (ACTION_CREATE_PATTERN.equals(fa.getIntent().getAction()))
            bundle.putCharArray(EXTRA_PATTERN, pattern);
        else {
            /*
             * If the user was "logging in", minimum try count can not be
             * zero.
             */
            bundle.putInt(EXTRA_RETRY_COUNT, mRetryCount + 1);
        }
        receiver.send(fa.RESULT_OK, bundle);
    }

    /*
     * PendingIntent
     */
    PendingIntent pi = fa.getIntent().getParcelableExtra(EXTRA_PENDING_INTENT_OK);
    if (pi != null) {
        try {
            pi.send(getActivity(), fa.RESULT_OK, mIntentResult);
        } catch (Throwable t) {
            Log.e(CLASSNAME, "Error sending PendingIntent: " + pi, t);
        }
    }

    fa.finish();
}

From source file:com.facebook.SharedPreferencesTokenCache.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }// www . jav a2 s  .  c o  m
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    }
}

From source file:com.facebook.LegacyTokenHelper.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }//  w  w w  .  ja v  a  2s .co m
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
        try {
            String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
            @SuppressWarnings("unchecked")
            Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
            bundle.putSerializable(key, enumValue);
        } catch (ClassNotFoundException e) {
        } catch (IllegalArgumentException e) {
        }
    }
}