List of usage examples for android.widget ArrayAdapter createFromResource
public static @NonNull ArrayAdapter<CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int textViewResId)
From source file:me.diskstation.ammon.gpsrunner.ui.LineDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_line_details, container, false); lineChart = (LineChart) view.findViewById(R.id.runLineChart); setUpChart(lineChart);//from w ww.j ava2s .co m Spinner modeSpinner = (Spinner) view.findViewById(R.id.modeSpinner); //Adding modes via adapter ArrayAdapter<CharSequence> modeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.detail_modes_array, R.layout.spinner_item); modeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); modeSpinner.setAdapter(modeAdapter); modeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mode = position; setUpChart(lineChart); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); return view; }
From source file:com.teddoll.movies.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); final MenuItem sort = menu.findItem(R.id.menu_list_select); Spinner spinner = (Spinner) MenuItemCompat.getActionView(sort); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.sort_array, R.layout.item_action_bar_spinner); adapter.setDropDownViewResource(R.layout.item_action_bar_spinner_item); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from w w w . j a v a2 s.co m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { sort(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinner.setAdapter(adapter); spinner.setSelection(this.sort.ordinal()); return true; }
From source file:mp.paschalis.BookSearchActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); resultsShowing = false;// ww w . j a v a 2 s . c o m app = (App) getApplication(); setContentView(R.layout.activity_book_search); app.selectedBook = null; linearLayoutSearchLayout = (LinearLayout) findViewById(R.id.linearLayoutSearchLayout); editTextSearchKeyword = (EditText) findViewById(R.id.editTextSearchKeyword); spinnerColumnSelect = (Spinner) findViewById(R.id.spinnerSearchSelectColumn); buttonSearch = (Button) findViewById(R.id.buttonSearchBookSearch); progressBarSearchButton = (ProgressBar) findViewById(R.id.progressBarSearchSearchButton); listViewBookResults = (ListView) findViewById(R.id.listViewBookResults); textViewSearchResults = (TextView) findViewById(R.id.textViewSearchSearchResults); arrayListSearchResultBooks = new ArrayList<Book>(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Create adapter for the Spinner adapterSearchColumns = ArrayAdapter.createFromResource(this, R.array.ArraySearchColumns, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices appears adapterSearchColumns.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinnerColumnSelect.setAdapter(adapterSearchColumns); isItemChecked = false; editTextSearchKeyword.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { if (s.length() == 0) { buttonSearch.setEnabled(false); } else { buttonSearch.setEnabled(true); } } }); // When button is pressed buttonSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dataClassSearch = new DataClassSearch(); dataClassSearch.column = getResources().getStringArray( R.array.ArraySearchColumnValues)[spinnerColumnSelect.getSelectedItemPosition()]; dataClassSearch.keyword = editTextSearchKeyword.getText().toString(); // Re-init results arrayListSearchResultBooks = new ArrayList<Book>(); new AsyncTaskSearchBooks().execute(dataClassSearch); } }); listViewBookResults.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { app.selectedBook = (Book) (listViewBookResults.getItemAtPosition(pos)); listViewBookResults.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listViewBookResults.setItemChecked(pos, true); isItemChecked = true; // Recreate the menu invalidateOptionsMenu(); } }); listViewBookResults.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { app.selectedBook = (Book) (listViewBookResults.getItemAtPosition(pos)); // Open Book { // If user owns that book, open edit book if (app.selectedBook.status != App.BOOK_STATE_USER_DONT_OWNS) { // Workaround - Change the status of // book, to users // specific status for (Book.DataClassUser u : app.selectedBook.owners) { // Find real status for that book if (u.username.equalsIgnoreCase(app.user.username)) { app.selectedBook.status = u.status; break; } } Intent intent = new Intent(BookSearchActivity.this, EditBookActivity.class); intent.putExtra(App.ExtrasForEditBookActivityFromBookSearch, true); openedEditBook = true; startActivity(intent); } else { Boolean isAvail = false; // Find all users who lent this book for (Book.DataClassUser u : app.selectedBook.owners) { if (u.status == App.BOOK_STATE_USER_AVAILABLE) { isAvail = true; } } Intent intent = new Intent(BookSearchActivity.this, WatchBookActivity.class); intent.putExtra(App.ExtrasForWatchBookActivityFromBookSearch, isAvail); startActivity(intent); } } return true; } }); }
From source file:color.kidpaint.com.kidpaintcolor.dialog.TextToolDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); AlertDialog.Builder builder = new CustomAlertDialogBuilder(mContext); builder.setTitle(R.string.text_tool_dialog_title); final View view = inflater.inflate(R.layout.dialog_text_tool, null); mTextEditText = (EditText) view.findViewById(R.id.text_tool_dialog_input_text); mTextEditText.addTextChangedListener(new TextWatcher() { @Override//w ww. j a va 2 s .c o m 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) { String text = mTextEditText.getText().toString(); mOnTextToolDialogChangedListener.setText(text); mText = text; } }); mFontSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_font); ArrayAdapter<CharSequence> fontAdapter = ArrayAdapter.createFromResource(mContext, R.array.text_tool_font_array, android.R.layout.simple_spinner_item); fontAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mFontSpinner.setAdapter(fontAdapter); mFontSpinner.setBackgroundColor(Color.GRAY); mFontSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { String font = parent.getItemAtPosition(position).toString(); mOnTextToolDialogChangedListener.setFont(font); mFontIndex = position; if (mFontSpinnerInitialized) hideKeyboard(); else mFontSpinnerInitialized = true; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mUnderlinedToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_underlined); mUnderlinedToggleButton.setTextOn(Html .fromHtml("<u>" + getResources().getString(R.string.text_tool_dialog_underline_shortcut) + "</u>")); mUnderlinedToggleButton.setOnClickListener(new ToggleButton.OnClickListener() { @Override public void onClick(View v) { boolean underlined = mUnderlinedToggleButton.isChecked(); mOnTextToolDialogChangedListener.setUnderlined(underlined); mUnderlined = underlined; hideKeyboard(); } }); mItalicToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_italic); mItalicToggleButton.setTextOn(Html .fromHtml("<i>" + getResources().getString(R.string.text_tool_dialog_italic_shortcut) + "</i>")); mItalicToggleButton.setOnClickListener(new ToggleButton.OnClickListener() { @Override public void onClick(View v) { boolean italic = mItalicToggleButton.isChecked(); mOnTextToolDialogChangedListener.setItalic(italic); mItalic = italic; hideKeyboard(); } }); mBoldToggleButton = (ToggleButton) view.findViewById(R.id.text_tool_dialog_toggle_bold); mBoldToggleButton.setTextOn( Html.fromHtml("<b>" + getResources().getString(R.string.text_tool_dialog_bold_shortcut) + "</b>")); mBoldToggleButton.setOnClickListener(new ToggleButton.OnClickListener() { @Override public void onClick(View v) { boolean bold = mBoldToggleButton.isChecked(); mOnTextToolDialogChangedListener.setBold(bold); mBold = bold; hideKeyboard(); } }); mTextSizeSpinner = (Spinner) view.findViewById(R.id.text_tool_dialog_spinner_text_size); ArrayAdapter<CharSequence> textSizeAdapter = ArrayAdapter.createFromResource(mContext, R.array.text_tool_size_array, android.R.layout.simple_spinner_item); textSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mTextSizeSpinner.setAdapter(textSizeAdapter); mTextSizeSpinner.setBackgroundColor(Color.GRAY); mTextSizeSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { int size = Integer.parseInt(parent.getItemAtPosition(position).toString()); mOnTextToolDialogChangedListener.setTextSize(size); mTextSizeIndex = position; if (mTextSizeSpinnerInitialized) hideKeyboard(); else mTextSizeSpinnerInitialized = true; } @Override public void onNothingSelected(AdapterView<?> parent) { } }); builder.setView(view); builder.setNeutralButton(R.string.done, this); Dialog textDialog = builder.create(); WindowManager.LayoutParams window_params = textDialog.getWindow().getAttributes(); textDialog.getWindow().setDimAmount(0.0f); textDialog.getWindow().setAttributes(window_params); return textDialog; }
From source file:edu.wpi.khufnagle.lighthousenavigator.PhotographsActivity.java
/** * Display the UI defined in activity_photographs.xml upon activity start. *//* ww w .j av a2s . c om*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_photographs); /* * Add "up" button functionality in the left of application icon in * top-left corner, allowing user to return to "welcome" screen */ final ActionBar ab = this.getSupportActionBar(); ab.setDisplayHomeAsUpEnabled(true); ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); /* * Create "navigation spinner" in activity action bar that allows user to * view a different content screen */ final ArrayAdapter<CharSequence> navDropDownAdapter = ArrayAdapter.createFromResource(this, R.array.ab_content_activities_names, R.layout.ab_navigation_dropdown_item); ab.setListNavigationCallbacks(navDropDownAdapter, this); ab.setSelectedNavigationItem(ContentActivity.PHOTOGRAPHS.getABDropDownListIndex()); // Retrieve name of lighthouse that user is viewing final Bundle extras = this.getIntent().getExtras(); final String lighthouseNameSelected = extras.getString("lighthousename"); // Lighthouse data guaranteed to exist ("Welcome" activity performs data // existence validation) final LighthouseDataParser lighthouseInformationParser = new LighthouseDataParser( this.getApplicationContext(), lighthouseNameSelected); lighthouseInformationParser.parseLighthouseData(); this.currentLighthouse = lighthouseInformationParser.getLighthouse(); /* * Complete Flickr downloading task only if a network connection exists * _and_ the cache is empty or contains information about a lighthouse * other than the "desired" one */ this.userConnectedToInternet = this.networkConnectionExists(); FlickrDownloadHandler downloadHandler = null; if (this.userConnectedToInternet) { if (!this.photoCacheExists()) { if (!PhotographsActivity.downloadingThreadStarted) { Log.d("LIGHTNAVDEBUG", "Creating dialog..."); // Display dialog informing user about download progress final ProgressDialog flickrPhotoDownloadDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER); flickrPhotoDownloadDialog.setTitle("Downloading Flickr photos"); flickrPhotoDownloadDialog.setMessage("Downloading photographs from Flickr..."); flickrPhotoDownloadDialog.setCancelable(true); flickrPhotoDownloadDialog.show(); final HashSet<Photograph> flickrPhotos = new HashSet<Photograph>(); /* * Start background thread that will complete actual downloading * process */ PhotographsActivity.downloadingThreadStarted = true; downloadHandler = new FlickrDownloadHandler(this, this.currentLighthouse, flickrPhotos, flickrPhotoDownloadDialog); final FlickrPhotoDownloadThread downloadThread = new FlickrPhotoDownloadThread( this.getApplicationContext(), this.currentLighthouse, downloadHandler, PhotographsActivity.XML_DOWNLOAD_COMPLETE, PhotographsActivity.INTERRUPT); Log.d("LIGHTNAVDEBUG", "Flickr download XML thread started"); downloadThread.start(); /* * Interrupt (stop) currently-running thread if user cancels * downloading operation explicitly */ flickrPhotoDownloadDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface di) { if (downloadThread.isAlive()) { downloadThread.interrupt(); } else if (PhotographsActivity.this.parseOutputThread != null && PhotographsActivity.this.parseOutputThread.isAlive()) { PhotographsActivity.this.parseOutputThread.interrupt(); } else { // Do nothing } } }); } } else { final ArrayList<Photograph> lighthousePhotos = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); lighthousePhotos.clear(); final File downloadCacheDir = new File(this.getFilesDir() + "/download-cache/"); final File[] downloadCacheDirContents = downloadCacheDir.listFiles(); for (int i = 0; i < downloadCacheDirContents.length; i++) { final String downloadCacheDirContentName = downloadCacheDirContents[i].getName(); final String[] downloadCacheDirContentPieces = downloadCacheDirContentName.split("_"); final Long photoID = Long.parseLong(downloadCacheDirContentPieces[2]); final String ownerName = downloadCacheDirContentPieces[3].replace("~", " "); final String creativeCommonsLicenseIDString = downloadCacheDirContentPieces[4].substring(0, 1); final int creativeCommonsLicenseID = Integer.parseInt(creativeCommonsLicenseIDString); final CreativeCommonsLicenseType licenseType = CreativeCommonsLicenseType .convertToLicenseEnum(creativeCommonsLicenseID); lighthousePhotos.add(new Photograph(photoID, ownerName, licenseType, "/download-cache/" + downloadCacheDirContentName)); } this.currentLighthouse.getAlbum().put(ActivityVisible.PHOTOGRAPHS, lighthousePhotos); } } if (!this.userConnectedToInternet || this.userConnectedToInternet && this.photoCacheExists() || downloadHandler != null && downloadHandler.getFlickrOperationsComplete()) { // Display first photograph as "selected" photograph in top-left corner // by default final ArrayList<Photograph> photoSet = this.currentLighthouse.getAlbum() .get(ActivityVisible.PHOTOGRAPHS); final Photograph currentPhotoOnLeftSide = photoSet.get(0); final ImageView currentPhotoView = (ImageView) this.findViewById(R.id.iv_photographs_current_image); if (this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + currentPhotoOnLeftSide.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(currentPhotoOnLeftSide.getResID()); } // Add credits for "default" main photograph final TextView owner = (TextView) this.findViewById(R.id.tv_photographs_photographer); final TextView licenseType = (TextView) this.findViewById(R.id.tv_photographs_license); owner.setText("Uploaded by: " + currentPhotoOnLeftSide.getOwner()); licenseType.setText("License: " + currentPhotoOnLeftSide.getLicenseTypeAbbreviation()); /* * Display Google Map as a SupportMapFragment (instead of MapFragment * for compatibility with Android 2.x) */ /* * BIG thanks to http://www.truiton.com/2013/05/ * android-supportmapfragment-example/ for getting this part of the app * working */ final FragmentManager fm = this.getSupportFragmentManager(); final Fragment mapFragment = fm.findFragmentById(R.id.frag_photographs_map); final SupportMapFragment smf = (SupportMapFragment) mapFragment; smf.getMap(); final GoogleMap supportMap = smf.getMap(); /* * Center map at lighthouse location, at a zoom level of 12 with no * tilt, facing due north */ final LatLng lighthouseLocation = new LatLng(this.currentLighthouse.getCoordinates().getLatitude(), this.currentLighthouse.getCoordinates().getLongitude()); final float zoomLevel = 12.0f; final float tiltAngle = 0.0f; final float bearing = 0.0f; final CameraPosition cameraPos = new CameraPosition(lighthouseLocation, zoomLevel, tiltAngle, bearing); supportMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPos)); /* * Allows user to open a maps application (such as Google Maps) upon * selecting the map fragment */ /* * Courtesy of: * http://stackoverflow.com/questions/6205827/how-to-open-standard * -google-map-application-from-my-application */ supportMap.setOnMapClickListener(new OnMapClickListener() { @Override public void onMapClick(LatLng lighthouseCoordinates) { final String uri = String.format(Locale.US, "geo:%f,%f", lighthouseCoordinates.latitude, lighthouseCoordinates.longitude); final Intent googleMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); PhotographsActivity.this.startActivity(googleMapsIntent); } }); this.gv = (GridView) this.findViewById(R.id.gv_photographs_thumbnails); /* * Photographs in the "current lighthouse album" are from Flickr if the * album is empty or if the first (or _any_) of the elements in the * album do not have a "proper" static resource ID */ this.photosFromFlickr = this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).isEmpty() || this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS).iterator().next() .getResID() == 0; final LighthouseImageAdapter thumbnailAdapter = new LighthouseImageAdapter(this, this.currentLighthouse.getAlbum().get(ActivityVisible.PHOTOGRAPHS), this.photosFromFlickr); this.gv.setAdapter(thumbnailAdapter); this.gv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Determine which photograph from the list was selected... final Photograph photoClicked = (Photograph) thumbnailAdapter.getItem(position); final int photoClickedResID = photoClicked.getResID(); // ...and change the information in the top-left corner // accordingly if (PhotographsActivity.this.userConnectedToInternet) { currentPhotoView.setImageDrawable(Drawable.createFromPath( PhotographsActivity.this.getFilesDir() + photoClicked.getInternalStorageLoc())); } else { currentPhotoView.setImageResource(photoClickedResID); } owner.setText("Uploaded by: " + photoClicked.getOwner()); licenseType.setText("License: " + photoClicked.getLicenseTypeAbbreviation()); } }); } }
From source file:com.ubundude.timesheet.ReportFragment.java
@Override public void onStart() { super.onStart(); /** Get the shared preference for the first day of the week */ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); firstDay = prefs.getString(getActivity().getString(R.string.prefDOWKey), "SUNDAY"); firstDOW = getFirstDay(firstDay);/* ww w . jav a 2 s . co m*/ hoursTextView = (TextView) getView().findViewById(R.id.rHoursTV); rSpinner = (Spinner) getView().findViewById(R.id.rSpinner); ArrayAdapter<CharSequence> adapt = ArrayAdapter.createFromResource(getActivity(), R.array.reports, android.R.layout.simple_spinner_item); adapt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); rSpinner.setAdapter(adapt); rSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { switch (pos) { case 0: sendDate = formDate.format(c.getTime()); dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime()); dateEditText.setText(dateView); reportType = 0; getTimestamps(sendDate, reportType); break; case 1: dateView = formWIY.format(c.getTime()); sendDate = dateView; dateEditText.setText(dateView); reportType = 1; getTimestamps(sendDate, reportType); break; case 2: sendDate = formMonthNum.format(c.getTime()); monthHelp = Integer.parseInt(sendDate) - 1; sendDate = Integer.toString(monthHelp); Log.d("Spinner Switch", "Date is: " + sendDate); dateView = formMonth.format(c.getTime()); Log.d("Spinner Switch", "DateView is: " + dateView); dateEditText.setText(dateView); reportType = 2; getTimestamps(sendDate, reportType); break; } } public void onNothingSelected(AdapterView<?> parent) { } }); dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime()); sendDate = formDate.format(c.getTime()); gDate = sendDate; getTimestamps(sendDate, reportType); /** Instantiates the dateEditText, set's it's text to the dateView, and sets the onClickListener */ dateEditText = (EditText) getView().findViewById(R.id.rDateEditText); dateEditText.setText(dateView); dateEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /** Gets the date based on the report type selected */ switch (reportType) { case 0: Log.d("Initial Dates", "In the On Click Listener"); arrDate = gDate.split("/"); year = Integer.valueOf(arrDate[2]); month = Integer.valueOf(arrDate[0]) - 1; dayOfMonth = Integer.valueOf(arrDate[1]); new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show(); break; case 1: sendDate = dateEditText.getText().toString(); arrDate = gDate.split("/"); year = Integer.valueOf(arrDate[2]); month = Integer.valueOf(arrDate[0]) - 1; dayOfMonth = Integer.valueOf(arrDate[1]); new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show(); break; case 2: pickMonth(); break; } } }); /** * Initialize minus button * * This method calls the minus button handler and stores the date returned * and also gets new timestamps for the date returned. */ minusButton = (Button) getView().findViewById(R.id.rMinusButton); minusButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { sendDate = minusButtonHandler(); getTimestamps(sendDate, reportType); } catch (ParseException e) { e.printStackTrace(); } } }); /** * Initialize plus button * * This method calls the plus button handler and stores the date returned * and also gets new timestamps for the date returned. */ plusButton = (Button) getView().findViewById(R.id.rPlusButton); plusButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { sendDate = plusButtonHandler(); getTimestamps(sendDate, reportType); } catch (ParseException e) { e.printStackTrace(); } } }); }
From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java
/** * {@inheritDoc}//from w w w. j a va 2 s .c om */ @Override public void onCreate(Bundle icicle) { Log.i(tag, "onCreate(" + icicle + ")"); super.onCreate(icicle); mAccountManager = AccountManager.get(this); Log.i(tag, "loading data from Intent"); final Intent intent = getIntent(); mUsername = intent.getStringExtra(PARAM_USERNAME); mAuthtokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE); mRequestNewAccount = mUsername == null; mConfirmCredentials = intent.getBooleanExtra(PARAM_CONFIRMCREDENTIALS, false); Log.i(tag, "request new: " + mRequestNewAccount + " ,ConfirmCredentials: " + mConfirmCredentials); requestWindowFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.login_activity); getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert); Spinner spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.country_code_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(this); setSpinnerCountry(spinner); mMessage = (TextView) findViewById(R.id.message); mUsernameEdit = (EditText) findViewById(R.id.username_edit); mPasswordEdit = (EditText) findViewById(R.id.password_edit); mPhoneEdit = (EditText) findViewById(R.id.phone_edit); getPhoneNumber(getApplicationContext()); mUsernameEdit.setText(mUsername); mMessage.setText(getMessage()); }
From source file:com.friedran.appengine.dashboard.gui.DashboardLoadFragment.java
private Spinner setSpinnerWithItems(LinearLayout layout, int optionsListResourceID, int spinnerResourceID) { Spinner spinner = (Spinner) layout.findViewById(spinnerResourceID); // Set options list ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(mActivity, optionsListResourceID, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);//from w ww.jav a 2 s . c o m // Set listener spinner.setOnItemSelectedListener(this); return spinner; }
From source file:eu.power_switch.gui.fragment.alarm_clock.SleepAsAndroidFragment.java
@Override public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_sleep_as_android, container, false); setHasOptionsMenu(true);// w ww . java2 s. c o m final RecyclerViewFragment recyclerViewFragment = this; Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off); switchOnOff.setChecked(SmartphonePreferencesHandler.getSleepAsAndroidEnabled()); switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isPressed()) { SmartphonePreferencesHandler.setSleepAsAndroidEnabled(isChecked); } } }); layout_installed = (LinearLayout) rootView.findViewById(R.id.layout_installed); layout_not_installed = (LinearLayout) rootView.findViewById(R.id.layout_not_installed); IconicsImageView getFromPlayStore = (IconicsImageView) rootView.findViewById(R.id.get_from_play_store); getFromPlayStore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SleepAsAndroidHelper.openPlayStorePage(getActivity()); } }); spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.sleep_as_android_event_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerEventType.setAdapter(adapter); SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() { @Override public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) { updateUI(); } }; spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener); spinnerEventType.setOnTouchListener(spinnerInteractionListener); recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions); recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { actions.remove(position); DatabaseHandler.setAlarmActions(SLEEP_AS_ANDROID_ALARM_EVENT .getById(spinnerEventType.getSelectedItemPosition()), actions); StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.action_removed, Snackbar.LENGTH_LONG); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } recyclerViewAdapter.notifyDataSetChanged(); } }).setNeutralButton(android.R.string.cancel, null).show(); } }); recyclerViewActions.setAdapter(recyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddSleepAsAndroidAlarmEventActionDialog addAlarmEventActionDialog = AddSleepAsAndroidAlarmEventActionDialog .newInstance(spinnerEventType.getSelectedItemPosition()); addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0); addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) { updateUI(); } else { updateUI(); } } }; }