List of usage examples for android.content Intent getLongExtra
public long getLongExtra(String name, long defaultValue)
From source file:com.nextgis.firereporter.GetFiresService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); if (intent == null) return START_REDELIVER_INTENT; int nCommnad = intent.getIntExtra(COMMAND, SERVICE_START); SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); long nUpdateInterval = prefs.getLong(SettingsActivity.KEY_PREF_INTERVAL + "_long", 30 * DateUtils.MINUTE_IN_MILLIS); //15 boolean bEnergyEconomy = prefs.getBoolean(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE, true); Log.d(MainActivity.TAG, "Received intent - id " + startId + ": " + intent + ", command:" + nCommnad); if ((nCommnad & SERVICE_START) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); if (mUserNasaReceiver != null) { mnFilter = intent.getIntExtra(SOURCE, MainActivity.SRC_NASA | MainActivity.SRC_USER); if (mnCurrentExec < 1) { mUserNasaReceiver.send(SERVICE_START, new Bundle()); }//w w w.j a v a 2 s . c o m Log.d(MainActivity.TAG, "GetFiresService service started"); if ((mnFilter & MainActivity.SRC_NASA) != 0) { mnCurrentExec++; GetNasaData(false); } if ((mnFilter & MainActivity.SRC_USER) != 0) { mnCurrentExec++; GetUserData(false); } } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_SCANEXSTART) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); if (mScanexReceiver != null) { if (mnCurrentExec < 1) { mScanexReceiver.send(SERVICE_SCANEXSTART, new Bundle()); } Log.d(MainActivity.TAG, "GetFiresService service started"); GetScanexData(false); } // plan next start ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } if ((nCommnad & SERVICE_STOP) != 0) { Log.d(MainActivity.TAG, "GetFiresService service stopped"); ScheduleNextUpdate(this, SERVICE_DESTROY, 150, true); stopSelf(); } if ((nCommnad & SERVICE_DESTROY) != 0) { stopSelf(); } if ((nCommnad & SERVICE_DATA) != 0) { mUserNasaReceiver = intent.getParcelableExtra(RECEIVER); for (FireItem item : mmoFires.values()) { SendItem(item); } } if ((nCommnad & SERVICE_SCANEXDATA) != 0) { mScanexReceiver = intent.getParcelableExtra(RECEIVER_SCANEX); for (ScanexSubscriptionItem Item : mmoSubscriptions.values()) { SendScanexItem(Item); } } if ((nCommnad & SERVICE_SCANEXDATAUPDATE) != 0) { long nSubscirbeId = intent.getLongExtra(SUBSCRIPTION_ID, -1); long nNotificationId = intent.getLongExtra(NOTIFICATION_ID, -1); ScanexSubscriptionItem subscribe = mmoSubscriptions.get(nSubscirbeId); if (subscribe != null) { ScanexNotificationItem notification = subscribe.GetItems().get(nNotificationId); if (notification != null) { notification.setWatched(true); } } } if ((nCommnad & SERVICE_NOTIFY_DISMISSED) != 0) { nUserCount = 0; nNasaCount = 0; nScanexCount = 0; mInboxStyle = new NotificationCompat.InboxStyle(); mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes)); ScheduleNextUpdate(this, SERVICE_START | SERVICE_SCANEXSTART, nUpdateInterval, bEnergyEconomy); } return START_REDELIVER_INTENT; }
From source file:org.cm.podd.report.activity.HomeActivity.java
@Override public void onNewIntent(Intent intent) { // handle intent result from notification Bundle extras = intent.getExtras();//w ww .ja va 2 s. com if (extras != null) { if (extras.containsKey("id")) { String title = extras.getString("title"); String content = extras.getString("content"); long id = extras.getLong("id"); displayWebViewContent(id, title, content); } } if (intent != null) { // Alert when register or login by code success Boolean registerSuccess = intent.getStringExtra("register") != null && intent.getStringExtra("register").equalsIgnoreCase("success"); Boolean forgetPasswordSuccess = intent.getStringExtra("forgetPassword") != null && intent.getStringExtra("forgetPassword").equalsIgnoreCase("success"); if (registerSuccess) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getString(R.string.title_activity_registration)); alertDialogBuilder.setMessage(getString(R.string.register_success) + "\n\n" + getString(R.string.username) + ": " + sharedPrefUtil.getUserName() + "\n" + getString(R.string.password) + ": " + sharedPrefUtil.getDisplayPassword() + "\n\n" + getString(R.string.register_warning_success) + "\n"); alertDialogBuilder.setPositiveButton(getString(R.string.start_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); alertDialogBuilder.show(); } else if (forgetPasswordSuccess) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(getString(R.string.login_title)); alertDialogBuilder.setMessage(getString(R.string.login_success) + "\n\n" + getString(R.string.username) + ": " + sharedPrefUtil.getUserName() + "\n" + getString(R.string.password) + ": " + sharedPrefUtil.getDisplayPassword() + "\n"); alertDialogBuilder.setPositiveButton(getString(R.string.start_app), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); alertDialogBuilder.show(); } else if (intent.getAction() != null && intent.getAction().equals(FollowAlertService.ORG_CM_PODD_REPORT_FOLLOW)) { Intent reportIntent = ReportActivity.followReportIntent(this, intent.getLongExtra("reportId", -99), intent.getLongExtra("reportType", 0)); reportIntent.putExtra("follow", intent.getBooleanExtra("follow", true)); intent.setAction(FollowAlertService.ORG_CM_PODD_REPORT_FOLLOW); startActivity(reportIntent); } } }
From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final FiretweetApplication app = FiretweetApplication.getInstance(this); mTwitterWrapper = app.getTwitterWrapper(); mResolver = getContentResolver();/* w w w. j av a2 s . c o m*/ mValidator = new FiretweetValidator(this); mImageLoader = app.getMediaLoaderWrapper(); setContentView(R.layout.activity_compose); // setSupportProgressBarIndeterminateVisibility(false); setFinishOnTouchOutside(false); final long[] defaultAccountIds = getAccountIds(this); if (defaultAccountIds.length <= 0) { final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN); intent.setClass(this, SignInActivity.class); startActivity(intent); finish(); return; } // mMenuBar.setIsBottomBar(true); mMenuBar.setOnMenuItemClickListener(this); mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null); mEditText.addTextChangedListener(this); mEditText.setCustomSelectionActionModeCallback(this); mAccountSelectorContainer.setOnClickListener(this); mAccountSelectorButton.setOnClickListener(this); mLocationContainer.setOnClickListener(this); final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setStackFromEnd(true); mAccountSelector.setLayoutManager(linearLayoutManager); mAccountSelector.addItemDecoration(new SpacingItemDecoration(this)); mAccountsAdapter = new AccountIconsAdapter(this); mAccountSelector.setAdapter(mAccountsAdapter); mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false)); mMediaPreviewAdapter = new MediaPreviewAdapter(this); mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter); final Intent intent = getIntent(); if (savedInstanceState != null) { // Restore from previous saved state mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS)); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState .getParcelableArrayList(EXTRA_MEDIA); if (mediaList != null) { addMedia(mediaList); } mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS); mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID); mMentionUser = savedInstanceState.getParcelable(EXTRA_USER); mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT); mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS); mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT); mTempPhotoUri = savedInstanceState.getParcelable(EXTRA_TEMP_URI); } else { // The context was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } if (!handleIntent(intent)) { handleDefaultIntent(intent); } final long[] accountIds = mAccountsAdapter.getSelectedAccountIds(); if (accountIds.length == 0) { final long[] idsInPrefs = FiretweetArrayUtils .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ','); final long[] intersection = FiretweetArrayUtils.intersection(idsInPrefs, defaultAccountIds); mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds); } mOriginalText = ParseUtils.parseString(mEditText.getText()); } if (!setComposeTitle(intent)) { setTitle(R.string.compose); } final Menu menu = mMenuBar.getMenu(); getMenuInflater().inflate(R.menu.menu_compose, menu); ThemeUtils.wrapMenuIcon(mMenuBar); mSendView.setOnClickListener(this); mSendView.setOnLongClickListener(this); final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE); addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION); final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu); if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) { addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION); } setMenu(); updateLocationState(); updateMediaPreview(); notifyAccountSelectionChanged(); }
From source file:mp.teardrop.LibraryActivity.java
/** * Called by LibraryAdapters when a row has been clicked. * * @param rowData The data for the row that was clicked. */// ww w . java2 s .c om public void onItemClicked(Intent rowData) { if (rowData == null) { return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_REQUEST_STORAGE_ACCESS, false)) { requestStorageAccess(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_LINK_WITH_DROPBOX, false)) { linkOrUnlink(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_GO_UP, false)) { //go to parent directory (local files or Dropbox) Limiter limiter = mPagerAdapter.getCurrentLimiter(); if (limiter.names.length > 1) { if (limiter.type == MediaUtils.TYPE_FILE) { File parentFile = ((File) limiter.data).getParentFile(); mPagerAdapter.setLimiter(FileSystemAdapter.buildLimiter(parentFile)); } else if (limiter.type == MediaUtils.TYPE_DROPBOX) { lockDropboxFileBrowser(); StringBuilder sb = new StringBuilder("/"); for (int i = 0; i < limiter.names.length - 1; i++) { sb.append(limiter.names[i]).append("/"); } mPagerAdapter.setLimiter(DropboxAdapter.buildLimiter(sb.toString())); } } else { if (limiter.type == MediaUtils.TYPE_DROPBOX) { lockDropboxFileBrowser(); } mPagerAdapter.clearLimiter(limiter.type); } updateLimiterViews(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_GO_TO_ALL_ARTISTS, false)) { mPagerAdapter.setLimiter(UnifiedAdapter.buildLimiterForMoreLink(UnifiedAdapter.ITEM_TYPE_MORE_ARTISTS, getResources().getString(R.string.artists))); updateLimiterViews(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_GO_TO_ALL_ALBUMS, false)) { mPagerAdapter.setLimiter(UnifiedAdapter.buildLimiterForMoreLink(UnifiedAdapter.ITEM_TYPE_MORE_ALBUMS, getResources().getString(R.string.albums))); updateLimiterViews(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_GO_TO_ALL_SONGS, false)) { mPagerAdapter.setLimiter(UnifiedAdapter.buildLimiterForMoreLink(UnifiedAdapter.ITEM_TYPE_MORE_SONGS, getResources().getString(R.string.songs))); updateLimiterViews(); return; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_GO_TO_ALL_PLAYLISTS, false)) { mPagerAdapter.setLimiter(UnifiedAdapter.buildLimiterForMoreLink(UnifiedAdapter.ITEM_TYPE_MORE_PLAYLISTS, getResources().getString(R.string.playlists))); updateLimiterViews(); return; } int action = mDefaultAction; if (action == ACTION_LAST_USED) { action = mLastAction; } if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) { onItemExpanded(rowData); } else if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == mLastActedId) { openPlaybackActivity(); } else if (action != ACTION_DO_NOTHING) { if (action == ACTION_EXPAND) { // default to playing when trying to expand something that can't be expanded action = ACTION_PLAY; } else if (action == ACTION_PLAY_OR_ENQUEUE) { action = (mState & PlaybackService.FLAG_PLAYING) == 0 ? ACTION_PLAY : ACTION_ENQUEUE; } pickSongs(rowData, action); } }
From source file:info.guardianproject.otr.app.im.app.NewChatActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent resultIntent) { if (resultCode == RESULT_OK) { if (requestCode == REQUEST_SEND_IMAGE || requestCode == REQUEST_SEND_FILE || requestCode == REQUEST_SEND_AUDIO) { Uri uri = resultIntent.getData(); if (uri == null) { return; }//from www.j a v a 2s . com boolean deleteAudioFile = (requestCode == REQUEST_SEND_AUDIO); handleSendDelete(uri, null, deleteAudioFile, false); } else if (requestCode == REQUEST_TAKE_PICTURE) { File file = new File(getRealPathFromURI(mLastPhoto)); final Handler handler = new Handler(); MediaScannerConnection.scanFile(this, new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, final Uri uri) { handler.post(new Runnable() { @Override public void run() { handleSendDelete(mLastPhoto, "image/*", true, true); } }); } }); } else if (requestCode == REQUEST_TAKE_PICTURE_SECURE) { String filename = resultIntent.getStringExtra(SecureCameraActivity.FILENAME); String mimeType = resultIntent.getStringExtra(SecureCameraActivity.MIMETYPE); Uri uri = Uri.parse("file:" + filename); handleSend(uri, mimeType); } else if (requestCode == REQUEST_SETTINGS) { try { mApp.getRemoteImService().updateStateFromSettings(); } catch (Exception e) { Log.e(ImApp.LOG_TAG, "unable to update service settings", e); } finish(); Intent intent = new Intent(getApplicationContext(), NewChatActivity.class); startActivity(intent); } else if (requestCode == REQUEST_PICK_CONTACTS || requestCode == REQUEST_ADD_CONTACT) { String username = resultIntent.getStringExtra(ContactsPickerActivity.EXTRA_RESULT_USERNAME); long providerId = resultIntent.getLongExtra(ContactsPickerActivity.EXTRA_RESULT_PROVIDER, -1); //String message = resultIntent.getStringExtra(ContactsPickerActivity.EXTRA_RESULT_MESSAGE); try { IChatSession chatSession = this.getCurrentChatSession(); if (chatSession != null && chatSession.isGroupChatSession()) { chatSession.inviteContact(username); showInvitationHasSent(username); } else { startChat(providerId, username, Imps.ContactsColumns.TYPE_NORMAL, true, null); } } catch (RemoteException e) { mHandler.showServiceErrorAlert("Error picking contacts"); Log.d(ImApp.LOG_TAG, "error picking contact", e); } } IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, resultIntent); if (scanResult != null) { String xmppUri = scanResult.getContents(); String result = null; if (xmppUri.startsWith("xmpp")) result = XmppUriHelper.getOtrFingerprint(xmppUri); if (getCurrentChatView() != null && result != null) getCurrentChatView().verifyScannedFingerprint(result); else { //add new contact? } } } }
From source file:com.koma.music.service.MusicService.java
private void handleCommandIntent(Intent intent) { final String action = intent.getAction(); final String command = MusicServiceConstants.SERVICECMD.equals(action) ? intent.getStringExtra(MusicServiceConstants.CMDNAME) : null;/*from w w w . j a v a2 s. co m*/ LogUtils.d(TAG, "handleCommandIntent: action = " + action + ", command = " + command); if (MusicServiceConstants.CMDNEXT.equals(command) || MusicServiceConstants.NEXT_ACTION.equals(action)) { gotoNext(true); } else if (MusicServiceConstants.CMDPREVIOUS.equals(command) || MusicServiceConstants.PREVIOUS_ACTION.equals(action) || MusicServiceConstants.PREVIOUS_FORCE_ACTION.equals(action)) { prev(MusicServiceConstants.PREVIOUS_FORCE_ACTION.equals(action)); } else if (MusicServiceConstants.CMDTOGGLEPAUSE.equals(command) || MusicServiceConstants.TOGGLEPAUSE_ACTION.equals(action)) { togglePlayPause(); } else if (MusicServiceConstants.CMDPAUSE.equals(command) || MusicServiceConstants.PAUSE_ACTION.equals(action)) { pause(); mPausedByTransientLossOfFocus = false; } else if (MusicServiceConstants.CMDPLAY.equals(command)) { play(); } else if (MusicServiceConstants.CMDSTOP.equals(command) || MusicServiceConstants.STOP_ACTION.equals(action)) { pause(); mPausedByTransientLossOfFocus = false; seek(0); releaseServiceUiAndStop(); } else if (MusicServiceConstants.REPEAT_ACTION.equals(action)) { cycleRepeat(); } else if (MusicServiceConstants.SHUFFLE_ACTION.equals(action)) { cycleShuffle(); } else if (MusicServiceConstants.CMDHEADSETHOOK.equals(command)) { long timestamp = intent.getLongExtra(MusicServiceConstants.TIMESTAMP, 0); handleHeadsetHookClick(timestamp); } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent);// w w w . j a v a 2 s. c o m Conversation conversation = null; mSentMessage = false; // If we have been passed a thread_id, use that to find our // conversation. // Note that originalThreadId might be zero but if this is a draft and we save the // draft, ensureThreadId gets called async from WorkingMessage.asyncUpdateDraftSmsMessage // the thread will get a threadId behind the UI thread's back. long originalThreadId = mConversation.getThreadId(); long threadId = intent.getLongExtra(THREAD_ID, 0); Uri intentUri = intent.getData(); boolean sameThread = false; if (threadId > 0) { conversation = Conversation.get(this, threadId, false); } else { if (mConversation.getThreadId() == 0) { // We've got a draft. Make sure the working recipients are synched // to the conversation so when we compare conversations later in this function, // the compare will work. mWorkingMessage.syncWorkingRecipients(); } // Get the "real" conversation based on the intentUri. The intentUri might specify // the conversation by a phone number or by a thread id. We'll typically get a threadId // based uri when the user pulls down a notification while in ComposeMessageActivity and // we end up here in onNewIntent. mConversation can have a threadId of zero when we're // working on a draft. When a new message comes in for that same recipient, a // conversation will get created behind CMA's back when the message is inserted into // the database and the corresponding entry made in the threads table. The code should // use the real conversation as soon as it can rather than finding out the threadId // when sending with "ensureThreadId". conversation = Conversation.get(this, intentUri, false); } if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("onNewIntent: data=" + intentUri + ", thread_id extra is " + threadId + ", new conversation=" + conversation + ", mConversation=" + mConversation); } // this is probably paranoid to compare both thread_ids and recipient lists, // but we want to make double sure because this is a last minute fix for Froyo // and the previous code checked thread ids only. // (we cannot just compare thread ids because there is a case where mConversation // has a stale/obsolete thread id (=1) that could collide against the new thread_id(=1), // even though the recipient lists are different) sameThread = ((conversation.getThreadId() == mConversation.getThreadId() || mConversation.getThreadId() == 0) && conversation.equals(mConversation)); if (sameThread) { log("onNewIntent: same conversation"); if (mConversation.getThreadId() == 0) { mConversation = conversation; mWorkingMessage.setConversation(mConversation); updateThreadIdIfRunning(); invalidateOptionsMenu(); } } else { if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("onNewIntent: different conversation"); } saveDraft(false); // if we've got a draft, save it first initialize(null, originalThreadId); } loadMessagesAndDraft(0); }
From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class); final TwidereApplication app = TwidereApplication.getInstance(this); mTwitterWrapper = app.getTwitterWrapper(); mResolver = getContentResolver();/*w w w . ja v a2s . c o m*/ mValidator = new TwidereValidator(this); mImageLoader = app.getMediaLoaderWrapper(); setContentView(R.layout.activity_compose); setFinishOnTouchOutside(false); final long[] defaultAccountIds = Utils.getAccountIds(this); if (defaultAccountIds.length <= 0) { final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN); intent.setClass(this, SignInActivity.class); startActivity(intent); finish(); return; } mMenuBar.setOnMenuItemClickListener(this); setupEditText(); mAccountSelectorContainer.setOnClickListener(this); mAccountSelectorButton.setOnClickListener(this); mLocationContainer.setOnClickListener(this); final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setStackFromEnd(true); mAccountSelector.setLayoutManager(linearLayoutManager); mAccountSelector.addItemDecoration(new SpacingItemDecoration(this)); mAccountSelector.setItemAnimator(new RecyclerView.ItemAnimator() { @Override public void runPendingAnimations() { } @Override public boolean animateRemove(ViewHolder holder) { return false; } @Override public boolean animateAdd(ViewHolder holder) { return false; } @Override public boolean animateMove(ViewHolder holder, int fromX, int fromY, int toX, int toY) { Log.d(LOGTAG, String.format("animateMove")); return false; } @Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromLeft, int fromTop, int toLeft, int toTop) { Log.d(LOGTAG, String.format("animateChange")); return false; } @Override public void endAnimation(ViewHolder item) { Log.d(LOGTAG, String.format("endAnimation")); } @Override public void endAnimations() { } @Override public boolean isRunning() { return false; } }); mAccountsAdapter = new AccountIconsAdapter(this); mAccountSelector.setAdapter(mAccountsAdapter); mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false)); mMediaPreviewAdapter = new MediaPreviewAdapter(this); mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter); final Intent intent = getIntent(); if (savedInstanceState != null) { // Restore from previous saved state mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS)); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState .getParcelableArrayList(EXTRA_MEDIA); if (mediaList != null) { addMedia(mediaList); } mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS); mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID); mMentionUser = savedInstanceState.getParcelable(EXTRA_USER); mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT); mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS); mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT); } else { // The context was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } if (!handleIntent(intent)) { handleDefaultIntent(intent); } final long[] accountIds = mAccountsAdapter.getSelectedAccountIds(); if (accountIds.length == 0) { final long[] idsInPrefs = TwidereArrayUtils .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ','); final long[] intersection = TwidereArrayUtils.intersection(idsInPrefs, defaultAccountIds); mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds); } mOriginalText = ParseUtils.parseString(mEditText.getText()); } if (!setComposeTitle(intent)) { setTitle(R.string.compose); } final Menu menu = mMenuBar.getMenu(); getMenuInflater().inflate(R.menu.menu_compose, menu); ThemeUtils.wrapMenuIcon(mMenuBar); mSendView.setOnClickListener(this); mSendView.setOnLongClickListener(this); final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE); Utils.addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION); final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu); if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) { Utils.addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION); } setMenu(); updateLocationState(); updateMediaPreview(); notifyAccountSelectionChanged(); mTextChanged = false; }
From source file:com.android.launcher3.Launcher.java
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); return false; }/*w w w . j a v a 2 s .c o m*/ // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; UserHandleCompat user = null; if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); user = UserManagerCompat.getInstance(this).getUserForSerialNumber(serialNumber); } // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (v != null) { intent.setSourceBounds(getViewBounds(v)); } try { if (Utilities.ATLEAST_MARSHMALLOW && item != null && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && ((ShortcutInfo) item).promisedIntent == null) { // Shortcuts need some special checks due to legacy reasons. startShortcutIntentSafely(intent, optsBundle, item); } else if (user == null || user.equals(UserHandleCompat.myUserHandle())) { // Could be launching some bookkeeping activity startActivity(intent, optsBundle); if (isAllAppsVisible()) { predictiveAppsProvider.updateComponentCount(intent.getComponent()); } } else { LauncherAppsCompat.getInstance(this).startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (ActivityNotFoundException | SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); } return false; }
From source file:com.cognizant.trumobi.PersonaLauncher.java
private void completeEditShirtcut(Intent data) { if (!data.hasExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO)) return;/*from w w w . j a va 2 s . c o m*/ long appInfoId = data.getLongExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO, 0); PersonaApplicationInfo info = PersonaLauncherModel.loadApplicationInfoById(this, appInfoId); if (info != null) { Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON); Drawable icon = null; boolean customIcon = false; ShortcutIconResource iconResource = null; if (bitmap != null) { icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, this)); customIcon = true; } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra != null && extra instanceof ShortcutIconResource) { try { iconResource = (ShortcutIconResource) extra; final PackageManager packageManager = getPackageManager(); Resources resources = packageManager.getResourcesForApplication(iconResource.packageName); final int id = resources.getIdentifier(iconResource.resourceName, null, null); icon = resources.getDrawable(id); } catch (Exception e) { PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra); } } } if (icon != null) { info.icon = icon; info.customIcon = customIcon; info.iconResource = iconResource; } info.itemType = PersonaLauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; info.title = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); info.intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); PersonaLauncherModel.updateItemInDatabase(this, info); if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_MAB) mHandleView.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB) mLAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB2) mLAB2.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB) mRAB.UpdateLaunchInfo(info); else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB2) mRAB2.UpdateLaunchInfo(info); mWorkspace.updateShortcutFromApplicationInfo(info); } }