Example usage for android.content.res Resources getString

List of usage examples for android.content.res Resources getString

Introduction

In this page you can find the example usage for android.content.res Resources getString.

Prototype

@NonNull
public String getString(@StringRes int id) throws NotFoundException 

Source Link

Document

Return the string value associated with a particular resource ID.

Usage

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private View generateKey(boolean landscape, int keyId) {
    KeyButtonView v = null;/*from   w  w w  .  ja  v a 2 s  .c o  m*/
    Resources r = getResources();

    int btnWidth = 80;

    switch (keyId) {

    case KEY_MENU_RIGHT:
        v = new KeyButtonView(mContext, null);
        v.setLayoutParams(getLayoutParams(landscape, (mTablet_UI == 1) ? 80 : 40));

        v.setId(R.id.menu);
        v.setCode(KeyEvent.KEYCODE_MENU);
        if (mTablet_UI == 1) {
            v.setImageResource(R.drawable.ic_sysbar_menu_big);
            v.setVisibility(View.GONE);
        } else {
            v.setImageResource(landscape ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu);
            v.setVisibility(View.INVISIBLE);
        }
        v.setContentDescription(r.getString(R.string.accessibility_menu));
        v.setGlowBackground(landscape ? R.drawable.ic_sysbar_highlight_land : R.drawable.ic_sysbar_highlight);
        return v;

    case KEY_MENU_LEFT:
        v = new KeyButtonView(mContext, null);
        v.setLayoutParams(getLayoutParams(landscape, (mTablet_UI == 1) ? 80 : 40));

        v.setId(R.id.menu_left);
        v.setCode(KeyEvent.KEYCODE_MENU);
        if (mTablet_UI == 1) {
            v.setImageResource(R.drawable.ic_sysbar_menu_big);
            v.setVisibility(View.GONE);
        } else {
            v.setImageResource(landscape ? R.drawable.ic_sysbar_menu_land : R.drawable.ic_sysbar_menu);
            v.setVisibility(View.INVISIBLE);
        }
        v.setContentDescription(r.getString(R.string.accessibility_menu));
        v.setGlowBackground(landscape ? R.drawable.ic_sysbar_highlight_land : R.drawable.ic_sysbar_highlight);
        return v;

    }

    return null;
}

From source file:at.flack.FacebookMainActivity.java

public void updateContacts(Activity activity) {
    if (MainActivity.getFbcontacts() == null || MainActivity.getFbcontacts().size() <= 0) {
        showErrorMessage(activity, true);
        if (getProgressbar() != null)
            getProgressbar().setVisibility(View.INVISIBLE);
        return;/*from   w  w  w. j ava 2 s. co  m*/
    }
    showErrorMessage(activity, false);

    MainActivity.setFblistItems(new ArrayList<ContactModel>());
    ContactModel model = null;
    Resources res = activity.getResources();
    for (FacebookContact fbc : MainActivity.getFbcontacts()) {
        model = new ContactModel(ProfilePictureCache.getInstance(activity).get(fbc.getName()),
                shortName(fbc.getName()), fbc.getLastMessage(), fbc.getTime(), fbc.isUnread(), fbc.isOnline(),
                fbc.isMobile());
        if (KeySafe.getInstance(activity).contains(fbc.getTid())) {
            KeyEntity key = KeySafe.getInstance(activity).get(fbc.getTid());
            if (key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY) {
                model.setEncrypted(View.VISIBLE);
                try {
                    model.setLastMessage(new Message(model.getLastMessage()).decryptedMessage(key));
                } catch (MessageDecrypterException e) {
                }
            }
        }
        // Pre Shared Exchange
        if ((fbc.getLastMessage().toString().length() == 10 || fbc.getLastMessage().toString().length() == 9)
                && fbc.getLastMessage().toString().charAt(0) == '%') { // 4
            if (Base64.isPureBase64(fbc.getLastMessage().toString().substring(1, 9))) {
                model.setLastMessage(res.getString(R.string.handshake_message));
            }
        }
        // DH Exchange
        if (fbc.getLastMessage().toString().length() >= 120 && fbc.getLastMessage().toString().length() < 125
                && fbc.getLastMessage().toString().charAt(0) == '%') { // DH
            // Exchange!
            if (Base64.isPureBase64(fbc.getLastMessage().toString().substring(1,
                    fbc.getLastMessage().toString().lastIndexOf("=")))) {
                model.setLastMessage(res.getString(R.string.handshake_message));
            }
        }
        if (smiley_helper != null)
            model.setLastMessage(smiley_helper.parseAndroid(model.getLastMessage()));
        MainActivity.getFblistItems().add(model);
    }

    if (contactList != null && contactList.getAdapter() == null) {
        ContactAdapter arrayAdapter = new ContactAdapter(activity, MainActivity.getFblistItems(), 1);
        contactList.setAdapter(arrayAdapter);
        contactList.setSelection(0);

    } else {
        if (contactList != null) {
            ((ContactAdapter) ((HeaderViewListAdapter) contactList.getAdapter()).getWrappedAdapter())
                    .refill(MainActivity.getFblistItems(), 1);

        }
    }
    if (swipe != null)
        swipe.setRefreshing(false);
    if (getProgressbar() != null)
        getProgressbar().setVisibility(View.INVISIBLE);
    if (loadmore != null)
        loadmore.setEnabled(true);

}

From source file:at.flack.MailMainActivity.java

public void updateContactList(MainActivity activity) {
    if (MainActivity.getMailcontacts() == null)
        return;/*from   w w w. j  a v a  2s  . co  m*/
    MainActivity.setMailItems(new ArrayList<ContactModel>());
    ContactModel model = null;
    Resources res = activity.getResources();
    for (Email mail : MainActivity.getMailcontacts()) {//
        model = new ContactModel(ProfilePictureCache.getInstance(activity).get(mail.getSender()),
                mail.getSubject(), mail.getText(), getDate(mail.getDate()), mail.isRead(), mail.getSender(),
                mail.getRecipient(), mail.getSenderName());
        if (KeySafe.getInstance(activity).contains(mail.getSender()) && Base64.isBase64(mail.getSubject())) {
            KeyEntity key = KeySafe.getInstance(activity).get(mail.getSender());
            if (key.getVersion() != KeyEntity.ECDH_PRIVATE_KEY) {
                model.setEncrypted(View.VISIBLE);
                try {
                    model.setTitle(new Message(mail.getSubject()).decryptedMessage(key));
                } catch (MessageDecrypterException e) {
                }
            }
        }
        // Pre Shared Exchange
        if ((mail.getText().toString().length() == 10 || mail.getText().toString().length() == 9)
                && mail.getText().toString().charAt(0) == '%') { // 4
            if (Base64.isPureBase64(mail.getText().toString().substring(1, 9))) {
                model.setTitle(res.getString(R.string.handshake_message));
            }
        }
        // DH Exchange
        if ((mail.getText()).toString().length() >= 120 && mail.getText().toString().length() < 125
                && mail.getText().toString().charAt(0) == '%') { // DH
            // Exchange!
            if (Base64.isPureBase64(
                    mail.getText().toString().substring(1, mail.getText().toString().lastIndexOf("=")))) {
                model.setTitle(res.getString(R.string.handshake_message));
            }
        }
        MainActivity.getMailItems().add(model);
    }

    if (contactList != null && contactList.getAdapter() == null) {
        ContactAdapter arrayAdapter = new ContactAdapter(activity, MainActivity.getMailItems(), 0);
        arrayAdapter.notifyDataSetChanged();
        contactList.setAdapter(arrayAdapter);
        contactList.setSelection(0);
    } else if (MainActivity.getMailItems().size() > 0 && contactList != null) {
        ((ContactAdapter) ((HeaderViewListAdapter) contactList.getAdapter()).getWrappedAdapter())
                .refill(MainActivity.getMailItems(), 0);
    }

    if (swipe != null)
        swipe.setRefreshing(false);
    if (progressbar != null)
        progressbar.setVisibility(View.INVISIBLE);
    if (loadmore != null)
        loadmore.setEnabled(true);
}

From source file:chrisrenke.drawerarrowdrawable.DrawerArrowSample.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_view);/*from  w  w  w.j av  a 2 s.co m*/

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
    final Resources resources = getResources();

    drawerArrowDrawable = new DrawerArrowDrawable(resources);
    drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.green));
    imageView.setImageDrawable(drawerArrowDrawable);

    drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            offset = slideOffset;
            // Sometimes slideOffset ends up so close to but not quite 1 or 0.
            if (slideOffset >= .995) {
                flipped = true;
                drawerArrowDrawable.setFlip(flipped);
            } else if (slideOffset <= .005) {
                flipped = false;
                drawerArrowDrawable.setFlip(flipped);
            }
            drawerArrowDrawable.setParameter(offset);
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawer.isDrawerVisible(START)) {
                drawer.closeDrawer(START);
            } else {
                drawer.openDrawer(START);
            }
        }
    });

    final TextView styleButton = (TextView) findViewById(R.id.indicator_style);
    styleButton.setOnClickListener(new View.OnClickListener() {
        boolean rounded = false;

        @Override
        public void onClick(View v) {
            styleButton.setText(rounded //
                    ? resources.getString(R.string.rounded) //
                    : resources.getString(R.string.squared));

            rounded = !rounded;

            drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded);
            drawerArrowDrawable.setParameter(offset);
            drawerArrowDrawable.setFlip(flipped);
            drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));

            imageView.setImageDrawable(drawerArrowDrawable);
        }
    });
}

From source file:com.ichi2.anki.dialogs.CustomStudyDialog.java

/**
 * Build an input dialog that is used to get a parameter related to custom study from the user
 * @param dialogId//from w ww  . java 2 s .com
 * @return
 */
private MaterialDialog buildInputDialog(final int dialogId) {
    /*
    TODO: Try to change to a standard input dialog (currently the thing holding us back is having the extra
    TODO: hint line for the number of cards available, and having the pre-filled text selected by default)
    */
    // Input dialogs
    Resources res = getActivity().getResources();
    // Show input dialog for an individual custom study dialog
    View v = getActivity().getLayoutInflater().inflate(R.layout.styled_custom_study_details_dialog, null);
    TextView textView1 = (TextView) v.findViewById(R.id.custom_study_details_text1);
    TextView textView2 = (TextView) v.findViewById(R.id.custom_study_details_text2);
    final EditText mEditText = (EditText) v.findViewById(R.id.custom_study_details_edittext2);
    // Set the text
    textView1.setText(getText1());
    textView2.setText(getText2());
    mEditText.setText(getDefaultValue());
    // Give EditText focus and show keyboard
    mEditText.setSelectAllOnFocus(true);
    mEditText.requestFocus();
    // deck id
    final long did = getArguments().getLong("did");
    // Whether or not to jump straight to the reviewer
    final boolean jumpToReviewer = getArguments().getBoolean("jumpToReviewer");
    // Set builder parameters
    MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).customView(v, true)
            .positiveText(res.getString(R.string.dialog_ok)).negativeText(res.getString(R.string.dialog_cancel))
            .callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    Collection col = CollectionHelper.getInstance().getCol(getActivity());
                    // Get the value selected by user
                    int n = Integer.parseInt(mEditText.getText().toString());
                    // Set behavior when clicking OK button
                    switch (dialogId) {
                    case CUSTOM_STUDY_NEW:
                        try {
                            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendNew", n).commit();
                            JSONObject deck = col.getDecks().get(did);
                            deck.put("extendNew", n);
                            col.getDecks().save(deck);
                            col.getSched().extendLimits(n, 0);
                            onLimitsExtended(jumpToReviewer);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_REV:
                        try {
                            AnkiDroidApp.getSharedPrefs(getActivity()).edit().putInt("extendRev", n).commit();
                            JSONObject deck = col.getDecks().get(did);
                            deck.put("extendRev", n);
                            col.getDecks().save(deck);
                            col.getSched().extendLimits(0, n);
                            onLimitsExtended(jumpToReviewer);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_FORGOT:
                        JSONArray ar = new JSONArray();
                        try {
                            ar.put(0, 1);
                            createCustomStudySession(ar,
                                    new Object[] { String.format(Locale.US, "rated:%d:1", n),
                                            Consts.DYN_MAX_SIZE, Consts.DYN_RANDOM },
                                    false);
                        } catch (JSONException e) {
                            throw new RuntimeException(e);
                        }
                        break;
                    case CUSTOM_STUDY_AHEAD:
                        createCustomStudySession(new JSONArray(),
                                new Object[] { String.format(Locale.US, "prop:due<=%d", n), Consts.DYN_MAX_SIZE,
                                        Consts.DYN_DUE },
                                true);
                        break;
                    case CUSTOM_STUDY_RANDOM:
                        createCustomStudySession(new JSONArray(), new Object[] { "", n, Consts.DYN_RANDOM },
                                true);
                        break;
                    case CUSTOM_STUDY_PREVIEW:
                        createCustomStudySession(new JSONArray(), new Object[] {
                                "is:new added:" + Integer.toString(n), Consts.DYN_MAX_SIZE, Consts.DYN_OLDEST },
                                false);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void onNegative(MaterialDialog dialog) {
                    ((AnkiActivity) getActivity()).dismissAllDialogFragments();
                }
            });
    final MaterialDialog dialog = builder.build();
    mEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            if (((EditText) view).getText().length() == 0) {
                dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
            } else {
                dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
            }
            return false;
        }
    });
    // Show soft keyboard
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return dialog;
}

From source file:com.example.drawerarrowdrawable.DrawerArrowSample.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_view);/*from   w  ww. ja  v a 2 s. c o  m*/

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
    final Resources resources = getResources();

    drawerArrowDrawable = new DrawerArrowDrawable(resources);
    drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));
    imageView.setImageDrawable(drawerArrowDrawable);

    drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            offset = slideOffset;

            // Sometimes slideOffset ends up so close to but not quite 1 or 0.
            if (slideOffset >= .995) {
                flipped = true;
                drawerArrowDrawable.setFlip(flipped);
            } else if (slideOffset <= .005) {
                flipped = false;
                drawerArrowDrawable.setFlip(flipped);
            }

            drawerArrowDrawable.setParameter(offset);
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawer.isDrawerVisible(START)) {
                drawer.closeDrawer(START);
            } else {
                drawer.openDrawer(START);
            }
        }
    });

    final TextView styleButton = (TextView) findViewById(R.id.indicator_style);
    styleButton.setOnClickListener(new View.OnClickListener() {
        boolean rounded = false;

        @Override
        public void onClick(View v) {
            styleButton.setText(rounded //
                    ? resources.getString(R.string.rounded) //
                    : resources.getString(R.string.squared));

            rounded = !rounded;

            drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded);
            drawerArrowDrawable.setParameter(offset);
            drawerArrowDrawable.setFlip(flipped);
            drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));

            imageView.setImageDrawable(drawerArrowDrawable);
        }
    });
}

From source file:com.ichi2.libanki.Collection.java

/** Undo menu item name, or "" if undo unavailable. */
public String undoName(Resources res) {
    if (mUndo.size() > 0) {
        int undoType = (Integer) mUndo.getLast()[0];
        if (undoType >= 0 && undoType < fUndoNames.length) {
            return res.getString(fUndoNames[undoType]);
        }// w  ww .  ja  v  a2  s  .co m
    }
    return "";
}

From source file:cn.flyrise.android3.test.graphic.DrawerArrowSample.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_view);//from www  .  j ava 2s .c om

    final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    final ImageView imageView = (ImageView) findViewById(R.id.drawer_indicator);
    final Resources resources = getResources();

    drawerArrowDrawable = new DrawerArrowDrawable(resources);
    drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));
    imageView.setImageDrawable(drawerArrowDrawable);

    drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            Log.e("Test", "slideOffset==" + slideOffset);
            offset = slideOffset;

            // Sometimes slideOffset ends up so close to but not quite 1 or 0.
            if (slideOffset >= .995) {
                flipped = true;
                drawerArrowDrawable.setFlip(flipped);
            } else if (slideOffset <= .005) {
                flipped = false;
                drawerArrowDrawable.setFlip(flipped);
            }

            drawerArrowDrawable.setParameter(offset);
        }
    });

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (drawer.isDrawerVisible(START)) {
                drawer.closeDrawer(START);
            } else {
                drawer.openDrawer(START);
            }
        }
    });

    final TextView styleButton = (TextView) findViewById(R.id.indicator_style);
    styleButton.setOnClickListener(new View.OnClickListener() {
        boolean rounded = false;

        @Override
        public void onClick(View v) {
            styleButton.setText(rounded //
                    ? resources.getString(R.string.rounded) //
                    : resources.getString(R.string.squared));

            rounded = !rounded;

            drawerArrowDrawable = new DrawerArrowDrawable(resources, rounded);
            drawerArrowDrawable.setParameter(offset);
            drawerArrowDrawable.setFlip(flipped);
            drawerArrowDrawable.setStrokeColor(resources.getColor(R.color.light_gray));

            imageView.setImageDrawable(drawerArrowDrawable);
        }
    });
}

From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java

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

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

    // If an accent color has not been set manually, get it from the context
    if (mAccentColor == -1) {
        mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
    }//from   w w w. j  av  a  2s  .c om

    // if theme mode has not been set by java code, check if it is specified in Style.xml
    if (!mThemeDarkChanged) {
        mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark);
    }

    Resources res = getResources();
    Context context = getActivity();
    mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description);
    mSelectHours = res.getString(R.string.mdtp_select_hours);
    mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description);
    mSelectMinutes = res.getString(R.string.mdtp_select_minutes);
    mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description);
    mSelectSeconds = res.getString(R.string.mdtp_select_seconds);
    mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused);

    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);
    mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space);
    mSecondView = (TextView) view.findViewById(R.id.seconds);
    mSecondView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());
    mInitialTime = roundToNearest(mInitialTime);

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), this, mInitialTime, 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);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mSecondView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            setCurrentItemShowing(SECOND_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mOkButton = (Button) view.findViewById(R.id.ok);
    mOkButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            notifyOnDateListener();
            dismiss();
        }
    });
    mOkButton.setOnKeyListener(keyboardListener);
    mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mOkString != null)
        mOkButton.setText(mOkString);
    else
        mOkButton.setText(mOkResid);

    mCancelButton = (Button) view.findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null)
                getDialog().cancel();
        }
    });
    mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium"));
    if (mCancelString != null)
        mCancelButton.setText(mCancelString);
    else
        mCancelButton.setText(mCancelResid);
    mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialTime.isAM() ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Don't do anything if either AM or PM are disabled
                if (isAmDisabled() || isPmDisabled())
                    return;

                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    // Disable seconds picker
    if (!mEnableSeconds) {
        mSecondSpaceView.setVisibility(View.GONE);
        view.findViewById(R.id.separator_seconds).setVisibility(View.GONE);
    }

    // Center stuff depending on what's visible
    if (mIs24HourMode && !mEnableSeconds) {
        // center first separator
        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 if (mEnableSeconds) {
        // link separator to minutes
        final View separator = view.findViewById(R.id.separator);
        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space);
        paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        separator.setLayoutParams(paramsSeparator);

        if (!mIs24HourMode) {
            // center minutes
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        } else {
            // move minutes to right of center
            RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view);
            mMinuteSpaceView.setLayoutParams(paramsMinutes);
        }
    }

    mAllowAutoAdvance = true;
    setHour(mInitialTime.getHour(), true);
    setMinute(mInitialTime.getMinute());
    setSecond(mInitialTime.getSecond());

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.mdtp_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<>();
    }

    // Set the title (if any)
    TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header);
    if (!mTitle.isEmpty()) {
        timePickerHeader.setVisibility(TextView.VISIBLE);
        timePickerHeader.setText(mTitle);
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mOkButton.setTextColor(mAccentColor);
    mCancelButton.setTextColor(mAccentColor);
    timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor));
    view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor);
    view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor);

    if (getDialog() == null) {
        view.findViewById(R.id.done_background).setVisibility(View.GONE);
    }

    int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background);
    int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color);
    int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray);
    int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray);

    mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground);
    view.findViewById(R.id.time_picker_dialog)
            .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor);
    return view;
}

From source file:com.delexus.imitationzhihu.MySearchView.java

/**
 * Create and return an Intent that can launch the voice search activity, perform a specific
 * voice transcription, and forward the results to the searchable activity.
 *
 * @param baseIntent The voice app search intent to start from
 * @return A completely-configured intent ready to send to the voice search activity
 *//*from   w  w w.ja v a  2  s.  c om*/
private Intent createVoiceAppSearchIntent(Intent baseIntent, SearchableInfo searchable) {
    ComponentName searchActivity = searchable.getSearchActivity();

    // create the necessary intent to set up a search-and-forward operation
    // in the voice search system.   We have to keep the bundle separate,
    // because it becomes immutable once it enters the PendingIntent
    Intent queryIntent = new Intent(Intent.ACTION_SEARCH);
    queryIntent.setComponent(searchActivity);
    PendingIntent pending = PendingIntent.getActivity(getContext(), 0, queryIntent,
            PendingIntent.FLAG_ONE_SHOT);

    // Now set up the bundle that will be inserted into the pending intent
    // when it's time to do the search.  We always build it here (even if empty)
    // because the voice search activity will always need to insert "QUERY" into
    // it anyway.
    Bundle queryExtras = new Bundle();
    if (mAppSearchData != null) {
        queryExtras.putParcelable(SearchManager.APP_DATA, mAppSearchData);
    }

    // Now build the intent to launch the voice search.  Add all necessary
    // extras to launch the voice recognizer, and then all the necessary extras
    // to forward the results to the searchable activity
    Intent voiceIntent = new Intent(baseIntent);

    // Add all of the configuration options supplied by the searchable's metadata
    String languageModel = RecognizerIntent.LANGUAGE_MODEL_FREE_FORM;
    String prompt = null;
    String language = null;
    int maxResults = 1;

    Resources resources = getResources();
    if (searchable.getVoiceLanguageModeId() != 0) {
        languageModel = resources.getString(searchable.getVoiceLanguageModeId());
    }
    if (searchable.getVoicePromptTextId() != 0) {
        prompt = resources.getString(searchable.getVoicePromptTextId());
    }
    if (searchable.getVoiceLanguageId() != 0) {
        language = resources.getString(searchable.getVoiceLanguageId());
    }
    if (searchable.getVoiceMaxResults() != 0) {
        maxResults = searchable.getVoiceMaxResults();
    }

    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, languageModel);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, prompt);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResults);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
            searchActivity == null ? null : searchActivity.flattenToShortString());

    // Add the values that configure forwarding the results
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT, pending);
    voiceIntent.putExtra(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT_BUNDLE, queryExtras);

    return voiceIntent;
}