Example usage for android.os Bundle putLong

List of usage examples for android.os Bundle putLong

Introduction

In this page you can find the example usage for android.os Bundle putLong.

Prototype

public void putLong(@Nullable String key, long value) 

Source Link

Document

Inserts a long value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.nononsenseapps.notepad.MainActivity.java

/**
 * Creates an editor fragment for the note specified in the intent. Use for
 * edit and complete intents./*ww  w.  j a v  a  2  s.c o  m*/
 * 
 * @param intent
 */
private void openNoteFragment(Intent intent) {
    Log.d(TAG, "openNoteFragment");
    Bundle arguments = new Bundle();
    arguments.putLong(NotesEditorFragment.KEYID, NotesEditorFragment.getIdFromUri(intent.getData()));
    NotesEditorFragment fragment = new NotesEditorFragment();
    fragment.setArguments(arguments);
    getFragmentManager().beginTransaction().replace(R.id.rightFragment, fragment).commit();
    // Open appropriate list if tablet mode
    if (this.currentContent == CONTENTVIEW.DUAL) {
        long listId = getAList(intent);
        /*
         * Open the containing list if we have to. No need to change lists
         * if we are already displaying all notes.
         */
        openListFromIntent(listId, intent);
    }
}

From source file:com.nononsenseapps.notepad.MainActivity.java

@Override
public void onItemSelected(long id) {
    Log.d(TAG, "onItemSelected: " + id);
    // Open a note
    if (id > -1) {
        if (getCurrentContent().equals(DualLayoutActivity.CONTENTVIEW.DUAL)) {
            Bundle arguments = new Bundle();
            arguments.putLong(NotesEditorFragment.KEYID, id);
            NotesEditorFragment fragment = new NotesEditorFragment();
            fragment.setArguments(arguments);
            getFragmentManager().beginTransaction().replace(R.id.rightFragment, fragment)
                    .commitAllowingStateLoss();
        } else {/*from w w  w. j  a  va 2s  .c o m*/
            Intent intent = new Intent();
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setClass(this, RightActivity.class)
                    .setData(Uri.withAppendedPath(NotePad.Notes.CONTENT_VISIBLE_ID_URI_BASE, Long.toString(id)))
                    .setAction(Intent.ACTION_EDIT);

            startActivity(intent);
        }
    }
}

From source file:com.nononsenseapps.notepad.MainActivity.java

private void handleInsertIntent(Intent intent) {
    if (intent.getType() != null && intent.getType().equals(NotePad.Lists.CONTENT_TYPE)
            || intent.getData() != null && intent.getData().equals(NotePad.Lists.CONTENT_VISIBLE_URI)) {
        // get Title
        if (intent.getExtras() != null) {
            String title = intent.getExtras().getString(NotePad.Lists.COLUMN_NAME_TITLE, "");
            createList(title);// w ww. jav  a2s  .  c om
        }
    } else if (intent.getType() != null
            && (intent.getType().equals(NotePad.Notes.CONTENT_TYPE) || intent.getType().startsWith("text/"))
            || intent.getData() != null && intent.getData().equals(NotePad.Notes.CONTENT_VISIBLE_URI)) {
        Log.d("FragmentLayout", "INSERT NOTE");
        // Get list to create note in first
        long listId = getAList(intent);
        String text = "";
        if (intent.getExtras() != null) {
            text = intent.getExtras().getCharSequence(Intent.EXTRA_TEXT, "").toString();
        }

        if (listId > -1) {
            Uri noteUri = MainActivity.createNote(this, listId, text);

            if (noteUri != null) {
                Bundle arguments = new Bundle();
                arguments.putLong(NotesEditorFragment.KEYID, NotesEditorFragment.getIdFromUri(noteUri));
                NotesEditorFragment fragment = new NotesEditorFragment();
                fragment.setArguments(arguments);
                getFragmentManager().beginTransaction().replace(R.id.rightFragment, fragment).commit();
            }

            // Open appropriate list if tablet mode
            if (this.currentContent == CONTENTVIEW.DUAL) {
                // Open the containing list if we have to. No need to
                // change
                // lists
                // if we are already displaying all notes.
                openListFromIntent(listId, intent);
            }
        }
    }
}

From source file:com.nononsenseapps.notepad.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    // Search/*from   w w  w  . java 2s  . com*/
    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        // list.onQueryTextChange(query);
        NotesListFragment list = getLeftFragment();
        if (list != null && list.mSearchView != null) {
            list.mSearchView.setQuery(query, false);
        } else if (list != null) {
            list.onQueryTextSubmit(query);
        }
        // Edit or View a list or a note.
    } else if (Intent.ACTION_EDIT.equals(intent.getAction()) || Intent.ACTION_VIEW.equals(intent.getAction())) {
        handleEditIntent(intent);
    } else if (Intent.ACTION_INSERT.equals(intent.getAction())) {
        handleInsertIntent(intent);
    } else if (Intent.ACTION_SEND.equals(intent.getAction())) {
        handleInsertIntent(intent);
    } else if (getString(R.string.complete_note_broadcast_intent).equals(intent.getAction())) {
        // Sent from lock-screen widget on 4.2 and above.
        // Send complete broadcast and finish
        long noteId = NotesEditorFragment.getIdFromUri(intent.getData());
        // This will complete the note
        if (noteId > -1) {
            Intent bintent = new Intent(this, NotePadBroadcastReceiver.class);
            bintent.setAction(getString(R.string.complete_note_broadcast_intent));
            bintent.putExtra(NotePad.Notes._ID, noteId);
            Log.d(TAG, "Sending complete broadcast");
            sendBroadcast(bintent);

            openNoteFragment(intent);

            // Toast.makeText(this, getString(R.string.completed),
            // Toast.LENGTH_SHORT).show();
        }
    } else {
        // Open a note
        if (noteIdToSelect > -1 && currentContent == CONTENTVIEW.DUAL) {
            Bundle arguments = new Bundle();
            arguments.putLong(NotesEditorFragment.KEYID, noteIdToSelect);
            NotesEditorFragment fragment = new NotesEditorFragment();
            fragment.setArguments(arguments);
            getFragmentManager().beginTransaction().replace(R.id.rightFragment, fragment).commit();
            noteIdToSelect = -1;
        }
    }
}

From source file:com.synox.android.ui.activity.FileActivity.java

/**
 * {@inheritDoc}// www .j  a va 2 s. c  o  m
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putParcelable(FileActivity.EXTRA_FILE, mFile);
    outState.putBoolean(FileActivity.EXTRA_FROM_NOTIFICATION, mFromNotification);
    outState.putLong(KEY_WAITING_FOR_OP_ID, mFileOperationsHelper.getOpIdWaitingFor());
    if (getSupportActionBar() != null && getSupportActionBar().getTitle() != null) {
        // Null check in case the actionbar is used in ActionBar.NAVIGATION_MODE_LIST
        // since it doesn't have a title then
        outState.putString(KEY_ACTION_BAR_TITLE, getSupportActionBar().getTitle().toString());
    }
    super.onSaveInstanceState(outState);
}

From source file:com.android.messaging.datamodel.action.SyncMessagesAction.java

@Override
protected Bundle doBackgroundWork() {
    final BugleGservices bugleGservices = BugleGservices.get();
    final DatabaseWrapper db = DataModel.get().getDatabase();

    final int maxMessagesToScan = bugleGservices.getInt(BugleGservicesKeys.SMS_SYNC_BATCH_MAX_MESSAGES_TO_SCAN,
            BugleGservicesKeys.SMS_SYNC_BATCH_MAX_MESSAGES_TO_SCAN_DEFAULT);

    final int initialMaxMessagesToUpdate = actionParameters.getInt(KEY_MAX_UPDATE);
    final int smsSyncSubsequentBatchSizeMin = bugleGservices.getInt(BugleGservicesKeys.SMS_SYNC_BATCH_SIZE_MIN,
            BugleGservicesKeys.SMS_SYNC_BATCH_SIZE_MIN_DEFAULT);
    final int smsSyncSubsequentBatchSizeMax = bugleGservices.getInt(BugleGservicesKeys.SMS_SYNC_BATCH_SIZE_MAX,
            BugleGservicesKeys.SMS_SYNC_BATCH_SIZE_MAX_DEFAULT);

    // Cap sync size to GServices limits
    final int maxMessagesToUpdate = Math.max(smsSyncSubsequentBatchSizeMin,
            Math.min(initialMaxMessagesToUpdate, smsSyncSubsequentBatchSizeMax));

    final long lowerBoundTimeMillis = actionParameters.getLong(KEY_LOWER_BOUND);
    final long upperBoundTimeMillis = actionParameters.getLong(KEY_UPPER_BOUND);

    LogUtil.i(TAG,//from  w ww  .j  a va 2  s. c o  m
            "SyncMessagesAction: Starting batch for messages from " + lowerBoundTimeMillis + " to "
                    + upperBoundTimeMillis + " (message update limit = " + maxMessagesToUpdate
                    + ", message scan limit = " + maxMessagesToScan + ")");

    // Clear last change time so that we can work out if this batch is dirty when it completes
    final SyncManager syncManager = DataModel.get().getSyncManager();

    // Clear the singleton cache that maps threads to recipients and to conversations.
    final SyncManager.ThreadInfoCache cache = syncManager.getThreadInfoCache();
    cache.clear();

    // Sms messages to store
    final ArrayList<SmsMessage> smsToAdd = new ArrayList<SmsMessage>();
    // Mms messages to store
    final LongSparseArray<MmsMessage> mmsToAdd = new LongSparseArray<MmsMessage>();
    // List of local SMS/MMS to remove
    final ArrayList<LocalDatabaseMessage> messagesToDelete = new ArrayList<LocalDatabaseMessage>();

    long lastTimestampMillis = SYNC_FAILED;
    if (syncManager.isSyncing(upperBoundTimeMillis)) {
        // Cursors
        final SyncCursorPair cursors = new SyncCursorPair(lowerBoundTimeMillis, upperBoundTimeMillis);

        // Actually compare the messages using cursor pair
        lastTimestampMillis = syncCursorPair(db, cursors, smsToAdd, mmsToAdd, messagesToDelete,
                maxMessagesToScan, maxMessagesToUpdate, cache);
    }
    final Bundle response = new Bundle();

    // If comparison succeeds bundle up the changes for processing in ActionService
    if (lastTimestampMillis > SYNC_FAILED) {
        final ArrayList<MmsMessage> mmsToAddList = new ArrayList<MmsMessage>();
        for (int i = 0; i < mmsToAdd.size(); i++) {
            final MmsMessage mms = mmsToAdd.valueAt(i);
            mmsToAddList.add(mms);
        }

        response.putParcelableArrayList(BUNDLE_KEY_SMS_MESSAGES, smsToAdd);
        response.putParcelableArrayList(BUNDLE_KEY_MMS_MESSAGES, mmsToAddList);
        response.putParcelableArrayList(BUNDLE_KEY_MESSAGES_TO_DELETE, messagesToDelete);
    }
    response.putLong(BUNDLE_KEY_LAST_TIMESTAMP, lastTimestampMillis);

    return response;
}

From source file:com.koma.music.detail.DetailsActivity.java

public void init() {
    if (getIntent() != null) {
        mWhichPage = getIntent().getIntExtra(Constants.WHICH_DETAIL_PAGE, Constants.ALBUM_DETAIL);
    }/*from w  w w  .ja  v a  2s .com*/

    setSupportActionBar(mToolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mToolbar.post(new Runnable() {
        @Override
        public void run() {
            Animation animation = AnimationUtils.loadAnimation(DetailsActivity.this, R.anim.toolbar_slide_in);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    mToolbar.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animation animation) {

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            mToolbar.startAnimation(animation);
        }
    });

    QuickControlFragment quickControlFragment = (QuickControlFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_playback_controls);

    new QuickControlPresenter(quickControlFragment);

    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.container);

    if (fragment != null) {
        return;
    }

    Bundle bundle;

    switch (mWhichPage) {

    case Constants.RECENTLY_ADDED:
        mTitle = getResources().getString(R.string.recently_add);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new RecentlyAddedFragment();
        break;
    case Constants.RECENTLY_PLAYED:
        mTitle = getResources().getString(R.string.recently_play);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new RecentlyPlayFragment();
        break;
    case Constants.MY_FAVORITE:
        mTitle = getResources().getString(R.string.my_favorite);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new MyFavoriteFragment();
        break;
    case Constants.ALBUM_DETAIL:
        mTargetId = getIntent().getLongExtra(Constants.ALBUM_ID, -1);
        mTitle = getIntent().getStringExtra(Constants.ALBUM_NAME);
        collapsingToolbarLayout.setTitle(mTitle);
        fragment = new AlbumDetailsFragment();
        bundle = new Bundle();
        bundle.putLong(Constants.ALBUM_ID, mTargetId);
        fragment.setArguments(bundle);
        break;
    case Constants.ARTIST_DETAIL:
        mTargetId = getIntent().getLongExtra(Constants.ARTIST_ID, -1);
        mTitle = getIntent().getStringExtra(Constants.ARTIST_NAME);
        collapsingToolbarLayout.setTitle(mTitle);
        fragment = new ArtistDetailFragment();
        bundle = new Bundle();
        bundle.putLong(Constants.ARTIST_ID, mTargetId);
        fragment.setArguments(bundle);
        break;
    default:
        break;
    }

    getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
}

From source file:com.nononsenseapps.notepad.MainActivity.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(RESUMING, true);
    // Save current list
    outState.putLong(CURRENT_LIST_ID, currentListId);
    outState.putInt(CURRENT_LIST_POS, currentListPos);
}

From source file:com.renard.ocr.BaseDocumentActivitiy.java

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    Log.i(LOG_TAG, "onSaveInstanceState" + this);
    //remember to register the receiver again in #onRestoreInstanceState
    savedInstanceState.putBoolean(STATE_RECEIVER_REGISTERED, mReceiverRegistered);
    unRegisterImageLoadedReceiver();/*  www.j  av a 2s .  com*/
    //unregister receiver before onSaveInstanceState is called!
    super.onSaveInstanceState(savedInstanceState);
    if (dateCameraIntentStarted != null) {
        savedInstanceState.putLong(DATE_CAMERA_INTENT_STARTED_STATE, dateCameraIntentStarted.getTime());
    }
    if (cameraPicUri != null) {
        savedInstanceState.putString(CAMERA_PIC_URI_STATE, cameraPicUri.toString());
    }
    savedInstanceState.putInt(IMAGE_SOURCE, mImageSource.ordinal());

    savedInstanceState.putInt(ROTATE_X_DEGREES_STATE, rotateXDegrees);

}

From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    Log.i(LOG_TAG, "onSaveInstanceState" + this);
    //remember to register the receiver again in #onRestoreInstanceState
    savedInstanceState.putBoolean(STATE_RECEIVER_REGISTERED, mReceiverRegistered);
    unRegisterImageLoadedReceiver();/*from w  w  w . j  a va2 s  .c  o m*/
    //unregister receiver before onSaveInstanceState is called!
    super.onSaveInstanceState(savedInstanceState);
    if (dateCameraIntentStarted != null) {
        savedInstanceState.putLong(DATE_CAMERA_INTENT_STARTED_STATE, dateCameraIntentStarted.getTime());
    }
    if (cameraPicUri != null) {
        savedInstanceState.putString(CAMERA_PIC_URI_STATE, cameraPicUri.toString());
    }
    savedInstanceState.putInt(IMAGE_SOURCE, mImageSource.ordinal());
}