List of usage examples for android.widget ArrayAdapter setDropDownViewResource
public void setDropDownViewResource(@LayoutRes int resource)
Sets the layout resource to create the drop down views.
From source file:com.zira.registration.VehicleInformationActivity.java
protected void setApapterForState() { ArrayAdapter<State> dataAdapter = new ArrayAdapter<State>(this, R.layout.spinner_list, stateList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); StateNameSpinner.setAdapter(dataAdapter); if (value == 1) { //gettingStatePosition=0; //StateNameSpinner.setSelection(gettingStatePosition); if (stateList.size() > gettingStatePosition) { StateNameSpinner.setSelection(gettingStatePosition); }//from w w w . j a v a 2 s. co m if (flag > 1) { StateNameSpinner.setSelection(gettingStatePosition); } //if((mProfileInfoModel.getLicenseplatecountryID()).equalsIgnoreCase()) } }
From source file:com.money.manager.ex.search.SearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) return null; View view = inflater.inflate(R.layout.search_fragment, container, false); initializeUiControlVariables(view);/* w w w. j a v a2s . c o m*/ initializeAmountSelectors(view); // Account if (mAccountList == null) { LookAndFeelSettings settings = new AppSettings(getContext()).getLookAndFeelSettings(); AccountService accountService = new AccountService(getContext()); mAccountList = accountService.getAccountList(settings.getViewOpenAccounts(), settings.getViewFavouriteAccounts()); mAccountList.add(0, null); for (int i = 0; i <= mAccountList.size() - 1; i++) { if (mAccountList.get(i) != null) { mAccountNameList.add(mAccountList.get(i).getName()); mAccountIdList.add(mAccountList.get(i).getId()); } else { mAccountNameList.add(""); mAccountIdList.add(AdapterView.INVALID_POSITION); } } } // create adapter for spinAccount ArrayAdapter<String> adapterAccount = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mAccountNameList); adapterAccount.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinAccount.setAdapter(adapterAccount); //Payee txtSelectPayee.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), PayeeActivity.class); intent.setAction(Intent.ACTION_PICK); startActivityForResult(intent, REQUEST_PICK_PAYEE); } }); //Category txtSelectCategory.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), CategoryListActivity.class); intent.setAction(Intent.ACTION_PICK); startActivityForResult(intent, REQUEST_PICK_CATEGORY); } }); // Status if (mStatusItems.size() <= 0) { // add blank row mStatusItems.add(""); mStatusValues.add(SearchParameters.STRING_NULL_VALUE); mStatusItems.addAll(Arrays.asList(getResources().getStringArray(R.array.status_items))); mStatusValues.addAll(Arrays.asList(getResources().getStringArray(R.array.status_values))); } // create adapter for spinnerStatus ArrayAdapter<String> adapterStatus = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mStatusItems); adapterStatus.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinStatus.setAdapter(adapterStatus); // Date from txtDateFrom.setOnClickListener(new OnDateButtonClickListener(getActivity(), txtDateFrom)); // Date to txtDateTo.setOnClickListener(new OnDateButtonClickListener(getActivity(), txtDateTo)); initializeResetButton(view); // Store search criteria values into the controls. displaySearchCriteria(view); return view; }
From source file:eu.power_switch.gui.fragment.settings.GeneralSettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_general_settings, container, false); final Fragment fragment = this; CompoundButton.OnCheckedChangeListener onCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override//from w w w .j ava 2 s. co m public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { switch (buttonView.getId()) { case R.id.checkBox_autoDiscover: SmartphonePreferencesHandler.setAutoDiscover(isChecked); break; case R.id.checkBox_autoCollapseRooms: SmartphonePreferencesHandler.setAutoCollapseRooms(isChecked); break; case R.id.checkBox_autoCollapseTimers: SmartphonePreferencesHandler.setAutoCollapseTimers(isChecked); break; case R.id.checkBox_showRoomAllOnOffButtons: SmartphonePreferencesHandler.setShowRoomAllOnOff(isChecked); break; case R.id.checkBox_hideAddFAB: SmartphonePreferencesHandler.setUseOptionsMenuInsteadOfFAB(isChecked); break; case R.id.checkBox_vibrateOnButtonPress: SmartphonePreferencesHandler.setVibrateOnButtonPress(isChecked); if (isChecked) { vibrationDurationLayout.setVisibility(View.VISIBLE); } else { vibrationDurationLayout.setVisibility(View.GONE); } break; case R.id.checkBox_highlightLastActivatedButton: SmartphonePreferencesHandler.setHighlightLastActivatedButton(isChecked); // force receiver widget update ReceiverWidgetProvider.forceWidgetUpdate(getContext()); break; default: break; } } }; // setup hidden developer menu TextView generalSettingsTextView = (TextView) rootView.findViewById(R.id.TextView_generalSettings); generalSettingsTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar currentTime = Calendar.getInstance(); if (devMenuFirstClickTime != null) { Calendar latestTime = Calendar.getInstance(); latestTime.setTime(devMenuFirstClickTime.getTime()); latestTime.add(Calendar.SECOND, 5); if (currentTime.after(latestTime)) { devMenuClickCounter = 0; } } devMenuClickCounter++; if (devMenuClickCounter == 1) { devMenuFirstClickTime = currentTime; } if (devMenuClickCounter >= 5) { devMenuClickCounter = 0; DeveloperOptionsDialog developerOptionsDialog = new DeveloperOptionsDialog(); developerOptionsDialog.show(getActivity().getSupportFragmentManager(), null); } } }); startupDefaultTab = (Spinner) rootView.findViewById(R.id.spinner_startupDefaultTab); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.main_tab_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); startupDefaultTab.setAdapter(adapter); startupDefaultTab.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SmartphonePreferencesHandler.setStartupDefaultTab(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); autoDiscover = (CheckBox) rootView.findViewById(R.id.checkBox_autoDiscover); autoDiscover.setOnCheckedChangeListener(onCheckedChangeListener); autoCollapseRooms = (CheckBox) rootView.findViewById(R.id.checkBox_autoCollapseRooms); autoCollapseRooms.setOnCheckedChangeListener(onCheckedChangeListener); autoCollapseTimers = (CheckBox) rootView.findViewById(R.id.checkBox_autoCollapseTimers); autoCollapseTimers.setOnCheckedChangeListener(onCheckedChangeListener); showRoomAllOnOffButtons = (CheckBox) rootView.findViewById(R.id.checkBox_showRoomAllOnOffButtons); showRoomAllOnOffButtons.setOnCheckedChangeListener(onCheckedChangeListener); hideAddFAB = (CheckBox) rootView.findViewById(R.id.checkBox_hideAddFAB); hideAddFAB.setOnCheckedChangeListener(onCheckedChangeListener); highlightLastActivatedButton = (CheckBox) rootView.findViewById(R.id.checkBox_highlightLastActivatedButton); highlightLastActivatedButton.setOnCheckedChangeListener(onCheckedChangeListener); vibrateOnButtonPress = (CheckBox) rootView.findViewById(R.id.checkBox_vibrateOnButtonPress); vibrateOnButtonPress.setOnCheckedChangeListener(onCheckedChangeListener); vibrationDurationLayout = (LinearLayout) rootView.findViewById(R.id.linearLayout_vibrationDuration); vibrationDuration = (EditText) rootView.findViewById(R.id.editText_vibrationDuration); vibrationDuration.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (s != null && s.length() > 0) { SmartphonePreferencesHandler.setVibrationDuration(Integer.valueOf(s.toString())); } } }); keepHistoryDuration = (Spinner) rootView.findViewById(R.id.spinner_keep_history); ArrayAdapter<CharSequence> adapterHistory = ArrayAdapter.createFromResource(getContext(), R.array.keep_history_selection_names, android.R.layout.simple_spinner_item); adapterHistory.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); keepHistoryDuration.setAdapter(adapterHistory); keepHistoryDuration.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SmartphonePreferencesHandler.setKeepHistoryDuration(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); textView_backupPath = (TextView) rootView.findViewById(R.id.textView_backupPath); Button button_changeBackupPath = (Button) rootView.findViewById(R.id.button_changeBackupPath); button_changeBackupPath.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!PermissionHelper.isWriteExternalStoragePermissionAvailable(getContext())) { Snackbar snackbar = Snackbar.make(rootView, R.string.missing_external_storage_permission, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.grant, new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(MainActivity.getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PermissionConstants.REQUEST_CODE_STORAGE_PERMISSION); } }); snackbar.show(); } PathChooserDialog pathChooserDialog = PathChooserDialog.newInstance(); pathChooserDialog.setTargetFragment(fragment, 0); pathChooserDialog.show(getActivity().getSupportFragmentManager(), null); } }); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.radioButton_darkBlue: SmartphonePreferencesHandler.setTheme(SettingsConstants.THEME_DARK_BLUE); break; case R.id.radioButton_lightBlue: SmartphonePreferencesHandler.setTheme(SettingsConstants.THEME_LIGHT_BLUE); break; case R.id.radioButton_dayNight_blue: SmartphonePreferencesHandler.setTheme(SettingsConstants.THEME_DAY_NIGHT_BLUE); break; default: break; } getActivity().finish(); Intent intent = new Intent(getContext(), MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }; radioButtonDarkBlue = (RadioButton) rootView.findViewById(R.id.radioButton_darkBlue); radioButtonDarkBlue.setOnClickListener(onClickListener); radioButtonLightBlue = (RadioButton) rootView.findViewById(R.id.radioButton_lightBlue); radioButtonLightBlue.setOnClickListener(onClickListener); radioButtonDayNightBlue = (RadioButton) rootView.findViewById(R.id.radioButton_dayNight_blue); radioButtonDayNightBlue.setOnClickListener(onClickListener); sendLogsProgress = (ProgressBar) rootView.findViewById(R.id.sendLogsProgress); sendLogs = (Button) rootView.findViewById(R.id.button_sendLogs); sendLogs.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendLogs.setEnabled(false); sendLogsProgress.setVisibility(View.VISIBLE); new AsyncTask<Void, Void, AsyncTaskResult<Boolean>>() { @Override protected AsyncTaskResult<Boolean> doInBackground(Void... params) { try { LogHandler.sendLogsAsMail(getContext()); return new AsyncTaskResult<>(true); } catch (Exception e) { return new AsyncTaskResult<>(e); } } @Override protected void onPostExecute(AsyncTaskResult<Boolean> booleanAsyncTaskResult) { if (booleanAsyncTaskResult.isSuccess()) { // all is good } else { if (booleanAsyncTaskResult.getException() instanceof MissingPermissionException) { Snackbar snackbar = Snackbar.make(rootView, R.string.missing_external_storage_permission, Snackbar.LENGTH_LONG); snackbar.setAction(R.string.grant, new View.OnClickListener() { @Override public void onClick(View v) { ActivityCompat.requestPermissions(MainActivity.getActivity(), new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PermissionConstants.REQUEST_CODE_STORAGE_PERMISSION); } }); snackbar.show(); } else { StatusMessageHandler.showErrorMessage(getContext(), booleanAsyncTaskResult.getException()); } } sendLogs.setEnabled(true); sendLogsProgress.setVisibility(View.GONE); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } }); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); updateUI(); } }; return rootView; }
From source file:com.teitsmch.hearthmaker.MainActivity.java
private void setSpinnerAdapter(Spinner currentSpinner, int arrayId) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayId, R.layout.spinner_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); currentSpinner.setAdapter(adapter);/*from w w w . j a va 2 s .c om*/ }
From source file:com.zira.registration.BackgroundCheckActivity.java
private void setAdapterForState() { statesArrayList = SingleTon.getInstance().getSelectedStates(); if (statesArrayList.size() > 0) { //gettingLicenceState=mProfileInfoModel.getDrivinglicensestate(); gettingState = mProfileInfoModel.getStateID(); int i = 0; for (State state : statesArrayList) { //String stateName=state.getStateName(); String stateName = state.getStateId(); //Log.e("stateID=", stateName); if (gettingState.equals(stateName)) { gettingStatePosition = i; }// ww w . jav a 2 s .c om i++; } } ArrayAdapter<State> dataAdapter = new ArrayAdapter<State>(this, R.layout.spinner_list, statesArrayList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stateSpinner.setAdapter(dataAdapter); stateSpinner.setSelection(gettingStatePosition); }
From source file:com.zira.registration.BackgroundCheckActivity.java
private void setAdapterForLicenceState() { statesArrayList = SingleTon.getInstance().getSelectedStates(); if (statesArrayList.size() > 0) { //gettingLicenceState=mProfileInfoModel.getDrivinglicensestate(); gettingLicenceState = mProfileInfoModel.getDrivinglicensestateID(); /*if(gettingLicenceState.equals("0")) {// w w w. j a va 2 s . c om //gettingLicenceState=prefs3.getString("DrivinglicensestateID", ""); //System.err.println("DrivinglicensestateID="+prefs3.getString("DrivinglicensestateID", "")); }*/ } int i = 0; for (State state : statesArrayList) { //String stateName=state.getStateName(); String stateName = state.getStateId(); //Log.e("stateID=", stateName); if (gettingLicenceState.equals(stateName)) { gettingLicenceStatePosition = i; } i++; } ArrayAdapter<State> dataAdapter = new ArrayAdapter<State>(this, R.layout.spinner_list, statesArrayList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); licenceStateSpinner.setAdapter(dataAdapter); licenceStateSpinner.setSelection(gettingLicenceStatePosition); }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateAmortizationSpinner(ResponseBody result) { final List<AmortizationType> amortizationType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> amortizationTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {//from w w w . j a v a 2 s . c om reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("amortizationTypeOptions")) { JSONArray amortizationTypes = obj.getJSONArray("amortizationTypeOptions"); for (int i = 0; i < amortizationTypes.length(); i++) { JSONObject amortizationTypeObject = amortizationTypes.getJSONObject(i); AmortizationType amortization = new AmortizationType(); amortization.setId(amortizationTypeObject.optInt("id")); amortization.setValue(amortizationTypeObject.optString("value")); amortizationType.add(amortization); amortizationTypeNames.add(amortizationTypeObject.optString("value")); amortizationTypeIdHashMap.put(amortization.getValue(), amortization.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> amortizationTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, amortizationTypeNames); amortizationTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_amortization.setAdapter(amortizationTypeAdapter); sp_amortization.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { amortizationTypeId = amortizationTypeIdHashMap.get(amortizationTypeNames.get(i)); Log.d("ammortization" + amortizationTypeNames.get(i), String.valueOf(amortizationTypeId)); if (amortizationTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateFrequencyPeriodSpinner(ResponseBody result) { final List<TermFrequencyTypeOptions> termFrequencyType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> termFrequencyTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {/*from w ww .ja v a2 s . c o m*/ reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("termFrequencyTypeOptions")) { JSONArray termFrequencyTypes = obj.getJSONArray("termFrequencyTypeOptions"); for (int i = 0; i < termFrequencyTypes.length(); i++) { JSONObject termFrequencyTypeObject = termFrequencyTypes.getJSONObject(i); TermFrequencyTypeOptions termFrequency = new TermFrequencyTypeOptions(); termFrequency.setId(termFrequencyTypeObject.optInt("id")); termFrequency.setValue(termFrequencyTypeObject.optString("value")); termFrequencyType.add(termFrequency); termFrequencyTypeNames.add(termFrequencyTypeObject.optString("value")); termFrequencyTypeIdHashMap.put(termFrequency.getValue(), termFrequency.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> termFrequencyTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, termFrequencyTypeNames); termFrequencyTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_payment_periods.setAdapter(termFrequencyTypeAdapter); sp_payment_periods.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanTermFrequency = termFrequencyTypeIdHashMap.get(termFrequencyTypeNames.get(i)); Log.d("termFrequencyTypeId" + termFrequencyTypeNames.get(i), String.valueOf(loanTermFrequency)); if (loanTermFrequency != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.duongnx.ndk.examples.activities.NativeAudioActivity.java
/** * Called when the activity is first created. */// w w w . ja v a2s . com @Override @TargetApi(17) protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_native_audio); setTitle(Defines.NATIVE_AUDIO); assetManager = getAssets(); // initialize native audio system createEngine(); int sampleRate = 0; int bufSize = 0; /* * retrieve fast audio path sample rate and buf size; if we have it, we pass to native * side to create a player with fast audio enabled [ fast audio == low latency audio ]; * IF we do not have a fast audio path, we pass 0 for sampleRate, which will force native * side to pick up the 8Khz sample rate. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); String nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); sampleRate = Integer.parseInt(nativeParam); nativeParam = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); bufSize = Integer.parseInt(nativeParam); } createBufferQueueAudioPlayer(sampleRate, bufSize); // initialize URI spinner Spinner uriSpinner = (Spinner) findViewById(R.id.uri_spinner); ArrayAdapter<CharSequence> uriAdapter = ArrayAdapter.createFromResource(this, R.array.uri_spinner_array, android.R.layout.simple_spinner_item); uriAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); uriSpinner.setAdapter(uriAdapter); uriSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { URI = parent.getItemAtPosition(pos).toString(); } public void onNothingSelected(AdapterView parent) { URI = null; } }); // initialize button click handlers ((Button) findViewById(R.id.hello)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_HELLO, 5); } }); ((Button) findViewById(R.id.android)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_ANDROID, 7); } }); ((Button) findViewById(R.id.sawtooth)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_SAWTOOTH, 1); } }); ((Button) findViewById(R.id.reverb)).setOnClickListener(new OnClickListener() { boolean enabled = false; public void onClick(View view) { enabled = !enabled; if (!enableReverb(enabled)) { enabled = !enabled; } } }); ((Button) findViewById(R.id.embedded_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created) { created = createAssetAudioPlayer(assetManager, "background.mp3"); } if (created) { isPlayingAsset = !isPlayingAsset; setPlayingAssetAudioPlayer(isPlayingAsset); } } }); // native uriPlayer is broken in android 21 and over, internal bug id: b/29321867 // will re-open after it is fixed in later OSes if (Build.VERSION.SDK_INT <= 19) { ((Button) findViewById(R.id.uri_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created && URI != null) { created = createUriAudioPlayer(URI); } } }); ((Button) findViewById(R.id.pause_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { setPlayingUriAudioPlayer(false); } }); ((Button) findViewById(R.id.play_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { setPlayingUriAudioPlayer(true); } }); ((Button) findViewById(R.id.loop_uri)).setOnClickListener(new OnClickListener() { boolean isLooping = false; public void onClick(View view) { isLooping = !isLooping; setLoopingUriAudioPlayer(isLooping); } }); ((Button) findViewById(R.id.mute_left_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setChannelMuteUriAudioPlayer(0, muted); } }); ((Button) findViewById(R.id.mute_right_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setChannelMuteUriAudioPlayer(1, muted); } }); ((Button) findViewById(R.id.solo_left_uri)).setOnClickListener(new OnClickListener() { boolean soloed = false; public void onClick(View view) { soloed = !soloed; setChannelSoloUriAudioPlayer(0, soloed); } }); ((Button) findViewById(R.id.solo_right_uri)).setOnClickListener(new OnClickListener() { boolean soloed = false; public void onClick(View view) { soloed = !soloed; setChannelSoloUriAudioPlayer(1, soloed); } }); ((Button) findViewById(R.id.mute_uri)).setOnClickListener(new OnClickListener() { boolean muted = false; public void onClick(View view) { muted = !muted; setMuteUriAudioPlayer(muted); } }); ((Button) findViewById(R.id.enable_stereo_position_uri)).setOnClickListener(new OnClickListener() { boolean enabled = false; public void onClick(View view) { enabled = !enabled; enableStereoPositionUriAudioPlayer(enabled); } }); ((Button) findViewById(R.id.channels_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { if (numChannelsUri == 0) { numChannelsUri = getNumChannelsUriAudioPlayer(); } Toast.makeText(NativeAudioActivity.this, "Channels: " + numChannelsUri, Toast.LENGTH_SHORT) .show(); } }); ((SeekBar) findViewById(R.id.volume_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int lastProgress = 100; public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) { throw new AssertionError(); } lastProgress = progress; } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { int attenuation = 100 - lastProgress; int millibel = attenuation * -50; setVolumeUriAudioPlayer(millibel); } }); ((SeekBar) findViewById(R.id.pan_uri)).setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int lastProgress = 100; public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (BuildConfig.DEBUG && !(progress >= 0 && progress <= 100)) { throw new AssertionError(); } lastProgress = progress; } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { int permille = (lastProgress - 50) * 20; setStereoPositionUriAudioPlayer(permille); } }); } else { int[] uriIds = { R.id.uri_soundtrack, R.id.pause_uri, R.id.play_uri, R.id.loop_uri, R.id.mute_left_uri, R.id.mute_right_uri, R.id.solo_left_uri, R.id.solo_right_uri, R.id.mute_uri, R.id.enable_stereo_position_uri, R.id.channels_uri, R.id.volume_uri, R.id.pan_uri, R.id.uri_spinner, }; for (int id : uriIds) findViewById(id).setVisibility(View.GONE); } ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() { public void onClick(View view) { int status = ActivityCompat.checkSelfPermission(NativeAudioActivity.this, Manifest.permission.RECORD_AUDIO); if (status != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(NativeAudioActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, AUDIO_ECHO_REQUEST); return; } recordAudio(); } }); ((Button) findViewById(R.id.playback)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // ignore the return value selectClip(CLIP_PLAYBACK, 3); } }); }
From source file:com.jlt.patadata.ChooseDatasetFragment.java
/** Other Methods */ // begin method initializeUI private void initializeUI(View rootView) { // 1. initialize UI // 1a. initialize the datasets spinner // 1a1. create an ArrayAdapter using the World Bank datasets and a default spinner layout // 1a2. specify the layout to use when the list of choices appears // 1a3. apply the adapter to the spinner // 1a4. set as selected the first item on the spinner // 1b. initialize the start year spinner // 1b1. create an ArrayAdapter using the start years and a default spinner layout // 1b2. specify the layout to use when the list of choices appears // 1b3. apply the adapter to the spinner // 1b4. set as selected the first item on the spinner // 1c. initialize the end year spinner // 1c1. create an ArrayAdapter using the end years and a default spinner layout // 1c2. specify the layout to use when the list of choices appears // 1c3. apply the adapter to the spinner // 1c4. set as selected the first item on the spinner // 1d. initialize the search fab // 1d1. when the fab is touched // 1d1a. validate the spinner choices and act accordingly // 1e. set the bar title to be the name of the app // 1a. initialize the datasets spinner datasetsSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_datasets); // 1a1. create an ArrayAdapter using the World Bank datasets and a default spinner layout ArrayAdapter<String> datasetsArrayAdapter = new ArrayAdapter<String>( getActivity(),/*w w w .j a va2s .c o m*/ android.R.layout.simple_spinner_item, WorldBankJSONUtils.RequestQueryBuilder.getDatasetValues()); // 1a2. specify the layout to use when the list of choices appears datasetsArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 1a3. apply the adapter to the spinner datasetsSpinner.setAdapter(datasetsArrayAdapter); // 1a4. set as selected the first item on the spinner datasetsSpinner.setSelection(0); // 1b. initialize the start year spinner startYearSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_start_year); // 1b1. create an ArrayAdapter using the start years and a default spinner layout ArrayAdapter<Integer> yearsArrayAdapter = new ArrayAdapter<Integer>( getActivity(), android.R.layout.simple_spinner_item, ArrayUtils.toObject(WorldBankJSONUtils.getDatasetYearsAsString())); // 1b2. specify the layout to use when the list of choices appears yearsArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 1b3. apply the adapter to the spinner startYearSpinner.setAdapter(yearsArrayAdapter); // 1b4. set as selected the first item on the spinner startYearSpinner.setSelection(0); // 1c. initialize the end year spinner endYearSpinner = (Spinner) rootView.findViewById(R.id.fcd_s_end_year); // 1c1. create an ArrayAdapter using the end years and a default spinner layout // 1c2. specify the layout to use when the list of choices appears // 1c3. apply the adapter to the spinner endYearSpinner.setAdapter(yearsArrayAdapter); // 1c4. set as selected the first item on the spinner endYearSpinner.setSelection(0); // 1d. initialize the search fab FloatingActionButton searchFloatingActionButton = (FloatingActionButton) rootView .findViewById(R.id.fcd_fab_search); // 1d1. when the fab is touched // begin searchFloatingActionButton.setOnClickListener searchFloatingActionButton.setOnClickListener( // begin new View.OnClickListener new View.OnClickListener() { @Override // begin onClick public void onClick(View view) { // 1d1a. validate the spinner choices and act accordingly validateChoicesAndAct(); } // end onClick } // end new View.OnClickListener ); // end searchFloatingActionButton.setOnClickListener // 1e. set the bar title to be the name of the app ((AppCompatActivity) (getActivity())).getSupportActionBar().setTitle(R.string.app_name); }