Example usage for android.os Bundle getIntegerArrayList

List of usage examples for android.os Bundle getIntegerArrayList

Introduction

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

Prototype

@Override
@Nullable
public ArrayList<Integer> getIntegerArrayList(@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.ale.scanner.zotero.MainActivity.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    setContentView(R.layout.main);/*  w  ww .j  a v  a2s  .c  om*/
    Bundle extras = getIntent().getExtras();

    mUIThreadHandler = new Handler();

    // Get the account we're logged in as
    mAccount = (Account) extras.getParcelable(INTENT_EXTRA_ACCOUNT);

    // Load preferences
    SharedPreferences prefs = getSharedPreferences(mAccount.getUid(), MODE_PRIVATE);
    // The group we'll upload to (default to user's personal library)
    mSelectedGroup = prefs.getInt(PREF_GROUP, Group.GROUP_LIBRARY);
    mISBNService = prefs.getInt(PREF_SERVICE, SERVICE_GOOGLE);

    // Initialize Clients
    mGoogleBooksAPI = new GoogleBooksAPIClient();
    mWorldCatAPI = new WorldCatAPIClient();
    mZAPI = new ZoteroAPIClient();
    mZAPI.setAccount(mAccount);

    // BibItem list
    ExpandableListView bibItemList = (ExpandableListView) findViewById(R.id.bib_items);

    // Pending item list
    View pendingListHolder = getLayoutInflater().inflate(R.layout.pending_item_list, bibItemList, false);
    bibItemList.addHeaderView(pendingListHolder);

    mPendingList = (ListView) pendingListHolder.findViewById(R.id.pending_item_list);

    int[] checked;
    if (state == null) { // Fresh activity
        mAccountAccess = null; // will check for permissions in onResume
        mPendingItems = new ArrayList<String>(2); // RC_PEND
        mPendingStatus = new ArrayList<Integer>(2); // RC_PEND_STAT
        checked = new int[0];
        mUploadState = UPLOAD_STATE_WAIT;
        mGroups = new SparseArray<PString>();
    } else { // Recreating activity
             // Rebuild pending list
        mAccountAccess = state.getParcelable(RC_ACCESS);
        mPendingItems = state.getStringArrayList(RC_PEND);
        mPendingStatus = state.getIntegerArrayList(RC_PEND_STAT);
        // Set checked items
        checked = state.getIntArray(RC_CHECKED);

        mUploadState = state.getInt(RC_UPLOADING);
        mGroups = state.getSparseParcelableArray(RC_GROUPS);
    }

    // Initialize list adapters
    mItemAdapter = new BibItemListAdapter(MainActivity.this);
    mItemAdapter.setChecked(checked);
    bibItemList.setAdapter(mItemAdapter);
    registerForContextMenu(bibItemList);

    mPendingAdapter = new PendingListAdapter(MainActivity.this, R.layout.pending_item, R.id.pending_item_id,
            mPendingItems, mPendingStatus);
    mPendingList.setAdapter(mPendingAdapter);
    registerForContextMenu(mPendingList);

    // Listeners
    findViewById(R.id.scan_isbn).setOnClickListener(scanIsbn);
    findViewById(R.id.upload).setOnClickListener(uploadSelected);

    // Load animations
    mAnimations = new Animation[] { AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_next),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_out_next),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_previous),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_out_previous) };

    // Upload Bar
    findViewById(R.id.upload_progress).setOnClickListener(dismissUploadStatus);
}

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

/**
 * Handle intent action to create new key
 *
 * @param intent/*w ww.java  2 s  . co  m*/
 */
private void handleActionCreateKey(Intent intent) {
    Bundle extras = intent.getExtras();

    mCurrentPassphrase = "";
    mIsBrandNewKeyring = true;

    if (extras != null) {
        // if userId is given, prefill the fields
        if (extras.containsKey(EXTRA_USER_IDS)) {
            Log.d(Constants.TAG, "UserIds are given!");
            mUserIds.add(extras.getString(EXTRA_USER_IDS));
        }

        // if no passphrase is given
        if (extras.containsKey(EXTRA_NO_PASSPHRASE)) {
            boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE);
            if (noPassphrase) {
                // check "no passphrase" checkbox and remove button
                mNoPassphrase.setChecked(true);
                mChangePassphrase.setVisibility(View.GONE);
            }
        }

        // generate key
        if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) {
            boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS);
            if (generateDefaultKeys) {

                // Send all information needed to service generate keys in other thread
                final Intent serviceIntent = new Intent(this, KeychainIntentService.class);
                serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS);

                // fill values for this action
                Bundle data = new Bundle();
                data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, mCurrentPassphrase);

                serviceIntent.putExtra(KeychainIntentService.EXTRA_DATA, data);

                // Message is received after generating is done in KeychainIntentService
                KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
                        getResources().getQuantityString(R.plurals.progress_generating, 1),
                        ProgressDialog.STYLE_HORIZONTAL, true,

                        new DialogInterface.OnCancelListener() {
                            @Override
                            public void onCancel(DialogInterface dialog) {
                                // Stop key generation on cancel
                                stopService(serviceIntent);
                                EditKeyActivity.this.setResult(Activity.RESULT_CANCELED);
                                EditKeyActivity.this.finish();
                            }
                        }) {

                    @Override
                    public void handleMessage(Message message) {
                        // handle messages by standard KeychainIntentServiceHandler first
                        super.handleMessage(message);

                        if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                            // get new key from data bundle returned from service
                            Bundle data = message.getData();

                            ArrayList<UncachedSecretKey> newKeys = PgpConversionHelper.BytesToPGPSecretKeyList(
                                    data.getByteArray(KeychainIntentService.RESULT_NEW_KEY));

                            ArrayList<Integer> keyUsageFlags = data
                                    .getIntegerArrayList(KeychainIntentService.RESULT_KEY_USAGES);

                            if (newKeys.size() == keyUsageFlags.size()) {
                                for (int i = 0; i < newKeys.size(); ++i) {
                                    mKeys.add(newKeys.get(i));
                                    mKeysUsages.add(keyUsageFlags.get(i));
                                }
                            }

                            buildLayout(true);
                        }
                    }
                };

                // Create a new Messenger for the communication back
                Messenger messenger = new Messenger(saveHandler);
                serviceIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

                saveHandler.showProgressDialog(this);

                // start service with intent
                startService(serviceIntent);
            }
        }
    } else {
        buildLayout(false);
    }
}

From source file:com.amaze.filemanager.fragments.MainFragment.java

void onSavedInstanceState(final Bundle savedInstanceState) {
    Bundle b = new Bundle();
    String cur = savedInstanceState.getString("CURRENT_PATH");

    if (cur != null) {
        b.putInt("index", savedInstanceState.getInt("index"));
        b.putInt("top", savedInstanceState.getInt("top"));
        scrolls.put(cur, b);//from  w  ww. java  2  s .  c om

        openMode = OpenMode.getOpenMode(savedInstanceState.getInt("openMode", 0));
        if (openMode == OpenMode.SMB)
            smbPath = savedInstanceState.getString("SmbPath");
        LIST_ELEMENTS = savedInstanceState.getParcelableArrayList("list");
        CURRENT_PATH = cur;
        folder_count = savedInstanceState.getInt("folder_count", 0);
        file_count = savedInstanceState.getInt("file_count", 0);
        results = savedInstanceState.getBoolean("results");
        getMainActivity().getAppbar().getBottomBar().updatePath(CURRENT_PATH, results,
                MainActivityHelper.SEARCH_TEXT, openMode, folder_count, file_count, this);
        reloadListElements(true, results, !IS_LIST);
        if (savedInstanceState.getBoolean("selection")) {
            for (Integer index : savedInstanceState.getIntegerArrayList("position")) {
                adapter.toggleChecked(index, null);
            }
        }
    }
}

From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java

void retrieveFromSavedInstance(final Bundle savedInstanceState) {
    Bundle b = new Bundle();
    String cur = savedInstanceState.getString("CURRENT_PATH");

    if (cur != null) {
        b.putInt("index", savedInstanceState.getInt("index"));
        b.putInt("top", savedInstanceState.getInt("top"));
        scrolls.put(cur, b);// w w  w  .j av  a2  s .co  m

        openMode = OpenMode.getOpenMode(savedInstanceState.getInt("openMode", 0));
        if (openMode == OpenMode.SMB)
            smbPath = savedInstanceState.getString("SmbPath");
        putLayoutElements(savedInstanceState.<LayoutElement>getParcelableArrayList("list"));
        CURRENT_PATH = cur;
        folder_count = savedInstanceState.getInt("folder_count", 0);
        file_count = savedInstanceState.getInt("file_count", 0);
        results = savedInstanceState.getBoolean("results");
        MAIN_ACTIVITY.updatePath(CURRENT_PATH, results, openMode, folder_count, file_count);
        createViews(getLayoutElements(), true, (CURRENT_PATH), openMode, results, !IS_LIST);
        if (savedInstanceState.getBoolean("selection")) {

            for (int i : savedInstanceState.getIntegerArrayList("position")) {
                adapter.toggleChecked(i, null);
            }
        }
    }
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFilesFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    if (activity == null) {
        activity = (AppCompatActivity) getActivity();
    }/*from w ww  .j  a v  a  2  s.co  m*/

    if (savedInstanceState != null) {
        fileTree = (TorrentContentFileTree) savedInstanceState.getSerializable(TAG_FILE_TREE);
        curDir = (TorrentContentFileTree) savedInstanceState.getSerializable(TAG_CUR_DIR);

    } else {
        ArrayList<BencodeFileItem> files = getArguments().getParcelableArrayList(TAG_FILES);
        ArrayList<Priority> priorities = (ArrayList<Priority>) getArguments().getSerializable(TAG_PRIORITIES);

        if ((files == null || priorities == null) || files.size() != priorities.size()) {
            return;
        }

        fileTree = TorrentContentFileTreeUtils.buildFileTree(files);

        FileTreeDepthFirstSearch<TorrentContentFileTree> search = new FileTreeDepthFirstSearch<TorrentContentFileTree>();

        /* Set priority for selected files */
        for (int i = 0; i < files.size(); i++) {
            if (priorities.get(i) != Priority.IGNORE) {
                BencodeFileItem f = files.get(i);

                TorrentContentFileTree file = search.find(fileTree, f.getIndex());
                if (file != null) {
                    file.setPriority(priorities.get(i));
                    /*
                     * Disable the ability to select the file
                     * because it's being downloaded/download
                     */
                    file.select(TorrentContentFileTree.SelectState.DISABLED);
                }
            }
        }

        /* Is assigned the root dir of the file tree */
        curDir = fileTree;
    }

    filesSize = (TextView) activity.findViewById(R.id.files_size);
    if (filesSize != null) {
        filesSize.setText(String.format(getString(R.string.files_size),
                Formatter.formatFileSize(activity.getApplicationContext(), fileTree.selectedFileSize()),
                Formatter.formatFileSize(activity.getApplicationContext(), fileTree.size())));
    }

    fileList = (RecyclerView) activity.findViewById(R.id.file_list);

    if (fileList != null) {
        layoutManager = new LinearLayoutManager(activity);
        fileList.setLayoutManager(layoutManager);
        /*
         * A RecyclerView by default creates another copy of the ViewHolder in order to
         * fade the views into each other. This causes the problem because the old ViewHolder gets
         * the payload but then the new one doesn't. So needs to explicitly tell it to reuse the old one.
         */
        DefaultItemAnimator animator = new DefaultItemAnimator() {
            @Override
            public boolean canReuseUpdatedViewHolder(RecyclerView.ViewHolder viewHolder) {
                return true;
            }
        };
        fileList.setItemAnimator(animator);
        adapter = new TorrentContentFilesAdapter(getChildren(curDir), activity,
                R.layout.item_torrent_content_file, this);

        fileList.setAdapter(adapter);
    }

    if (savedInstanceState != null) {
        selectedFiles = savedInstanceState.getStringArrayList(TAG_SELECTED_FILES);
        if (savedInstanceState.getBoolean(TAG_IN_ACTION_MODE, false)) {
            actionMode = activity.startActionMode(actionModeCallback);
            adapter.setSelectedItems(savedInstanceState.getIntegerArrayList(TAG_SELECTABLE_ADAPTER));
            actionMode.setTitle(String.valueOf(adapter.getSelectedItemCount()));
        }
    }
}

From source file:com.irccloud.android.fragment.BuffersListFragment.java

@SuppressWarnings("unchecked")
@Override//from  www. ja v  a 2s .com
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    conn = NetworkConnection.getInstance();
    view = inflater.inflate(R.layout.bufferslist, null);
    topUnreadIndicator = (LinearLayout) view.findViewById(R.id.topUnreadIndicator);
    topUnreadIndicator.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int scrollTo = adapter.unreadPositionAbove(getListView().getFirstVisiblePosition());
            if (scrollTo > 0)
                getListView().setSelection(scrollTo - 1);
            else
                getListView().setSelection(0);

            updateUnreadIndicators(getListView().getFirstVisiblePosition(),
                    getListView().getLastVisiblePosition());
        }

    });
    topUnreadIndicatorColor = (LinearLayout) view.findViewById(R.id.topUnreadIndicatorColor);
    topUnreadIndicatorBorder = (LinearLayout) view.findViewById(R.id.topUnreadIndicatorBorder);
    bottomUnreadIndicator = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicator);
    bottomUnreadIndicator.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int offset = getListView().getLastVisiblePosition() - getListView().getFirstVisiblePosition();
            int scrollTo = adapter.unreadPositionBelow(getListView().getLastVisiblePosition()) - offset + 2;
            if (scrollTo < adapter.getCount())
                getListView().setSelection(scrollTo);
            else
                getListView().setSelection(adapter.getCount() - 1);

            updateUnreadIndicators(getListView().getFirstVisiblePosition(),
                    getListView().getLastVisiblePosition());
        }

    });
    bottomUnreadIndicatorColor = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicatorColor);
    bottomUnreadIndicatorBorder = (LinearLayout) view.findViewById(R.id.bottomUnreadIndicatorBorder);
    listView = (ListView) view.findViewById(android.R.id.list);
    listView.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            updateUnreadIndicators(firstVisibleItem, firstVisibleItem + visibleItemCount - 1);
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
            return mListener
                    .onBufferLongClicked(BuffersDataSource.getInstance().getBuffer(adapter.data.get(pos).bid));
        }

    });

    ready = NetworkConnection.getInstance().ready;

    if (ready) {
        if (savedInstanceState != null && savedInstanceState.containsKey("expandedArchives")) {
            ArrayList<Integer> expandedArchives = savedInstanceState.getIntegerArrayList("expandedArchives");
            Iterator<Integer> i = expandedArchives.iterator();
            while (i.hasNext()) {
                Integer cid = i.next();
                mExpandArchives.put(cid, true);
            }
        }
        refreshTask = new RefreshTask();
        refreshTask.doInBackground((Void) null);
        refreshTask.onPostExecute(null);
        if (savedInstanceState != null && savedInstanceState.containsKey("scrollPosition"))
            listView.setSelection(savedInstanceState.getInt("scrollPosition"));
    }
    return view;
}

From source file:mirko.android.datetimepicker.time.TimePickerDialogSupport.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(
            mEnableClearButton ? R.layout.time_picker_dialog_clear : R.layout.time_picker_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mBlue = res.getColor(R.color.blue);/*from ww w  .  j  a  v  a2s.c  om*/
    mBlack = res.getColor(R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode);
    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);
    mDoneButton.setOnKeyListener(keyboardListener);
    mClearButton = (TextView) view.findViewById(R.id.clear_button);
    mClearButton.setOnClickListener(this);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mTimePicker.tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    return view;
}

From source file:com.diandi.widget.googledatetimepicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(R.layout.time_picker_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mBlue = res.getColor(R.color.blue);//from  ww  w  . ja v  a 2s. co m
    mBlack = res.getColor(R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode);
    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                mTimePicker.tryVibrate();
            }
            if (mCallback != null) {
                mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
            }
            dismiss();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mTimePicker.tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    return view;
}

From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialTimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(R.layout.radial_time_picker_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mBlue = res.getColor(R.color.blue);/*from w w w  . j a  va  2  s . c o m*/
    mBlack = res.getColor(R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode);
    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                mTimePicker.tryVibrate();
            }
            if (mCallback != null) {
                mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
            }
            dismiss();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mTimePicker.tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    return view;
}

From source file:com.wecook.uikit.widget.datetimepicker.time.TimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(R.layout.time_picker_dialogs, container);
    KeyboardListener keyboardListener = new KeyboardListener();
    LinearLayout ly = (LinearLayout) view.findViewById(R.id.picker_dialog);
    ly.setOnKeyListener(keyboardListener);

    Resources res = getResources();
    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mBlue = res.getColor(R.color.blue);//from ww w.  j ava  2  s. co  m
    mBlack = res.getColor(R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mInitialHourOfDay, mInitialMinute, mIs24HourMode);
    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            mTimePicker.tryVibrate();
        }
    });

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                mTimePicker.tryVibrate();
            }
            if (mCallback != null) {
                mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
            }
            dismiss();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mTimePicker.tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    return view;
}