List of usage examples for android.widget AdapterView.OnItemSelectedListener AdapterView.OnItemSelectedListener
AdapterView.OnItemSelectedListener
From source file:cm.aptoide.pt.ApkInfo.java
/** * *///from ww w . ja v a 2s. co m private void loadApkVersions() { if (category.equals(Category.INFOXML)) { spinner = (Spinner) findViewById(R.id.spinnerMultiVersion); adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, null, new String[] { "vername", "repo_id" }, new int[] { android.R.id.text1 }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View textView, Cursor cursor, int position) { ((android.widget.TextView) textView) .setText(getString(R.string.version) + " " + cursor.getString(position) + " - " + RepoUtils.split(db.getServer(cursor.getLong(3), false).url)); return true; } }); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (spinnerInstanciated) { if (!download.isNull()) { try { serviceDownloadManager.callUnregisterDownloadObserver(viewApk.hashCode()); } catch (RemoteException e) { e.printStackTrace(); } } loadElements(arg3); } else { spinnerInstanciated = true; } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); getSupportLoaderManager().initLoader(0, null, ApkInfo.this); } }
From source file:com.facebook.samples.booleanog.LogicActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); setContentView(R.layout.main);/*from ww w .jav a 2 s . c om*/ // Views logicButton = (Button) findViewById(R.id.logic_button); friendsButton = (Button) findViewById(R.id.friends_button); settingsButton = (Button) findViewById(R.id.settings_button); contentButton = (Button) findViewById(R.id.content_button); logicGroup = (ViewGroup) findViewById(R.id.logic_group); leftSpinner = (Spinner) findViewById(R.id.left_spinner); rightSpinner = (Spinner) findViewById(R.id.right_spinner); andButton = (Button) findViewById(R.id.and_button); orButton = (Button) findViewById(R.id.or_button); resultText = (TextView) findViewById(R.id.result_text); postResultText = (TextView) findViewById(R.id.post_result_text); friendsGroup = (ViewGroup) findViewById(R.id.friends_group); ListView friendActivityList = (ListView) findViewById(R.id.friend_activity_list); String[] mapColumnNames = { "date", "action" }; int[] mapViewIds = { R.id.friend_action_date, R.id.friend_action_data }; friendActivityAdapter = new SimpleCursorAdapter(this, R.layout.friend_activity_row, createEmptyCursor(), mapColumnNames, mapViewIds); friendActivityList.setAdapter(friendActivityAdapter); friendActivityProgressBar = (ProgressBar) findViewById(R.id.friend_activity_progress_bar); settingsGroup = (ViewGroup) findViewById(R.id.settings_group); contentGroup = (ViewGroup) findViewById(R.id.content_group); contentImage = (ImageView) findViewById(R.id.content_image); contentSpinner = (Spinner) findViewById(R.id.content_spinner); // Fragments FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); friendPickerFragment = (FriendPickerFragment) fragmentManager.findFragmentById(R.id.friend_picker_fragment); if (friendPickerFragment == null) { Bundle args = new Bundle(); args.putBoolean(FriendPickerFragment.SHOW_TITLE_BAR_BUNDLE_KEY, false); friendPickerFragment = new FriendPickerFragment(args); transaction.add(R.id.friend_picker_fragment, friendPickerFragment); } userSettingsFragment = (UserSettingsFragment) fragmentManager.findFragmentById(R.id.login_fragment); if (userSettingsFragment == null) { userSettingsFragment = new UserSettingsFragment(); transaction.add(R.id.login_fragment, userSettingsFragment); } transaction.commit(); // Spinners ArrayAdapter<CharSequence> truthAdapter = ArrayAdapter.createFromResource(this, R.array.truth_values, android.R.layout.simple_spinner_item); truthAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); leftSpinner.setAdapter(truthAdapter); rightSpinner.setAdapter(truthAdapter); contentSpinner.setAdapter(truthAdapter); leftSpinner.setSelection(0); rightSpinner.setSelection(0); // Navigation for (Button button : Arrays.asList(logicButton, friendsButton, settingsButton, contentButton)) { initializeNavigationButton(button); } // Logic initializeCalculationButton(andButton); initializeCalculationButton(orButton); // Friends friendPickerFragment.setOnErrorListener(new PickerFragment.OnErrorListener() { @Override public void onError(PickerFragment<?> fragment, FacebookException error) { LogicActivity.this.onError(error); } }); friendPickerFragment.setUserId("me"); friendPickerFragment.setMultiSelect(false); friendPickerFragment.setOnSelectionChangedListener(new PickerFragment.OnSelectionChangedListener() { @Override public void onSelectionChanged(PickerFragment<?> fragment) { LogicActivity.this.onFriendSelectionChanged(); } }); friendPickerFragment.setExtraFields(Arrays.asList(INSTALLED)); friendPickerFragment.setFilter(new PickerFragment.GraphObjectFilter<GraphUser>() { @Override public boolean includeItem(GraphUser graphObject) { Boolean installed = graphObject.cast(GraphUserWithInstalled.class).getInstalled(); return (installed != null) && installed.booleanValue(); } }); // Content contentSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { LogicActivity.this.onContentSelectionChanged(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { LogicActivity.this.onContentSelectionChanged(); } }); // Restore saved state Button startButton = logicButton; if (savedInstanceState != null) { leftSpinner.setSelection(savedInstanceState.getInt(SAVE_LEFT_OPERAND_SELECTION)); rightSpinner.setSelection(savedInstanceState.getInt(SAVE_RIGHT_OPERAND_SELECTION)); contentSpinner.setSelection(savedInstanceState.getInt(SAVE_CONTENT_SELECTION)); resultText.setText(savedInstanceState.getString(SAVE_RESULT_TEXT)); postResultText.setText(savedInstanceState.getString(SAVE_POST_RESULT_TEXT)); activeTab = savedInstanceState.getString(SAVE_ACTIVE_TAB); pendingPost = savedInstanceState.getBundle(SAVE_PENDING); friendActionList = savedInstanceState.getParcelableArrayList(SAVE_FRIEND_ACTIONS); if ((friendActionList != null) && (friendActionList.size() > 0)) { updateCursor(friendActionList); } if (getString(R.string.navigate_friends).equals(activeTab)) { startButton = friendsButton; } else if (getString(R.string.navigate_content).equals(activeTab)) { startButton = contentButton; } else if (getString(R.string.navigate_settings).equals(activeTab)) { startButton = settingsButton; } } if (!handleNativeLink()) { onNavigateButtonClick(startButton); } }
From source file:com.digi.android.wva.fragments.EndpointOptionsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (mConfig == null && savedInstanceState == null) { Log.e(TAG, "mConfig is null, not showing dialog!"); return null; }/*from ww w . j a va2 s . c o m*/ LayoutInflater inf = getActivity().getLayoutInflater(); View v = inf.inflate(R.layout.dialog_endpoint_options, null); // Suppresses warnings, and ensures the layout exists. assert v != null; final TextView subIntervalTV = (TextView) v.findViewById(R.id.textView_interval); final TextView alarmInfoTV = (TextView) v.findViewById(R.id.alarm_info); final CheckBox subscribedCB = (CheckBox) v.findViewById(R.id.subscribedCheckbox); final CheckBox alarmCB = (CheckBox) v.findViewById(R.id.alarmCheckbox); final EditText subInterval = (EditText) v.findViewById(R.id.subscriptionInterval); final EditText alarmThreshold = (EditText) v.findViewById(R.id.alarmThreshold); final Spinner typeSpinner = (Spinner) v.findViewById(R.id.alarmTypeSpinner); final LinearLayout makeAlarmSection = (LinearLayout) v.findViewById(R.id.section_make_alarm); final LinearLayout showAlarmSection = (LinearLayout) v.findViewById(R.id.section_show_alarm); final CheckBox dcSendCB = (CheckBox) v.findViewById(R.id.dcPushCheckbox); String alarmInfo = "No alarm yet"; boolean isSubscribed = false; String endpointName = "UNKNOWN"; int sinterval = 10; boolean alarmCreated = false; double threshold = 0; int alarmtypeidx = 0; boolean isSendingToDC = false; if (savedInstanceState != null && savedInstanceState.containsKey("config")) { mConfig = savedInstanceState.getParcelable("config"); } if (mConfig != null) { endpointName = mConfig.getEndpoint(); alarmInfo = mConfig.getAlarmSummary(); if (mConfig.getSubscriptionConfig() != null) { isSubscribed = mConfig.getSubscriptionConfig().isSubscribed(); sinterval = mConfig.getSubscriptionConfig().getInterval(); isSendingToDC = mConfig.shouldBePushedToDeviceCloud(); } else { // Not subscribed; default interval value from preferences. String i = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("pref_default_interval", "0"); try { sinterval = Integer.parseInt(i); } catch (NumberFormatException e) { Log.d(TAG, "Failed to parse default interval from preferences: " + i); sinterval = 0; } } if (mConfig.getAlarmConfig() != null) { alarmCreated = mConfig.getAlarmConfig().isCreated(); threshold = mConfig.getAlarmConfig().getThreshold(); String typestr = AlarmType.makeString(mConfig.getAlarmConfig().getType()); for (int i = 0; i < alarmTypes.length; i++) { if (alarmTypes[i].toLowerCase(Locale.US).equals(typestr)) alarmtypeidx = i; } } } // Set up event listeners on EditText and CheckBox items subscribedCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { subInterval.setEnabled(isChecked); subIntervalTV.setEnabled(isChecked); } }); alarmCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { typeSpinner.setEnabled(isChecked); alarmThreshold.setEnabled(false); // If type spinner is set to Change, we want threshold disabled again if (isChecked) { alarmThreshold.setEnabled(!shouldDisableAlarmThreshold(typeSpinner.getSelectedItemPosition())); } } }); typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { if (alarmCB.isChecked() && shouldDisableAlarmThreshold(position)) alarmThreshold.setEnabled(false); else if (!alarmCB.isChecked()) alarmThreshold.setEnabled(false); else alarmThreshold.setEnabled(true); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); subIntervalTV.setEnabled(false); subInterval.setEnabled(false); alarmThreshold.setEnabled(false); typeSpinner.setEnabled(false); alarmInfoTV.setText(alarmInfo); // Click checkboxes, show data depending on if subscription or alarm // has been added already if (isSubscribed) subscribedCB.performClick(); if (alarmCreated) { showAlarmSection.setVisibility(View.VISIBLE); makeAlarmSection.setVisibility(View.GONE); alarmCB.setText("Remove alarm"); } else { makeAlarmSection.setVisibility(View.VISIBLE); showAlarmSection.setVisibility(View.GONE); alarmCB.setText("Create alarm"); } dcSendCB.setChecked(isSendingToDC); subInterval.setText(Integer.toString(sinterval)); alarmThreshold.setText(Double.toString(threshold)); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_types, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeSpinner.setAdapter(adapter); typeSpinner.setSelection(alarmtypeidx); DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { // Fetch the EndpointsAdapter's configuration for this endpoint. // (We might have gotten mConfig from the saved instance bundle) EndpointConfiguration cfg = EndpointsAdapter.getInstance() .findEndpointConfiguration(mConfig.getEndpoint()); // Set whether this endpoint's data should be pushed to Device Cloud if (cfg != null) { cfg.setPushToDeviceCloud(dcSendCB.isChecked()); } // Handle (un)subscribing if (isUnsubscribing(subscribedCB.isChecked())) { unsubscribe(mConfig.getEndpoint()); } else if (subscribedCB.isChecked()) { if (handleMakingSubscription(subInterval)) { // Subscription was successful... most likely. Log.d(TAG, "Probably subscribed to endpoint."); } else { // Invalid interval. Toast.makeText(getActivity(), getString(R.string.configure_endpoints_toast_invalid_sub_interval), Toast.LENGTH_SHORT).show(); } } // Handle adding/removing alarm as necessary if (isRemovingAlarm(alarmCB.isChecked())) { removeAlarm(mConfig.getEndpoint(), mConfig.getAlarmConfig().getType()); } else if (alarmCB.isChecked()) { Editable thresholdText = alarmThreshold.getText(); String thresholdString; if (thresholdText == null) thresholdString = ""; else thresholdString = thresholdText.toString(); double threshold; try { threshold = Double.parseDouble(thresholdString); } catch (NumberFormatException e) { Toast.makeText(getActivity(), getString(R.string.configure_endpoints_invalid_threshold), Toast.LENGTH_SHORT).show(); return; } int alarmidx = typeSpinner.getSelectedItemPosition(); if (alarmidx == -1) { // But... how? Log.wtf(TAG, "alarm type index -1 ?"); return; } String type = alarmTypes[alarmidx]; AlarmType atype = AlarmType.fromString(type); createAlarm(mConfig.getEndpoint(), atype, threshold); } dialog.dismiss(); } }; return new AlertDialog.Builder(getActivity()).setView(v).setTitle("Endpoint: " + endpointName) .setPositiveButton("Save", clickListener) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Cancel means just dismiss the dialog. dialog.dismiss(); } }).create(); }
From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java
public void refreshSpinnerFrequencies() { frequencies = new ArrayList<>(); frequencies.add(new FrequencyData("Day", FrequencyData.DELAY_DAY)); frequencies.add(new FrequencyData("Week", FrequencyData.DELAY_WEEK)); frequencies.add(new FrequencyData("Month", FrequencyData.DELAY_MONTH)); frequencies.add(new FrequencyData("Year", FrequencyData.DELAY_YEAR)); frequencies.add(new FrequencyData("Everything", FrequencyData.DELAY_EVERYTHING)); spinnerFrequency.setAdapter(new SpinnerFrequencyAdapter(mActivity, frequencies)); spinnerFrequency.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from w w w. j a v a 2s . c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { refreshSpinnerPrecision(); refreshSpinnerDate(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.juick.android.MessagesFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); viewLoading = li.inflate(R.layout.listitem_loading, null); if (!messagesSource.canNext()) { viewLoading.findViewById(R.id.loadingg).setVisibility(View.GONE); viewLoading.findViewById(R.id.end_of_messages).setVisibility(View.VISIBLE); viewLoading.findViewById(R.id.progress_bar).setVisibility(View.GONE); viewLoading.findViewById(R.id.progress_loading_more).setVisibility(View.GONE); }/*from w ww . ja v a 2 s.c om*/ mRefreshView = (RelativeLayout) li.inflate(R.layout.pull_to_refresh_header, null); mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text); mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image); mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress); mRefreshViewImage.setMinimumHeight(50); mRefreshView.setOnClickListener(this); mRefreshOriginalTopPadding = mRefreshView.getPaddingTop(); mRefreshState = TAP_TO_REFRESH; final ListView listView = getListView(); listView.setBackgroundDrawable(null); listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); installDividerColor(listView); MainActivity.restyleChildrenOrWidget(listView); listAdapter = new JuickMessagesAdapter(getActivity(), this, JuickMessagesAdapter.TYPE_MESSAGES, allMessages ? JuickMessagesAdapter.SUBTYPE_ALL : JuickMessagesAdapter.SUBTYPE_OTHER); listAdapter.setOnForgetListener(new Utils.Function<Void, JuickMessage>() { @Override public Void apply(final JuickMessage jm) { Network.executeJAHTTPS( getActivity(), null, JA_API_URL + "/pending?command=ignore&mid=" + ((JuickMessageID) jm.getMID()).getMid() + "&rid=" + jm.getRID(), new Utils.Function<Void, RESTResponse>() { @Override public Void apply(final RESTResponse response) { final Activity activity = getActivity(); if (activity == null) return null; // gone. if (response.getErrorText() != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(activity, response.getErrorText(), Toast.LENGTH_SHORT) .show(); } }); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { listAdapter.remove(jm); //To change body of implemented methods use File | Settings | File Templates. if (listAdapter.getCount() == 0) { if ((activity instanceof MainActivity)) { ((MainActivity) activity).doReload(); } } } }); } return null; } }); return null; } }); listView.setOnTouchListener(this); listView.setOnScrollListener(this); listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { if (view instanceof ImageGallery) { return false; // no need that! (possibly, make this condition work only if not scrolled meanwhile) } final Object itemAtPosition = parent.getItemAtPosition(position); if (itemAtPosition instanceof JuickMessage) { doOnClickActualTime = System.currentTimeMillis(); doOnClick = new Runnable() { @Override public void run() { JuickMessage msg = (JuickMessage) itemAtPosition; MessageMenu messageMenu = MainActivity.getMicroBlog(msg).getMessageMenu(getActivity(), messagesSource, listView, listAdapter); if (messageMenu != null) { messageMenu.onItemLongClick(parent, view, position, id); } else { Toast.makeText(getActivity(), "Not implemented ;-(", Toast.LENGTH_LONG).show(); } } }; if (alternativeLongClick) { listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } else { doOnClick.run(); doOnClick = null; return true; } } return false; } }); listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { System.out.println(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { System.out.println(); } }); init(false); if (parent != null) { parent.onFragmentCreated(); } }
From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java
public void refreshSpinnerPrecision() { int precision = frequencies.get(spinnerFrequency.getSelectedItemPosition()).getDelay(); ArrayList<FrequencyData> precisionData = new ArrayList<>(); switch (precision) { case FrequencyData.DELAY_DAY: precisionData.add(new FrequencyData("Minute", FrequencyData.DELAY_MINUTE)); precisionData.add(new FrequencyData("5 minutes", FrequencyData.DELAY_FIVE_MINUTES)); precisionData.add(new FrequencyData("15 minutes", FrequencyData.DELAY_15MIN)); precisionData.add(new FrequencyData("Hour", FrequencyData.DELAY_HOUR)); break;/*w ww .j a v a 2 s. co m*/ case FrequencyData.DELAY_WEEK: precisionData.add(new FrequencyData("15 minutes", FrequencyData.DELAY_15MIN)); precisionData.add(new FrequencyData("Hour", FrequencyData.DELAY_HOUR)); precisionData.add(new FrequencyData("Day", FrequencyData.DELAY_DAY)); break; case FrequencyData.DELAY_MONTH: precisionData.add(new FrequencyData("Hour", FrequencyData.DELAY_HOUR)); precisionData.add(new FrequencyData("Day", FrequencyData.DELAY_DAY)); break; case FrequencyData.DELAY_YEAR: precisionData.add(new FrequencyData("Day", FrequencyData.DELAY_DAY)); precisionData.add(new FrequencyData("Week", FrequencyData.DELAY_WEEK)); precisionData.add(new FrequencyData("Month", FrequencyData.DELAY_MONTH)); break; case FrequencyData.DELAY_EVERYTHING: precisionData.add(new FrequencyData("Minute", FrequencyData.DELAY_MINUTE)); precisionData.add(new FrequencyData("5 minutes", FrequencyData.DELAY_FIVE_MINUTES)); precisionData.add(new FrequencyData("15 minutes", FrequencyData.DELAY_15MIN)); precisionData.add(new FrequencyData("Hour", FrequencyData.DELAY_HOUR)); precisionData.add(new FrequencyData("Day", FrequencyData.DELAY_DAY)); precisionData.add(new FrequencyData("Week", FrequencyData.DELAY_WEEK)); precisionData.add(new FrequencyData("Month", FrequencyData.DELAY_MONTH)); precisionData.add(new FrequencyData("Year", FrequencyData.DELAY_YEAR)); break; default: precisionData.add(new FrequencyData("Minute", FrequencyData.DELAY_MINUTE)); break; } spinnerPrecision.setOnItemSelectedListener(null); spinnerPrecision.setAdapter(new SpinnerFrequencyAdapter(mActivity, precisionData)); if (precision == FrequencyData.DELAY_EVERYTHING) { spinnerPrecision.setSelection(precisionData.size() - 2); } spinnerPrecision.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (spinnerDate.getCount() == 0) { return; } FrequencyData f = frequencies.get(spinnerFrequency.getSelectedItemPosition()); FrequencyData precision = (FrequencyData) spinnerPrecision.getSelectedItem(); if (precision != null) EventBus.getDefault() .post(new DateChangedEvent(((SpinnerDateData) spinnerDate.getSelectedItem()).getDate(), f.getDelay(), precision.getDelay())); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:nf.frex.android.FrexActivity.java
private void prepareColorsDialog(final Dialog dialog) { //Log.d(TAG, "prepareColorsDialog() entered"); getColorSchemes();/*from w ww. java2s. co m*/ //Log.d(TAG, "prepareColorsDialog: new bitmaps are being created"); Bitmap[] colorSchemeIcons = new Bitmap[colorSchemes.getSize()]; for (int i = 0; i < colorSchemeIcons.length; i++) { ColorScheme colorScheme = colorSchemes.getValue(i); colorSchemeIcons[i] = colorScheme.getGradientIcon(); } int checkedIndex = Registries.colorSchemes.getIndex(view.getColorSchemeId()); //Log.d(TAG, "prepareColorsDialog: checkedIndex = " + checkedIndex); final Spinner colorTableSpinner = (Spinner) dialog.findViewById(R.id.color_table_spinner); colorTableSpinner.setAdapter(new ImageArrayAdapter(this, 0, colorSchemeIcons)); colorTableSpinner.setSelection(checkedIndex, false); colorTableSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { view.setColorSchemeId(Registries.colorSchemes.getId(position)); view.setColorScheme(Registries.colorSchemes.getValue(position)); view.recomputeColors(); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final SeekBar colorFactorSeekBar = (SeekBar) dialog.findViewById(R.id.color_gain_seek_bar); final double colorFactorMin = -3.0; final double colorFactorMax = 2.0; final SeekBarConfigurer colorFactorSeekBarConfigurer = SeekBarConfigurer.create(colorFactorSeekBar, colorFactorMin, colorFactorMax, true, view.getColorGain()); colorFactorSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { view.setColorGain((float) colorFactorSeekBarConfigurer.getValue()); view.recomputeColors(); } }); final SeekBar colorBiasSeekBar = (SeekBar) dialog.findViewById(R.id.color_offset_seek_bar); final double colorBiasMin = 0; final double colorBiasMax = 1024; final SeekBarConfigurer colorBiasSeekBarConfigurer = SeekBarConfigurer.create(colorBiasSeekBar, colorBiasMin, colorBiasMax, false, view.getColorOffset()); colorBiasSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { view.setColorOffset((float) colorBiasSeekBarConfigurer.getValue()); view.recomputeColors(); } }); final CheckBox colorRepeatCheckBox = (CheckBox) dialog.findViewById(R.id.color_repeat); colorRepeatCheckBox.setChecked(view.isColorRepeat()); colorRepeatCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { view.setColorRepeat(isChecked); view.recomputeColors(); } }); Button randomButton = (Button) dialog.findViewById(R.id.random_button); randomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { colorTableSpinner.setSelection((int) (Math.random() * colorSchemes.getSize())); colorFactorSeekBarConfigurer.setRandomValue(); colorBiasSeekBarConfigurer.setRandomValue(); view.recomputeColors(); } }); Button getPalFromImgButton = (Button) dialog.findViewById(R.id.get_pal_from_img_button); getPalFromImgButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); dialog.dismiss(); startActivityForResult(photoPickerIntent, SELECT_PICTURE_REQUEST_CODE); } }); //Log.d(TAG, "prepareColorsDialog() exited"); }
From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java
public void refreshSpinnerDate() { if (SingleInstance.getUserController().getUser() != null && SingleInstance.getUserController().getUser().getSensors().size() == 0) { mLinearLayout.setVisibility(View.GONE); return;// w ww . j a va 2 s . c om } long start = Long.MAX_VALUE; long end = 0; for (SensorData sensor : SingleInstance.getUserController().getUser().getSensors()) { if (start > sensor.getFirstLocalValue().getTime()) { start = sensor.getFirstLocalValue().getTime(); } if (end < sensor.getLastLocalValue().getTime()) { end = sensor.getLastLocalValue().getTime(); } start = start - start % 86400000L; end = end - end % 86400000L; } final List<SpinnerDateData> dates = new ArrayList<>(); int precision = frequencies.get(spinnerFrequency.getSelectedItemPosition()).getDelay(); SimpleDateFormat formatter = null; if (precision == FrequencyData.DELAY_EVERYTHING) { dates.add(new SpinnerDateData(new Date(0), "Everything")); } else if (precision == FrequencyData.DELAY_MONTH) { formatter = new SimpleDateFormat("MMMM yyyy"); Calendar next = new GregorianCalendar(); next.setTimeInMillis(start); next.set(Calendar.DAY_OF_MONTH, 1); start = next.getTimeInMillis(); } else if (precision == FrequencyData.DELAY_YEAR) { formatter = new SimpleDateFormat("yyyy"); Calendar next = new GregorianCalendar(); next.setTimeInMillis(start); next.set(Calendar.DAY_OF_MONTH, 1); next.set(Calendar.MONTH, Calendar.JANUARY); start = next.getTimeInMillis(); } else { formatter = new SimpleDateFormat("dd MMMM yyyy"); } if (start == 0) { mLinearLayout.setVisibility(View.GONE); return; } long cur = start; while (cur <= end && precision != FrequencyData.DELAY_EVERYTHING) { Date d = new Date(cur); dates.add(new SpinnerDateData(d, formatter.format(d))); switch (precision) { case FrequencyData.DELAY_MONTH: { Calendar next = new GregorianCalendar(); next.setTimeInMillis(cur); next.add(Calendar.MONTH, 1); cur = next.getTimeInMillis(); break; } case FrequencyData.DELAY_YEAR: { Calendar next = new GregorianCalendar(); next.setTimeInMillis(cur); next.add(Calendar.YEAR, 1); cur = next.getTimeInMillis(); break; } case FrequencyData.DELAY_MINUTE: case FrequencyData.DELAY_DAY: case FrequencyData.DELAY_HOUR: case FrequencyData.DELAY_WEEK: default: cur += (long) precision * 1000; } } spinnerDate.setOnItemSelectedListener(null); //spinnerDate.setAdapter(new SpinnerDateAdapter(getActivity(), dates)); spinnerDate.setAdapter(new SpinnerDateAdapter(mActivity, dates)); spinnerDate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { FrequencyData f = frequencies.get(spinnerFrequency.getSelectedItemPosition()); FrequencyData precision = (FrequencyData) spinnerPrecision.getSelectedItem(); if (precision != null) EventBus.getDefault().post(new DateChangedEvent(dates.get(position).getDate(), f.getDelay(), precision.getDelay())); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinnerDate.setSelection(dates.size() - 1); mLinearLayout.setVisibility(View.VISIBLE); }
From source file:nf.frex.android.FrexActivity.java
private void preparePropertiesDialog(final Dialog dialog) { final Registry<Fractal> fractals = Registries.fractals; int fractalTypeIndex = fractals.getIndex(view.getFractalId()); final Spinner fractalTypeSpinner = (Spinner) dialog.findViewById(R.id.fractal_type_spinner); final SeekBar iterationsSeekBar = (SeekBar) dialog.findViewById(R.id.num_iterations_seek_bar); final EditText iterationsEditText = (EditText) dialog.findViewById(R.id.num_iterations_edit_text); final CheckBox juliaModeCheckBox = (CheckBox) dialog.findViewById(R.id.julia_mode_fractal_check_box); final CheckBox decoratedFractal = (CheckBox) dialog.findViewById(R.id.decorated_fractal_check_box); final Button okButton = (Button) dialog.findViewById(R.id.ok_button); final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button); juliaModeCheckBox.setEnabled(true);//from w ww . j a va 2 s. c o m ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, fractals.getIds()); arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fractalTypeSpinner.setAdapter(arrayAdapter); fractalTypeSpinner.setSelection(fractalTypeIndex, true); fractalTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View spinnerView, int position, long id) { Fractal fractal = fractals.getValue(position); iterationsEditText.setText(fractal.getDefaultIterMax() + ""); boolean sameFractal = view.getFractalId().equals(fractals.getId(position)); if (!sameFractal) { juliaModeCheckBox.setChecked(false); } juliaModeCheckBox.setEnabled(sameFractal); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); iterationsEditText.setText(view.getIterMax() + "", TextView.BufferType.NORMAL); final double iterationsMin = 1; final double iterationsMax = 3; final SeekBarConfigurer iterationsSeekBarConfigurer = SeekBarConfigurer.create(iterationsSeekBar, iterationsMin, iterationsMax, true, view.getIterMax()); iterationsSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { int iterMax = iterationsSeekBarConfigurer.getValueInt(); iterationsEditText.setText(iterMax + "", TextView.BufferType.NORMAL); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); iterationsEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { try { int iterMax = Integer.parseInt(v.getText().toString()); iterationsSeekBarConfigurer.setValue(iterMax); return true; } catch (NumberFormatException e) { return false; } } }); decoratedFractal.setChecked(view.isDecoratedFractal()); juliaModeCheckBox.setChecked(view.isJuliaModeFractal()); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int iterMax; try { iterMax = Integer.parseInt(iterationsEditText.getText().toString()); } catch (NumberFormatException e) { Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show(); return; } dialog.dismiss(); String oldConfigName = view.getConfigName(); String newFractalId = fractals.getId(fractalTypeSpinner.getSelectedItemPosition()); Fractal fractal = fractals.getValue(fractalTypeSpinner.getSelectedItemPosition()); String oldFractalId = view.getFractalId(); boolean newJuliaModeFractal = juliaModeCheckBox.isChecked(); boolean oldJuliaModeFractal = view.isJuliaModeFractal(); view.setFractalId(newFractalId); view.setIterMax(iterMax); view.setDecoratedFractal(decoratedFractal.isChecked()); view.setJuliaModeFractal(newJuliaModeFractal); boolean fractalTypeChanged = !oldFractalId.equals(newFractalId); if (fractalTypeChanged) { if (oldConfigName.contains(oldFractalId.toLowerCase())) { view.setConfigName(newFractalId.toLowerCase()); } view.setRegion(fractal.getDefaultRegion()); view.setBailOut(fractal.getDefaultBailOut()); } boolean juliaModeChanged = oldJuliaModeFractal != newJuliaModeFractal; if (fractalTypeChanged || juliaModeChanged) { view.getRegionHistory().clear(); view.getRegionHistory().add(fractal.getDefaultRegion().clone()); } view.recomputeAll(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); }