Example usage for android.os Bundle getParcelable

List of usage examples for android.os Bundle getParcelable

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> T getParcelable(@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:com.tdispatch.passenger.fragment.SearchAddressFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle args = getArguments();
    if (args != null) {
        mType = args.getInt(Const.Bundle.TYPE);
        mAddress = args.getParcelable(Const.Bundle.LOCATION);
    } else {/*  www.  ja va2 s.co  m*/
        throw new IllegalArgumentException("Arguments not passed");
    }

    // Check to see if a voice recognition activity is present on device
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> activities = pm
            .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    mVoiceSearchAvailable = (activities.size() != 0);
}

From source file:com.thunder.iap.IAPActivity.java

/**
 * this methods is needed when a user wants to buy a subscription
 * @param sku/* ww  w  .j  a v a 2s  .  c o m*/
 * @param developerPayload
 * @param buySubscriptionListener
 */
public void buySubscription(final String sku, final String developerPayload,
        final BuySubscriptionListener buySubscriptionListener) {
    this.buySubscriptionListener = buySubscriptionListener;
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Bundle bundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", developerPayload);
                PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT");
                if (bundle.getInt("RESPONSE_CODE") == 0) {
                    // Start purchase flow (this brings up the Google Play UI).
                    // Result will be delivered through onActivityResult().
                    try {
                        startIntentSenderForResult(pendingIntent.getIntentSender(), RC_SUBS_BUY, new Intent(),
                                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                        buySubscriptionListener.onError(e);
                    }
                } else {
                    buySubscriptionListener.onServerError(bundle);
                }
            } catch (RemoteException e) {
                e.printStackTrace();
                buySubscriptionListener.onError(e);
            }
        }
    }).start();
}

From source file:com.android.settings.locationprivacy.LocationPrivacyDialog.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lp_dialog);//from w  ww .j  ava  2 s .c  om
    lpManager = new LocationPrivacyManager(this);
    sharePrivacySettings = lpManager.isSharePrivacySettings();
    showCommunityAdvice = lpManager.isShowCommunityAdvice();

    res = getResources();
    Bundle extras = getIntent().getExtras();
    app = extras.getParcelable("app");
    useStarsInDialog = lpManager.isUseStarsInDialog();
    choosen = app.getPresetConfig();

    list = (ListView) findViewById(R.id.lp_dialog_listview);
    ok_btn = (Button) findViewById(R.id.lp_dialog_ok);
    intro = (TextView) findViewById(R.id.lp_dialog_intro);
    community = (TextView) findViewById(R.id.lp_dialog_community_value);
    cancel = (TextView) findViewById(R.id.lp_dialog_cancel);
    border = (View) findViewById(R.id.lp_dialog_border_vertical);
    progress = (ProgressBar) findViewById(R.id.lp_dialog_progress);
    ok_btn.setOnClickListener(this);

    intro.setText(app.getLabel(getPackageManager()) + " " + res.getString(R.string.lp_dialog_intro));

    if (showCommunityAdvice) {
        new Thread(new DataFromWebservice(app.getPackagename())).start();
        community.setText(R.string.lp_dialog_get_from_webservice);
        community.setVisibility(View.VISIBLE);
        progress.setVisibility(View.VISIBLE);
    }
    ArrayList<Integer> icons = new ArrayList<Integer>();
    icons.add(R.drawable.lp_on_light);
    icons.add(R.drawable.lp_street_light);
    icons.add(R.drawable.lp_postalcode_light);
    icons.add(R.drawable.lp_city_light);
    icons.add(R.drawable.lp_off_light);

    adapter = new LPPresetConfigAdapter(icons, getResources().getStringArray(R.array.preconfigs), this, this);
    if (app.getPresetConfig() > -1) {
        cancel.setVisibility(View.VISIBLE);
        cancel.setOnClickListener(this);
        border.setVisibility(View.VISIBLE);
        ok_btn.setEnabled(true);

        adapter.setChecked(app.getPresetConfig());
        needRestartActivity = false;

    }
    list.setAdapter(adapter);

    this.setFinishOnTouchOutside(false);

    if (useStarsInDialog) {
        mHandler = new Handler(getMainLooper()) {
            public void handleMessage(Message inputMessage) {
                if (inputMessage.what == RECIEVED_DATA) {
                    progress.setVisibility(View.GONE);
                    int[] stars = (int[]) inputMessage.obj;
                    int sum = inputMessage.arg1;
                    if (sum > 10) {
                        adapter.setStars(stars);
                        adapter.notifyDataSetChanged();
                        community.setText(R.string.lp_dialog_stars);
                    } else {
                        community.setText(R.string.lp_dialog_user_choice_no_recommendation);
                    }

                } else if (inputMessage.what == ERROR) {
                    progress.setVisibility(View.GONE);
                    community.setText(R.string.lp_dialog_error);
                }
            }
        };
    } else {
        mHandler = new Handler(getMainLooper()) {
            public void handleMessage(Message inputMessage) {
                if (inputMessage.what == RECIEVED_DATA) {
                    progress.setVisibility(View.GONE);
                    String[] presets = LocationPrivacyDialog.this.getResources()
                            .getStringArray(R.array.preconfigs_short);
                    int[] values = (int[]) inputMessage.obj;
                    int sum = inputMessage.arg1;
                    if (sum > 10) {

                        // to Do: add String value
                        String uservote = res.getString(R.string.lp_dialog_user_choice) + " ";
                        for (int i = 0; i < values.length; i++) {
                            int max = 0;
                            for (int j = 1; j < values.length; j++) {
                                int valueTmp = values[j];
                                if (values[max] < valueTmp) {
                                    max = j;
                                }
                            }
                            int value = values[max];
                            double percent = (double) value / (double) sum;
                            if (percent > 0.2) {
                                uservote += ((int) (percent * 100)) + "% " + presets[max] + ", ";
                            } else {
                                break;
                            }
                            values[max] = -1;
                        }
                        uservote = uservote.substring(0, uservote.length() - 2);
                        community.setText(uservote);
                    } else {
                        community.setText(R.string.lp_dialog_user_choice_no_recommendation);
                    }

                } else if (inputMessage.what == ERROR) {
                    progress.setVisibility(View.GONE);
                    community.setText(R.string.lp_dialog_error);
                }
            }
        };
    }
}

From source file:com.flat20.fingerplay.FingerPlayActivity.java

private void subscribe() {
    try {//w  w w  .  j  a  v  a  2s.  c  o m
        Bundle bundle = mBillingService.getBuyIntent(3, getPackageName(), IAP_SUBS_KEY, "subs", null);
        PendingIntent pendingIntent = bundle.getParcelable("BUY_INTENT");
        if (bundle.getInt("RESPONSE_CODE") == 0) {
            startIntentSenderForResult(pendingIntent.getIntentSender(), REQUEST_PURCHASE, new Intent(), 0, 0,
                    0);
        } else {
            unableToVerifyLicense(getString(R.string.billing_error_during_process), true);
        }
    } catch (Exception e) {
        Log.e("Fingerplay", "Error subscribing", e);
        unableToVerifyLicense(getString(R.string.billing_error_during_process), true);
    }
}

From source file:com.binomed.showtime.android.screen.results.CineShowTimeResultsActivity.java

@Override
protected void onPreRestoreBundle(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        boolean saved = savedInstanceState.getBoolean(ParamIntent.BUNDLE_SAVE, false);
        if (saved) {
            getModelActivity().setNearResp((NearResp) savedInstanceState.getParcelable(ParamIntent.NEAR_RESP));
            intentResult = new Intent();
            intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_FORCE_REQUEST,
                    savedInstanceState.getBoolean(ParamIntent.ACTIVITY_SEARCH_FORCE_REQUEST, false));
            intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_CITY,
                    savedInstanceState.getString(ParamIntent.ACTIVITY_SEARCH_CITY));
            intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_MOVIE_NAME,
                    savedInstanceState.getString(ParamIntent.ACTIVITY_SEARCH_MOVIE_NAME));
            intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_THEATER_ID,
                    savedInstanceState.getString(ParamIntent.ACTIVITY_SEARCH_THEATER_ID));
            intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_DAY,
                    savedInstanceState.getInt(ParamIntent.ACTIVITY_SEARCH_DAY, 0));
            intentResult.putIntegerArrayListExtra(ParamIntent.ACTIVITY_SEARCH_GROUP_EXPAND,
                    savedInstanceState.getIntegerArrayList(ParamIntent.ACTIVITY_SEARCH_GROUP_EXPAND));
            Double latitude = savedInstanceState.getDouble(ParamIntent.ACTIVITY_SEARCH_LATITUDE, -1);
            Double longitude = savedInstanceState.getDouble(ParamIntent.ACTIVITY_SEARCH_LONGITUDE, -1);
            if ((latitude != -1) && (longitude != -1)) {
                intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_LATITUDE, latitude);
                intentResult.putExtra(ParamIntent.ACTIVITY_SEARCH_LONGITUDE, longitude);
            }/* ww  w  .  j a va 2 s.  co m*/
        }

    }
}

From source file:com.application.treasurehunt.ScanQRCodeActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {

    super.onRestoreInstanceState(savedInstanceState);
    mLastLocation = savedInstanceState.getParcelable("lastLocation");
    mLocationServicesChecked = savedInstanceState.getBoolean("mLocationServicesChecked");
}

From source file:com.actinarium.nagbox.ui.EditTaskDialogFragment.java

@NonNull
@Override//  w w w.j  av  a 2  s.  co  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Task taskToEdit = getArguments().getParcelable(ARG_TASK);
    final boolean isEdit = taskToEdit != null;

    // Set up our live model:
    if (savedInstanceState != null) {
        // a) restore after config change
        mTask = savedInstanceState.getParcelable(ARG_TASK);
    } else if (isEdit) {
        // b) populate from the one under editing
        mTask = new Task(taskToEdit);
    } else {
        // c) create a blank task with default interval = 5 mins
        mTask = new Task();
    }

    mBinding = EditTaskDialogBinding.inflate(LayoutInflater.from(getContext()), null, false);
    mBinding.setTask(mTask);

    final AlertDialog dialog = new AlertDialog.Builder(getContext())
            .setTitle(getString(isEdit ? R.string.dialog_edit_task : R.string.dialog_new_task))
            .setView(mBinding.getRoot()).setPositiveButton(R.string.dialog_save, null)
            .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            }).create();

    // At this moment dialog is not yet inflated, so we need to use this listener to defer some logic
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface di) {
            // Set the positive button listener. This is needed to prevent dismissing the dialog when validation fails
            dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    boolean isValid = validateForm();
                    if (isValid) {
                        // Actually I could call the service right here instead of delegating it to the activity
                        // But for the sake of consistency let the activity serve as a controller and handle this
                        if (isEdit) {
                            mHost.saveEditedTask(mTask);
                        } else {
                            mHost.saveNewTask(mTask);
                        }
                        dismiss();
                    }
                }
            });

            // Also try requesting the input method
            if (mBinding.taskTitleInput.getEditText().requestFocus()) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(mBinding.taskTitleInput.getEditText(), InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    return dialog;
}

From source file:cn.com.hgh.view.SlideSwitch.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        this.isOpen = bundle.getBoolean("isOpen");
        state = bundle.getParcelable("instanceState");
    }/*  w  w  w .  j  a  va 2  s  .c  o m*/
    super.onRestoreInstanceState(state);
}

From source file:com.crossconnect.activity.main.NotesEditorFragment.java

@Override
public Loader<String> onCreateLoader(int id, Bundle args) {
    // This is called when a new Loader needs to be created.  This
    // sample only has one Loader with no arguments, so it is simple.
    Log.i(TAG, "onCreateLoader()");
    return new NoteLoader(getActivity(), (BibleText) args.getParcelable("BibleText"));
}

From source file:cn.arvin.example.ui.custom.observablescrollview.CacheFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    Bundle bundle = (Bundle) state;
    int pages = bundle.getInt(STATE_PAGES);
    if (0 < pages) {
        for (int i = 0; i < pages; i++) {
            int position = bundle.getInt(createCacheIndex(i));
            Fragment f = mFm.getFragment(bundle, createCacheKey(position));
            mPages.put(position, f);/*from  w w w.  j a v a2  s.co m*/
        }
    }

    Parcelable p = bundle.getParcelable(STATE_SUPER_STATE);
    super.restoreState(p, loader);
}