Example usage for android.os Bundle Bundle

List of usage examples for android.os Bundle Bundle

Introduction

In this page you can find the example usage for android.os Bundle Bundle.

Prototype

public Bundle() 

Source Link

Document

Constructs a new, empty Bundle.

Usage

From source file:fr.cph.chicago.core.fragment.NearbyFragment.java

@NonNull
public static NearbyFragment newInstance(final int sectionNumber) {
    final NearbyFragment fragment = new NearbyFragment();
    final Bundle args = new Bundle();
    args.putInt(ARG_SECTION_NUMBER, sectionNumber);
    fragment.setArguments(args);/*from  ww w. j a  v a 2s . c  om*/
    return fragment;
}

From source file:com.groupme.sdk.util.HttpUtilsTest.java

public void testSetHttpParamsGet() {
    MockHttpClient client = new MockHttpClient();
    client.setContext(getContext());//  w ww.java  2s  .c  om
    String response = null;

    try {
        Bundle params = new Bundle();
        params.putString("group", "mygroup");
        params.putString("format", "json");

        response = HttpUtils.openUrl(client, OK_REQUEST, HttpUtils.METHOD_GET, null, params, null);
    } catch (HttpResponseException e) {
        fail("Received a response exception: " + e.toString());
    }

    String query = client.getRequest().getURI().getQuery();
    Bundle requestParams = HttpUtils.decodeParams(query);

    if (requestParams != null && !requestParams.isEmpty()) {
        assertEquals("mygroup", requestParams.getString("group"));
        assertEquals("json", requestParams.getString("format"));
    } else {
        fail("Params are not set!");
    }

    if (response == null) {
        fail("Unexpected empty response");
    }
}

From source file:com.chess.genesis.activity.RegisterFrag.java

private void register_validate() {
    EditText txt = (EditText) act.findViewById(R.id.username);
    final String username = txt.getText().toString().trim();
    if (!valid_username(username))
        return;//from  ww w  . ja  v a  2 s .co m

    txt = (EditText) act.findViewById(R.id.password);
    final String password = txt.getText().toString();
    txt = (EditText) act.findViewById(R.id.password2);
    final String password2 = txt.getText().toString();
    if (!valid_password(password, password2))
        return;

    txt = (EditText) act.findViewById(R.id.email);
    final String email = txt.getText().toString().trim();
    if (!valid_email(email))
        return;

    final Bundle bundle = new Bundle();
    bundle.putString("username", username);
    bundle.putString("password", password);
    bundle.putString("email", email);

    new RegisterConfirm(act, handle, bundle).show();
}

From source file:com.aleiacampo.oristanobus.util.ViewUtil.java

public static void loadMostSearched(final AppCompatActivity appCompatActivity) {

    final ArrayList<Stop> stopsList = new ArrayList<>();
    final ArrayList<String> stopsNameList = new ArrayList<>();

    new AsyncTask<Void, Void, Void>() {

        @Override//from  ww  w.ja va2s  .  co  m
        protected void onPreExecute() {
            super.onPreExecute();
            if (!ConnectionsHandler.isNetworkPresent(appCompatActivity)) {
                this.cancel(true);
                stopsNameList.add("Connessione dati non presente");
                ListView listView_searched = (ListView) appCompatActivity
                        .findViewById(R.id.textView_mostSerched);
                ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
                        R.layout.text_view, stopsNameList);
                listView_searched.setAdapter(adapter);
            }
        }

        @Override
        protected Void doInBackground(Void... params) {

            Stop stop;
            String url = "http://www.aleiacampo.com/stops.php?clicked=10";
            WebServerHandler webServerHandler = new WebServerHandler();
            String jsonStr = webServerHandler.getJSONData(url);
            try {
                JSONObject jsonObject = new JSONObject(jsonStr);
                JSONArray stopsJSON = jsonObject.getJSONArray("bus_stops");
                for (int i = 0; i < stopsJSON.length(); i++) {
                    JSONObject bus_stop = stopsJSON.getJSONObject(i);
                    stop = new Stop(bus_stop.getInt("id_line"), bus_stop.getInt("id_stop"),
                            bus_stop.getString("name_line"), bus_stop.getString("name_stop"));
                    stopsList.add(stop);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            for (Stop stop : stopsList) {
                stopsNameList.add("Linea " + stop.idLine + " - " + stop.nameStop);
            }

            ListView listView_searched = (ListView) appCompatActivity.findViewById(R.id.textView_mostSerched);
            ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
                    R.layout.text_view, stopsNameList);
            listView_searched.setAdapter(adapter);
            listView_searched.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Bundle bundle = new Bundle();
                    bundle.putInt("id_stop", stopsList.get(position).idStop);
                    bundle.putInt("id_line", stopsList.get(position).idLine);
                    bundle.putString("name_line", stopsList.get(position).nameLine);
                    bundle.putString("name_stop", stopsList.get(position).nameStop);

                    FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
                    TimesFragment timesFragment = new TimesFragment();
                    timesFragment.setArguments(bundle);
                    appCompatActivity.onBackPressed();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.home_frag, timesFragment, "Times");
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();

                }
            });
        }
    }.execute();
}

From source file:com.example.igorklimov.popularmoviesdemo.sync.SyncAdapter.java

public static void syncImmediately(Context context) {
    Log.d(LOG_TAG, "syncImmediately: ");
    ConnectivityManager systemService = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = systemService.getActiveNetworkInfo();
    if (activeNetworkInfo == null) {
        new NoInternet().show(((MainActivity) context).getSupportFragmentManager(), "1");
    }//from   ww w  .j a  v  a2 s  .  c  o  m
    Bundle bundle = new Bundle();
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
    bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
    ContentResolver.requestSync(getSyncAccount(context), context.getString(R.string.content_authority), bundle);
}

From source file:com.googlecode.android_scripting.facade.CameraFacade.java

@Rpc(description = "Take a picture and save it to the specified path.", returns = "A map of Booleans autoFocus and takePicture where True "
        + "indicates success. cameraId also included.")
public Bundle cameraCapturePicture(@RpcParameter(name = "targetPath") final String targetPath,
        @RpcParameter(name = "useAutoFocus") @RpcDefault("true") Boolean useAutoFocus,
        @RpcParameter(name = "cameraId", description = "Id of camera to use. SDK 9") @RpcDefault("0") Integer cameraId)
        throws Exception {
    final BooleanResult autoFocusResult = new BooleanResult();
    final BooleanResult takePictureResult = new BooleanResult();
    Camera camera = openCamera(cameraId);
    if (camera == null) {
        String msg = String.format("can't initialize camera id %d, try to use another id", cameraId);
        Log.e(msg);/*from  w w w.  j  a v  a  2  s  . com*/

        Bundle result = new Bundle();
        result.putInt("cameraId", cameraId);
        result.putBoolean("autoFocus", false);
        result.putBoolean("takePicture", false);
        result.putString("reason", msg + ", see logcat for details");
        return result;
    }
    Parameters prm = camera.getParameters();
    camera.setParameters(prm);

    try {
        Method method = camera.getClass().getMethod("setDisplayOrientation", int.class);
        method.invoke(camera, 90);
    } catch (Exception e) {
        Log.e(e);
    }

    try {
        FutureActivityTask<SurfaceHolder> previewTask = setPreviewDisplay(camera);
        camera.startPreview();
        if (useAutoFocus) {
            autoFocus(autoFocusResult, camera);
        }
        takePicture(new File(targetPath), takePictureResult, camera);
        previewTask.finish();
    } catch (Exception e) {
        Log.e(e);
    } finally {
        camera.release();
    }

    Bundle result = new Bundle();
    result.putBoolean("autoFocus", autoFocusResult.mmResult);
    result.putBoolean("takePicture", takePictureResult.mmResult);
    result.putInt("cameraId", cameraId);
    return result;
}

From source file:com.qburst.android.linkedin.Util.java

/**
 * Connect to an HTTP URL and return the response as a string.
 * /*from ww w  .j  a v a2s  . c  om*/
 * 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;
}

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

/**
 * Connect to an HTTP URL and return the response as a string.
 * /*from w  ww .  ja va  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:org.klnusbaum.udj.auth.Authenticator.java

private Bundle bundleUpAuthToken(Account account, String authToken) {
    final Bundle result = new Bundle();
    result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
    result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
    result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
    return result;
}