Example usage for android.os Bundle putParcelable

List of usage examples for android.os Bundle putParcelable

Introduction

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

Prototype

public void putParcelable(@Nullable String key, @Nullable Parcelable value) 

Source Link

Document

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

Usage

From source file:com.marianhello.bgloc.LocationService.java

/**
 * Handle location from location location provider
 *
 * All locations updates are recorded in local db at all times.
 * Also location is also send to all messenger clients.
 *
 * If option.url is defined, each location is also immediately posted.
 * If post is successful, the location is deleted from local db.
 * All failed to post locations are coalesced and send in some time later in one single batch.
 * Batch sync takes place only when number of failed to post locations reaches syncTreshold.
 *
 * If only option.syncUrl is defined, locations are send only in single batch,
 * when number of locations reaches syncTreshold.
 *
 * @param location//  w  w  w .  j  av a 2 s  . c  om
 */
public void handleLocation(BackgroundLocation location) {
    log.debug("New location {}", location.toString());

    location.setBatchStartMillis(System.currentTimeMillis() + ONE_MINUTE); // prevent sync of not yet posted location
    persistLocation(location);

    if (config.hasUrl() || config.hasSyncUrl()) {
        Long locationsCount = dao.locationsForSyncCount(System.currentTimeMillis());
        log.debug("Location to sync: {} threshold: {}", locationsCount, config.getSyncThreshold());
        if (locationsCount >= config.getSyncThreshold()) {
            log.debug("Attempt to sync locations: {} threshold: {}", locationsCount, config.getSyncThreshold());
            SyncService.sync(syncAccount, getStringResource(Config.CONTENT_AUTHORITY_RESOURCE));
        }
    }

    if (hasConnectivity && config.hasUrl()) {
        postLocationAsync(location);
    }

    Bundle bundle = new Bundle();
    bundle.putParcelable("location", location);
    Message msg = Message.obtain(null, MSG_LOCATION_UPDATE);
    msg.setData(bundle);

    sendClientMessage(msg);
}

From source file:com.bczm.widgetcollections.player.MusicPlayer.java

private void sendPlayBundle() {
    Intent intent = new Intent(Constants.ACTION_MUSIC_BUNDLE_BROADCAST);
    Bundle extras = new Bundle();
    LogUtils.e("sendPlayBundle-------------------------------->" + getDuration());
    extras.putInt(Constants.KEY_MUSIC_TOTAL_DURATION, getDuration());
    extras.putParcelable(Constants.KEY_MUSIC_PARCELABLE_DATA, mMusicList.get(mCurPlayIndex));
    intent.putExtras(extras);//from   w  ww. j  a v  a2 s.  c  o  m
    mContext.sendBroadcast(intent);
}

From source file:com.oscarsalguero.solartracker.MainActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putBoolean(REQUESTING_LOCATION_UPDATES_KEY, mRequestingLocationUpdates);
    savedInstanceState.putParcelable(LOCATION_KEY, mLastLocation);
    savedInstanceState.putString(LAST_UPDATED_TIME_STRING_KEY, mLastUpdateTime);
    super.onSaveInstanceState(savedInstanceState);
}

From source file:com.alboteanu.android.sunshine.app.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocation = Utility.getPreferredLocation(this);
    Uri contentUri = getIntent() != null ? getIntent().getData() : null;
    PROJECT_NUMBER = getString(R.string.project_number);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w  w w. j  a  v a  2  s.c  o  m*/
    //        getSupportActionBar().setDisplayShowTitleEnabled(false);

    /* images = new int[] {R.drawable.city0, R.drawable.city1, R.drawable.city2};
     backImage_id_Key = getString(R.string.pref_background_image_key);
     id_image = prefs.getInt(backImage_id_Key, 2);
     ((ImageView) findViewById(R.id.backgroundImageView)).setImageResource(images[id_image]);*/

    if (findViewById(R.id.weather_detail_container) != null) {
        // The detail container view will be present only in the large-screen layouts
        // (res/layout-sw600dp). If this view is present, then the activity should be
        // in two-pane mode.
        mTwoPane = true;
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        if (savedInstanceState == null) {
            DetailFragment fragment = new DetailFragment();
            if (contentUri != null) {
                Bundle args = new Bundle();
                args.putParcelable(DetailFragment.DETAIL_URI, contentUri);
                fragment.setArguments(args);
            }
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG).commit();
        }
    } else {
        mTwoPane = false;
        getSupportActionBar().setElevation(0f);
    }

    ForecastFragment forecastFragment = ((ForecastFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_forecast));
    forecastFragment.setUseTodayLayout(!mTwoPane);
    if (contentUri != null) {
        forecastFragment.setInitialSelectedDate(WeatherContract.WeatherEntry.getDateFromUri(contentUri));
    }

    SunshineSyncAdapter.initializeSyncAdapter(this);

    // If Google Play Services is not available, some features, such as GCM-powered weather
    // alerts, will not be available.
    if (checkPlayServices()) {
        mGcm = GoogleCloudMessaging.getInstance(this);
        String regId = getRegistrationId(this);

        /*if (PROJECT_NUMBER.equals("Your Project Number")) {
        new AlertDialog.Builder(this)
        .setTitle("Needs Project Number")
        .setMessage("GCM will not function in Sunshine until you set the Project Number to the one from the Google Developers Console.")
        .setPositiveButton(android.R.string.ok, null)
        .create().show();
        } else */if (regId.isEmpty()) {
            registerInBackground(this);
        }
    } else {
        Log.i(LOG_TAG, "No valid Google Play Services APK. Weather alerts will be disabled.");
        // Store regID as null
        storeRegistrationId(this, null);
    }
    /*
            requestNewInterstitial();
            if (savedInstanceState == null)
    initTimer();*/

    // Load an ad into the AdMob banner view.
    loadBanner();
}

From source file:org.ohmage.auth.Authenticator.java

@Override
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType,
        Bundle loginOptions) throws NetworkErrorException {

    // Extract the email and refresh_token from the Account Manager, and ask
    // the server for a new refresh_token.
    String authToken = am.peekAuthToken(account, authTokenType);

    // Lets give another try to authenticate the user
    AccessToken token = null;//from  ww w . j  a  v  a  2 s.  co m
    UserRecoverableAuthException userRecoverableAuthException = null;

    if (TextUtils.isEmpty(authToken)) {
        final String refreshToken = am.getPassword(account);
        Log.i(TAG, "Auth token is null");
        if (refreshToken != null) {
            Log.i(TAG, "Refresh Token");
            try {
                // If the account credentials have not gone to the server yet we saved the
                // password for the user
                if (Boolean.parseBoolean(am.getUserData(account, USE_PASSWORD))) {
                    token = ohmageService.getAccessToken(account.name, refreshToken);
                    if (token != null) {
                        am.setUserData(account, Authenticator.USE_PASSWORD, String.valueOf(false));
                        am.setUserData(account, Authenticator.USER_ID, token.getUserId());
                    }
                } else {
                    // refresh token
                    if (Ohmage.USE_DSU_DATAPOINTS_API) {

                        Log.i(TAG, "Refresh Token with DSU");
                        token = ohmageService.refreshAccessToken(refreshToken, "refresh_token");
                    } else {
                        token = ohmageService.getAccessToken(refreshToken);
                    }
                }
            } catch (AuthenticationException e) {
                // This will happen if the refresh token was already used, or it was
                // invalidated or something

                // We can try getting the token from google
                String googleAccount = am.getUserData(account, USER_DATA_GOOGLE_ACCOUNT);
                if (googleAccount != null) {
                    try {
                        token = getTokenFromGoogle(googleAccount);
                        Log.i(TAG, token.toString());
                    } catch (UserRecoverableAuthException e1) {
                        userRecoverableAuthException = e1;
                    }
                }
            } catch (RetrofitError e) {
                if (e.getResponse() != null && e.getResponse().getStatus() == 409) {
                    // The user hasn't activated their account by clicking the link
                    final Bundle bundle = new Bundle();
                    bundle.putString(AccountManager.KEY_AUTH_FAILED_MESSAGE,
                            Ohmage.app().getString(R.string.account_not_activated));
                    bundle.putParcelable(AccountManager.KEY_INTENT,
                            new Intent(mContext, AccountNotActivatedDialog.class));
                    return bundle;
                } else {
                    throw new NetworkErrorException();
                }
            } catch (Exception e) {
                Log.e(TAG, "", e);
            }
        }
    }

    // If we get an authToken - we return it
    if (token != null) {
        am.setPassword(account, token.getRefreshToken());
        authToken = token.getAccessToken();
    }

    if (!TextUtils.isEmpty(authToken)) {
        final Bundle result = new Bundle();
        result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
        result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
        result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
        return result;
    }

    // If we get here, then we couldn't access the user's password - so we
    // need to re-prompt them for their credentials. We do that by creating
    // an intent to display our AuthenticatorActivity.
    final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
    intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
    intent.putExtra(AuthenticatorActivity.EXTRA_FROM_AUTHENTICATOR, true);
    intent.putExtra(AuthenticatorActivity.EXTRA_HANDLE_USER_RECOVERABLE_ERROR, userRecoverableAuthException);
    final Bundle bundle = new Bundle();
    bundle.putParcelable(AccountManager.KEY_INTENT, intent);
    return bundle;
}

From source file:com.bitants.wally.fragments.ImageZoomFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putInt(STATE_TOOLBAR_VISIBILITY, toolBarVisibility);
    if (bitmap != null) {
        outState.putParcelable(STATE_BITMAP, bitmap);
    }/*  www. j a  v a  2  s.co m*/
    if (fileUri != null) {
        outState.putParcelable(STATE_URI_FILE, fileUri);
    }
    if (contentUri != null) {
        outState.putParcelable(STATE_URI_CONTENT, contentUri);
    }
    super.onSaveInstanceState(outState);
}

From source file:at.tomtasche.reader.ui.activity.DocumentActivity.java

public DocumentLoader loadUri(Uri uri, String password, boolean limit, boolean translatable) {
    Bundle bundle = new Bundle();
    bundle.putString(EXTRA_PASSWORD, password);
    bundle.putParcelable(EXTRA_URI, uri);
    bundle.putBoolean(EXTRA_LIMIT, limit);
    bundle.putBoolean(EXTRA_TRANSLATABLE, translatable);

    int lastIndex = uri.toString().lastIndexOf("/");
    String name = uri.toString().substring(lastIndex + 1);
    mFrDocument = new FrDocument(-1, name, uri.toString(), FrDocument.DOCTYPE_ODT, FrDocument.getDate());
    mFrDocument.updateDate(FrDocument.getDate());
    DatabaseHandler handler = new DatabaseHandler(this);
    long id = handler.hasFrDocument(mFrDocument);
    if (id == -1) {
        handler.addFrDocument(mFrDocument);
    } else {/*from  w w w.j a v a  2 s.c  o m*/
        mFrDocument.updateId((int) id);
        handler.updateFrDocumentLastDate(mFrDocument);
    }
    return (DocumentLoader) getSupportLoaderManager().restartLoader(0, bundle, this);
}

From source file:com.adkdevelopment.earthquakesurvival.ui.MapviewFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (mGoogleMap != null) {
        CameraPosition save = mGoogleMap.getCameraPosition();
        outState.putParcelable(CAMERA_POSITION, save);
    }/*w ww  . j a  v  a2  s .  c om*/
}

From source file:com.ant.sunshine.app.activities.MainActivity.java

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

    //mLocationLatLng = Utility.getLocation();
    mLocation = Utility.getPreferredLocation(this);
    Uri contentUri = getIntent() != null ? getIntent().getData() : null;

    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.app_toolbar);
    setSupportActionBar(toolbar);/* w  w w  .ja  va  2s  .  co m*/
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    if (findViewById(R.id.weather_detail_container) != null) {
        // The detail container view will be present only in the large-screen layouts
        // (res/layout-sw600dp). If this view is present, then the activity should be
        // in two-pane mode.
        mTwoPane = true;
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        if (savedInstanceState == null) {
            DetailFragment fragment = new DetailFragment();
            if (contentUri != null) {
                Bundle args = new Bundle();
                args.putParcelable(DetailFragment.DETAIL_URI, contentUri);
                fragment.setArguments(args);
            }
            getFragmentManager().beginTransaction()
                    .replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG).commit();
        }
    } else {
        mTwoPane = false;
        getSupportActionBar().setElevation(0f);
    }
    initFragment(contentUri);
    SunshineSyncAdapter.initializeSyncAdapter(this);
    registerToGcm();
}

From source file:ro.tudorluca.gpstracks.android.MainActivity.java

/**
 * Stores activity data in the Bundle.//  ww w.  j ava2  s .c  o m
 */
public void onSaveInstanceState(Bundle savedInstanceState) {
    savedInstanceState.putBoolean(REQUESTING_LOCATION_UPDATES_KEY, mRequestingLocationUpdates);
    savedInstanceState.putParcelable(LOCATION_KEY, mCurrentLocation);
    savedInstanceState.putString(LAST_UPDATED_TIME_STRING_KEY, mLastUpdateTime);
    super.onSaveInstanceState(savedInstanceState);
}