List of usage examples for android.content Intent getBooleanExtra
public boolean getBooleanExtra(String name, boolean defaultValue)
From source file:com.android.gallery3d.filtershow.FilterShowActivity.java
private void processIntent() { Intent intent = getIntent(); if (intent.getBooleanExtra(LAUNCH_FULLSCREEN, false)) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); }// w ww .j a va 2 s. c o m mAction = intent.getAction(); mSelectedImageUri = intent.getData(); Uri loadUri = mSelectedImageUri; if (mOriginalImageUri != null) { loadUri = mOriginalImageUri; } if (loadUri != null) { startLoadBitmap(loadUri); } else { pickImage(); } }
From source file:eu.intermodalics.tango_ros_streamer.activities.RunningActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_CANCELED) { // Result code returned when back button is pressed. // Upload new settings to parameter server. if ((requestCode == StartSettingsActivityRequest.STANDARD_RUN || requestCode == StartSettingsActivityRequest.FIRST_RUN) && mParameterNode != null) { try { mParameterNode.uploadPreferencesToParameterServer(); } catch (RuntimeException e) { e.printStackTrace();/*w ww . j a v a 2 s .com*/ } } if (data != null && data.getBooleanExtra(RESTART_TANGO, false)) { restartTango(); } if (requestCode == StartSettingsActivityRequest.FIRST_RUN) { mRunLocalMaster = mSharedPref.getBoolean(getString(R.string.pref_master_is_local_key), false); mMasterUri = mSharedPref.getString(getString(R.string.pref_master_uri_key), getResources().getString(R.string.pref_master_uri_default)); mUriTextView.setText(mMasterUri); String logFileName = mSharedPref.getString(getString(R.string.pref_log_file_key), getString(R.string.pref_log_file_default)); mLogger.setLogFileName(logFileName); mLogger.start(); getTangoPermission(EXTRA_VALUE_ADF, REQUEST_CODE_ADF_PERMISSION); getTangoPermission(EXTRA_VALUE_DATASET, REQUEST_CODE_DATASET_PERMISSION); updateLoadAndSaveMapButtons(); } else if (requestCode == StartSettingsActivityRequest.STANDARD_RUN) { // It is ok to change the log file name at runtime. String logFileName = mSharedPref.getString(getString(R.string.pref_log_file_key), getString(R.string.pref_log_file_default)); mLogger.setLogFileName(logFileName); if (mRosStatus == RosStatus.MASTER_NOT_CONNECTED && mSnackbarRosReconnection != null) { // Show snackbar with ROS reconnection button. // It was dismissed when switching to the SettingsActivity. mSnackbarRosReconnection.show(); } } } if (requestCode == REQUEST_CODE_ADF_PERMISSION || requestCode == REQUEST_CODE_DATASET_PERMISSION) { if (resultCode == RESULT_CANCELED) { // No Tango permissions granted by the user. displayToastMessage(R.string.tango_permission_denied); } if (requestCode == REQUEST_CODE_ADF_PERMISSION) { // The user answered the ADF permission popup (the permission has not been necessarily granted). mAdfPermissionHasBeenAnswered = true; } if (requestCode == REQUEST_CODE_DATASET_PERMISSION) { // The user answered the dataset permission popup (the permission has not been necessarily granted). mDatasetPermissionHasBeenAnswered = true; } if (mAdfPermissionHasBeenAnswered && mDatasetPermissionHasBeenAnswered) { // Both ADF and dataset permissions popup have been answered by the user, the node // can start. Log.i(TAG, "initAndStartRosJavaNode"); initAndStartRosJavaNode(); } } }
From source file:gov.wa.wsdot.android.wsdot.service.HighwayAlertsSyncService.java
@SuppressLint("SimpleDateFormat") @Override//from w w w . j av a 2s.co m protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null; long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, projection, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "highway_alerts" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Tapping the refresh button will force a data refresh. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { try { URL url = new URL(HIGHWAY_ALERTS_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) { jsonFile += line; } in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("alerts"); JSONArray items = result.getJSONArray("items"); List<ContentValues> alerts = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); JSONObject startRoadwayLocation = item.getJSONObject("StartRoadwayLocation"); ContentValues alertData = new ContentValues(); alertData.put(HighwayAlerts.HIGHWAY_ALERT_ID, item.getString("AlertID")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_HEADLINE, item.getString("HeadlineDescription")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_CATEGORY, item.getString("EventCategory")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_PRIORITY, item.getString("Priority")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LATITUDE, startRoadwayLocation.getString("Latitude")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LONGITUDE, startRoadwayLocation.getString("Longitude")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_ROAD_NAME, startRoadwayLocation.getString("RoadName")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LAST_UPDATED, dateFormat .format(new Date(Long.parseLong(item.getString("LastUpdatedTime").substring(6, 19))))); alerts.add(alertData); } // Purge existing highway alerts covered by incoming data resolver.delete(HighwayAlerts.CONTENT_URI, null, null); // Bulk insert all the new highway alerts resolver.bulkInsert(HighwayAlerts.CONTENT_URI, alerts.toArray(new ContentValues[alerts.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "highway_alerts" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.HIGHWAY_ALERTS_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.example.mydemos.view.RingtonePickerActivity.java
/** Called when the activity is first created. */ @Override/*w w w . j a v a2s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.ringtone_picker); CharSequence sysTitle = (CharSequence) getResources().getText(R.string.sys_tone); CharSequence MusicTitle = (CharSequence) getResources().getText(R.string.sd_music); CharSequence RecordTitle = (CharSequence) getResources().getText(R.string.record_tone); Intent intent = getIntent(); toneType = intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1); Log.e("duwenhua", "ringPick get toneType:" + toneType); //! by duwenhua //if(toneType == RingtoneManager.TYPE_RINGTONE_SECOND) // toneType = RINGTONE_TYPE; //! by duwenhua mHasDefaultItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); mUriForDefaultItem = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //Log.i("lys", "mUriForDefaultItem == " + mUriForDefaultItem); if (savedInstanceState != null) { mSelectedId = savedInstanceState.getLong(SAVE_CLICKED_POS, -1); } //Log.i("lys", "mUriForDefaultItem 1== " + mUriForDefaultItem+", mSelectedId =="+mSelectedId); mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); mExistingUri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI); //if(mUriForDefaultItem != null) //{ // mSelectedId = ContentUris.parseId(mUriForDefaultItem); //} //Log.i("lys", "RingtonePickerActivity.java onCreate mExistingUri == " + mExistingUri); //String action = getIntent().getAction(); //Log.i("lys", "PT Intent action == " + action); if (toneType == NOTIFICATION_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_NOTIFICATION_URI; } else if (toneType == RINGTONE_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_RINGTONE_URI; } else if (toneType == ALARM_TYPE) { mUriForDefaultItem = Settings.System.DEFAULT_ALARM_ALERT_URI; } if (isAvailableToCheckRingtone() == true) { Ringtone ringtone_DefaultItem = checkRingtone_reflect(this, mUriForDefaultItem, toneType); if (ringtone_DefaultItem != null && ringtone_DefaultItem.getUri() != null) { mUriForDefaultItem = ringtone_DefaultItem.getUri(); Log.i("lys", "RingtoneManager.getRingtone mUriForDefaultItem== " + mUriForDefaultItem); } else { //mUriForDefaultItem = 'content/medial/'; /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard start */ String originalRingtone = Settings.System.getString(getApplicationContext().getContentResolver(), "ringtone_original"); if (originalRingtone != null && !TextUtils.isEmpty(originalRingtone)) { mUriForDefaultItem = Uri.parse(originalRingtone); Log.e("liyang", "select riongtone error ,change to originalRingtone == " + mExistingUri); } /*ZTE_AUDIO_LIYANG 2014/06/30 fix bug for ringtone when remove sdcard end */ Log.i("lys", "mUriForDefaultItem set as default mUriForDefaultItem== 222"); } if (mExistingUri != null) { Ringtone ringtone = checkRingtone_reflect(this, mExistingUri, toneType); if (ringtone != null && ringtone.getUri() != null) { //mUriForDefaultItem = ringtone.getUri(); mExistingUri = ringtone.getUri(); Log.i("lys", "RingtoneManager.getRingtone mExistingUri== " + mExistingUri); } else { mExistingUri = mUriForDefaultItem; Log.i("lys", "mExistingUri set as default mExistingUri== " + mExistingUri); } } } boolean includeDrm = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, false); Log.e("lys", "includeDrm ==" + includeDrm); mRingtoneManager = new RingtoneManager(this); mRingtoneManager.setIncludeDrm(includeDrm); if (toneType != -1) { mRingtoneManager.setType(toneType); } setVolumeControlStream(mRingtoneManager.inferStreamType()); // toneActivityType = mRingtoneManager.getActivityType(); if (toneType == ALARM_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.alarm_tone); } else if (toneType == NOTIFICATION_TYPE) { sysTitle = (CharSequence) getResources().getText(R.string.notification_tone); } listView = new ListView(this); listView.setOnItemClickListener(this); //listView.setBackgroundColor(#ff5a5a5a); listView.setFastScrollEnabled(true); //listView.setFastScrollAlwaysVisible(true); listView.setEmptyView(findViewById(android.R.id.empty)); //mHasSilentItem = intent.getBooleanExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); //mHasDefaultItem = true; //temp if (mHasDefaultItem) { //chengcheng addDefaultStaticItem(listView, com.android.internal.R.string.ringtone_default); } setDefaultRingtone(); if (mHasSilentItem) { // chengcheng addSilendStaticItem(listView, com.android.internal.R.string.ringtone_silent); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mAudioFocusListener = new OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { } }; okBtn = (Button) findViewById(R.id.ok); okBtn.setOnClickListener(this); cancelBtn = (Button) findViewById(R.id.cancel); cancelBtn.setOnClickListener(this); TabHost mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); mTabHost.addTab(mTabHost.newTabSpec("tab_system").setIndicator(sysTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_music").setIndicator(MusicTitle, null).setContent(this)); mTabHost.addTab(mTabHost.newTabSpec("tab_record").setIndicator(RecordTitle, null).setContent(this)); mTabHost.setCurrentTab(0); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { // stopMediaPlayer(); createTabContent(tabId); } }); }
From source file:com.nit.vicky.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);/* w ww.j a v a 2s . co m*/ Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "word", "sfld", "deck", "flags" }, new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); //mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class); //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview); mCardsGridView.setAdapter(mGridAdapter); mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() { @Override public void onItemClick(StaggeredGridView parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class); //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } String imgURL = getImgURL(sCardBrowserCard); Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show(); } }); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java
/** Called with the activity is first created. */ @Override/*from w w w . ja v a 2 s .co m*/ public void onCreate(Bundle icicle) { super.onCreate(icicle); mRecordingFilename = null; mRecordingUri = null; mPlayer = null; mIsPlaying = false; Intent intent = getIntent(); if (intent.getBooleanExtra("privacy", false)) { finish(); return; } // If the Ringdroid media select activity was launched via a // GET_CONTENT intent, then we shouldn't display a "saved" // message when the user saves, we should just return whatever // they create. mWasGetContentIntent = intent.getBooleanExtra("was_get_content_intent", false); mFilename = intent.getData().toString(); mSoundFile = null; mKeyDown = false; if (mFilename.equals("record")) { try { Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); startActivityForResult(recordIntent, REQUEST_CODE_RECORD); } catch (Exception e) { showFinalAlert(e, R.string.record_error); } } mHandler = new Handler(); loadGui(); mHandler.postDelayed(mTimerRunnable, 100); if (!mFilename.equals("record")) { loadFromFile(); } }
From source file:com.aegiswallet.services.PeerBlockchainService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { if (intent == null) return START_NOT_STICKY; final String action = intent.getAction(); if (PeerBlockchainService.ACTION_CANCEL_COINS_RECEIVED.equals(action)) { notificationCount = 0;/*from w ww . j av a2s . c om*/ notificationAccumulatedAmount = BigInteger.ZERO; notificationAddresses.clear(); nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); } else if (PeerBlockchainService.ACTION_RESET_BLOCKCHAIN.equals(action)) { resetBlockchainOnShutdown = true; stopSelf(); } else if (PeerBlockchainService.ACTION_BROADCAST_TRANSACTION.equals(action)) { String addressExtra = intent.getStringExtra("address"); String amountExtra = intent.getStringExtra("amount"); boolean justDecrypted = intent.getBooleanExtra("justDecrypted", false); String tagExtra = intent.getStringExtra("tagText"); BigInteger amountBigInt = new BigInteger(amountExtra); final Wallet wallet = application.getWallet(); try { Address address = new Address(Constants.NETWORK_PARAMETERS, addressExtra); Wallet.SendRequest sendRequest = Wallet.SendRequest.to(address, amountBigInt); //Adding the tag to the shared prefs tagPrefs = application.getSharedPreferences(getString(R.string.tag_pref_filename), Context.MODE_PRIVATE); tagPrefs.edit().putString(sendRequest.tx.getHashAsString(), tagExtra).commit(); sendRequest.ensureMinRequiredFee = false; //sendRequest.fee = BigInteger.valueOf(1000); Transaction transaction = wallet.sendCoinsOffline(sendRequest); if (transaction != null && peerGroup != null) { ListenableFuture<Transaction> future = peerGroup.broadcastTransaction(transaction); //TODO: Maybe doe something with future? } } catch (AddressFormatException e) { Log.e(TAG, "Address format exception " + e.getMessage()); } catch (InsufficientMoneyException e) { Log.e(TAG, "Insufficient Money Exception " + e.getMessage()); } catch (NullPointerException e) { Log.e(TAG, "null pointer exception: " + e.getMessage()); } catch (IllegalArgumentException e) { Log.e(TAG, "illegal argument exception: " + e.getMessage()); } catch (IllegalStateException e) { Log.e(TAG, "illegal state exception: " + e.getMessage()); } catch (KeyCrypterException e) { Log.e(TAG, "key crypter exception: " + e.getMessage()); } finally { if (justDecrypted) { if (application.getKeyCache() != null) { wallet.encrypt(application.getKeyCache().getKeyCrypter(), application.getKeyCache().getAesKey()); String x2 = prefs.getString(Constants.SHAMIR_ENCRYPTED_KEY, null); if (x2 != null) { String encryptedX2 = WalletUtils.encryptString(x2, application.getKeyCache().getPassword()); prefs.edit().putString(Constants.SHAMIR_ENCRYPTED_KEY, encryptedX2).commit(); } } } } } return START_NOT_STICKY; }
From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java
@Override @SuppressWarnings("unchecked") public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_PHOTO) { onSelectFromGalleryResult(data); } else if (requestCode == REQUEST_CAMERA) { } else if (requestCode == REQUEST_ANNOTATE && data != null) { // If mechanismViewId == -1, an error occurred int mechanismViewId = data.getIntExtra(Utils.EXTRA_KEY_MECHANISM_VIEW_ID, -1); if (mechanismViewId != -1) { ScreenshotMechanismView screenshotMechanismView = (ScreenshotMechanismView) allMechanismViews .get(mechanismViewId); // Sticker annotations if (data.getBooleanExtra(Utils.EXTRA_KEY_HAS_STICKER_ANNOTATIONS, false)) { screenshotMechanismView.setAllStickerAnnotations((HashMap<Integer, String>) data .getSerializableExtra(Utils.EXTRA_KEY_ALL_STICKER_ANNOTATIONS)); }/*from w w w . j av a 2s. co m*/ // Text annotations if (data.getBooleanExtra(Utils.EXTRA_KEY_HAS_TEXT_ANNOTATIONS, false)) { screenshotMechanismView.setAllTextAnnotations((HashMap<Integer, String>) data .getSerializableExtra(Utils.EXTRA_KEY_ALL_TEXT_ANNOTATIONS)); } // Annotated image with stickers String tempPathWithStickers = data .getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITH_STICKERS) + "/" + mechanismViewId + ANNOTATED_IMAGE_NAME_WITH_STICKERS; screenshotMechanismView.setAnnotatedImagePath(tempPathWithStickers); screenshotMechanismView.setPicturePath(tempPathWithStickers); Bitmap annotatedBitmap = Utils.loadImageFromStorage(tempPathWithStickers); if (annotatedBitmap != null) { screenshotMechanismView.setPictureBitmap(annotatedBitmap); screenshotMechanismView.getScreenShotPreviewImageView().setImageBitmap(annotatedBitmap); } // Annotated image without stickers if (data.getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS) == null) { screenshotMechanismView.setPicturePathWithoutStickers(null); } else { String tempPathWithoutStickers = data .getStringExtra(Utils.EXTRA_KEY_ANNOTATED_IMAGE_PATH_WITHOUT_STICKERS) + "/" + mechanismViewId + ANNOTATED_IMAGE_NAME_WITHOUT_STICKERS; screenshotMechanismView.setPicturePathWithoutStickers(tempPathWithoutStickers); } } else { Log.e(TAG, "Failed to annotate the image. No mechanismViewID provided"); } } } }
From source file:uk.bowdlerize.service.CensorCensusService.java
@Override public int onStartCommand(final Intent intent, int flags, int startId) { if (null == mNotifyManager) mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (null == mBuilder) mBuilder = new NotificationCompat.Builder(this); if (null == api) api = new API(this); mContext = this; checkedCount = getPreferences(this).getInt("checkedCount", 0); censoredCount = getPreferences(this).getInt("censoredCount", 0); sendtoORG = getPreferences(this).getBoolean("sendToOrg", false); //Make it so tapping an intent will launch the app (Fix #12) launchAppIntent = new Intent(mContext, MainActivity.class); pendingIntent = PendingIntent.getActivity(mContext, 0, launchAppIntent, 0); mBuilder.setContentIntent(pendingIntent); //Lets findout why we've been started if (intent.getBooleanExtra(API.EXTRA_POLL, false) || intent.getBooleanExtra(API.EXTRA_GCM_TICKLE, false)) { prepProbe(intent);//from w ww .jav a 2s . co m } else if (intent.hasExtra("url") && !intent.getStringExtra("url").equals("")) { performProbe(intent); } else { onProbeFinish(); } //If we're polling we probably want to stay alive if (getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE) .getInt(API.SETTINGS_GCM_PREFERENCE, API.SETTINGS_GCM_FULL) == API.SETTINGS_GCM_DISABLED) { return START_STICKY; } else { return START_NOT_STICKY; } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/* ww w .j a v a 2s . c o m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "ferries_schedules" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (30 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(FERRIES_SCHEDULES_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray items = new JSONArray(jsonFile); List<ContentValues> schedules = new ArrayList<ContentValues>(); int numItems = items.length(); for (int i = 0; i < numItems; i++) { JSONObject item = items.getJSONObject(i); ContentValues schedule = new ContentValues(); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ID, item.getInt("RouteID")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_TITLE, item.getString("Description")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_DATE, item.getString("Date")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ALERT, item.getString("RouteAlert")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_UPDATED, dateFormat .format(new Date(Long.parseLong(item.getString("CacheDate").substring(6, 19))))); if (starred.contains(item.getInt("RouteID"))) { schedule.put(FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED, 1); } schedules.add(schedule); } // Purge existing travel times covered by incoming data resolver.delete(FerriesSchedules.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(FerriesSchedules.CONTENT_URI, schedules.toArray(new ContentValues[schedules.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "ferries_schedules" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_SCHEDULES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }