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.bpd.facebook.Util.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  ww.  ja v  a 2  s . c o 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-Util", 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;
}

From source file:com.glabs.homegenie.util.VoiceControl.java

@Override
public void onResults(Bundle results) {
    if ((results != null) && results.containsKey(SpeechRecognizer.RESULTS_RECOGNITION)) {
        List<String> heard = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
        float[] scores = results.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);
        String msg = "";
        for (String s : heard) {
            Toast.makeText(_hgcontext.getApplicationContext(), "Executing: " + s, 20000).show();
            interpretInput(s);//from   www. j  a v  a  2  s  . c o m
            //                msg += s;
            break;
        }
    }
}

From source file:com.ichi2.anki.FilteredDeckOptions.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  v  a  2 s  .  co m*/
        return;
    }
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("did")) {
        mDeck = mCol.getDecks().get(extras.getLong("did"));
    } else {
        mDeck = mCol.getDecks().current();
    }

    registerExternalStorageListener();

    try {
        if (mCol == null || mDeck.getInt("dyn") != 1) {
            Timber.w("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);
    }

    // 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:com.cyanogenmod.effem.FmRadio.java

@Override
public void onRdsDataAvailable(Bundle rdsData) {
    if (rdsData.containsKey("PSN")) {
        mStationNameTextView.setText(rdsData.getString("PSN").trim());
    }//from w  w w.jav a2  s . c om

    if (rdsData.containsKey("RT")) {
        String text = rdsData.getString("RT").trim();

        // only update if the text differs, otherwise this messes
        // up the marquee
        if (!mStationInfoTextView.getText().equals(text))
            mStationInfoTextView.setText(text);
    }

    if (rdsData.containsKey("PTY")) {
        int pty = rdsData.getShort("PTY");
        if (pty > 0)
            mProgramTypeTextView.setText(FmUtils.getPTYName(this, pty));
        else
            mProgramTypeTextView.setText("");
    }
}

From source file:edu.stanford.junction.sample.partyware.ImgurUploadService.java

/**
 * //from w w  w .j ava2 s  . 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());
                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:com.karmick.android.citizenalert.alarm.AlarmAddActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alarm_add);// w  ww.j av a  2 s.  com

    actionBar();

    initViews();

    Bundle bundle = getIntent().getExtras();
    if (bundle != null && bundle.containsKey("alarm")) {
        setMathAlarm((Alarm) bundle.getSerializable("alarm"));
    } else {
        setMathAlarm(new Alarm());
    }

    fillAlarmData();

    eventCalls();
}

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

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // If the user cleared search history and rotated the device before the snackbar
    // disappeared, let's show the snackbar again to let them undo.
    if (savedInstanceState.containsKey(EXTRA_CLEARED_HISTORY)) {
        String[] clearedHistory = savedInstanceState.getStringArray(EXTRA_CLEARED_HISTORY);
        mClearedHistory = clearedHistory;
        showClearHistorySnackbar(clearedHistory);
    }/*w  ww . j  a  v a  2  s  .  c o m*/
}

From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_sensor);

    Toolbar toolbar = getActionBarToolbar();
    getSupportActionBar().setTitle(getString(R.string.title_add_sensor));
    toolbar.setNavigationIcon(R.drawable.ic_up);

    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override//from w  ww.j  a  v a2  s . co  m
        public void onClick(View view) {
            Intent intent = getParentActivityIntent();
            startActivity(intent);
            finish();
        }
    });

    spinnerSensorType = (Spinner) findViewById(R.id.spinnerSensorType);
    editTextSensorName = (EditText) findViewById(R.id.editTextSensorName);
    layoutSensorSpecificSettings = (LinearLayout) findViewById(R.id.layoutSensorSpecificSettings);

    buttonCreateSensor = (Button) findViewById(R.id.buttonCreateSensor);

    if (getIntent().getExtras() != null) {
        Bundle b = getIntent().getExtras();
        if (b.containsKey("edit")) {
            try {
                editSensor = SingleInstance.getDatabaseHelper().getSensorDao().queryForId(b.getString("edit"));
                edit = true;
                editTextSensorName.setText(editSensor.getName());
                sensorTypes = new String[1];
                sensorTypes[0] = editSensor.getType();
                layoutSensorSpecificSettings.removeAllViews();
                selectedSensorType = sensorTypes[0].toLowerCase();
                sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType);
                sensorView.setEditMode(true);
                layoutSensorSpecificSettings.addView(sensorView);
                buttonCreateSensor.setText(R.string.button_edit_sensor);
            } catch (SQLException e) {
                finish();
            }
        }
    }

    spinnerSensorType.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, sensorTypes));

    if (!edit) {
        spinnerSensorType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                layoutSensorSpecificSettings.removeAllViews();
                selectedSensorType = sensorTypes[position].toLowerCase();
                sensorView = SensorViewFactory.makeView(AddSensorActivity.this, selectedSensorType);
                layoutSensorSpecificSettings.addView(sensorView);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        buttonCreateSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!MiscFunctions.isOnline(AddSensorActivity.this)) {
                    MiscFunctions.makeOfflineDialog(AddSensorActivity.this).show();
                    return;
                }
                if (editTextSensorName.getText().toString().equals("") || !sensorView.areSettingsValid()) {
                    new AlertDialog.Builder(AddSensorActivity.this).setTitle(R.string.dialog_title_error)
                            .setMessage("You must fill all the fields in order to add a sensor !")
                            .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).show();
                    return;
                }

                new AsyncTask<Void, Boolean, Void>() {
                    private ProgressDialog waitingDialog;

                    @Override
                    protected void onPreExecute() {
                        waitingDialog = new ProgressDialog(AddSensorActivity.this);
                        waitingDialog.setTitle(R.string.dialog_title_loading);
                        waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        waitingDialog.setMessage(
                                getResources().getString(R.string.dialog_message_loading_creating_sensor));
                        waitingDialog.show();
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        publishProgress(create());
                        return null;
                    }

                    @Override
                    protected void onProgressUpdate(Boolean... values) {
                        for (boolean b : values) {
                            if (b) {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_information)
                                        .setMessage(R.string.dialog_message_information_sensor_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        setResult(RESULT_OK);
                                                        Intent intent = new Intent(AddSensorActivity.this,
                                                                ChartActivity.class);
                                                        intent.putExtra(Config.EXTRA_FIRST_LAUNCH, true);
                                                        startActivity(intent);
                                                    }
                                                })
                                        .show();
                            } else {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_error)
                                        .setMessage(R.string.dialog_message_error_sensor_not_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                })
                                        .show();
                            }
                        }
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        waitingDialog.dismiss();
                    }
                }.execute();
            }
        });
    } else {
        buttonCreateSensor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new AsyncTask<Void, Boolean, Void>() {
                    private ProgressDialog waitingDialog;

                    @Override
                    protected void onPreExecute() {
                        waitingDialog = new ProgressDialog(AddSensorActivity.this);
                        waitingDialog.setTitle(R.string.dialog_title_loading);
                        waitingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                        waitingDialog.setMessage(
                                getResources().getString(R.string.dialog_message_loading_editing_sensor));
                        waitingDialog.show();
                    }

                    @Override
                    protected Void doInBackground(Void... params) {
                        publishProgress(edit());
                        return null;
                    }

                    @Override
                    protected void onProgressUpdate(Boolean... values) {
                        for (boolean b : values) {
                            if (b) {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_information)
                                        .setMessage(R.string.dialog_message_information_sensor_edited)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                        setResult(Activity.RESULT_OK);
                                                        finish();
                                                    }
                                                })
                                        .show();
                            } else {
                                new AlertDialog.Builder(AddSensorActivity.this)
                                        .setTitle(R.string.dialog_title_error)
                                        .setMessage(R.string.dialog_message_error_sensor_not_added)
                                        .setPositiveButton(R.string.button_ok,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        dialog.dismiss();
                                                    }
                                                })
                                        .show();
                            }
                        }
                    }

                    @Override
                    protected void onPostExecute(Void aVoid) {
                        waitingDialog.dismiss();
                    }
                }.execute();
            }
        });

    }
}

From source file:de.unclenet.dehabewe.CalendarActivity.java

private void gotAccount(final AccountManager manager, final Account account) {
    SharedPreferences settings = getSharedPreferences(PREF, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("accountName", account.name);
    editor.commit();//from   w  ww .j a  va 2  s.com
    new Thread() {

        @Override
        public void run() {
            try {
                final Bundle bundle = manager.getAuthToken(account, AUTH_TOKEN_TYPE, true, null, null)
                        .getResult();
                runOnUiThread(new Runnable() {

                    public void run() {
                        try {
                            if (bundle.containsKey(AccountManager.KEY_INTENT)) {
                                Intent intent = bundle.getParcelable(AccountManager.KEY_INTENT);
                                int flags = intent.getFlags();
                                flags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
                                intent.setFlags(flags);
                                startActivityForResult(intent, REQUEST_AUTHENTICATE);
                            } else if (bundle.containsKey(AccountManager.KEY_AUTHTOKEN)) {
                                authenticatedClientLogin(bundle.getString(AccountManager.KEY_AUTHTOKEN));
                            }
                        } catch (Exception e) {
                            handleException(e);
                        }
                    }
                });
            } catch (Exception e) {
                handleException(e);
            }
        }
    }.start();
}

From source file:app.philm.in.fragments.MovieImagesFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mAdapter = new ImageAdapter();

    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mViewPager.setPageTransformer(true, new CardTransformer(0.8f));
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setAdapter(mAdapter);/* w w  w  .j  a  v a 2 s .c o  m*/

    if (savedInstanceState != null && savedInstanceState.containsKey(BUNDLE_CURRENT_ITEM)) {
        mVisibleItem = savedInstanceState.getInt(BUNDLE_CURRENT_ITEM);
    }
}