List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:com.gelakinetic.mtgfam.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* http://stackoverflow.com/questions/13179620/force-overflow-menu-in-actionbarsherlock/13180285 * //w w w . j a va 2 s . c o m * Open ActionBarSherlock/src/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter.java, go to method reserveOverflow * Replace the original with: * public static boolean reserveOverflow(Context context) { return true; } */ if (DEVICE_VERSION >= DEVICE_HONEYCOMB) { try { ViewConfiguration config = ViewConfiguration.get(this); Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); if (menuKeyField != null) { menuKeyField.setAccessible(true); menuKeyField.setBoolean(config, false); } } catch (Exception ex) { // Ignore } } mFragmentManager = getSupportFragmentManager(); try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (NameNotFoundException e) { pInfo = null; } if (prefAdapter == null) { prefAdapter = new PreferencesAdapter(this); } int lastVersion = prefAdapter.getLastVersion(); if (pInfo.versionCode != lastVersion) { // Clear the robospice cache on upgrade. This way, no cached values w/o foil prices will exist try { spiceManager.removeAllDataFromCache(); } catch (NullPointerException e) { // eat it. tasty } showDialogFragment(CHANGELOGDIALOG); prefAdapter.setLastVersion(pInfo.versionCode); bounceMenu = lastVersion <= 15; //Only bounce if the last version is 1.8.1 or lower (or a fresh install) } File mtr = new File(getFilesDir(), JudgesCornerFragment.MTR_LOCAL_FILE); File ipg = new File(getFilesDir(), JudgesCornerFragment.IPG_LOCAL_FILE); if (!mtr.exists()) { try { InputStream in = getResources().openRawResource(R.raw.mtr); FileOutputStream fos = new FileOutputStream(mtr); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "MTR file could not be copied: " + e.getMessage()); } } if (!ipg.exists()) { try { InputStream in = getResources().openRawResource(R.raw.ipg); FileOutputStream fos = new FileOutputStream(ipg); IOUtils.copy(in, fos); } catch (FileNotFoundException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } catch (IOException e) { Log.w("MainActivity", "IPG file could not be copied: " + e.getMessage()); } } ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setIcon(R.drawable.sliding_menu_icon); SlidingMenu slidingMenu = getSlidingMenu(); slidingMenu.setBehindWidthRes(R.dimen.sliding_menu_width); slidingMenu.setBehindScrollScale(0.0f); slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); slidingMenu.setShadowWidthRes(R.dimen.shadow_width); slidingMenu.setShadowDrawable(R.drawable.sliding_menu_shadow); setSlidingActionBarEnabled(false); setBehindContentView(R.layout.fragment_menu); me = this; boolean autoupdate = prefAdapter.getAutoUpdate(); if (autoupdate) { // Only update the banning list if it hasn't been updated recently long curTime = new Date().getTime(); int updatefrequency = Integer.valueOf(prefAdapter.getUpdateFrequency()); int lastLegalityUpdate = prefAdapter.getLastLegalityUpdate(); // days to ms if (((curTime / 1000) - lastLegalityUpdate) > (updatefrequency * 24 * 60 * 60)) { startService(new Intent(this, DbUpdaterService.class)); } } timerHandler = new Handler(); registerReceiver(endTimeReceiver, new IntentFilter(RoundTimerFragment.RESULT_FILTER)); registerReceiver(startTimeReceiver, new IntentFilter(RoundTimerService.START_FILTER)); registerReceiver(cancelTimeReceiver, new IntentFilter(RoundTimerService.CANCEL_FILTER)); updatingDisplay = false; timeShowing = false; getSlidingMenu().setOnOpenedListener(new OnOpenedListener() { @Override public void onOpened() { // Close the keyboard if the slidingMenu is opened hideKeyboard(); } }); setContentView(R.layout.fragment_activity); getSupportFragmentManager().beginTransaction().replace(R.id.frag_menu, new MenuFragment()).commit(); showOnePane(); if (findViewById(R.id.middle_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mIsATablet = true; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { mThreePane = true; } else { mThreePane = false; } } else { mThreePane = false; mIsATablet = false; if (findViewById(R.id.middle_container) != null) { findViewById(R.id.middle_container).setVisibility(View.GONE); findViewById(R.id.right_container).setVisibility(View.GONE); } } Intent intent = getIntent(); if (savedInstanceState == null) { try { if (intent.getAction().equals(Intent.ACTION_VIEW)) { //apparently this can NPE on 4.3. because why not. if we catch it, launch the default frag // handles a click on a search suggestion; launches activity to show word Uri u = intent.getData(); long id = Long.parseLong(u.getLastPathSegment()); // add a fragment Bundle args = new Bundle(); args.putBoolean("isSingle", true); args.putLong("id", id); CardViewFragment rlFrag = new CardViewFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); showOnePane(); hideKeyboard(); } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) { boolean consolidate = prefAdapter.getConsolidateSearch(); String query = intent.getStringExtra(SearchManager.QUERY); SearchCriteria sc = new SearchCriteria(); sc.Name = query; sc.Set_Logic = (consolidate ? CardDbAdapter.FIRSTPRINTING : CardDbAdapter.ALLPRINTINGS); // add a fragment Bundle args = new Bundle(); args.putBoolean(SearchViewFragment.RANDOM, false); args.putSerializable(SearchViewFragment.CRITERIA, sc); if (mIsATablet) { SearchViewFragment svFrag = new SearchViewFragment(); svFrag.setArguments(args); attachSingleFragment(svFrag, "left_frag", false, false); } else { ResultListFragment rlFrag = new ResultListFragment(); rlFrag.setArguments(args); attachSingleFragment(rlFrag, "left_frag", false, false); } hideKeyboard(); } else if (intent.getAction().equals(ACTION_FULL_SEARCH)) { attachSingleFragment(new SearchViewFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_WIDGET_SEARCH)) { attachSingleFragment(new SearchWidgetFragment(), "left_frag", false, false); showOnePane(); } else if (intent.getAction().equals(ACTION_ROUND_TIMER)) { attachSingleFragment(new RoundTimerFragment(), "left_frag", false, false); showOnePane(); } else { launchDefaultFragment(); } } catch (NullPointerException e) { launchDefaultFragment(); } } }
From source file:com.hichinaschool.flashcards.anki.CardBrowser.java
/** * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver) *///from w w w.j ava2 s . c o m private void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) { finish(); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(SdCardReceiver.MEDIA_EJECT); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.ubuntuone.android.files.service.UpDownService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!Preferences.hasTokens(this)) { stopSelf();/*from w w w. ja v a 2 s. com*/ } else if (intent != null) { final String action = intent.getAction(); if (action.equals(ACTION_UPLOAD)) { startUploader(); return START_REDELIVER_INTENT; } else if (action.equals(ACTION_DOWNLOAD)) { startDownloader(); return START_REDELIVER_INTENT; } else if (ACTION_RETRY.equals(action)) { TransferUtils.clearFailedUploadsState(contentResolver); startUploader(); } } return START_NOT_STICKY; }
From source file:com.intel.xdk.device.Device.java
private void registerScreenStatusReceiver() { if (screenStatusReceiver == null) { //Listener to the screen unlock event. screenStatusReceiver = new BroadcastReceiver() { @Override/* w ww . j a v a 2 s. co m*/ public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { Log.d("screen_on", "Screen is on."); } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.d("screen_lock", "Screen is off"); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.pause');e.success=true;document.dispatchEvent(e);"; injectJS(js); } else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { Log.d("user_present", "User is present."); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.continue');e.success=true;document.dispatchEvent(e);"; injectJS(js); } } }; } IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); activity.registerReceiver(screenStatusReceiver, filter); }
From source file:edu.mit.media.funf.probe.Probe.java
private boolean isRequestsIntent(Intent intent) { // TODO: verify security number // TODO: maybe count brute force attacks, shut down if too many return ACTION_INTERNAL_REQUESTS.equals(intent.getAction()); }
From source file:net.peterkuterna.android.apps.devoxxsched.service.NewsSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start news sync"); final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { mLocalExecutor.execute(context, "cache-news.json", new NewsHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.NEWS_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(News.NEWS_NEW, 0);/*from w w w . j a va 2s. c o m*/ getContentResolver().update(News.CONTENT_NEW_URI, values, null, null); } Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); mRemoteExecutor.executeGet(NEWS_URL, new NewsHandler()); Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewNewsItems(); Log.d(TAG, "News sync finished"); }
From source file:br.com.bioscada.apps.biotracks.io.file.importer.ImportActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); importAll = intent.getBooleanExtra(EXTRA_IMPORT_ALL, false); trackFileFormat = intent.getParcelableExtra(EXTRA_TRACK_FILE_FORMAT); if (trackFileFormat == null) { trackFileFormat = TrackFileFormat.GPX; }//from www . ja va2s. com if (!FileUtils.isExternalStorageAvailable()) { Toast.makeText(this, R.string.external_storage_not_available, Toast.LENGTH_LONG).show(); finish(); return; } String directoryPath; if (importAll) { directoryDisplayName = FileUtils.getPathDisplayName(trackFileFormat.getExtension()); directoryPath = FileUtils.getPath(trackFileFormat.getExtension()); if (!FileUtils.isDirectory(new File(directoryPath))) { Toast.makeText(this, getString(R.string.import_no_directory, directoryDisplayName), Toast.LENGTH_LONG).show(); finish(); return; } } else { String action = intent.getAction(); if (!(Intent.ACTION_ATTACH_DATA.equals(action) || Intent.ACTION_VIEW.equals(action))) { Log.d(TAG, "Invalid action: " + intent); finish(); return; } Uri data = intent.getData(); if (!UriUtils.isFileUri(data)) { Log.d(TAG, "Invalid data: " + intent); finish(); return; } directoryDisplayName = data.getPath(); directoryPath = data.getPath(); } Object retained = getLastNonConfigurationInstance(); if (retained instanceof ImportAsyncTask) { importAsyncTask = (ImportAsyncTask) retained; importAsyncTask.setActivity(this); } else { importAsyncTask = new ImportAsyncTask(this, importAll, trackFileFormat, directoryPath); importAsyncTask.execute(); } }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
private void buildDefaultState() { mState = new State(); final Intent intent = virtualIntent; final String action = intent.getAction(); if (Intent.ACTION_OPEN_DOCUMENT.equals(action)) { mState.action = ACTION_OPEN;//w w w .j ava2 s . c o m } else if (Intent.ACTION_CREATE_DOCUMENT.equals(action)) { mState.action = ACTION_CREATE; } else if (Intent.ACTION_GET_CONTENT.equals(action)) { mState.action = ACTION_GET_CONTENT; } else if (DocumentsContract.ACTION_MANAGE_ROOT.equals(action)) { mState.action = ACTION_MANAGE; } if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { mState.allowMultiple = intent.getBooleanExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); } if (mState.action == ACTION_MANAGE) { mState.acceptMimes = new String[] { "*/*" }; mState.allowMultiple = true; } else if (intent.hasExtra(Intent.EXTRA_MIME_TYPES)) { mState.acceptMimes = intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES); } else { mState.acceptMimes = new String[] { intent.getType() }; } mState.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false); mState.forceAdvanced = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false); mState.showAdvanced = mState.forceAdvanced | SettingsActivity.getDisplayAdvancedDevices(this); }
From source file:com.horizondigital.delta.UpdateService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { if (ACTION_CHECK.equals(intent.getAction())) { checkForUpdates(true);/*from w w w .j a v a 2s . c om*/ } else if (ACTION_FLASH.equals(intent.getAction())) { flashUpdate(); } else if (ACTION_ALARM.equals(intent.getAction())) { scheduler.alarm(intent.getIntExtra(EXTRA_ALARM_ID, -1)); autoState(); } else if (ACTION_NOTIFICATION_DELETED.equals(intent.getAction())) { Logger.i("Snoozing for 24 hours"); prefs.edit().putLong(PREF_LAST_SNOOZE_TIME_NAME, System.currentTimeMillis()).commit(); autoState(); } } return START_STICKY; }