Example usage for android.widget ArrayAdapter createFromResource

List of usage examples for android.widget ArrayAdapter createFromResource

Introduction

In this page you can find the example usage for android.widget ArrayAdapter createFromResource.

Prototype

public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context,
        @ArrayRes int textArrayResId, @LayoutRes int textViewResId) 

Source Link

Document

Creates a new ArrayAdapter from external resources.

Usage

From source file:com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;/*from w w  w . j a  va2 s.  com*/
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle b = getArguments();
        if (b != null) {
            mTime.set(b.getLong(BUNDLE_START_TIME_MILLIS));

            String tz = b.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.timezone = tz;
            }
            mTime.normalize(false);

            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
            String rrule = b.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
                }
            }

        } else {
            mTime.setToNow();
        }
    }

    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);

    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();

    mRepeatSwitch = (SwitchCompat) mView.findViewById(R.id.repeat_switch);
    mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
    mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE
                    : RecurrenceModel.STATE_NO_RECURRENCE;
            togglePickerOptions();
        }
    });

    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);

    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);

    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray,
            R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        // Get screen width in dp first
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        float density = getResources().getDisplayMetrics().density;
        float dpWidth = outMetrics.widthPixels / density;
        if (dpWidth > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
            numOfButtonsInRow1 = 7;
            numOfButtonsInRow2 = 0;
            mWeekGroup2.setVisibility(View.GONE);
            mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
        } else {
            numOfButtonsInRow1 = 4;
            numOfButtonsInRow2 = 3;

            mWeekGroup2.setVisibility(View.VISIBLE);
            // Set rightmost button on the second row invisible so it takes up
            // space and everything centers properly
            mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
        }
    } else if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;

        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }

    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }

        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);

    mDone = (Button) mView.findViewById(R.id.done);
    mDone.setOnClickListener(this);

    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}

From source file:com.doomonafireball.betterpickers.recurrencepicker.RecurrencePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;//from   w  w  w  .ja v a  2  s  .c o m
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle b = getArguments();
        if (b != null) {
            mTime.set(b.getLong(BUNDLE_START_TIME_MILLIS));

            String tz = b.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.timezone = tz;
            }
            mTime.normalize(false);

            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
            String rrule = b.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
                }
            }

        } else {
            mTime.setToNow();
        }
    }

    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);

    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();

    mRepeatSwitch = (SwitchCompat) mView.findViewById(R.id.repeat_switch);
    mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
    mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE
                    : RecurrenceModel.STATE_NO_RECURRENCE;
            togglePickerOptions();
        }
    });

    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);

    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);

    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray,
            R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_HOURLY:
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        // Get screen width in dp first
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        float density = getResources().getDisplayMetrics().density;
        float dpWidth = outMetrics.widthPixels / density;
        if (dpWidth > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
            numOfButtonsInRow1 = 7;
            numOfButtonsInRow2 = 0;
            mWeekGroup2.setVisibility(View.GONE);
            mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
        } else {
            numOfButtonsInRow1 = 4;
            numOfButtonsInRow2 = 3;

            mWeekGroup2.setVisibility(View.VISIBLE);
            // Set rightmost button on the second row invisible so it takes up
            // space and everything centers properly
            mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
        }
    } else if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;

        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }

    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }

        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);

    mDoneButton = (Button) mView.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);

    Button cancelButton = (Button) mView.findViewById(R.id.cancel_button);
    //FIXME no text color for this one ?
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}

From source file:com.mattfred.betterpickers.recurrencepicker.RecurrencePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;//from  w  w  w  .j av  a 2 s.c  o m
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle bundle = getArguments();
        if (bundle != null) {
            mTime.set(bundle.getLong(BUNDLE_START_TIME_MILLIS));

            String tz = bundle.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.timezone = tz;
            }
            mTime.normalize(false);

            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
            String rrule = bundle.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
                }
            }

            mModel.forceHideSwitchButton = bundle.getBoolean(BUNDLE_HIDE_SWITCH_BUTTON, false);
        } else {
            mTime.setToNow();
        }
    }

    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);

    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();

    mRepeatSwitch = (SwitchCompat) mView.findViewById(R.id.repeat_switch);
    if (mModel.forceHideSwitchButton) {
        mRepeatSwitch.setChecked(true);
        mRepeatSwitch.setVisibility(View.GONE);
        mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
    } else {
        mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
        mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE
                        : RecurrenceModel.STATE_NO_RECURRENCE;
                togglePickerOptions();
            }
        });
    }
    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);

    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);

    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray,
            R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_HOURLY:
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        // Get screen width in dp first
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        float density = getResources().getDisplayMetrics().density;
        float dpWidth = outMetrics.widthPixels / density;
        if (dpWidth > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
            numOfButtonsInRow1 = 7;
            numOfButtonsInRow2 = 0;
            mWeekGroup2.setVisibility(View.GONE);
            mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
        } else {
            numOfButtonsInRow1 = 4;
            numOfButtonsInRow2 = 3;

            mWeekGroup2.setVisibility(View.VISIBLE);
            // Set rightmost button on the second row invisible so it takes up
            // space and everything centers properly
            mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
        }
    } else if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;

        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }

    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }

        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);

    mDoneButton = (Button) mView.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);

    Button cancelButton = (Button) mView.findViewById(R.id.cancel_button);
    //FIXME no text color for this one ?
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}

From source file:com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;//w w  w.  j av a  2  s.  c om
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle bundle = getArguments();
        if (bundle != null) {
            mTime.set(bundle.getLong(BUNDLE_START_TIME_MILLIS));

            String tz = bundle.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.timezone = tz;
            }
            mTime.normalize(false);

            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
            String rrule = bundle.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
                }
            }

            mModel.forceHideSwitchButton = bundle.getBoolean(BUNDLE_HIDE_SWITCH_BUTTON, false);
        } else {
            mTime.setToNow();
        }
    }

    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);

    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();

    mRepeatSwitch = (SwitchCompat) mView.findViewById(R.id.repeat_switch);
    if (mModel.forceHideSwitchButton) {
        mRepeatSwitch.setChecked(true);
        mRepeatSwitch.setVisibility(View.GONE);
        mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
    } else {
        mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
        mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE
                        : RecurrenceModel.STATE_NO_RECURRENCE;
                togglePickerOptions();
            }
        });
    }
    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);

    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);

    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray,
            R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_HOURLY:
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        // Get screen width in dp first
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        float density = getResources().getDisplayMetrics().density;
        float dpWidth = outMetrics.widthPixels / density;
        if (dpWidth > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
            numOfButtonsInRow1 = 7;
            numOfButtonsInRow2 = 0;
            mWeekGroup2.setVisibility(View.GONE);
            mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
        } else {
            numOfButtonsInRow1 = 4;
            numOfButtonsInRow2 = 3;

            mWeekGroup2.setVisibility(View.VISIBLE);
            // Set rightmost button on the second row invisible so it takes up
            // space and everything centers properly
            mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
        }
    } else if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;

        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }

    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }

        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);

    mDoneButton = (Button) mView.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);

    Button cancelButton = (Button) mView.findViewById(R.id.cancel_button);
    //FIXME no text color for this one ?
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}

From source file:com.code44.finance.ui.dialogs.recurrencepicker.RecurrencePickerDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    eventBus.register(this);
    mRecurrence.wkst = EventRecurrence.timeDay2Day(Utils.getFirstDayOfWeek(getActivity()));

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    boolean endCountHasFocus = false;
    if (savedInstanceState != null) {
        RecurrenceModel m = (RecurrenceModel) savedInstanceState.get(BUNDLE_MODEL);
        if (m != null) {
            mModel = m;/*from w w  w.  j  a  v a2  s  .  com*/
        }
        endCountHasFocus = savedInstanceState.getBoolean(BUNDLE_END_COUNT_HAS_FOCUS);
    } else {
        Bundle bundle = getArguments();
        if (bundle != null) {
            mTime.set(bundle.getLong(BUNDLE_START_TIME_MILLIS));

            String tz = bundle.getString(BUNDLE_TIME_ZONE);
            if (!TextUtils.isEmpty(tz)) {
                mTime.timezone = tz;
            }
            mTime.normalize(false);

            // Time days of week: Sun=0, Mon=1, etc
            mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
            String rrule = bundle.getString(BUNDLE_RRULE);
            if (!TextUtils.isEmpty(rrule)) {
                mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
                mRecurrence.parse(rrule);
                copyEventRecurrenceToModel(mRecurrence, mModel);
                // Leave today's day of week as checked by default in weekly view.
                if (mRecurrence.bydayCount == 0) {
                    mModel.weeklyByDayOfWeek[mTime.weekDay] = true;
                }
            }

            mModel.forceHideSwitchButton = bundle.getBoolean(BUNDLE_HIDE_SWITCH_BUTTON, false);
        } else {
            mTime.setToNow();
        }
    }

    mResources = getResources();
    mView = inflater.inflate(R.layout.recurrencepicker, container, true);

    final Activity activity = getActivity();
    final Configuration config = activity.getResources().getConfiguration();

    mRepeatSwitch = (SwitchCompat) mView.findViewById(R.id.repeat_switch);
    if (mModel.forceHideSwitchButton) {
        mRepeatSwitch.setChecked(true);
        mRepeatSwitch.setVisibility(View.GONE);
        mModel.recurrenceState = RecurrenceModel.STATE_RECURRENCE;
    } else {
        mRepeatSwitch.setChecked(mModel.recurrenceState == RecurrenceModel.STATE_RECURRENCE);
        mRepeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mModel.recurrenceState = isChecked ? RecurrenceModel.STATE_RECURRENCE
                        : RecurrenceModel.STATE_NO_RECURRENCE;
                togglePickerOptions();
            }
        });
    }
    mFreqSpinner = (Spinner) mView.findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);
    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.recurrence_freq, R.layout.recurrencepicker_freq_item);
    freqAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mFreqSpinner.setAdapter(freqAdapter);

    mIntervalGroup = (LinearLayout) mView.findViewById(R.id.intervalGroup);
    mInterval = (EditText) mView.findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) mView.findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) mView.findViewById(R.id.intervalPostText);

    mStartDatePreText = (TextView) mView.findViewById(R.id.startDatePreText);
    mStartDateTextView = (TextView) mView.findViewById(R.id.startDate);
    mStartDateTextView.setOnClickListener(this);
    if (mModel.startDate == null) {
        mModel.startDate = new Time(mTime);
        mModel.startDate.normalize(false);
    }

    mEndGroup = (LinearLayout) mView.findViewById(R.id.endGroup);
    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) mView.findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);
    mEndSpinnerAdapter = new EndSpinnerAdapter(getActivity(), mEndSpinnerArray,
            R.layout.recurrencepicker_freq_item, R.layout.recurrencepicker_end_text);
    mEndSpinnerAdapter.setDropDownViewResource(R.layout.recurrencepicker_freq_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) mView.findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) mView.findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) mView.findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime);
        switch (mModel.freq) {
        case RecurrenceModel.FREQ_DAILY:
        case RecurrenceModel.FREQ_WEEKLY:
            mModel.endDate.month += 1;
            break;
        case RecurrenceModel.FREQ_MONTHLY:
            mModel.endDate.month += 3;
            break;
        case RecurrenceModel.FREQ_YEARLY:
            mModel.endDate.year += 3;
            break;
        }
        mModel.endDate.normalize(false);
    }

    mWeekGroup = (LinearLayout) mView.findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) mView.findViewById(R.id.weekGroup2);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = Utils.getFirstDayOfWeek(getActivity());

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
        // Get screen width in dp first
        Display display = getActivity().getWindowManager().getDefaultDisplay();
        DisplayMetrics outMetrics = new DisplayMetrics();
        display.getMetrics(outMetrics);

        float density = getResources().getDisplayMetrics().density;
        float dpWidth = outMetrics.widthPixels / density;
        if (dpWidth > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
            numOfButtonsInRow1 = 7;
            numOfButtonsInRow2 = 0;
            mWeekGroup2.setVisibility(View.GONE);
            mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
        } else {
            numOfButtonsInRow1 = 4;
            numOfButtonsInRow2 = 3;

            mWeekGroup2.setVisibility(View.VISIBLE);
            // Set rightmost button on the second row invisible so it takes up
            // space and everything centers properly
            mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
        }
    } else if (mResources.getConfiguration().screenWidthDp > MIN_SCREEN_WIDTH_FOR_SINGLE_ROW_WEEK) {
        numOfButtonsInRow1 = 7;
        numOfButtonsInRow2 = 0;
        mWeekGroup2.setVisibility(View.GONE);
        mWeekGroup2.getChildAt(3).setVisibility(View.GONE);
    } else {
        numOfButtonsInRow1 = 4;
        numOfButtonsInRow2 = 3;

        mWeekGroup2.setVisibility(View.VISIBLE);
        // Set rightmost button on the second row invisible so it takes up
        // space and everything centers properly
        mWeekGroup2.getChildAt(3).setVisibility(View.INVISIBLE);
    }

    /* First row */
    for (int i = 0; i < 7; i++) {
        if (i >= numOfButtonsInRow1) {
            mWeekGroup.getChildAt(i).setVisibility(View.GONE);
            continue;
        }

        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    /* 2nd Row */
    for (int i = 0; i < 3; i++) {
        if (i >= numOfButtonsInRow2) {
            mWeekGroup2.getChildAt(i).setVisibility(View.GONE);
            continue;
        }
        mWeekByDayButtons[idx] = (ToggleButton) mWeekGroup2.getChildAt(i);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthGroup = (LinearLayout) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup = (RadioGroup) mView.findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) mView.findViewById(R.id.repeatMonthlyByNthDayOfMonth);

    mDoneButton = (Button) mView.findViewById(R.id.done_button);
    mDoneButton.setOnClickListener(this);

    Button cancelButton = (Button) mView.findViewById(R.id.cancel_button);
    //FIXME no text color for this one ?
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });

    togglePickerOptions();
    updateDialog();
    if (endCountHasFocus) {
        mEndCount.requestFocus();
    }
    return mView;
}

From source file:com.appeaser.sublimepickerlibrary.recurrencepicker.RecurrenceOptionCreator.java

void initializeLayout() {
    int weekButtonUnselectedTextColor, weekButtonSelectedTextColor, weekButtonSelectedCircleColor;

    final TypedArray a = getContext().obtainStyledAttributes(R.styleable.RecurrenceOptionCreator);
    try {// www  .  j a v a2 s  .  c  om
        mHeaderBackgroundColor = a.getColor(R.styleable.RecurrenceOptionCreator_spHeaderBackground, 0);

        int endDateFormat = a.getInt(R.styleable.RecurrenceOptionCreator_spEndDateFormat, 1);

        mEndDateFormatter = DateFormat.getDateInstance(
                endDateFormat == 0 ? DateFormat.SHORT : DateFormat.MEDIUM, Locale.getDefault());

        weekButtonUnselectedTextColor = a.getColor(
                R.styleable.RecurrenceOptionCreator_spWeekButtonUnselectedTextColor, SUtils.COLOR_ACCENT);
        weekButtonSelectedTextColor = a.getColor(
                R.styleable.RecurrenceOptionCreator_spWeekButtonSelectedTextColor,
                SUtils.COLOR_TEXT_PRIMARY_INVERSE);
        weekButtonSelectedCircleColor = a.getColor(
                R.styleable.RecurrenceOptionCreator_spWeekButtonSelectedCircleColor, SUtils.COLOR_ACCENT);
    } finally {
        a.recycle();
    }

    mResources = getResources();

    LayoutInflater.from(getContext()).inflate(R.layout.recurrence_picker, this);

    mRecurrencePicker = findViewById(R.id.recurrence_picker);

    mDateOnlyPicker = (RecurrenceEndDatePicker) findViewById(R.id.date_only_picker);
    mDateOnlyPicker.setVisibility(View.GONE);

    // OK/Cancel buttons
    mButtonLayout = (DecisionButtonLayout) findViewById(R.id.roc_decision_button_layout);
    mButtonLayout.applyOptions(mButtonLayoutCallback);

    SUtils.setViewBackground(findViewById(R.id.freqSpinnerHolder), mHeaderBackgroundColor,
            SUtils.CORNER_TOP_LEFT | SUtils.CORNER_TOP_RIGHT);

    /** EFrequency Spinner {Repeat daily, Repeat weekly, Repeat monthly, Repeat yearly} **/

    mFreqSpinner = (Spinner) findViewById(R.id.freqSpinner);
    mFreqSpinner.setOnItemSelectedListener(this);

    ArrayAdapter<CharSequence> freqAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.recurrence_freq, R.layout.roc_freq_spinner_item);
    freqAdapter.setDropDownViewResource(R.layout.roc_spinner_dropdown_item);
    mFreqSpinner.setAdapter(freqAdapter);

    Drawable freqSpinnerBg = ContextCompat.getDrawable(getContext(), R.drawable.abc_spinner_mtrl_am_alpha);
    PorterDuffColorFilter cfFreqSpinner = new PorterDuffColorFilter(SUtils.COLOR_TEXT_PRIMARY_INVERSE,
            PorterDuff.Mode.SRC_IN);
    if (freqSpinnerBg != null) {
        freqSpinnerBg.setColorFilter(cfFreqSpinner);
        SUtils.setViewBackground(mFreqSpinner, freqSpinnerBg);
    }

    mInterval = (EditText) findViewById(R.id.interval);
    mInterval.addTextChangedListener(new minMaxTextWatcher(1, INTERVAL_DEFAULT, INTERVAL_MAX) {
        @Override
        void onChange(int v) {
            if (mIntervalResId != -1 && mInterval.getText().toString().length() > 0) {
                mModel.interval = v;
                updateIntervalText();
                mInterval.requestLayout();
            }
        }
    });
    mIntervalPreText = (TextView) findViewById(R.id.intervalPreText);
    mIntervalPostText = (TextView) findViewById(R.id.intervalPostText);

    /** End Spinner {Forever, Until a date, For a number of events} **/

    mEndNeverStr = mResources.getString(R.string.recurrence_end_continously);
    mEndDateLabel = mResources.getString(R.string.recurrence_end_date_label);
    mEndCountLabel = mResources.getString(R.string.recurrence_end_count_label);

    mEndSpinnerArray.add(mEndNeverStr);
    mEndSpinnerArray.add(mEndDateLabel);
    mEndSpinnerArray.add(mEndCountLabel);
    mEndSpinner = (Spinner) findViewById(R.id.endSpinner);
    mEndSpinner.setOnItemSelectedListener(this);

    mEndSpinnerAdapter = new EndSpinnerAdapter(getContext(), mEndSpinnerArray, R.layout.roc_end_spinner_item,
            R.id.spinner_item, R.layout.roc_spinner_dropdown_item);
    mEndSpinner.setAdapter(mEndSpinnerAdapter);

    mEndCount = (EditText) findViewById(R.id.endCount);
    mEndCount.addTextChangedListener(new minMaxTextWatcher(1, COUNT_DEFAULT, COUNT_MAX) {
        @Override
        void onChange(int v) {
            if (mModel.endCount != v) {
                mModel.endCount = v;
                updateEndCountText();
                mEndCount.requestLayout();
            }
        }
    });
    mPostEndCount = (TextView) findViewById(R.id.postEndCount);

    mEndDateTextView = (TextView) findViewById(R.id.endDate);
    mEndDateTextView.setOnClickListener(this);

    SUtils.setViewBackground(mEndDateTextView,
            SUtils.createButtonBg(getContext(), SUtils.COLOR_BUTTON_NORMAL, SUtils.COLOR_CONTROL_HIGHLIGHT));

    // set default & checked state colors
    WeekButton.setStateColors(weekButtonUnselectedTextColor, weekButtonSelectedTextColor);

    // AOSP code handled this differently. It has been refactored to
    // let Android decide if we have enough space to show
    // all seven 'WeekButtons' inline. In this case, 'mWeekGroup2'
    // will be null (see @layout-w460dp/week_buttons).
    mWeekGroup = (LinearLayout) findViewById(R.id.weekGroup);
    mWeekGroup2 = (LinearLayout) findViewById(R.id.weekGroup2);

    // Only non-null when available width is < 460dp
    // Used only for positioning 'WeekButtons' in two rows
    // of 4 & 3.
    View eighthWeekDay = findViewById(R.id.week_day_8);
    if (eighthWeekDay != null)
        eighthWeekDay.setVisibility(View.INVISIBLE);

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    //String[] dayOfWeekString = new DateFormatSymbols().getWeekdays();

    mMonthRepeatByDayOfWeekStrs = new String[7][];
    // from Time.SUNDAY as 0 through Time.SATURDAY as 6
    mMonthRepeatByDayOfWeekStrs[0] = mResources.getStringArray(R.array.repeat_by_nth_sun);
    mMonthRepeatByDayOfWeekStrs[1] = mResources.getStringArray(R.array.repeat_by_nth_mon);
    mMonthRepeatByDayOfWeekStrs[2] = mResources.getStringArray(R.array.repeat_by_nth_tues);
    mMonthRepeatByDayOfWeekStrs[3] = mResources.getStringArray(R.array.repeat_by_nth_wed);
    mMonthRepeatByDayOfWeekStrs[4] = mResources.getStringArray(R.array.repeat_by_nth_thurs);
    mMonthRepeatByDayOfWeekStrs[5] = mResources.getStringArray(R.array.repeat_by_nth_fri);
    mMonthRepeatByDayOfWeekStrs[6] = mResources.getStringArray(R.array.repeat_by_nth_sat);

    // In Time.java day of week order e.g. Sun = 0
    int idx = RecurrenceUtils.getFirstDayOfWeek();

    // In Calendar.java day of week order e.g Sun = 1 ... Sat = 7
    String[] dayOfWeekString = new DateFormatSymbols().getShortWeekdays();

    // CheckableDrawable's width & height
    int expandedWidthHeight = mResources.getDimensionPixelSize(R.dimen.week_button_state_on_circle_size);

    WeekButton[] tempWeekButtons = new WeekButton[7];
    tempWeekButtons[0] = (WeekButton) findViewById(R.id.week_day_1);
    tempWeekButtons[1] = (WeekButton) findViewById(R.id.week_day_2);
    tempWeekButtons[2] = (WeekButton) findViewById(R.id.week_day_3);
    tempWeekButtons[3] = (WeekButton) findViewById(R.id.week_day_4);
    tempWeekButtons[4] = (WeekButton) findViewById(R.id.week_day_5);
    tempWeekButtons[5] = (WeekButton) findViewById(R.id.week_day_6);
    tempWeekButtons[6] = (WeekButton) findViewById(R.id.week_day_7);

    for (int i = 0; i < mWeekByDayButtons.length; i++) {
        mWeekByDayButtons[idx] = tempWeekButtons[i];
        SUtils.setViewBackground(mWeekByDayButtons[idx],
                new CheckableDrawable(weekButtonSelectedCircleColor, false, expandedWidthHeight));
        mWeekByDayButtons[idx].setTextColor(weekButtonUnselectedTextColor);
        mWeekByDayButtons[idx].setTextOff(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setTextOn(dayOfWeekString[TIME_DAY_TO_CALENDAR_DAY[idx]]);
        mWeekByDayButtons[idx].setOnCheckedChangeListener(this);

        if (++idx >= 7) {
            idx = 0;
        }
    }

    mMonthRepeatByRadioGroup = (RadioGroup) findViewById(R.id.monthGroup);
    mMonthRepeatByRadioGroup.setOnCheckedChangeListener(this);
    mRepeatMonthlyByNthDayOfWeek = (RadioButton) findViewById(R.id.repeatMonthlyByNthDayOfTheWeek);
    mRepeatMonthlyByNthDayOfMonth = (RadioButton) findViewById(R.id.repeatMonthlyByNthDayOfMonth);
}

From source file:com.cypress.cysmart.BLEServiceFragments.SensorHubService.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.sensor_hub, container, false);
    LinearLayout parent = (LinearLayout) rootView.findViewById(R.id.parent_sensorhub);
    parent.setOnClickListener(new OnClickListener() {

        @Override/*from w ww  .  j av a 2 s.c om*/
        public void onClick(View v) {

        }
    });
    accX = (TextView) rootView.findViewById(R.id.acc_x_value);
    accY = (TextView) rootView.findViewById(R.id.acc_y_value);
    accZ = (TextView) rootView.findViewById(R.id.acc_z_value);
    BAT = (TextView) rootView.findViewById(R.id.bat_value);
    STEMP = (TextView) rootView.findViewById(R.id.temp_value);
    mProgressDialog = new ProgressDialog(getActivity());
    Spressure = (TextView) rootView.findViewById(R.id.pressure_value);

    // Locate device button listener
    Button locateDevice = (Button) rootView.findViewById(R.id.locate_device);
    locateDevice.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Button btn = (Button) v;
            String buttonText = btn.getText().toString();
            String startText = getResources().getString(R.string.sen_hub_locate);
            String stopText = getResources().getString(R.string.sen_hub_locate_stop);
            if (buttonText.equalsIgnoreCase(startText)) {
                btn.setText(stopText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }

            } else {
                btn.setText(startText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }
            }

        }
    });
    final ImageButton acc_more = (ImageButton) rootView.findViewById(R.id.acc_more);
    final ImageButton stemp_more = (ImageButton) rootView.findViewById(R.id.stemp_more);
    final ImageButton spressure_more = (ImageButton) rootView.findViewById(R.id.spressure_more);

    final LinearLayout acc_layLayout = (LinearLayout) rootView.findViewById(R.id.acc_context_menu);
    final LinearLayout stemp_layLayout = (LinearLayout) rootView.findViewById(R.id.stemp_context_menu);
    final LinearLayout spressure_layLayout = (LinearLayout) rootView.findViewById(R.id.spressure_context_menu);

    // expand listener
    acc_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (acc_layLayout.getVisibility() != View.VISIBLE) {
                acc_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                acc_layLayout.startAnimation(a);
                acc_scan_interval = (EditText) rootView.findViewById(R.id.acc_sensor_scan_interval);
                if (ACCSensorScanCharacteristic != null) {
                    acc_scan_interval.setText(ACCSensorScanCharacteristic);
                }
                acc_sensortype = (TextView) rootView.findViewById(R.id.acc_sensor_type);
                if (ACCSensorTypeCharacteristic != null) {
                    acc_sensortype.setText(ACCSensorTypeCharacteristic);
                }
                acc_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(acc_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadACCSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.acc_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);

            } else {
                acc_more.setRotation(-90);

                acc_scan_interval.setText("");
                acc_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                acc_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    stemp_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (stemp_layLayout.getVisibility() != View.VISIBLE) {
                stemp_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                stemp_layLayout.startAnimation(a);
                stemp_scan_interval = (EditText) rootView.findViewById(R.id.stemp_sensor_scan_interval);
                if (STEMPSensorScanCharacteristic != null) {
                    stemp_scan_interval.setText(STEMPSensorScanCharacteristic);
                }
                stemp_sensortype = (TextView) rootView.findViewById(R.id.stemp_sensor_type);
                if (STEMPSensorTypeCharacteristic != null) {
                    stemp_sensortype.setText(STEMPSensorTypeCharacteristic);
                }
                stemp_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadSTEMPSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                stemp_more.setRotation(-90);
                stemp_scan_interval.setText("");
                stemp_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                stemp_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    spressure_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (spressure_layLayout.getVisibility() != View.VISIBLE) {
                spressure_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                spressure_layLayout.startAnimation(a);
                spressure_scan_interval = (EditText) rootView.findViewById(R.id.spressure_sensor_scan_interval);
                if (SPRESSURESensorScanCharacteristic != null) {
                    spressure_scan_interval.setText(SPRESSURESensorScanCharacteristic);
                }
                spressure_sensortype = (TextView) rootView.findViewById(R.id.spressure_sensor_type);
                if (SPRESSURESensorTypeCharacteristic != null) {
                    spressure_sensortype.setText(SPRESSURESensorTypeCharacteristic);
                }
                spressure_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSURESensorScanCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.spressure_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);
                spressure_threshold_value = (EditText) rootView.findViewById(R.id.spressure_threshold);
                spressure_threshold_value.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(spressure_threshold_value.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSUREThresholdCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                spressure_more.setRotation(-90);
                spressure_scan_interval.setText("");
                spressure_sensortype.setText("");
                spressure_threshold_value.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                spressure_layLayout.startAnimation(a);
            }

        }
    });
    ImageButton acc_graph = (ImageButton) rootView.findViewById(R.id.acc_graph);
    setupAccChart(rootView);

    acc_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mACCGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mACCGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {
                mACCGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton stemp_graph = (ImageButton) rootView.findViewById(R.id.temp_graph);
    setupTempGraph(rootView);
    stemp_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mTemperatureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mTemperatureGraphLayoutParent.setVisibility(View.VISIBLE);
            } else {
                mTemperatureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton spressure_graph = (ImageButton) rootView.findViewById(R.id.pressure_graph);
    setupPressureGraph(rootView);

    spressure_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mPressureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mPressureGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {

                mPressureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:g7.bluesky.launcher3.Launcher.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    activity = this;
    if (DEBUG_STRICT_MODE) {
        StrictMode.setThreadPolicy(//from  w w  w  .  j  ava2s.co m
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    }

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.preOnCreate();
    }

    super.onCreate(savedInstanceState);

    LauncherAppState.setApplicationContext(getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    LauncherAppState.getLauncherProvider().setLauncherProviderChangeListener(this);

    // Lazy-initialize the dynamic grid
    DeviceProfile grid = app.initDynamicGrid(this);

    // the LauncherApplication should call this, but in case of Instrumentation it might not be present yet
    mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);

    // Set defaultSharedPref
    defaultSharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    mIsSafeModeEnabled = getPackageManager().isSafeMode();
    mModel = app.setLauncher(this);
    mIconCache = app.getIconCache();
    mIconCache.flushInvalidIcons(grid);
    mDragController = new DragController(this);
    mInflater = getLayoutInflater();

    mStats = new Stats(this);

    mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);

    mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
    mAppWidgetHost.startListening();

    // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
    // this also ensures that any synchronous binding below doesn't re-trigger another
    // LauncherModel load.
    mPaused = false;

    if (PROFILE_STARTUP) {
        android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher");
    }

    checkForLocaleChange();
    setContentView(R.layout.launcher);

    setupViews();
    grid.layout(this);

    registerContentObservers();

    lockAllApps();

    mSavedState = savedInstanceState;
    restoreState(mSavedState);

    if (PROFILE_STARTUP) {
        android.os.Debug.stopMethodTracing();
    }

    if (!mRestoring) {
        if (DISABLE_SYNCHRONOUS_BINDING_CURRENT_PAGE) {
            // If the user leaves launcher, then we should just load items asynchronously when
            // they return.
            mModel.startLoader(true, PagedView.INVALID_RESTORE_PAGE);
        } else {
            // We only load the page synchronously if the user rotates (or triggers a
            // configuration change) while launcher is in the foreground
            mModel.startLoader(true, mWorkspace.getRestorePage());
        }
    }

    // For handling default keys
    mDefaultKeySsb = new SpannableStringBuilder();
    Selection.setSelection(mDefaultKeySsb, 0);

    IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    registerReceiver(mCloseSystemDialogsReceiver, filter);

    // On large interfaces, we want the screen to auto-rotate based on the current orientation
    unlockScreenOrientation(true);

    if (mLauncherCallbacks != null) {
        mLauncherCallbacks.onCreate(savedInstanceState);
        if (mLauncherCallbacks.hasLauncherOverlay()) {
            ViewStub stub = (ViewStub) findViewById(R.id.launcher_overlay_stub);
            mLauncherOverlayContainer = (InsettableFrameLayout) stub.inflate();
            mLauncherOverlay = mLauncherCallbacks.setLauncherOverlayView(mLauncherOverlayContainer,
                    mLauncherOverlayCallbacks);
            mWorkspace.setLauncherOverlay(mLauncherOverlay);
        }
    }

    if (shouldShowIntroScreen()) {
        showIntroScreen();
    } else {
        showFirstRunActivity();
        showFirstRunClings();
    }

    //create extramenu
    //llExtraMenu = (LinearLayout) findViewById(R.id.ll_extra_menu);
    //llExtraMenu.addView(new ExtraMenu(this, null));
    flLauncher = (LauncherRootView) findViewById(R.id.launcher);
    mExtraMenu = new ExtraMenu(this, null);
    flLauncher.addView(mExtraMenu);
    if (!defaultSharedPref.getBoolean(SettingConstants.EXTRA_MENU_PREF_KEY, false)) {
        mExtraMenu.setVisibility(View.GONE);
    }

    editTextFilterApps.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            String searchString = editTextFilterApps.getText().toString();
            if (listApps != null && listApps.size() > 0) {
                if (searchString.trim().length() > 0) {
                    ArrayList<AppInfo> searchList = new ArrayList<>();
                    for (AppInfo appInfo : listApps) {
                        String appTitle = StringUtil
                                .convertVNString(appInfo.getTitle().toString().toLowerCase().trim());
                        searchString = StringUtil.convertVNString(searchString.toLowerCase().trim());
                        if (appTitle.contains(searchString)) {
                            searchList.add(appInfo);
                        }
                    }
                    mAppsCustomizeContent.setApps(searchList);
                } else {
                    mAppsCustomizeContent.setApps((ArrayList<AppInfo>) listApps);
                }
            }
        }
    });

    // Spinner element
    Spinner spinner = (Spinner) findViewById(R.id.spinner);

    // Spinner click listener
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Clear spinner text
            ((TextView) view).setText(null);

            SharedPreferences.Editor editor = defaultSharedPref.edit();
            editor.putInt(SettingConstants.SORT_PREF_KEY, position);
            editor.apply();

            // Value from preference
            int prefVal = defaultSharedPref.getInt(SettingConstants.SORT_PREF_KEY, SettingConstants.SORT_A_Z);
            LauncherUtil.sortListApps(defaultSharedPref, listApps, prefVal);
            mAppsCustomizeContent.invalidatePageData();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    // Creating adapter for spinner
    ArrayAdapter<CharSequence> dataAdapter = ArrayAdapter.createFromResource(this, R.array.sort_options,
            android.R.layout.simple_spinner_item);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);

    // Set default value
    final int prefSortOptionVal = defaultSharedPref.getInt(SettingConstants.SORT_PREF_KEY,
            SettingConstants.SORT_A_Z);
    spinner.setSelection(prefSortOptionVal);

    // Listen on pref change
    prefChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
        @Override
        public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
            if (key.equalsIgnoreCase(SettingConstants.EXTRA_MENU_PREF_KEY)) {
                if (!defaultSharedPref.getBoolean(SettingConstants.EXTRA_MENU_PREF_KEY, false)) {
                    mExtraMenu.setVisibility(View.GONE);
                } else {
                    mExtraMenu.setVisibility(View.VISIBLE);
                }
            } else if (key.equalsIgnoreCase(SettingConstants.ICON_THEME_PREF_KEY)) {
                mModel.forceReload();
                loadIconPack();
            }
        }
    };
    defaultSharedPref.registerOnSharedPreferenceChangeListener(prefChangeListener);
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupScheduleSpinner() {
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.schedules_array,
            R.layout.spinner_text_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    // Apply the adapter to the spinner
    scheduleSpinner.setAdapter(adapter);
    scheduleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  w ww  .  j  ava  2 s .  com
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            onScheduleSelected(selected, i);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}

From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java

@Override
public void onItemSelected(final AdapterView<?> parent, final View v, final int position, final long pos) {
    int id = parent.getId();
    Spinner spinner = (Spinner) parent;/*  ww w.  j a  v a 2 s.  c o m*/
    if (id == R.id.reqProfile) {
        String profileName = spinner.getSelectedItem().toString();
        if (!profileName.equals("")) {
            int resInterfacesId = getResources().getIdentifier(profileName + "_interface_list", "array",
                    getPackageName());
            ArrayAdapter<CharSequence> adapterInterfaces = ArrayAdapter.createFromResource(this,
                    resInterfacesId, android.R.layout.simple_spinner_item);
            adapterInterfaces.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mInter.setAdapter(adapterInterfaces);
            int resAttributeId = getResources().getIdentifier(profileName + "_attrib_list", "array",
                    getPackageName());
            ArrayAdapter<CharSequence> adapterAttribute = ArrayAdapter.createFromResource(this, resAttributeId,
                    android.R.layout.simple_spinner_item);
            adapterInterfaces.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mAttrib.setAdapter(adapterAttribute);
        }
    }
}