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.cylab.starslinger.view.SaveActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Safeslinger);
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        mListTopOffset = 0;/*w  ww  . j  a  v a  2 s. c o  m*/
        mListVisiblePos = 0;
    }

    final ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    bar.setTitle(R.string.app_name);
    bar.setSubtitle(R.string.title_save);

    setContentView(R.layout.savedata);

    mListViewSaveContacts = (ListView) findViewById(R.id.SaveScrollViewMembers);
    mButtonSave = (Button) findViewById(R.id.SaveButtonSave);

    // init
    mContacts = new ArrayList<ContactStruct>();

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        byte[] data = null;
        int length = extras.size();
        mMemData = new byte[length][];
        int i = 0;
        do {
            data = extras.getByteArray(ExchangeConfig.extra.MEMBER_DATA + i);
            if (data != null) {
                mMemData[i] = data;
                i++;
            }
        } while (data != null);
    }

    // display names list so users can selectively choose which to save
    if (mMemData != null) {
        mContacts = parseVCards(mMemData);

        SaveContactAdapter adapter = new SaveContactAdapter(SaveActivity.this, mContacts);
        mListViewSaveContacts.setAdapter(adapter);

        // restore list position
        mListViewSaveContacts.setSelectionFromTop(mListVisiblePos, mListTopOffset);
    }

    mButtonSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SaveSelectedContactsTask saveSelected = new SaveSelectedContactsTask();
            saveSelected.execute(new String());
        }
    });

    mListViewSaveContacts.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // nothing to do...
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // save list position
            if (visibleItemCount != 0) {
                mListVisiblePos = firstVisibleItem;
                View v = mListViewSaveContacts.getChildAt(0);
                mListTopOffset = (v == null) ? 0 : v.getTop();
            }
        }
    });

    mUnsyncName = getString(R.string.label_None);
    mUnsyncType = getString(R.string.label_phoneOnly);

    mPrefsSelected = false;

    mTableLayoutSpin = (TableLayout) findViewById(R.id.accountLayout);
    TextView textView = new TextView(this);
    mAccountSpinner = new Spinner(this);
    textView.setText(R.string.label_SaveAccount);
    textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mAccountSpinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    mTableLayoutSpin.addView(textView);
    mTableLayoutSpin.addView(mAccountSpinner);

    // Prepare model for account spinner
    mAccounts = new ArrayList<AccountData>();
    mAccountAdapter = new AccountAdapter(this, this, mAccounts);
    mAccountSpinner.setAdapter(mAccountAdapter);

    // Load account preference if any
    mPrefAccountName = SafeSlingerPrefs.getAccountName();
    mPrefAccountType = SafeSlingerPrefs.getAccountType();

    // Prepare the system account manager. On registering the listener
    // below, we also ask for
    // an initial callback to pre-populate the account list.
    AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);

    // Register handlers for UI elements
    mAccountSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long i) {
            updateAccountSelection();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // We don't need to worry about nothing being selected, since
            // Spinners don't allow
            // this.
        }
    });
}

From source file:illab.nabal.proxy.TwitterContext.java

/**
 * Called when user authorizes app request on OAuth web dialog.
 * //from   w ww  .  j  a  v  a  2 s  .  c om
 * @param bundle
 */
protected void onAuthComplete(final Bundle bundle) {
    Log.d(TAG, "called onAuthComplete()");
    mAuthWebDialog.dismiss();

    if (bundle != null) {
        Log.d(TAG, "bundle.size() : " + bundle.size());

        // create a new thread for HTTP connections 
        // since HTTP connections are forbidden on UI thread
        new Thread() {
            public void run() {
                try {
                    // if user authorizes app request, 
                    // fetch access token on non-UI thread
                    getAccessToken(bundle);
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage());
                    onAuthError(e.getMessage());
                }
            }
        }.start();

    } else {
        Log.e(TAG, "bundle IS NULL");
        onAuthError("bundle IS NULL");
    }
}

From source file:org.hfoss.posit.android.api.fragment.FindFragment.java

/**
 * This may be invoked by a FindActivity subclass, which may or may not have
 * latitude and longitude fields./*from   w  w w. j av  a2  s  .  co  m*/
 */
@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    // Sets listeners for various UI elements
    initializeListeners();

    mAddFindMenuPlugins = FindPluginManager.getFunctionPlugins(FindPluginManager.ADD_FIND_MENU_EXTENSION);

    setHasOptionsMenu(true);

    // Initialize all UI elements for later uses
    mNameET = (EditText) getView().findViewById(R.id.nameEditText);
    mDescriptionET = (EditText) getView().findViewById(R.id.descriptionEditText);
    mGuidTV = (TextView) getView().findViewById(R.id.guidValueTextView);
    mGuidRealTV = (TextView) getView().findViewById(R.id.guidRealValueTextView);
    mTimeTV = (TextView) getView().findViewById(R.id.timeValueTextView);
    mLatTV = (TextView) getView().findViewById(R.id.latitudeTextView);
    mLatitudeTV = (TextView) getView().findViewById(R.id.latitudeValueTextView);
    mLongTV = (TextView) getView().findViewById(R.id.longitudeTextView);
    mLongitudeTV = (TextView) getView().findViewById(R.id.longitudeValueTextView);
    mAdhocTV = (TextView) getView().findViewById(R.id.isAdhocTextView);

    // Check if settings allow Geotagging
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mGeoTagEnabled = prefs.getBoolean("geotagKey", true);

    // If enabled, get location manager and provider
    if (mGeoTagEnabled) {
        mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    }

    // Set the content of UI elements, either auto-generated or retrieved
    // from a Find
    Bundle extras = getArguments();

    if (extras != null && !(extras.size() == 1 && extras.containsKey("ACTION"))) {
        // Existing Find
        if (getAction().equals(Intent.ACTION_EDIT)) {
            int id = extras.getInt(Find.ORM_ID);
            Log.i(TAG, "ORM_id = " + id);
            //            Find find = getHelper().getFindById(id);
            mFind = getHelper().getFindById(id);
            Log.i(TAG, "Updating: " + mFind);
            displayContentInView(mFind);
        } else

        // Bundled Find (from SMS)
        if (getAction().equals(Intent.ACTION_INSERT_OR_EDIT)) {
            // Pull a Bundle corresponding to a Find from the Intent and put
            // that in the view
            Bundle findBundle = extras.getBundle("findbundle");
            //Find find;
            try {
                FindPlugin plugin = FindPluginManager.mFindPlugin;
                if (plugin == null) {
                    Log.e(TAG, "Could not retrieve Find Plugin.");
                    Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                            Toast.LENGTH_LONG).show();
                    getActivity().finish();
                    return;
                }
                mFind = plugin.getmFindClass().newInstance();
            } catch (IllegalAccessException e) {
                Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                        Toast.LENGTH_LONG).show();
                getActivity().finish();
                return;
            } catch (java.lang.InstantiationException e) {
                Toast.makeText(getActivity(), "A fatal error occurred while trying to start FindActivity",
                        Toast.LENGTH_LONG).show();
                getActivity().finish();
                return;
            }
            mFind.updateObject(findBundle);
            displayContentInView(mFind);
        } else
        // CSV Find   
        if (getAction().equals(CsvListFindsFragment.ACTION_CSV_FINDS)) {

        }
        // New Find
    } else {
        Log.i("TAG", "new find");
        // Set real GUID
        if (mGuidRealTV != null)
            mGuidRealTV.setText(UUID.randomUUID().toString());
        // Set displayed GUID
        if (mGuidTV != null)
            mGuidTV.setText(mGuidRealTV.getText().toString().substring(0, 8) + "...");
        // Set Time
        if (mTimeTV != null) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            Date date = new Date();
            mTimeTV.setText(dateFormat.format(date));
        }

        if (mGeoTagEnabled) {
            // Set Longitude and Latitude
            mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this);
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);

            Location netLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if (gpsLocation != null) {
                mCurrentLocation = gpsLocation;
            } else {
                mCurrentLocation = netLocation;
            }

            if (mCurrentLocation == null) {
                Log.i(TAG, "Location issue, mCurrentLocation = " + mCurrentLocation);
                if (mLongitudeTV != null)
                    mLongitudeTV.setText("0.0");
                if (mLatitudeTV != null)
                    mLatitudeTV.setText("0.0");
                // Toast.makeText(this, "Unable to retrieve GPS info." +
                // " Please make sure your Data or Wi-Fi is enabled.",
                // Toast.LENGTH_SHORT).show();
                // Log.i(TAG,
                // "Cannot request location updates; Data or Wifi might not be enabled.");
            } else {
                if (mLongitudeTV != null)
                    mLongitudeTV.setText(String.valueOf(mCurrentLocation.getLongitude()));
                if (mLatitudeTV != null)
                    mLatitudeTV.setText(String.valueOf(mCurrentLocation.getLatitude()));
            }
        } else {
            if (mLongitudeTV != null && mLongTV != null) {
                mLongitudeTV.setVisibility(TextView.INVISIBLE);
                mLongTV.setVisibility(TextView.INVISIBLE);
            }
            if (mLatitudeTV != null && mLatTV != null) {
                mLatitudeTV.setVisibility(TextView.INVISIBLE);
                mLatTV.setVisibility(TextView.INVISIBLE);
            }
        }
    }
}

From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java

public InputStream executeRequestForInputStream(HttpRequestTypes requestType, String requestUrl, Bundle params)
        throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException,
        OAuthCommunicationException, IllegalStateException, IOException {

    if (accessToken == null) {

        throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED);
    }//w  w  w . j a v a2s  . c o  m

    StringBuilder requestParamsBuilder;

    switch (requestType) {

    case GET:

        HttpGet get = null;
        requestParamsBuilder = new StringBuilder('?');
        if (params != null && params.size() > 0) {

            Set<String> keySet = params.keySet();
            Iterator<String> keyIterator = keySet.iterator();
            String curKey;

            while (keyIterator.hasNext()) {

                curKey = keyIterator.next();

                requestParamsBuilder.append(curKey).append('=').append(params.get(curKey));

                requestParamsBuilder.append('&');

            }
        }

        switch (oAuthConfig.oAuthType) {

        case OAUTH_1_0_A:
            if (requestParamsBuilder.lastIndexOf("&") != -1)
                requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1);
            get = new HttpGet(requestUrl + requestParamsBuilder.toString());
            signHttpRequest(get);
            break;

        case OAUTH_2_0:

            requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken());

            get = new HttpGet(requestUrl + requestParamsBuilder.toString());
            break;
        }
        return httpManager.executeHttpRequestForStreamResponse(get);

    case POST:

        HttpPost post = null;

        List<NameValuePair> postParams = null;

        if (params != null && params.size() > 0) {

            Set<String> keySet = params.keySet();
            Iterator<String> keyIterator = keySet.iterator();
            String curKey;
            postParams = new ArrayList<NameValuePair>(params.size());

            while (keyIterator.hasNext()) {

                curKey = keyIterator.next();
                postParams.add(new BasicNameValuePair(curKey, params.getString(curKey)));
            }
        }

        switch (oAuthConfig.oAuthType) {

        case OAUTH_1_0_A:

            post = new HttpPost(requestUrl);

            signHttpRequest(post);
            break;

        case OAUTH_2_0:

            requestParamsBuilder = new StringBuilder('?');
            requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken());

            post = new HttpPost(requestUrl + requestParamsBuilder.toString());

            break;
        }

        post.setEntity(new UrlEncodedFormEntity(postParams));
        return httpManager.executeHttpRequestForStreamResponse(post);

    default:
        throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD);
    }

}

From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java

public String executeRequestForString(HttpRequestTypes requestType, String requestUrl, Bundle params)
        throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException,
        OAuthCommunicationException, IllegalStateException, IOException {

    if (accessToken == null) {

        throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED);
    }//  www  .ja  v a2 s . co m

    StringBuilder requestParamsBuilder;

    switch (requestType) {

    case GET:

        HttpGet get = null;
        requestParamsBuilder = new StringBuilder('?');
        if (params != null && params.size() > 0) {

            Set<String> keySet = params.keySet();
            Iterator<String> keyIterator = keySet.iterator();
            String curKey;

            while (keyIterator.hasNext()) {

                curKey = keyIterator.next();

                requestParamsBuilder.append(curKey).append('=').append(params.get(curKey));

                requestParamsBuilder.append('&');

            }
        }

        switch (oAuthConfig.oAuthType) {

        case OAUTH_1_0_A:
            if (requestParamsBuilder.lastIndexOf("&") != -1)
                requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1);
            get = new HttpGet(requestUrl + requestParamsBuilder.toString());
            signHttpRequest(get);
            break;

        case OAUTH_2_0:

            requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken());

            get = new HttpGet(requestUrl + requestParamsBuilder.toString());
            break;
        }
        return httpManager.executeHttpRequestForStringResponse(get);

    case POST:

        HttpPost post = null;

        List<NameValuePair> postParams = null;

        if (params != null && params.size() > 0) {

            Set<String> keySet = params.keySet();
            Iterator<String> keyIterator = keySet.iterator();
            String curKey;
            postParams = new ArrayList<NameValuePair>(params.size());

            while (keyIterator.hasNext()) {

                curKey = keyIterator.next();
                postParams.add(new BasicNameValuePair(curKey, params.getString(curKey)));
            }
        }

        switch (oAuthConfig.oAuthType) {

        case OAUTH_1_0_A:

            post = new HttpPost(requestUrl);

            signHttpRequest(post);
            break;

        case OAUTH_2_0:

            requestParamsBuilder = new StringBuilder('?');
            requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken());

            post = new HttpPost(requestUrl + requestParamsBuilder.toString());

            break;
        }

        post.setEntity(new UrlEncodedFormEntity(postParams));
        return httpManager.executeHttpRequestForStringResponse(post);

    default:
        throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD);
    }

}

From source file:com.kuassivi.october.util.Navigator.java

/**
 * Pops back with some specific fragment arguments.
 *
 * @param clazz          The fragment class
 * @param args           Arguments to update into the Fragment
 * @param clearArguments if true clear the current Fragment arguments
 *///w  ww  .j  ava 2 s . com
public void popToFragment(@NonNull Class<?> clazz, Bundle args, boolean clearArguments) {
    if (!(activity instanceof FragmentActivity)) {
        throw new RuntimeException("The activity must inherits from FragmentActivity or AppCompatActivity");
    }

    FragmentActivity fragmentActivity = (FragmentActivity) activity;
    FragmentManager fragmentManager = fragmentActivity.getSupportFragmentManager();

    /*
     * The method isFinishing() prevents to load a Fragment
     * when the activity is going to be killed or destroyed.
     */
    if (fragmentManager == null || fragmentActivity.isFinishing()) {
        return;
    }

    List<Fragment> fragments = fragmentManager.getFragments();
    int index;

    for (index = 0; index < fragments.size(); index++) {
        Fragment frag = fragments.get(index);
        if (frag.getClass().equals(clazz)) {
            if (args != null && args.size() > 0 && frag.getArguments() == null) {
                throw new IllegalArgumentException("Fragment constructor must call super()");
            }
            if (frag.getArguments() != null && args != null) {
                if (clearArguments) {
                    frag.getArguments().clear();
                }
                frag.getArguments().putAll(args);
            }
            this.fragment = frag;
            popToStack(index + 1);
            break;
        }
    }
}

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

@Override
public void dispatchInvalidateOptionsMenu() {
    if (DEBUG)/*from  w  ww  . j  a  va 2  s  . c o m*/
        Log.d(TAG, "[dispatchInvalidateOptionsMenu]");

    Bundle savedActionViewStates = null;
    if (mMenu != null) {
        savedActionViewStates = new Bundle();
        mMenu.saveActionViewStates(savedActionViewStates);
        if (savedActionViewStates.size() > 0) {
            mMenuFrozenActionViewState = savedActionViewStates;
        }
        // This will be started again when the panel is prepared.
        mMenu.stopDispatchingItemsChanged();
        mMenu.clear();
    }
    mMenuRefreshContent = true;

    // Prepare the options panel if we have an action bar
    if (wActionBar != null) {
        mMenuIsPrepared = false;
        preparePanel();
    }
}

From source file:com.silentcircle.contacts.editor.ContactEditorFragment.java

/**
 * Merges extras from the intent./* ww  w .  j av  a 2 s  .  co  m*/
 */
public void setIntentExtras(Bundle extras) {
    if (extras == null || extras.size() == 0) {
        return;
    }

    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
    for (RawContactDelta state : mState) {
        final AccountType type = state.getAccountType(accountTypes);
        if (type.areContactsWritable()) {
            // Apply extras to the first writable raw contact only
            RawContactModifier.parseExtras(mContext, type, state, extras);
            break;
        }
    }
}

From source file:jackpal.androidterm.Term.java

private String makePathFromBundle(Bundle extras) {
    if (extras == null || extras.size() == 0) {
        return "";
    }/*  www. j av a2  s.  c o m*/

    String[] keys = new String[extras.size()];
    keys = extras.keySet().toArray(keys);
    Collator collator = Collator.getInstance(Locale.US);
    Arrays.sort(keys, collator);

    StringBuilder path = new StringBuilder();
    for (String key : keys) {
        String dir = extras.getString(key);
        if (dir != null && !dir.equals("")) {
            path.append(dir);
            path.append(":");
        }
    }

    return path.substring(0, path.length() - 1);
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void doInvalidatePanelMenu(int featureId) {
    PanelFeatureState st = getPanelState(featureId, true);
    Bundle savedActionViewStates = null;
    if (st.menu != null) {
        savedActionViewStates = new Bundle();
        st.menu.saveActionViewStates(savedActionViewStates);
        if (savedActionViewStates.size() > 0) {
            st.frozenActionViewState = savedActionViewStates;
        }/*w  ww  .j  a va  2 s . c o  m*/
        // This will be started again when the panel is prepared.
        st.menu.stopDispatchingItemsChanged();
        st.menu.clear();
    }
    st.refreshMenuContent = true;
    st.refreshDecorView = true;

    // Prepare the options panel if we have an action bar
    if ((featureId == FEATURE_ACTION_BAR || featureId == FEATURE_OPTIONS_PANEL)
            && mDecorContentParent != null) {
        st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false);
        if (st != null) {
            st.isPrepared = false;
            preparePanel(st, null);
        }
    }
}