Example usage for android.os Bundle getCharArray

List of usage examples for android.os Bundle getCharArray

Introduction

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

Prototype

@Override
@Nullable
public char[] getCharArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:Main.java

/**
 * Extract a char[] received from the test package engine.
 * The char[] message is extracted via Bundle.getCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item. 
 * The original intent here is to retrieve Java Properties stored as a char[] suitable for deserialization 
 * via the Java Properties.load method.<br>
 * NOTE: This has not yet been tested!/*w w w . ja  va2  s  .  co m*/
 * @param Parcelable Bundle received from the test package engine
 * @return char[] suitable for Java Properties.load
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static char[] getParcelableProps(Parcelable parcelable) {
    Bundle bundle = (Bundle) parcelable;
    return bundle.getCharArray(BUNDLE_PROPERTIES);
}

From source file:com.mplayer_remote.SettingsForAPP.java

/**
  * Metoda wywoywana przez system Android przy starcie aktywnoci.
  * Tu nastpuje wyczytanie ustawie aplikacji i zainicjowanie GUI aktywnoci.
  * @see android.app.Activity#onCreate(android.os.Bundle)
  *//* w  ww . j  a va 2s.  c  o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(false);
    //ustawianie GUI
    setContentView(R.layout.layout_for_settingsforserverlist);
    settingsForAPPSharedPreferences = getSharedPreferences("settings_for_APP", 0);
    isThisFirstRunboolean = settingsForAPPSharedPreferences.getBoolean("is_this_first_run", true);
    isCryptoEnabledboolean = settingsForAPPSharedPreferences.getBoolean("is_crypto_enabled", true); //byo false
    showOnlyMediaTypeFilesBoolean = settingsForAPPSharedPreferences.getBoolean(SHOW_ONLY_MEDIA_TYPE_FILES,
            true);

    if (savedInstanceState == null) {
        Intent intent_from_ServerList = getIntent(); //getIntent() zwraca obiekt Intent ktry wystartowa Activity
        appPasswordcharArray = intent_from_ServerList.getCharArrayExtra("app_password");
    } else {
        appPasswordcharArray = savedInstanceState.getCharArray("appPasswordcharArray");
    }

    Log.v(TAG, "aktualny isThisFirstRunboolean: " + isThisFirstRunboolean);
    Log.v(TAG, "aktualny isCryptoEnabledboolean: " + isCryptoEnabledboolean);

    if (appPasswordcharArray != null) {
        String appPasswordcharArrayConvertedToString = new String(appPasswordcharArray);
        Log.v(TAG, "Aktuane appPasswordcharArray: " + appPasswordcharArrayConvertedToString);
    }

    //creating a XML

    Context mContext = getApplicationContext();
    aXMLReaderWriter = new XMLReaderWriter(mContext);

    if (isCryptoEnabledboolean == true && appPasswordcharArray != null) { //appPasswordcharArray == null 
        try {
            serverListArrayList = aXMLReaderWriter
                    .decryptFileWithXMLAndParseItToServerList(appPasswordcharArray);
        } catch (WrongPasswordException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption, Toast.LENGTH_SHORT)
                    .show();
            finish(); //something is wrong
        }
    } else {
        try {
            serverListArrayList = aXMLReaderWriter
                    .decryptFileWithXMLAndParseItToServerList("default_password".toCharArray());
        } catch (WrongPasswordException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Toast.makeText(getApplicationContext(), R.string.wrong_app_password_exeption, Toast.LENGTH_SHORT)
                    .show();
            finish(); //something is wrong
        }
    }

    useEencryptionCheckBox = (CheckBox) findViewById(R.id.use_encryption_in_SettingForServer_checkBox);
    useEencryptionCheckBox.setChecked(isCryptoEnabledboolean);
    useEencryptionCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (useEencryptionCheckBox.isChecked() == true) {
                isCryptoEnabledboolean = true;
                isThisFirstRunboolean = true;

            } else {
                isCryptoEnabledboolean = false;
            }

            SharedPreferences settings_for_activity_ServerList = getSharedPreferences("settings_for_APP", 0);
            SharedPreferences.Editor editor = settings_for_activity_ServerList.edit();
            editor.putBoolean("is_crypto_enabled", isCryptoEnabledboolean);
            editor.putBoolean("is_this_first_run", isThisFirstRunboolean);
            // Commit the edits!
            editor.commit();

            if (useEencryptionCheckBox.isChecked() == true) {
                Toast.makeText(getApplicationContext(),
                        R.string.text_for_toast_Edit_server_data_fill_server_password_field, Toast.LENGTH_LONG)
                        .show();
                aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                        appPasswordcharArray);
            } else {
                //appPasswordcharArray = "default_password".toCharArray();
                for (int i = 0; i < serverListArrayList.size(); i++) {
                    serverListArrayList.get(i).setPassword("".toCharArray());
                }
                aXMLReaderWriter.createEncryptedXMLFileWithServerList(serverListArrayList,
                        "default_password".toCharArray());
            }

        }
    });

    showOnlyMediaTypeFilesCheckBox = (CheckBox) findViewById((R.id.show_only_media_type_files_checkBox));
    showOnlyMediaTypeFilesCheckBox.setChecked(showOnlyMediaTypeFilesBoolean);
    showOnlyMediaTypeFilesCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

            if (showOnlyMediaTypeFilesCheckBox.isChecked() == true) {
                showOnlyMediaTypeFilesBoolean = true;
            } else {
                showOnlyMediaTypeFilesBoolean = false;
            }

            SharedPreferences settings_for_activity_ServerList = getSharedPreferences("settings_for_APP", 0);
            SharedPreferences.Editor editor = settings_for_activity_ServerList.edit();
            editor.putBoolean(SHOW_ONLY_MEDIA_TYPE_FILES, showOnlyMediaTypeFilesBoolean);
            //Commit the edits!
            editor.commit();
        }
    });

    knowFileExtensionsTextView = (TextView) findViewById(R.id.know_file_extensions);
    knowFileExtensionsTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.v(TAG, "klikem knowFileExtensionsTextView");
            DialogFragment newFragment = new KnowFileExtensionsDialogFragment();
            newFragment.show(getSupportFragmentManager(), "KnowFileExtensionsDialogFragment");

        }
    });

}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindFragmentArgument(Fragment receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/*from w  w w . j  a  va2  s. c  o m*/
        FragmentArgument fragmentArgument = field.getAnnotation(FragmentArgument.class);
        if (fragmentArgument != null) {
            try {
                Bundle bundle = receiver.getArguments();
                if (bundle != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, bundle.getBoolean(fragmentArgument.value()));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, bundle.getByte(fragmentArgument.value()));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, bundle.getChar(fragmentArgument.value()));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, bundle.getDouble(fragmentArgument.value()));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, bundle.getFloat(fragmentArgument.value()));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, bundle.getInt(fragmentArgument.value()));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, bundle.getLong(fragmentArgument.value()));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, bundle.getShort(fragmentArgument.value()));
                    } else if (type == String.class) {
                        field.set(receiver, bundle.getString(fragmentArgument.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, bundle.getBooleanArray(fragmentArgument.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, bundle.getByteArray(fragmentArgument.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, bundle.getCharArray(fragmentArgument.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, bundle.getDoubleArray(fragmentArgument.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, bundle.getFloatArray(fragmentArgument.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, bundle.getIntArray(fragmentArgument.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, bundle.getLongArray(fragmentArgument.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, bundle.getShortArray(fragmentArgument.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, bundle.getStringArray(fragmentArgument.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, bundle.getSerializable(fragmentArgument.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, bundle.getBundle(fragmentArgument.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.facebook.LegacyTokenCacheTest.java

@Test
public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);/*  w  w w  . jav a 2s. c  o  m*/
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application);
    cache.save(originalBundle);

    LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);
    Bundle cachedBundle = cache2.load();

    assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
            cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY),
            cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY),
            cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
            cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY),
            cachedBundle.getStringArrayList(STRING_LIST_KEY));
    assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY),
            cachedBundle.getSerializable(SERIALIZABLE_KEY));
}