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.coderstory.FTool.utils.licensesdialog.LicensesDialogFragment.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Resources resources = getResources();

    if (savedInstanceState != null) {
        mTitleText = savedInstanceState.getString(STATE_TITLE_TEXT);
        mLicensesText = savedInstanceState.getString(STATE_LICENSES_TEXT);
        mCloseButtonText = savedInstanceState.getString(STATE_CLOSE_TEXT);
        if (savedInstanceState.containsKey(STATE_THEME_XML_ID)) {
            mThemeResourceId = savedInstanceState.getInt(STATE_THEME_XML_ID);
        }//from   w ww .  j  a  v a2  s .co m
        if (savedInstanceState.containsKey(STATE_DIVIDER_COLOR)) {
            mDividerColor = savedInstanceState.getInt(STATE_DIVIDER_COLOR);
        }
    } else {
        mTitleText = resources.getString(R.string.notices_title);
        mCloseButtonText = resources.getString(R.string.notices_close);
        try {
            final Notices notices;
            final Bundle arguments = getArguments();
            if (arguments != null) {
                if (arguments.containsKey(ARGUMENT_NOTICES_XML_ID)) {
                    notices = NoticesXmlParser.parse(resources.openRawResource(getNoticesXmlResourceId()));
                } else if (arguments.containsKey(ARGUMENT_NOTICES)) {
                    notices = arguments.getParcelable(ARGUMENT_NOTICES);
                } else {
                    throw new IllegalStateException("Missing ARGUMENT_NOTICES_XML_ID / ARGUMENT_NOTICES");
                }
                if (arguments.getBoolean(ARGUMENT_INCLUDE_OWN_LICENSE, false)) {
                    notices.getNotices().add(LicensesDialog.LICENSES_DIALOG_NOTICE);
                }
                final boolean showFullLicenseText = arguments.getBoolean(ARGUMENT_FULL_LICENSE_TEXT, false);
                if (arguments.containsKey(ARGUMENT_THEME_XML_ID)) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        mThemeResourceId = arguments.getInt(ARGUMENT_THEME_XML_ID,
                                android.R.style.Theme_DeviceDefault_Light_Dialog);
                    } else {
                        mThemeResourceId = arguments.getInt(ARGUMENT_THEME_XML_ID);
                    }
                }
                if (arguments.containsKey(ARGUMENT_DIVIDER_COLOR)) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        mDividerColor = arguments.getInt(ARGUMENT_DIVIDER_COLOR,
                                android.R.color.holo_blue_light);
                    } else {
                        mDividerColor = arguments.getInt(ARGUMENT_DIVIDER_COLOR);
                    }
                }
                mLicensesText = NoticesHtmlBuilder.create(getActivity()).setNotices(notices)
                        .setShowFullLicenseText(showFullLicenseText).build();
            } else {
                throw new IllegalStateException("Missing arguments");
            }
        } catch (final Exception e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

private List<DirectorySearchParams> setupOtherDirectories(Cursor directoryCursor) {
    final PackageManager packageManager = mContext.getPackageManager();
    final List<DirectorySearchParams> paramsList = new ArrayList<DirectorySearchParams>();
    DirectorySearchParams preferredDirectory = null;
    while (directoryCursor.moveToNext()) {
        final long id = directoryCursor.getLong(DirectoryListQuery.ID);

        // Skip the local invisible directory, because the default directory already includes
        // all local results.
        if (id == Directory.LOCAL_INVISIBLE) {
            continue;
        }/*from  w ww  .  j av a 2  s.c  o m*/

        final DirectorySearchParams params = new DirectorySearchParams();
        final String packageName = directoryCursor.getString(DirectoryListQuery.PACKAGE_NAME);
        final int resourceId = directoryCursor.getInt(DirectoryListQuery.TYPE_RESOURCE_ID);
        params.directoryId = id;
        params.displayName = directoryCursor.getString(DirectoryListQuery.DISPLAY_NAME);
        params.accountName = directoryCursor.getString(DirectoryListQuery.ACCOUNT_NAME);
        params.accountType = directoryCursor.getString(DirectoryListQuery.ACCOUNT_TYPE);
        if (packageName != null && resourceId != 0) {
            try {
                final Resources resources = packageManager.getResourcesForApplication(packageName);
                params.directoryType = resources.getString(resourceId);
                if (params.directoryType == null) {
                    Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName);
                }
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Cannot resolve directory name: " + resourceId + "@" + packageName, e);
            }
        }

        // If an account has been provided and we found a directory that
        // corresponds to that account, place that directory second, directly
        // underneath the local contacts.
        if (mAccount != null && mAccount.name.equals(params.accountName)
                && mAccount.type.equals(params.accountType)) {
            preferredDirectory = params;
        } else {
            paramsList.add(params);
        }
    }

    if (preferredDirectory != null) {
        paramsList.add(1, preferredDirectory);
    }

    return paramsList;
}

From source file:com.ichi2.anki.Feedback.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    Context context = getBaseContext();
    SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
    mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);

    mNonce = UUID.randomUUID().getMostSignificantBits();
    mFeedbackUrl = res.getString(R.string.feedback_post_url);
    mErrorUrl = res.getString(R.string.error_post_url);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mPostingFeedback = false;/*ww  w . j  av a2  s .co  m*/
    initAllAlertDialogs();

    getErrorFiles();
    Intent i = getIntent();
    mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK
            || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR))
            || mReportErrorMode.equals(REPORT_ASK);
    if (!mAllowFeedback) {
        if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report
            try {
                String feedback = "Automatically sent";
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), true }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
            } catch (Exception e) {
                Log.e(AnkiDroidApp.TAG, e.toString());
            }
            finish();
            ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            return;
        } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report
            deleteFiles(false, false);
            finish();
            ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            return;
        }
    }

    View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
    Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));

    Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
    Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
    Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
    mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
    mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);

    mErrorAdapter = new SimpleAdapter(this, mErrorReports, R.layout.error_item,
            new String[] { "name", "state", "result" },
            new int[] { R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status });
    mErrorAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            switch (view.getId()) {
            case R.id.error_item_progress:
                if (text.equals(STATE_UPLOADING)) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    view.setVisibility(View.GONE);
                }
                return true;
            case R.id.error_item_status:
                if (text.length() == 0) {
                    view.setVisibility(View.GONE);
                    return true;
                } else {
                    view.setVisibility(View.VISIBLE);
                    return false;
                }
            }
            return false;
        }
    });

    btnClearAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, false);
            refreshErrorListView();
            refreshInterface();
        }
    });

    mLvErrorList.setAdapter(mErrorAdapter);

    btnSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPostingFeedback) {
                String feedback = mEtFeedbackText.getText().toString();
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), false }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
                refreshInterface();
            }
        }
    });

    btnKeepLatest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, true);
            refreshErrorListView();
            refreshInterface();
        }
    });

    refreshInterface();

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_SEARCH:
        mBottomBarControls.showSearch(true);
        break;// w  ww. jav  a  2s  . com
    case MENU_PLAYBACK:
        openPlaybackActivity();
        break;
    case MENU_GO_HOME:
        mPagerAdapter.setLimiter(FileSystemAdapter.buildHomeLimiter(getApplicationContext()));
        updateLimiterViews();
        break;
    case MENU_SORT: {
        SortableAdapter adapter = (SortableAdapter) mCurrentAdapter;
        LinearLayout list = (LinearLayout) getLayoutInflater().inflate(R.layout.sort_dialog, null);
        CheckBox reverseSort = (CheckBox) list.findViewById(R.id.reverse_sort);

        int[] itemIds = adapter.getSortEntries();
        String[] items = new String[itemIds.length];
        Resources res = getResources();
        for (int i = 0; i < itemIds.length; i++) {
            items[i] = res.getString(itemIds[i]);
        }

        int mode = adapter.getSortModeIndex();
        reverseSort.setChecked(adapter.isSortDescending());

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.sort_by);
        builder.setSingleChoiceItems(items, mode, this);
        builder.setPositiveButton(R.string.done, null);

        AlertDialog dialog = builder.create();
        dialog.getListView().addFooterView(list);
        dialog.setOnDismissListener(this);
        dialog.show();
        break;
    }
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

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  w  w  w.  j av a 2s . 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.hichinaschool.flashcards.anki.Feedback.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    Context context = getBaseContext();
    SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
    mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);

    mNonce = UUID.randomUUID().getMostSignificantBits();
    mFeedbackUrl = res.getString(R.string.feedback_post_url);
    mErrorUrl = res.getString(R.string.error_post_url);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mPostingFeedback = false;/*from  w w  w. j  ava2 s. c o  m*/
    initAllAlertDialogs();

    getErrorFiles();
    Intent i = getIntent();
    mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK
            || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR))
            || mReportErrorMode.equals(REPORT_ASK);
    if (!mAllowFeedback) {
        if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report
            try {
                String feedback = "Automatically sent";
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), true }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
            } catch (Exception e) {
                Log.e(AnkiDroidApp.TAG, e.toString());
            }
            finish();
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            }
            return;
        } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report
            deleteFiles(false, false);
            finish();
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            }
            return;
        }
    }

    View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
    Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));

    Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
    Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
    Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
    mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
    mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);

    mErrorAdapter = new SimpleAdapter(this, mErrorReports, R.layout.error_item,
            new String[] { "name", "state", "result" },
            new int[] { R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status });
    mErrorAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            switch (view.getId()) {
            case R.id.error_item_progress:
                if (text.equals(STATE_UPLOADING)) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    view.setVisibility(View.GONE);
                }
                return true;
            case R.id.error_item_status:
                if (text.length() == 0) {
                    view.setVisibility(View.GONE);
                    return true;
                } else {
                    view.setVisibility(View.VISIBLE);
                    return false;
                }
            }
            return false;
        }
    });

    btnClearAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, false);
            refreshErrorListView();
            refreshInterface();
        }
    });

    mLvErrorList.setAdapter(mErrorAdapter);

    btnSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPostingFeedback) {
                String feedback = mEtFeedbackText.getText().toString();
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), false }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
                refreshInterface();
            }
        }
    });

    btnKeepLatest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, true);
            refreshErrorListView();
            refreshInterface();
        }
    });

    refreshInterface();

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

}

From source file:com.borax12.materialdaterangepicker.date.MonthView.java

public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;/*from   www .  j  a va 2 s.c o m*/
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.mdtrp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtrp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
        mDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_normal_dark_theme);
        mMonthDayTextColor = res.getColor(R.color.mdtrp_date_picker_month_day_dark_theme);
        mDisabledDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_disabled_dark_theme);
        mHighlightedDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_highlighted_dark_theme);
    } else {
        mDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_normal);
        mMonthDayTextColor = res.getColor(R.color.mdtrp_date_picker_month_day);
        mDisabledDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_disabled);
        mHighlightedDayTextColor = res.getColor(R.color.mdtrp_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = res.getColor(R.color.mdtrp_white);
    mTodayNumberColor = res.getColor(R.color.mdtrp_accent_color);
    mMonthTitleColor = res.getColor(R.color.mdtrp_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtrp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtrp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtrp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtrp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.mdtrp_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtrp_date_picker_view_animator_height)
            - getMonthHeaderSize()) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}

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  ww w. j a v a  2s.  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.borax12.materialdaterangepicker.multi.date.MonthView.java

public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;//from   ww  w  .j a  va 2 s .  c om
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
        mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
        mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
        mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
        mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
    } else {
        mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
        mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
        mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
        mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
    mTodayNumberColor = res.getColor(R.color.mdtp_accent_color);
    mMonthTitleColor = res.getColor(R.color.mdtp_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
            - getMonthHeaderSize()) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}