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:android.support.car.ui.CarNavExtender.java

/**
 * Reconstruct a CarNavExtender from an existing notification. Can be used to retrieve values.
 *
 * @param notification The notification to retrieve the values from.
 */// w  w w  . jav a  2  s .co  m
public CarNavExtender(@NonNull Notification notification) {
    Bundle extras = NotificationCompat.getExtras(notification);
    if (extras == null) {
        return;
    }
    Bundle b = extras.getBundle(EXTRA_CAR_EXTENDER);
    if (b == null) {
        return;
    }

    mIsExtended = b.getBoolean(EXTRA_IS_EXTENDED);
    mContentId = (Long) b.getSerializable(EXTRA_CONTENT_ID);
    // The ternary guarantees that we return either TYPE_HERO or TYPE_NORMAL.
    mType = (b.getInt(EXTRA_TYPE, TYPE_NORMAL) == TYPE_HERO) ? TYPE_HERO : TYPE_NORMAL;
    mContentTitle = b.getCharSequence(Notification.EXTRA_TITLE);
    mContentText = b.getCharSequence(Notification.EXTRA_TEXT);
    mSubText = b.getCharSequence(EXTRA_SUB_TEXT);
    mLargeIcon = b.getParcelable(Notification.EXTRA_LARGE_ICON);
    mActionIcon = b.getInt(EXTRA_ACTION_ICON);
    mContentIntent = b.getParcelable(EXTRA_CONTENT_INTENT);
    mColor = b.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT);
    mNightColor = b.getInt(EXTRA_NIGHT_COLOR, Notification.COLOR_DEFAULT);
    mShowInStream = b.getBoolean(EXTRA_STREAM_VISIBILITY, true);
    mShowAsHeadsUp = b.getBoolean(EXTRA_HEADS_UP_VISIBILITY);
    mIgnoreInStream = b.getBoolean(EXTRA_IGNORE_IN_STREAM);
}

From source file:com.cloudbees.gasp.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    // When an intent is received by this Service, this method
    // is called on a new thread.

    Uri action = intent.getData();//from ww  w . j  a  va  2  s. co m
    Bundle extras = intent.getExtras();

    if (extras == null || action == null || !extras.containsKey(EXTRA_RESULT_RECEIVER)) {
        // Extras contain our ResultReceiver and data is our REST action.  
        // So, without these components we can't do anything useful.
        Log.e(TAG, "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);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    ResultReceiver receiver = extras.getParcelable(EXTRA_RESULT_RECEIVER);

    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) {
            HttpClient client = new DefaultHttpClient();

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Log.d(TAG, "Executing request: " + 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);

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

            // Our ResultReceiver allows us to communicate back the results to the caller. This
            // class has a method named send() that can send back a code and a Bundle
            // of data. ResultReceiver and IntentService abstract away all the IPC code
            // we would need to write to normally make this work.
            if (responseEntity != null) {
                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);
    }
}

From source file:com.nextgis.maplibui.service.LayerFillService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("LayerFillService", "Received start id " + startId + ": " + intent);
    if (intent != null) {
        String action = intent.getAction();

        if (!TextUtils.isEmpty(action)) {
            switch (action) {
            case ACTION_ADD_TASK:
                int layerGroupId = intent.getIntExtra(KEY_LAYER_GROUP_ID, Constants.NOT_FOUND);
                mLayerGroup = (LayerGroup) MapBase.getInstance().getLayerById(layerGroupId);

                Bundle extra = intent.getExtras();
                int layerType = extra.getInt(KEY_INPUT_TYPE, Constants.NOT_FOUND);

                switch (layerType) {
                case VECTOR_LAYER:
                    mQueue.add(new VectorLayerFillTask(extra));
                    break;
                case VECTOR_LAYER_WITH_FORM:
                    mQueue.add(new UnzipForm(extra));
                    break;
                case TMS_LAYER:
                    mQueue.add(new LocalTMSFillTask(extra));
                    break;
                case NGW_LAYER:
                    mQueue.add(new NGWVectorLayerFillTask(extra));
                    break;
                }/* ww  w.  ja v  a 2  s  . c o m*/

                if (!mIsRunning) {
                    startNextTask();
                }

                return START_STICKY;
            case ACTION_STOP:
                mQueue.clear();
                mIsCanceled = true;
                break;
            case ACTION_SHOW:
                mProgressIntent.putExtra(KEY_STATUS, STATUS_SHOW).putExtra(KEY_TITLE, mBuilder.mContentTitle);
                sendBroadcast(mProgressIntent);
                break;
            }
        }
    }
    return START_STICKY;
}

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

private void saveEnv(Bundle paramBundle) {
    File permDir = new File(this.mContext.getFilesDir().getAbsoluteFile() + "/permmgr/");
    Log.e("permmgr", "permDir:" + permDir.getAbsolutePath());
    permDir.mkdirs();/*from   w w  w  .j  a v  a  2  s.c  om*/
    File localFile = new File(this.mContext.getFilesDir().getAbsoluteFile() + "/permmgr/" + "env_file");
    if ((localFile != null) && (localFile.exists()))
        localFile.delete();
    paramBundle.getInt("root_type", 0);
    int j = paramBundle.getInt("env_num", 0);
    int k = paramBundle.getInt("arg_num", 0);
    String[] arrayOfString1 = new String[j];
    String[] arrayOfString2 = new String[k];
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("#!/system/bin/sh");
    localStringBuilder.append('\n');
    for (int i = 0; i < j; ++i) {
        arrayOfString1[i] = paramBundle.getString("env_" + i);
        localStringBuilder.append("export " + arrayOfString1[i]);
        localStringBuilder.append('\n');
    }
    for (int i = 0; i < k; ++i) {
        arrayOfString2[i] = paramBundle.getString("arg_" + i);
        localStringBuilder.append(arrayOfString2[i]);
        localStringBuilder.append(" ");
    }
    localStringBuilder.append("\n");
    localStringBuilder.append("rm " + localFile.getAbsolutePath());
    localStringBuilder.append("\n");
    writeFileData(localFile, localStringBuilder.toString());
    try {
        Runtime.getRuntime().exec("chmod 755 " + localFile.getPath()).waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.microsoft.office365.msgraphsnippetapp.SnippetDetailFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (null != getActivity() && getActivity() instanceof AppCompatActivity) {
        AppCompatActivity activity = (AppCompatActivity) getActivity();
        if (null != activity.getSupportActionBar()) {
            activity.getSupportActionBar().setTitle(mItem.getName());
        }/*from  w ww.  j  a  v a  2 s .  c  o m*/
    }
    if (null != savedInstanceState && savedInstanceState.containsKey(STATUS_COLOR)) {
        int statusColor = savedInstanceState.getInt(STATUS_COLOR, UNSET);
        if (UNSET != statusColor) {
            mStatusColor.setBackgroundColor(statusColor);
            mStatusColor.setTag(statusColor);
        }
    }
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void updateClock(Context context, AppWidgetManager appWidgetManager, int appWidgetId, float ratio) {
    RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);

    // Launch setinngs when clicking on the time in the widget only if not a lock screen widget
    Bundle newOptions = appWidgetManager.getAppWidgetOptions(appWidgetId);
    if (newOptions != null && newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
            -1) != AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) {
        Intent mIntent = new Intent(Intent.ACTION_MAIN);
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName component = new ComponentName("com.android.settings", "com.android.settings.Settings");
        mIntent.setComponent(component);
        widget.setOnClickPendingIntent(R.id.digital_appwidget,
                PendingIntent.getActivity(context, 0, mIntent, 0));
    }/*from  www  . jav a  2 s .co  m*/

    //cg sai.pan begin
    refreshWifiStatus(context, widget);
    refreshBtStatus(context, widget);
    refreshAirplaneStatus(context, widget,
            Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0);
    mLocationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    refreshGpsStatus(context, widget, mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER));
    //refreshDataStatus(context, widget, Settings.Global.getInt(context.getContentResolver(), Settings.Global.MOBILE_DATA, 0) != 0);
    requestLocation(context);
    //cg sai.pan end

    // SPRD for bug421127 add am/pm for widget
    WidgetUtils.setTimeFormat(widget, (int) context.getResources().getDimension(R.dimen.widget_label_font_size),
            R.id.the_clock);
    WidgetUtils.setClockSize(context, widget, ratio);

    // Set today's date format
    CharSequence dateFormat = DateFormat.getBestDateTimePattern(Locale.getDefault(),
            context.getString(R.string.abbrev_wday_month_day_no_year));
    widget.setCharSequence(R.id.date, "setFormat12Hour", dateFormat);
    widget.setCharSequence(R.id.date, "setFormat24Hour", dateFormat);

    appWidgetManager.updateAppWidget(appWidgetId, widget);
}

From source file:net.naonedbus.fragment.CustomListFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    if (container == null) // must put this in
        return null;

    if (DBG)//from  w w w .  j a  v  a  2 s  .  c om
        Log.d(LOG_TAG + "$" + getClass().getSimpleName(), "onCreateView " + mCurrentState);

    if (savedInstanceState != null) {
        mListViewStatePosition = savedInstanceState.getInt(STATE_POSITION, -1);
        mListViewStateTop = savedInstanceState.getInt(STATE_TOP, 0);
    } else {
        mListViewStatePosition = -1;
        mListViewStateTop = 0;
    }

    mFragmentView = (ViewGroup) inflater.inflate(R.layout.fragment_base, container, false);
    final View view = inflater.inflate(mLayoutId, container, false);
    bindView(view, savedInstanceState);

    mFragmentView.addView(view);

    setupListView(inflater, mFragmentView);

    return mFragmentView;
}

From source file:com.bellman.bible.android.view.activity.search.Search.java

/**
 * Called when the activity is first created.
 *//*from   w  w  w  .ja  v a 2  s .c  o m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, true);
    Log.i(TAG, "Displaying Search view");
    setContentView(R.layout.search);

    if (!searchControl.validateIndex(getDocumentToSearch())) {
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() {
            @Override
            public void okay() {
                finish();
            }
        });
    }

    mSearchTextInput = (EditText) findViewById(R.id.searchText);
    mSearchTextInput.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                onSearch(null);
                return true;
            }
            return false;
        }
    });

    // pre-load search string if passed in
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String searchText = extras.getString(SEARCH_TEXT_SAVE);
        if (StringUtils.isNotEmpty(searchText)) {
            mSearchTextInput.setText(searchText);
        }
    }

    RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup);
    wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            wordsRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1);
        if (wordsSelection != -1) {
            wordsRadioGroup.check(wordsSelection);
        }
    }

    RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup);
    sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            sectionRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1);
        if (sectionSelection != -1) {
            sectionRadioGroup.check(sectionSelection);
        }
    }

    // set text for current bible book on appropriate radio button
    RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook);

    // set current book to default and allow override if saved - implies returning via Back button
    currentBookName = searchControl.getCurrentBookName();
    if (extras != null) {
        String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE);
        if (currentBibleBookSaved != null) {
            currentBookName = currentBibleBookSaved;
        }
    }
    currentBookRadioButton.setText(currentBookName);

    Log.d(TAG, "Finished displaying Search view");
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@SuppressWarnings("deprecation")
public Notification createNotification(Bundle settings, JSONObject obj) {

    // notifications[i] = api.normalizeAPI({
    // 'string': {
    // mandatory: ['title', 'body'],
    // defaults: {'icon':'icon'}
    // },//from  ww  w  .j  a  v a 2  s.c om
    //
    // 'number': {
    // mandatory: ['id', 'timeMillisSince1970'],
    // // the number of ms after which we start prioritising more recent
    // things above you.
    // defaults: {'epsilon': 1000 * 60 * 24 * 365}
    // },
    //
    // 'boolean': {
    // defaults: {
    // 'vibrate': false,
    // 'sound': false
    // }
    // }

    int icon = settings.getInt("notification_icon", -1);
    if (icon == -1) {
        Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    Notification n = new Notification();
    n.icon = icon;
    n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    long alarmTime = obj.optLong("timeMillisSince1970");
    long displayTime = obj.optLong("displayTimestamp", alarmTime);
    n.when = displayTime;
    n.tickerText = obj.optString("body");
    n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null);

    if (obj.optBoolean("vibrate")) {
        n.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (obj.optBoolean("sound")) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    String uriString = settings.getString("content_uri_prefix");
    if (uriString == null) {
        Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    if (uriString.contains("%d")) {
        uriString = String.format(uriString, obj.optInt("id"));
    }
    Uri uri = Uri.parse(uriString);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(uri);
    n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT);
    return n;
}

From source file:au.com.wallaceit.reddinator.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    Bundle update = global.getItemUpdate();
    if (update != null) {
        listAdapter.updateUiVote(update.getInt("position", 0), update.getString("id"), update.getString("val"));
    }//from  w  w w.  ja  v a2s. co m
}