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:edu.rit.csh.androidwebnews.ComposeActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();
    hc.getNewsGroups(); // used for list of newsgroups to look through

    if (extras != null) {
        if (extras.containsKey("SUBJECT")) { // coming from a reply
            subject = extras.getString("SUBJECT");
            body = extras.getString("QUOTED_TEXT");
            parentId = extras.getInt("PARENT");
        }//from ww  w. j  a va 2 s  .co  m
        // for when a new post is done from a newsgroup
        newsgroup = extras.getString("NEWSGROUP");
    }

    setContentView(R.layout.activity_compose);
    dialog = new InvalidApiKeyDialog(this);

    ArrayList<String> groupNames = new ArrayList<String>();
    listAdapter = new ArrayAdapter<String>(this, R.layout.rowlayout, groupNames);
    spinner = (Spinner) findViewById(R.id.newsgroupSpinner);
    if (parentId <= 0) {// do not display the spinner if it is a reply to a post
        spinner.setAdapter(listAdapter);
        spinner.setSelection(listAdapter.getPosition(newsgroup));
    } else {
        spinner.setVisibility(View.GONE);
    }

    subLine = (EditText) findViewById(R.id.subject_line);
    subLine.setText(subject);

    bodyText = (EditText) findViewById(R.id.post_body);
    bodyText.setText(body);

    setTitle("Compose");
}

From source file:net.idlesoft.android.apps.github.activities.CreateIssue.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.create_issue);

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey("repo_owner")) {
            mRepositoryOwner = extras.getString("repo_owner");
        } else {/*from  w  ww .j ava 2  s.  c o m*/
            mRepositoryOwner = mUsername;
        }
        if (extras.containsKey("repo_name")) {
            mRepositoryName = extras.getString("repo_name");
        }
    } else {
        mRepositoryOwner = mUsername;
    }

    mCreateIssueTask = (CreateIssueTask) getLastNonConfigurationInstance();
    if (mCreateIssueTask == null) {
        mCreateIssueTask = new CreateIssueTask();
    }
    mCreateIssueTask.activity = this;

    if (mCreateIssueTask.getStatus() == AsyncTask.Status.RUNNING) {
        mProgressDialog = ProgressDialog.show(CreateIssue.this, "Please Wait...", "Creating issue...", true);
    }

    ((TextView) findViewById(R.id.tv_page_title)).setText("New Issue");

    ((Button) findViewById(R.id.btn_create_issue_submit)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            if (mCreateIssueTask.getStatus() == AsyncTask.Status.FINISHED) {
                mCreateIssueTask = new CreateIssueTask();
                mCreateIssueTask.activity = CreateIssue.this;
            }
            if (mCreateIssueTask.getStatus() == AsyncTask.Status.PENDING) {
                mCreateIssueTask.execute();
            }
        }
    });
}

From source file:edu.csh.coursebrowser.SectionInfoActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Restore the previously serialized current tab position.
    if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
        getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
    }//from  www .  j a  v a2  s.co m
}

From source file:fr.cph.stock.android.activity.MainActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    // Restore the previously serialized current dropdown position.
    if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
        getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
    }/*from   w  w w . j a  v a 2 s  .co  m*/
}

From source file:net.idlesoft.android.apps.github.activities.CommitsList.java

@Override
public void onRestoreInstanceState(final Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    try {/* w w  w  .j  a v  a  2 s . com*/
        if (savedInstanceState.containsKey("commitsJson")) {
            mCommitsJSON = new JSONArray(savedInstanceState.getString("commitsJson"));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        return;
    }
    if (mCommitsJSON != null) {
        mCommitListAdapter = new CommitListAdapter(this, mCommitsJSON);
    }
}

From source file:com.esminis.server.library.service.server.installpackage.InstallerPackage.java

private void stopServer(Context context, ServerControl serverControl) {
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override/*  w  w w. j av a  2  s. c  o m*/
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction() == null
                    || !intent.getAction().equals(MainActivity.getIntentActionServerStatus(context))) {
                return;
            }
            final Bundle extras = intent.getExtras();
            if (extras == null || extras.containsKey("errorLine") || extras.getBoolean("running")) {
                return;
            }
            try {
                barrier.await();
            } catch (InterruptedException | BrokenBarrierException ignored) {
            }
        }
    };
    context.registerReceiver(receiver, new IntentFilter(MainActivity.getIntentActionServerStatus(context)));
    preferences.set(context, Preferences.SERVER_STARTED, false);
    serverControl.requestStop(null);
    try {
        barrier.await();
    } catch (InterruptedException | BrokenBarrierException ignored) {
    }
    context.unregisterReceiver(receiver);
}

From source file:br.com.ufc.palestrasufc.twitter.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * //from   w w  w.ja  v  a 2  s . c  o m
 * 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
 * @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;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Log.d("Twitter-Util", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " TwitterAndroidSDK");
    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=\"" + 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.irccloud.android.fragment.ChannelOptionsFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (savedInstanceState != null && savedInstanceState.containsKey("cid") && cid == -1) {
        cid = savedInstanceState.getInt("cid");
        bid = savedInstanceState.getInt("bid");
    }/*from   w w w  .  j  a v a 2 s  .  c o m*/
    Context ctx = getActivity();
    if (ctx == null)
        return null;
    LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.dialog_channel_options, null);
    members = (SwitchCompat) v.findViewById(R.id.members);
    unread = (SwitchCompat) v.findViewById(R.id.unread);
    notifyAll = (SwitchCompat) v.findViewById(R.id.notifyAll);
    joinpart = (SwitchCompat) v.findViewById(R.id.joinpart);
    collapse = (SwitchCompat) v.findViewById(R.id.collapse);
    autosuggest = (SwitchCompat) v.findViewById(R.id.autosuggest);

    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.jiramot.foursquare.android.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 www  .j av  a 2  s  .c  om*/
 * @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;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Log.d("Foursquare-Util", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " FoursquareAndroidSDK");
    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=\"" + 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.qburst.android.linkedin.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * // w  w w.  j a  v a 2 s .  c  o m
 * 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
 * @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;

    if (method.equals("GET")) {
        url = url + "?" + encodeUrl(params);
    }
    Log.d("Twitter-Util", method + " URL: " + url);
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestProperty("User-Agent",
            System.getProperties().getProperty("http.agent") + " LinkedInAndroidSDK");
    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=\"" + 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;
}