Example usage for android.os Bundle getBundle

List of usage examples for android.os Bundle getBundle

Introduction

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

Prototype

@Nullable
public Bundle getBundle(@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.jedi.setupwizard.ui.SetupWizardActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setup_main);
    ((SetupWizard) AppGlobals.getInitialApplication()).disableStatusBar();
    mSharedPreferences = getSharedPreferences(SetupWizard.SETTINGS_PREFERENCES, Context.MODE_PRIVATE);
    mSetupData = (AbstractSetupData) getLastNonConfigurationInstance();
    if (mSetupData == null) {
        mSetupData = new SetupWizardData(this);
    }/*ww w  .  j a  va  2s  . c  o  m*/

    if (savedInstanceState != null) {
        mSetupData.load(savedInstanceState.getBundle("data"));
    } else {
        mSharedPreferences.edit().putBoolean(KEY_SIM_MISSING_SHOWN, false).commit();
    }
    mNextButton = (Button) findViewById(R.id.next_button);
    mPrevButton = (Button) findViewById(R.id.prev_button);
    mSetupData.registerListener(this);
    mPagerAdapter = new PagerAdapter(getFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setPageTransformer(true, new DepthPageTransformer());
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            if (position < mPageList.size()) {
                onPageLoaded(mPageList.get(position));
            }
        }
    });
    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            doNext();
        }
    });
    mPrevButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            doPrevious();
        }
    });
    final EnableAccessibilityController acc = new EnableAccessibilityController(this);
    mViewPager.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return acc.onInterceptTouchEvent(event);
        }
    });
    onPageTreeChanged();
    removeUnNeededPages();
}

From source file:com.google.android.gcm.demo.ui.GroupActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    setContentView(R.layout.activity_group);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }/*w ww  .j a  va 2 s.co  m*/

    mLogger = new LoggingService.Logger(this);
    mDeviceGroupsHelper = new DeviceGroupsHelper(this);
    mSenders = SenderCollection.getInstance(this);

    if (savedState != null) {
        if (savedState.containsKey(STATE_NEW_MEMBERS)) {
            newMembers = savedState.getBundle(STATE_NEW_MEMBERS);
        }
        if (savedState.containsKey(STATE_REMOVED_MEMBERS)) {
            removedMembers = savedState.getBundle(STATE_REMOVED_MEMBERS);
        }
        sender.senderId = savedState.getString(STATE_SELECTED_SENDER_ID);
        senderApiKey = savedState.getString(STATE_SELECTED_SENDER_ID);
        group.notificationKeyName = savedState.getString(STATE_SELECTED_SENDER_ID);
    }

    newMembersView = findViewById(R.id.group_new_members);
    noNewMembersView = findViewById(R.id.group_no_new_members);
    removedMembersView = findViewById(R.id.group_removed_members);
    currentMembersView = findViewById(R.id.group_current_members);

    senderIdTexView = (TextView) findViewById(R.id.group_sender_id);
    chooseSenderIdTexView = (TextView) findViewById(R.id.group_choose_sender_id);
    chooseApiKeyTextView = (TextView) findViewById(R.id.group_api_key);
    newNameEditText = (EditText) findViewById(R.id.group_new_name);

    newMembersList = (LinearLayout) findViewById(R.id.group_new_members_list);
    removedMembersList = (LinearLayout) findViewById(R.id.group_removed_members_list);
    currentMembersList = (LinearLayout) findViewById(R.id.group_current_members_list);

    Button submit = (Button) findViewById(R.id.group_submit);

    if (getIntent().hasExtra(EXTRA_GROUP_NAME)) {
        // Caller provided a group name, entering EDIT mode.
        editMode = true;
        getSupportActionBar().setTitle(R.string.group_activity_title_edit_group);
        String senderId = getIntent().getStringExtra(EXTRA_SENDER_ID);
        String groupName = getIntent().getStringExtra(EXTRA_GROUP_NAME);
        sender = mSenders.getSender(senderId);
        group = sender.groups.get(groupName);

        senderIdTexView.setVisibility(View.VISIBLE);
        senderIdTexView.setText(sender.senderId);
        chooseSenderIdTexView.setVisibility(View.GONE);

        TextView nameTextView = (TextView) findViewById(R.id.group_name);
        TextView keyTextView = (TextView) findViewById(R.id.group_key);
        nameTextView.setText(group.notificationKeyName);
        keyTextView.setText(AbstractFragment.truncateToMediumString(group.notificationKey));
        submit.setText(R.string.group_submit_edit_group);

        newNameEditText.setVisibility(View.GONE);
    } else {
        // Caller did not provide a group name, entering NEW-GROUP mode.
        editMode = false;
        getSupportActionBar().setTitle(R.string.group_activity_title_new_group);
        findViewById(R.id.group_key_view).setVisibility(View.GONE);
        senderIdTexView.setVisibility(View.GONE);
        chooseSenderIdTexView.setOnClickListener(this);
        submit.setText(R.string.group_submit_new_group);
    }

    submit.setOnClickListener(this);
    findViewById(R.id.group_new_member).setOnClickListener(this);

    refresh();

    // Piggyback on the "NEW_LOG" event to refresh the activity UI.
    mLoggerCallback = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            refresh();
        }
    };
}

From source file:com.google.samples.apps.topeka.fragment.QuizFragment.java

private void restoreQuizState(final Bundle savedInstanceState) {
    if (null == savedInstanceState) {
        return;//w  ww. j ava  2  s  . co m
    }
    mQuizView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            mQuizView.removeOnLayoutChangeListener(this);
            View currentChild = mQuizView.getChildAt(0);
            if (currentChild instanceof ViewGroup) {
                final View potentialQuizView = ((ViewGroup) currentChild).getChildAt(0);
                if (potentialQuizView instanceof AbsQuizView) {
                    ((AbsQuizView) potentialQuizView)
                            .setUserInput(savedInstanceState.getBundle(KEY_USER_INPUT));
                }
            }
        }
    });

}

From source file:jp.co.noxi.app.NXDialog.java

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

    // Load date from savedState
    if (savedInstanceState != null) {
        mKeyListener = findListenerByTag(OnKeyListener.class, savedInstanceState, SAVED_KEY_LISTENER);
        mShowListener = findListenerByTag(OnShowListener.class, savedInstanceState, SAVED_SHOW_LISTENER);
        mCancelListener = findListenerByTag(OnCancelListener.class, savedInstanceState, SAVED_CANCEL_LISTENER);
        mDismissListener = findListenerByTag(OnDismissListener.class, savedInstanceState,
                SAVED_DISMISS_LISTENER);

        mCanceledOnTouchOutside = savedInstanceState.getInt(SAVED_TOUCH_OUTSIDE, VALUE_NULL);
        mExtra = savedInstanceState.getBundle(SAVED_EXTRA);
    }//from   w w w. j a v  a  2  s .  c o m

    setOnKeyListenerInternal(mKeyListener);
    setOnShowListenerInternal(mShowListener);
    setOnCancelListenerInternal(mCancelListener);
    setOnDismissListenerInternal(mDismissListener);

    if (mCanceledOnTouchOutside != VALUE_NULL) {
        getDialog().setCanceledOnTouchOutside(mCanceledOnTouchOutside == VALUE_TRUE);
    }
}

From source file:org.ntpsync.service.NtpSyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    // lock cpu// w ww.  j  a va 2  s. co  m
    getLocks(this);
    lock();

    Bundle extras = intent.getExtras();
    if (extras == null) {
        Log.e(Constants.TAG, "Extra bundle is null!");
        return;
    }

    // fail if required keys are not present
    if (!extras.containsKey(EXTRA_ACTION)) {
        Log.e(Constants.TAG, "Extra bundle must contain a action!");
        return;
    }

    int action = extras.getInt(EXTRA_ACTION);

    // for these actions we get a result back which is send via the messenger and we require
    // a data bundle
    if (!(extras.containsKey(EXTRA_DATA))) {
        Log.e(Constants.TAG, "Extra bundle must contain a data bundle!");
        return;
    } else {
        mData = extras.getBundle(EXTRA_DATA);
    }

    boolean noMessenger = false;
    if (!(extras.containsKey(EXTRA_MESSENGER))) {
        Log.e(Constants.TAG, "No messenger present, using default result handling!");
        noMessenger = true;
    } else {
        mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
    }

    // get NTP server from preferences
    String ntpHostname = PreferenceHelper.getNtpServer(this);

    // default values
    int returnMessage = RETURN_GENERIC_ERROR;
    long offset = 0;

    // execute action from extra bundle
    switch (action) {
    case ACTION_QUERY:

        // return time to ui
        Bundle messageData = new Bundle();
        try {
            offset = NtpSyncUtils.query(ntpHostname);
            returnMessage = RETURN_OKAY;

            // calculate new time
            Date newTime = new Date(System.currentTimeMillis() + offset);

            messageData.putSerializable(MESSAGE_DATA_TIME, newTime);

            if (mData.containsKey(DATA_APPLY_DIRECTLY)) {
                if (mData.getBoolean(DATA_APPLY_DIRECTLY)) {
                    returnMessage = Utils.setTime(offset);
                }
            }
        } catch (IOException e) {
            returnMessage = RETURN_SERVER_TIMEOUT;
            Log.d(Constants.TAG, "Timeout on server!");
        }

        if (noMessenger && PreferenceHelper.getShowSyncToast(this)) {
            Message msg = Message.obtain();
            msg.arg1 = returnMessage;
            msg.setData(messageData);
            handleResult(msg);
        } else {
            sendMessageToHandler(returnMessage, messageData);
        }

        break;

    case ACTION_QUERY_DETAILED:

        String output = null;
        Bundle messageDataDetailedQuery = null;
        try {
            TimeInfo info = NtpSyncUtils.detailedQuery(ntpHostname);

            output = NtpSyncUtils.processResponse(info, this);

            // return detailed output to ui
            messageDataDetailedQuery = new Bundle();
            messageDataDetailedQuery.putSerializable(MESSAGE_DATA_DETAILED_OUTPUT, output);

            returnMessage = RETURN_OKAY;
        } catch (IOException e) {
            returnMessage = RETURN_SERVER_TIMEOUT;
            Log.d(Constants.TAG, "Timeout on server!");
        }

        if (noMessenger && PreferenceHelper.getShowSyncToast(this)) {
            Message msg = Message.obtain();
            msg.arg1 = returnMessage;
            msg.setData(messageDataDetailedQuery);
            handleResult(msg);
        } else {
            sendMessageToHandler(returnMessage, messageDataDetailedQuery);
        }

        break;

    default:
        break;

    }

    // unlock cpu
    unlock();
}

From source file:br.com.arlsoft.pushclient.PushClientModule.java

private void checkForExtras() {
    Activity activity = TiApplication.getAppRootOrCurrentActivity();
    if (activity != null) {
        Intent intent = activity.getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null && !extras.isEmpty() && extras.containsKey(PROPERTY_EXTRAS)) {
                extras = extras.getBundle(PROPERTY_EXTRAS);
                HashMap data = PushClientModule.convertBundleToHashMap(extras);
                data.put("prev_state", "stopped");
                PushClientModule.sendMessage(data, PushClientModule.MODE_CLICK);
                intent.removeExtra(PROPERTY_EXTRAS);
            }//www  .j  ava2  s. com
        }
    }
}

From source file:android.support.v7.preference.PreferenceController.java

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    if (mHavePrefs) {
        bindPreferences();/*from ww  w.  j  a v  a2  s  .  c  o  m*/
        if (mSelectPreferenceRunnable != null) {
            mSelectPreferenceRunnable.run();
            mSelectPreferenceRunnable = null;
        }
    }

    mInitDone = true;

    if (savedInstanceState != null) {
        Bundle container = savedInstanceState.getBundle(PREFERENCES_TAG);
        if (container != null) {
            final PreferenceScreen preferenceScreen = getPreferenceScreen();
            if (preferenceScreen != null) {
                preferenceScreen.restoreHierarchyState(container);
            }
        }
    }
}

From source file:com.stupid.method.app.DialogFragment.java

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

    if (!mShowsDialog) {
        return;//from w w  w  .  j a  v  a 2 s . c  o  m
    }

    View view = getView();
    if (view != null) {
        if (view.getParent() != null) {
            throw new IllegalStateException("DialogFragment can not be attached to a container view");
        }
        mDialog.setContentView(view);
    }
    mDialog.setOwnerActivity(getActivity());
    mDialog.setCancelable(mCancelable);
    mDialog.setOnCancelListener(this);
    mDialog.setOnDismissListener(this);
    if (savedInstanceState != null) {
        Bundle dialogState = savedInstanceState.getBundle(SAVED_DIALOG_STATE_TAG);
        if (dialogState != null) {
            mDialog.onRestoreInstanceState(dialogState);
        }
    }
}

From source file:com.sharpcart.android.wizardpager.SharpCartLoginActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_wizard);

    mContext = this;
    mAccountManager = AccountManager.get(this);

    //init progress dialog
    pd = new ProgressDialog(this);

    if (savedInstanceState != null) {
        mWizardModel.load(savedInstanceState.getBundle("model"));
    }//from   w w w. j a v  a 2s. co m

    mWizardModel.registerListener(this);

    mPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mStepPagerStrip = (StepPagerStrip) findViewById(R.id.strip);
    mStepPagerStrip.setOnPageSelectedListener(new StepPagerStrip.OnPageSelectedListener() {
        @Override
        public void onPageStripSelected(int position) {
            position = Math.min(mPagerAdapter.getCount() - 1, position);
            if (mPager.getCurrentItem() != position) {
                mPager.setCurrentItem(position);
            }
        }
    });

    mNextButton = (Button) findViewById(R.id.next_button);
    mPrevButton = (Button) findViewById(R.id.prev_button);

    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(final int position) {
            mStepPagerStrip.setCurrentPage(position);

            if (mConsumePageSelectedEvent) {
                mConsumePageSelectedEvent = false;
                return;
            }

            mEditingAfterReview = false;
            updateBottomBar();
        }
    });

    mNextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View view) {

            //Check Internet connection
            if (!hasInternetConnection) {
                Toast.makeText(mContext, "No Internet Connection", Toast.LENGTH_SHORT).show();

                //Check Internet connection. if there is none we wont be able to register the user
                checkInternetConnection = new CheckInternetConnection();
                checkInternetConnection.execute();
            }

            //Check to see if user already exists on servers
            if (mPager.getCurrentItem() == 0) {
                final ArrayList<ReviewItem> reviewItems = new ArrayList<ReviewItem>();
                for (final Page page : mWizardModel.getCurrentPageSequence()) {
                    page.getReviewItems(reviewItems);
                }

                checkIfRegistered(reviewItems.get(0).getDisplayValue(), reviewItems.get(1).getDisplayValue());
            }

            //If we have reached the last page
            if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {

                //if we still dont have an Internet connection we cant move on
                if (!hasInternetConnection) {
                    new NoInternetConnectionDialog().show(getSupportFragmentManager(), "");

                } else {
                    /*
                     * Login/Create new account
                     * 1. Save relevant information to UserProfile object
                     * 2. Update SharedPreferences
                     * 3. Create Authenticator account
                     * 4. Update server
                     */

                    final ContentValues cv = new ContentValues();

                    //Reset all items active to 1
                    cv.put(SharpCartContentProvider.COLUMN_ACTIVE, "1");

                    getContentResolver().update(SharpCartContentProvider.CONTENT_URI_SHOPPING_ITEMS, cv, null,
                            null);

                    final ArrayList<ReviewItem> reviewItems = new ArrayList<ReviewItem>();
                    for (final Page page : mWizardModel.getCurrentPageSequence()) {
                        page.getReviewItems(reviewItems);
                    }

                    Collections.sort(reviewItems, new Comparator<ReviewItem>() {
                        @Override
                        public int compare(final ReviewItem a, final ReviewItem b) {
                            return a.getWeight() > b.getWeight() ? +1 : a.getWeight() < b.getWeight() ? -1 : 0;
                        }
                    });

                    mCurrentReviewItems = reviewItems;

                    //Save relevant information to UserProfile object
                    UserProfile.getInstance().setUserName(mCurrentReviewItems.get(0).getDisplayValue());
                    UserProfile.getInstance().setPassword(mCurrentReviewItems.get(1).getDisplayValue());
                    UserProfile.getInstance().setZip(mCurrentReviewItems.get(2).getDisplayValue());
                    UserProfile.getInstance().setFamilySize(mCurrentReviewItems.get(3).getDisplayValue());

                    //update shared preferences
                    //update settings
                    final SharedPreferences sharedPref = PreferenceManager
                            .getDefaultSharedPreferences(mContext);
                    sharedPref.edit().putString("pref_zip", UserProfile.getInstance().getZip()).commit();
                    sharedPref.edit().putString("pref_family_size",
                            String.valueOf(UserProfile.getInstance().getFamilySize())).commit();

                    sharedPref.edit().putLong("user_profile_last_updated", new Date().getTime()).commit();

                    //Present user with a dialog to choose up to 4 local stores based on their ZIP code
                    final Intent i = new Intent(view.getContext(), ChooseGroceryStoreMapFragment.class);
                    startActivityForResult(i, SELECT_STORES);

                }
            } else {
                if (mEditingAfterReview) {
                    mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
                } else {
                    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                }
            }
        }
    });

    mPrevButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
        }
    });

    onPageTreeChanged();
    updateBottomBar();

    //Check Internet connection. if there is none we wont be able to register the user
    checkInternetConnection = new CheckInternetConnection();
    checkInternetConnection.execute();
}

From source file:com.jafme.mobile.activity.CropImageActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crop_image);
    Utils.setupRobotoFont(findViewById(R.id.layout_activity_crop_image));
    Utils.setupSystemBarsTint(this, R.color.actionbar_bg, R.color.actionbar_bg);

    setResult(RESULT_CANCELED);//from   ww w  . j  ava  2 s .c  o m

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.crop_photo);
    }

    toolbarUtils = new ToolbarUtils(this, toolbar, R.color.actionbar_bg, R.color.actionbar_text,
            R.color.color_primary, R.drawable.ic_action_back);
    toolbar.setVisibility(View.GONE);

    layoutPhoto = findViewById(R.id.layout_photo);
    assert layoutPhoto != null;
    layoutPhoto.setVisibility(View.GONE);

    // ================

    imageView = (CropImageView) findViewById(R.id.crop_image);
    assert imageView != null;
    imageView.context = this;
    imageView.setRecycler(new ImageViewTouchBase.Recycler() {
        @Override
        public void recycle(Bitmap b) {
            b.recycle();
            System.gc();
        }
    });

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        sourceUri = getIntent().getData();
        removeOriginal = extras.getBoolean(EXT_REMOVE_ORIGINAL);

        maxX = extras.getInt(EXT_MAX_X);
        maxY = extras.getInt(EXT_MAX_Y);
        type = extras.getInt(EXT_TYPE);
        needUpload = extras.getBoolean(EXT_NEED_UPLOAD);
        args = extras.getBundle(EXT_ARGS);

        switch (type) {
        case TYPE_USER_AVATAR:
            aspectX = 1;
            aspectY = 1;
            break;
        case TYPE_APPLICANT_PHOTO:
            aspectX = 0;
            aspectY = 0;
            break;
        case TYPE_VACANCY_PHOTO:
            aspectX = 0;
            aspectY = 0;
            break;
        }
    }
    if (sourceUri != null) {
        exifRotation = CropUtil.getExifRotation(CropUtil.getFromMediaUri(this, sourceUri));
        InputStream is = null;
        try {
            sampleSize = calculateBitmapSampleSize(sourceUri);
            is = getContentResolver().openInputStream(sourceUri);
            BitmapFactory.Options option = new BitmapFactory.Options();
            option.inSampleSize = sampleSize;
            rotateBitmap = new RotateBitmap(BitmapFactory.decodeStream(is, null, option), exifRotation);
        } catch (IOException e) {
            Log.e(LOG_TAG, "Error reading image: " + e.getMessage(), e);
            setResultException(e);
        } catch (OutOfMemoryError e) {
            Log.e(LOG_TAG, "OOM reading image: " + e.getMessage(), e);
            setResultException(e);
        } finally {
            CropUtil.closeSilently(is);
        }
    } else {
        finish();
        return;
    }
    if (rotateBitmap == null) {
        finish();
        return;
    }

    layoutPhoto.post(new Runnable() {
        @Override
        public void run() {
            startCrop();
        }
    });

    Analytics.setScreenName(this, "User-Crop_photo");
}