@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { mText = new TextView(context); mText.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); addView(mText, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mAction = new Button(context); mAction.setBackgroundResource(0); mAction.setGravity(Gravity.CENTER); mAction.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (mActionClickListener != null) mActionClickListener.onActionClick(SnackBar.this, mActionId); dismiss(); } }); addView(mAction, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mBackground = new BackgroundDrawable(); ViewUtil.setBackground(this, mBackground); setClickable(true); applyStyle(context, attrs, defStyleAttr, defStyleRes); }
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { setWillNotDraw(false); mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ContactView, defStyleAttr, defStyleRes); mAvatarSize = a.getDimensionPixelSize( R.styleable.ContactView_cv_avatarSize, ThemeUtil.dpToPx(context, 40)); mSpacing = a.getDimensionPixelOffset(R.styleable.ContactView_cv_spacing, ThemeUtil.dpToPx(context, 8)); mMinHeight = a.getDimensionPixelOffset(R.styleable.ContactView_android_minHeight, 0); int avatarSrc = a.getResourceId(R.styleable.ContactView_cv_avatarSrc, 0); mNameView = new TextView(context); mNameView.setGravity(GravityCompat.START); mNameView.setSingleLine(true); mNameView.setEllipsize(TextUtils.TruncateAt.END); int nameTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_nameTextSize, 0); ColorStateList nameTextColor = a.getColorStateList(R.styleable.ContactView_cv_nameTextColor); int nameTextAppearance = a.getResourceId(R.styleable.ContactView_cv_nameTextAppearance, 0); if (nameTextAppearance > 0) mNameView.setTextAppearance(context, nameTextAppearance); if (nameTextSize > 0) mNameView.setTextSize(TypedValue.COMPLEX_UNIT_PX, nameTextSize); if (nameTextColor != null) mNameView.setTextColor(nameTextColor); setNameText(a.getString(R.styleable.ContactView_cv_name)); mAddressView = new TextView(context); mAddressView.setGravity(GravityCompat.START); mAddressView.setSingleLine(true); mAddressView.setEllipsize(TextUtils.TruncateAt.END); int addressTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_addressTextSize, 0); ColorStateList addressTextColor = a.getColorStateList(R.styleable.ContactView_cv_addressTextColor); int addressTextAppearance = a.getResourceId(R.styleable.ContactView_cv_addressTextAppearance, 0); if (addressTextAppearance > 0) mAddressView.setTextAppearance(context, addressTextAppearance); if (addressTextSize > 0) mAddressView.setTextSize(TypedValue.COMPLEX_UNIT_PX, addressTextSize); if (addressTextColor != null) mAddressView.setTextColor(addressTextColor); setAddressText(a.getString(R.styleable.ContactView_cv_address)); mButtonSize = a.getDimensionPixelOffset(R.styleable.ContactView_cv_buttonSize, 0); if (mButtonSize > 0) { mButton = new ImageButton(context); int resId = a.getResourceId(R.styleable.ContactView_cv_buttonSrc, 0); if (resId != 0) mButton.setImageResource(resId); ViewUtil.setBackground(mButton, BlankDrawable.getInstance()); mButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); mButton.setFocusableInTouchMode(false); mButton.setFocusable(false); mButton.setClickable(false); } a.recycle(); addView(mNameView); addView(mAddressView); if (mButton != null) addView(mButton); mAvatarDrawable = new AvatarDrawable(); if (avatarSrc != 0) setAvatarResource(avatarSrc); }
/** * Set the style of RippleEffect of the ActionButton. * * @param resId The resourceId of RippleEffect. * @return This SnackBar for chaining methods. */ public SnackBar actionRipple(int resId) { if (resId != 0) ViewUtil.setBackground(mAction, new RippleDrawable.Builder(getContext(), resId).build()); return this; }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override protected void onCreate() { View v = LayoutInflater.from(getContext()).inflate(R.layout.dialog_recurring, null); setContentView(v); FrameLayout fl_mode = (FrameLayout) v.findViewById(R.id.rd_fl_mode); final ScrollView sv_repeat = (ScrollView) v.findViewById(R.id.rd_sv_repeat); final LinearLayout ll_repeat = (LinearLayout) v.findViewById(R.id.rd_ll_repeat); mModeSpinner = (Spinner) fl_mode.findViewById(R.id.rd_spn_mode); mEndSpinner = (Spinner) v.findViewById(R.id.rd_spn_end); mPeriodEditText = (EditText) v.findViewById(R.id.rd_et_period); mPeriodUnitTextView = (TextView) v.findViewById(R.id.rd_tv_period_unit); mSameDayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_same); mSameWeekdayRadioButton = (RadioButton) v.findViewById(R.id.rd_month_rb_week); mEndNumEditText = (EditText) v.findViewById(R.id.rd_et_end_num); mEndNumUnitTextView = (TextView) v.findViewById(R.id.rd_tv_end_num_unit); mEndDateButton = (Button) v.findViewById(R.id.rd_bt_end_date); mWeekView = (WeekView) v.findViewById(R.id.rd_wv_week); sv_repeat .getViewTreeObserver() .addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { showDivider(ll_repeat.getMeasuredHeight() > sv_repeat.getMeasuredHeight()); } }); mHeaderBackground = new HeaderDrawable(getContext()); ViewCompat.setPaddingRelative(fl_mode, mContentPadding, 0, mContentPadding, 0); ViewUtil.setBackground(fl_mode, mHeaderBackground); ViewCompat.setPaddingRelative( ll_repeat, mContentPadding, mActionOuterPadding, mContentPadding, mActionPadding); mModeAdapter = new ModeAdapter(); mModeSpinner.setAdapter(mModeAdapter); mModeSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onModeSelected(position); } }); mEndAdapter = new EndAdapter(); mEndSpinner.setAdapter(mEndAdapter); mEndSpinner.setOnItemSelectedListener( new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { onEndSelected(position); } }); mPeriodEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onPeriodChanged(); } }); mPeriodEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mPeriodEditText.getText().toString(); if (TextUtils.isEmpty(text)) mPeriodEditText.setText(String.valueOf(mRecurring.getPeriod())); } return false; } }); CompoundButton.OnCheckedChangeListener mCheckChangeListener = new android.widget.CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged( android.widget.CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView == mSameDayRadioButton) mSameWeekdayRadioButton.setChecked(false); else mSameDayRadioButton.setChecked(false); onMonthSettingChanged(); } } }; mSameDayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mSameWeekdayRadioButton.setOnCheckedChangeListener(mCheckChangeListener); mEndNumEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { onEventNumberChanged(); } }); mEndNumEditText.setOnKeyListener( new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { String text = mEndNumEditText.getText().toString(); if (TextUtils.isEmpty(text)) mEndNumEditText.setText(String.valueOf(mRecurring.getEventNumber())); } return false; } }); View.OnClickListener mDateClickListener = new View.OnClickListener() { @Override public void onClick(View v) { final DatePickerDialog dialog = new DatePickerDialog(getContext(), mDatePickerDialogStyleId); long minTime = System.currentTimeMillis(); Calendar cal = dialog.getCalendar(); cal.setTimeInMillis(minTime); cal.add(Calendar.YEAR, 100); long maxTime = cal.getTimeInMillis(); dialog .dateRange(minTime, maxTime) .date((long) mEndDateButton.getTag()) .positiveAction(mPositiveAction.getText()) .positiveActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { onEndDateChanged(dialog.getDate()); dialog.dismiss(); } }) .negativeAction(mNegativeAction.getText()) .negativeActionClickListener( new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }) .show(); } }; mEndDateButton.setOnClickListener(mDateClickListener); mWeekView.setOnDaySelectionChangedListener(this); }