List of usage examples for android.content.res TypedArray hasValueOrEmpty
public boolean hasValueOrEmpty(@StyleableRes int index)
From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java
private void initializeLayout() { mContext = getContext();/* ww w.ja v a 2 s .com*/ setCurrentLocale(Locale.getDefault()); // process style attributes final TypedArray a = mContext.obtainStyledAttributes(R.styleable.SublimeTimePicker); final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mSelectHours = res.getString(R.string.select_hours); mSelectMinutes = res.getString(R.string.select_minutes); DateFormatSymbols dfs = DateFormatSymbols.getInstance(mCurrentLocale); String[] amPmStrings = dfs.getAmPmStrings();/*{"AM", "PM"}*/ if (amPmStrings.length == 2 && !TextUtils.isEmpty(amPmStrings[0]) && !TextUtils.isEmpty(amPmStrings[1])) { mAmText = amPmStrings[0].length() > 2 ? amPmStrings[0].substring(0, 2) : amPmStrings[0]; mPmText = amPmStrings[1].length() > 2 ? amPmStrings[1].substring(0, 2) : amPmStrings[1]; } else { // Defaults mAmText = "AM"; mPmText = "PM"; } final int layoutResourceId = R.layout.time_picker_layout; final View mainView = inflater.inflate(layoutResourceId, this); mHeaderView = mainView.findViewById(R.id.time_header); // Set up hour/minute labels. mHourView = (TextView) mainView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(mContext, R.string.select_hours)); mSeparatorView = (TextView) mainView.findViewById(R.id.separator); mMinuteView = (TextView) mainView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mMinuteView, new ClickActionDelegate(mContext, R.string.select_minutes)); // Now that we have text appearances out of the way, make sure the hour // and minute views are correctly sized. mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); // Set up AM/PM labels. mAmPmLayout = mainView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(obtainVerbatim(amPmStrings[0])); mAmLabel.setOnClickListener(mClickListener); mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label); mPmLabel.setText(obtainVerbatim(amPmStrings[1])); mPmLabel.setOnClickListener(mClickListener); ColorStateList headerTextColor = a.getColorStateList(R.styleable.SublimeTimePicker_spHeaderTextColor); if (headerTextColor != null) { mHourView.setTextColor(headerTextColor); mSeparatorView.setTextColor(headerTextColor); mMinuteView.setTextColor(headerTextColor); mAmLabel.setTextColor(headerTextColor); mPmLabel.setTextColor(headerTextColor); } // Set up header background, if available. if (SUtils.isApi_22_OrHigher()) { if (a.hasValueOrEmpty(R.styleable.SublimeTimePicker_spHeaderBackground)) { SUtils.setViewBackground(mHeaderView, a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground)); } } else { if (a.hasValue(R.styleable.SublimeTimePicker_spHeaderBackground)) { SUtils.setViewBackground(mHeaderView, a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground)); } } a.recycle(); mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker); setupListeners(); mAllowAutoAdvance = true; // 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(); // Initialize with current time final Calendar calendar = Calendar.getInstance(mCurrentLocale); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); }