List of usage examples for android.widget Spinner setAdapter
@Override public void setAdapter(SpinnerAdapter adapter)
From source file:com.near.chimerarevo.fragments.ProductsListFragment.java
private void setSpinnerValue(Spinner sp, JSONArray jArr) { if (sp.getId() == R.id.brand_spinner) { brandsList.add(getResources().getString(R.string.text_brands_all)); for (int i = 0; i < jArr.length(); i++) { try { brandsList.add(jArr.getString(i)); } catch (JSONException e) { e.printStackTrace();/*from w ww . ja va 2 s . c o m*/ } } sp.setAdapter( new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, brandsList)); } else if (sp.getId() == R.id.category_spinner) { catList.add(getResources().getString(R.string.text_categories_all)); for (int i = 0; i < jArr.length(); i++) { JSONObject jCat; try { jCat = jArr.getJSONObject(i); catList.add(jCat.getString(Constants.KEY_NAME)); catIdList.add(jCat.getInt(Constants.KEY_ID)); } catch (JSONException e) { e.printStackTrace(); } } sp.setAdapter( new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, catList)); } }
From source file:org.ciasaboark.tacere.activity.fragment.BugReportDialogFragment.java
@Nullable @Override/*w w w . j ava 2 s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.activity_bug_report, container, false); final Spinner spinner = (Spinner) rootView.findViewById(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.report_types, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); Button closeButton = (Button) rootView.findViewById(R.id.bug_report_button_cancel); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BugReportDialogFragment.this.dismiss(); } }); final Button sendButton = (Button) rootView.findViewById(R.id.bug_report_button_send); sendButton.setEnabled(false); sendButton.setVisibility(View.INVISIBLE); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendButton.setEnabled(false); final ProgressBar busySpinner = (ProgressBar) rootView.findViewById(R.id.bug_report_progressbar); busySpinner.setVisibility(View.VISIBLE); EditText messageEditText = (EditText) rootView.findViewById(R.id.bug_report_message); final String messageText = messageEditText.getText().toString(); EditText emailEditText = (EditText) rootView.findViewById(R.id.bug_report_email); String emailText = emailEditText.getText().toString(); final String emailString = emailText.length() == 0 ? "no email address given" : emailText; final String spinnerSelection = spinner.getSelectedItem() == null ? "bug" : spinner.getSelectedItem().toString(); new Thread(new Runnable() { @Override public void run() { boolean reportSent = false; GitHubClient client = new GitHubClient(); client.setOAuth2Token(GitHubKeySet.GITHUB_OAUTH); RepositoryService repositoryService = new RepositoryService(client); try { Repository repository = repositoryService.getRepository("ciasaboark", "Tacere"); IssueService issueService = new IssueService(); issueService.getClient().setOAuth2Token(GitHubKeySet.GITHUB_OAUTH); Issue issue = new Issue(); issue.setTitle("Tacere issue submit"); String bodyText = ""; bodyText += messageText; bodyText += "\n\nEmail : " + emailString; bodyText += "\nAndroid Version: " + Build.VERSION.RELEASE; bodyText += "\nTacere version: " + Versioning.getVersionCode(); bodyText += "\nDevice: " + Build.MANUFACTURER + " - " + Build.MODEL; bodyText += "\nRom: " + Build.DISPLAY; issue.setBody(bodyText); Label label = new Label(); label.setName("autosubmit"); List<Label> labels = new ArrayList<Label>(); labels.add(label); String reportTypeLabel; switch (spinnerSelection.toLowerCase()) { case "bug": reportTypeLabel = "bug"; break; case "wishlist": reportTypeLabel = "wishlist"; break; default: Log.w(TAG, "unknown reportType " + spinnerSelection + ", assuming to " + "be a bug report"); reportTypeLabel = "bug"; } Label reportLabel = new Label(); reportLabel.setName(reportTypeLabel); labels.add(reportLabel); issue.setLabels(labels); UserService userService = new UserService(client); User user = userService.getUser("ciasaboark"); issue.setAssignee(user); try { issueService.createIssue(repository, issue); reportSent = true; } catch (IOException e) { Log.e(TAG, "unable to create issue in repository"); } } catch (IOException e) { Log.e(TAG, "unable to get list of user repositories"); } if (reportSent) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), R.string.bug_report_toast_sent, Toast.LENGTH_LONG) .show(); BugReportDialogFragment.this.dismiss(); } }); } else { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), R.string.bug_report_toast_failed, Toast.LENGTH_LONG).show(); busySpinner.setVisibility(View.INVISIBLE); sendButton.setEnabled(true); sendButton.setVisibility(View.VISIBLE); } }); } } }).start(); } }); EditText messageEditText = (EditText) rootView.findViewById(R.id.bug_report_message); messageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { //nothing to do here } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { //nothing to do here } @Override public void afterTextChanged(Editable s) { if (s.length() > 0) { sendButton.setVisibility(View.VISIBLE); sendButton.setEnabled(true); } else { sendButton.setVisibility(View.INVISIBLE); sendButton.setEnabled(false); } } }); return rootView; }
From source file:com.keithandthegirl.ui.activity.EpisodesFragment.java
@TargetApi(11) @Override/*from ww w . j a va 2 s. co m*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { Log.v(TAG, "onCreateOptionsMenu : enter"); super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.fragment_episodes_menu, menu); if (mainApplication.isVIP()) { if (null == mSpinnerItem) { mSpinnerItem = menu.findItem(R.id.episodes_show); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mSpinnerItem.setVisible(true); View view = mSpinnerItem.getActionView(); view.setVisibility(View.VISIBLE); if (view instanceof Spinner) { final Spinner spinner = (Spinner) view; spinner.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_dropdown_item, Show.getKeys())); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String selected = (String) spinner.getSelectedItem(); Show show = Show.findByKey(selected); restartLoader(show); } public void onNothingSelected(AdapterView<?> arg0) { } }); } } else { mSpinnerItem.setVisible(false); } } // mPlayer = menu.findItem( R.id.episodes_player ); // if( MediaPlayerServiceRunning() ) { // mPlayer.setVisible( true ); // } else { // mPlayer.setVisible( false ); // } Log.v(TAG, "onCreateOptionsMenu : exit"); }
From source file:com.esri.arcgisruntime.sample.rgbrenderer.ParametersDialogFragment.java
/** * Builds parameter dialog with values pulled through from MainActivity. * * @param savedInstanceState//www . j av a 2 s . com * @return create parameter dialog box */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); Bundle rgbParameters = getArguments(); if (rgbParameters != null) { mMinR = rgbParameters.getInt("minR"); mMaxR = rgbParameters.getInt("maxR"); mMinG = rgbParameters.getInt("minG"); mMaxG = rgbParameters.getInt("maxG"); mMinB = rgbParameters.getInt("minB"); mMaxB = rgbParameters.getInt("maxB"); mPercentClipMin = rgbParameters.getInt("percent_clip_min"); mPercentClipMax = rgbParameters.getInt("percent_clip_max"); mStdDevFactor = rgbParameters.getInt("std_dev_factor"); mStretchType = (MainActivity.StretchType) rgbParameters.getSerializable("stretch_type"); Log.d("Incoming Parameters", "min r: " + mMinR + " max r: " + mMaxR + " min g: " + mMinG + " max g: " + mMaxG + " min b: " + mMinB + " max b: " + mMaxB); } final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext()); @SuppressLint("InflateParams") final View dialogView = inflater.inflate(R.layout.rgb_dialog_box, null); paramDialog.setView(dialogView); paramDialog.setTitle(R.string.rgb_rendering_parameters); paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }); paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); ParametersListener activity = (ParametersListener) getActivity(); activity.returnParameters(mMinR, mMaxR, mMinG, mMaxG, mMinB, mMaxB, mPercentClipMin, mPercentClipMax, mStdDevFactor, mStretchType); } }); // min max ui elements mMinRedTextView = (TextView) dialogView.findViewById(R.id.min_red_value_text_view); mMaxRedTextView = (TextView) dialogView.findViewById(R.id.max_red_value_text_view); mMinGreenTextView = (TextView) dialogView.findViewById(R.id.min_green_value_text_view); mMaxGreenTextView = (TextView) dialogView.findViewById(R.id.max_green_value_text_view); mMinBlueTextView = (TextView) dialogView.findViewById(R.id.min_blue_value_text_view); mMaxBlueTextView = (TextView) dialogView.findViewById(R.id.max_blue_value_text_view); mMinRedSeekBar = (SeekBar) dialogView.findViewById(R.id.min_red_seek_bar); mMaxRedSeekBar = (SeekBar) dialogView.findViewById(R.id.max_red_seek_bar); mMinGreenSeekBar = (SeekBar) dialogView.findViewById(R.id.min_green_seek_bar); mMaxGreenSeekBar = (SeekBar) dialogView.findViewById(R.id.max_green_seek_bar); mMinBlueSeekBar = (SeekBar) dialogView.findViewById(R.id.min_blue_seek_bar); mMaxBlueSeekBar = (SeekBar) dialogView.findViewById(R.id.max_blue_seek_bar); mMinRedSeekBar.setMax(255); mMaxRedSeekBar.setMax(255); mMinGreenSeekBar.setMax(255); mMaxGreenSeekBar.setMax(255); mMinBlueSeekBar.setMax(255); mMaxBlueSeekBar.setMax(255); mCurrMinRedTextView = (TextView) dialogView.findViewById(R.id.curr_min_red_text_view); mCurrMaxRedTextView = (TextView) dialogView.findViewById(R.id.curr_max_red_text_view); mCurrMinGreenTextView = (TextView) dialogView.findViewById(R.id.curr_min_green_text_view); mCurrMaxGreenTextView = (TextView) dialogView.findViewById(R.id.curr_max_green_text_view); mCurrMinBlueTextView = (TextView) dialogView.findViewById(R.id.curr_min_blue_text_view); mCurrMaxBlueTextView = (TextView) dialogView.findViewById(R.id.curr_max_blue_text_view); //update seek bar positions with current mMinMax values updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); // percent clip ui elements mPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.percent_clip_min_value_text_view); mPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.percent_clip_max_value_text_view); mPercentClipMinSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_min_seek_bar); mPercentClipMaxSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_max_seek_bar); mPercentClipMinSeekBar.setMax(99); mPercentClipMaxSeekBar.setMax(99); mCurrPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_min_text_view); mCurrPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_max_text_view); //update seek bar positions with current PercentClip updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); // standard deviation ui elements mStdDevTextView = (TextView) dialogView.findViewById(R.id.std_dev_text_view); mStdDevSeekBar = (SeekBar) dialogView.findViewById(R.id.std_dev_seek_bar); mStdDevSeekBar.setMax(3); mCurrStdDevTextView = (TextView) dialogView.findViewById(R.id.curr_std_dev_text_view); //update seek bar position with current StandardDeviation updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView); // set ui to previous selection if (mStretchType == MainActivity.StretchType.MIN_MAX) { setMinMaxVisibility(true); setPercentClipVisibility(false); setStdDevVisibility(false); } else if (mStretchType == MainActivity.StretchType.PERCENT_CLIP) { setMinMaxVisibility(false); setPercentClipVisibility(true); setStdDevVisibility(false); } else if (mStretchType == MainActivity.StretchType.STANDARD_DEVIATION) { setMinMaxVisibility(false); setPercentClipVisibility(false); setStdDevVisibility(true); } // seek bar listeners mMinRedSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinR = progress; updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); // move max to march min if max goes below min if (mMaxR < mMinR) { mMaxR = mMinR; updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxRedSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxR = progress; updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); // move min to match max if min goes above max if (mMinR > mMaxR) { mMinR = mMaxR; updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMinGreenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinG = progress; updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); // move max to march min if max goes below min if (mMaxG < mMinG) { mMaxG = mMinG; updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxGreenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxG = progress; updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); // move min to match max if min goes above max if (mMinG > mMaxG) { mMinG = mMaxG; updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMinBlueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinB = progress; updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); // move max to march min if max goes below min if (mMaxB < mMinB) { mMaxB = mMinB; updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxBlueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxB = progress; updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); // move min to match max if min goes above max if (mMinB > mMaxB) { mMinB = mMaxB; updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mPercentClipMinSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mPercentClipMin = progress; updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); if (mPercentClipMin + mPercentClipMax > 100) { // constrain min + max <= 100 mPercentClipMax = 100 - mPercentClipMin; updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mPercentClipMaxSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mPercentClipMax = progress; updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); if (mPercentClipMin + mPercentClipMax > 100) { // constrain min + max <= 100 mPercentClipMin = 100 - mPercentClipMax; updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mStdDevSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mStdDevFactor = progress; updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // stretch type spinner List<String> stretchTypeArray = new ArrayList<>(); stretchTypeArray.add(MainActivity.StretchType.MIN_MAX.toString()); //ordinals:0 stretchTypeArray.add(MainActivity.StretchType.PERCENT_CLIP.toString()); //1 stretchTypeArray.add(MainActivity.StretchType.STANDARD_DEVIATION.toString()); //2 ArrayAdapter<String> stretchTypeSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.rgb_spinner_text_view, stretchTypeArray); Spinner stretchTypeSpinner = (Spinner) dialogView.findViewById(R.id.stretch_type_spinner); stretchTypeSpinner.setAdapter(stretchTypeSpinnerAdapter); stretchTypeSpinner.setSelection(mStretchType.ordinal()); stretchTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: mStretchType = MainActivity.StretchType.MIN_MAX; setMinMaxVisibility(true); setPercentClipVisibility(false); setStdDevVisibility(false); break; case 1: mStretchType = MainActivity.StretchType.PERCENT_CLIP; setMinMaxVisibility(false); setPercentClipVisibility(true); setStdDevVisibility(false); break; case 2: mStretchType = MainActivity.StretchType.STANDARD_DEVIATION; setMinMaxVisibility(false); setPercentClipVisibility(false); setStdDevVisibility(true); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); return paramDialog.create(); }
From source file:com.yschi.castscreen.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mResultCode = savedInstanceState.getInt(STATE_RESULT_CODE); mResultData = savedInstanceState.getParcelable(STATE_RESULT_DATA); }//from w w w . j a v a 2s .com mContext = this; mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); mDiscoverdMap = new HashMap<>(); mDiscoverListView = (ListView) findViewById(R.id.discover_listview); mDiscoverAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); mDiscoverAdapter.addAll(mDiscoverdMap.keySet()); mDiscoverListView.setAdapter(mDiscoverAdapter); mDiscoverListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String name = mDiscoverAdapter.getItem(i); String ip = mDiscoverdMap.get(name); Log.d(TAG, "Select receiver name: " + name + ", ip: " + ip); mReceiverIp = ip; updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } }); // add server mode option mDiscoverAdapter.add(mContext.getString(R.string.server_mode)); mDiscoverdMap.put(mContext.getString(R.string.server_mode), ""); mReceiverTextView = (TextView) findViewById(R.id.receiver_textview); final EditText ipEditText = (EditText) findViewById(R.id.ip_edittext); final Button selectButton = (Button) findViewById(R.id.select_button); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (ipEditText.getText().length() > 0) { mReceiverIp = ipEditText.getText().toString(); Log.d(TAG, "Using ip: " + mReceiverIp); updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit() .putString(PREF_KEY_INPUT_RECEIVER, mReceiverIp).commit(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } } }); ipEditText.setText(mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_INPUT_RECEIVER, "")); Spinner formatSpinner = (Spinner) findViewById(R.id.format_spinner); ArrayAdapter<CharSequence> formatAdapter = ArrayAdapter.createFromResource(this, R.array.format_options, android.R.layout.simple_spinner_item); formatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); formatSpinner.setAdapter(formatAdapter); formatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedFormat = FORMAT_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedFormat = FORMAT_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, 0).commit(); } }); formatSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_FORMAT, 0)); Spinner resolutionSpinner = (Spinner) findViewById(R.id.resolution_spinner); ArrayAdapter<CharSequence> resolutionAdapter = ArrayAdapter.createFromResource(this, R.array.resolution_options, android.R.layout.simple_spinner_item); resolutionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); resolutionSpinner.setAdapter(resolutionAdapter); resolutionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedWidth = RESOLUTION_OPTIONS[i][0]; mSelectedHeight = RESOLUTION_OPTIONS[i][1]; mSelectedDpi = RESOLUTION_OPTIONS[i][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedWidth = RESOLUTION_OPTIONS[0][0]; mSelectedHeight = RESOLUTION_OPTIONS[0][1]; mSelectedDpi = RESOLUTION_OPTIONS[0][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, 0).commit(); } }); resolutionSpinner .setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_RESOLUTION, 0)); Spinner bitrateSpinner = (Spinner) findViewById(R.id.bitrate_spinner); ArrayAdapter<CharSequence> bitrateAdapter = ArrayAdapter.createFromResource(this, R.array.bitrate_options, android.R.layout.simple_spinner_item); bitrateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bitrateSpinner.setAdapter(bitrateAdapter); bitrateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedBitrate = BITRATE_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedBitrate = BITRATE_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, 0).commit(); } }); bitrateSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_BITRATE, 0)); mReceiverIp = mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_RECEIVER, ""); updateReceiverStatus(); startService(); }
From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java
@Override public View getPrototypeView(Context context) { View prototypeView = View.inflate(context, R.layout.brick_set_variable, null); Spinner variableSpinner = (Spinner) prototypeView.findViewById(R.id.set_variable_spinner); variableSpinner.setFocusableInTouchMode(false); variableSpinner.setFocusable(false); UserVariableAdapter userVariableAdapter = ProjectManager.getInstance().getCurrentProject() .getUserVariables().createUserVariableAdapter(context, sprite); UserVariableAdapterWrapper userVariableAdapterWrapper = new UserVariableAdapterWrapper(context, userVariableAdapter);/* w ww .j a v a 2 s . c o m*/ userVariableAdapterWrapper.setItemLayout(android.R.layout.simple_spinner_item, android.R.id.text1); variableSpinner.setAdapter(userVariableAdapterWrapper); setSpinnerSelection(variableSpinner, null); TextView textSetVariable = (TextView) prototypeView.findViewById(R.id.brick_set_variable_prototype_view); textSetVariable.setText(String.valueOf(variableFormula.interpretDouble(sprite))); return prototypeView; }
From source file:com.ichi2.anki.ModelBrowser.java
private void addNewNoteTypeDialog() { String add = getResources().getString(R.string.model_browser_add_add); String clone = getResources().getString(R.string.model_browser_add_clone); // AnkiDroid doesn't have stdmodels class or model name localization, this could be much cleaner if implemented final String basicName = "Basic"; final String addForwardReverseName = "Basic (and reversed card)"; final String addForwardOptionalReverseName = "Basic (optional reversed card)"; final String addClozeModelName = "Cloze"; //Populates arrayadapters listing the mModels (includes prefixes/suffixes) mNewModelLabels = new ArrayList<>(); //Used to fetch model names mNewModelNames = new ArrayList<>(); mNewModelLabels.add(String.format(add, basicName)); mNewModelLabels.add(String.format(add, addForwardReverseName)); mNewModelLabels.add(String.format(add, addForwardOptionalReverseName)); mNewModelLabels.add(String.format(add, addClozeModelName)); mNewModelNames.add(basicName);// w w w. j a v a 2 s.co m mNewModelNames.add(addForwardReverseName); mNewModelNames.add(addForwardOptionalReverseName); mNewModelNames.add(addClozeModelName); final int numStdModels = mNewModelLabels.size(); if (mModels != null) { for (JSONObject model : mModels) { try { mNewModelLabels.add(String.format(clone, model.getString("name"))); mNewModelNames.add(model.getString("name")); } catch (JSONException e) { throw new RuntimeException(e); } } } final Spinner addSelectionSpinner = new Spinner(this); ArrayAdapter<String> mNewModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item, mNewModelLabels); addSelectionSpinner.setAdapter(mNewModelAdapter); new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok) .customView(addSelectionSpinner, true).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { mModelNameInput = new EditText(ModelBrowser.this); mModelNameInput.setSingleLine(); //Temporary workaround - Lack of stdmodels class if (addSelectionSpinner.getSelectedItemPosition() < numStdModels) { mModelNameInput.setText(randomizeName( mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition()))); } else { mModelNameInput .setText(mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition()) + " " + getResources().getString(R.string.model_clone_suffix)); } mModelNameInput.setSelection(mModelNameInput.getText().length()); //Create textbox to name new model new MaterialDialog.Builder(ModelBrowser.this).title(R.string.model_browser_add) .positiveText(R.string.dialog_ok).customView(mModelNameInput, true) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { String modelName = mModelNameInput.getText().toString(); addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition()); } }).negativeText(R.string.dialog_cancel).show(); } }).negativeText(R.string.dialog_cancel).show(); }
From source file:li.klass.fhem.fragments.TimerDetailFragment.java
private void createRepetitionSpinner(View view) { Spinner repetitionSpinner = getRepetitionSpinner(view); ArrayAdapter<String> repetitionAdapter = new ArrayAdapter<>(getActivity(), R.layout.spinnercontent); for (AtDevice.AtRepetition atRepetition : AtDevice.AtRepetition.values()) { repetitionAdapter.add(view.getContext().getString(atRepetition.getText())); }/*from ww w .java 2 s . co m*/ repetitionSpinner.setAdapter(repetitionAdapter); repetitionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { TimerDetailFragment.this.repetition = AtDevice.AtRepetition.values()[i]; } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
From source file:com.adithya321.sharesanalysis.fragments.SalesShareFragment.java
@Nullable @Override// w w w . ja va 2 s . c om public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_sales, container, false); databaseHandler = new DatabaseHandler(getContext()); salesRecyclerView = (RecyclerView) root.findViewById(R.id.sales_recycler_view); setRecyclerViewAdapter(); FloatingActionButton sellShareFab = (FloatingActionButton) root.findViewById(R.id.sell_share_fab); sellShareFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getContext()); dialog.setTitle("Sell Share Holdings"); dialog.setContentView(R.layout.dialog_sell_share_holdings); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); for (Share share : sharesList) { shares.add(share.getName()); } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); Calendar calendar = Calendar.getInstance(); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start, month_start - 1, day_start); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { selectDate.setText(new StringBuilder().append(day_start).append("/") .append(month_start).append("/").append(year_start)); } }); dialog.show(); } }); Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn); sellShareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase purchase = new Purchase(); purchase.setId(databaseHandler.getNextKey("purchase")); purchase.setName(spinner.getSelectedItem().toString()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); purchase.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); try { purchase.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } EditText price = (EditText) dialog.findViewById(R.id.selling_price); try { purchase.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Selling Price", Toast.LENGTH_SHORT).show(); return; } purchase.setType("sell"); databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); return root; }
From source file:li.klass.fhem.fragments.ConnectionDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { return view; }//from w w w .j a v a2 s .c om view = inflater.inflate(R.layout.connection_detail, container, false); assert (view != null); Spinner connectionTypeSpinner = (Spinner) view.findViewById(R.id.connectionType); if (isModify) { connectionTypeSpinner.setEnabled(false); } final List<ServerType> connectionTypes = getServerTypes(); ArrayAdapter<ServerType> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, connectionTypes); connectionTypeSpinner.setAdapter(adapter); connectionTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) { handleConnectionTypeChange(connectionTypes.get(position)); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); Button saveButton = (Button) view.findViewById(R.id.save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleSave(); } }); return view; }