Example usage for android.os Bundle getLongArray

List of usage examples for android.os Bundle getLongArray

Introduction

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

Prototype

@Nullable
public long[] getLongArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.dwdesign.tweetings.activity.HomeActivity.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
    final ContentResolver resolver = getContentResolver();
    ContentValues values;/*from  w  ww .  j  a v a 2 s.c o m*/
    switch (requestCode) {
    case REQUEST_SELECT_ACCOUNT: {
        if (resultCode == RESULT_OK) {
            if (intent == null || intent.getExtras() == null) {
                break;
            }
            final Bundle bundle = intent.getExtras();
            if (bundle == null) {
                break;
            }
            final long[] account_ids = bundle.getLongArray(INTENT_KEY_IDS);
            if (account_ids != null) {
                values = new ContentValues();
                values.put(Accounts.IS_ACTIVATED, 0);
                resolver.update(Accounts.CONTENT_URI, values, null, null);
                values = new ContentValues();
                values.put(Accounts.IS_ACTIVATED, 1);
                for (final long account_id : account_ids) {
                    final String where = Accounts.USER_ID + " = " + account_id;
                    resolver.update(Accounts.CONTENT_URI, values, where, null);
                }
            }
            checkDefaultAccountSet();
        } else if (resultCode == RESULT_CANCELED) {
            if (getActivatedAccountIds(this).length <= 0) {
                finish();
            } else {
                checkDefaultAccountSet();
            }
        }
        break;
    }
    }
    super.onActivityResult(requestCode, resultCode, intent);
}

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

private boolean hasAccountId(Bundle args, long accountId) {
    if (args == null)
        return false;
    if (args.containsKey(EXTRA_ACCOUNT_ID)) {
        return args.getLong(EXTRA_ACCOUNT_ID) == accountId;
    } else if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
        return ArrayUtils.contains(args.getLongArray(EXTRA_ACCOUNT_IDS), accountId);
    }/*www . j ava 2 s .c  o m*/
    return false;
}

From source file:org.mariotaku.twidere.activity.ComposeActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mTwitterWrapper = getTwidereApplication().getTwitterWrapper();
    mResolver = getContentResolver();/*from w  ww  . ja v  a  2s.  co m*/
    super.onCreate(savedInstanceState);
    final long[] account_ids = getAccountIds(this);
    if (account_ids.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    setContentView(R.layout.compose);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Bundle bundle = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    final long account_id = bundle != null ? bundle.getLong(INTENT_KEY_ACCOUNT_ID) : -1;
    mAccountIds = bundle != null ? bundle.getLongArray(INTENT_KEY_IDS) : null;
    mInReplyToStatusId = bundle != null ? bundle.getLong(INTENT_KEY_IN_REPLY_TO_ID) : -1;
    mInReplyToScreenName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME) : null;
    mInReplyToName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_NAME) : null;
    mIsImageAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_IMAGE_ATTACHED) : false;
    mIsPhotoAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_PHOTO_ATTACHED) : false;
    mImageUri = bundle != null ? (Uri) bundle.getParcelable(INTENT_KEY_IMAGE_URI) : null;
    final String[] mentions = bundle != null ? bundle.getStringArray(INTENT_KEY_MENTIONS) : null;
    final int notification_id = bundle != null ? bundle.getInt(INTENT_KEY_NOTIFICATION_ID, -1) : -1;
    if (notification_id != -1) {
        mTwitterWrapper.clearNotification(notification_id);
    }
    final String account_screen_name = getAccountScreenName(this, account_id);
    int text_selection_start = -1;
    if (mInReplyToStatusId > 0) {
        if (bundle != null && bundle.getString(INTENT_KEY_TEXT) != null
                && (mentions == null || mentions.length < 1)) {
            mText = bundle.getString(INTENT_KEY_TEXT);
        } else if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
            text_selection_start = mText.indexOf(' ') + 1;
        }

        mIsQuote = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_QUOTE, false) : false;

        final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
                .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
        if (mInReplyToScreenName != null && mInReplyToName != null) {
            setTitle(getString(mIsQuote ? R.string.quote_user : R.string.reply_to,
                    display_screen_name ? mInReplyToScreenName : mInReplyToName));
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            mAccountIds = new long[] { account_id };
        }
    } else {
        if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            final long[] ids_in_prefs = ArrayUtils
                    .fromString(mPreferences.getString(PREFERENCE_KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = ArrayUtils.intersection(ids_in_prefs, account_ids);
            mAccountIds = intersection.length > 0 ? intersection : account_ids;
        }
        final String action = getIntent().getAction();
        if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            setTitle(R.string.share);
            final Bundle extras = getIntent().getExtras();
            if (extras != null) {
                if (mText == null) {
                    final CharSequence extra_subject = extras.getCharSequence(Intent.EXTRA_SUBJECT);
                    final CharSequence extra_text = extras.getCharSequence(Intent.EXTRA_TEXT);
                    mText = getShareStatus(this, parseString(extra_subject), parseString(extra_text));
                } else {
                    mText = bundle.getString(INTENT_KEY_TEXT);
                }
                if (mImageUri == null) {
                    final Uri extra_stream = extras.getParcelable(Intent.EXTRA_STREAM);
                    final String content_type = getIntent().getType();
                    if (extra_stream != null && content_type != null && content_type.startsWith("image/")) {
                        final String real_path = getImagePathFromUri(this, extra_stream);
                        final File file = real_path != null ? new File(real_path) : null;
                        if (file != null && file.exists()) {
                            mImageUri = Uri.fromFile(file);
                            mIsImageAttached = true;
                            mIsPhotoAttached = false;
                        } else {
                            mImageUri = null;
                            mIsImageAttached = false;
                        }
                    }
                }
            }
        } else if (bundle != null) {
            if (bundle.getString(INTENT_KEY_TEXT) != null) {
                mText = bundle.getString(INTENT_KEY_TEXT);
            }
        }
    }

    final File image_file = mImageUri != null && "file".equals(mImageUri.getScheme())
            ? new File(mImageUri.getPath())
            : null;
    final boolean image_file_valid = image_file != null && image_file.exists();
    mImageThumbnailPreview.setVisibility(image_file_valid ? View.VISIBLE : View.GONE);
    if (image_file_valid) {
        reloadAttachedImageThumbnail(image_file);
    }

    mImageThumbnailPreview.setOnClickListener(this);
    mImageThumbnailPreview.setOnLongClickListener(this);
    mMenuBar.setOnMenuItemClickListener(this);
    mMenuBar.inflate(R.menu.menu_compose);
    final Menu menu = mMenuBar.getMenu();
    final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
    if (extensions != null) {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
        final Bundle extras = new Bundle();
        final String screen_name = mAccountIds != null && mAccountIds.length > 0
                ? getAccountScreenName(this, mAccountIds[0])
                : null;
        extras.putString(INTENT_KEY_TEXT, parseString(mEditText.getText()));
        extras.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, mInReplyToScreenName);
        extras.putString(INTENT_KEY_IN_REPLY_TO_NAME, mInReplyToName);
        extras.putString(INTENT_KEY_SCREEN_NAME, screen_name);
        extras.putLong(INTENT_KEY_IN_REPLY_TO_ID, mInReplyToStatusId);
        intent.putExtras(extras);
        addIntentToSubMenu(this, extensions.getSubMenu(), intent);
    }
    mMenuBar.show();
    if (mPreferences.getBoolean(PREFERENCE_KEY_QUICK_SEND, false)) {
        mEditText.setOnEditorActionListener(this);
    }
    mEditText.addTextChangedListener(this);
    if (mText != null) {
        mEditText.setText(mText);
        if (mIsQuote) {
            mEditText.setSelection(0);
        } else if (text_selection_start != -1 && text_selection_start < mEditText.length()
                && mEditText.length() > 0) {
            mEditText.setSelection(text_selection_start, mEditText.length() - 1);
        } else if (mEditText.length() > 0) {
            mEditText.setSelection(mEditText.length());
        }
    }
    setMenu();
    mColorIndicator.setColors(getAccountColors(this, mAccountIds));
    mContentModified = savedInstanceState != null ? savedInstanceState.getBoolean(INTENT_KEY_CONTENT_MODIFIED)
            : false;
    mIsPossiblySensitive = savedInstanceState != null
            ? savedInstanceState.getBoolean(INTENT_KEY_IS_POSSIBLY_SENSITIVE)
            : false;
}

From source file:com.app.uafeed.fragment.EntryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry, container, false);

    mCancelFullscreenBtn = rootView.findViewById(R.id.cancelFullscreenBtn);
    mCancelFullscreenBtn.setOnClickListener(new View.OnClickListener() {
        @Override//ww  w.  j  av  a2  s  .  c  o m
        public void onClick(View view) {
            toggleFullScreen();
        }
    });

    mEntryPager = (ViewPager) rootView.findViewById(R.id.pager);
    //mEntryPager.setPageTransformer(true, new DepthPageTransformer());
    mEntryPager.setAdapter(mEntryPagerAdapter);

    if (savedInstanceState != null) {
        mBaseUri = savedInstanceState.getParcelable(STATE_BASE_URI);
        mEntriesIds = savedInstanceState.getLongArray(STATE_ENTRIES_IDS);
        mInitialEntryId = savedInstanceState.getLong(STATE_INITIAL_ENTRY_ID);
        mCurrentPagerPos = savedInstanceState.getInt(STATE_CURRENT_PAGER_POS);
        mEntryPager.getAdapter().notifyDataSetChanged();
        mEntryPager.setCurrentItem(mCurrentPagerPos);
        mEntryPagerAdapter.setScrollPercentage(savedInstanceState.getFloat(STATE_SCROLL_PERCENTAGE));
    }

    mEntryPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            mCurrentPagerPos = i;
            mEntryPagerAdapter.onPause(); // pause all webviews
            mEntryPagerAdapter.onResume(); // resume the current webview

            refreshUI(mEntryPagerAdapter.getCursor(i));
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    return rootView;
}

From source file:net.czlee.debatekeeper.debatemanager.DebateManager.java

/**
 * Restores the state of this <code>DebateManager</code> from a {@link Bundle}.
 * @param key A String to uniquely distinguish this <code>DebateManager</code> from any other
 *        objects that might be stored in the same Bundle.
 * @param bundle The Bundle from which to restore this information.
 *///from   w w w  .j ava 2  s.c  o  m
public void restoreState(String key, Bundle bundle) {

    // Restore the current item type
    String itemTypeValue = bundle.getString(key + BUNDLE_SUFFIX_ITEM_TYPE);
    if (itemTypeValue == null)
        Log.e(TAG, "restoreState: No item type found");
    else
        try {
            mActivePhaseType = DebatePhaseType.toEnum(itemTypeValue);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "restoreState: Invalid item type: " + itemTypeValue);
        }

    // Restore the current speech
    mActiveSpeechIndex = bundle.getInt(key + BUNDLE_SUFFIX_INDEX, 0);
    loadSpeech();

    // If there are saved speech times, restore them as well
    long[] speechTimes = bundle.getLongArray(key + BUNDLE_SUFFIX_SPEECH_TIMES);
    if (speechTimes != null)
        for (int i = 0; i < speechTimes.length; i++)
            mSpeechTimes.set(i, speechTimes[i]);

    // Restore the prep time
    mPrepTime = bundle.getLong(key + BUNDLE_SUFFIX_PREP_TIME, 0);

    mPhaseManager.restoreState(key + BUNDLE_SUFFIX_SPEECH, bundle);
}

From source file:net.fred.feedex.fragment.EntryFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry, container, true);

    mCancelFullscreenBtn = rootView.findViewById(R.id.cancelFullscreenBtn);
    mCancelFullscreenBtn.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w  w.j a va 2s  .  com
        public void onClick(View view) {
            toggleFullScreen();
        }
    });

    mEntryPager = (ViewPager) rootView.findViewById(R.id.pager);
    //mEntryPager.setPageTransformer(true, new DepthPageTransformer());
    mEntryPager.setAdapter(mEntryPagerAdapter);

    if (savedInstanceState != null) {
        mBaseUri = savedInstanceState.getParcelable(STATE_BASE_URI);
        mEntriesIds = savedInstanceState.getLongArray(STATE_ENTRIES_IDS);
        mInitialEntryId = savedInstanceState.getLong(STATE_INITIAL_ENTRY_ID);
        mCurrentPagerPos = savedInstanceState.getInt(STATE_CURRENT_PAGER_POS);
        mEntryPager.getAdapter().notifyDataSetChanged();
        mEntryPager.setCurrentItem(mCurrentPagerPos);
    }

    mEntryPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            mCurrentPagerPos = i;
            mEntryPagerAdapter.onPause(); // pause all webviews
            mEntryPagerAdapter.onResume(); // resume the current webview

            refreshUI(mEntryPagerAdapter.getCursor(i));
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.wirelessmoves.cl.MainActivity.java

@SuppressWarnings("deprecation")
@Override//from  ww w  .  ja  v  a2  s .  co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /* If saved variable state exists from last run, recover it */
    if (savedInstanceState != null) {
        NumberOfSignalStrengthUpdates = savedInstanceState.getLong("NumberOfSignalStrengthUpdates");

        LastCellId = savedInstanceState.getLong("LastCellId");
        NumberOfCellChanges = savedInstanceState.getLong("NumberOfCellChanges");

        LastLacId = savedInstanceState.getLong("LastLacId");
        NumberOfLacChanges = savedInstanceState.getLong("NumberOfLacChanges");

        PreviousCells = savedInstanceState.getLongArray("PreviousCells");
        PreviousCellsIndex = savedInstanceState.getInt("PreviousCellsIndex");
        NumberOfUniqueCellChanges = savedInstanceState.getLong("NumberOfUniqueCellChanges");

        outputDebugInfo = savedInstanceState.getBoolean("outputDebugInfo");

        CurrentLocationLong = savedInstanceState.getDouble("CurrentLocationLong");
        CurrentLocationLat = savedInstanceState.getDouble("CurrentLocationLat");

        /* attempt to restore the previous gps location information object */
        PrevLocation = (Location) getLastNonConfigurationInstance();

    } else {
        /* Initialize PreviousCells Array to defined values */
        for (int x = 0; x < PreviousCells.length; x++)
            PreviousCells[x] = 0;
    }

    /* Get a handle to the telephony manager service */
    /* A listener will be installed in the object from the onResume() method */
    MyListener = new MyPhoneStateListener();
    Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    /* get a handle to the power manager and set a wake lock so the screen saver
     * is not activated after a timeout */
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

    /* Get a handle to the location system for getting GPS information */
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    gpsListener = new myLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener);

}

From source file:com.viktorrudometkin.burramys.fragment.EntryFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry, container, true);

    mCancelFullscreenBtn = rootView.findViewById(R.id.cancelFullscreenBtn);
    mCancelFullscreenBtn.setOnClickListener(new View.OnClickListener() {
        @Override//  www.  j a  va2 s.  c om
        public void onClick(View view) {
            setImmersiveFullScreen(false);
        }
    });

    mEntryPager = (ViewPager) rootView.findViewById(R.id.pager);
    //mEntryPager.setPageTransformer(true, new DepthPageTransformer());
    mEntryPager.setAdapter(mEntryPagerAdapter);

    if (savedInstanceState != null) {
        mBaseUri = savedInstanceState.getParcelable(STATE_BASE_URI);
        mEntriesIds = savedInstanceState.getLongArray(STATE_ENTRIES_IDS);
        mInitialEntryId = savedInstanceState.getLong(STATE_INITIAL_ENTRY_ID);
        mCurrentPagerPos = savedInstanceState.getInt(STATE_CURRENT_PAGER_POS);
        mEntryPager.getAdapter().notifyDataSetChanged();
        mEntryPager.setCurrentItem(mCurrentPagerPos);
    }

    mEntryPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            mCurrentPagerPos = i;
            mEntryPagerAdapter.onPause(); // pause all webviews
            mEntryPagerAdapter.onResume(); // resume the current webview

            refreshUI(mEntryPagerAdapter.getCursor(i));
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.carlrice.reader.fragment.EntryFragment.java

@Override
public View inflateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_entry, container, true);

    mCancelFullscreenBtn = rootView.findViewById(R.id.cancelFullscreenBtn);
    mCancelFullscreenBtn.setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww w  .  j a  va 2s. c  om*/
        public void onClick(View view) {
            setImmersiveFullScreen(false);
        }
    });

    mEntryPager = (ViewPager) rootView.findViewById(R.id.pager);
    //mEntryPager.setPageTransformer(true, new DepthPageTransformer());
    mEntryPager.setAdapter(mEntryPagerAdapter);

    if (savedInstanceState != null) {
        mBaseUri = savedInstanceState.getParcelable(STATE_BASE_URI);
        mEntriesIds = savedInstanceState.getLongArray(STATE_ENTRIES_IDS);
        mInitialEntryId = savedInstanceState.getLong(STATE_INITIAL_ENTRY_ID);
        mCurrentPagerPos = savedInstanceState.getInt(STATE_CURRENT_PAGER_POS);
        mEntryPager.getAdapter().notifyDataSetChanged();
        mEntryPager.setCurrentItem(mCurrentPagerPos);
    }

    mEntryPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int i, float v, int i2) {
        }

        @Override
        public void onPageSelected(int i) {
            mCurrentPagerPos = i;
            mEntryPagerAdapter.onPause(); // pause all webviews
            mEntryPagerAdapter.onResume(); // resume the current webview

            refreshUI(mEntryPagerAdapter.getCursor(i));
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });

    disableSwipe();

    return rootView;
}

From source file:com.example.android.honeypad.ui.NoteListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mTwoPaneView = UiUtils.isHoneycombTablet(getActivity());
    setEmptyText(getActivity().getString(R.string.no_notes));

    // create an empty adapter, our Loader will retrieve the data
    // asynchronously
    mAdapter = new NotesListCursorAdapter(getActivity(), R.layout.list_item_notes, null,
            new String[] { NotesProvider.KEY_TITLE }, new int[] { android.R.id.text1 }, 0);

    setListAdapter(mAdapter);/*  w w w.  ja va 2 s  .  c om*/

    // setup our list view
    final ListView notesList = getListView();

    // add listners to handle note selection & contextual action bar
    notesList.setOnItemLongClickListener(this);
    notesList.setOnItemClickListener(this);

    // restore any saved state
    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(KEY_CURRENT_ACTIVATED)) {
            mCurrentActivePosition = savedInstanceState.getInt(KEY_CURRENT_ACTIVATED,
                    ListView.INVALID_POSITION);
        }
        if (savedInstanceState.containsKey(KEY_CURRENT_CHECKED)) {
            final long[] checked = savedInstanceState.getLongArray(KEY_CURRENT_CHECKED);
            for (long l : checked) {
                mCheckedItems.add(l);
            }
            startContextualActionMode();
        }
    }

    // Prepare the loader. Either re-connect with an existing one,
    // or start a new one.
    getLoaderManager().initLoader(LOADER_ID, null, this);
}