Example usage for android.os Bundle get

List of usage examples for android.os Bundle get

Introduction

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

Prototype

@Nullable
public Object get(String key) 

Source Link

Document

Returns the entry with the given key as an object.

Usage

From source file:com.rappsantiago.weighttracker.profile.setup.ProfileSetupActivity.java

private boolean saveAndValidatePageData(int currentPage) {

    Fragment currentFragment = mPagerAdapter.getItem(currentPage);

    if (currentFragment instanceof PageWithData) {
        PageWithData currentFragmentData = (PageWithData) currentFragment;
        Bundle pageData = currentFragmentData.getProfileData();

        if (null == pageData) {
            return false;
        }/*from w  ww  .j  a va 2 s .co m*/

        Set<String> errors = new HashSet<>();

        // validate entries
        for (String key : pageData.keySet()) {
            Object obj = pageData.get(key);

            if (null == obj) {
                errors.add(key);
                continue;
            }

            if (obj instanceof String) { // name
                if (((String) obj).trim().isEmpty()) {
                    errors.add(key);
                }
            } else if (obj instanceof Double) { // weight, body fat index, height

                // body fat index is optional
                if (WeightHeightFragment.KEY_BODY_FAT_INDEX == key
                        || SetGoalsFragment.KEY_TARGET_BODY_FAT_INDEX == key) {
                    continue;
                }

                // inches is allowed to be 0 if foot is not less than or equal to 0
                if (WeightHeightFragment.KEY_HEIGHT_INCHES == key) {
                    if (errors.contains(WeightHeightFragment.KEY_HEIGHT)) {
                        if (0 >= ((Double) obj).doubleValue()) {
                            errors.add(key);
                        } else {
                            errors.remove(WeightHeightFragment.KEY_HEIGHT);
                        }
                    } else {
                        continue;
                    }
                }

                if (0 >= ((Double) obj).doubleValue()) {
                    errors.add(key);
                }
            } else if (obj instanceof Long) { // birthday, due date

                // due date is optional
                if (SetGoalsFragment.KEY_DUE_DATE == key) {
                    continue;
                }

                if (0 >= ((Long) obj).longValue()) {
                    errors.add(key);
                }
            }
        }

        boolean withNoErrors = errors.isEmpty();

        if (withNoErrors) {
            Log.d(TAG, "pageData = " + pageData);
            mProfileData.putAll(pageData);
        } else {
            Log.d(TAG, errors.toString());
            currentFragmentData.showErrorMessage(errors);
        }

        return withNoErrors;
    } else {
        return true;
    }
}

From source file:com.hybris.mobile.lib.location.geofencing.service.GeofencingIntentService.java

/**
 * Handles incoming intents/*from w w  w  .  j av a 2  s  . com*/
 *
 * @param intent The Intent sent by Location Services. This Intent is provided to Location Services (inside a
 *               PendingIntent) when you call addGeofences()
 */
@Override
protected void onHandleIntent(Intent intent) {

    Log.i(TAG, "Geofencing event received");

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);

    // Check for errors
    if (geofencingEvent.hasError()) {
        Log.e(TAG, "Error with geofencing. Error Code: " + geofencingEvent.getErrorCode());
    } else {
        // Get the type of transition (entry or leaving_geofence)
        int geofenceTransition = geofencingEvent.getGeofenceTransition();

        Log.i(TAG, "Geofence transition type: " + geofenceTransition);

        // Test that a valid transition was reported
        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER
                || geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT) {

            // Post a notification
            List<Geofence> geofences = geofencingEvent.getTriggeringGeofences();

            if (geofences != null && !geofences.isEmpty()) {
                for (Geofence geofence : geofences) {

                    Log.d(TAG, "Intent information: ");

                    Bundle intentBundle = intent
                            .getBundleExtra(GeofencingConstants.PREFIX_INTENT_BUNDLE + geofence.getRequestId());

                    if (intentBundle != null) {

                        Log.d(TAG, "Bundle information: ");
                        for (String key : intentBundle.keySet()) {
                            Log.d(TAG, "Key: " + key + ". Value: " + intentBundle.get(key));
                        }

                        sendNotification(geofence, (GeofenceObject.Notification) intentBundle.getParcelable(
                                GeofencingConstants.PREFIX_INTENT_NOTIFICATION_TRANSITION + geofenceTransition),
                                geofenceTransition);
                    } else {
                        Log.e(TAG, "No bundle found for geofence id " + geofence.getRequestId());
                    }

                }
            } else {
                Log.e(TAG, "No associated geofences found for transition " + geofenceTransition);
            }

        } else {
            // Log the error.
            Log.e(TAG, "Geofence transition not supported by the library. Details: " + geofenceTransition);
        }
    }
}

From source file:com.kakao.util.helper.SharedPreferencesCache.java

public synchronized void save(final Bundle bundle) {
    Utility.notNull(bundle, "bundle");

    SharedPreferences.Editor editor = file.edit();
    for (String key : bundle.keySet()) {
        try {//from  ww w . ja va 2 s.c o m
            serializeKey(key, bundle.get(key), editor);
        } catch (JSONException e) {
            Logger.w("SharedPreferences.save", "Error serializing value for key: " + key + ", e = " + e);
            return;
        }
    }

    editor.apply();
    for (String key : bundle.keySet()) {
        try {
            deserializeKey(key);
        } catch (JSONException e) {
            Logger.w("SharedPreferences.save", "Error deserializing value for key: " + key + ", e = " + e);
        }
    }
}

From source file:andlabs.lounge.service.LoungeServiceImpl.java

private void sendMessage(String pType, String pPackageId, String pMatchId, Bundle pMoveBundle) {
    try {/*w w  w.  ja v a 2 s . com*/
        // PAYLOAD { gameID: packageID?, matchID: matchID?, move: {... } }
        JSONObject payload = new JSONObject().put("gameID", pPackageId).put("matchID", pMatchId);
        JSONObject bundleJson = new JSONObject();
        for (String key : pMoveBundle.keySet()) {
            bundleJson.put(key, pMoveBundle.get(key));
        }
        payload.put("move", bundleJson.toString());
        mSocketIO.emit(pType, payload);
    } catch (JSONException e) {
        Ln.e(e, pType + "(): caught exception while sending move");
    }
}

From source file:com.inbeacon.cordova.CordovaInbeaconManager.java

/**
 * Transform Android event data into JSON Object used by JavaScript
 * @param intent inBeacon SDK event data
 * @return a JSONObject with keys 'event', 'name' and 'data'
 *///  w w  w.ja v  a 2  s  .  c  o m
private JSONObject getEventObject(Intent intent) {
    String action = intent.getAction();
    String event = action.substring(action.lastIndexOf(".") + 1); // last part of action
    String message = intent.getStringExtra("message");
    Bundle extras = intent.getExtras();

    JSONObject eventObject = new JSONObject();
    JSONObject data = new JSONObject();

    try {
        if (extras != null) {
            Set<String> keys = extras.keySet();
            for (String key : keys) {
                data.put(key, extras.get(key)); // Android API < 19
                //                    data.put(key, JSONObject.wrap(extras.get(key)));    // Android API >= 19
            }
        }
        data.put("message", message);

        eventObject.put("name", event);
        eventObject.put("data", data);

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage(), e);
    }

    return eventObject;
}

From source file:bander.notepad.NoteEditAppCompat.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Setting the theme

    Notepad.setAppCompatThemeFromPreferences(this, "Edit");

    if (savedInstanceState != null) {
        final Object note = savedInstanceState.get(ORIGINAL_NOTE);
        if (note != null)
            mOriginalNote = (Note) note;
    }//from w  w  w. ja  v a 2  s.c  o m

    final Intent intent = getIntent();
    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)) {
        mState = STATE_EDIT;
        mUri = intent.getData();
    } else if (Intent.ACTION_INSERT.equals(action)) {
        mState = STATE_INSERT;
        if (mOriginalNote == null) {
            mUri = getContentResolver().insert(intent.getData(), null);
        } else {
            mUri = mOriginalNote.getUri();
        }

        setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));
    }

    if (mUri == null) {
        finish();
        return;
    }

    {
        setContentView(R.layout.edit_appcompat);
        SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(this);

        ViewStub stub = (ViewStub) findViewById(R.id.toolbarWrapper);
        if (mSettings.getBoolean("darkAppCompatTheme", false))
            stub.setLayoutResource(R.layout.toolbar_dark);
        else
            stub.setLayoutResource(R.layout.toolbar_light);
        stub.inflate();
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        Notepad.setToolbarColor(this);
        setSupportActionBar(toolbar);

        if (mSettings.getBoolean("darkAppCompatTheme", false)) {
            toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        } else {
            toolbar.setNavigationIcon(
                    IconTintFactory.setDarkMaterialColor(R.drawable.abc_ic_ab_back_mtrl_am_alpha, this));
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mBodyText = (EditText) findViewById(R.id.body);

    }

}

From source file:edu.pdx.its.portal.routelandia.MapsActivity.java

/**
 * get all the data from save bundle*// w  w w  .j  av a 2  s.com
 * @param savedInstanceState: bundle from the activities
 */
private void getItemsFromSaveBundle(Bundle savedInstanceState) {
    //get the hashmap list of station before users rotate the phone
    listOfStationsBaseOnHighwayid = (HashMap<Integer, List<Station>>) savedInstanceState
            .get("a hashmap of list stations");

    //if users drag first marker, get the latlng back and re-create that marker
    if (savedInstanceState.get("lat of first marker") != null) {
        LatLng latLngOfFirstMarker = new LatLng((Double) savedInstanceState.get("lat of first marker"),
                (Double) savedInstanceState.get("lng of first marker"));
        firstMarker = mMap.addMarker(new MarkerOptions().position(latLngOfFirstMarker)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)).draggable(true)
                .title("Start"));
        startPoint = firstMarker.getPosition();
    }

    //if users drag second marker, get the latlng back and re-create that marker
    if (savedInstanceState.get("lat of second marker") != null) {
        LatLng latLngOfSecondMarker = new LatLng((Double) savedInstanceState.get("lat of second marker"),
                (Double) savedInstanceState.get("lng of second marker"));
        secondMarker = mMap.addMarker(new MarkerOptions().position(latLngOfSecondMarker)
                .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).draggable(true)
                .title("End"));
        endPoint = secondMarker.getPosition();
    }
}

From source file:com.xixicm.ca.presentation.mvp.MvpFragment.java

/**
 * Called in {@link #onViewCreated}//w ww. j  a v a2 s  . c om
 *
 * @param savedInstanceState
 */
protected void onInitializePresenter(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        // For the back stack fragment, it's just destroy the view. So keep the viewModel here.
        mPresenter.attachView((V) this, mPresenter.getViewModel());
    } else {
        M viewModel;
        if (mPresenter.getViewModel() != null) {
            // no need to restore from the savedInstanceState, if mPresenter.getViewModel() is not null.
            viewModel = mPresenter.getViewModel();
        } else {
            viewModel = (M) savedInstanceState.get(VIEW_MODE_KEY);
        }
        mPresenter.attachView((V) this, viewModel);
    }
}

From source file:com.androzic.plugin.tracker.SMSReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String Sender = "";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.e(TAG, "SMS received");

    Bundle extras = intent.getExtras();
    if (extras == null)
        return;//from  w  ww .ja  va 2  s.  co m

    StringBuilder messageBuilder = new StringBuilder();
    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String text = msg.getMessageBody();
        Sender = msg.getDisplayOriginatingAddress();
        Log.w(TAG, "Sender: " + Sender);
        if (text == null)
            continue;
        messageBuilder.append(text);
    }

    String text = messageBuilder.toString();
    boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode),
            context.getResources().getBoolean(R.bool.def_flex_mode));

    Log.i(TAG, "SMS: " + text);
    Tracker tracker = new Tracker();
    if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker)
            && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode))
        return;

    if (tracker.message != null) {
        tracker.message = tracker.message.trim();
        if ("".equals(tracker.message))
            tracker.message = null;
    }

    tracker.sender = Sender;

    if (!"".equals(tracker.sender)) {
        // Save tracker data
        TrackerDataAccess dataAccess = new TrackerDataAccess(context);
        dataAccess.updateTracker(tracker);

        try {
            Application application = Application.getApplication();
            tracker = dataAccess.getTracker(tracker.sender);//get  latest positon of tracker

            application.sendTrackerOnMap(dataAccess, tracker);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dataAccess.close();

        context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST));

        // Show notification
        boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications),
                context.getResources().getBoolean(R.bool.def_notifications));
        if (notifications) {
            Intent i = new Intent("com.androzic.COORDINATES_RECEIVED");
            i.putExtra("title", tracker.message != null ? tracker.message : tracker.name);
            i.putExtra("sender", tracker.name);
            i.putExtra("origin", context.getApplicationContext().getPackageName());
            i.putExtra("lat", tracker.latitude);
            i.putExtra("lon", tracker.longitude);

            String msg = context.getString(R.string.notif_text, tracker.name);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle(context.getString(R.string.app_name));
            if (tracker.message != null)
                builder.setContentText(tracker.name + ": " + tracker.message);
            else
                builder.setContentText(msg);
            PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i,
                    PendingIntent.FLAG_ONE_SHOT);
            builder.setContentIntent(contentIntent);
            builder.setSmallIcon(R.drawable.ic_stat_tracker);
            builder.setTicker(msg);
            builder.setWhen(tracker.time);
            int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
            boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate),
                    context.getResources().getBoolean(R.bool.def_vibrate));
            if (vibrate)
                defaults |= Notification.DEFAULT_VIBRATE;
            builder.setDefaults(defaults);
            builder.setAutoCancel(true);
            Notification notification = builder.build();
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify((int) tracker._id, notification);
        }

        // Conceal SMS
        boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms),
                context.getResources().getBoolean(R.bool.def_concealsms));
        if (concealsms)
            abortBroadcast();
    }
}

From source file:com.google.android.gms.location.sample.locationaddress.LocationMainActivity.java

/**
 * Kicks off the request to fetch an address when pressed.
 */// ww w . j a  va2s  . c  o  m
//Button mFetchAddressButton;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.l_main_activity);
    buildGoogleApiClient();
    mResultReceiver = new AddressResultReceiver(new Handler());

    mLocationAddressTextView = (TextView) findViewById(R.id.location_address_view);
    mDescriptionTextView = (TextView) findViewById(R.id.descriptionTextView);
    mObjectTextView = (TextView) findViewById(R.id.objectTextView);
    mUserTextView = (TextView) findViewById(R.id.userTextView);
    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    //mFetchAddressButton = (Button) findViewById(R.id.fetch_address_button);

    // Set defaults, then update using values stored in the Bundle.
    mAddressRequested = true;
    mAddressOutput = "";
    if (mGoogleApiClient.isConnected() && mLastLocation != null) {
        startIntentService();
    }
    // If GoogleApiClient isn't connected, we process the user's request by setting
    // mAddressRequested to true. Later, when GoogleApiClient connects, we launch the service to
    // fetch the address. As far as the user is concerned, pressing the Fetch Address button
    // immediately kicks off the process of getting the address
    updateUIWidgets();

    Intent in = getIntent();
    Bundle b = in.getExtras();

    if (b != null) {
        if (b.containsKey("identifiedObject")) {
            objectName = b.get("identifiedObject").toString();
            description = b.get("description").toString();
            // mObjectTextView.setText(objectName);
            // mDescriptionTextView.setText(description);
            userName = b.get("userName").toString();
            //    encodedImage = b.get("encodedImage").toString();

            //mUserTextView.setText(userName);
        }

    }

    updateValuesFromBundle(savedInstanceState);
    //fetchUserIdentity();
    //updateUIWidgets();

}