List of usage examples for android.widget Spinner setSelection
@Override public void setSelection(int position)
From source file:net.majorkernelpanic.spydroid.ClientActivity.java
/** Fetch the current streaming configuration of the remote phone **/ private void getCurrentConfiguration() { new AsyncTask<Void, Void, String>() { @Override//from w w w. ja va2 s. co m protected String doInBackground(Void... params) { HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 3000); HttpConnectionParams.setSoTimeout(httpParameters, 3000); HttpClient client = new DefaultHttpClient(httpParameters); HttpGet request = new HttpGet( "http://" + editTextIP.getText().toString() + ":8080/config.json?get"); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = ""; try { response = client.execute(request, responseHandler); } catch (ConnectTimeoutException e) { Log.i(TAG, "Connection timeout ! "); onCompletion(null); } catch (Exception e) { Log.e(TAG, "Could not fetch current configuration on remote device !"); e.printStackTrace(); } return response; } @Override protected void onPostExecute(String response) { try { JSONObject object = (JSONObject) new JSONTokener(response).nextValue(); ((CheckBox) findViewById(R.id.checkbox1)).setChecked(object.getBoolean("streamVideo")); ((CheckBox) findViewById(R.id.checkbox2)).setChecked(object.getBoolean("streamAudio")); for (int spinner : new int[] { R.id.spinner1, R.id.spinner2, R.id.spinner3, R.id.spinner4, R.id.spinner5 }) { Spinner view = (Spinner) findViewById(spinner); SpinnerAdapter adapter = view.getAdapter(); for (int i = 0; i < adapter.getCount(); i++) { Iterator<String> keys = object.keys(); while (keys.hasNext()) { String key = keys.next(); if (adapter.getItem(i).equals(object.get(key))) { view.setSelection(i); } } } } generateURI(); connectToServer(); } catch (Exception e) { stopStreaming(); e.printStackTrace(); } } }.execute(); }
From source file:gr.scify.newsum.ui.SearchViewActivity.java
private void initLayoutAndControls() { // Init topics initTopicSpinner();/*from www . j a va 2 s .c o m*/ // Init zoom controls initZoomControls(); // Init rating bar initRatingBar(); // Init selected item Spinner spinner = (Spinner) findViewById(R.id.spinner1); // take the selected topic from the TopicActivity Bundle extras = getIntent().getExtras(); // Show active topic final int num = extras.getInt("topicNum"); spinner.setSelection(num); }
From source file:com.esri.arcgisruntime.sample.rgbrenderer.ParametersDialogFragment.java
/** * Builds parameter dialog with values pulled through from MainActivity. * * @param savedInstanceState/* w ww. ja va2s.c om*/ * @return create parameter dialog box */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); Bundle rgbParameters = getArguments(); if (rgbParameters != null) { mMinR = rgbParameters.getInt("minR"); mMaxR = rgbParameters.getInt("maxR"); mMinG = rgbParameters.getInt("minG"); mMaxG = rgbParameters.getInt("maxG"); mMinB = rgbParameters.getInt("minB"); mMaxB = rgbParameters.getInt("maxB"); mPercentClipMin = rgbParameters.getInt("percent_clip_min"); mPercentClipMax = rgbParameters.getInt("percent_clip_max"); mStdDevFactor = rgbParameters.getInt("std_dev_factor"); mStretchType = (MainActivity.StretchType) rgbParameters.getSerializable("stretch_type"); Log.d("Incoming Parameters", "min r: " + mMinR + " max r: " + mMaxR + " min g: " + mMinG + " max g: " + mMaxG + " min b: " + mMinB + " max b: " + mMaxB); } final AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext()); @SuppressLint("InflateParams") final View dialogView = inflater.inflate(R.layout.rgb_dialog_box, null); paramDialog.setView(dialogView); paramDialog.setTitle(R.string.rgb_rendering_parameters); paramDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }); paramDialog.setPositiveButton("Render", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); ParametersListener activity = (ParametersListener) getActivity(); activity.returnParameters(mMinR, mMaxR, mMinG, mMaxG, mMinB, mMaxB, mPercentClipMin, mPercentClipMax, mStdDevFactor, mStretchType); } }); // min max ui elements mMinRedTextView = (TextView) dialogView.findViewById(R.id.min_red_value_text_view); mMaxRedTextView = (TextView) dialogView.findViewById(R.id.max_red_value_text_view); mMinGreenTextView = (TextView) dialogView.findViewById(R.id.min_green_value_text_view); mMaxGreenTextView = (TextView) dialogView.findViewById(R.id.max_green_value_text_view); mMinBlueTextView = (TextView) dialogView.findViewById(R.id.min_blue_value_text_view); mMaxBlueTextView = (TextView) dialogView.findViewById(R.id.max_blue_value_text_view); mMinRedSeekBar = (SeekBar) dialogView.findViewById(R.id.min_red_seek_bar); mMaxRedSeekBar = (SeekBar) dialogView.findViewById(R.id.max_red_seek_bar); mMinGreenSeekBar = (SeekBar) dialogView.findViewById(R.id.min_green_seek_bar); mMaxGreenSeekBar = (SeekBar) dialogView.findViewById(R.id.max_green_seek_bar); mMinBlueSeekBar = (SeekBar) dialogView.findViewById(R.id.min_blue_seek_bar); mMaxBlueSeekBar = (SeekBar) dialogView.findViewById(R.id.max_blue_seek_bar); mMinRedSeekBar.setMax(255); mMaxRedSeekBar.setMax(255); mMinGreenSeekBar.setMax(255); mMaxGreenSeekBar.setMax(255); mMinBlueSeekBar.setMax(255); mMaxBlueSeekBar.setMax(255); mCurrMinRedTextView = (TextView) dialogView.findViewById(R.id.curr_min_red_text_view); mCurrMaxRedTextView = (TextView) dialogView.findViewById(R.id.curr_max_red_text_view); mCurrMinGreenTextView = (TextView) dialogView.findViewById(R.id.curr_min_green_text_view); mCurrMaxGreenTextView = (TextView) dialogView.findViewById(R.id.curr_max_green_text_view); mCurrMinBlueTextView = (TextView) dialogView.findViewById(R.id.curr_min_blue_text_view); mCurrMaxBlueTextView = (TextView) dialogView.findViewById(R.id.curr_max_blue_text_view); //update seek bar positions with current mMinMax values updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); // percent clip ui elements mPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.percent_clip_min_value_text_view); mPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.percent_clip_max_value_text_view); mPercentClipMinSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_min_seek_bar); mPercentClipMaxSeekBar = (SeekBar) dialogView.findViewById(R.id.percent_clip_max_seek_bar); mPercentClipMinSeekBar.setMax(99); mPercentClipMaxSeekBar.setMax(99); mCurrPercentClipMinTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_min_text_view); mCurrPercentClipMaxTextView = (TextView) dialogView.findViewById(R.id.curr_percent_clip_max_text_view); //update seek bar positions with current PercentClip updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); // standard deviation ui elements mStdDevTextView = (TextView) dialogView.findViewById(R.id.std_dev_text_view); mStdDevSeekBar = (SeekBar) dialogView.findViewById(R.id.std_dev_seek_bar); mStdDevSeekBar.setMax(3); mCurrStdDevTextView = (TextView) dialogView.findViewById(R.id.curr_std_dev_text_view); //update seek bar position with current StandardDeviation updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView); // set ui to previous selection if (mStretchType == MainActivity.StretchType.MIN_MAX) { setMinMaxVisibility(true); setPercentClipVisibility(false); setStdDevVisibility(false); } else if (mStretchType == MainActivity.StretchType.PERCENT_CLIP) { setMinMaxVisibility(false); setPercentClipVisibility(true); setStdDevVisibility(false); } else if (mStretchType == MainActivity.StretchType.STANDARD_DEVIATION) { setMinMaxVisibility(false); setPercentClipVisibility(false); setStdDevVisibility(true); } // seek bar listeners mMinRedSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinR = progress; updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); // move max to march min if max goes below min if (mMaxR < mMinR) { mMaxR = mMinR; updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxRedSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxR = progress; updateSeekBar(mMaxRedSeekBar, mMaxR, mCurrMaxRedTextView); // move min to match max if min goes above max if (mMinR > mMaxR) { mMinR = mMaxR; updateSeekBar(mMinRedSeekBar, mMinR, mCurrMinRedTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMinGreenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinG = progress; updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); // move max to march min if max goes below min if (mMaxG < mMinG) { mMaxG = mMinG; updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxGreenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxG = progress; updateSeekBar(mMaxGreenSeekBar, mMaxG, mCurrMaxGreenTextView); // move min to match max if min goes above max if (mMinG > mMaxG) { mMinG = mMaxG; updateSeekBar(mMinGreenSeekBar, mMinG, mCurrMinGreenTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMinBlueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMinB = progress; updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); // move max to march min if max goes below min if (mMaxB < mMinB) { mMaxB = mMinB; updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mMaxBlueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mMaxB = progress; updateSeekBar(mMaxBlueSeekBar, mMaxB, mCurrMaxBlueTextView); // move min to match max if min goes above max if (mMinB > mMaxB) { mMinB = mMaxB; updateSeekBar(mMinBlueSeekBar, mMinB, mCurrMinBlueTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mPercentClipMinSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mPercentClipMin = progress; updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); if (mPercentClipMin + mPercentClipMax > 100) { // constrain min + max <= 100 mPercentClipMax = 100 - mPercentClipMin; updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mPercentClipMaxSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mPercentClipMax = progress; updateSeekBar(mPercentClipMaxSeekBar, mPercentClipMax, mCurrPercentClipMaxTextView); if (mPercentClipMin + mPercentClipMax > 100) { // constrain min + max <= 100 mPercentClipMin = 100 - mPercentClipMax; updateSeekBar(mPercentClipMinSeekBar, mPercentClipMin, mCurrPercentClipMinTextView); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mStdDevSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mStdDevFactor = progress; updateSeekBar(mStdDevSeekBar, mStdDevFactor, mCurrStdDevTextView); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // stretch type spinner List<String> stretchTypeArray = new ArrayList<>(); stretchTypeArray.add(MainActivity.StretchType.MIN_MAX.toString()); //ordinals:0 stretchTypeArray.add(MainActivity.StretchType.PERCENT_CLIP.toString()); //1 stretchTypeArray.add(MainActivity.StretchType.STANDARD_DEVIATION.toString()); //2 ArrayAdapter<String> stretchTypeSpinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.rgb_spinner_text_view, stretchTypeArray); Spinner stretchTypeSpinner = (Spinner) dialogView.findViewById(R.id.stretch_type_spinner); stretchTypeSpinner.setAdapter(stretchTypeSpinnerAdapter); stretchTypeSpinner.setSelection(mStretchType.ordinal()); stretchTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: mStretchType = MainActivity.StretchType.MIN_MAX; setMinMaxVisibility(true); setPercentClipVisibility(false); setStdDevVisibility(false); break; case 1: mStretchType = MainActivity.StretchType.PERCENT_CLIP; setMinMaxVisibility(false); setPercentClipVisibility(true); setStdDevVisibility(false); break; case 2: mStretchType = MainActivity.StretchType.STANDARD_DEVIATION; setMinMaxVisibility(false); setPercentClipVisibility(false); setStdDevVisibility(true); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); return paramDialog.create(); }
From source file:com.google.android.apps.flexbox.MainActivity.java
private void initializeSpinner(int currentValue, int menuItemId, Menu navigationMenu, int arrayResourceId, AdapterView.OnItemSelectedListener listener, ValueToStringConverter converter) { Spinner spinner = (Spinner) MenuItemCompat.getActionView(navigationMenu.findItem(menuItemId)); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayResourceId, R.layout.spinner_item);/*from w w w . ja va2s . c o m*/ spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(listener); String selectedAsString = converter.asString(currentValue); int position = adapter.getPosition(selectedAsString); spinner.setSelection(position); }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the Google Drive account is changed */ private void updateGdriveAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.gdrive_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.gdrive_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsGDrivePlayUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); TextView acctView = (TextView) findViewById(R.id.gdrive_acct); assert acctView != null; acctView.setText(acct);/*from w w w . j a va 2 s .c om*/ View freqSpinLabel = findViewById(R.id.gdrive_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.gdrive_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); } else { itsGDrivePlayUri = null; } }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the Box account is changed */ private void updateBoxAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.box_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.box_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsBoxUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); boolean authorized = getBoxProvider().isAccountAuthorized(); TextView acctView = (TextView) findViewById(R.id.box_acct); assert acctView != null; acctView.setText(acct);/*from ww w . j av a 2 s . c o m*/ View freqSpinLabel = findViewById(R.id.box_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.box_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); GuiUtils.setVisible(findViewById(R.id.box_acct_unlink), !authorized); } else { itsBoxUri = null; } }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the Dropbox account is changed */ private void updateDropboxAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.dropbox_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.dropbox_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsDropboxUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); boolean authorized = getDbxProvider().isAccountAuthorized(); TextView acctView = (TextView) findViewById(R.id.dropbox_acct); assert acctView != null; acctView.setText(acct);/*from w ww . j a va 2s. c o m*/ View chooseFilesBtn = findViewById(R.id.dropbox_choose_files); assert chooseFilesBtn != null; chooseFilesBtn.setEnabled(authorized); View freqSpinLabel = findViewById(R.id.dropbox_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.dropbox_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); GuiUtils.setVisible(findViewById(R.id.dropbox_acct_unlink), !authorized); } else { itsDropboxUri = null; } }
From source file:com.jefftharris.passwdsafe.sync.MainActivity.java
/** Update the UI when the OneDrive account is changed */ private void updateOnedriveAccount(Cursor cursor) { boolean haveCursor = (cursor != null); GuiUtils.setVisible(findViewById(R.id.onedrive_container), haveCursor); GuiUtils.setVisible(findViewById(R.id.onedrive_separator), haveCursor); if (haveCursor) { long id = cursor.getLong(PasswdSafeContract.Providers.PROJECTION_IDX_ID); String acct = PasswdSafeContract.Providers.getDisplayName(cursor); int freqVal = cursor.getInt(PasswdSafeContract.Providers.PROJECTION_IDX_SYNC_FREQ); ProviderSyncFreqPref freq = ProviderSyncFreqPref.freqValueOf(freqVal); itsOnedriveUri = ContentUris.withAppendedId(PasswdSafeContract.Providers.CONTENT_URI, id); Provider provider = getOnedriveProvider(); boolean authorized = provider.isAccountAuthorized(); TextView acctView = (TextView) findViewById(R.id.onedrive_acct); assert acctView != null; acctView.setText(acct);/*from w w w . java2 s . c o m*/ GuiUtils.setVisible(findViewById(R.id.onedrive_auth_required), !authorized); View freqSpinLabel = findViewById(R.id.onedrive_interval_label); assert freqSpinLabel != null; Spinner freqSpin = (Spinner) findViewById(R.id.onedrive_interval); assert freqSpin != null; freqSpin.setSelection(freq.getDisplayIdx()); freqSpin.setEnabled(true); freqSpinLabel.setEnabled(true); } else { itsOnedriveUri = null; } }
From source file:com.armtimes.dialogs.DialogSettings.java
/** * This function initialize News Preview Font Size Spinner and * it's adapter./*from w ww . j a va 2s. com*/ * * @param settingsView Settings view with controllers. */ private void initFontSizeStuff(final View settingsView) { Spinner fontSizeSpinner = (Spinner) settingsView.findViewById(R.id.spinnerFontSize); // Initialize Adapter ArrayAdapter fontSizeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.font_size_array, android.R.layout.simple_spinner_item); fontSizeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fontSizeSpinner.setAdapter(fontSizeAdapter); int selectedItem = 0; switch (getTextFontSize(getActivity())) { case android.R.style.TextAppearance_Medium: selectedItem = 1; break; case android.R.style.TextAppearance_Large: selectedItem = 2; break; } fontSizeSpinner.setSelection(selectedItem); fontSizeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { setTextFontSize(position == 1 ? android.R.style.TextAppearance_Medium : position == 2 ? android.R.style.TextAppearance_Large : android.R.style.TextAppearance_Small); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:org.openoverlayrouter.noroot.updateConfActivity.java
public void readConfFileAndFillParameters() { try {//from w w w. j a v a2s .c o m BufferedReader br = new BufferedReader(new FileReader(conf_file)); String line = br.readLine(); String sub_line = null; String sub_line_1 = null; ifaces = new ArrayList<String>(); while (line != null) { if (line.startsWith("#")) { line = br.readLine(); continue; } line = line.toLowerCase(); line = line.replaceAll("\\s", ""); if (line.contains("database-mapping")) { int num_braces = 0; if (line.contains("{")) { num_braces++; } do { sub_line = br.readLine(); if (sub_line.startsWith("#")) { sub_line = br.readLine(); continue; } if (sub_line.contains("{")) { num_braces++; } sub_line = sub_line.toLowerCase(); sub_line = sub_line.replaceAll("\\s", ""); if (sub_line.contains("eid-prefix")) { String[] tmp = sub_line.split("="); if (tmp.length < 2) continue; String[] tmp_1 = tmp[1].split("/"); if (tmp_1.length < 2) continue; if (tmp_1[0].contains(":")) { eidIPv6 = tmp_1[0]; EditText e = (EditText) llLayout.findViewById(R.id.updateConfeid6Text); e.setText(eidIPv6); } else if (tmp_1[0].contains(".")) { eidIPv4 = tmp_1[0]; EditText e = (EditText) llLayout.findViewById(R.id.updateConfeid4Text); e.setText(eidIPv4); } } if (sub_line.contains("rloc-iface")) { sub_line = br.readLine(); if (sub_line.startsWith("#")) { sub_line = br.readLine(); continue; } sub_line = sub_line.toLowerCase(); sub_line = sub_line.replaceAll("\\s", ""); if (sub_line.contains("interface")) { String[] tmp = sub_line.split("="); if (tmp.length < 2) continue; String iface_name = tmp[1]; Iterator<String> iface_it = iface_list.iterator(); while (iface_it.hasNext()) { if (iface_it.next().equals(iface_name)) { if (!ifaces.contains(iface_name)) { ifaces.add(iface_name); } break; } } } } if (sub_line.contains("}")) { num_braces--; } } while (num_braces != 0); } else if (line.contains("map-resolver")) { sub_line = br.readLine(); if (sub_line.startsWith("#")) { sub_line = br.readLine(); continue; } sub_line = sub_line.replaceAll("\\s", ""); if (sub_line.contains(",")) { String[] tmp = sub_line.split(","); if (tmp.length != 0) { MR = tmp[0]; } } else { MR = sub_line; } EditText e = (EditText) llLayout.findViewById(R.id.updateConfMRText); e.setText(MR); } else if (line.contains("nat_traversal_support") && !line.startsWith("#")) { String[] tmp = line.split("="); if (tmp.length > 1) { String nat_aware_aux = tmp[1]; if (nat_aware_aux.equals("on") || nat_aware_aux.equals("true")) { nat_aware = true; } else { nat_aware = false; } } CheckBox c = (CheckBox) llLayout.findViewById(R.id.updateConf_NAT_aware); c.setChecked(nat_aware); } else if (line.contains("map-server")) { do { sub_line = br.readLine(); if (sub_line.startsWith("#")) { sub_line = br.readLine(); continue; } sub_line = sub_line.replaceAll("\\s", ""); sub_line_1 = sub_line; // Not lose uppercase in password sub_line = sub_line.toLowerCase(); if (sub_line.contains("address")) { String[] tmp = sub_line.split("="); if (tmp.length > 1) { MS = tmp[1]; } } else if (sub_line.contains("key") & !sub_line.contains("key-type")) { String[] tmp = sub_line_1.split("="); if (tmp.length > 1) { MSKey = tmp[1]; } } } while (!sub_line.contains("}")); EditText e = (EditText) llLayout.findViewById(R.id.updateConfMSText); e.setText(MS); EditText et = (EditText) llLayout.findViewById(R.id.updateConfMSKeyText); et.setText(MSKey); } else if (line.contains("proxy-etr")) { do { sub_line = br.readLine(); if (sub_line.startsWith("#")) { sub_line = br.readLine(); continue; } sub_line = sub_line.toLowerCase(); sub_line = sub_line.replaceAll("\\s", ""); if (sub_line.contains("address")) { String[] tmp = sub_line.split("="); if (tmp.length > 1) { proxyETR = tmp[1]; } } } while (!sub_line.contains("}")); EditText e = (EditText) llLayout.findViewById(R.id.updateConf_proxy_etr); e.setText(proxyETR); } else if (line.contains("override-dns=")) { String[] tmp = line.split("="); if (tmp.length > 1) { String overrideDNS_aux = tmp[1]; if (overrideDNS_aux.equals("on") || overrideDNS_aux.equals("true")) { overrideDNS = true; } else { overrideDNS = false; } } CheckBox c = (CheckBox) llLayout.findViewById(R.id.updateConfDNSCheck); c.setChecked(overrideDNS); } else if (line.contains("override-dns-primary=")) { String[] tmp = line.split("="); if (tmp.length > 1) { if (ConfigTools.validate_IP_Address(tmp[1])) { DNS1 = tmp[1]; } } EditText e = (EditText) llLayout.findViewById(R.id.updateConfDNS1Text); e.setText(DNS1); } else if (line.contains("override-dns-secondary=")) { String[] tmp = line.split("="); if (tmp.length > 1) { if (ConfigTools.validate_IP_Address(tmp[1])) { DNS2 = tmp[1]; } } EditText e = (EditText) llLayout.findViewById(R.id.updateConfDNS2Text); e.setText(DNS2); } else if (line.contains("debug=")) { String[] tmp = line.split("="); if (tmp.length > 1) { logLevel = tmp[1]; } Spinner log_spinner = (Spinner) llLayout.findViewById(R.id.LogSpinner); log_spinner.setSelection(new Integer(logLevel).intValue()); } line = br.readLine(); } MultiSelectionSpinner spinner = (MultiSelectionSpinner) llLayout.findViewById(R.id.IfaceNameSpinner); spinner.setSelection(ifaces); EditText e = (EditText) llLayout.findViewById(R.id.updateConfDNS1Text); e.setEnabled(overrideDNS); e = (EditText) llLayout.findViewById(R.id.updateConfDNS2Text); e.setEnabled(overrideDNS); e = (EditText) llLayout.findViewById(R.id.updateConf_proxy_etr); e.setEnabled(!nat_aware); e = (EditText) llLayout.findViewById(R.id.updateConfMRText); e.setEnabled(!nat_aware); } catch (IOException e) { Log.e("updateconf", "An IOException was caught :" + e.getMessage()); } }