Example usage for android.content Intent getLongExtra

List of usage examples for android.content Intent getLongExtra

Introduction

In this page you can find the example usage for android.content Intent getLongExtra.

Prototype

public long getLongExtra(String name, long defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.notifry.android.SourceEditor.java

/**
 * Fetch the account that this source list is for.
 * /*w  w  w .j a  v a 2 s .  c om*/
 * @return
 */
public NotifrySource getSource() {
    if (this.source == null) {
        // Get the source from the intent.
        // We store it in a private variable to save us having to query the
        // DB each time.
        Intent sourceIntent = getIntent();
        this.source = NotifrySource.FACTORY.get(this, sourceIntent.getLongExtra("sourceId", 0));
    }

    return this.source;
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipeEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*/* w  w  w.  j av a  2  s.  c om*/
     * Creates an Intent to use when the Activity object's result is sent back to the
     * caller.
     */
    final Intent intent = getIntent();

    if (intent.getBooleanExtra(RecipeEditor.NEW_RECIPE, true)) {
        id = null;
        mState = STATE_INSERT;
    } else {

        mState = STATE_EDIT;
        id = intent.getLongExtra(RecipeEditor.RECIPE_ID, 0L);
    }

    // Sets the layout for this Activity. See res/layout/recipe_editor.xml
    setContentView(R.layout.recipe_editor);

    // Gets a handle to the EditText in the the layout.
    mText = (EditText) findViewById(R.id.recipe);

    title = (EditText) findViewById(R.id.title);

    typeSpinner = (Spinner) this.findViewById(R.id.spinner1);

    // Step 2: Create and fill an ArrayAdapter with a bunch of "State" objects
    ArrayAdapter<DishType> spinnerArrayAdapter = new ArrayAdapter<DishType>(this,
            android.R.layout.simple_spinner_item,
            new DishType[] { DishType.ENTREE, DishType.MAIN_DISH, DishType.DESSERT });

    // Step 3: Tell the spinner about our adapter
    typeSpinner.setAdapter(spinnerArrayAdapter);

    /*
     * If this Activity had stopped previously, its state was written the ORIGINAL_CONTENT
     * location in the saved Instance state. This gets the state.
     */
    if (savedInstanceState != null) {
        mOriginalContent = savedInstanceState.getString(ORIGINAL_CONTENT);
    }
}

From source file:com.example.evan.comp296.profile.MainActivity_Profile.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_profile);

    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();/*  ww  w.j av  a  2  s.  c  o m*/

    // Click listeners
    findViewById(R.id.button_camera).setOnClickListener(this);
    findViewById(R.id.button_sign_in).setOnClickListener(this);
    findViewById(R.id.button_download).setOnClickListener(this);
    findViewById(R.id.button_cancel).setOnClickListener(this);

    // Restore instance state
    if (savedInstanceState != null) {
        mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI);
        mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL);
    }
    onNewIntent(getIntent());

    // Local broadcast receiver
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive:" + intent);
            hideProgressDialog();

            switch (intent.getAction()) {
            case MyDownloadService.DOWNLOAD_COMPLETED:
                // Get number of bytes downloaded
                long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0);

                // Alert success
                showMessageDialog(getString(R.string.success),
                        String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes,
                                intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH)));
                break;
            case MyDownloadService.DOWNLOAD_ERROR:
                // Alert failure
                showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s",
                        intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH)));
                break;
            case MyUploadService.UPLOAD_COMPLETED:
            case MyUploadService.UPLOAD_ERROR:
                try {
                    onUploadResultIntent(intent);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            }
        }
    };
}

From source file:org.getlantern.firetweet.activity.support.MediaViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mActionBar = getSupportActionBar();/*from   w  w  w. j  av  a 2 s  .c o m*/
    mActionBar.setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.activity_media_viewer);
    mAdapter = new MediaPagerAdapter(this);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.element_spacing_normal));
    mViewPager.setOnPageChangeListener(this);
    final Intent intent = getIntent();
    final long accountId = intent.getLongExtra(EXTRA_ACCOUNT_ID, -1);
    final ParcelableMedia[] media = Utils.newParcelableArray(intent.getParcelableArrayExtra(EXTRA_MEDIA),
            ParcelableMedia.CREATOR);
    final ParcelableMedia currentMedia = intent.getParcelableExtra(EXTRA_CURRENT_MEDIA);
    mAdapter.setMedia(accountId, media);
    final int currentIndex = ArrayUtils.indexOf(media, currentMedia);
    if (currentIndex != -1) {
        mViewPager.setCurrentItem(currentIndex, false);
    }
    if (intent.hasExtra(EXTRA_STATUS)) {
        mMediaStatusContainer.setVisibility(View.VISIBLE);
        final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        final Fragment f = new ViewStatusDialogFragment();
        final Bundle args = new Bundle();
        args.putParcelable(EXTRA_STATUS, intent.getParcelableExtra(EXTRA_STATUS));
        args.putBoolean(EXTRA_SHOW_MEDIA_PREVIEW, false);
        args.putBoolean(EXTRA_SHOW_EXTRA_TYPE, false);
        f.setArguments(args);
        ft.replace(R.id.media_status, f);
        ft.commit();
    } else {
        mMediaStatusContainer.setVisibility(View.GONE);
    }
}

From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java

private void init() {
    Intent intent = getIntent();

    // get intent extras
    currentMediaId = intent.getLongExtra(Globals.EXTRA_CURRENT_MEDIA_ID, -1);

    // get default metadata sharing values
    SharedPreferences sharedPref = this.getSharedPreferences(Globals.PREF_FILE_KEY, Context.MODE_PRIVATE);

    // check for new file or existing media
    if (currentMediaId >= 0) {
        mMedia = Media.findById(Media.class, currentMediaId);
    } else {/*from  w  w  w  . ja v a  2s . c o m*/
        Utility.toastOnUiThread(this, getString(R.string.error_no_media));
        finish();
        return;
    }

    if (mMedia.getMimeType().startsWith("image")) {

        mPicasso.load(Uri.parse(mMedia.getOriginalFilePath())).fit().centerCrop().into(ivMedia);
    } else if (mMedia.getMimeType().startsWith("video")) {

        mPicasso.load(VideoRequestHandler.SCHEME_VIDEO + ":" + mMedia.getOriginalFilePath()).fit().centerCrop()
                .into(ivMedia);
    } else if (mMedia.getMimeType().startsWith("audio")) {
        ivMedia.setImageDrawable(getResources().getDrawable(R.drawable.audio_waveform));

        SoundFile soundFile = MediaViewHolder.mSoundFileCache.get(mMedia.getOriginalFilePath());
        if (soundFile != null) {
            swMedia.setAudioFile(soundFile);
            swMedia.setVisibility(View.VISIBLE);
            ivMedia.setVisibility(View.GONE);
        }
    } else
        ivMedia.setImageDrawable(getResources().getDrawable(R.drawable.no_thumbnail));

    swMedia.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showMedia();
        }
    });

    ivMedia.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showMedia();
        }
    });
}

From source file:nazmul.storagesampletest.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ImageView imageView = (ImageView) findViewById(R.id.imageTest);
    camera = (ImageView) findViewById(R.id.cameraPhoto);

    Glide.with(this).load(
            "https://firebasestorage.googleapis.com/v0/b/fir-demo-375a1.appspot.com/o/photos%2Fimage%3A51?alt=media&token=b6c6863a-5225-48ca-9d36-4b7efdcbae98")
            .into(imageView);// w w w  .  ja  v a  2s  .co m

    // Initialize Firebase Auth
    mAuth = FirebaseAuth.getInstance();
    mDatabase = FirebaseDatabase.getInstance().getReference();

    // Click listeners
    findViewById(R.id.button_camera).setOnClickListener(this);
    findViewById(R.id.button_sign_in).setOnClickListener(this);
    findViewById(R.id.button_download).setOnClickListener(this);

    // Restore instance state
    if (savedInstanceState != null) {
        mFileUri = savedInstanceState.getParcelable(KEY_FILE_URI);
        mDownloadUrl = savedInstanceState.getParcelable(KEY_DOWNLOAD_URL);
    }
    onNewIntent(getIntent());

    // Local broadcast receiver
    mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive:" + intent);
            hideProgressDialog();

            switch (intent.getAction()) {
            case MyDownloadService.DOWNLOAD_COMPLETED:
                // Get number of bytes downloaded
                long numBytes = intent.getLongExtra(MyDownloadService.EXTRA_BYTES_DOWNLOADED, 0);

                // Alert success
                showMessageDialog(getString(R.string.success),
                        String.format(Locale.getDefault(), "%d bytes downloaded from %s", numBytes,
                                intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH)));
                break;
            case MyDownloadService.DOWNLOAD_ERROR:
                // Alert failure
                showMessageDialog("Error", String.format(Locale.getDefault(), "Failed to download from %s",
                        intent.getStringExtra(MyDownloadService.EXTRA_DOWNLOAD_PATH)));
                break;
            case MyUploadService.UPLOAD_COMPLETED:
            case MyUploadService.UPLOAD_ERROR:
                onUploadResultIntent(intent);
                break;
            }
        }
    };
}

From source file:com.keylesspalace.tusky.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    int tabPosition = 0;

    if (intent != null) {
        long accountId = intent.getLongExtra(NotificationHelper.ACCOUNT_ID, -1);

        if (accountId != -1) {
            // user clicked a notification, show notification tab and switch user if necessary
            tabPosition = 1;//w ww .j  av a 2s . c om
            AccountEntity account = accountManager.getActiveAccount();

            if (account == null || accountId != account.getId()) {
                accountManager.setActiveAccount(accountId);
            }
        }
    }

    setContentView(R.layout.activity_main);

    composeButton = findViewById(R.id.floating_btn);
    ImageButton drawerToggle = findViewById(R.id.drawer_toggle);
    TabLayout tabLayout = findViewById(R.id.tab_layout);
    viewPager = findViewById(R.id.pager);

    composeButton.setOnClickListener(v -> {
        Intent composeIntent = new Intent(getApplicationContext(), ComposeActivity.class);
        startActivity(composeIntent);
    });

    setupDrawer();

    // Setup the navigation drawer toggle button.
    ThemeUtils.setDrawableTint(this, drawerToggle.getDrawable(), R.attr.toolbar_icon_tint);
    drawerToggle.setOnClickListener(v -> drawer.openDrawer());

    /* Fetch user info while we're doing other things. This has to be done after setting up the
     * drawer, though, because its callback touches the header in the drawer. */
    fetchUserInfo();

    // Setup the tabs and timeline pager.
    TimelinePagerAdapter adapter = new TimelinePagerAdapter(getSupportFragmentManager());

    int pageMargin = getResources().getDimensionPixelSize(R.dimen.tab_page_margin);
    viewPager.setPageMargin(pageMargin);
    Drawable pageMarginDrawable = ThemeUtils.getDrawable(this, R.attr.tab_page_margin_drawable,
            R.drawable.tab_page_margin_dark);
    viewPager.setPageMarginDrawable(pageMarginDrawable);
    viewPager.setAdapter(adapter);

    tabLayout.setupWithViewPager(viewPager);

    int[] tabIcons = { R.drawable.ic_home_24dp, R.drawable.ic_notifications_24dp, R.drawable.ic_local_24dp,
            R.drawable.ic_public_24dp, };
    String[] pageTitles = { getString(R.string.title_home), getString(R.string.title_notifications),
            getString(R.string.title_public_local), getString(R.string.title_public_federated), };
    for (int i = 0; i < 4; i++) {
        TabLayout.Tab tab = tabLayout.getTabAt(i);
        tab.setIcon(tabIcons[i]);
        tab.setContentDescription(pageTitles[i]);
    }

    if (tabPosition != 0) {
        TabLayout.Tab tab = tabLayout.getTabAt(tabPosition);
        if (tab != null) {
            tab.select();
        } else {
            tabPosition = 0;
        }
    }

    tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());

            tintTab(tab, true);

            if (tab.getPosition() == 1) {
                NotificationHelper.clearNotificationsForActiveAccount(MainActivity.this, accountManager);
            }
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            tintTab(tab, false);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });

    for (int i = 0; i < 4; i++) {
        tintTab(tabLayout.getTabAt(i), i == tabPosition);
    }

    // Setup push notifications
    if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {
        enablePushNotifications();
    } else {
        disablePushNotifications();
    }

    eventHub.getEvents().observeOn(AndroidSchedulers.mainThread())
            .as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe(event -> {
                if (event instanceof ProfileEditedEvent) {
                    onFetchUserInfoSuccess(((ProfileEditedEvent) event).getNewProfileData());
                }
            });

}

From source file:net.xisberto.phonetodesktop.network.GoogleTasksService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        Utils.log("onHandleIntent " + intent.getAction());
        long[] tasks_ids;
        try {//ww w  . j  a  v  a2  s .c  om
            if (action.equals(Utils.ACTION_PROCESS_TASK)) {
                long task_id = intent.getLongExtra(Utils.EXTRA_TASK_ID, -1);
                LocalTask task = DatabaseHelper.getInstance(this).getTask(task_id);
                final Intent result = new Intent(Utils.ACTION_RESULT_PROCESS_TASK);
                result.putExtra(Utils.EXTRA_TASK_ID, task.getLocalId());
                if (isOnline()) {
                    processOptions(task);
                    task.persistBlocking(new PersistCallback() {
                        @Override
                        public void run() {
                            if (cache_unshorten != null) {
                                result.putExtra(Utils.EXTRA_CACHE_UNSHORTEN, cache_unshorten);
                            }
                            if (cache_titles != null) {
                                result.putExtra(Utils.EXTRA_CACHE_TITLES, cache_titles);
                            }
                            LocalBroadcastManager.getInstance(GoogleTasksService.this).sendBroadcast(result);
                        }
                    });
                } else {
                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                    revertTaskToReady(tasks_ids);
                    LocalBroadcastManager.getInstance(this).sendBroadcast(result);
                }
            } else if (action.equals(Utils.ACTION_SEND_TASKS)) {
                if (isOnline()) {

                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);

                    if (tasks_ids.length == 1) {
                        DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this);
                        LocalTask task = databaseHelper.getTask(tasks_ids[0]);
                        handleActionSend(task);
                    } else {
                        handleActionSendMultiple(tasks_ids);
                    }

                    stopForeground(true);
                } else {
                    tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                    revertTaskToReady(tasks_ids);
                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(
                            NOTIFICATION_SEND_LATER, buildNotification(NOTIFICATION_SEND_LATER).build());
                }
            } else if (action.equals(Utils.ACTION_LIST_TASKS)) {
                handleActionList();
            } else if (action.equals(Utils.ACTION_REMOVE_TASKS)) {
                handleActionRemove(intent.getStringArrayListExtra(Utils.EXTRA_TASKS_IDS));
            }
        } catch (UserRecoverableAuthIOException userRecoverableException) {
            Utils.log(Log.getStackTraceString(userRecoverableException));
            stopForeground(true);
            tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
            revertTaskToReady(tasks_ids);
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_NEED_AUTHORIZE,
                    buildNotification(NOTIFICATION_NEED_AUTHORIZE).build());
        } catch (IOException ioException) {
            Utils.log(Log.getStackTraceString(ioException));
            if (action.equals(Utils.ACTION_SEND_TASKS)) {
                tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
                stopForeground(true);
                revertTaskToReady(tasks_ids);
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ERROR,
                        buildNotification(NOTIFICATION_ERROR).build());
            } else {
                Intent broadcast = new Intent(Utils.ACTION_LIST_TASKS);
                broadcast.putExtra(Utils.EXTRA_ERROR_TEXT, getString(R.string.txt_error_list));
                LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
            }
        } catch (NullPointerException npe) {
            tasks_ids = intent.getLongArrayExtra(Utils.EXTRA_TASKS_IDS);
            Utils.log(Log.getStackTraceString(npe));
            stopForeground(true);
            revertTaskToReady(tasks_ids);
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_NEED_AUTHORIZE,
                    buildNotification(NOTIFICATION_NEED_AUTHORIZE).build());
        }
    }
}

From source file:io.plaidapp.ui.PlayerActivity.java

@Override
public void onActivityReenter(int resultCode, Intent data) {
    if (data == null || resultCode != RESULT_OK || !data.hasExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID))
        return;//from w ww .  j  a v  a  2 s  .c om

    // When reentering, if the shared element is no longer on screen (e.g. after an
    // orientation change) then scroll it into view.
    final long sharedShotId = data.getLongExtra(DribbbleShot.RESULT_EXTRA_SHOT_ID, -1L);
    if (sharedShotId != -1L // returning from a shot
            && adapter.getDataItemCount() > 0 // grid populated
            && shots.findViewHolderForItemId(sharedShotId) == null) { // view not attached
        final int position = adapter.getItemPosition(sharedShotId);
        if (position == RecyclerView.NO_POSITION)
            return;

        // delay the transition until our shared element is on-screen i.e. has been laid out
        postponeEnterTransition();
        shots.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
            @Override
            public void onLayoutChange(View v, int l, int t, int r, int b, int oL, int oT, int oR, int oB) {
                shots.removeOnLayoutChangeListener(this);
                startPostponedEnterTransition();
            }
        });
        shots.scrollToPosition(position);
    }
}