List of usage examples for android.os Bundle getInt
public int getInt(String key, int defaultValue)
From source file:com.ubikod.urbantag.ContentViewerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); /* If we are coming from Notification delete notification */ if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_CONTENT_NOTIF) { NotificationHelper notificationHelper = new NotificationHelper(this); notificationHelper.closeContentNotif(); } else if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_PLACE_NOTIF) { NotificationHelper notificationHelper = new NotificationHelper(this); notificationHelper.closePlaceNotif(); }/*from ww w. j av a2 s . com*/ /* Fetch content info */ ContentManager contentManager = new ContentManager(new DatabaseHelper(this, null)); Log.i(UrbanTag.TAG, "View content : " + extras.getInt(CONTENT_ID)); this.content = contentManager.get(extras.getInt(CONTENT_ID)); if (this.content == null) { Toast.makeText(this, R.string.error_occured, Toast.LENGTH_SHORT).show(); finish(); return; } setTitle(content.getName()); com.actionbarsherlock.app.ActionBar actionBar = this.getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.content_viewer); /* Find webview and create url for content */ final WebView webView = (WebView) findViewById(R.id.webview); final String URL = UrbanTag.API_URL + ACTION_GET_CONTENT.replaceAll("%", "" + this.content.getId()); /* Display progress animation */ final ProgressDialog progress = ProgressDialog.show(this, "", this.getResources().getString(R.string.loading_content), false, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { timeOutHandler.interrupt(); webView.stopLoading(); ContentViewerActivity.this.finish(); } }); /* Go fetch content */ contentFetcher = new Thread(new Runnable() { DefaultHttpClient httpClient; @Override public void run() { Looper.prepare(); Log.i(UrbanTag.TAG, "Fetching content..."); httpClient = new DefaultHttpClient(); try { String responseBody = httpClient.execute(new HttpGet(URL), new BasicResponseHandler()); webView.loadDataWithBaseURL("fake://url/for/encoding/hack...", responseBody, mimeType, encoding, ""); timeOutHandler.interrupt(); if (progress.isShowing()) progress.dismiss(); } catch (ClientProtocolException cpe) { new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); timeOutHandler.interrupt(); progress.cancel(); } catch (IOException ioe) { new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); timeOutHandler.interrupt(); progress.cancel(); } Looper.loop(); } }); contentFetcher.start(); /* TimeOut Handler */ timeOutHandler = new Thread(new Runnable() { private int INCREMENT = 1000; @Override public void run() { Looper.prepare(); try { for (int time = 0; time < TIMEOUT; time += INCREMENT) { Thread.sleep(INCREMENT); } Log.w(UrbanTag.TAG, "TimeOut !"); new Handler().post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), R.string.error_loading_content, Toast.LENGTH_SHORT).show(); } }); contentFetcher.interrupt(); progress.cancel(); } catch (InterruptedException e) { e.printStackTrace(); } Looper.loop(); } }); timeOutHandler.start(); }
From source file:org.klnusbaum.udj.EventListFragment.java
private void restoreLastSearch(Bundle icicle) { int searchType = icicle.getInt(LAST_SEARCH_TYPE_EXTRA, -1); switch (searchType) { case LocationEventSearch.SEARCH_TYPE: lastSearch = new LocationEventSearch(lastKnown); break;// ww w .j a v a2 s. c o m case NameEventSearch.SEARCH_TYPE: lastSearch = new NameEventSearch(icicle.getString(EVENT_SEARCH_QUERY)); break; } }
From source file:org.klnusbaum.udj.EventListFragment.java
public Loader<EventsLoader.EventsLoaderResult> onCreateLoader(int id, Bundle args) { int eventSearchType = args.getInt(EVENT_SEARCH_TYPE_EXTRA, -1); if (eventSearchType == LocationEventSearch.SEARCH_TYPE) { return new EventsLoader(getActivity(), account, (Location) args.getParcelable(LOCATION_EXTRA)); } else if (eventSearchType == NameEventSearch.SEARCH_TYPE) { return new EventsLoader(getActivity(), account, args.getString(EVENT_SEARCH_QUERY)); } else {// w w w. j a v a 2 s .c o m return null; } }
From source file:android.support.mediacompat.service.ServiceBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (ACTION_CALL_MEDIA_BROWSER_SERVICE_METHOD.equals(intent.getAction()) && extras != null) { StubMediaBrowserServiceCompat service = StubMediaBrowserServiceCompat.sInstance; int method = extras.getInt(KEY_METHOD_ID, 0); switch (method) { case NOTIFY_CHILDREN_CHANGED: service.notifyChildrenChanged(extras.getString(KEY_ARGUMENT)); break; case SEND_DELAYED_NOTIFY_CHILDREN_CHANGED: service.sendDelayedNotifyChildrenChanged(); break; case SEND_DELAYED_ITEM_LOADED: service.sendDelayedItemLoaded(); break; case CUSTOM_ACTION_SEND_PROGRESS_UPDATE: service.mCustomActionResult.sendProgressUpdate(extras.getBundle(KEY_ARGUMENT)); break; case CUSTOM_ACTION_SEND_ERROR: service.mCustomActionResult.sendError(extras.getBundle(KEY_ARGUMENT)); break; case CUSTOM_ACTION_SEND_RESULT: service.mCustomActionResult.sendResult(extras.getBundle(KEY_ARGUMENT)); break; case SET_SESSION_TOKEN: StubMediaBrowserServiceCompatWithDelayedMediaSession.sInstance.callSetSessionToken(); break; }//w ww . j ava 2 s . c o m } else if (ACTION_CALL_MEDIA_SESSION_METHOD.equals(intent.getAction()) && extras != null) { MediaSessionCompat session = StubMediaBrowserServiceCompat.sSession; int method = extras.getInt(KEY_METHOD_ID, 0); switch (method) { case SET_EXTRAS: session.setExtras(extras.getBundle(KEY_ARGUMENT)); break; case SET_FLAGS: session.setFlags(extras.getInt(KEY_ARGUMENT)); break; case SET_METADATA: session.setMetadata((MediaMetadataCompat) extras.getParcelable(KEY_ARGUMENT)); break; case SET_PLAYBACK_STATE: session.setPlaybackState((PlaybackStateCompat) extras.getParcelable(KEY_ARGUMENT)); break; case SET_QUEUE: List<QueueItem> items = extras.getParcelableArrayList(KEY_ARGUMENT); session.setQueue(items); break; case SET_QUEUE_TITLE: session.setQueueTitle(extras.getCharSequence(KEY_ARGUMENT)); break; case SET_SESSION_ACTIVITY: session.setSessionActivity((PendingIntent) extras.getParcelable(KEY_ARGUMENT)); break; case SET_CAPTIONING_ENABLED: session.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT)); break; case SET_REPEAT_MODE: session.setRepeatMode(extras.getInt(KEY_ARGUMENT)); break; case SET_SHUFFLE_MODE: session.setShuffleMode(extras.getInt(KEY_ARGUMENT)); break; case SEND_SESSION_EVENT: Bundle arguments = extras.getBundle(KEY_ARGUMENT); session.sendSessionEvent(arguments.getString("event"), arguments.getBundle("extras")); break; case SET_ACTIVE: session.setActive(extras.getBoolean(KEY_ARGUMENT)); break; case RELEASE: session.release(); break; case SET_PLAYBACK_TO_LOCAL: session.setPlaybackToLocal(extras.getInt(KEY_ARGUMENT)); break; case SET_PLAYBACK_TO_REMOTE: ParcelableVolumeInfo volumeInfo = extras.getParcelable(KEY_ARGUMENT); session.setPlaybackToRemote(new VolumeProviderCompat(volumeInfo.controlType, volumeInfo.maxVolume, volumeInfo.currentVolume) { }); break; case SET_RATING_TYPE: session.setRatingType(RatingCompat.RATING_5_STARS); break; } } }
From source file:net.reichholf.dreamdroid.fragment.ScreenShotFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.screenshot, null); mImageView = (ImageView) view.findViewById(R.id.screenshoot); mImageView.setBackgroundColor(Color.BLACK); Bundle extras = getArguments();/* ww w . jav a 2s. c o m*/ if (extras == null) { extras = new Bundle(); } mType = extras.getInt(KEY_TYPE, TYPE_ALL); mFormat = extras.getInt(KEY_FORMAT, FORMAT_PNG); mSize = extras.getInt(KEY_SIZE, 720); mFilename = extras.getString(KEY_FILENAME); if (savedInstanceState != null) { mRawImage = savedInstanceState.getByteArray("rawImage"); } else if (mRawImage == null) { mRawImage = new byte[0]; } mAttacher = new PhotoViewAttacher(mImageView); return view; }
From source file:eu.thecoder4.gpl.pleftdroid.PleftDroidActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && data != null) { super.onActivityResult(requestCode, resultCode, data); Bundle extras = data.getExtras(); switch (requestCode) { case ACT_CREATE: int SC = extras.getInt(SC_CREATE, 500); switch (SC) { case HttpStatus.SC_OK: new AlertDialog.Builder(this).setTitle(R.string.dialog_title_apptcreated) .setMessage(R.string.dialog_msg_apptcreated) .setPositiveButton("OK", new OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { }//from w w w . ja v a2 s .c o m }).show(); //Toast.makeText(this, R.string.toast_apptcreated, Toast.LENGTH_SHORT).show(); break; case PleftBroker.SC_CLIREDIR: Toast.makeText(this, R.string.toast_createapptfailredir, Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(this, R.string.toast_createapptfail, Toast.LENGTH_LONG).show(); } break; } } }
From source file:eu.faircode.netguard.IAB.java
public PendingIntent getBuyIntent(String sku, boolean subscription) throws RemoteException { if (service == null) return null; Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, subscription ? "subs" : "inapp", "netguard"); Log.i(TAG, "getBuyIntent sku=" + sku + " subscription=" + subscription); Util.logBundle(bundle);/*from w w w . ja v a 2 s. com*/ int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); Log.i(TAG, "Response=" + getResult(response)); if (response != 0) throw new IllegalArgumentException(getResult(response)); if (!bundle.containsKey("BUY_INTENT")) throw new IllegalArgumentException("BUY_INTENT missing"); return bundle.getParcelable("BUY_INTENT"); }
From source file:com.shanet.relayremote.Background.java
protected ArrayList<BasicNameValuePair> doInBackground(Bundle... params) { // There should only be 1 bundle if (params.length != 1) { if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { DialogUtils.displayErrorDialog(context, R.string.malformedDataErrorTitle, R.string.malformedDataError); }//w ww.j av a2s . c om }); } return new ArrayList<BasicNameValuePair>(); } // Get the UI info from the bundle Bundle info = params[0]; op = info.getChar("op", Constants.OP_GET); char cmd = info.getChar("cmd", Constants.CMD_OFF); pin = info.getInt("pin", Constants.DEFAULT_PIN); String host = info.getString("server", ""); int port = info.getInt("port", Constants.DEFAULT_PORT); appWidgetId = info.getInt("appWidgetId", -1); // Create the server Server server; String reply; ArrayList<BasicNameValuePair> states = new ArrayList<BasicNameValuePair>(); try { server = new Server(host, port); } catch (SocketException e) { if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { dialog.dismiss(); DialogUtils.displayErrorDialog(context, R.string.serverCommErrorTitle, R.string.serverCommError); } }); } return createErrorStatesArray(host, pin, cmd); } try { // Connect to the server if not already connected if (!server.isConnected()) { server.connect(); // Ensure we're connected now if (!server.isConnected()) { if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { DialogUtils.displayErrorDialog(context, R.string.serverConnectErrorTitle, R.string.serverConnectError); } }); } throw new Exception(); } } // Format and send the data to the server if (op == Constants.OP_GET) { // GET operations are just the letter "g" server.send(Constants.OP_GET + "\n"); } else { // SET operations are of the form "s-[pin]-[state]" // Pin is the pin the relay is connected to // State is 0 for off, 1 for on, or t for toggle (not used in this app) server.send(Constants.OP_SET + "-" + pin + "-" + cmd + "\n"); } // Get the reply from the server reply = server.receive(); if (reply.equals("ERR")) { if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { DialogUtils.displayErrorDialog(context, R.string.serverErrorTitle, R.string.serverError); } }); } throw new Exception(); // Create the states array } else { // The first entry in the states list should be the server the states belong to states.add(new BasicNameValuePair("server", host)); // If a get operation, format the reply if (op == Constants.OP_GET) { for (int i = 0; i < reply.length(); i += 4) { states.add(new BasicNameValuePair(String.valueOf(reply.charAt(i)), String .valueOf((reply.charAt(i + 2) == '1') ? Constants.CMD_ON : Constants.CMD_OFF))); } // Else, it's a set command so just add the pin we just handled } else { states.add(new BasicNameValuePair(String.valueOf(pin), String.valueOf(cmd))); } } } catch (UnknownHostException uhe) { states = createErrorStatesArray(host, pin, cmd); if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { dialog.dismiss(); DialogUtils.displayErrorDialog(context, R.string.unknownHostErrorTitle, R.string.unknownHostError); } }); } } catch (final IOException ioe) { states = createErrorStatesArray(host, pin, cmd); if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { dialog.dismiss(); DialogUtils.displayErrorDialog(context, context.getString(R.string.serverCommErrorTitle), ioe.getMessage()); } }); } } catch (NullPointerException npe) { states = createErrorStatesArray(host, pin, cmd); if (!isWidget) { ((Activity) context).runOnUiThread(new Runnable() { public void run() { dialog.dismiss(); DialogUtils.displayErrorDialog(context, R.string.serverCommErrorTitle, R.string.serverCommError); } }); } } catch (Exception e) { states = createErrorStatesArray(host, pin, cmd); } finally { // Shut down the server try { if (server != null && !server.isConnected()) server.close(); } catch (IOException ioe) { } } return states; }