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.maass.android.imgur_uploader.ImgurUpload.java

/**
 * //from   w  w w  .java 2s  .  c  o  m
 * @return a map that contains objects with the following keys:
 * 
 *         delete - the url used to delete the uploaded image (null if
 *         error).
 * 
 *         original - the url to the uploaded image (null if error) The map
 *         is null if error
 */
private Map<String, String> handleSendIntent(final Intent intent) {
    Log.i(this.getClass().getName(), "in handleResponse()");

    Log.d(this.getClass().getName(), intent.toString());
    final Bundle extras = intent.getExtras();
    try {
        //upload a new image
        if (Intent.ACTION_SEND.equals(intent.getAction()) && (extras != null)
                && extras.containsKey(Intent.EXTRA_STREAM)) {

            final Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
            if (uri != null) {
                Log.d(this.getClass().getName(), uri.toString());
                // store uri so we can create the thumbnail if we succeed
                imageLocation = uri;
                final String jsonOutput = readPictureDataAndUpload(uri);
                return parseJSONResponse(jsonOutput);
            }
            Log.e(this.getClass().getName(), "URI null");
        }
    } catch (final Exception e) {
        Log.e(this.getClass().getName(), "Completely unexpected error", e);
    }
    return null;
}

From source file:facebook.FacebookModule.java

@Kroll.method
public void request(String method, KrollDict params, KrollFunction callback) {
    if (facebook == null) {
        Log.w(TAG, "request called without Facebook being instantiated.  Have you set appid?");
        return;/*from w  ww  .  j  a v  a  2  s  . c  o m*/
    }

    String httpMethod = "GET";
    if (params != null) {
        for (Object v : params.values()) {
            if (v instanceof TiBlob || v instanceof TiBaseFile) {
                httpMethod = "POST";
                break;
            }
        }
    }

    Bundle bundle = Utils.mapToBundle(params);
    if (!bundle.containsKey("method")) {
        bundle.putString("method", method);
    }
    getFBRunner().request(null, bundle, httpMethod, new TiRequestListener(this, method, false, callback), null);
}

From source file:butter.droid.base.fragments.dialog.StringArraySelectorDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    if (getArguments() == null || !getArguments().containsKey(ARRAY) || !getArguments().containsKey(TITLE)
            || mOnClickListener == null) {
        return builder.create();
    }// w  ww .j  av a 2 s  . c  o m

    Bundle b = getArguments();
    Object array = b.get(ARRAY);
    String[] stringArray;
    if (array instanceof List) {
        stringArray = (String[]) ((List) array).toArray(new String[((List) array).size()]);
    } else if (array instanceof String[]) {
        stringArray = b.getStringArray(ARRAY);
    } else {
        return builder.create();
    }
    String title = b.getString(TITLE);

    if (b.containsKey(MODE) && b.getInt(MODE) == SINGLE_CHOICE) {
        int defaultPosition = -1;
        if (b.containsKey(POSITION)) {
            defaultPosition = b.getInt(POSITION);
        }
        builder.setSingleChoiceItems(stringArray, defaultPosition, mOnClickListener);
    } else {
        builder.setItems(stringArray, mOnClickListener);
    }

    builder.setTitle(title).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    return builder.create();
}

From source file:eu.faircode.adblocker.IAB.java

public PendingIntent getBuyIntent(String sku) throws RemoteException {
    if (service == null)
        return null;
    Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, "inapp", "adblocker");
    Log.i(TAG, "getBuyIntent");
    Util.logBundle(bundle);/*from www .jav a 2s  . c  o  m*/
    int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1));
    Log.i(TAG, "Response=" + getResult(response));
    if (response != 0)
        throw new IllegalArgumentException(getResult(response));
    if (!bundle.containsKey("BUY_INTENT"))
        throw new IllegalArgumentException("BUY_INTENT missing");
    return bundle.getParcelable("BUY_INTENT");
}

From source file:rpi.rpiface.VoteActivity.java

/**
 * Recupera el recuento de votos si la actividad se est recuperando de un
 * cambio de estado, o lo obtiene del servidor si la actividad se est
 * creando.//  w  w  w . j av  a2s.co  m
 * 
 * @param savedInstanceState
 *            Estado guardado de la actividad, o <b>null</b> si la actividad
 *            se est creando.
 * @param preferences
 *            Preferencias de la aplicacin.
 */
private void restoreState(Bundle savedInstanceState, SharedPreferences preferences) {
    if (savedInstanceState == null) {
        updateVoteCount(preferences);
        return;
    }
    if (savedInstanceState.containsKey(VOTE_STATE_PLUS) && savedInstanceState.containsKey(VOTE_STATE_MINUS)) {
        botonYes.setText(savedInstanceState.getInt(VOTE_STATE_PLUS, 0));
        botonNo.setText(savedInstanceState.getInt(VOTE_STATE_MINUS, 0));
    } else {
        updateVoteCount(preferences);
    }
}

From source file:com.coloreight.plugin.socialAuth.SocialAuth.java

public void getTwitterSystemAccount(final String networkUserName, final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {
        public void run() {

            PluginResult pluginResult;//from ww  w  .j a  va2 s  . c o m
            final JSONObject json = new JSONObject();
            final JSONObject account = new JSONObject();

            final Account[] twitterAccounts = accountManager
                    .getAccountsByType("com.twitter.android.auth.login");

            try {
                if (twitterAccounts.length > 0) {
                    json.put("granted", true);

                    for (int i = 0; i < twitterAccounts.length; i++) {
                        if (twitterAccounts[i].name.equals(networkUserName)) {
                            account.put("userName", twitterAccounts[i].name);

                            final Account twitterAccount = twitterAccounts[i];

                            accountManager.getAuthToken(twitterAccount, "com.twitter.android.oauth.token", null,
                                    false, new AccountManagerCallback<Bundle>() {
                                        @Override
                                        public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
                                            try {
                                                Bundle bundle = accountManagerFuture.getResult();

                                                if (bundle.containsKey(AccountManager.KEY_INTENT)) {
                                                    Intent intent = bundle
                                                            .getParcelable(AccountManager.KEY_INTENT);

                                                    //clear the new task flag just in case, since a result is expected
                                                    int flags = intent.getFlags();
                                                    flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                                                    intent.setFlags(flags);

                                                    requestedTwitterAccountName = networkUserName;

                                                    cordova.getActivity().startActivityForResult(intent,
                                                            TWITTER_OAUTH_REQUEST);
                                                } else {
                                                    account.put("oauth_token",
                                                            bundle.getString(AccountManager.KEY_AUTHTOKEN));

                                                    accountManager.getAuthToken(twitterAccount,
                                                            "com.twitter.android.oauth.token.secret", null,
                                                            false, new AccountManagerCallback<Bundle>() {
                                                                @Override
                                                                public void run(
                                                                        AccountManagerFuture<Bundle> accountManagerFuture) {
                                                                    try {
                                                                        Bundle bundle = accountManagerFuture
                                                                                .getResult();

                                                                        if (bundle.containsKey(
                                                                                AccountManager.KEY_INTENT)) {
                                                                            Intent intent = bundle
                                                                                    .getParcelable(
                                                                                            AccountManager.KEY_INTENT);

                                                                            //clear the new task flag just in case, since a result is expected
                                                                            int flags = intent.getFlags();
                                                                            flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                                                                            intent.setFlags(flags);

                                                                            requestedTwitterAccountName = networkUserName;

                                                                            cordova.getActivity()
                                                                                    .startActivityForResult(
                                                                                            intent,
                                                                                            TWITTER_OAUTH_REQUEST);
                                                                        } else {
                                                                            account.put("oauth_token_secret",
                                                                                    bundle.getString(
                                                                                            AccountManager.KEY_AUTHTOKEN));

                                                                            json.put("data", account);

                                                                            Log.v(TAG, "Account data: "
                                                                                    + json.toString());

                                                                            PluginResult pluginResult = new PluginResult(
                                                                                    PluginResult.Status.OK,
                                                                                    json);
                                                                            pluginResult.setKeepCallback(true);
                                                                            callbackContext.sendPluginResult(
                                                                                    pluginResult);
                                                                        }

                                                                    } catch (Exception e) {
                                                                        PluginResult pluginResult = new PluginResult(
                                                                                PluginResult.Status.ERROR,
                                                                                e.getLocalizedMessage());
                                                                        pluginResult.setKeepCallback(true);
                                                                        callbackContext
                                                                                .sendPluginResult(pluginResult);
                                                                    }
                                                                }
                                                            }, null);
                                                }

                                            } catch (Exception e) {
                                                PluginResult pluginResult = new PluginResult(
                                                        PluginResult.Status.ERROR, e.getLocalizedMessage());
                                                pluginResult.setKeepCallback(true);
                                                callbackContext.sendPluginResult(pluginResult);
                                            }
                                        }
                                    }, null);
                        }
                    }
                } else {
                    json.put("code", "0");
                    json.put("message", "no have twitter accounts");

                    pluginResult = new PluginResult(PluginResult.Status.ERROR, json);
                    pluginResult.setKeepCallback(true);
                    callbackContext.sendPluginResult(pluginResult);
                }
            } catch (JSONException e) {
                pluginResult = new PluginResult(PluginResult.Status.ERROR, e.getLocalizedMessage());
                pluginResult.setKeepCallback(true);
                callbackContext.sendPluginResult(pluginResult);
            }
        }
    });
}

From source file:za.co.neilson.alarm.preferences.AlarmPreferencesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_item_save:
        Database.init(getApplicationContext());
        Database.setEmail(email);//from  w w  w .j  a v  a2  s .c  o m

        if (getMathAlarm().getId() < 1) {
            getMathAlarm().setEmail(email);
            Database.create(getMathAlarm());
            Bundle bundle = getIntent().getExtras();
            if (bundle != null && bundle.containsKey("user")) {
                User user = (User) bundle.getSerializable("user");
                Group group = new Group(getMathAlarm(), user);
                Database.addGroup(group);
            }
            params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("email", email));
            Log.d("??? ? : ", "" + email);
            params.add(new BasicNameValuePair("time", getMathAlarm().getAlarmTimeString()));
            params.add(new BasicNameValuePair("difficulty",
                    Integer.toString(getMathAlarm().getDifficulty().ordinal())));
            params.add(new BasicNameValuePair("tone", getMathAlarm().getAlarmTonePath()));
            params.add(new BasicNameValuePair("vibrate", Boolean.toString(getMathAlarm().getVibrate())));
            params.add(new BasicNameValuePair("name", getMathAlarm().getAlarmName()));
            //params.add(new BasicNameValuePair("days", Arrays.toString(getMathAlarm().getDays())));
            for (int i = 0; i < getMathAlarm().getDays().length; i++) {
                params.add(new BasicNameValuePair("days", getMathAlarm().getDays()[i].toString()));
            }
            ServerRequest sr = new ServerRequest();
            JSONObject json = sr.getJSON("http://168.188.123.218:8080/alarmdata", params);
            if (json != null) {
                try {
                    String jsonstr = json.getString("response");
                    //JSONObject json2 = sr.getJSON("http://168.188.123.218:8080/useralarm", params);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        } else {
            Database.update(getMathAlarm());
            Database.setEmail(email);

        }

        callMathAlarmScheduleService();
        Toast.makeText(AlarmPreferencesActivity.this, getMathAlarm().getTimeUntilNextAlarmMessage(),
                Toast.LENGTH_LONG).show();
        finish();
        break;
    case R.id.menu_item_delete:
        AlertDialog.Builder dialog = new AlertDialog.Builder(AlarmPreferencesActivity.this);
        dialog.setTitle("Delete");
        dialog.setMessage("Delete this alarm?");
        dialog.setPositiveButton("Ok", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {

                Database.init(getApplicationContext());
                Database.setEmail(email);

                if (getMathAlarm().getId() < 1) {
                    // Alarm not saved
                } else {
                    params = new ArrayList<NameValuePair>();
                    params.add(new BasicNameValuePair("email", email));
                    params.add(new BasicNameValuePair("time", alarm.getAlarmTimeString()));
                    Log.d("??? ? : ", "" + email);
                    ServerRequest sr = new ServerRequest();
                    JSONObject json = sr.getJSON("http://168.188.123.218:8080/deletealarm", params);

                    Database.deleteEntry(alarm);
                    callMathAlarmScheduleService();
                }
                finish();
            }
        });
        dialog.setNegativeButton("Cancel", new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();

        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:ca.mudar.mtlaucasou.BaseMapFragment.java

/**
 * Create the map view and restore saved instance (if any). {@inheritDoc}
 *//*from ww  w. ja  va 2s  . com*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /**
     * Restore map center and zoom
     */
    int savedZoom = ZOOM_DEFAULT;
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(Const.KEY_INSTANCE_COORDS)) {
            int[] coords = savedInstanceState.getIntArray(Const.KEY_INSTANCE_COORDS);
            mMapCenter = new GeoPoint(coords[0], coords[1]);
        }
        if (savedInstanceState.containsKey(Const.KEY_INSTANCE_ZOOM)) {
            savedZoom = savedInstanceState.getInt(Const.KEY_INSTANCE_ZOOM);
        }
    }

    View root = inflater.inflate(R.layout.fragment_map, container, false);

    mMapView = (MapView) root.findViewById(R.id.map_view);

    mMapView.setBuiltInZoomControls(true);

    mMapController = mMapView.getController();
    mMapController.setZoom(savedZoom);

    mLocationManager = (LocationManager) getActivity().getApplicationContext()
            .getSystemService(MapActivity.LOCATION_SERVICE);

    initMap();

    return root;
}

From source file:com.hichinaschool.flashcards.anki.CramDeckOptions.java

@Override
protected void onCreate(Bundle icicle) {
    // Workaround for bug 4611: http://code.google.com/p/android/issues/detail?id=4611
    // This screen doesn't suffer from this bug really as it doesn't have nested
    // PreferenceScreens, but we have change the background for consistency with
    // DeckOptions background.
    if (AnkiDroidApp.SDK_VERSION >= 7 && AnkiDroidApp.SDK_VERSION <= 10) {
        Themes.applyTheme(this, Themes.THEME_ANDROID_DARK);
    }/*w w  w  . jav  a  2s.co  m*/
    super.onCreate(icicle);

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        finish();
        return;
    }
    mDeck = mCol.getDecks().current();

    Bundle initialConfig = getIntent().getBundleExtra("cramInitialConfig");
    if (initialConfig != null) {
        if (initialConfig.containsKey("searchSuffix")) {
            mPresetSearchSuffix = initialConfig.getString("searchSuffix");
        }
    }

    registerExternalStorageListener();

    try {
        if (mCol == null || mDeck.getInt("dyn") != 1) {
            Log.w(AnkiDroidApp.TAG, "CramDeckOptions - No Collection loaded or deck is not a dyn deck");
            finish();
            return;
        } else {
            mPref = new DeckPreferenceHack();
            mPref.registerOnSharedPreferenceChangeListener(this);

            this.addPreferencesFromResource(R.xml.cram_deck_options);
            this.buildLists();
            this.updateSummaries();
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
}