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.code.android.vibevault.SearchScreen.java

private void init() {

    // Set up the date selection spinner.
    spinnerAdapter = ArrayAdapter.createFromResource(this, R.array.date_modifier,
            android.R.layout.simple_spinner_item);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dateModifierSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from  w ww  .  ja  v  a2  s  . c om*/
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            VibeVault.dateSearchModifierPos = pos;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    dateModifierSpinner.setAdapter(spinnerAdapter);
    dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);

    searchDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() {

        @Override
        public void onScrollEnded() {
        }

        @Override
        public void onScrollStarted() {
            vibrator.vibrate(50);
        }

    });
    artistSearchInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (isMoreSearch(s.toString(), yearSearchInput.getText().toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
            } else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });
    yearSearchInput.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (isMoreSearch(artistSearchInput.getText().toString(), s.toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
            } else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });
    searchDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
        @Override
        public void onDrawerOpened() {
            searchList.setBackgroundDrawable(getResources().getDrawable(R.drawable.backgrounddrawableblue));
            searchList.getBackground().setDither(true);
            searchList.setEnabled(false);
            handleText.setText("Search Panel");
            handleText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            artistSearchInput.setText(VibeVault.artistSearchText);

            if (VibeVault.yearSearchInt != -1) {
                yearSearchInput.setText(String.valueOf(VibeVault.yearSearchInt));
            } else {
                yearSearchInput.setText("");
            }
            dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);
        }
    });
    searchDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
        @Override
        public void onDrawerClosed() {
            searchList.setBackgroundColor(Color.BLACK);
            searchList.setEnabled(true);
            handleText.setText("Drag up to search...");
            handleText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 28);
        }
    });

    // Set listeners in the show details and artist search bars for the enter key.
    OnKeyListener enterListener = new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                if (!(artistSearchInput.getText().toString().equals(""))) {
                    VibeVault.artistSearchText = artistSearchInput.getText().toString();
                    if (setDate()) {
                        executeSearch(makeSearchURLString(1));
                        pageNum = 1;
                        searchDrawer.close();
                        return true;
                    }
                }
            }
            return false;
        }
    };
    this.artistSearchInput.setOnKeyListener(enterListener);

    this.searchButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            String query = artistSearchInput.getText().toString();
            // Blank
            if (query.equals("")) {
                vibrator.vibrate(50);
                Toast.makeText(getBaseContext(), "You need a query first...", Toast.LENGTH_SHORT).show();
                return;
            }
            // Search more
            else if (isMoreSearch(artistSearchInput.getText().toString(),
                    yearSearchInput.getText().toString())) {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.morebutton), null, null, null);
                searchButton.setText("More");
                dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);
                // pageNum is incremented then searched with to get the next
                // page.
                executeSearch(makeSearchURLString(++pageNum));
                vibrator.vibrate(50);
                searchDrawer.close();
            }
            // New search
            else {
                searchButton.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
                searchButton.setText("Search");
                VibeVault.searchResults.clear();
                VibeVault.artistSearchText = artistSearchInput.getText().toString();
                if (setDate()) {
                    // "1" is passed to retrieve page number 1.
                    vibrator.vibrate(50);
                    executeSearch(makeSearchURLString(1));
                    pageNum = 1;
                    searchDrawer.close();
                }
            }

        }
    });

    this.settingsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            launchSettingsDialog();
            vibrator.vibrate(50);
        }
    });

    this.clearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            artistSearchInput.setText("");
            yearSearchInput.setText("");
            VibeVault.artistSearchText = "";
            VibeVault.yearSearchInt = -1;
            searchButton.setCompoundDrawablesWithIntrinsicBounds(
                    getResources().getDrawable(R.drawable.searchbutton_plain), null, null, null);
            searchButton.setText("Search");
            VibeVault.searchResults.clear();
            refreshSearchList();
            vibrator.vibrate(50);
        }
    });

    searchList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            ArchiveShowObj show = (ArchiveShowObj) searchList.getItemAtPosition(position);
            Intent i = new Intent(SearchScreen.this, ShowDetailsScreen.class);
            i.putExtra("Show", show);
            startActivity(i);
        }
    });

    // Create the directory for our app if it don't exist.
    appRootDir = new File(Environment.getExternalStorageDirectory(), VibeVault.APP_DIRECTORY);
    if (!appRootDir.isFile() || !appRootDir.isDirectory()) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            appRootDir.mkdirs();
        } else {
            Toast.makeText(getBaseContext(), "sdcard is unwritable...  is it mounted on the computer?",
                    Toast.LENGTH_SHORT).show();
        }
    }
    artistSearchInput.setText(VibeVault.artistSearchText);
    if (VibeVault.yearSearchInt != -1) {
        yearSearchInput.setText(String.valueOf(VibeVault.yearSearchInt));
    } else {
        yearSearchInput.setText("");
    }
    dateModifierSpinner.setSelection(VibeVault.dateSearchModifierPos);

}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

/**
 * Set the GUI-Content from <code>mTimer</code>
 *///ww  w. j av a2s  .  c  o  m
protected void reload() {
    // Name
    mName.setText(mTimer.getString(Timer.KEY_NAME));
    mName.setHint(R.string.title);

    // Description
    mDescription.setText(mTimer.getString(Timer.KEY_DESCRIPTION));
    mDescription.setHint(R.string.description);

    // Enabled
    int disabled = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_DISABLED));
    if (disabled == 0) {
        mEnabled.setChecked(true);
    } else {
        mEnabled.setChecked(false);
    }

    int zap = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_JUST_PLAY));
    if (zap == 1) {
        mZap.setChecked(true);
    } else {
        mZap.setChecked(false);
    }

    mService.setText(mTimer.getString(Timer.KEY_SERVICE_NAME));

    // Afterevents
    ArrayAdapter<CharSequence> aaAfterevent = ArrayAdapter.createFromResource(getAppCompatActivity(),
            R.array.afterevents, android.R.layout.simple_spinner_item);
    aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mAfterevent.setAdapter(aaAfterevent);

    int aeValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_AFTER_EVENT));
    mAfterevent.setSelection(aeValue);

    // Locations
    ArrayAdapter<String> aaLocations = new ArrayAdapter<>(getAppCompatActivity(),
            android.R.layout.simple_spinner_item, DreamDroid.getLocations());
    aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocation.setAdapter(aaLocations);

    String timerLoc = mTimer.getString(Timer.KEY_LOCATION);
    for (int i = 0; i < DreamDroid.getLocations().size(); i++) {
        String loc = DreamDroid.getLocations().get(i);

        if (timerLoc != null) {
            if (timerLoc.equals(loc)) {
                mLocation.setSelection(i);
            }
        }
    }

    // Start and Endtime
    mBegin = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_BEGIN));
    mEnd = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_END));
    Date dateBegin = new Date(((long) mBegin) * 1000);
    Date dateEnd = new Date(((long) mEnd) * 1000);

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");

    mStartDate.setText(dateFormat.format(dateBegin));
    mStartTime.setText(timeFormat.format(dateBegin));
    mEndDate.setText(dateFormat.format(dateEnd));
    mEndTime.setText(timeFormat.format(dateEnd));

    // Repeatings
    int repeatedValue = 0;
    try {
        repeatedValue = DateTime.parseTimestamp(mTimer.getString(Timer.KEY_REPEATED));
    } catch (NumberFormatException ex) {
    }

    String repeatedText = getRepeated(repeatedValue);
    mRepeatings.setText(repeatedText);

    String text = mTimer.getString(Timer.KEY_TAGS);
    if (text == null) {
        text = "";
    }
    mTags.setText(text);
    String[] tags = text.split(" ");
    Collections.addAll(mSelectedTags, tags);
}

From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java

/**
 * Set the GUI-Content from <code>mTimer</code>
 *//*from  w w  w. j a  v a  2s  .co m*/
private void reload() {
    // Name
    mName.setText(mTimer.getString(Timer.NAME));
    mName.setHint(R.string.title);

    // Description
    mDescription.setText(mTimer.getString(Timer.DESCRIPTION));
    mDescription.setHint(R.string.description);

    // Enabled
    int disabled = new Integer(mTimer.getString(Timer.DISABLED));
    if (disabled == 0) {
        mEnabled.setChecked(true);
    } else {
        mEnabled.setChecked(false);
    }

    mService.setText(mTimer.getString(Timer.SERVICE_NAME));

    // Afterevents
    ArrayAdapter<CharSequence> aaAfterevent = ArrayAdapter.createFromResource(this, R.array.afterevents,
            android.R.layout.simple_spinner_item);
    aaAfterevent.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mAfterevent.setAdapter(aaAfterevent);

    int aeValue = new Integer(mTimer.getString(Timer.AFTER_EVENT)).intValue();
    mAfterevent.setSelection(aeValue);

    // Locations
    ArrayAdapter<String> aaLocations = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            DreamDroid.LOCATIONS);
    aaLocations.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLocation.setAdapter(aaLocations);

    String timerLoc = mTimer.getString(Timer.LOCATION);
    for (int i = 0; i < DreamDroid.LOCATIONS.size(); i++) {
        String loc = DreamDroid.LOCATIONS.get(i);

        if (timerLoc != null) {
            if (timerLoc.equals(loc)) {
                mLocation.setSelection(i);
            }
        }
    }

    // Start and Endtime
    int begin = new Integer(mTimer.getString(Timer.BEGIN));
    int end = new Integer(mTimer.getString(Timer.END));
    long b = ((long) begin) * 1000;
    long e = ((long) end) * 1000;
    Date dateBegin = new Date(b);
    Date dateEnd = new Date(e);

    mStart.setText(dateBegin.toLocaleString());
    mEnd.setText(dateEnd.toLocaleString());

    // Repeatings
    int repeatedValue = new Integer(mTimer.getString(Timer.REPEATED));
    String repeatedText = getRepeated(repeatedValue);
    mRepeatings.setText(repeatedText);

    String text = mTimer.getString(Timer.TAGS);
    if (text == null) {
        text = "";
    }
    mTags.setText(text);
    String[] tags = text.split(" ");
    for (String tag : tags) {
        mSelectedTags.add(tag);
    }
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void showSettings() {
    final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    int selfReportIntervalSpinnerPosition = sharedPref.getInt("selfReportIntervalSpinnerPosition", 2);
    int selfReportVarianceSpinnerPosition = sharedPref.getInt("selfReportVarianceSpinnerPosition", 0);
    int questionnaireSpinnerPosition = sharedPref.getInt("questionnaireSpinnerPosition", 0);
    //int baselineQuestionnaireSpinnerPosition = sharedPref.getInt("baselineQuestionnaireSpinnerPosition", 0);
    String activityName = sharedPref.getString("activityName", "");
    String participantFirstName = sharedPref.getString("participantFirstName", "");
    String participantLastName = sharedPref.getString("participantLastName", "");
    boolean configureInterval = sharedPref.getBoolean("configureInterval", false);
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.settings);
    dialog.setTitle(getString(R.string.action_settings));
    dialog.setCancelable(true);//from  www .ja va2 s. c  om
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setAttributes(lp);
    selfReportIntervalSpinner = (Spinner) dialog.findViewById(R.id.self_report_interval_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_interval_values, android.R.layout.simple_spinner_item);
    selfReportIntervalSpinner.setAdapter(adapter);
    selfReportIntervalSpinner.setSelection(selfReportIntervalSpinnerPosition);
    selfReportVarianceSpinner = (Spinner) dialog.findViewById(R.id.self_report_variance_spinner);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_variance_values, android.R.layout.simple_spinner_item);
    selfReportVarianceSpinner.setAdapter(adapter2);
    selfReportVarianceSpinner.setSelection(selfReportVarianceSpinnerPosition);

    questionnaireSpinner = (Spinner) dialog.findViewById(R.id.questionnaireSpinner);
    //baselineQuestionnaireSpinner = (Spinner) dialog.findViewById(R.id.baseline_questionnaireSpinner);

    String[] questionnaireTitles = new String[0];
    try {
        questionnaireTitles = new String[questionnaireCount];
        for (int i = 0; i < questionnaireCount; i++) {
            String questionnaireFilename = questionnaireFilenames[i];
            String questionnairePath = "questionnaires/" + localeString + "/" + questionnaireFilename;
            try {
                JSONObject questionnaire = Utils
                        .getJSONObjectFromInputStream(getAssets().open(questionnairePath));
                String questionnaireTitle = questionnaire.getJSONObject("questionnaire").getString("title");
                questionnaireTitles[i] = questionnaireTitle;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    ArrayAdapter<String> qSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            questionnaireTitles);
    questionnaireSpinner.setAdapter(qSpinnerAdapter);
    questionnaireSpinner.setSelection(questionnaireSpinnerPosition);
    //baselineQuestionnaireSpinner.setAdapter(qSpinnerAdapter);
    //baselineQuestionnaireSpinner.setSelection(baselineQuestionnaireSpinnerPosition);

    final EditText participantFirstNameEditText = (EditText) dialog
            .findViewById(R.id.participant_first_name_edit_text);
    final EditText participantLastNameEditText = (EditText) dialog
            .findViewById(R.id.participant_last_name_edit_text);
    final EditText activityNameEditText = (EditText) dialog.findViewById(R.id.activity_name_edit_text);
    participantFirstNameEditText.setText(participantFirstName);
    participantLastNameEditText.setText(participantLastName);
    activityNameEditText.setText(activityName);

    final Switch configureIntervalSwitch = (Switch) dialog.findViewById(R.id.configure_interval_switch);
    configureIntervalSwitch.setChecked(configureInterval);
    if (configureInterval) {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
    } else {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
    }

    Button saveButton = (Button) dialog.findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selfReportInterval = Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString());
            selfReportVariance = Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString());

            MainActivity.this.participantFirstName = participantFirstNameEditText.getText().toString().trim();
            MainActivity.this.participantLastName = participantLastNameEditText.getText().toString().trim();
            MainActivity.this.activityName = activityNameEditText.getText().toString().trim();
            MainActivity.this.intervalConfigured = configureIntervalSwitch.isChecked();

            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("selfReportIntervalSpinnerPosition",
                    selfReportIntervalSpinner.getSelectedItemPosition());
            editor.putInt("selfReportVarianceSpinnerPosition",
                    selfReportVarianceSpinner.getSelectedItemPosition());
            editor.putInt("questionnaireSpinnerPosition", questionnaireSpinner.getSelectedItemPosition());
            //editor.putInt("baselineQuestionnaireSpinnerPosition", baselineQuestionnaireSpinner.getSelectedItemPosition());
            editor.putInt("selfReportInterval",
                    Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString()));
            editor.putInt("selfReportVariance",
                    Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString()));

            editor.putString("participantFirstName", participantFirstNameEditText.getText().toString().trim());
            editor.putString("participantLastName", participantLastNameEditText.getText().toString().trim());
            editor.putString("activityName", activityNameEditText.getText().toString().trim());
            editor.putBoolean("configureInterval", configureIntervalSwitch.isChecked());
            editor.apply();

            dialog.dismiss();
        }
    });

    configureIntervalSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
            } else {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
            }
        }
    });
    dialog.show();
}

From source file:com.wishlist.Wishlist.java

public void setPlacesSpinnerAdapter(int spinner_array) {
    ArrayAdapter<CharSequence> location_adapter = ArrayAdapter.createFromResource(this, spinner_array,
            android.R.layout.simple_spinner_item);
    location_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mPlacesListSpinner.setAdapter(location_adapter);
    mPlacesListSpinner.invalidate();/*  ww  w.j av a  2  s  .  c  o  m*/
}

From source file:no.barentswatch.fiskinfo.BaseActivity.java

/**
 * This function creates a dialog which allows the user to register a item
 * or tool used./*ww w  . j  ava  2 s  .c  o  m*/
 * 
 * @param activityContext
 *            The context of the current activity.
 */
public void registerItemAndToolUsed(Context activityContext) {
    LayoutInflater layoutInflater = getLayoutInflater();
    View view = layoutInflater.inflate(R.layout.dialog_register_tool, (null));
    final AlertDialog builder = new AlertDialog.Builder(activityContext).create();
    builder.setTitle(R.string.register_tool_dialog_title);
    builder.setView(view);
    final EditText startingCoordinates = (EditText) view.findViewById(R.id.registerStartingCoordinatesOfTool);
    final EditText endCoordinates = (EditText) view.findViewById(R.id.registerEndCoordinatesOfTool);
    final TextView invalidInputFeedback = (TextView) view.findViewById(R.id.RegisterToolInvalidInputTextView);

    if (lastSetStartingPosition != null) {
        startingCoordinates.setText(lastSetStartingPosition);
    }
    if (lastSetEndPosition != null) {
        endCoordinates.setText(lastSetEndPosition);
    }

    final Spinner projectionSpinner = (Spinner) view.findViewById(R.id.projectionChangingSpinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.projections,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    projectionSpinner.setPrompt("Velg projeksjon");
    projectionSpinner.setAdapter(
            new NoDefaultSpinner(adapter, R.layout.spinner_layout_select_projection, activityContext));

    final Spinner itemSpinner = (Spinner) view.findViewById(R.id.registerMiscType);
    ArrayAdapter<CharSequence> itemAdapter = ArrayAdapter.createFromResource(this, R.array.tool_types,
            android.R.layout.simple_spinner_item);
    itemAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    itemSpinner.setPrompt("Velg redskapstype");
    itemSpinner.setAdapter(
            new NoDefaultSpinner(itemAdapter, R.layout.spinner_layout_choose_tool, activityContext));

    Button fetchToolStartingCoordinatesButton = (Button) view
            .findViewById(R.id.dialogFetchUserStartingCoordinates);
    Button fetchToolEndCoordinatesButton = (Button) view.findViewById(R.id.dialogFetchUserEndCoordinates);

    fetchToolStartingCoordinatesButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setToolCoordinatesPosition(startingCoordinates);
        }
    });

    fetchToolEndCoordinatesButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setToolCoordinatesPosition(endCoordinates);
        }
    });

    acceptButtonRegister(view, builder, startingCoordinates, endCoordinates, invalidInputFeedback,
            projectionSpinner, itemSpinner);

    Button cancelButton = (Button) view.findViewById(R.id.DialogCancelRegistration);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            builder.dismiss();
        }
    });

    builder.show();
}

From source file:org.smilec.smile.ui.GeneralActivity.java

private void showResults() {
    TableLayout tlTotal = (TableLayout) findViewById(R.id.tl_total);
    tlTotal.setVisibility(View.GONE);

    TextView tvTotal = (TextView) findViewById(R.id.tv_total);
    tvTotal.setVisibility(View.GONE);

    View vTotal = findViewById(R.id.view_separator_total);
    vTotal.setVisibility(View.GONE);

    TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 315);

    ListView lvListStudents = (ListView) GeneralActivity.this.findViewById(R.id.lv_students);
    lvListStudents.setLayoutParams(layoutParams);
    lvListStudents.setPadding(5, 0, 0, 0);

    TextView tvTopTitle = (TextView) GeneralActivity.this.findViewById(R.id.tv_top_scorers);
    tvTopTitle.setVisibility(View.VISIBLE);

    //        View vSeparatorScore = findViewById(R.id.view_separator_score);
    //        vSeparatorScore.setVisibility(View.VISIBLE);

    RelativeLayout rlTopScorersContainer = (RelativeLayout) GeneralActivity.this
            .findViewById(R.id.rl_top_scorers);
    rlTopScorersContainer.setVisibility(View.VISIBLE);

    spLimitToSucceed = (Spinner) findViewById(R.id.sp_limit_to_succeed);
    ArrayAdapter<?> adapterLimit = ArrayAdapter.createFromResource(this, R.array.percent_correct,
            android.R.layout.simple_spinner_item);
    adapterLimit.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spLimitToSucceed.setAdapter(adapterLimit);

    // Initialize the spinner to 70%
    spLimitToSucceed.setSelection(2);//w w w .  j  a va  2 s.  c om

    // If the teacher clicks on the spinner to set a different limit to succeed
    spLimitToSucceed.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {

            String[] bases = getResources().getStringArray(R.array.percent_correct);
            if (activeFragment instanceof StudentsFragment) {
                ((StudentsFragment) activeFragment).updatePercentCorrect(Integer.parseInt(bases[position]));
            }
        }

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

    // If the teacher clicks on "Send results" button
    Button btSendResults = (Button) GeneralActivity.this.findViewById(R.id.bt_send_results);
    btSendResults.setVisibility(View.VISIBLE);
    btSendResults.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SendEmailResultsUtil.send(board, ip, GeneralActivity.this);
        }
    });
}

From source file:be.billington.calendar.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 av  a2  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 = (Switch) 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 (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.android.calendar.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;// ww w .j  a  v a  2s  . 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 = (Switch) 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);

    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());

    int numOfButtonsInRow1;
    int numOfButtonsInRow2;

    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(DateUtils.getDayOfWeekString(TIME_DAY_TO_CALENDAR_DAY[idx], DateUtils.LENGTH_LONG));
        mWeekByDayButtons[idx]
                .setTextOn(DateUtils.getDayOfWeekString(TIME_DAY_TO_CALENDAR_DAY[idx], DateUtils.LENGTH_LONG));
        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(DateUtils.getDayOfWeekString(TIME_DAY_TO_CALENDAR_DAY[idx], DateUtils.LENGTH_LONG));
        mWeekByDayButtons[idx]
                .setTextOn(DateUtils.getDayOfWeekString(TIME_DAY_TO_CALENDAR_DAY[idx], DateUtils.LENGTH_LONG));
        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.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;//  w  w  w . j a v a  2 s  . c om
        }
        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 = (Switch) 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;
}