List of usage examples for android.content Intent getAction
public @Nullable String getAction()
From source file:cgeo.geocaching.CacheListActivity.java
private boolean isInvokedFromAttachment() { final Intent intent = getIntent(); return Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null; }
From source file:com.fvd.nimbus.PaintActivity.java
/** Called when the activity is first created. */ @Override// w ww.ja va 2 s . c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up ); overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { requestWindowFeature(Window.FEATURE_NO_TITLE); } catch (Exception e) { e.printStackTrace(); } ctx = this; prefs = PreferenceManager.getDefaultSharedPreferences(this); dWidth = prefs.getInt("dWidth", 2); fWidth = prefs.getInt("fWidth", 1); dColor = prefs.getInt(pColor, Color.RED); saveFormat = Integer.parseInt(prefs.getString("saveFormat", "1")); serverHelper.getInstance().setCallback(this, this); serverHelper.getInstance().setMode(saveFormat); setContentView(R.layout.screen_edit); drawer = (DrawerLayout) findViewById(R.id.root); findViewById(R.id.bDraw1).setOnClickListener(this); findViewById(R.id.bDraw2).setOnClickListener(this); findViewById(R.id.bDraw3).setOnClickListener(this); findViewById(R.id.bDraw4).setOnClickListener(this); findViewById(R.id.bDraw5).setOnClickListener(this); findViewById(R.id.bDraw6).setOnClickListener(this); findViewById(R.id.bDraw8).setOnClickListener(this); findViewById(R.id.bColor1).setOnClickListener(this); findViewById(R.id.bColor2).setOnClickListener(this); findViewById(R.id.bColor3).setOnClickListener(this); findViewById(R.id.bColor4).setOnClickListener(this); findViewById(R.id.bColor5).setOnClickListener(this); paletteButton = (CircleButton) findViewById(R.id.bToolColor); paletteButton.setOnClickListener(this); paletteButton_land = (CircleButton) findViewById(R.id.bToolColor_land); //paletteButton_land.setOnClickListener(this); ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(dWidth * 10); ((SeekBar) findViewById(R.id.seekBarType)).setProgress(fWidth * 10); ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", 40 + fWidth * 20)); findViewById(R.id.bUndo).setOnClickListener(this); findViewById(R.id.btnBack).setOnClickListener(this); findViewById(R.id.bClearAll).setOnClickListener(this); findViewById(R.id.bTurnLeft).setOnClickListener(this); findViewById(R.id.bTurnRight).setOnClickListener(this); findViewById(R.id.bDone).setOnClickListener(this); findViewById(R.id.bApplyText).setOnClickListener(this); ((ImageButton) findViewById(R.id.bStroke)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.setSelected(!v.isSelected()); } }); lineWidthListener = new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if (true || fromUser) { /*dWidth = (progress/10); drawView.setWidth((dWidth+1)*5);*/ dWidth = progress; drawView.setWidth(dWidth); Editor e = prefs.edit(); e.putInt("dWidth", dWidth); e.commit(); } } }; ((SeekBar) findViewById(R.id.seekBarLine)).setOnSeekBarChangeListener(lineWidthListener); ((SeekBar) findViewById(R.id.ls_seekBarLine)).setOnSeekBarChangeListener(lineWidthListener); fontSizeListener = new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if (fromUser) { fWidth = progress / 10; int c = 40 + fWidth * 20; drawView.setFontSize(c); Editor e = prefs.edit(); e.putInt("fWidth", fWidth); e.commit(); try { ((TextView) findViewById(R.id.tvTextType)).setText(String.format("%d", c)); ((TextView) findViewById(R.id.ls_tvTextType)).setText(String.format("%d", c)); } catch (Exception ex) { } } } }; ((SeekBar) findViewById(R.id.seekBarType)).setOnSeekBarChangeListener(fontSizeListener); ((SeekBar) findViewById(R.id.ls_seekBarType)).setOnSeekBarChangeListener(fontSizeListener); drawView = (DrawView) findViewById(R.id.painter); drawView.setWidth((dWidth + 1) * 5); drawView.setFontSize(40 + fWidth * 20); setBarConfig(getResources().getConfiguration().orientation); findViewById(R.id.bEditPage).setOnClickListener(this); findViewById(R.id.bToolColor).setOnClickListener(this); findViewById(R.id.bErase).setOnClickListener(this); findViewById(R.id.bToolShape).setOnClickListener(this); findViewById(R.id.bToolText).setOnClickListener(this); findViewById(R.id.bToolCrop).setOnClickListener(this); findViewById(R.id.btnBack).setOnClickListener(this); findViewById(R.id.bDone).setOnClickListener(this); findViewById(R.id.btnShare).setOnClickListener(this); findViewById(R.id.bSave2SD).setOnClickListener(this); findViewById(R.id.bSave2Nimbus).setOnClickListener(this); userMail = prefs.getString("userMail", ""); userPass = prefs.getString("userPass", ""); sessionId = prefs.getString("sessionId", ""); appSettings.sessionId = sessionId; appSettings.userMail = userMail; appSettings.userPass = userPass; storePath = ""; Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); //storePath= intent.getPackage().getClass().toString(); if ((Intent.ACTION_VIEW.equals(action) || Intent.ACTION_SEND.equals(action) || "com.onebit.nimbusnote.EDIT_PHOTO".equals(action)) && type != null) { if (type.startsWith("image/")) { Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (imageUri == null) imageUri = intent.getData(); if (imageUri != null) { String url = Uri.decode(imageUri.toString()); if (url.startsWith(CONTENT_PHOTOS_URI_PREFIX)) { url = getPhotosPhotoLink(url); } //else url=Uri.decode(url); ContentResolver cr = getContentResolver(); InputStream is; try { is = cr.openInputStream(Uri.parse(url)); if ("com.onebit.nimbusnote.EDIT_PHOTO".equals(action)) storePath = " ";//getGalleryPath(Uri.parse(url)); Bitmap bmp = BitmapFactory.decodeStream(is); if (bmp.getWidth() != -1 && bmp.getHeight() != -1) drawView.setBitmap(bmp, 0); } catch (Exception e) { appSettings.appendLog("paint:onCreate " + e.getMessage()); } } } } else { String act = getIntent().getExtras().getString("act"); if ("photo".equals(act)) { getPhoto(); } else if ("picture".equals(act)) { getPicture(); } else { String filePath = getIntent().getExtras().getString("path"); boolean isTemp = getIntent().getExtras().getBoolean("temp"); domain = getIntent().getExtras().getString("domain"); if (domain == null) domain = serverHelper.getDate(); if (filePath.contains("://")) { Bitmap bmp = helper.LoadImageFromWeb(filePath); if (bmp != null) { drawView.setBitmap(bmp, 0); } } else { File file = new File(filePath); if (file.exists()) { try { int orient = helper.getOrientationFromExif(filePath); Bitmap bmp = helper.decodeSampledBitmap(filePath, 1000, 1000); if (bmp != null) { drawView.setBitmap(bmp, orient); } } catch (Exception e) { appSettings.appendLog("paint.onCreate() " + e.getMessage()); } if (isTemp) file.delete(); } } } } drawView.setBackgroundColor(Color.WHITE); drawView.requestFocus(); drawView.setColour(dColor); setPaletteColor(dColor); drawView.setSelChangeListener(new shapeSelectionListener() { @Override public void onSelectionChanged(int shSize, int fSize, int shColor) { setSelectedFoot(0); setLandToolSelected(R.id.bEditPage_land); //updateColorDialog(shSize!=-1?(shSize/5)-1:dWidth, fSize!=-1?(fSize-40)/20:fWidth, shColor!=0?colorToId(shColor):dColor); dColor = shColor; ccolor = shColor; int sw = shSize != -1 ? shSize : dWidth; canChange = false; ((SeekBar) findViewById(R.id.seekBarLine)).setProgress(sw); ((SeekBar) findViewById(R.id.ls_seekBarLine)).setProgress(sw); setPaletteColor(dColor); drawView.setColour(dColor); canChange = true; } @Override public void onTextChanged(String text, boolean stroke) { if (findViewById(R.id.text_field).getVisibility() != View.VISIBLE) { hideTools(); findViewById(R.id.bStroke).setSelected(stroke); ((EditText) findViewById(R.id.etEditorText)).setText(text); findViewById(R.id.text_field).setVisibility(View.VISIBLE); findViewById(R.id.etEditorText).requestFocus(); ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .showSoftInput(findViewById(R.id.etEditorText), 0); findViewById(R.id.bToolText).postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub setSelectedFoot(2); } }, 100); } } }); setColorButtons(dColor); //mPlanetTitles = getResources().getStringArray(R.array.lmenu_paint); /*ListView listView = (ListView) findViewById(R.id.left_drawer); listView.setAdapter(new DrawerMenuAdapter(this,getResources().getStringArray(R.array.lmenu_paint))); listView.setOnItemClickListener(this);*/ }
From source file:com.ichi2.anki.NoteEditor.java
@Override protected void onCreate(Bundle savedInstanceState) { Timber.d("onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.note_editor); Intent intent = getIntent(); if (savedInstanceState != null) { mCaller = savedInstanceState.getInt("caller"); mAddNote = savedInstanceState.getBoolean("addFact"); mCurrentDid = savedInstanceState.getLong("did"); mSelectedTags = new ArrayList<>(Arrays.asList(savedInstanceState.getStringArray("tags"))); mSavedFields = savedInstanceState.getBundle("editFields"); } else {/*from w w w. j a v a2 s. co m*/ mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER); if (mCaller == CALLER_NOCALLER) { String action = intent.getAction(); if (action != null && (ACTION_CREATE_FLASHCARD.equals(action) || ACTION_CREATE_FLASHCARD_SEND.equals(action))) { mCaller = CALLER_CARDEDITOR_INTENT_ADD; } } } startLoadingCollection(); }
From source file:android.support.v7.media.RemotePlaybackClient.java
private void performSessionAction(final Intent intent, final String sessionId, Bundle extras, final SessionActionCallback callback) { intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); if (sessionId != null) { intent.putExtra(MediaControlIntent.EXTRA_SESSION_ID, sessionId); }/* w w w.ja v a 2s . c o m*/ if (extras != null) { intent.putExtras(extras); } logRequest(intent); mRoute.sendControlRequest(intent, new MediaRouter.ControlRequestCallback() { @Override public void onResult(Bundle data) { if (data != null) { String sessionIdResult = inferMissingResult(sessionId, data.getString(MediaControlIntent.EXTRA_SESSION_ID)); MediaSessionStatus sessionStatus = MediaSessionStatus .fromBundle(data.getBundle(MediaControlIntent.EXTRA_SESSION_STATUS)); adoptSession(sessionIdResult); if (sessionIdResult != null) { if (DEBUG) { Log.d(TAG, "Received result from " + intent.getAction() + ": data=" + bundleToString(data) + ", sessionId=" + sessionIdResult + ", sessionStatus=" + sessionStatus); } try { callback.onResult(data, sessionIdResult, sessionStatus); } finally { if (intent.getAction().equals(MediaControlIntent.ACTION_END_SESSION) && sessionIdResult.equals(mSessionId)) { setSessionId(null); } } return; } } handleInvalidResult(intent, callback, data); } @Override public void onError(String error, Bundle data) { handleError(intent, callback, error, data); } }); }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MediaPlaybackService.java
/** * Registers an intent to listen for ACTION_MEDIA_EJECT notifications. * The intent will call closeExternalStorageFiles() if the external media * is going to be ejected, so applications can clean up any files they have open. *///from w w w . j a v a 2 s .co m public void registerExternalStorageListener() { if (mUnmountReceiver == null) { mUnmountReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_MEDIA_EJECT)) { saveQueue(true); mQueueIsSaveable = false; closeExternalStorageFiles(intent.getData().getPath()); } else if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) { mMediaMountedCount++; mCardId = MusicUtils.getCardId(MediaPlaybackService.this); reloadQueue(); mQueueIsSaveable = true; notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); } } }; IntentFilter iFilter = new IntentFilter(); iFilter.addAction(Intent.ACTION_MEDIA_EJECT); iFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); iFilter.addDataScheme("file"); registerReceiver(mUnmountReceiver, iFilter); } }
From source file:com.ichi2.anki.CardEditor.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.i(AnkiDroidApp.TAG, "CardEditor: onCreate"); Themes.applyTheme(this); super.onCreate(savedInstanceState); this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Intent intent = getIntent(); if (savedInstanceState != null) { mCaller = savedInstanceState.getInt("caller"); mAddNote = savedInstanceState.getBoolean("addFact"); } else {/*ww w .jav a 2s . co m*/ mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER); if (mCaller == CALLER_NOCALLER) { String action = intent.getAction(); if (action != null && (ACTION_CREATE_FLASHCARD.equals(action) || ACTION_CREATE_FLASHCARD_SEND.equals(action))) { mCaller = CALLER_INDICLASH; } } } Log.i(AnkiDroidApp.TAG, "CardEditor: caller: " + mCaller); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); if (mCaller == CALLER_INDICLASH && preferences.getBoolean("intentAdditionInstantAdd", false)) { // save information without showing card editor fetchIntentInformation(intent); MetaDB.saveIntentInformation(CardEditor.this, Utils.joinFields(mSourceText)); Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.app_name) + ": " + getResources().getString(R.string.CardEditorLaterMessage), false); finish(); return; } mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } registerExternalStorageListener(); View mainView = getLayoutInflater().inflate(R.layout.card_editor, null); setContentView(mainView); Themes.setWallpaper(mainView); Themes.setContentStyle(mainView, Themes.CALLER_CARD_EDITOR); mFieldsLayoutContainer = (LinearLayout) findViewById(R.id.CardEditorEditFieldsLayout); mSave = (Button) findViewById(R.id.CardEditorSaveButton); mCancel = (Button) findViewById(R.id.CardEditorCancelButton); mLater = (Button) findViewById(R.id.CardEditorLaterButton); mDeckButton = (TextView) findViewById(R.id.CardEditorDeckText); mModelButton = (TextView) findViewById(R.id.CardEditorModelText); mTagsButton = (TextView) findViewById(R.id.CardEditorTagText); mSwapButton = (Button) findViewById(R.id.CardEditorSwapButton); mSwapButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { swapText(false); } }); mAedictIntent = false; switch (mCaller) { case CALLER_NOCALLER: Log.i(AnkiDroidApp.TAG, "CardEditor: no caller could be identified, closing"); finish(); return; case CALLER_REVIEWER: mCurrentEditedCard = Reviewer.getEditorCard(); if (mCurrentEditedCard == null) { finish(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_STUDYOPTIONS: case CALLER_DECKPICKER: mAddNote = true; break; case CALLER_BIGWIDGET_EDIT: // Card widgetCard = AnkiDroidWidgetBig.getCard(); // if (widgetCard == null) { // finish(); // return; // } // mEditorNote = widgetCard.getFact(); // mAddNote = false; break; case CALLER_BIGWIDGET_ADD: mAddNote = true; break; case CALLER_CARDBROWSER_EDIT: mCurrentEditedCard = CardBrowser.sCardBrowserCard; if (mCurrentEditedCard == null) { finish(); return; } mEditorNote = mCurrentEditedCard.note(); mAddNote = false; break; case CALLER_CARDBROWSER_ADD: mAddNote = true; break; case CALLER_CARDEDITOR: mAddNote = true; break; case CALLER_CARDEDITOR_INTENT_ADD: mAddNote = true; break; case CALLER_INDICLASH: fetchIntentInformation(intent); if (mSourceText == null) { finish(); return; } if (mSourceText[0].equals("Aedict Notepad") && addFromAedict(mSourceText[1])) { finish(); return; } mAddNote = true; break; } setNote(mEditorNote); if (mAddNote) { setTitle(R.string.cardeditor_title_add_note); // set information transferred by intent String contents = null; if (mSourceText != null) { if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) { contents = mSourceText[1].replaceFirst("\\[", "\u001f"); contents = contents.substring(0, contents.length() - 1); } else { mEditFields.get(0).setText(mSourceText[0]); mEditFields.get(1).setText(mSourceText[1]); } } else { contents = intent.getStringExtra(EXTRA_CONTENTS); } if (contents != null) { setEditFieldTexts(contents); } LinearLayout modelButton = ((LinearLayout) findViewById(R.id.CardEditorModelButton)); modelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_MODEL_SELECT); } }); modelButton.setVisibility(View.VISIBLE); mSave.setText(getResources().getString(R.string.add)); mCancel.setText(getResources().getString(R.string.close)); mLater.setVisibility(View.VISIBLE); mLater.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String content = getFieldsText(); if (content.length() > mEditFields.size() - 1) { MetaDB.saveIntentInformation(CardEditor.this, content); populateEditFields(); mSourceText = null; Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.CardEditorLaterMessage), false); } if (mCaller == CALLER_INDICLASH || mCaller == CALLER_CARDEDITOR_INTENT_ADD) { closeCardEditor(); } } }); } else { setTitle(R.string.cardeditor_title_edit_card); mSwapButton.setVisibility(View.GONE); mSwapButton = (Button) findViewById(R.id.CardEditorLaterButton); mSwapButton.setVisibility(View.VISIBLE); mSwapButton.setText(getResources().getString(R.string.fact_adder_swap)); mSwapButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { swapText(false); } }); } ((LinearLayout) findViewById(R.id.CardEditorDeckButton)).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(DIALOG_DECK_SELECT); } }); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); // if Arabic reshaping is enabled, disable the Save button to avoid // saving the reshaped string to the deck if (mPrefFixArabic && !mAddNote) { mSave.setEnabled(false); } ((LinearLayout) findViewById(R.id.CardEditorTagButton)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showDialog(DIALOG_TAGS_SELECT); } }); mSave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (duplicateCheck(true)) { return; } boolean modified = false; for (FieldEditText f : mEditFields) { modified = modified | f.updateField(); } if (mAddNote) { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, mSaveFactHandler, new DeckTask.TaskData(mEditorNote)); } else { // added tag? for (String t : mCurrentTags) { modified = modified || !mEditorNote.hasTag(t); } // removed tag? modified = modified || mEditorNote.getTags().size() > mCurrentTags.size(); // changed did? boolean changedDid = mCurrentEditedCard.getDid() != mCurrentDid; modified = modified || changedDid; if (modified) { mEditorNote.setTags(mCurrentTags); // set did for card if (changedDid) { mCurrentEditedCard.setDid(mCurrentDid); } mChanged = true; } closeCardEditor(); // if (mCaller == CALLER_BIGWIDGET_EDIT) { // // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, // // mSaveFactHandler, new // // DeckTask.TaskData(Reviewer.UPDATE_CARD_SHOW_QUESTION, // // mDeck, AnkiDroidWidgetBig.getCard())); // } else if (!mCardReset) { // // Only send result to save if something was actually // // changed // if (mModified) { // setResult(RESULT_OK); // } else { // setResult(RESULT_CANCELED); // } // closeCardEditor(); // } } } }); mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { closeCardEditor(); } }); }
From source file:com.maskyn.fileeditorpro.activity.MainActivity.java
/** * Parses the intent//from w w w. j a v a 2s . com */ private void parseIntent(Intent intent) { final String action = intent.getAction(); final String type = intent.getType(); if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action) || Intent.ACTION_PICK.equals(action) && type != null) { // Post event //newFileToOpen(new File(intent // .getData().getPath()), ""); Uri uri = intent.getData(); GreatUri newUri = new GreatUri(uri, AccessStorageApi.getPath(this, uri), AccessStorageApi.getName(this, uri)); newFileToOpen(newUri, ""); } else if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { newFileToOpen(new GreatUri(Uri.EMPTY, "", ""), intent.getStringExtra(Intent.EXTRA_TEXT)); } } }
From source file:mp.teardrop.PlaybackService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { String action = intent.getAction(); if (ACTION_TOGGLE_PLAYBACK.equals(action)) { playPause();//from w w w. j ava2s .com } else if (ACTION_TOGGLE_PLAYBACK_NOTIFICATION.equals(action)) { mForceNotificationVisible = true; synchronized (mStateLock) { if ((mState & FLAG_PLAYING) != 0) pause(); else play(); } } else if (ACTION_TOGGLE_PLAYBACK_DELAYED.equals(action)) { if (mHandler.hasMessages(CALL_GO, Integer.valueOf(0))) { mHandler.removeMessages(CALL_GO, Integer.valueOf(0)); Intent launch = new Intent(this, LibraryActivity.class); launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); launch.setAction(Intent.ACTION_MAIN); startActivity(launch); } else { mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, 0, 0, Integer.valueOf(0)), 400); } } else if (ACTION_NEXT_SONG.equals(action)) { setCurrentSong(1, false); userActionTriggered(); } else if (ACTION_NEXT_SONG_AUTOPLAY.equals(action)) { setCurrentSong(1, false); play(); } else if (ACTION_NEXT_SONG_DELAYED.equals(action)) { if (mHandler.hasMessages(CALL_GO, Integer.valueOf(1))) { mHandler.removeMessages(CALL_GO, Integer.valueOf(1)); Intent launch = new Intent(this, LibraryActivity.class); launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); launch.setAction(Intent.ACTION_MAIN); startActivity(launch); } else { mHandler.sendMessageDelayed(mHandler.obtainMessage(CALL_GO, 1, 0, Integer.valueOf(1)), 400); } } else if (ACTION_PREVIOUS_SONG.equals(action)) { setCurrentSong(-1, false); userActionTriggered(); } else if (ACTION_REWIND_SONG.equals(action)) { /* only rewind song IF we played more than 2.5 sec (and song is longer than 5 sec) */ if (getPosition() > REWIND_AFTER_PLAYED_MS && getDuration() > REWIND_AFTER_PLAYED_MS * 2) { setCurrentSong(0, false); } else { setCurrentSong(-1, false); } play(); } else if (ACTION_PLAY.equals(action)) { play(); } else if (ACTION_PAUSE.equals(action)) { pause(); } else if (ACTION_CYCLE_REPEAT.equals(action)) { cycleFinishAction(); } else if (ACTION_CYCLE_SHUFFLE.equals(action)) { cycleShuffle(); } else if (ACTION_CLOSE_NOTIFICATION.equals(action)) { mForceNotificationVisible = false; pause(); stopForeground(true); // sometimes required to clear notification mNotificationManager.cancel(NOTIFICATION_ID); } MediaButtonReceiver.registerMediaButton(this); } return START_NOT_STICKY; }