Example usage for android.os Bundle getInt

List of usage examples for android.os Bundle getInt

Introduction

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

Prototype

public int getInt(String key, int defaultValue) 

Source Link

Document

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

Usage

From source file:com.pseudosudostudios.jdd.activities.GameActivity.java

private boolean loadFromBundle(Bundle state) {
    if (state == null)
        return false;
    Log.d("onCreateStuff", "Using bundle");
    Log.d("Loading", "Reading from bundle");
    // Reload the game after a screen rotation
    Tile.initPaints();//from   w  w  w.j  a v  a  2s  .  c o m
    Tile[][] loadedTiles = new Tile[3][3];
    Tile[][] loadedSol = new Tile[3][3];
    for (int r = 0; r < bg.tiles.length; r++)
        for (int c = 0; c < bg.tiles[r].length; c++) {
            loadedTiles[r][c] = new Tile(this, state.getIntArray(onSaveBaseString + r + c));
            int[] arr = state.getIntArray(onSaveSolution + r + c);
            if (arr != null)
                loadedSol[r][c] = new Tile(this, arr);
        }
    int moves = state.getInt(onSaveMoves, 0);
    long time = state.getLong(onSaveTime, 0L);
    bg.setTileArray(loadedTiles, loadedSol, moves, time, state.getInt(jsonTileSize, 0));
    bg.setDifficulty(findDifficulty(state.getString(onSaveBaseString)));
    Grid.numberOfColors = state.getInt(bundleGameColors);
    bg.setCenterTile(new Tile(this, state.getIntArray(onSaveCeterTile)));
    Tile.initPaints();
    bg.invalidate();
    return true;
}

From source file:com.piusvelte.taplock.client.core.TapLockSettings.java

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();/* ww w  .  ja  v  a  2 s .  c  o m*/
    if (mInWriteMode) {
        if (intent != null) {
            String action = intent.getAction();
            if (mInWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
                    && intent.hasExtra(EXTRA_DEVICE_NAME)) {
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                String name = intent.getStringExtra(EXTRA_DEVICE_NAME);
                if ((tag != null) && (name != null)) {
                    // write the device and address
                    String lang = "en";
                    // don't write the passphrase!
                    byte[] textBytes = name.getBytes();
                    byte[] langBytes = null;
                    int langLength = 0;
                    try {
                        langBytes = lang.getBytes("US-ASCII");
                        langLength = langBytes.length;
                    } catch (UnsupportedEncodingException e) {
                        Log.e(TAG, e.toString());
                    }
                    int textLength = textBytes.length;
                    byte[] payload = new byte[1 + langLength + textLength];

                    // set status byte (see NDEF spec for actual bits)
                    payload[0] = (byte) langLength;

                    // copy langbytes and textbytes into payload
                    if (langBytes != null) {
                        System.arraycopy(langBytes, 0, payload, 1, langLength);
                    }
                    System.arraycopy(textBytes, 0, payload, 1 + langLength, textLength);
                    NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT,
                            new byte[0], payload);
                    NdefMessage message = new NdefMessage(
                            new NdefRecord[] { record, NdefRecord.createApplicationRecord(getPackageName()) });
                    // Get an instance of Ndef for the tag.
                    Ndef ndef = Ndef.get(tag);
                    if (ndef != null) {
                        try {
                            ndef.connect();
                            if (ndef.isWritable()) {
                                ndef.writeNdefMessage(message);
                            }
                            ndef.close();
                            Toast.makeText(this, "tag written", Toast.LENGTH_LONG).show();
                        } catch (IOException e) {
                            Log.e(TAG, e.toString());
                        } catch (FormatException e) {
                            Log.e(TAG, e.toString());
                        }
                    } else {
                        NdefFormatable format = NdefFormatable.get(tag);
                        if (format != null) {
                            try {
                                format.connect();
                                format.format(message);
                                format.close();
                                Toast.makeText(getApplicationContext(), "tag written", Toast.LENGTH_LONG);
                            } catch (IOException e) {
                                Log.e(TAG, e.toString());
                            } catch (FormatException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                    }
                    mNfcAdapter.disableForegroundDispatch(this);
                }
            }
        }
        mInWriteMode = false;
    } else {
        SharedPreferences sp = getSharedPreferences(KEY_PREFS, MODE_PRIVATE);
        onSharedPreferenceChanged(sp, KEY_DEVICES);
        // check if configuring a widget
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                final String[] displayNames = TapLock.getDeviceNames(mDevices);
                final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
                        AppWidgetManager.INVALID_APPWIDGET_ID);
                if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                    mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle("Select device for widget")
                            .setItems(displayNames, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // set the successful widget result
                                    Intent resultValue = new Intent();
                                    resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
                                    setResult(RESULT_OK, resultValue);

                                    // broadcast the new widget to update
                                    JSONObject deviceJObj = mDevices.get(which);
                                    dialog.cancel();
                                    TapLockSettings.this.finish();
                                    try {
                                        sendBroadcast(TapLock
                                                .getPackageIntent(TapLockSettings.this, TapLockWidget.class)
                                                .setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
                                                .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
                                                .putExtra(EXTRA_DEVICE_NAME, deviceJObj.getString(KEY_NAME)));
                                    } catch (JSONException e) {
                                        Log.e(TAG, e.toString());
                                    }
                                }
                            }).create();
                    mDialog.show();
                }
            }
        }
        // start the service before binding so that the service stays around for faster future connections
        startService(TapLock.getPackageIntent(this, TapLockService.class));
        bindService(TapLock.getPackageIntent(this, TapLockService.class), this, BIND_AUTO_CREATE);

        int serverVersion = sp.getInt(KEY_SERVER_VERSION, 0);
        if (mShowTapLockSettingsInfo && (mDevices.size() == 0)) {
            if (serverVersion < SERVER_VERSION)
                sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit();
            mShowTapLockSettingsInfo = false;
            Intent i = TapLock.getPackageIntent(this, TapLockInfo.class);
            i.putExtra(EXTRA_INFO, getString(R.string.info_taplocksettings));
            startActivity(i);
        } else if (serverVersion < SERVER_VERSION) {
            // TapLockServer has been updated
            sp.edit().putInt(KEY_SERVER_VERSION, SERVER_VERSION).commit();
            mDialog = new AlertDialog.Builder(TapLockSettings.this).setTitle(R.string.ttl_hasupdate)
                    .setMessage(R.string.msg_hasupdate)
                    .setNeutralButton(R.string.button_getserver, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();

                            mDialog = new AlertDialog.Builder(TapLockSettings.this)
                                    .setTitle(R.string.msg_pickinstaller)
                                    .setItems(R.array.installer_entries, new DialogInterface.OnClickListener() {

                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            dialog.cancel();
                                            final String installer_file = getResources()
                                                    .getStringArray(R.array.installer_values)[which];

                                            mDialog = new AlertDialog.Builder(TapLockSettings.this)
                                                    .setTitle(R.string.msg_pickdownloader)
                                                    .setItems(R.array.download_entries,
                                                            new DialogInterface.OnClickListener() {

                                                                @Override
                                                                public void onClick(DialogInterface dialog,
                                                                        int which) {
                                                                    dialog.cancel();
                                                                    String action = getResources()
                                                                            .getStringArray(
                                                                                    R.array.download_values)[which];
                                                                    if (ACTION_DOWNLOAD_SDCARD.equals(action)
                                                                            && copyFileToSDCard(installer_file))
                                                                        Toast.makeText(TapLockSettings.this,
                                                                                "Done!", Toast.LENGTH_SHORT)
                                                                                .show();
                                                                    else if (ACTION_DOWNLOAD_EMAIL
                                                                            .equals(action)
                                                                            && copyFileToSDCard(
                                                                                    installer_file)) {
                                                                        Intent emailIntent = new Intent(
                                                                                android.content.Intent.ACTION_SEND);
                                                                        emailIntent.setType(
                                                                                "application/java-archive");
                                                                        emailIntent.putExtra(Intent.EXTRA_TEXT,
                                                                                getString(
                                                                                        R.string.email_instructions));
                                                                        emailIntent.putExtra(
                                                                                Intent.EXTRA_SUBJECT,
                                                                                getString(R.string.app_name));
                                                                        emailIntent.putExtra(
                                                                                Intent.EXTRA_STREAM,
                                                                                Uri.parse("file://"
                                                                                        + Environment
                                                                                                .getExternalStorageDirectory()
                                                                                                .getPath()
                                                                                        + "/"
                                                                                        + installer_file));
                                                                        startActivity(Intent.createChooser(
                                                                                emailIntent, getString(
                                                                                        R.string.button_getserver)));
                                                                    }
                                                                }

                                                            })
                                                    .create();
                                            mDialog.show();
                                        }
                                    }).create();
                            mDialog.show();
                        }
                    }).create();
            mDialog.show();
        }
    }
}

From source file:com.taw.gotothere.GoToThereActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // Let superclass handle map type/centre point and zoom level
    super.onRestoreInstanceState(savedInstanceState);

    Log.d(TAG, "onRestoreInstanceState()");

    int latitude = savedInstanceState.getInt(END_LAT_KEY, -1);
    int longitude = savedInstanceState.getInt(END_LONG_KEY, -1);

    placingMarker = savedInstanceState.getBoolean(PLACING_MARKER_KEY);
    if (placingMarker) {
        startMarkerPlacement();/*from   w w w  .j ava  2s.  c om*/

        // May have tapped an endpoint already
        if (latitude != -1 && longitude != -1) {
            navigationOverlay.setSelectedLocation(new GeoPoint(latitude, longitude));
            directionsImageView.setEnabled(true);
        } else {
            directionsImageView.setEnabled(false);
        }
    }

    navigating = savedInstanceState.getBoolean(NAVIGATING_KEY);
    if (navigating) {

        navigationOverlay.startNavigating();

        if (latitude != -1 && longitude != -1) {
            navigationOverlay.setSelectedLocation(new GeoPoint(latitude, longitude));
        }

        latitude = savedInstanceState.getInt(START_LAT_KEY, -1);
        longitude = savedInstanceState.getInt(START_LONG_KEY, -1);

        if (latitude != -1 && longitude != -1) {
            navigationOverlay.setStartLocation(new GeoPoint(latitude, longitude));
        }

        navigationOverlay.setDirections((MapDirections) savedInstanceState.getSerializable(DIRECTIONS_KEY));

        directionsImageView.setSelected(true);
        directionsImageView.setEnabled(true);

        markerImageView.setEnabled(false);
    }

    // Save the previousQuery flag as a preference: if the screen is re-oriented
    // then the activity is killed + restarted, meaning we lose the 
    // savedInstanceState bundle. This is an easy way to keep track of this flag.
    SharedPreferences prefs = getPreferences(Activity.MODE_PRIVATE);
    searchTextView.setText(prefs.getString(PREVIOUS_QUERY, null));
}

From source file:de.da_sense.moses.client.FormFragment.java

/**
 * Creates a Layout for a Single_Questionnaire
 * //w ww  . j a  v a 2s  .  c  o m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Intent intent = getActivity().getIntent();
    mBelongsTo = intent.getIntExtra(WelcomeActivity.KEY_BELONGS_TO, WelcomeActivityPagerAdapter.TAB_RUNNING);

    mLayoutInflater = inflater;

    container.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    if (savedInstanceState != null) {
        if (mPosition == -1)
            mPosition = savedInstanceState.getInt(KEY_POSITION, -1);

        if (mAPKID == null)
            mAPKID = savedInstanceState.getString(InstalledExternalApplication.KEY_APK_ID, null);
    }

    if (mAPKID == null)
        Log.e(LOG_TAG, "onCreateView the APKID was not set and not in the bundle");

    // check the presence of the formID
    if (mFormID == -1) {
        // the id is not set, it must be in the bundle
        mFormID = savedInstanceState.getInt(Form.KEY_FORM_ID, -1);
        if (mFormID == -1)
            // the id of the form was not in the bundle, this should never have happened
            Log.e(LOG_TAG, "onCreateView the formID was not set and not in the bundle");
    }

    ExternalApplication app;

    // get the corresponding installedApp
    if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) {
        app = HistoryExternalApplicationsManager.getInstance().getAppForId(mAPKID);
    } else {
        app = InstalledExternalApplicationsManager.getInstance().getAppForId(mAPKID);
    }

    if (app != null) {
        mForm = app.getSurvey().getForm(mFormID);
    }

    mRoot = (LinearLayout) inflater.inflate(R.layout.form, container, false);

    mScrollView = (ScrollView) mRoot.findViewById(R.id.scrollView1);

    // set focus to the dummy layout in order to prevent virtual keyboard from popping up
    View dummyLayout = mRoot.findViewById(R.id.dummy_layout_form);
    dummyLayout.requestFocus();

    addFormToLayout(mForm, mRoot);

    if (savedInstanceState != null) {
        if (mIsFirst == null)
            mIsFirst = savedInstanceState.getBoolean(KEY_IS_FIRST);

        if (mIsLast == null)
            mIsLast = savedInstanceState.getBoolean(KEY_IS_LAST);
    }

    return (View) mRoot;
}

From source file:me.willowcheng.makerthings.ui.OpenHABWidgetListFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate()");
    Log.d(TAG, "isAdded = " + isAdded());
    mTag = this;/* w w w.j a v  a 2s. co m*/
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        Log.d(TAG, "restoring state from savedInstanceState");
        displayPageUrl = savedInstanceState.getString("displayPageUrl");
        openHABBaseUrl = savedInstanceState.getString("openHABBaseUrl");
        sitemapRootUrl = savedInstanceState.getString("sitemapRootUrl");
        openHABUsername = savedInstanceState.getString("openHABUsername");
        openHABPassword = savedInstanceState.getString("openHABPassword");
        mCurrentSelectedItem = savedInstanceState.getInt("currentSelectedItem", -1);
        mPosition = savedInstanceState.getInt("position", -1);
        Log.d(TAG, String.format("onCreate selected item = %d", mCurrentSelectedItem));
    }
    if (getArguments() != null) {
        displayPageUrl = getArguments().getString("displayPageUrl");
        openHABBaseUrl = getArguments().getString("openHABBaseUrl");
        sitemapRootUrl = getArguments().getString("sitemapRootUrl");
        openHABUsername = getArguments().getString("openHABUsername");
        openHABPassword = getArguments().getString("openHABPassword");
        mPosition = getArguments().getInt("position");
    }
    if (savedInstanceState != null)
        if (!displayPageUrl.equals(savedInstanceState.getString("displayPageUrl")))
            mCurrentSelectedItem = -1;
}

From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java

public Loader<Response<UserList>> onCreateLoader(final int id, final Bundle args) {
    mListContainer.setVisibility(View.VISIBLE);
    mErrorMessageView.setText(null);// w  w  w.  j  a  v  a 2  s .  c om
    mErrorMessageView.setVisibility(View.GONE);
    mErrorRetryContainer.setVisibility(View.GONE);
    setListShown(false);
    setProgressBarIndeterminateVisibility(true);
    long account_id = -1, user_id = -1;
    int list_id = -1;
    String screen_name = null, list_name = null;
    if (args != null) {
        account_id = args.getLong(INTENT_KEY_ACCOUNT_ID, -1);
        user_id = args.getLong(INTENT_KEY_USER_ID, -1);
        list_id = args.getInt(INTENT_KEY_LIST_ID, -1);
        list_name = args.getString(INTENT_KEY_LIST_NAME);
        screen_name = args.getString(INTENT_KEY_SCREEN_NAME);
    }
    return new ListInfoLoader(getActivity(), account_id, list_id, list_name, user_id, screen_name);
}

From source file:android.support.v17.leanback.app.GuidedStepFragment.java

/**
 * Read UI style from fragment arguments.  Default value is {@link #UI_STYLE_ENTRANCE} when
 * fragment is first initialized.  UI style is used to choose different fragment transition
 * animations and determine if this is the first GuidedStepFragment on backstack.
 *
 * @return {@link #UI_STYLE_ACTIVITY_ROOT} {@link #UI_STYLE_REPLACE} or
 * {@link #UI_STYLE_ENTRANCE}.// ww w  .  j  a v a 2  s  . com
 * @see #onProvideFragmentTransitions()
 */
public int getUiStyle() {
    Bundle b = getArguments();
    if (b == null)
        return UI_STYLE_ENTRANCE;
    return b.getInt(EXTRA_UI_STYLE, UI_STYLE_ENTRANCE);
}

From source file:it.scoppelletti.mobilepower.app.FragmentLayoutController.java

/**
 * Ripristina lo stato dell&rsquo;istanza.
 * /*w  w w  .j ava2  s.  c o m*/
 * <P>L&rsquo;attivit&agrave; ripristina lo stato dell&rsquo;istanza
 * {@code FragmentLayoutController} all&rsquo;interno del proprio metodo
 * {@code onRestoreInstanceState}.</P>
 * 
 * @param savedInstanceState Stato dell&rsquo;istanza.
 * @param fragmentCollector  Collettore dei frammenti di dettaglio. 
 */
public void onRestoreInstanceState(Bundle savedInstanceState,
        FragmentLayoutController.FragmentCollector fragmentCollector) {
    int n, oldPanelCount, tnId;
    String tag;
    ActivitySupport activitySupport;
    FragmentSupport fragment;
    FragmentManager fragmentMgr;
    FragmentLayoutController.BackStackChangedListener backStackListener;
    Queue<FragmentSupport> fragmentQueue;
    Queue<FragmentLayoutController.FragmentEntry> clonedQueue;

    if (savedInstanceState == null) {
        throw new NullPointerException("Argument savedInstanceState is null.");
    }
    if (fragmentCollector == null) {
        throw new NullPointerException("Argument fragmentCollector is null.");
    }

    if (!(myActivity instanceof ActivitySupport)) {
        myLogger.warn("Activity not implement interface ActivitySupport.");
        return;
    }

    oldPanelCount = savedInstanceState.getInt(FragmentLayoutController.STATE_PANELCOUNT, 0);
    if (oldPanelCount < 1) {
        myLogger.warn("Unexpected {}={} in saved instance state.", FragmentLayoutController.STATE_PANELCOUNT,
                oldPanelCount);
        return;
    }

    myLogger.debug("{}: current={}, saved instance state={}.",
            new Object[] { FragmentLayoutController.STATE_PANELCOUNT, myFrameCount, oldPanelCount });
    if (oldPanelCount == myFrameCount) {
        // Il numero di pannelli non e' cambiato:
        // Il sistema ha gia' ripristinato correttamente i frammenti.
        return;
    }

    fragmentQueue = new ArrayDeque<FragmentSupport>();
    fragmentCollector.collectFragments(fragmentQueue);

    // Ad ogni frammento associo il tag con il quale &egrave; stato
    // inserito
    clonedQueue = new ArrayDeque<FragmentLayoutController.FragmentEntry>();
    while (!fragmentQueue.isEmpty()) {
        fragment = fragmentQueue.remove();
        if (fragment == null) {
            myLogger.warn("Ignoring null.");
            continue;
        }

        tag = fragment.asFragment().getTag();
        if (StringUtils.isBlank(tag)) {
            myLogger.warn("Ignoring fragment with empty tag.");
            continue;
        }

        clonedQueue.offer(new FragmentLayoutController.FragmentEntry(fragment.cloneFragment(), tag));
    }

    fragmentQueue = null; // free memory

    activitySupport = (ActivitySupport) myActivity;
    fragmentMgr = activitySupport.getSupportFragmentManager();

    // Ripristino la configurazione dei frammenti iniziale
    for (n = fragmentMgr.getBackStackEntryCount(); n > 0; n--) {
        fragmentMgr.popBackStack();
    }

    if (myFrameCount > 1) {
        tnId = arrangeFragments(fragmentMgr, clonedQueue);
    } else {
        tnId = arrangePanel(fragmentMgr, clonedQueue);
    }

    if (Build.VERSION.SDK_INT < BuildCompat.VERSION_CODES.HONEYCOMB) {
        return;
    }

    // - Android 4.1.2
    // La barra delle azioni non e' correttamente aggiornata forse perche'
    // si assume che non ce ne sia bisogno con transazioni schedulate
    // durante il ripristino dell'attivita' (o magari perche' non e' proprio
    // previsto che si schedulino transazioni durante il ripristino
    // dell'attivita'):
    // Visto che l'esecuzione delle transazioni e' asincrona, devo
    // utilizzare un gestore degli eventi di modifica del back stack che
    // gestisca l&rsquo;ultima transazione che ho schedulato.
    backStackListener = new FragmentLayoutController.BackStackChangedListener(myActivity, fragmentMgr, tnId);
    fragmentMgr.addOnBackStackChangedListener(backStackListener);
}