Example usage for android.os Bundle getInt

List of usage examples for android.os Bundle getInt

Introduction

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

Prototype

public int getInt(String key, int defaultValue) 

Source Link

Document

Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.

Usage

From source file:it.gulch.linuxday.android.activities.TrackScheduleEventActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    events = new ArrayList<>();
    setupServices();// ww  w  . j  av  a  2s.c  o m

    setContentView(R.layout.track_schedule_event);

    Bundle extras = getIntent().getExtras();
    track = (Track) extras.getSerializable(EXTRA_TRACK);

    progress = findViewById(R.id.progress);
    pager = (ViewPager) findViewById(R.id.pager);
    adapter = new TrackScheduleEventAdapter(getSupportFragmentManager());
    pageIndicator = (PageIndicator) findViewById(R.id.indicator);

    if (savedInstanceState == null) {
        initialPosition = extras.getInt(EXTRA_POSITION, -1);
        pager.setAdapter(adapter);
        pageIndicator.setViewPager(pager);
    }

    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);
    bar.setTitle(R.string.event_details);
    bar.setSubtitle(track.getTitle());

    // Enable Android Beam
    NfcUtils.setAppDataPushMessageCallbackIfAvailable(this, this);

    setCustomProgressVisibility(true);

    setupLoaderCallbacks();
}

From source file:com.qihoo.permmgr.PermManager.java

public void receiverAndWriteDataMobilesafe(Bundle paramBundle) {
    File localFile = new File(this.mContext.getFilesDir().getAbsoluteFile() + "/" + "env_file");
    if ((localFile != null) && (localFile.exists()))
        localFile.delete();// ww w.  j ava  2  s.co  m
    int j = paramBundle.getInt("root_type", 0);

    int k = paramBundle.getInt("env_num", 0);
    String[] arrayOfString1 = new String[k];

    int n = paramBundle.getInt("arg_num", 0);
    String[] arrayOfString2 = new String[n];

    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("source=").append(this.mSourceType).append('\n');
    localStringBuilder.append('\n');
    localStringBuilder.append("root_type").append('\n');
    localStringBuilder.append(j).append('\n').append('\n');

    localStringBuilder.append("env").append('\n');
    for (int i = 0; i < k; ++i) {
        arrayOfString1[i] = paramBundle.getString("env_" + i);
        localStringBuilder.append(arrayOfString1[i]).append('\n');
    }
    localStringBuilder.append('\n');

    localStringBuilder.append("arg").append('\n');
    for (int i = 0; i < n; ++i) {
        arrayOfString2[i] = paramBundle.getString("arg_" + i);
        localStringBuilder.append(arrayOfString2[i]).append('\n');
    }
    localStringBuilder.append('\n');
    writeFileData(localFile, localStringBuilder.toString());
}

From source file:com.nokia.example.pepperfarm.iap.Payment.java

/**
 * Fetches the prices asynchronously//w  w w .j ava2 s  . c o m
 */
public void fetchPrices() {

    if (!isBillingAvailable())
        return;

    for (Product p : Content.ITEMS) {
        if (p.getPrice() != "") {
            Log.i("fetchPrices", "Prices already available. Not fetching.");
            return;
        }
    }

    AsyncTask<Void, String, Void> pricesTask = new AsyncTask<Void, String, Void>() {

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

            ArrayList<String> productIdArray = new ArrayList<String>(Content.ITEM_MAP.keySet());
            Bundle productBundle = new Bundle();
            productBundle.putStringArrayList("ITEM_ID_LIST", productIdArray);

            try {
                Bundle priceInfo = npay.getProductDetails(API_VERSION, activity.getPackageName(),
                        ITEM_TYPE_INAPP, productBundle);

                if (priceInfo.getInt("RESPONSE_CODE", RESULT_ERR) == RESULT_OK) {
                    ArrayList<String> productDetailsList = priceInfo.getStringArrayList("DETAILS_LIST");

                    for (String productDetails : productDetailsList) {
                        parseProductDetails(productDetails);
                    }

                } else {
                    Log.e("fetchPrices", "PRICE - priceInfo was not ok: Result was: "
                            + priceInfo.getInt("RESPONSE_CODE", -100));
                }

            } catch (JSONException e) {
                Log.e("fetchPrices", "PRODUCT DETAILS PARSING EXCEPTION: " + e.getMessage(), e);
            } catch (RemoteException e) {
                Log.e("fetchPrices", "PRICE EXCEPTION: " + e.getMessage(), e);
            }
            return null;
        }

        private void parseProductDetails(String productDetails) throws JSONException {

            ProductDetails details = new ProductDetails(productDetails);

            Log.i("fetchPrices", productDetails);

            Product p = Content.ITEM_MAP.get(details.getProductId());

            if (p != null) {
                p.setPrice(details.getPriceFormatted());
                Log.i("fetchPrices", "PRICE RECEIVED - " + details.getPrice() + " " + details.getCurrency());
            } else {
                Log.i("fetchPrices",
                        "Unable to set price for product " + details.getProductId() + ". Product not found.");
            }
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            if (ProductListFragment.purchaseListAdapter != null) {
                ProductListFragment.purchaseListAdapter.notifyDataSetChanged();
            }
            if (MainScreenPepperListFragment.reference.adapter != null) {
                MainScreenPepperListFragment.reference.adapter.notifyDataSetChanged();
            }
        }

    };
    pricesTask.execute();
}

From source file:org.jboss.aerogear.android.sync.SyncService.java

@Override
public void onCreate() {
    try {// w ww. jav  a2  s  .  c o m
        super.onCreate();

        ComponentName myService = new ComponentName(this, this.getClass());
        Bundle data = getPackageManager().getServiceInfo(myService, PackageManager.GET_META_DATA).metaData;

        if (data.getString(SERVER_HOST) == null) {
            throw new IllegalStateException(SERVER_HOST + " may not be null");
        }

        if (data.getString(SERVER_PATH) == null) {
            throw new IllegalStateException(SERVER_PATH + " may not be null");
        }

        if (data.getInt(SERVER_PORT, -1) == -1) {
            throw new IllegalStateException(SERVER_PORT + " may not be null");
        }

        JsonPatchClientSynchronizer synchronizer = new JsonPatchClientSynchronizer();
        ClientInMemoryDataStore<JsonNode, JsonPatchEdit> dataStore = new ClientInMemoryDataStore<JsonNode, JsonPatchEdit>();
        ClientSyncEngine<JsonNode, JsonPatchEdit> clientSyncEngine = new ClientSyncEngine<JsonNode, JsonPatchEdit>(
                synchronizer, dataStore, new DefaultPatchObservable<JsonNode>());

        syncClient = NettySyncClient.<JsonNode, JsonPatchEdit>forHost(data.getString(SERVER_HOST))
                .port(data.getInt(SERVER_PORT)).path(data.getString(SERVER_PATH)).syncEngine(clientSyncEngine)
                .build();

        Log.i(SyncService.class.getName(), "onCreated");
    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.getMessage(), ex);
        throw new IllegalStateException(ex);
    }
}

From source file:com.ntsync.android.sync.client.NetworkUtilities.java

/**
 * //from   w  w  w. j av  a 2  s  .  c o  m
 * @param acm
 * @param account
 * 
 * 
 * @param Activity
 *            if null show a notification when Login is needed otherwise
 *            show the Login-Activity in the context of the provided
 *            Activity. *
 * @return SessionId
 * @throws OperationCanceledException
 * @throws ServerException
 * @throws NetworkErrorException
 */
@SuppressWarnings("deprecation")
public static String blockingGetAuthToken(AccountManager acm, Account account, Activity activity)
        throws OperationCanceledException, ServerException, NetworkErrorException {
    String authToken = null;
    try {
        Bundle result;
        if (activity == null) {
            // New is available from API 14 -> use deprecated API
            result = acm.getAuthToken(account, Constants.AUTHTOKEN_TYPE, true, null, null).getResult();
        } else {
            result = acm.getAuthToken(account, Constants.AUTHTOKEN_TYPE, null, activity, null, null)
                    .getResult();
        }
        if (result != null) {
            if (result.containsKey(AccountManager.KEY_AUTHTOKEN)) {
                authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
            }
            if (result.containsKey(AccountManager.KEY_ERROR_CODE)) {
                int errorCode = result.getInt(AccountManager.KEY_ERROR_CODE, -1);
                String msg = result.getString(AccountManager.KEY_ERROR_MESSAGE);
                if (errorCode == Constants.AUTH_ERRORCODE_SERVEREXCEPTION) {
                    throw new ServerException(msg);
                } else {
                    LogHelper.logE(TAG,
                            "Authentification failed with unknown errorCode:" + errorCode + " Message:" + msg,
                            null);
                }
            }
        }
    } catch (AuthenticatorException e) {
        LogHelper.logE(TAG, "Authentification failed.", e);
        // Should not happen -> report error
        ErrorHandler.reportException(e);
    } catch (IOException ex) {
        throw new NetworkErrorException(ex);
    }
    return authToken;
}

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 ww. j  a  v a 2s. c o  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.antew.redditinpictures.library.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();//from w  w  w . j  av  a  2s .c o  m
    Bundle extras = intent.getExtras();

    if (extras == null || action == null) {
        Ln.e("You did not pass extras or data with the Intent.");
        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    String cookie = extras.getString(EXTRA_COOKIE);
    String userAgent = extras.getString(EXTRA_USER_AGENT);

    // Items in this bundle are simply passed on in onRequestComplete
    Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH);

    HttpEntity responseEntity = null;
    Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED);
    result.putExtra(EXTRA_PASS_THROUGH, passThrough);
    Bundle resultData = new Bundle();

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        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()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case
            // below.
            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()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            DefaultHttpClient client = new DefaultHttpClient();

            // GZip requests
            // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error:
            // 03-12 21:02:09.248    9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
            //         java.lang.Throwable: Explicit termination method 'end' not called
            // at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            // at java.util.zip.Inflater.<init>(Inflater.java:82)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
            // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346)
            client.addRequestInterceptor(getGzipRequestInterceptor());
            client.addResponseInterceptor(getGzipResponseInterceptor());

            if (cookie != null) {
                request.addHeader("Cookie", cookie);
            }

            if (userAgent != null) {
                request.addHeader("User-Agent", Constants.Reddit.USER_AGENT);
            }

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Ln.d("Executing request: %s %s ", verbToString(verb), action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if (responseEntity != null) {
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode);
                resultData.putInt(EXTRA_STATUS_CODE, statusCode);
                result.putExtra(EXTRA_BUNDLE, resultData);

                onRequestComplete(result);
            } else {
                onRequestFailed(result, statusCode);
            }
        }
    } catch (URISyntaxException e) {
        Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString());
        onRequestFailed(result, 0);
    } catch (UnsupportedEncodingException e) {
        Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding.");
        onRequestFailed(result, 0);
    } catch (ClientProtocolException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } catch (IOException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } finally {
        if (responseEntity != null) {
            try {
                responseEntity.consumeContent();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:com.nokia.example.pepperfarm.iap.Payment.java

/**
 * Check the products that we have already purchased
 *//*ww  w.  ja v a 2s.  com*/
public void getPurchases(boolean ignoreLifeCycleCheck) {

    if (!isBillingAvailable())
        return;

    if (ignoreLifeCycleCheck == false) {
        if (purchases_asked) {
            Log.i("getPurchases", "Restorables already asked.");
            return;
        }
    }

    MainScreenPepperListFragment.getpeppers.setVisibility(View.INVISIBLE);
    MainScreenPepperListFragment.fetch_peppers_progressbar.setVisibility(View.VISIBLE);
    MainScreenPepperListFragment.fetching_peppers.setVisibility(View.VISIBLE);

    AsyncTask<Void, String, Void> restoreTask = new AsyncTask<Void, String, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            ArrayList<String> productIdArray = new ArrayList<String>(Content.ITEM_MAP.keySet());
            Bundle productBundle = new Bundle();
            productBundle.putStringArrayList("ITEM_ID_LIST", productIdArray);

            try {
                Bundle purchases = npay.getPurchases(API_VERSION, activity.getPackageName(), ITEM_TYPE_INAPP,
                        productBundle, null);
                Log.i("getPurchases",
                        "GET PURCHASES RESPONSE CODE: " + purchases.getInt("RESPONSE_CODE", RESULT_ERR));

                if (purchases.getInt("RESPONSE_CODE", RESULT_ERR) == RESULT_OK) {

                    ArrayList<String> purchaseDataList = purchases
                            .getStringArrayList("INAPP_PURCHASE_DATA_LIST");

                    for (String purchaseData : purchaseDataList) {
                        parsePurchaseData(purchaseData);
                    }
                    purchases_asked = true;
                } else {
                    Log.e("getPurchases", "GET PURCHASES - response was not ok: Result was: "
                            + purchases.getInt("RESPONSE_CODE", RESULT_ERR));
                }

            } catch (JSONException e) {
                Log.e("getPurchases", "PURCHASE DATA PARSING EXCEPTION: " + e.getMessage(), e);
            } catch (RemoteException e) {
                Log.e("getPurchases", "EXCEPTION: " + e.getMessage(), e);
            }
            return null;
        }

        private void parsePurchaseData(String purchaseData) throws JSONException {

            Purchase purchase = new Purchase(purchaseData);

            Product p = Content.ITEM_MAP.get(purchase.getProductId());

            if (p != null) {
                p.setPurchased(purchase);
                Log.i("getPurchases", "Restoring product " + purchase.getProductId() + " Purchase token: "
                        + purchase.getToken());
            } else {
                Log.i("getPurchases",
                        "Unable to restore product " + purchase.getProductId() + ". Product not found.");
            }

        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            MainScreenPepperListFragment.getpeppers.setVisibility(View.VISIBLE);
            MainScreenPepperListFragment.fetch_peppers_progressbar.setVisibility(View.GONE);
            MainScreenPepperListFragment.fetching_peppers.setVisibility(View.GONE);

            if (ProductListFragment.purchaseListAdapter != null) {
                ProductListFragment.purchaseListAdapter.notifyDataSetChanged();
            }
            if (MainScreenPepperListFragment.reference.adapter != null) {
                MainScreenPepperListFragment.reference.adapter.notifyDataSetChanged();
            }
        }

    };
    restoreTask.execute();
}

From source file:au.id.tedp.mapdroid.Picker.java

private MapLocation getInitialLocation(Bundle savedState) {
    double newLat, newLong;
    int newZoom;/*w  w w .j a v a 2 s  . com*/

    // Default location: Germany, from a high zoom level.
    // OpenStreetMap is big in Germany.
    newLat = 52.5;
    newLong = 13.4;
    newZoom = 2;

    SharedPreferences settings = getPreferences(MODE_PRIVATE);

    if (savedState != null) {
        newLat = savedState.getFloat(SAVED_LATITUDE_KEY, (float) newLat);
        newLong = savedState.getFloat(SAVED_LONGITUDE_KEY, (float) newLong);
        newZoom = savedState.getInt(SAVED_ZOOM_KEY, newZoom);
    } else if (settings != null) {
        newLat = settings.getFloat(SAVED_LATITUDE_KEY, (float) newLat);
        newLong = settings.getFloat(SAVED_LONGITUDE_KEY, (float) newLong);
        newZoom = settings.getInt(SAVED_ZOOM_KEY, newZoom);
    }

    MapLocation l = new MapLocation(new Location("default"), newZoom);
    l.setLatitude(newLat);
    l.setLongitude(newLong);
    return l;
}