Example usage for android.os Bundle size

List of usage examples for android.os Bundle size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of mappings contained in this Bundle.

Usage

From source file:edu.cmu.sei.cloudlet.client.ska.adb.OutDataService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "Received data request.");
    Bundle extras = intent.getExtras();
    Log.v(TAG, "Number of items requested: " + extras.size());

    JSONObject jsonData = new JSONObject();
    for (String key : extras.keySet()) {
        try {//w  ww .j  a v a2 s. c o m
            jsonData.put(key, extras.getString(key));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    String jsonDataAsString = mDataHandler.getData(jsonData, this);

    Log.v(TAG, "Writing to file.");
    FileHandler.writeToFile(ADBConstants.OUT_FILE_PATH, jsonDataAsString);
    Log.v(TAG, "Finished writing to file.");

    // We don't need this service to run anymore.
    stopSelf();
    return START_NOT_STICKY;
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem1.java

/**
 * Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.<br>
 * It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state.<br>
 * It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, 
 * as this callback tells the fragment when it is fully associated with the new activity instance.<br>
 * This is called after onCreateView(LayoutInflater, ViewGroup, Bundle) and before onViewStateRestored(Bundle).
 * /*from   www.j  a v a 2s . c  o m*/
 * @param savedInstanceState   If the fragment is being re-created from a previous saved state, this is the state.
 * 
 * @author Weijie Sun
 * @author Yufei Zhang
 * @version 1.1
 * @since 2015-03-15
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    user = SignInManager.loadFromFile(getActivity());
    Bundle bundle = getActivity().getIntent().getExtras();
    if (bundle.size() == 1) {
        EditItemActivity.addEditItemStatus = 0;
    } else if (bundle.size() == 2) {
        EditItemActivity.addEditItemStatus = 1;
        claimName = bundle.getString("MyClaimName");
        myItemId = bundle.getInt("myItemId");
        itemName = (TextView) getView().findViewById(R.id.itemNameEditText);
        datePicker = (DatePicker) getView().findViewById(R.id.itemDateDatePicker);
        category = (Spinner) getView().findViewById(R.id.itemCategorySpinner);
        currencyUnit = (Spinner) getView().findViewById(R.id.currencyUnitsSpinner);
        amount = (TextView) getView().findViewById(R.id.itemCurrencyEditText);
        EditItemActivity.itemId = this.myItemId;
        GetThread get = new GetThread(claimName);
        get.start();
        // set item name

    }

}

From source file:nuclei.task.TaskGcmService.java

@Override
public int onRunTask(TaskParams taskParams) {
    try {/*w  w w .  j a v  a  2s  . c  om*/
        Bundle bundle = taskParams.getExtras();
        String taskName = bundle.getString(TaskScheduler.TASK_NAME);
        Task task = (Task) Class.forName(taskName).newInstance();
        ArrayMap<String, Object> map = new ArrayMap<>(bundle.size());
        for (String key : bundle.keySet()) {
            map.put(key, bundle.get(key));
        }
        task.deserialize(map);
        if (task.isRunning())
            return GcmNetworkManager.RESULT_RESCHEDULE;
        task.attach(null, ContextHandle.getApplicationHandle());
        task.run();
        task.deliverResult(this);
        return GcmNetworkManager.RESULT_SUCCESS;
    } catch (Exception err) {
        LOG.e("Error running task", err);
        return GcmNetworkManager.RESULT_FAILURE;
    }
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditItem2.java

/**
 * Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.<br>
 * It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state.<br>
 * It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, 
 * as this callback tells the fragment when it is fully associated with the new activity instance.<br>
 * This is called after onCreateView(LayoutInflater, ViewGroup, Bundle) and before onViewStateRestored(Bundle).
 * //from w ww  .  j a va2s .c o m
 * @param savedInstanceState   If the fragment is being re-created from a previous saved state, this is the state.
 * @author Weijie Sun
 * @version 1.1
 * @since 2015-03-15
 * @author Yufei Zhang
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    user = SignInManager.loadFromFile(getActivity());
    Bundle bundle = getActivity().getIntent().getExtras();
    if (bundle.size() == 1) {
        EditItemActivity.addEditItemStatus = 0;
    } else if (bundle.size() == 2) {
        EditItemActivity.addEditItemStatus = 1;
        claimName = bundle.getString("MyClaimName");
        myItemId = bundle.getInt("myItemId");
        itemDescription = (TextView) getView().findViewById(R.id.fragmentEditItem2DiscriptionEditText);
        GetThread get = new GetThread(claimName);
        get.start();
    }

}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.LockActivity.java

private void handleExtra(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null && extras.size() > 0) {
        for (String k : extras.keySet()) {
            Log.i(TAG, "k = " + k + " : " + extras.getString(k));
        }/*from   w  w  w  .j  a v  a  2  s  . co  m*/
    }
    if (extras != null && "dialog".equals(extras.get("_extra1"))) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle("" + extras.get("_extra2"));
        alertDialogBuilder.setMessage("" + extras.get("_extra3")).setCancelable(false).setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        alertDialogBuilder.create().show();
    }
}

From source file:org.dmfs.android.retentionmagic.RetentionMagic.java

private static void init(final Class<?> classInstance, final Object instance, final Bundle bundle)
        throws IllegalAccessException {
    if (bundle == null || bundle.size() == 0) {
        return;/* w  w w.j  a  va  2s.  c  om*/
    }

    for (Field field : classInstance.getDeclaredFields()) {
        Parameter param = field.getAnnotation(Parameter.class);
        if (param != null && !ArrayList.class.isAssignableFrom(field.getType())) {
            field.setAccessible(true);

            String key = param.key();
            if (key == null || key.length() == 0) {
                key = field.getName();
            }

            PersistenceHelper helper = getHelper(field.getType());
            if (helper != null) {
                helper.restoreFromBundle(field, instance, key, bundle);
            } else {
                throw new UnsupportedOperationException("field of class " + field.getType().getCanonicalName()
                        + " not supported for initialization from a Bundle");
            }
        } else if (param != null) {
            throw new UnsupportedOperationException(
                    "@Parameter does not support ArrayLists, use @ParameterArrayList instead");
        } else {
            ParameterArrayList paramList = field.getAnnotation(ParameterArrayList.class);
            if (paramList != null && ArrayList.class.isAssignableFrom(field.getType())) {
                field.setAccessible(true);
                String key = paramList.value();
                if (key == null || key.length() == 0) {
                    key = field.getName();
                }

                PersistenceHelper helper = getArrayListHelper(paramList.genericType());
                if (helper != null) {
                    helper.restoreFromBundle(field, instance, key, bundle);
                } else {
                    throw new UnsupportedOperationException("list with generic type of "
                            + field.getType().getCanonicalName() + " not supported");
                }
            } else if (paramList != null) {
                throw new UnsupportedOperationException(
                        "@ParameterArrayList supports only ArrayList fields, use @Parameter instead");
            }
        }

    }
}

From source file:com.facebook.share.internal.DeviceShareDialogFragment.java

private void startShare() {
    Bundle parameters = getGraphParametersForShareContent();
    if (parameters == null || parameters.size() == 0) {
        this.finishActivityWithError(new FacebookRequestError(0, "", "Failed to get share content"));
    }/*from  w w  w.j ava  2 s  . c o m*/

    String accessToken = Validate.hasAppID() + "|" + Validate.hasClientToken();
    parameters.putString(GraphRequest.ACCESS_TOKEN_PARAM, accessToken);
    parameters.putString(DeviceRequestsHelper.DEVICE_INFO_PARAM, DeviceRequestsHelper.getDeviceInfo());

    GraphRequest graphRequest = new GraphRequest(null, DEVICE_SHARE_ENDPOINT, parameters, HttpMethod.POST,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        finishActivityWithError(error);
                        return;
                    }

                    JSONObject jsonObject = response.getJSONObject();
                    RequestState requestState = new RequestState();
                    try {
                        requestState.setUserCode(jsonObject.getString("user_code"));
                        requestState.setExpiresIn(jsonObject.getLong("expires_in"));
                    } catch (JSONException ex) {
                        finishActivityWithError(new FacebookRequestError(0, "", "Malformed server response"));
                        return;
                    }

                    setCurrentRequestState(requestState);
                }
            });
    graphRequest.executeAsync();
}

From source file:com.example.hllut.app.Deprecated.MainActivity.java

/**
 * Parse the data received from the intent. Assign the total CO2 output to a
 * local variable and fill a local HashMap with the food categories and their CO2 output.
 *///from ww  w.  jav  a 2  s.  c  o m
private void parse(Bundle data) {
    String[] foodTypes = data.keySet().toArray(new String[data.size()]);

    for (String s : foodTypes) {
        if (s.matches("Total")) {
            total = data.getFloat(s);
        } else {
            float cO2 = data.getFloat(s);
            food.put(s, cO2);
        }
    }

    System.out.println(food);

}

From source file:org.jboss.aerogear.android.authentication.impl.loader.support.SupportAuthenticationModuleAdapter.java

@Override
public Loader<HeaderAndBody> onCreateLoader(int id, Bundle bundle) {
    SupportAuthenticationModuleAdapter.Methods method = (SupportAuthenticationModuleAdapter.Methods) bundle
            .get(METHOD);//from   www . j ava  2s  . c o  m
    Callback callback = (Callback) bundle.get(CALLBACK);
    Loader loader = null;
    switch (method) {
    case LOGIN: {
        Bundle loginBundle = bundle.getBundle(PARAMS);
        Map<String, String> loginParams = new HashMap<String, String>(loginBundle.size());
        for (String key : loginBundle.keySet()) {
            loginParams.put(key, loginBundle.getString(key));
        }
        loader = new SupportLoginLoader(applicationContext, callback, module, loginParams);
    }
        break;
    case LOGOUT: {
        loader = new SupportLogoutLoader(applicationContext, callback, module);
    }
        break;
    case ENROLL: {
        Map<String, String> params = (Map<String, String>) bundle.getSerializable(PARAMS);
        loader = new SupportEnrollLoader(applicationContext, callback, module, params);
    }
        break;
    }
    return loader;
}

From source file:org.jboss.aerogear.android.authentication.impl.loader.AuthenticationModuleAdapter.java

@Override
public Loader<HeaderAndBody> onCreateLoader(int id, Bundle bundle) {
    AuthenticationModuleAdapter.Methods method = (AuthenticationModuleAdapter.Methods) bundle.get(METHOD);
    Callback callback = (Callback) bundle.get(CALLBACK);
    Loader loader = null;// w ww . j a v  a 2  s  .  c  o m
    switch (method) {
    case LOGIN: {
        Bundle loginBundle = bundle.getBundle(PARAMS);
        Map<String, String> loginParams = new HashMap<String, String>(loginBundle.size());
        for (String key : loginBundle.keySet()) {
            loginParams.put(key, loginBundle.getString(key));
        }
        loader = new LoginLoader(applicationContext, callback, module, loginParams);
    }
        break;
    case LOGOUT: {
        loader = new LogoutLoader(applicationContext, callback, module);
    }
        break;
    case ENROLL: {
        Map<String, String> params = (Map<String, String>) bundle.getSerializable(PARAMS);
        loader = new EnrollLoader(applicationContext, callback, module, params);
    }
        break;
    }
    return loader;
}