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:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java

/**
 * Handles all actions with this intent// w  w w.java2s  .com
 *
 * @param intent
 */
private void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();
    ArrayList<Uri> uris = new ArrayList<Uri>();

    if (extras == null) {
        extras = new Bundle();
    }

    if (intent.getData() != null) {
        uris.add(intent.getData());
    }

    /*
     * Android's Action
     */

    // When sending to OpenKeychain Encrypt via share menu
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // Files via content provider, override uri and action
        uris.clear();
        uris.add(intent.<Uri>getParcelableExtra(Intent.EXTRA_STREAM));
    }

    if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    }

    if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
        mUseArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
    }

    // preselect keys given by intent
    mSigningKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
    mEncryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);

    // Save uris
    mInputUris = uris;

}

From source file:org.lyricue.android.Lyricue.java

/**
 * Called when the activity is first created.
 *///from  ww w . j  a  va  2s.com
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, "onCreate()");
    activity = this;
    setContentView(R.layout.main);
    FragmentManager fragman = getSupportFragmentManager();
    vib = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);

    if (savedInstanceState != null) {
        for (Fragment frag : fragman.getFragments()) {
            if (frag != null) {
                Log.d(TAG, frag.toString());
                Log.d(TAG, frag.getClass().getName());
                fragments.put(frag.getClass().getName(), frag);
            }
        }
        hosts = (HostItem[]) savedInstanceState.getParcelableArray("hosts");
        profile = savedInstanceState.getString("profile");
        playlistid = savedInstanceState.getLong("playlistid");
        playlists_text = savedInstanceState.getStringArray("playlists_text");
        playlists_id = savedInstanceState.getLongArray("playlists_id");
        bibles_text = savedInstanceState.getStringArray("bibles_text");
        bibles_id = savedInstanceState.getStringArray("bibles_id");
        bibles_type = savedInstanceState.getStringArray("bibles_type");
        ld = new LyricueDisplay(hosts);
    }

    LyricuePagerAdapter adapter = new LyricuePagerAdapter(fragman, activity, activity);
    pager = (ViewPager) findViewById(R.id.viewpager);
    pager.setAdapter(adapter);

    actionBar = getSupportActionBar();
    ActionBar.TabListener tabListener = new ActionBar.TabListener() {
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
            // When the tab is selected, switch to the
            // corresponding page in the ViewPager.
            pager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
        }

        @Override
        public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
        }
    };

    Tab controlTab = actionBar.newTab().setText("Control").setTabListener(tabListener);
    actionBar.addTab(actionBar.newTab().setText(R.string.playlist).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.available).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.bible).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(R.string.display).setTabListener(tabListener));
    actionBar.addTab(controlTab);

    pager.setOffscreenPageLimit(actionBar.getTabCount());

    Resources res = getResources();
    Configuration conf = res.getConfiguration();
    boolean isLandscape = (conf.orientation == Configuration.ORIENTATION_LANDSCAPE);
    boolean isLarge = (conf.screenLayout & 0x4) == 0x4;
    Log.d(TAG, "Status:" + isLarge + ":" + isLandscape);
    if (isLarge && isLandscape) {
        activity.setQuickBar(false);
        actionBar.removeTab(controlTab);
        pager.setCurrentItem(0);
    } else {
        pager.setCurrentItem(4);
    }
    pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            getSupportActionBar().setSelectedNavigationItem(position);
        }
    });

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.RED);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    thumbnail_width = Math.min(displaymetrics.widthPixels, displaymetrics.heightPixels) / 2;
    if (profile.equals("")) {
        getPrefs();
    }
}

From source file:org.totschnig.myexpenses.activity.MyExpenses.java

@Override
public void onPositive(Bundle args, boolean checked) {
    switch (args.getInt(ConfirmationDialogFragment.KEY_COMMAND_POSITIVE)) {
    case R.id.DELETE_COMMAND_DO:
        finishActionMode();/* w w w. jav a 2  s  . c o m*/
        startTaskExecution(TaskExecutionFragment.TASK_DELETE_TRANSACTION,
                ArrayUtils.toObject(args.getLongArray(TaskExecutionFragment.KEY_OBJECT_IDS)),
                Boolean.valueOf(checked), R.string.progress_dialog_deleting);
    }
}

From source file:org.sufficientlysecure.keychain.ui.EncryptActivity.java

/**
 * Handles all actions with this intent// w w  w . j  a  va2  s  .  c  o m
 *
 * @param intent
 */
private void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();
    Uri uri = intent.getData();

    if (extras == null) {
        extras = new Bundle();
    }

    /*
     * Android's Action
     */
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // When sending to APG Encrypt via share menu
        if ("text/plain".equals(type)) {
            // Plain text
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (sharedText != null) {
                // handle like normal text encryption, override action and extras to later
                // executeServiceMethod ACTION_ENCRYPT in main actions
                extras.putString(EXTRA_TEXT, sharedText);
                extras.putBoolean(EXTRA_ASCII_ARMOR, true);
                action = ACTION_ENCRYPT;
            }
        } else {
            // Files via content provider, override uri and action
            uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            action = ACTION_ENCRYPT;
        }
    }

    if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
        boolean requestAsciiArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
        mFileFragmentBundle.putBoolean(EncryptFileFragment.ARG_ASCII_ARMOR, requestAsciiArmor);
    }

    String textData = extras.getString(EXTRA_TEXT);

    long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
    long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);

    // preselect keys given by intent
    mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds);
    mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID, signatureKeyId);
    mSwitchToMode = PAGER_MODE_ASYMMETRIC;

    /**
     * Main Actions
     */
    if (ACTION_ENCRYPT.equals(action) && textData != null) {
        // encrypt text based on given extra
        mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData);
        mSwitchToContent = PAGER_CONTENT_MESSAGE;
    } else if (ACTION_ENCRYPT.equals(action) && uri != null) {
        // encrypt file based on Uri

        // get file path from uri
        String path = FileHelper.getPath(this, uri);

        if (path != null) {
            mFileFragmentBundle.putString(EncryptFileFragment.ARG_FILENAME, path);
            mSwitchToContent = PAGER_CONTENT_FILE;
        } else {
            Log.e(Constants.TAG, "Direct binary data without actual file in filesystem is not supported "
                    + "by Intents. Please use the Remote Service API!");
            Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG).show();
            // end activity
            finish();
        }
    } else {
        Log.e(Constants.TAG, "Include the extra 'text' or an Uri with setData() in your Intent!");
    }
}

From source file:org.thialfihar.android.apg.ui.EncryptActivity.java

/**
 * Handles all actions with this intent//w w  w. j a  va  2s.  c  o m
 *
 * @param intent
 */
private void handleActions(Intent intent) {
    String action = intent.getAction();
    Bundle extras = intent.getExtras();
    String type = intent.getType();
    Uri uri = intent.getData();

    if (extras == null) {
        extras = new Bundle();
    }

    /*
     * Android's Action
     */
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        // When sending to APG Encrypt via share menu
        if ("text/plain".equals(type)) {
            // Plain text
            String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
            if (sharedText != null) {
                // handle like normal text encryption, override action and extras to later
                // executeServiceMethod ACTION_ENCRYPT in main actions
                extras.putString(EXTRA_TEXT, sharedText);
                extras.putBoolean(EXTRA_ASCII_ARMOR, true);
                action = ACTION_ENCRYPT;
            }
        } else {
            // Files via content provider, override uri and action
            uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
            action = ACTION_ENCRYPT;
        }
    }

    if (extras.containsKey(EXTRA_ASCII_ARMOR)) {
        boolean requestAsciiArmor = extras.getBoolean(EXTRA_ASCII_ARMOR, true);
        mFileFragmentBundle.putBoolean(EncryptFileFragment.ARG_ASCII_ARMOR, requestAsciiArmor);
    }

    String textData = extras.getString(EXTRA_TEXT);

    long signatureKeyId = extras.getLong(EXTRA_SIGNATURE_KEY_ID);
    long[] encryptionKeyIds = extras.getLongArray(EXTRA_ENCRYPTION_KEY_IDS);

    mLegacyMode = false;
    if ("org.thialfihar.android.apg.intent.ENCRYPT_AND_RETURN".equals(action)) {
        mLegacyMode = true;
        encryptionKeyIds = extras.getLongArray("encryptionKeyIds");
        signatureKeyId = extras.getLong("signatureKeyId");
        mSigningKeyId = signatureKeyId;
        mEncryptionKeyIds = encryptionKeyIds;
        mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData);
        mSwitchToContent = PAGER_CONTENT_MESSAGE;
    }

    // preselect keys given by intent
    mAsymmetricFragmentBundle.putLongArray(EncryptAsymmetricFragment.ARG_ENCRYPTION_KEY_IDS, encryptionKeyIds);
    mAsymmetricFragmentBundle.putLong(EncryptAsymmetricFragment.ARG_SIGNATURE_KEY_ID, signatureKeyId);
    mSwitchToMode = PAGER_MODE_ASYMMETRIC;

    /**
     * Main Actions
     */
    if (ACTION_ENCRYPT.equals(action) && textData != null) {
        // encrypt text based on given extra
        mMessageFragmentBundle.putString(EncryptMessageFragment.ARG_TEXT, textData);
        mSwitchToContent = PAGER_CONTENT_MESSAGE;
    } else if (ACTION_ENCRYPT.equals(action) && uri != null) {
        // encrypt file based on Uri

        // get file path from uri
        String path = FileHelper.getPath(this, uri);

        if (path != null) {
            mFileFragmentBundle.putString(EncryptFileFragment.ARG_FILENAME, path);
            mSwitchToContent = PAGER_CONTENT_FILE;
        } else {
            Log.e(Constants.TAG, "Direct binary data without actual file in filesystem is not supported "
                    + "by Intents. Please use the Remote Service API!");
            Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG).show();
            // end activity
            finish();
        }
    } else {
        Log.e(Constants.TAG, "Include the extra 'text' or an Uri with setData() in your Intent!");
    }
}

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

@Override
public void onCreate(final Bundle savedInstanceState) {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mService = getTweetingsApplication().getServiceInterface();
    mResolver = getContentResolver();//  w  w w. j av  a  2  s . c om
    super.onCreate(savedInstanceState);
    setContentView(R.layout.compose);
    mActionBar = getSupportActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(true);

    mUploadProvider = mPreferences.getString(PREFERENCE_KEY_IMAGE_UPLOADER, null);

    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;
    mInReplyToText = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_TWEET) : 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 String account_username = getAccountUsername(this, account_id);
    int text_selection_start = -1;
    mIsBuffer = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_BUFFER, false) : false;

    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_username)) {
                    builder.append('@' + account_username + ' ');
                } else if (!mention.equalsIgnoreCase(account_username)) {
                    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_name = mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_NAME, false);
        final String name = display_name ? mInReplyToName : mInReplyToScreenName;
        if (name != null) {
            setTitle(getString(mIsQuote ? R.string.quote_user : R.string.reply_to, name));
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            mAccountIds = new long[] { account_id };
        }
        TextView replyText = (TextView) findViewById(R.id.reply_text);
        if (!isNullOrEmpty(mInReplyToText)) {
            replyText.setVisibility(View.VISIBLE);
            replyText.setText(mInReplyToText);
        } else {
            replyText.setVisibility(View.GONE);
        }
    } else {
        if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_username)) {
                    builder.append('@' + account_username + ' ');
                } else if (!mention.equalsIgnoreCase(account_username)) {
                    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[] activated_ids = getActivatedAccountIds(this);
            final long[] intersection = ArrayUtils.intersection(ids_in_prefs, activated_ids);
            mAccountIds = intersection.length > 0 ? intersection : activated_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);
    mMenuBar.show();
    if (mPreferences.getBoolean(PREFERENCE_KEY_QUICK_SEND, false)) {
        mEditText.setRawInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
                | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        mEditText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
        mEditText.setImeOptions(EditorInfo.IME_ACTION_GO);
        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());
        }
    }
    invalidateSupportOptionsMenu();
    setMenu();
    if (mColorIndicator != null) {
        mColorIndicator.setOrientation(ColorView.VERTICAL);
        mColorIndicator.setColor(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.android.deskclock.AlarmClockFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.alarm_clock, container, false);

    long expandedId = INVALID_ID;
    long[] repeatCheckedIds = null;
    long[] selectedAlarms = null;
    Bundle previousDayMap = null;//from   ww w.  j a  va  2s. c  o m
    if (savedState != null) {
        expandedId = savedState.getLong(KEY_EXPANDED_ID);
        repeatCheckedIds = savedState.getLongArray(KEY_REPEAT_CHECKED_IDS);
        mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE);
        mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM);
        mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING);
        selectedAlarms = savedState.getLongArray(KEY_SELECTED_ALARMS);
        previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP);
        mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM);
    }

    mExpandInterpolator = new DecelerateInterpolator(EXPAND_DECELERATION);
    mCollapseInterpolator = new DecelerateInterpolator(COLLAPSE_DECELERATION);

    if (USE_TRANSITION_FRAMEWORK) {
        mAddRemoveTransition = new AutoTransition();
        mAddRemoveTransition.setDuration(ANIMATION_DURATION);

        /// M: Scrap the views in ListView and request layout again, then alarm item will be
        /// attached correctly. This is to avoid the case when some items are not correctly
        ///  attached after animation end  @{
        mAddRemoveTransition.addListener(new Transition.TransitionListenerAdapter() {
            @Override
            public void onTransitionEnd(Transition transition) {
                mAlarmsList.clearScrapViewsIfNeeded();
            }
        });
        /// @}

        mRepeatTransition = new AutoTransition();
        mRepeatTransition.setDuration(ANIMATION_DURATION / 2);
        mRepeatTransition.setInterpolator(new AccelerateDecelerateInterpolator());

        mEmptyViewTransition = new TransitionSet().setOrdering(TransitionSet.ORDERING_SEQUENTIAL)
                .addTransition(new Fade(Fade.OUT)).addTransition(new Fade(Fade.IN))
                .setDuration(ANIMATION_DURATION);
    }

    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    View menuButton = v.findViewById(R.id.menu_button);
    if (menuButton != null) {
        if (isLandscape) {
            menuButton.setVisibility(View.GONE);
        } else {
            menuButton.setVisibility(View.VISIBLE);
            setupFakeOverflowMenuButton(menuButton);
        }
    }

    mEmptyView = v.findViewById(R.id.alarms_empty_view);

    mMainLayout = (FrameLayout) v.findViewById(R.id.main);
    mAlarmsList = (ListView) v.findViewById(R.id.alarms_list);

    mUndoBar = (ActionableToastBar) v.findViewById(R.id.undo_bar);
    mUndoFrame = v.findViewById(R.id.undo_frame);
    mUndoFrame.setOnTouchListener(this);

    mFooterView = v.findViewById(R.id.alarms_footer_view);
    mFooterView.setOnTouchListener(this);

    mAdapter = new AlarmItemAdapter(getActivity(), expandedId, repeatCheckedIds, selectedAlarms, previousDayMap,
            mAlarmsList);
    mAdapter.registerDataSetObserver(new DataSetObserver() {

        private int prevAdapterCount = -1;

        @Override
        public void onChanged() {

            final int count = mAdapter.getCount();
            if (mDeletedAlarm != null && prevAdapterCount > count) {
                showUndoBar();
            }

            if (USE_TRANSITION_FRAMEWORK && ((count == 0 && prevAdapterCount > 0) || /* should fade  in */
            (count > 0 && prevAdapterCount == 0) /* should fade out */)) {
                TransitionManager.beginDelayedTransition(mMainLayout, mEmptyViewTransition);
            }
            mEmptyView.setVisibility(count == 0 ? View.VISIBLE : View.GONE);

            // Cache this adapter's count for when the adapter changes.
            prevAdapterCount = count;
            super.onChanged();
        }
    });

    if (mRingtoneTitleCache == null) {
        mRingtoneTitleCache = new Bundle();
    }

    mAlarmsList.setAdapter(mAdapter);
    mAlarmsList.setVerticalScrollBarEnabled(true);
    mAlarmsList.setOnCreateContextMenuListener(this);

    if (mUndoShowing) {
        showUndoBar();
    }
    return v;
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindFragmentArgument(Fragment receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);/* www.j  a va 2s.c  o m*/
        FragmentArgument fragmentArgument = field.getAnnotation(FragmentArgument.class);
        if (fragmentArgument != null) {
            try {
                Bundle bundle = receiver.getArguments();
                if (bundle != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, bundle.getBoolean(fragmentArgument.value()));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, bundle.getByte(fragmentArgument.value()));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, bundle.getChar(fragmentArgument.value()));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, bundle.getDouble(fragmentArgument.value()));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, bundle.getFloat(fragmentArgument.value()));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, bundle.getInt(fragmentArgument.value()));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, bundle.getLong(fragmentArgument.value()));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, bundle.getShort(fragmentArgument.value()));
                    } else if (type == String.class) {
                        field.set(receiver, bundle.getString(fragmentArgument.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, bundle.getBooleanArray(fragmentArgument.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, bundle.getByteArray(fragmentArgument.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, bundle.getCharArray(fragmentArgument.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, bundle.getDoubleArray(fragmentArgument.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, bundle.getFloatArray(fragmentArgument.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, bundle.getIntArray(fragmentArgument.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, bundle.getLongArray(fragmentArgument.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, bundle.getShortArray(fragmentArgument.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, bundle.getStringArray(fragmentArgument.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, bundle.getSerializable(fragmentArgument.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, bundle.getBundle(fragmentArgument.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.facebook.LegacyTokenCacheTest.java

@Test
public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);//  w  w w.j  a  v a 2 s .  co m
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application);
    cache.save(originalBundle);

    LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);
    Bundle cachedBundle = cache2.load();

    assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
            cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY),
            cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY),
            cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
            cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY),
            cachedBundle.getStringArrayList(STRING_LIST_KEY));
    assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY),
            cachedBundle.getSerializable(SERIALIZABLE_KEY));
}

From source file:saphion.fragments.alarm.AlarmFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {

    mCursorLoader = getActivity().getSupportLoaderManager().initLoader(0, null, this);
    try {/*from ww w.  jav a  2  s  .  co m*/
        if (!created)
            mCursorLoader.forceLoad();
    } catch (Exception ex) {
    }
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.alarm_listview, container, false);

    long[] expandedIds = null;
    long[] repeatCheckedIds = null;
    long[] selectedAlarms = null;
    Bundle previousDayMap = null;
    if (savedState != null) {
        expandedIds = savedState.getLongArray(KEY_EXPANDED_IDS);
        repeatCheckedIds = savedState.getLongArray(KEY_REPEAT_CHECKED_IDS);
        mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE);
        mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM);
        mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING);
        selectedAlarms = savedState.getLongArray(KEY_SELECTED_ALARMS);
        previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP);
        mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM);
    }

    mMessageBar = new MessageBar(getActivity());

    mExpandInterpolator = new DecelerateInterpolator(EXPAND_DECELERATION);
    mCollapseInterpolator = new DecelerateInterpolator(COLLAPSE_DECELERATION);

    mAddAlarmButton = (ImageButton) v.findViewById(R.id.alarm_add_alarm);
    mAddAlarmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            hideUndoBar(true, null);
            startCreatingAlarm();
        }
    });
    // For landscape, put the add button on the right and the menu in the
    // actionbar.
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mAddAlarmButton.getLayoutParams();
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    if (isLandscape) {
        layoutParams.gravity = Gravity.RIGHT;
    } else {
        layoutParams.gravity = Gravity.CENTER;
    }
    mAddAlarmButton.setLayoutParams(layoutParams);

    View menuButton = v.findViewById(R.id.menu_button);
    if (menuButton != null) {
        if (isLandscape) {
            menuButton.setVisibility(View.GONE);
        } else {
            menuButton.setVisibility(View.VISIBLE);
            setupFakeOverflowMenuButton(menuButton);
        }
    }

    mEmptyView = v.findViewById(R.id.alarms_empty_view);
    mEmptyView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startCreatingAlarm();
        }
    });
    mAlarmsList = (ListView) v.findViewById(R.id.alarms_list);

    mFadeIn = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_in);
    mFadeIn.setDuration(ANIMATION_DURATION);
    mFadeIn.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            mEmptyView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    mFadeIn.setTarget(mEmptyView);
    mFadeOut = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_out);
    mFadeOut.setDuration(ANIMATION_DURATION);
    mFadeOut.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator arg0) {
            mEmptyView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator arg0) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator arg0) {
            mEmptyView.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animator arg0) {
            // Do nothing.
        }
    });
    mFadeOut.setTarget(mEmptyView);

    mFooterView = v.findViewById(R.id.alarms_footer_view);
    mFooterView.setOnTouchListener(this);

    mAdapter = new AlarmItemAdapter(getActivity(), expandedIds, repeatCheckedIds, selectedAlarms,
            previousDayMap, mAlarmsList);

    hideandshow(mAdapter.getCount());

    mAdapter.registerDataSetObserver(new DataSetObserver() {

        private int prevAdapterCount = -1;

        @Override
        public void onChanged() {

            final int count = mAdapter.getCount();
            if (mDeletedAlarm != null && prevAdapterCount > count) {
                showUndoBar();
            }

            hideandshow(count);
            // Cache this adapter's count for when the adapter changes.
            prevAdapterCount = count;
            super.onChanged();
        }
    });

    if (mRingtoneTitleCache == null) {
        mRingtoneTitleCache = new Bundle();
    }

    mAlarmsList.setAdapter(mAdapter);
    mAlarmsList.setVerticalScrollBarEnabled(true);
    mAlarmsList.setOnCreateContextMenuListener(this);

    if (mUndoShowing) {
        showUndoBar();
    }
    return v;
}