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:android.support.v7.widget.AppCompatSpinner.java
/** * Constructs a new spinner with the given context's theme, the supplied * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG} * or {@link #MODE_DROPDOWN}), and the context against which the popup * should be inflated.// ww w. j a v a 2 s.com * * @param context The context against which the view is inflated, which * provides access to the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the view. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default * values for the view. Can be 0 to not look for * defaults. * @param mode Constant describing how the user will select choices from * the spinner. * @param popupTheme The theme against which the dialog or dropdown popup * should be inflated. May be {@code null} to use the * view theme. If set, this will override any value * specified by * {@link R.styleable#Spinner_popupTheme}. * @see #MODE_DIALOG * @see #MODE_DROPDOWN */ public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) { super(context, attrs, defStyleAttr); TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr, 0); mDrawableManager = AppCompatDrawableManager.get(); mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager); if (popupTheme != null) { mPopupContext = new ContextThemeWrapper(context, popupTheme); } else { final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0); if (popupThemeResId != 0) { mPopupContext = new ContextThemeWrapper(context, popupThemeResId); } else { // If we're running on a < M device, we'll use the current context and still handle // any dropdown popup mPopupContext = !IS_AT_LEAST_M ? context : null; } } if (mPopupContext != null) { if (mode == MODE_THEME) { if (Build.VERSION.SDK_INT >= 11) { // If we're running on API v11+ we will try and read android:spinnerMode TypedArray aa = null; try { aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0); if (aa.hasValue(0)) { mode = aa.getInt(0, MODE_DIALOG); } } catch (Exception e) { Log.i(TAG, "Could not read android:spinnerMode", e); } finally { if (aa != null) { aa.recycle(); } } } else { // Else, we use a default mode of dropdown mode = MODE_DROPDOWN; } } if (mode == MODE_DROPDOWN) { final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr); final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs, R.styleable.Spinner, defStyleAttr, 0); mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth, LayoutParams.WRAP_CONTENT); popup.setBackgroundDrawable(pa.getDrawable(R.styleable.Spinner_android_popupBackground)); popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt)); pa.recycle(); mPopup = popup; mForwardingListener = new ForwardingListener(this) { @Override public ShowableListMenu getPopup() { return popup; } @Override public boolean onForwardingStarted() { if (!mPopup.isShowing()) { mPopup.show(); } return true; } }; } } final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries); if (entries != null) { final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, entries); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); setAdapter(adapter); } a.recycle(); mPopupSet = true; // Base constructors can call setAdapter before we initialize mPopup. // Finish setting things up if this happened. if (mTempAdapter != null) { setAdapter(mTempAdapter); mTempAdapter = null; } mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr); }
From source file:android.support.v7ox.widget.AppCompatSpinner.java
/** * Constructs a new spinner with the given context's theme, the supplied * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG} * or {@link #MODE_DROPDOWN}), and the context against which the popup * should be inflated.//from w w w . j ava2 s.c o m * * @param context The context against which the view is inflated, which * provides access to the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the view. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default * values for the view. Can be 0 to not look for * defaults. * @param mode Constant describing how the user will select choices from * the spinner. * @param popupTheme The theme against which the dialog or dropdown popup * should be inflated. May be {@code null} to use the * view theme. If set, this will override any value * specified by * {@link R.styleable#Spinner_popupTheme}. * @see #MODE_DIALOG * @see #MODE_DROPDOWN */ public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) { super(context, attrs, defStyleAttr); TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr, 0); mDrawableManager = AppCompatDrawableManager.get(); mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager); if (popupTheme != null) { mPopupContext = new ContextThemeWrapper(context, popupTheme); } else { final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0); if (popupThemeResId != 0) { mPopupContext = new ContextThemeWrapper(context, popupThemeResId); } else { // If we're running on a < M device, we'll use the current context and still handle // any dropdown popup mPopupContext = !IS_AT_LEAST_M ? context : null; } } if (mPopupContext != null) { if (mode == MODE_THEME) { if (Build.VERSION.SDK_INT >= 11) { // If we're running on API v11+ we will try and read android:spinnerMode TypedArray aa = null; try { aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0); if (aa.hasValue(0)) { mode = aa.getInt(0, MODE_DIALOG); } } catch (Exception e) { Log.i(TAG, "Could not read android:spinnerMode", e); } finally { if (aa != null) { aa.recycle(); } } } else { // Else, we use a default mode of dropdown mode = MODE_DROPDOWN; } } if (mode == MODE_DROPDOWN) { final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr); final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs, R.styleable.Spinner, defStyleAttr, 0); mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth, LayoutParams.WRAP_CONTENT); popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt)); pa.recycle(); mPopup = popup; mForwardingListener = new ListPopupWindow.ForwardingListener(this) { @Override public ListPopupWindow getPopup() { return popup; } @Override public boolean onForwardingStarted() { if (!mPopup.isShowing()) { mPopup.show(); } return true; } }; } } final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries); if (entries != null) { final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item, entries); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); setAdapter(adapter); } a.recycle(); mPopupSet = true; // Base constructors can call setAdapter before we initialize mPopup. // Finish setting things up if this happened. if (mTempAdapter != null) { setAdapter(mTempAdapter); mTempAdapter = null; } mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr); }
From source file:edu.asu.msse.sgowdru.moviemediaplayerrpc.SearchMovie.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_movie); //Collect the intent object with parameters sent from the caller intent = getIntent();/*from w w w. j a v a 2 s . c om*/ info = new TextView[5]; //In the info array of TextView type store id of each field info[0] = (TextView) findViewById(R.id.autoCompleteTextView); info[1] = (TextView) findViewById(R.id.editTitleSearch); info[2] = (TextView) findViewById(R.id.editGenreSearch); info[3] = (TextView) findViewById(R.id.editYearSearch); info[4] = (TextView) findViewById(R.id.editActorsSearch); //Ratings field is of type Spinner class with field values (PG, PG-13, R rated) dropdown = (Spinner) findViewById(R.id.spinnerSearch); adapter = ArrayAdapter.createFromResource(this, R.array.Ratings, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); dropdown.setAdapter(adapter); addButton = (Button) findViewById(R.id.addSearch); //Set the Video player ID, initially set the visibility to NONE playButton = (Button) findViewById(R.id.play); playButton.setVisibility(View.GONE); //There is no file available to play by default videoFile = null; context = getApplicationContext(); duration = Toast.LENGTH_SHORT; db = new MoviesDB(this); try { crsDB = db.openDB(); } catch (SQLException e) { e.printStackTrace(); } ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, gen); AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.editGenreSearch); textView.setAdapter(adapter); }
From source file:com.diedrico.diedricoapp.PicMenuActivity.java
License:asdf
private ImageButton.OnClickListener wrongButtonClickListener() { return new View.OnClickListener() { @Override//from w w w.j a va 2 s . com public void onClick(View view) { if (analyzerFinished) { //The analysis was wrong so we move to the menu to select manually the interesting points and lines Log.i("asdf", "asdffff"); confirmationLayout.removeAllViews(); layoutInflater.inflate(R.layout.pic_analyzer_menu, confirmationLayout); nPointsEditText = (EditText) findViewById(R.id.nPoints); //The editText where the user specify the number of points nLinesEditText = (EditText) findViewById(R.id.nLines); //The editText where the user specify the number of lines nPlanesEditText = (EditText) findViewById(R.id.nPlanes); //The editText where the user specify the number of planes //array of color String colors[] = { "Red", "Green", "Blue" }; //Set menuType to the view and then put an array menuType = (Spinner) confirmationLayout.findViewById(R.id.menu_tipo); ArrayAdapter<String> menuTipoArrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, colors); menuTipoArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // The drop down view menuType.setAdapter(menuTipoArrayAdapter); //Set menuNumber to the view and then put an array menuNumber = (Spinner) confirmationLayout.findViewById(R.id.menu_numero); ArrayAdapter<String> menuNumeroArrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, colors); menuNumeroArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); menuNumber.setAdapter(menuNumeroArrayAdapter); } else { Toast.makeText(context, "First you have to select the best picture and confirm", Toast.LENGTH_LONG).show(); } } }; }
From source file:com.example.nativeaudio.NativeAudio.java
/** Called when the activity is first created. */ @Override//from w ww .j a va 2s . co m @TargetApi(17) protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); Log.d(TAG, "onCreate ----------- "); assetManager = getAssets(); /* Ctrl+O ? Ctrl+I ? Ctrl+N /? Ctrl+Shift+N Ctrl+Shift+ALt+N ? Ctrl+Space ??? Ctrl+Shift+Space ? Ctrl+Shift+Enter (? ?; ) Ctrl+P ?? Alt+Enter ?/?/ Ctrl+J ?? ( for foreach Toast system.out.println) logm logr loge */ // 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); // buffer? PackageManager pm = getPackageManager(); boolean claimsFeature = pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY); // ?5 OUTPUT_SAMPLE_RATE = 48000 OUTPUT_FRAMES_PER_BUFFER = 192 FEATURE_AUDIO_LOW_LATENCY = false // MTK MT6735 OUTPUT_SAMPLE_RATE = 44100 OUTPUT_FRAMES_PER_BUFFER = 1024 FEATURE_AUDIO_LOW_LATENCY = false Log.d(TAG, "OUTPUT_SAMPLE_RATE = " + sampleRate + " OUTPUT_FRAMES_PER_BUFFER = " + bufSize + " FEATURE_AUDIO_LOW_LATENCY = " + claimsFeature); } // buffer queue AudioPlayer Demo createBufferQueueAudioPlayer(sampleRate, bufSize); // initialize URI spinner Spinner uriSpinner = (Spinner) findViewById(R.id.uri_spinner); ArrayAdapter<CharSequence> uriAdapter = ArrayAdapter.createFromResource(this, R.array.local_uri_spinner_array, /* 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(); /* ? ? <string-array name="uri_spinner_array"> <item>http://upload.wikimedia.org/wikipedia/commons/6/6d/Banana.ogg</item> <item>http://www.freesound.org/data/previews/18/18765_18799-lq.mp3</item> </string-array> */ } 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, 2); } }); ((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; } } }); // AssertManager APK?mp3 // ((Button) findViewById(R.id.embedded_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created) { created = createAssetAudioPlayer(assetManager, "withus.mp3"); } if (created) { // URI AudioPlayer Demo ? // URI AudioPlayer Demo ? ?play pause // Assert/fd AudioPlayer Demo ? isPlayingAsset = !isPlayingAsset; setPlayingAssetAudioPlayer(isPlayingAsset); } } }); ((Button) findViewById(R.id.uri_soundtrack)).setOnClickListener(new OnClickListener() { boolean created = false; public void onClick(View view) { if (!created && URI != null) { Log.d(TAG, " uri_soundtrack create URI Audio Player URI " + URI); //URI = "file:///mnt/sdcard/xxx.3gp" ; //URI = "file:///mnt/sdcard/Banana.ogg" ; created = createUriAudioPlayer(URI); } } }); ((Button) findViewById(R.id.pause_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { Log.d(TAG, " setPlayingUriAudioPlayer pause URI "); setPlayingUriAudioPlayer(false); } }); ((Button) findViewById(R.id.play_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { Log.d(TAG, " setPlayingUriAudioPlayer play URI "); 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); } }); /* * ???? ? Stereo Panning * https://developer.android.com/ndk/guides/audio/opensl-prog-notes.html#panning * * */ ((Button) findViewById(R.id.enable_stereo_position_uri)).setOnClickListener(new OnClickListener() { boolean enabled = false; public void onClick(View view) { enabled = !enabled; enableStereoPositionUriAudioPlayer(enabled); } }); // ?? ?AudioPlayer ??? ?SetPlayState??? ((Button) findViewById(R.id.channels_uri)).setOnClickListener(new OnClickListener() { public void onClick(View view) { if (numChannelsUri == 0) { numChannelsUri = getNumChannelsUriAudioPlayer(); } Toast.makeText(NativeAudio.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; // 100 * -50 ~ 0 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) { // ?? ? // ? ? ?<50 >50 ? int permille = (lastProgress - 50) * 20; setStereoPositionUriAudioPlayer(permille); } }); ((SeekBar) findViewById(R.id.playback_rate_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) { /* 0 ----- 50 ---- 100 -1000 --- 0 ---- 1000 */ int permille = lastProgress * (1000 - -1000) / 100 + (-1000); setPlaybackRateUriAudioPlayer(permille); } }); ((Button) findViewById(R.id.record)).setOnClickListener(new OnClickListener() { public void onClick(View view) { // int status = ActivityCompat.checkSelfPermission(NativeAudio.this, // Manifest.permission.RECORD_AUDIO); // if (status != PackageManager.PERMISSION_GRANTED) { // ActivityCompat.requestPermissions( // NativeAudio.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:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java
protected void createPrioritySpinnerAdapterForValues(List<String> texts, List<String> values) { final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getSherlockActivity(), android.R.layout.simple_spinner_item, android.R.id.text1, texts); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); prioritySpinner.setAdapter(adapter); prioritySpinner.setValues(values);/*from www . j a va2s. c om*/ prioritySpinner.setSelectionByValue(getCurrentValue(Tasks.PRIORITY, String.class), 0); }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override// ww w. ja v a 2 s . com public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beacon.expectedStability != null && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beacon.status = Beacon.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beacon.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }
From source file:dev.drsoran.moloko.fragments.AbstractTaskEditFragment.java
protected void createListSpinnerAdapterForValues(List<String> listIds, List<String> listNames) { final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getSherlockActivity(), android.R.layout.simple_spinner_item, android.R.id.text1, listNames); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); listsSpinner.setAdapter(adapter);//from w w w .j ava2s . com listsSpinner.setValues(listIds); listsSpinner.setSelectionByValue(getCurrentValue(Tasks.LIST_ID, String.class), 0); }
From source file:com.googlecode.CallerLookup.Main.java
@SuppressWarnings("unchecked") public void updateLookupEntries() { parseLookupEntries();/* w ww.java 2 s . c o m*/ ArrayAdapter<CharSequence> adapter = (ArrayAdapter<CharSequence>) mLookup.getAdapter(); if (adapter == null) { adapter = new ArrayAdapter<CharSequence>(getApplicationContext(), android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLookup.setAdapter(adapter); } else { adapter.clear(); } adapter.add("Custom"); for (String lookupEntryName : mLookupEntries.keySet()) { adapter.add(lookupEntryName); } for (String lookupEntryName : mUserLookupEntries.keySet()) { assert (!mLookupEntries.containsKey(lookupEntryName)); mLookupEntries.put(lookupEntryName, mUserLookupEntries.get(lookupEntryName)); adapter.add(lookupEntryName); } String name = mPrefs.getString(PREFS_LOOKUP, "Custom"); if ((name.length() > 0) && !name.equals("Custom")) { int count = mLookup.getCount(); for (int i = 1; i < count; i++) { if (mLookup.getItemAtPosition(i).toString().equals(name)) { mLookup.setSelection(i); break; } } } else { if (mLookup.getSelectedItemPosition() != 0) { mIgnoreItemSelection = true; mLookup.setSelection(0); } } }
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
private void handleGovernors() { String currentGovernor = ""; if (Helpers.doesFileExist(GOVERNOR)) currentGovernor = CPUHelper.readOneLineNotRoot(GOVERNOR); String currentGovernor2 = ""; if (Helpers.doesFileExist(GOVERNOR2)) currentGovernor2 = CPUHelper.readOneLineNotRoot(GOVERNOR2); else//from w ww. ja va2s . c o m currentGovernor2 = bootPrefs.getString("CORE1_GOVERNOR", "NaN"); String currentGovernor3 = ""; if (Helpers.doesFileExist(GOVERNOR3)) currentGovernor3 = CPUHelper.readOneLineNotRoot(GOVERNOR3); else currentGovernor3 = bootPrefs.getString("CORE2_GOVERNOR", "NaN"); String currentGovernor4 = ""; if (Helpers.doesFileExist(GOVERNOR4)) currentGovernor4 = CPUHelper.readOneLineNotRoot(GOVERNOR4); else currentGovernor4 = bootPrefs.getString("CORE3_GOVERNOR", "NaN"); /** CPU Governor for all cores */ String[] availableGovernorsGeneral = CPUHelper.readOneLineNotRoot(GOVERNORS_LIST).split(" "); ArrayAdapter<CharSequence> governorAdapterGeneral = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapterGeneral.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String availableGovernor : availableGovernorsGeneral) { governorAdapterGeneral.add(availableGovernor); } mGeneralGovernor.setAdapter(governorAdapterGeneral); mGeneralGovernor.setSelection(Arrays.asList(availableGovernorsGeneral).indexOf(currentGovernor)); mGeneralGovernor.setOnItemSelectedListener(new GeneralGovListener()); /** CPU Governor for core 0 */ String[] availableGovernors = CPUHelper.readOneLineNotRoot(GOVERNORS_LIST).split(" "); ArrayAdapter<CharSequence> governorAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String availableGovernor : availableGovernors) { governorAdapter.add(availableGovernor); } mGovernor.setAdapter(governorAdapter); mGovernor.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor)); mGovernor.setOnItemSelectedListener(new GovListener()); /** CPU Governor for core 1 */ ArrayAdapter<CharSequence> governorAdapter2 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors2 : availableGovernors) { governorAdapter2.add(anAvailableGovernors2); } mGovernor2.setAdapter(governorAdapter2); mGovernor2.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor2)); mGovernor2.setOnItemSelectedListener(new GovListener2()); /** CPU Governor for core 2 */ ArrayAdapter<CharSequence> governorAdapter3 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors3 : availableGovernors) { governorAdapter3.add(anAvailableGovernors3); } mGovernor3.setAdapter(governorAdapter3); mGovernor3.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor3)); mGovernor3.setOnItemSelectedListener(new GovListener3()); /** CPU Governor for core 3 */ ArrayAdapter<CharSequence> governorAdapter4 = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); governorAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String anAvailableGovernors4 : availableGovernors) { governorAdapter4.add(anAvailableGovernors4); } mGovernor4.setAdapter(governorAdapter4); mGovernor4.setSelection(Arrays.asList(availableGovernors).indexOf(currentGovernor4)); mGovernor4.setOnItemSelectedListener(new GovListener4()); /** CPU Boost */ if (Helpers.doesFileExist(KRAIT_BOOST)) { Switch cpuBoostSwitch = (Switch) findViewById(R.id.krait_boost_switch); String cpuBoostState = CPUHelper.readOneLineNotRoot(KRAIT_BOOST); if (cpuBoostState.equals("Y")) cpuBoostSwitch.setChecked(true); else cpuBoostSwitch.setChecked(false); cpuBoostSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo Y > " + KRAIT_BOOST); else Helpers.CMDProcessorWrapper.runSuCommand("busybox echo N > " + KRAIT_BOOST); } }); } else { findViewById(R.id.card_krait_boost).setVisibility(View.GONE); } /** CPU Informations */ String pvs = "NaN"; String table = "NaN"; TextView pvsBinning = (TextView) findViewById(R.id.pvs_bin); TextView pvsSpeed = (TextView) findViewById(R.id.pvs_speed); if (Helpers.doesFileExist(PVS_BINNING)) { String rawTableName = CPUHelper.readOneLineNotRoot(PVS_BINNING); rawTableName = rawTableName.replaceAll("[\\D]", ""); table = rawTableName; String[] params = rawTableName.split(""); if (rawTableName.length() == 3) pvs = params[2]; } pvsBinning.setText(getString(R.string.pvs_binning) + " " + pvs); pvsSpeed.setText(getString(R.string.freq_table) + " " + table); }