Example usage for android.os Bundle containsKey

List of usage examples for android.os Bundle containsKey

Introduction

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

Prototype

public boolean containsKey(String key) 

Source Link

Document

Returns true if the given key is contained in the mapping of this Bundle.

Usage

From source file:cgeo.geocaching.CacheListActivity.java

@Override
public Loader<SearchResult> onCreateLoader(final int type, final Bundle extras) {
    if (type >= CacheListLoaderType.values().length) {
        throw new IllegalArgumentException("invalid loader type " + type);
    }//  w  ww .  ja v a2  s  . c o  m
    final CacheListLoaderType enumType = CacheListLoaderType.values()[type];
    AbstractSearchLoader loader = null;
    switch (enumType) {
    case OFFLINE:
        // open either the requested or the last list
        if (extras.containsKey(Intents.EXTRA_LIST_ID)) {
            listId = extras.getInt(Intents.EXTRA_LIST_ID);
        } else {
            listId = Settings.getLastDisplayedList();
        }
        if (listId == PseudoList.ALL_LIST.id) {
            title = res.getString(R.string.list_all_lists);
        } else if (listId <= StoredList.TEMPORARY_LIST.id) {
            listId = StoredList.STANDARD_LIST_ID;
            title = res.getString(R.string.stored_caches_button);
        } else {
            final StoredList list = DataStore.getList(listId);
            // list.id may be different if listId was not valid
            if (list.id != listId) {
                showToast(getString(R.string.list_not_available));
            }
            listId = list.id;
            title = list.title;
        }

        loader = new OfflineGeocacheListLoader(this, coords, listId);

        break;
    case HISTORY:
        title = res.getString(R.string.caches_history);
        listId = PseudoList.HISTORY_LIST.id;
        loader = new HistoryGeocacheListLoader(this, coords);
        break;
    case NEAREST:
        title = res.getString(R.string.caches_nearby);
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case COORDINATE:
        title = coords.toString();
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case KEYWORD:
        final String keyword = extras.getString(Intents.EXTRA_KEYWORD);
        title = listNameMemento.rememberTerm(keyword);
        if (keyword != null) {
            loader = new KeywordGeocacheListLoader(this, keyword);
        }
        break;
    case ADDRESS:
        final String address = extras.getString(Intents.EXTRA_ADDRESS);
        if (StringUtils.isNotBlank(address)) {
            title = listNameMemento.rememberTerm(address);
        } else {
            title = coords.toString();
        }
        loader = new CoordsGeocacheListLoader(this, coords);
        break;
    case FINDER:
        final String username = extras.getString(Intents.EXTRA_USERNAME);
        title = listNameMemento.rememberTerm(username);
        if (username != null) {
            loader = new FinderGeocacheListLoader(this, username);
        }
        break;
    case OWNER:
        final String ownerName = extras.getString(Intents.EXTRA_USERNAME);
        title = listNameMemento.rememberTerm(ownerName);
        if (ownerName != null) {
            loader = new OwnerGeocacheListLoader(this, ownerName);
        }
        break;
    case MAP:
        //TODO Build Null loader
        title = res.getString(R.string.map_map);
        search = (SearchResult) extras.get(Intents.EXTRA_SEARCH);
        replaceCacheListFromSearch();
        loadCachesHandler.sendMessage(Message.obtain());
        break;
    case NEXT_PAGE:
        loader = new NextPageGeocacheListLoader(this, search);
        break;
    case POCKET:
        final String guid = extras.getString(Intents.EXTRA_POCKET_GUID);
        title = listNameMemento.rememberTerm(extras.getString(Intents.EXTRA_NAME));
        loader = new PocketGeocacheListLoader(this, guid);
        break;
    }
    // if there is a title given in the activity start request, use this one instead of the default
    if (extras != null && StringUtils.isNotBlank(extras.getString(Intents.EXTRA_TITLE))) {
        title = extras.getString(Intents.EXTRA_TITLE);
    }
    if (loader != null && extras != null && extras.getSerializable(BUNDLE_ACTION_KEY) != null) {
        final AfterLoadAction action = (AfterLoadAction) extras.getSerializable(BUNDLE_ACTION_KEY);
        loader.setAfterLoadAction(action);
    }
    updateTitle();
    showProgress(true);
    showFooterLoadingCaches();

    return loader;
}

From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is
 * {@code MediaMetaData.MEDIA_TYPE_MOVIE}
 *
 * @see <code>mediaInfoToBundle()</code>
 *//*from   w ww  .j a v  a 2s  .c  o  m*/
public static MediaInfo bundleToMediaInfo(Bundle wrapper) {
    if (wrapper == null) {
        return null;
    }

    MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE));
    metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE));
    metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO));
    ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
    if (images != null && !images.isEmpty()) {
        for (String url : images) {
            Uri uri = Uri.parse(url);
            metaData.addImage(new WebImage(uri));
        }
    }
    String customDataStr = wrapper.getString(KEY_CUSTOM_DATA);
    JSONObject customData = null;
    if (!TextUtils.isEmpty(customDataStr)) {
        try {
            customData = new JSONObject(customDataStr);
        } catch (JSONException e) {
            LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr);
        }
    }
    List<MediaTrack> mediaTracks = null;
    if (wrapper.getString(KEY_TRACKS_DATA) != null) {
        try {
            JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA));
            mediaTracks = new ArrayList<MediaTrack>();
            if (jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObj = (JSONObject) jsonArray.get(i);
                    MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID),
                            jsonObj.getInt(KEY_TRACK_TYPE));
                    if (jsonObj.has(KEY_TRACK_NAME)) {
                        builder.setName(jsonObj.getString(KEY_TRACK_NAME));
                    }
                    if (jsonObj.has(KEY_TRACK_SUBTYPE)) {
                        builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE));
                    }
                    if (jsonObj.has(KEY_TRACK_CONTENT_ID)) {
                        builder.setContentId(jsonObj.getString(KEY_TRACK_CONTENT_ID));
                    }
                    if (jsonObj.has(KEY_TRACK_LANGUAGE)) {
                        builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE));
                    }
                    if (jsonObj.has(KEY_TRACKS_DATA)) {
                        builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA)));
                    }
                    mediaTracks.add(builder.build());
                }
            }
        } catch (JSONException e) {
            LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e);
        }
    }
    MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL))
            .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE))
            .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks);

    if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) {
        mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION));
    }

    return mediaBuilder.build();
}

From source file:com.example.alvarpao.popularmovies.MovieGridFragment.java

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

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // The adapter is initialized with an empty array if state wasn't restore on rotation, if
    // it was, the array of movies already has the saved data.
    //Toast.makeText(getActivity(), "mMovies size restored: " + mMovies.size(), Toast.LENGTH_SHORT).show();
    mMovieAdapter = new MovieAdapter(getActivity(), mMovies);
    mMoviesGridView = (GridView) rootView.findViewById(R.id.movies_grid);
    mMoviesGridView.setDrawSelectorOnTop(true);
    mMoviesGridView.setAdapter(mMovieAdapter);
    mMoviesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // This will force to draw the selector on top of the poster for the selected movie
            view.setSelected(true);//from   w  w  w  .  j a  v a 2 s.c o  m
            mSelectedMovie = position;
            // A selection occurred as opposed to selecting the first visible item by default
            // so the details fragment is not empty in the two-pane layout.
            mSelectionOccurred = true;
            //Toast.makeText(getActivity(), "Selected Movie: " +
            // ((Movie) mMoviesGridView.getItemAtPosition(position)).getOriginalTitle(),
            // Toast.LENGTH_SHORT).show();
            Movie movie = mMovieAdapter.getItem(position);
            // A movie has been selected so the MainActivity has to be notified to take
            // appropriate action
            ((Callback) getActivity()).onItemSelected(movie);
        }
    });

    // Handles pagination for movie grid, except in the case the sort option is "Favorites",
    // since we don't need pagination in that case
    mMoviesGridView.setOnScrollListener(this);

    // If a rotation occurred, restore the selected movie (either selected by the user or
    // "selected" by default (first visible movie before rotation))
    // The restore of the details fragment with this selected after rotation is handled in the
    // onCreateOptionsMenu() method which is called after onCreateView()
    if (savedInstanceState != null && savedInstanceState.containsKey((SELECTED_MOVIE)))
        mSelectedMovie = savedInstanceState.getInt(SELECTED_MOVIE);

    return rootView;
}

From source file:co.taqat.call.LinphoneActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Bundle extras = intent.getExtras();
    if (extras != null && extras.getBoolean("GoToChat", false)) {
        LinphoneService.instance().removeMessageNotification();
        String sipUri = extras.getString("ChatContactSipUri");
        doNotGoToCallActivity = true;//w w w .  j  a va2s . c om
        displayChat(sipUri);
    } else if (extras != null && extras.getBoolean("GoToHistory", false)) {
        doNotGoToCallActivity = true;
        changeCurrentFragment(FragmentsAvailable.HISTORY_LIST, null);
    } else if (extras != null && extras.getBoolean("GoToInapp", false)) {
        LinphoneService.instance().removeMessageNotification();
        doNotGoToCallActivity = true;
        displayInapp();
    } else if (extras != null && extras.getBoolean("Notification", false)) {
        if (LinphoneManager.getLc().getCallsNb() > 0) {
            LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
            startIncallActivity(call);
        }
    } else {
        DialerFragment dialerFragment = DialerFragment.instance();
        if (dialerFragment != null) {
            if (extras != null && extras.containsKey("SipUriOrNumber")) {
                if (getResources().getBoolean(R.bool.automatically_start_intercepted_outgoing_gsm_call)) {
                    ((DialerFragment) dialerFragment).newOutgoingCall(extras.getString("SipUriOrNumber"));
                } else {
                    ((DialerFragment) dialerFragment)
                            .displayTextInAddressBar(extras.getString("SipUriOrNumber"));
                }
            } else {
                ((DialerFragment) dialerFragment).newOutgoingCall(intent);
            }
        }
        if (LinphoneManager.getLc().getCalls().length > 0) {
            // If a call is ringing, start incomingcallactivity
            Collection<LinphoneCall.State> incoming = new ArrayList<LinphoneCall.State>();
            incoming.add(LinphoneCall.State.IncomingReceived);
            if (LinphoneUtils.getCallsInState(LinphoneManager.getLc(), incoming).size() > 0) {
                if (CallActivity.isInstanciated()) {
                    CallActivity.instance().startIncomingCallActivity();
                } else {
                    startActivity(new Intent(this, CallIncomingActivity.class));
                }
            }
        }
    }
}

From source file:br.com.casadalagoa.vorf.BoatFragment.java

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

    // The ArrayAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mBoatAdapter = new BoatAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    View descView = inflater.inflate(R.layout.list_item_description, container, false);
    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_boats);
    mListView.addHeaderView(descView);/*from   w  w  w.j  a  va2s . c  o m*/
    mListView.setAdapter(mBoatAdapter);
    mBoatAdapter.setUseTodayLayout(false);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Context mContext = getActivity().getBaseContext();
            if (position == 0) {
                String show = Utility.getNextEventShow(mContext) ? "false" : "true";
                switch (Utility.getNextEventIdx(mContext)) {
                case 0:
                    Utility.setNextEventShow(mContext, show);
                    Utility.setNextEventTimeInUse(mContext, Utility.getNextEventTime(mContext));
                    Utility.setNextEventTitleInUse(mContext, Utility.getNextEventTitle(mContext));
                    break;
                case 1:
                    Utility.setNextEventTimeInUse(mContext, Utility.getNextUpdateLong(mContext));
                    Utility.setNextEventTitleInUse(mContext, "NxtUpdate");
                    break;
                case 2:
                    Utility.setNextEventShow(mContext, show);
                    break;
                }
                Log.v("SetCrono: ",
                        show + " " + Utility.getNextEventTimeInUse(mContext)
                                + Utility.getNextEventTitleInUse(mContext)
                                + String.valueOf(Utility.getNextEventIdx(mContext)));
                Utility.setNextEventTimeIdx(mContext);
            } else {
                Cursor cursor = mBoatAdapter.getCursor();
                if (cursor != null && cursor.moveToPosition(position - 1)) {
                    ((Callback) getActivity()).onItemSelected(cursor.getString(COL_BOAT_ID));
                    Utility.setPreferredBoat(mContext, cursor.getString(COL_BOAT_CODE));
                }
            }
            updateBoat();
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their device sideways
    // does crazy lifecycle related things.  It should feel like some stuff stretched out,
    // or magically appeared to take advantage of room, but data or place in the app was never
    // actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    //mBoatAdapter.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.chatwing.whitelabel.activities.CommunicationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ChatWing.instance(getApplicationContext()).getChatwingGraph().plus();

    setContentView(R.layout.activity_communication);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from ww w .ja v a  2  s  .  co m

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);

    mBus.register(this);

    mContentView = findViewById(R.id.fragment_container);
    mProgressView = findViewById(R.id.progress_container);
    mProgressBar = (ProgressBar) mProgressView.findViewById(R.id.loading_view);
    mProgressText = (TextView) mProgressView.findViewById(R.id.progress_text);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mLoadingView = (ProgressBar) findViewById(R.id.progress_bar);

    mNewMessageSoundId = getSoundNewMessageId();

    mChatboxModeManager.onCreate(savedInstanceState);
    mConversationModeManager.onCreate(savedInstanceState);

    stopRefreshAnimation();

    //This mode is priority due to user action requesting open
    int actionMode = getActionMode(getIntent());
    LogUtils.v("Intent to use actionMode mode " + actionMode);

    int pauseSavedMode = mCommunicationActivityManager.getInt(R.string.current_mode_state, 0);
    int currentMode = MODE_CHAT_BOX; //Default mode is chatbox

    if (pauseSavedMode != 0) {
        currentMode = pauseSavedMode;
    }

    if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_CURRENT_MODE)) {
        currentMode = savedInstanceState.getInt(EXTRA_CURRENT_MODE);
    }

    //Override current mode by priority mode
    if (actionMode != MODE_NONE) {
        currentMode = actionMode;
    }

    if (currentMode == MODE_CHAT_BOX) {
        setupChatboxMode();
    } else {
        setupConversationMode();
    }

    mIsCreated = true;

    String action = getIntent().getAction();
    if (ACTION_STOP_MEDIA.equals(action)) {
        startService(new Intent(MusicService.ACTION_STOP));
    }

    if (!mBuildManager.isOfficialChatWingApp() && userManager.getCurrentUser() == null) {
        startActivity(new Intent(this, WhiteLabelCoverActivity.class));
        finish();
        return;
    }

    String onlineFragmentTag = getString(R.string.fragment_tag_online_user);
    if (getSupportFragmentManager().findFragmentByTag(onlineFragmentTag) == null) {
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.right_drawer_container, new OnlineUsersFragment(), onlineFragmentTag);
        fragmentTransaction.commit();
    }

    String adsFragmentTag = getString(R.string.fragment_tag_ads);
    if (mBuildManager.isSupportedAds()
            && getSupportFragmentManager().findFragmentByTag(adsFragmentTag) == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.ads_container, new AdFragment(), adsFragmentTag)
                .commit();
    }

    //We start our lovely ChatService so that it listen to faye server
    startService(new Intent(this, ChatWingChatService.class));
}

From source file:org.getlantern.firetweet.util.Utils.java

public static long[] getAccountIds(Bundle args) {
    final long[] accountIds;
    if (args.containsKey(EXTRA_ACCOUNT_IDS)) {
        accountIds = args.getLongArray(EXTRA_ACCOUNT_IDS);
    } else if (args.containsKey(EXTRA_ACCOUNT_ID)) {
        accountIds = new long[] { args.getLong(EXTRA_ACCOUNT_ID, -1) };
    } else {//  w  ww.  ja v  a 2s .co m
        accountIds = null;
    }
    return accountIds;
}

From source file:com.a.mirko.android.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_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);//w  w  w  .  j ava 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);
    if (Build.VERSION.SDK_INT <= 14) {

        mAmPmTextView.setTransformationMethod(new TransformationMethod() {

            private final Locale locale = getResources().getConfiguration().locale;

            @Override
            public CharSequence getTransformation(CharSequence source, View view) {
                return source != null ? source.toString().toUpperCase(locale) : null;
            }

            @Override
            public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction,
                    Rect previouslyFocusedRect) {

            }
        });
    }
    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, mVibrate);
    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) {
            onDoneButtonClick();
        }
    });
    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:cn.fulldroid.lib.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_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.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 = ContextCompat.getColor(getContext(), R.color.blue);
    mBlack = ContextCompat.getColor(getContext(), 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);
    if (Build.VERSION.SDK_INT <= 14) {

        mAmPmTextView.setTransformationMethod(new TransformationMethod() {

            private final Locale locale = getResources().getConfiguration().locale;

            @Override// w ww . j a  v a 2 s .  c om
            public CharSequence getTransformation(CharSequence source, View view) {
                return source != null ? source.toString().toUpperCase(locale) : null;
            }

            @Override
            public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction,
                    Rect previouslyFocusedRect) {

            }
        });
    }
    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, mVibrate);
    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) {
            onDoneButtonClick();
        }
    });
    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;
}