List of usage examples for android.os Bundle containsKey
public boolean containsKey(String key)
From source file:com.example.android.popularmovies.app.MoviesFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Restore state if it exists if (savedInstanceState == null || !savedInstanceState.containsKey("movies")) { movieArray = new ArrayList<Movie>(); } else {//from w w w . ja v a2 s .c o m movieArray = savedInstanceState.getParcelableArrayList("movies"); } setHasOptionsMenu(true); }
From source file:org.mifos.androidclient.main.OverdueBorrowersListActivity.java
@Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.overdue_borrowers_list); if (bundle != null && bundle.containsKey(CustomersData.BUNDLE_KEY)) { mOverdueCustomers = Arrays .asList((OverdueCustomer[]) bundle.getSerializable(OverdueCustomer.BUNDLE_KEY)); }/*from w w w. j a v a2 s .com*/ mFilterBox = (EditText) findViewById(R.id.overdueBorrowersList_filter_box); mOverdueBorrowersList = (ExpandableListView) findViewById(R.id.overdueBorrowersList_list); mContent = (LinearLayout) findViewById(R.id.overdueBorrowersList_content); mMessage = (TextView) findViewById(R.id.overdueBorrowersList_noDataMessage); mCustomerService = new CustomerService(this); }
From source file:ca.ualberta.cmput301w14t08.geochan.fragments.FavouritesFragment.java
/** * Restore spinner state from savedInstanceState. * @param savedInstanceState The previously saved state of the fragment. * //from w w w . j av a2s . c o m */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Restore the previously serialized current dropdown position. if (savedInstanceState != null) { if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { actionBar.setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); } } getChildFragmentManager().addOnBackStackChangedListener(this); }
From source file:com.eyekabob.util.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/*w w w .j av a 2 s. co m*/ * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ // COFFBR01 MODIFIED 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); } Util.logd("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()) { Object value = params.get(key); if (value instanceof byte[]) { dataparams.putByteArray(key, (byte[]) value); } } // 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:net.idlesoft.android.apps.github.activities.Repository.java
@Override protected void onRestoreInstanceState(final Bundle savedInstanceState) { try {//from w w w . j ava2s . com if (savedInstanceState.containsKey("json")) { mJson = new JSONObject(savedInstanceState.getString("json")); } if (mJson != null) { loadRepoInfo(); } } catch (final JSONException e) { e.printStackTrace(); } super.onRestoreInstanceState(savedInstanceState); }
From source file:com.trk.aboutme.facebook.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 w w w. j a va2 s . c o m * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ @Deprecated 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); } Utility.logd("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()) { Object parameter = params.get(key); if (parameter instanceof byte[]) { dataparams.putByteArray(key, (byte[]) parameter); } } // 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.appdynamics.demo.gasp.service.RESTIntentService.java
@Override protected void onHandleIntent(Intent intent) { Uri action = intent.getData();// ww w .j av a2 s . co m Bundle extras = intent.getExtras(); if (extras == null || action == null || !extras.containsKey(EXTRA_RESULT_RECEIVER)) { Log.e(TAG, "You did not pass extras or data with the Intent."); return; } int verb = extras.getInt(EXTRA_HTTP_VERB, GET); Bundle params = extras.getParcelable(EXTRA_PARAMS); Bundle headers = extras.getParcelable(EXTRA_HEADERS); ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER); try { HttpRequestBase request = null; // Get query params from Bundle and build URL switch (verb) { case GET: { request = new HttpGet(); attachUriWithQuery(request, action, params); } break; case DELETE: { request = new HttpDelete(); attachUriWithQuery(request, action, params); } break; case POST: { request = new HttpPost(); request.setURI(new URI(action.toString())); HttpPost postRequest = (HttpPost) request; if (params != null) { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params)); postRequest.setEntity(formEntity); } } break; case PUT: { request = new HttpPut(); request.setURI(new URI(action.toString())); HttpPut putRequest = (HttpPut) request; if (params != null) { UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params)); putRequest.setEntity(formEntity); } } break; } // Get Headers from Bundle for (BasicNameValuePair header : paramsToList(headers)) { request.setHeader(header.getName(), header.getValue()); } if (request != null) { HttpClient client = new DefaultHttpClient(); Log.d(TAG, "Executing request: " + verbToString(verb) + ": " + action.toString()); HttpResponse response = client.execute(request); HttpEntity responseEntity = response.getEntity(); StatusLine responseStatus = response.getStatusLine(); int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0; if ((responseEntity != null) && (responseStatus.getStatusCode() == 200)) { Bundle resultData = new Bundle(); resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity)); receiver.send(statusCode, resultData); } else { receiver.send(statusCode, null); } } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect. " + verbToString(verb) + ": " + action.toString(), e); receiver.send(0, null); } catch (UnsupportedEncodingException e) { Log.e(TAG, "A UrlEncodedFormEntity was created with an unsupported encoding.", e); receiver.send(0, null); } catch (ClientProtocolException e) { Log.e(TAG, "There was a problem when sending the request.", e); receiver.send(0, null); } catch (IOException e) { Log.e(TAG, "There was a problem when sending the request.", e); receiver.send(0, null); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.onesignal.OneSignal.java
static boolean isValidAndNotDuplicated(Context context, Bundle bundle) { if (bundle.isEmpty()) return false; try {//from w w w. j a v a 2 s . c om if (bundle.containsKey("custom")) { JSONObject customJSON = new JSONObject(bundle.getString("custom")); if (customJSON.has("i")) return !OneSignal.isDuplicateNotification(customJSON.getString("i"), context); else Log(LOG_LEVEL.DEBUG, "Not a OneSignal formatted GCM message. No 'i' field in custom."); } else Log(LOG_LEVEL.DEBUG, "Not a OneSignal formatted GCM message. No 'custom' field in the bundle."); } catch (Throwable t) { Log(LOG_LEVEL.DEBUG, "Could not parse bundle for duplicate, probably not a OneSignal notification.", t); } return false; }
From source file:barcamp.com.facebook.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 w w w . jav 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("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.get(key) instanceof byte[]) { //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.mercandalli.android.apps.files.file.text.FileTextActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_file_text); final Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar); if (toolbar != null) { setSupportActionBar(toolbar);// w w w . ja va2 s . c o m final ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setDisplayHomeAsUpEnabled(true); } } mEditText = (EditText) findViewById(R.id.txt); mProgressBar = (ProgressBar) findViewById(R.id.circularProgressBar); // Visibility mEditText.setVisibility(View.GONE); mProgressBar.setVisibility(View.VISIBLE); final Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); overridePendingTransition(R.anim.right_in, R.anim.right_out); return; } if (extras.containsKey(EXTRA_MODEL_FILE_ARTICLE_CONTENT_1)) { mInitialText = extras.getString(EXTRA_MODEL_FILE_ARTICLE_CONTENT_1); mEditText.setText(mInitialText); mEditText.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.GONE); } else { mUrl = extras.getString(EXTRA_MODEL_FILE_URL); mIsOnline = extras.getBoolean(EXTRA_MODEL_FILE_ONLINE); if (savedInstanceState == null) { new TaskGet(this, this.mUrl, this).execute(); } else { mProgressBar.setVisibility(View.GONE); } } }