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.ryan.ryanreader.activities.CommentReplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);

    super.onCreate(savedInstanceState);

    final LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.comment_reply);

    usernameSpinner = (Spinner) layout.findViewById(R.id.comment_reply_username);
    textEdit = (EditText) layout.findViewById(R.id.comment_reply_text);

    if (getIntent() != null && getIntent().hasExtra("parentIdAndType")) {
        parentIdAndType = getIntent().getStringExtra("parentIdAndType");

    } else if (savedInstanceState != null && savedInstanceState.containsKey("comment_text")) {
        textEdit.setText(savedInstanceState.getString("comment_text"));
        parentIdAndType = savedInstanceState.getString("parentIdAndType");

    } else if (lastText != null) {
        textEdit.setText(lastText);/*from  www .j a  v a  2 s  . c  o  m*/
        parentIdAndType = lastParentIdAndType;
    }

    final ArrayList<RedditAccount> accounts = RedditAccountManager.getInstance(this).getAccounts();
    final ArrayList<String> usernames = new ArrayList<String>();

    for (RedditAccount account : accounts) {
        if (!account.isAnonymous()) {
            usernames.add(account.username);
        }
    }

    if (usernames.size() == 0) {
        General.quickToast(this, "You must be logged in to do that.");
        finish();
    }

    usernameSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernames));

    final ScrollView sv = new ScrollView(this);
    sv.addView(layout);
    setContentView(sv);
}

From source file:com.irccloud.android.fragment.BufferOptionsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context ctx = getActivity();//from w  w w . j  a v a 2s.c om
    if (ctx == null)
        return null;
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.dialog_buffer_options, null);
    unread = (SwitchCompat) v.findViewById(R.id.unread);
    joinpart = (SwitchCompat) v.findViewById(R.id.joinpart);
    collapse = (SwitchCompat) v.findViewById(R.id.collapse);
    expandDisco = (SwitchCompat) v.findViewById(R.id.expandDisco);

    if (savedInstanceState != null && bid == -1 && savedInstanceState.containsKey("bid")) {
        bid = savedInstanceState.getInt("bid");
        cid = savedInstanceState.getInt("cid");
        type = savedInstanceState.getString("type");
    }

    if (type != null && type.equalsIgnoreCase("console")) {
        joinpart.setVisibility(View.GONE);
        collapse.setVisibility(View.GONE);
    } else {
        expandDisco.setVisibility(View.GONE);
    }

    return new AlertDialog.Builder(ctx)
            .setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
            .setTitle("Display Options").setView(v).setPositiveButton("Save", new SaveClickListener())
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create();
}

From source file:com.github.gorbin.asne.odnoklassniki.OkSocialNetwork.java

private boolean checkTokenError(Bundle result) {
    if (result != null && result.containsKey(ERROR_CODE) && result.getString(ERROR_CODE).equals("102")) {
        mRequestBundle = result;/*from   w  ww  .  j  a va  2s  .  com*/
        mRequestBundle.remove(ERROR_CODE);
        mRequestBundle.remove(SocialNetworkAsyncTask.RESULT_ERROR);
        mOdnoklassniki.refreshToken(mActivity);
        return true;
    }
    return false;
}

From source file:com.ichi2.anki.DeckOptions.java

@Override
protected void onCreate(Bundle icicle) {
    Themes.setThemeLegacy(this);
    super.onCreate(icicle);

    mCol = CollectionHelper.getInstance().getCol(this);
    if (mCol == null) {
        finish();/*from   w  w w . ja  va 2 s.  com*/
        return;
    }
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("did")) {
        mDeck = mCol.getDecks().get(extras.getLong("did"));
    } else {
        mDeck = mCol.getDecks().current();
    }
    registerExternalStorageListener();

    if (mCol == null) {
        Timber.w("DeckOptions - No Collection loaded");
        finish();
    } else {
        mPref = new DeckPreferenceHack();
        mPref.registerOnSharedPreferenceChangeListener(this);

        this.addPreferencesFromResource(R.xml.deck_options);
        this.buildLists();
        this.updateSummaries();
        // Set the activity title to include the name of the deck
        String title = getResources().getString(R.string.deckpreferences_title);
        if (title.contains("XXX")) {
            try {
                title = title.replace("XXX", mDeck.getString("name"));
            } catch (JSONException e) {
                title = title.replace("XXX", "???");
            }
        }
        this.setTitle(title);
    }

    // Add a home button to the actionbar
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

@Override
public void onActivityCreated(Bundle bundle) {
    if (null != bundle) {
        //Log.e("Saving","Found a bundle!!!!");

        if (bundle.containsKey("eventStateAcknowledged") && bundle.getBoolean("eventStateAcknowledged")) {
            ackIcon.setImageResource(R.drawable.ic_acknowledged);
            isAcknowledged = true;/*from  w w w .  j a  v  a 2 s.c  o  m*/
        }

        if (bundle.containsKey("Title"))
            Title.setText(bundle.getString("Title"));

        if (bundle.containsKey("Component"))
            Component.setText(bundle.getString("Component"));

        if (bundle.containsKey("EventClass"))
            EventClass.setText(bundle.getString("EventClass"));

        if (bundle.containsKey("Summary"))
            Summary.setText(Html.fromHtml(bundle.getString("Summary"), null, null));

        if (bundle.containsKey("FirstTime"))
            FirstTime.setText(bundle.getString("FirstTime"));

        if (bundle.containsKey("LastTime"))
            LastTime.setText(bundle.getString("LastTime"));

        if (bundle.containsKey("EventCount"))
            EventCount.setText(bundle.getString("EventCount"));

        if (bundle.containsKey("agent"))
            agent.setText(bundle.getString("agent"));

        if (bundle.containsKey("LogEntries")) {
            try {
                String[] LogEntries = bundle.getStringArray("LogEntries");
                int LogEntryCount = LogEntries.length;

                for (int i = 0; i < LogEntryCount; i++) {
                    TextView newLog = new TextView(getActivity());
                    newLog.setText(Html.fromHtml(LogEntries[i]));
                    newLog.setPadding(0, 6, 0, 6);
                    logList.addView(newLog);
                }
            } catch (Exception e) {
                e.printStackTrace();
                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "oncreate bundle", e);
            }
        }

        if (bundle.containsKey("img")) {
            try {
                img.setImageBitmap((Bitmap) bundle.getParcelable("img"));
                img.invalidate();
            } catch (Exception e) {
                e.printStackTrace();
                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "oncreate bundle image", e);
            }
        }

        progressbar.setVisibility(View.INVISIBLE);
    } else {
        //Log.e("Saving","Didn't find any data so getting it");
        preLoadData();
    }

    super.onActivityCreated(bundle);
}

From source file:com.neusou.bioroid.restful.RestfulClient.java

/**
* Extracts a restful method contained in the <b>Bundle</b> data and executes it. 
* The operation returns immediately and does not block the calling thread.
* <br/><br/>// w  ww .j av a 2s.  co  m
* Usage: <b>Activity</b> should not call this directly, should be called by a <b>Service</b>. 
* 
* @param b
* @throws IllegalArgumentException
*/
public void execute(final Bundle b) throws IllegalArgumentException {

    Runnable r = new Runnable() {
        @Override
        public void run() {
            if (b == null) {
                //         Logger.l(Logger.WARN, LOG_TAG, "no execution data");
                return;
            }
            if (!b.containsKey(XTRA_METHOD)) {
                throw new IllegalArgumentException("Does not have method information to execute");
            }

            RestfulMethod method = (RestfulMethod) getParcelable(b, XTRA_METHOD);

            Logger.l(Logger.WARN, LOG_TAG, "executing restful method " + method.describeContents() + " "
                    + method.getClass().getCanonicalName());

            method.go(b);
        }
    };

    //Logger.l(Logger.DEBUG, LOG_TAG, "executing runnable.");
    mExecutor.execute(r);
}

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

/**
 * @return true if the cursor extras contains all of the signs of being paged.
 *     Technically we could also check SDK version since facilities for paging
 *     were added in SDK 26, but if it looks like a duck and talks like a duck
 *     itsa duck (especially if it helps with testing).
 *//*  ww w  .  ja va  2 s .  c  om*/
@WorkerThread
private boolean isProviderPaged(Cursor cursor) {
    Bundle extras = cursor.getExtras();
    extras = extras != null ? extras : Bundle.EMPTY;
    String[] honoredArgs = extras.getStringArray(EXTRA_HONORED_ARGS);

    return (extras.containsKey(EXTRA_TOTAL_COUNT) && honoredArgs != null
            && contains(honoredArgs, QUERY_ARG_OFFSET) && contains(honoredArgs, QUERY_ARG_LIMIT));
}

From source file:com.example.jumpnote.android.jsonrpc.AuthenticatedJsonRpcJavaClient.java

public void blockingAuthenticateAccount(final Account account, final int needAuthAction,
        boolean forceReauthenticate) throws AuthenticationException, OperationCanceledException,
        RequestedUserAuthenticationException, InvalidAuthTokenException {

    String existingToken = mTokenStoreHelper.getToken(account);
    if (!forceReauthenticate && existingToken != null) {
        BasicClientCookie c = new BasicClientCookie("ACSID", existingToken);
        try {//from w w  w.j  a  va  2  s .co  m
            c.setDomain(new URI(Config.SERVER_BASE_URL).getHost());
            mHttpClient.getCookieStore().addCookie(c);
            return;
        } catch (URISyntaxException e) {
        }
    }

    // Get an auth token for this account.
    AccountManager am = AccountManager.get(mContext);
    Bundle authBundle = null;
    String authToken = null;

    // Block on getting the auth token result.
    try {
        authBundle = am.getAuthToken(account, APPENGINE_SERVICE_NAME, needAuthAction == NEED_AUTH_NOTIFICATION,
                null, null).getResult();
    } catch (IOException e) {
        throw new AuthenticationException("IOException while getting auth token.", e);
    } catch (AuthenticatorException e) {
        throw new AuthenticationException("AuthenticatorException while getting auth token.", e);
    }

    if (authBundle.containsKey(AccountManager.KEY_INTENT) && needAuthAction == NEED_AUTH_INTENT) {
        Intent authRequestIntent = (Intent) authBundle.get(AccountManager.KEY_INTENT);
        mContext.startActivity(authRequestIntent);
        throw new RequestedUserAuthenticationException();
    } else if (authBundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
        authToken = authBundle.getString(AccountManager.KEY_AUTHTOKEN);
    }

    if (authToken == null) {
        throw new AuthenticationException("Retrieved auth token was null.");
    }

    try {
        blockingAuthenticateWithToken(account, authToken);
    } catch (InvalidAuthTokenException e) {
        am.invalidateAuthToken(account.type, authToken);
        throw e;
    }
}

From source file:com.samsung.android.remindme.jsonrpc.AuthenticatedJsonRpcJavaClient.java

public void blockingAuthenticateAccount(final Account account, final int needAuthAction,
        boolean forceReauthenticate) throws AuthenticationException, OperationCanceledException,
        RequestedUserAuthenticationException, InvalidAuthTokenException {

    String existingToken = mTokenStoreHelper.getToken(account);
    if (!forceReauthenticate && existingToken != null) {
        BasicClientCookie c = new BasicClientCookie("ACSID", existingToken);
        try {/*from   w ww. ja v  a 2s .  c  om*/
            c.setDomain(new URI(Config.SERVER_BASE_URL).getHost());
            mHttpClient.getCookieStore().addCookie(c);
            return;
        } catch (URISyntaxException e) {
        }
    }

    // Get an auth token for this account.
    AccountManager am = AccountManager.get(mContext);
    Bundle authBundle = null;
    String authToken = null;

    // Block on getting the auth token result.
    try {
        authBundle = am.getAuthToken(account, APPENGINE_SERVICE_NAME, needAuthAction == NEED_AUTH_NOTIFICATION,
                null, null).getResult();
    } catch (IOException e) {
        throw new AuthenticationException("IOException while getting auth token.", e);
    } catch (AuthenticatorException e) {
        throw new AuthenticationException("AuthenticatorException while getting auth token.", e);
    }

    if (authBundle.containsKey(AccountManager.KEY_INTENT) && needAuthAction == NEED_AUTH_INTENT) {
        Intent authRequestIntent = (Intent) authBundle.get(AccountManager.KEY_INTENT);
        mContext.startActivity(authRequestIntent);
        throw new RequestedUserAuthenticationException();
    } else if (authBundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
        authToken = authBundle.getString(AccountManager.KEY_AUTHTOKEN);
        System.out.println(authToken);
        System.out.println(AccountManager.KEY_AUTHTOKEN);
    }

    if (authToken == null) {
        throw new AuthenticationException("Retrieved auth token was null.");
    }

    try {
        blockingAuthenticateWithToken(account, authToken);
    } catch (InvalidAuthTokenException e) {
        am.invalidateAuthToken(account.type, authToken);
        throw e;
    }
}

From source file:com.facebook.android.FBUtil.java

/**
 * Connect to an HTTP URL and return the response as a string.
 *
 * Note that the HTTP method override is used on non-GET requests. (i.e.
 * requests are made as "POST" with method specified in the body).
 *
 * @param url - the resource to open: must be a welformed URL
 * @param method - the HTTP method to use ("GET", "POST", etc.)
 * @param params - the query parameter for the URL (e.g. access_token=foo)
 * @return the URL contents as a String//from w  w w .  j a v  a2  s .co m
 * @throws MalformedURLException - if the URL format is invalid
 * @throws IOException - if a network problem occurs
 */
public static String openUrl(String url, String method, Bundle params)
        throws MalformedURLException, IOException {
    // random string as boundary for multi-part http post
    String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f";
    String endLine = "\r\n";

    OutputStream os;

    // Try to get filename key
    String filename = params.getString("filename");

    // If found
    if (filename != null) {
        // Remove from params
        params.remove("filename");
    }

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Log.d("Facebook-FBUtil", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK");
    if (!method.equals("GET")) {
        Bundle dataparams = new Bundle();
        for (String key : params.keySet()) {
            if (params.getByteArray(key) != null) {
                dataparams.putByteArray(key, params.getByteArray(key));
            }
        }

        // use method override
        if (!params.containsKey("method")) {
            params.putString("method", method);
        }

        if (params.containsKey("access_token")) {
            String decoded_token = URLDecoder.decode(params.getString("access_token"));
            params.putString("access_token", decoded_token);
        }

        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary);
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setRequestProperty("Connection", "Keep-Alive");
        conn.connect();
        os = new BufferedOutputStream(conn.getOutputStream());

        os.write(("--" + strBoundary + endLine).getBytes());
        os.write((encodePostBody(params, strBoundary)).getBytes());
        os.write((endLine + "--" + strBoundary + endLine).getBytes());

        if (!dataparams.isEmpty()) {

            for (String key : dataparams.keySet()) {
                os.write(("Content-Disposition: form-data; filename=\"" + ((filename) != null ? filename : key)
                        + "\"" + endLine).getBytes());
                os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
                os.write(dataparams.getByteArray(key));
                os.write((endLine + "--" + strBoundary + endLine).getBytes());

            }
        }
        os.flush();
    }

    String response = "";
    try {
        response = read(conn.getInputStream());
    } catch (FileNotFoundException e) {
        // Error Stream contains JSON that we can parse to a FB error
        response = read(conn.getErrorStream());
    }
    return response;
}