Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:com.activiti.android.app.fragments.account.WelcomeFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(false);/*from   ww w  . j  a  va2 s.c  o  m*/

    if (getRootView() != null) {
        return getRootView();
    }

    setRootView(inflater.inflate(R.layout.fr_welcome, container, false));

    // Instantiate a ViewPager and a PagerAdapter.
    Bundle extras = getArguments();
    if (extras != null && extras.containsKey(WelcomeActivity.EXTRA_ADD_ACCOUNT)) {
        hide(R.id.welcome_title);
        hide(R.id.welcome_pager);
        hide(R.id.welcome_pager_indicator);
        LinearLayout layout = (LinearLayout) viewById(R.id.welcome_page_actions_container);
        layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
    } else if (getActivity().findViewById(R.id.double_panel) != null) {
        hide(R.id.welcome_title);
        hide(R.id.welcome_pager);
        hide(R.id.welcome_pager_indicator);
        LinearLayout layout = (LinearLayout) viewById(R.id.welcome_page_actions_container);
        layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
    } else {
        CircleIndicator defaultIndicator = (CircleIndicator) viewById(R.id.welcome_pager_indicator);
        mPager = (ViewPager) viewById(R.id.welcome_pager);
        mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
        mPager.setAdapter(mPagerAdapter);
        defaultIndicator.setViewPager(mPager);
    }

    return getRootView();
}

From source file:android.support.content.TestQueryCallback.java

public void assertReceivedContent(Uri expectedUri, final int expectedPageId) {
    mReplyLatch.assertHasItem(new Matcher<Pair<Integer, Cursor>>() {
        @Override/*w  w  w. ja v  a2 s  .  c  o  m*/
        public boolean matches(Pair<Integer, Cursor> value) {
            return expectedPageId == value.first;
        }
    });
    List<Pair<Integer, Cursor>> collected = mReplyLatch.getCollected();
    Cursor cursor = null;

    for (Pair<Integer, Cursor> pair : collected) {
        if (expectedPageId == pair.first) {
            cursor = pair.second;
        }
    }

    assertEquals(0, cursor.getCount()); // we don't add any records to our test cursor.
    Bundle extras = cursor.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey(URI_KEY));
    assertEquals(extras.getParcelable(URI_KEY), expectedUri);
    assertTrue(extras.containsKey(URI_PAGE_ID));
    assertEquals(extras.getInt(URI_PAGE_ID), expectedPageId);
}

From source file:ch.scythe.hsr.DayFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (savedInstanceState != null && savedInstanceState.containsKey(FRAGMENT_PARAMETER_DATA)) {
        week = (UiWeek) (savedInstanceState.getSerializable(FRAGMENT_PARAMETER_DATA));
        weekDay = (Weekday) (savedInstanceState.getSerializable(FRAGMENT_PARAMETER_WEEKDAY));
    }/*from  w  w w  . j a  v  a2 s  .  c o m*/

    layoutInflater = getLayoutInflater(savedInstanceState);
    View v = inflater.inflate(R.layout.timetable_day, container, false);
    TableLayout timeTable = (TableLayout) v.findViewById(R.id.timeTable);

    updateTable(timeTable);

    return v;
}

From source file:co.nerdart.ourss.fragment.EntriesListFragment.java

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

    if (getArguments() != null) {
        Bundle args = getArguments();

        if (args.containsKey(ARG_SHOW_FEED_INFO)) {
            mShowFeedInfo = getArguments().getBoolean(ARG_SHOW_FEED_INFO);
        }//  w w w.j a va2s.  c o  m

        if (args.containsKey(ARG_URI)) {
            mUri = getArguments().getParcelable(ARG_URI);

            mEntriesCursorAdapter = new EntriesCursorAdapter(getActivity(), mUri, null, mShowFeedInfo);
            PrefUtils.registerOnSharedPreferenceChangeListener(prefListener);
            getLoaderManager().initLoader(loaderId, null, this);
        }
    }
}

From source file:ca.rmen.android.poetassistant.main.PagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    Bundle bundle = (Bundle) state;
    if (bundle.containsKey(EXTRA_EXTRA_TAB)) {
        mExtraTab = (Tab) bundle.getSerializable(EXTRA_EXTRA_TAB);
        notifyDataSetChanged();//from   www.j  a v a 2  s .  c o  m
    }
}

From source file:com.nextgis.maplibui.control.PhotoGallery.java

@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;

        if (bundle.containsKey(BUNDLE_DELETED_IMAGES)) {
            ArrayList<Integer> deletedImages = bundle.getIntegerArrayList(BUNDLE_DELETED_IMAGES);

            if (deletedImages != null)
                mDeletedImages.addAll(deletedImages);
        }/*w w  w .ja  va 2s.co m*/
    }

    super.onRestoreInstanceState(state);
}

From source file:ch.bfh.instacircle.MessageListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
        setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
    }//from  w w w  .  j av  a2s .c om

    this.getListView().setTranscriptMode(2);
}

From source file:ca.mudar.parkcatcher.ui.fragments.FavoritesFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {

    String[] selectionArgs = null;
    if (id == FavoritesQuery._TOKEN && args.containsKey(Const.KEY_BUNDLE_CURSOR_SELECTION)) {
        selectionArgs = args.getStringArray(Const.KEY_BUNDLE_CURSOR_SELECTION);
    }/*ww  w  . j a  v  a  2s . c  o m*/

    return new CursorLoader(getSherlockActivity().getApplicationContext(), Posts.CONTENT_STARRED_URI,
            FavoritesQuery.FAVORITES_SUMMARY_PROJECTION, null, selectionArgs, Posts.FORBIDDEN_DISTANCE_SORT);
}

From source file:com.manning.androidhacks.hack023.authenticator.Authenticator.java

@Override
public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, Account account)
        throws NetworkErrorException {
    Bundle result = super.getAccountRemovalAllowed(response, account);

    if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT)
            && !result.containsKey(AccountManager.KEY_INTENT)) {
        boolean allowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);

        if (allowed) {
            for (int i = 0; i < authoritiesToSync.length; i++) {
                ContentResolver.cancelSync(account, authoritiesToSync[i]);
            }//from w  ww .j  a  v  a 2  s  . c  o  m

            mContext.deleteDatabase(DatabaseHelper.DATABASE_NAME);
        }
    }

    return result;
}

From source file:org.linkdroid.PostJob.java

/**
 * Posts the data to our webhook.//from  w  w w.  j  a v  a2 s .  co  m
 * 
 * The HMAC field calculation notes:
 * <ol>
 * <li>The Extras.HMAC field is calculated from all the non Extras.STREAM
 * fields; this includes all the original bundle extra fields, plus the
 * linkdroid fields (e.g Extras.STREAM_MIME_TYPE, and including
 * Extras.STREAM_HMAC); the NONCE is NOT prepended to the input since it will
 * be somewhere in the data bundle.</li>
 * <li>The Extras.STREAM_HMAC field is calculated by digesting the concat of
 * the NONCE (first) and the actual binary data obtained from the
 * EXTRAS_STREAM uri; this STREAM_HMAC field (along with the other
 * Extras.STREAM_* fields) are added to the data bundle, which will also be
 * hmac'd.</li>
 * <li>If no hmac secret is set, then the NONCEs will not be set in the upload
 * </li>
 * </ol>
 * 
 * @param contentResolver
 * @param webhook
 * @param data
 * @throws UnsupportedEncodingException
 * @throws IOException
 * @throws InvalidKeyException
 * @throws NoSuchAlgorithmException
 */
public static void execute(ContentResolver contentResolver, Bundle webhook, Bundle data)
        throws UnsupportedEncodingException, IOException, InvalidKeyException, NoSuchAlgorithmException {

    // Set constants that may be used in this method.
    final String secret = webhook.getString(WebhookColumns.SECRET);

    // This is the multipart form object that will contain all the data bundle
    // extras; it also will include the data of the extra stream and any other
    // extra linkdroid specific field required.
    MultipartEntity entity = new MultipartEntity();

    // Do the calculations to create our nonce string, if necessary.
    String nonce = obtainNonce(webhook);

    // Add the nonce to the data bundle if we have it.
    if (nonce != null) {
        data.putString(Extras.NONCE, nonce);
    }

    // We have a stream of data, so we need to add that to the multipart form
    // upload with a possible HMAC.
    if (data.containsKey(Intent.EXTRA_STREAM)) {
        Uri mediaUri = (Uri) data.get(Intent.EXTRA_STREAM);

        // Open our mediaUri, base 64 encode it and add it to our multipart upload
        // entity.
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Base64OutputStream b64os = new Base64OutputStream(baos);
        InputStream is = contentResolver.openInputStream(mediaUri);
        byte[] bytes = new byte[1024];
        int count;
        while ((count = is.read(bytes)) != -1) {
            b64os.write(bytes, 0, count);
        }
        is.close();
        baos.close();
        b64os.close();
        final String base64EncodedString = new String(baos.toByteArray(), UTF8);
        entity.addPart(Extras.STREAM, new StringBody(base64EncodedString, UTF8_CHARSET));

        // Add the mimetype of the stream to the data bundle.
        final String mimeType = contentResolver.getType(mediaUri);
        if (mimeType != null) {
            data.putString(Extras.STREAM_MIME_TYPE, mimeType);
        }

        // Do the hmac calculation of the stream and add it to the data bundle.
        // NOTE: This hmac string will be included as part of the input to the
        // other Extras hmac.
        if (shouldDoHmac(webhook)) {
            InputStream inputStream = contentResolver.openInputStream(mediaUri);
            final String streamHmac = hmacSha1(inputStream, secret, nonce);
            inputStream.close();
            data.putString(Extras.STREAM_HMAC, streamHmac);
            Log.d(TAG, "STREAM_HMAC: " + streamHmac);
        }
    }

    // Calculate the Hmac for all the items by iterating over the data bundle
    // keys in order.
    if (shouldDoHmac(webhook)) {
        final String dataHmac = calculateBundleExtrasHmac(data, secret);
        data.putString(Extras.HMAC, dataHmac);
        Log.d(TAG, "HMAC: " + dataHmac);
    }

    // Dump all the data bundle keys into the form.
    for (String k : data.keySet()) {
        Object value = data.get(k);
        // If the value is null, the key will still be in the form, but with
        // an empty string as its value.
        if (value != null) {
            entity.addPart(k, new StringBody(value.toString(), UTF8_CHARSET));
        } else {
            entity.addPart(k, new StringBody("", UTF8_CHARSET));
        }
    }

    // Create the client and request, then populate it with our multipart form
    // upload entity as part of the POST request; finally post the form.
    final String webhookUri = webhook.getString(WebhookColumns.URI);
    final HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(USER_AGENT_KEY, USER_AGENT);
    final HttpPost request = new HttpPost(webhookUri);
    request.setEntity(entity);
    HttpResponse response = client.execute(request);
    switch (response.getStatusLine().getStatusCode()) {
    case HttpStatus.SC_OK:
    case HttpStatus.SC_CREATED:
    case HttpStatus.SC_ACCEPTED:
        break;
    default:
        throw new RuntimeException(response.getStatusLine().toString());
    }
}