Example usage for android.os Bundle putSerializable

List of usage examples for android.os Bundle putSerializable

Introduction

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

Prototype

@Override
public void putSerializable(@Nullable String key, @Nullable Serializable value) 

Source Link

Document

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

Usage

From source file:com.irccloud.android.activity.MainActivity.java

@Override
public void onSaveInstanceState(Bundle state) {
    super.onSaveInstanceState(state);
    if (server != null)
        state.putInt("cid", server.cid);
    if (buffer != null) {
        state.putInt("bid", buffer.bid);
        if (messageTxt != null && messageTxt.getText() != null)
            buffer.draft = messageTxt.getText().toString();
        else/* w w w  .  ja  v a 2s.c  o  m*/
            buffer.draft = null;
    }
    state.putSerializable("backStack", backStack);
    if (imageCaptureURI != null)
        state.putString("imagecaptureuri", imageCaptureURI.toString());
}

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 ww  . j  ava  2 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);
    } 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) {
        }
    }
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putSerializable(STATE_DISPLAY_MODE, mDisplayMode);
    outState.putBoolean(STATE_MESSAGE_LIST_WAS_DISPLAYED, mMessageListWasDisplayed);
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

public static ConversationGroupFragment newInstance(Groups grupo) {
    ConversationGroupFragment fragment = new ConversationGroupFragment();
    Bundle args = new Bundle();
    args.putSerializable(C.c_targets_group, grupo);
    fragment.setArguments(args);//from w  ww  .  j a va 2s. com
    return fragment;
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public static ConversationChatFragment newInstance(Contact contact) {
    ConversationChatFragment fragment = new ConversationChatFragment();
    Bundle args = new Bundle();
    args.putSerializable(C.contact, contact);
    fragment.setArguments(args);//from   ww  w.j a  va2s.  co  m
    return fragment;
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    if (mWorkspace.getChildCount() > 0) {
        outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPageOffsetFromCustomContent());
    }//from w  w  w  .  j a v a 2  s  .  c  o m
    super.onSaveInstanceState(outState);

    outState.putInt(RUNTIME_STATE, mState.ordinal());
    // We close any open folder since it will not be re-opened, and we need to make sure
    // this state is reflected.
    closeFolder();

    if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screenId > -1 && mWaitingForResult) {
        outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container);
        outState.putLong(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screenId);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, mPendingAddInfo.spanX);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, mPendingAddInfo.spanY);
        outState.putParcelable(RUNTIME_STATE_PENDING_ADD_WIDGET_INFO, mPendingAddWidgetInfo);
        outState.putInt(RUNTIME_STATE_PENDING_ADD_WIDGET_ID, mPendingAddWidgetId);
    }

    // Save the current widgets tray?
    // TODO(hyunyoungs)
    outState.putSerializable(RUNTIME_STATE_VIEW_IDS, mItemIdToViewId);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onSaveInstanceState(outState);
    }
}

From source file:uf.edu.encDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.encdetail_activity);
    context = this.getApplicationContext();
    TextView tv = null;/*from   w  ww.  j av a2s . co m*/
    SeekBar sb = null;
    Button b = null;
    Bundle bundle = this.getIntent().getExtras();
    Log.i("TAG", "encDetailActivity:onCreate,  Max Trust =" + getString(R.string.TrustSliderMax));
    MaxTrust = Integer.parseInt(getString(R.string.TrustSliderMax)) / 2;

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case DialogInterface.BUTTON_POSITIVE:
                //Okay clicked.
                break;

            case DialogInterface.BUTTON_NEGATIVE:
                //No button clicked
                break;
            }
        }
    };

    //builder.setMessage("Are you sure?").setPositiveButton("Okay", dialogClickListener);

    final EncUser encUser = (EncUser) bundle.getSerializable("userdata");
    final ArrayList<String> Address = (ArrayList<String>) bundle.getSerializable("useraddress");
    if (encUser == null) {
        Log.i(TAG, "encDetailsActivity: parameter received was null");
    }
    //Name
    tv = (TextView) findViewById(R.id.encdetail_name);
    tv.setText(encUser.Name);
    //Mac
    tv = (TextView) findViewById(R.id.encdetail_mac);
    tv.setText(encUser.Mac);
    tv.setOnClickListener(new View.OnClickListener() { //event listener to fetch more info abt a user.
        @Override
        public void onClick(View v) {
            iTrust.cd.write("Registration Lookup requested for " + encUser.Mac);
            Toast.makeText(encDetailActivity.this, "Please wait while we lookup the information",
                    Toast.LENGTH_LONG).show();
            String data = getData(encUser.Mac).replace('\n', ' ').trim();
            String message = null;
            if (data.substring(0, 5).compareToIgnoreCase("Error") == 0) {
                message = "No more info available for this device";
            } else {
                data = data.replace('\'', ' '); //remove single quotes
                data = data.replace(')', ' ').trim(); //remove closing brackets.
                StringTokenizer tok = new StringTokenizer(data.substring(1), ",");
                message = "Name: " + tok.nextToken() + " " + tok.nextToken() + "\n" + "Email: "
                        + tok.nextToken() + "\n" + "Profile: " + tok.nextToken();
            }
            //Toast.makeText(encDetailActivity.this, getData(encUser.Mac), Toast.LENGTH_LONG).show();
            builder.setMessage(message);
            builder.show();
        }
    });
    //lasttime
    tv = (TextView) findViewById(R.id.encdetail_lasttime);
    tv.setText((new java.util.Date((long) encUser.lastEncounterTime * 1000)).toString());
    tv.setOnClickListener(new View.OnClickListener() { //To generate graph
        @Override
        public void onClick(View v) {
            Intent intent = barchartIntent(encUser.timeSeries, encUser.Mac, encUser.Name);
            startActivity(intent);
        }
    });

    //tv.setText(Integer.toString(encUser.lastEncounterTime)); 
    //FE
    tv = (TextView) findViewById(R.id.encdetail_FE);
    tv.setText(Float.toString(encUser.score[0]));
    tv = (TextView) findViewById(R.id.encdetail_decayFE);
    tv.setText(Float.toString(encUser.decayScore[0] * ((float) Math.pow(.5,
            (float) (((float) System.currentTimeMillis() / 1000) - (float) encUser.lastEncounterTime)
                    / (float) 15552000.0F))));
    //DE
    tv = (TextView) findViewById(R.id.encdetail_DE);
    tv.setText(Float.toString(encUser.score[1]));
    tv = (TextView) findViewById(R.id.encdetail_decayDE);
    tv.setText(Float.toString(encUser.decayScore[1] * ((float) Math.pow(.5,
            (float) (((float) System.currentTimeMillis() / 1000) - (float) encUser.lastEncounterTime)
                    / (float) 15552000.0F))));
    //LV-C
    tv = (TextView) findViewById(R.id.encdetail_LVC);
    tv.setText(Float.toString(encUser.score[2]));
    //LV-D
    tv = (TextView) findViewById(R.id.encdetail_LVD);
    tv.setText(Float.toString(encUser.score[3]));
    //combined 
    //FE
    tv = (TextView) findViewById(R.id.encdetail_comb);
    tv.setText(Float.toString(encUser.score[4]));

    //check the toggle button state

    sb = (SeekBar) findViewById(R.id.encdetail_trust);
    //since Seekbar cannot go into -ve values we scale -Max Value to Max Value
    sb.setProgress(encUser.trusted + MaxTrust);
    tv = (TextView) findViewById(R.id.CurrentTrustValue);
    tv.setText(TrustArray[encUser.trusted + MaxTrust]);

    sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        TextView tvcurrent = (TextView) findViewById(R.id.CurrentTrustValue);

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser == true) {
                Log.i(TAG, "encDetailsActivity: User changed value for Trust to " + progress);
                encUser.trusted = progress - MaxTrust;
                tvcurrent.setText(TrustArray[progress]);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

        }
    });

    b = (Button) findViewById(R.id.encdetail_done);
    b.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            iTrust.cd.write("Trust Value changed for this user :" + encUser.Mac + " to:" + encUser.trusted);
            Bundle bundle = new Bundle();
            Intent returnIntent = new Intent();
            bundle.putSerializable("Object", encUser);
            returnIntent.putExtras(bundle);
            //returnIntent.putExtra("TrustSet",trustResult);
            encDetailActivity.this.setResult(Activity.RESULT_OK, returnIntent);
            finish();
        }
    });

    //show map
    tv = (TextView) findViewById(R.id.encdetail_map);
    tv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            iTrust.cd.write("Map lookup for encounter user " + encUser.Mac);
            Bundle bundle = new Bundle();
            Intent newIntent = new Intent(context, map.class);
            bundle.putSerializable("useraddress", Address);
            newIntent.putExtras(bundle);
            startActivity(newIntent);
        }
    });

}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable("contacto", this.contact);
}

From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

private void searchUser(final int id) {
    RequestParams params = new RequestParams();
    params.put("id", MyApplication.getInstance().UserInfo.getUserId());
    params.put("friendId", id);
    HttpUtil.post(Url.dependIDGetUserInfo, params, new JsonHttpResponseHandler() {
        @Override//from  www  .j  a  v  a 2  s . com
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                if (response.getInt("code") == 0) {
                    JSONObject jsonObject = response.getJSONObject("dataObject");
                    UserInfo UserInfo = new UserInfo();
                    UserInfo.setUserId(jsonObject.getInt("id"));
                    //                        UserInfo.setCreatedTime(jsonObject.getString("createdTime"));
                    //                        UserInfo.setLocked(jsonObject.getBoolean("isLocked"));
                    //                        UserInfo.setLastModifiedTime(jsonObject.getString("lastModifiedTime"));
                    //                        UserInfo.setLastModifier(jsonObject.getString("lastModifier"));
                    UserInfo.setUsername(jsonObject.getString("username"));
                    UserInfo.setPassword(jsonObject.getString("password"));
                    UserInfo.setAccountNumber(jsonObject.getString("accountNumber"));
                    UserInfo.setQrCode(jsonObject.getString("qrCode"));
                    UserInfo.setDistrictId(jsonObject.getString("districtId"));
                    UserInfo.setSex(jsonObject.getString("sex"));
                    UserInfo.setThermalSignatrue(jsonObject.getString("thermalSignatrue"));
                    UserInfo.setPhoneNumber(jsonObject.getString("phoneNumber"));
                    UserInfo.setUserEmail(jsonObject.getString("userEmail"));
                    UserInfo.setBalance(jsonObject.getString("balance"));
                    UserInfo.setAvatar(jsonObject.getString("avatar"));
                    UserInfo.setBackAvatar(jsonObject.getString("backAvatar"));
                    //                        UserInfo.setLoginFailedCount(jsonObject.getInt("loginFailedCount"));
                    UserInfo.setIsfriend(jsonObject.getInt("isfriend"));
                    UserInfo.setLabelName(jsonObject.getString("labelName"));
                    //                        UserInfo.setImages(jsonObject.getString("images"));
                    Bundle Bundle = new Bundle();
                    Bundle.putSerializable("data", UserInfo);
                    //TODO 
                    //                        ActivityUtil.next(getActivity(), FriendDetailActivity.class, Bundle);
                    //                        ActivityUtil.next(getActivity(), FriendInfoActivity.class, Bundle);
                    startActivity(new Intent(getActivity(), FriendInfoActivity.class));
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                finish();
            }
        }

        @Override
        public void onFinish() {
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            DBLog.e("tag", statusCode + ":" + responseString);
            ShowDialog.dissmiss();
        }
    });
}