List of usage examples for android.widget SeekBar setMax
@Override public synchronized void setMax(int max)
From source file:com.rks.musicx.ui.fragments.EqFragment.java
private void initEq(View rootView) { try {//from w ww . j av a2 s . com for (short i = 0; i < Equalizers.getNumberOfBands(); i++) { short eqbands = i; short[] bandLevel = Equalizers.getBandLevelRange(); seekBar = new VerticalSeekBar(getContext()); textView = new TextView(getContext()); switch (i) { case 0: seekBar = (VerticalSeekBar) rootView.findViewById(R.id.seek_bar1); textView = (TextView) rootView.findViewById(R.id.level1); break; case 1: seekBar = (VerticalSeekBar) rootView.findViewById(R.id.seek_bar2); textView = (TextView) rootView.findViewById(R.id.level2); break; case 2: seekBar = (VerticalSeekBar) rootView.findViewById(R.id.seek_bar3); textView = (TextView) rootView.findViewById(R.id.level3); break; case 3: seekBar = (VerticalSeekBar) rootView.findViewById(R.id.seek_bar4); textView = (TextView) rootView.findViewById(R.id.level4); break; case 4: seekBar = (VerticalSeekBar) rootView.findViewById(R.id.seek_bar5); textView = (TextView) rootView.findViewById(R.id.level5); break; } seekBarFinal[eqbands] = seekBar; seekBar.setId(i); if (Extras.getInstance().getDarkTheme() || Extras.getInstance().getBlackTheme()) { textView.setTextColor(Color.WHITE); seekBar.setThumb(ContextCompat.getDrawable(getContext(), R.drawable.thumb)); seekBar.getThumb().setTint(accentcolor); seekBar.setProgressTintMode(PorterDuff.Mode.SRC_ATOP); seekBar.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP); } else { textView.setTextColor(Color.WHITE); seekBar.setThumb(ContextCompat.getDrawable(getContext(), R.drawable.thumb)); seekBar.getThumb().setTint(accentcolor); seekBar.setProgressTintMode(PorterDuff.Mode.SRC_ATOP); seekBar.setBackgroundTintMode(PorterDuff.Mode.SRC_ATOP); } if (bandLevel != null) { seekBar.setMax(bandLevel[1] - bandLevel[0]); int presetPos = Extras.getInstance().getPresetPos(); if (presetPos < Equalizers.getPresetNo()) { seekBarFinal[eqbands].setProgress(Equalizers.getBandLevel(eqbands) - bandLevel[0]); } else { seekBarFinal[i].setProgress( Extras.getInstance().saveEq().getInt(BAND_LEVEL + i, 0) - bandLevel[0]); } } int frequency = Equalizers.getCenterFreq(eqbands); if (frequency < 1000 * 1000) { textView.setText((frequency / 1000) + "Hz"); } else { textView.setText((frequency / (1000 * 1000)) + "kHz"); } seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { try { if (fromUser) { if (bandLevel != null) { int level = seekbar.getProgress() + bandLevel[0]; Equalizers.setBandLevel(eqbands, (short) level); int presetNo = Equalizers.getPresetNo(); if (presetNo != 0) { appCompatSpinner.setSelection(Equalizers.getPresetNo()); } else { appCompatSpinner.setSelection(0); } Equalizers.savePrefs(eqbands, level); } } } catch (Exception e) { e.printStackTrace(); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } } catch (Exception e) { e.printStackTrace(); Log.d(TAG, "Failed to init eq"); } }
From source file:universe.constellation.orion.viewer.OrionViewerActivity.java
public void initZoomScreen() { //zoom screen final Spinner sp = (Spinner) findMyViewById(R.id.zoom_spinner); final EditText zoomText = (EditText) findMyViewById(R.id.zoom_picker_message); final SeekBar zoomSeek = (SeekBar) findMyViewById(R.id.zoom_picker_seeker); if (zoomSeek != null) { zoomSeek.setMax(300); zoomSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (zoomInternal != 1) { zoomText.setText("" + progress); if (sp.getSelectedItemPosition() != 0) { int oldInternal = zoomInternal; zoomInternal = 2; sp.setSelection(0); zoomInternal = oldInternal; }// ww w .j a v a 2 s.com } } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { } }); } getSubscriptionManager().addDocListeners(new DocumentViewAdapter() { @Override public void documentOpened(Controller controller) { updateZoom(); } }); final ImageButton zplus = (ImageButton) findMyViewById(R.id.zoom_picker_plus); zplus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { zoomSeek.incrementProgressBy(1); } }); final ImageButton zminus = (ImageButton) findMyViewById(R.id.zoom_picker_minus); zminus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (zoomSeek.getProgress() != 0) { zoomSeek.incrementProgressBy(-1); } } }); ImageButton closeZoomPeeker = (ImageButton) findMyViewById(R.id.zoom_picker_close); closeZoomPeeker.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //main menu onAnimatorCancel(); //updateZoom(); } }); ImageButton zoom_preview = (ImageButton) findMyViewById(R.id.zoom_preview); zoom_preview.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onApplyAction(); int index = sp.getSelectedItemPosition(); controller.changeZoom(index == 0 ? (int) (Float.parseFloat(zoomText.getText().toString()) * 100) : -1 * (index - 1)); updateZoom(); } }); sp.setAdapter(new MyArrayAdapter()); sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { boolean disable = position != 0; int oldZoomInternal = zoomInternal; if (zoomInternal != 2) { zoomInternal = 1; if (disable) { zoomText.setText((String) parent.getAdapter().getItem(position)); } else { zoomText.setText("" + ((int) (controller.getCurrentPageZoom() * 10000)) / 100f); zoomSeek.setProgress((int) (controller.getCurrentPageZoom() * 100)); } zoomInternal = oldZoomInternal; } zminus.setVisibility(disable ? View.GONE : View.VISIBLE); zplus.setVisibility(disable ? View.GONE : View.VISIBLE); zoomText.setFocusable(!disable); zoomText.setFocusableInTouchMode(!disable); final LinearLayout parent1 = (LinearLayout) zoomText.getParent(); parent1.post(new Runnable() { @Override public void run() { parent1.requestLayout(); } }); } public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); //by width sp.setSelection(1); }
From source file:universe.constellation.orion.viewer.OrionViewerActivity.java
public void initPagePeekerScreen() { final SeekBar pageSeek = (SeekBar) findMyViewById(R.id.page_picker_seeker); getSubscriptionManager().addDocListeners(new DocumentViewAdapter() { @Override// w w w .j a v a2s . c o m public void documentOpened(Controller controller) { pageSeek.setMax(controller.getPageCount() - 1); pageSeek.setProgress(controller.getCurrentPage()); } @Override public void pageChanged(int newPage, int pageCount) { pageSeek.setProgress(newPage); } }); final TextView pageNumberText = (TextView) findMyViewById(R.id.page_picker_message); //initial state pageNumberText.setText("" + 1); pageSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { pageNumberText.setText("" + (progress + 1)); } public void onStartTrackingTouch(SeekBar seekBar) { } public void onStopTrackingTouch(SeekBar seekBar) { } }); ImageButton closePagePeeker = (ImageButton) findMyViewById(R.id.page_picker_close); ImageButton plus = (ImageButton) findMyViewById(R.id.page_picker_plus); plus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { pageSeek.incrementProgressBy(1); } }); ImageButton minus = (ImageButton) findMyViewById(R.id.page_picker_minus); minus.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (pageSeek.getProgress() != 0) { pageSeek.incrementProgressBy(-1); } } }); closePagePeeker.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //controller.drawPage(Integer.valueOf(pageNumberText.getText().toString()) - 1); //main menu onAnimatorCancel(); updatePageSeeker(); //animator.setDisplayedChild(MAIN_SCREEN); } }); ImageButton page_preview = (ImageButton) findMyViewById(R.id.page_preview); page_preview.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onApplyAction(); if (!"".equals(pageNumberText.getText())) { try { int parsedInput = Integer.valueOf(pageNumberText.getText().toString()); controller.drawPage(parsedInput - 1); } catch (NumberFormatException ex) { showError("Couldn't parse " + pageNumberText.getText(), ex); } } } }); }
From source file:com.mylovemhz.simplay.MediaControlFragment.java
private void configureButtons(PlaybackStateCompat state) { if (state == null) { return;/* w ww . jav a 2s.co m*/ } boolean enablePlay = false; switch (state.getState()) { case PlaybackStateCompat.STATE_STOPPED: albumImage.setImageResource(R.drawable.ic_album); artistText.setText(""); titleText.setText(""); seekBar.setProgress(0); seekBar.setMax(1); case PlaybackStateCompat.STATE_PAUSED: handler.removeCallbacks(seekTickRunnable); enablePlay = true; break; case PlaybackStateCompat.STATE_PLAYING: handler.post(seekTickRunnable); break; case PlaybackStateCompat.STATE_ERROR: Log.e(TAG, "error playbackstate: " + state.getErrorMessage()); Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show(); break; } if (enablePlay) { playPauseButton.setImageResource(playDrawableResource); } else { playPauseButton.setImageResource(pauseDrawableResource); } playPauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (getPlaybackState() != PlaybackStateCompat.STATE_PLAYING) { mediaController.getTransportControls().play(); } else { mediaController.getTransportControls().pause(); } } }); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mediaController.getTransportControls().skipToPrevious(); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mediaController.getTransportControls().skipToNext(); } }); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { mediaController.getTransportControls().seekTo(progress); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); }
From source file:com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true);/*w w w . jav a 2 s. c om*/ ScrollView ll = (ScrollView) inflater.inflate(R.layout.sound_control, container, false); fa = (ActionBarActivity) super.getActivity(); fa.getSupportActionBar().setDisplayHomeAsUpEnabled(true); fa.getSupportActionBar().setHomeButtonEnabled(true); bootPrefs = fa.getSharedPreferences("BOOT_PREFS", 0); final Boolean isLinked = fa.getSharedPreferences("SOUND_CONTROL", 0).getBoolean("LINKED", true); assert ll != null; final SeekBar headphoneLeft = (SeekBar) ll.findViewById(R.id.headphone_seekbar_left); final SeekBar headphoneRight = (SeekBar) ll.findViewById(R.id.headphone_seekbar_right); final SeekBar headphonePALeft = (SeekBar) ll.findViewById(R.id.headphone_pa_seekbar_left); final SeekBar headphonePARight = (SeekBar) ll.findViewById(R.id.headphone_pa_seekbar_right); final SeekBar speakerLeft = (SeekBar) ll.findViewById(R.id.speaker_seekbar_left); final SeekBar speakerRight = (SeekBar) ll.findViewById(R.id.speaker_seekbar_right); final SeekBar micGain = (SeekBar) ll.findViewById(R.id.mic_seekbar); final SeekBar camMicGain = (SeekBar) ll.findViewById(R.id.cam_mic_seekbar); final TextView headUnitLeft = (TextView) ll.findViewById(R.id.headphone_unit_left); final TextView headUnitRight = (TextView) ll.findViewById(R.id.headphone_unit_right); final TextView headPAUnitLeft = (TextView) ll.findViewById(R.id.headphone_pa_unit_left); final TextView headPAUnitRight = (TextView) ll.findViewById(R.id.headphone_pa_unit_right); final TextView speakerUnitLeft = (TextView) ll.findViewById(R.id.speaker_unit_left); final TextView speakerUnitRight = (TextView) ll.findViewById(R.id.speaker_unit_right); final TextView micUnit = (TextView) ll.findViewById(R.id.mic_unit); final TextView camMicUnit = (TextView) ll.findViewById(R.id.cam_mic_unit); // Headphone L/R Gain if (Helpers.doesFileExist(FAUX_SC_HEADPHONE)) { headphoneLeft.setMax(40); headphoneRight.setMax(40); String[] headphoneGains = CPUHelper.readOneLineNotRoot(FAUX_SC_HEADPHONE).split(" "); int headphoneGainLeft = Integer.valueOf(headphoneGains[0]); if (headphoneGainLeft > 100) headphoneGainLeft -= 256; int headphoneGainRight = Integer.valueOf(headphoneGains[1]); if (headphoneGainRight > 100) headphoneGainRight -= 256; headphoneLeft.setProgress(headphoneGainLeft + 30); headphoneRight.setProgress(headphoneGainRight + 30); headUnitLeft.setText(headphoneGainLeft + ""); headUnitRight.setText(headphoneGainRight + ""); headphoneLeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { headUnitLeft.setText(i - 30 + ""); if (isLinked) { headUnitRight.setText(i - 30 + ""); headphoneRight.setProgress(i); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSCInt(seekBar.getProgress()); int toApplyRight = getSCInt(headphoneRight.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_HEADPHONE + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("HEADPHONE", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); headphoneRight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { headUnitRight.setText(i - 30 + ""); if (isLinked) { headUnitLeft.setText(i - 30 + ""); headphoneLeft.setProgress(i); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSCInt(headphoneLeft.getProgress()); int toApplyRight = getSCInt(seekBar.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_HEADPHONE + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("HEADPHONE", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); } else { headphoneLeft.setMax(40); headphoneRight.setMax(40); headphoneLeft.setProgress(20); headphoneRight.setProgress(20); headphoneLeft.setEnabled(false); headphoneRight.setEnabled(false); headUnitLeft.setText("Unsupported"); headUnitRight.setText("Unsupported"); } // Headphone analog L/R gain if (Helpers.doesFileExist(FAUX_SC_HEADPHONE_POWERAMP)) { headphonePALeft.setMax(12); headphonePARight.setMax(12); String[] headphonePAGains = CPUHelper.readOneLineNotRoot(FAUX_SC_HEADPHONE_POWERAMP).split(" "); int headphonePAGainLeft = Integer.valueOf(headphonePAGains[0]); int headphonePAGainRight = Integer.valueOf(headphonePAGains[1]); headphonePALeft.setProgress(headphonePAGainLeft); headphonePARight.setProgress(headphonePAGainRight); headPAUnitLeft.setText(headphonePAGainLeft - 26 + ""); headPAUnitRight.setText(headphonePAGainRight - 26 + ""); headphonePALeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { headPAUnitLeft.setText(i - 6 + ""); if (isLinked) { headphonePARight.setProgress(i); headPAUnitRight.setText(i - 6 + ""); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSysfsValue(seekBar.getProgress()); int toApplyRight = getSysfsValue(headphonePARight.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_HEADPHONE_POWERAMP + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("HEADPHONE_PA", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); headphonePARight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { headPAUnitRight.setText(i - 6 + ""); if (isLinked) { headphonePALeft.setProgress(i); headPAUnitLeft.setText(i - 6 + ""); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSysfsValue(headphonePALeft.getProgress()); int toApplyRight = getSysfsValue(seekBar.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_HEADPHONE_POWERAMP + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("HEADPHONE_PA", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); } else { headphonePALeft.setMax(40); headphonePARight.setMax(40); headphonePALeft.setProgress(20); headphonePARight.setProgress(20); headphonePALeft.setEnabled(false); headphonePARight.setEnabled(false); headPAUnitLeft.setText("Unsupported"); headPAUnitRight.setText("Unsupported"); } // Speaker L/R Gain if (Helpers.doesFileExist(FAUX_SC_SPEAKER)) { speakerLeft.setMax(40); speakerRight.setMax(40); String[] speakerGains = CPUHelper.readOneLineNotRoot(FAUX_SC_SPEAKER).split(" "); int speakerGainLeft = Integer.valueOf(speakerGains[0]); if (speakerGainLeft > 100) speakerGainLeft -= 256; int speakerGainRight = Integer.valueOf(speakerGains[1]); if (speakerGainRight > 100) speakerGainRight -= 256; speakerLeft.setProgress(speakerGainLeft + 30); speakerRight.setProgress(speakerGainRight + 30); speakerUnitLeft.setText(speakerGainLeft + ""); speakerUnitRight.setText(speakerGainRight + ""); speakerLeft.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { speakerUnitLeft.setText(i - 30 + ""); if (isLinked) { speakerUnitRight.setText(i - 30 + ""); speakerRight.setProgress(i); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSCInt(seekBar.getProgress()); int toApplyRight = getSCInt(speakerRight.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_SPEAKER + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("SPEAKER", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); speakerRight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { speakerUnitRight.setText(i - 30 + ""); if (isLinked) { speakerUnitLeft.setText(i - 30 + ""); speakerLeft.setProgress(i); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int toApplyLeft = getSCInt(speakerLeft.getProgress()); int toApplyRight = getSCInt(seekBar.getProgress()); Helpers.CMDProcessorWrapper.runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight) + " > " + FAUX_SC_SPEAKER + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("SPEAKER", toApplyLeft + " " + toApplyRight + " " + Helpers.getSoundCountrolBitRepresentation(toApplyLeft, toApplyRight)) .commit(); } }); } else { speakerLeft.setMax(40); speakerRight.setMax(40); speakerLeft.setProgress(20); speakerRight.setProgress(20); speakerLeft.setEnabled(false); speakerRight.setEnabled(false); speakerUnitLeft.setText("Unsupported"); speakerUnitRight.setText("Unsupported"); } // Microphone Gain if (Helpers.doesFileExist(FAUX_SC_MIC)) { int micValue = Integer.valueOf(CPUHelper.readOneLine(FAUX_SC_MIC)); if (micValue > 100) micValue -= 256; micGain.setMax(40); micGain.setProgress(micValue + 30); micUnit.setText(micValue + ""); micGain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { micUnit.setText(i - 30 + ""); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int scProgress = seekBar.getProgress() - 30; if (scProgress < 0) scProgress += 256; Helpers.CMDProcessorWrapper .runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + scProgress + " " + Helpers.getSoundCountrolBitRepresentation(scProgress, 0) + " > " + FAUX_SC_MIC + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("SC_MIC", scProgress + " " + Helpers.getSoundCountrolBitRepresentation(scProgress, 0)) .commit(); } }); } else { micGain.setMax(40); micGain.setProgress(20); micUnit.setText("Unsupported"); micGain.setEnabled(false); } // Camera Microphone Gain if (Helpers.doesFileExist(FAUX_SC_CAM_MIC)) { int camMicValue = Integer.valueOf(CPUHelper.readOneLine(FAUX_SC_CAM_MIC)); if (camMicValue > 100) camMicValue -= 256; camMicGain.setMax(40); camMicGain.setProgress(camMicValue + 30); camMicUnit.setText(camMicValue + ""); camMicGain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { camMicUnit.setText(i - 30 + ""); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(final SeekBar seekBar) { int scProgress = seekBar.getProgress() - 30; if (scProgress < 0) scProgress += 256; Helpers.CMDProcessorWrapper .runSuCommand("busybox echo 0 > " + FAUX_SC_LOCKED + "\n" + "busybox echo " + scProgress + " " + Helpers.getSoundCountrolBitRepresentation(scProgress, 0) + " > " + FAUX_SC_CAM_MIC + "\n" + "busybox echo 1 > " + FAUX_SC_LOCKED); bootPrefs.edit() .putString("SC_MIC", scProgress + " " + Helpers.getSoundCountrolBitRepresentation(scProgress, 0)) .commit(); } }); } else { camMicGain.setMax(40); camMicGain.setProgress(20); camMicUnit.setText("Unsupported"); camMicGain.setEnabled(false); } return ll; }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user adjust gain settings */// w w w . j a v a 2 s. c o m private void adjustGain() { if (source == null) return; int sourceType = Integer.valueOf(preferences.getString(getString(R.string.pref_sourceType), "1")); switch (sourceType) { case FILE_SOURCE: Toast.makeText(this, getString(R.string.filesource_doesnt_support_gain), Toast.LENGTH_LONG).show(); break; case HACKRF_SOURCE: // Prepare layout: final LinearLayout view_hackrf = (LinearLayout) this.getLayoutInflater().inflate(R.layout.hackrf_gain, null); final SeekBar sb_hackrf_vga = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_vga_gain); final SeekBar sb_hackrf_lna = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_lna_gain); final TextView tv_hackrf_vga = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_vga_gain); final TextView tv_hackrf_lna = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_lna_gain); sb_hackrf_vga.setMax(HackrfSource.MAX_VGA_RX_GAIN / HackrfSource.VGA_RX_GAIN_STEP_SIZE); sb_hackrf_lna.setMax(HackrfSource.MAX_LNA_GAIN / HackrfSource.LNA_GAIN_STEP_SIZE); sb_hackrf_vga.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_hackrf_vga.setText("" + progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE); ((HackrfSource) source).setVgaRxGain(progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_hackrf_lna.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_hackrf_lna.setText("" + progress * HackrfSource.LNA_GAIN_STEP_SIZE); ((HackrfSource) source).setLnaGain(progress * HackrfSource.LNA_GAIN_STEP_SIZE); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_hackrf_vga.setProgress(((HackrfSource) source).getVgaRxGain() / HackrfSource.VGA_RX_GAIN_STEP_SIZE); sb_hackrf_lna.setProgress(((HackrfSource) source).getLnaGain() / HackrfSource.LNA_GAIN_STEP_SIZE); // Show dialog: AlertDialog hackrfDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings") .setView(view_hackrf).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_hackrf_vgaRxGain), sb_hackrf_vga.getProgress() * HackrfSource.VGA_RX_GAIN_STEP_SIZE); edit.putInt(getString(R.string.pref_hackrf_lnaGain), sb_hackrf_lna.getProgress() * HackrfSource.LNA_GAIN_STEP_SIZE); edit.apply(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).create(); hackrfDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // sync source with (new/old) settings int vgaRxGain = preferences.getInt(getString(R.string.pref_hackrf_vgaRxGain), HackrfSource.MAX_VGA_RX_GAIN / 2); int lnaGain = preferences.getInt(getString(R.string.pref_hackrf_lnaGain), HackrfSource.MAX_LNA_GAIN / 2); if (((HackrfSource) source).getVgaRxGain() != vgaRxGain) ((HackrfSource) source).setVgaRxGain(vgaRxGain); if (((HackrfSource) source).getLnaGain() != lnaGain) ((HackrfSource) source).setLnaGain(lnaGain); } }); hackrfDialog.show(); hackrfDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); break; case RTLSDR_SOURCE: final int[] possibleGainValues = ((RtlsdrSource) source).getPossibleGainValues(); final int[] possibleIFGainValues = ((RtlsdrSource) source).getPossibleIFGainValues(); if (possibleGainValues.length <= 1 && possibleIFGainValues.length <= 1) { Toast.makeText(MainActivity.this, source.getName() + " does not support gain adjustment!", Toast.LENGTH_LONG).show(); } // Prepare layout: final LinearLayout view_rtlsdr = (LinearLayout) this.getLayoutInflater().inflate(R.layout.rtlsdr_gain, null); final LinearLayout ll_rtlsdr_gain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_gain); final LinearLayout ll_rtlsdr_ifgain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_ifgain); final Switch sw_rtlsdr_manual_gain = (Switch) view_rtlsdr.findViewById(R.id.sw_rtlsdr_manual_gain); final CheckBox cb_rtlsdr_agc = (CheckBox) view_rtlsdr.findViewById(R.id.cb_rtlsdr_agc); final SeekBar sb_rtlsdr_gain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_gain); final SeekBar sb_rtlsdr_ifGain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_ifgain); final TextView tv_rtlsdr_gain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_gain); final TextView tv_rtlsdr_ifGain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_ifgain); // Assign current gain: int gainIndex = 0; int ifGainIndex = 0; for (int i = 0; i < possibleGainValues.length; i++) { if (((RtlsdrSource) source).getGain() == possibleGainValues[i]) { gainIndex = i; break; } } for (int i = 0; i < possibleIFGainValues.length; i++) { if (((RtlsdrSource) source).getIFGain() == possibleIFGainValues[i]) { ifGainIndex = i; break; } } sb_rtlsdr_gain.setMax(possibleGainValues.length - 1); sb_rtlsdr_ifGain.setMax(possibleIFGainValues.length - 1); sb_rtlsdr_gain.setProgress(gainIndex); sb_rtlsdr_ifGain.setProgress(ifGainIndex); tv_rtlsdr_gain.setText("" + possibleGainValues[gainIndex]); tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[ifGainIndex]); // Assign current manual gain and agc setting sw_rtlsdr_manual_gain.setChecked(((RtlsdrSource) source).isManualGain()); cb_rtlsdr_agc.setChecked(((RtlsdrSource) source).isAutomaticGainControl()); // Add listener to gui elements: sw_rtlsdr_manual_gain.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sb_rtlsdr_gain.setEnabled(isChecked); tv_rtlsdr_gain.setEnabled(isChecked); sb_rtlsdr_ifGain.setEnabled(isChecked); tv_rtlsdr_ifGain.setEnabled(isChecked); ((RtlsdrSource) source).setManualGain(isChecked); if (isChecked) { ((RtlsdrSource) source).setGain(possibleGainValues[sb_rtlsdr_gain.getProgress()]); ((RtlsdrSource) source).setIFGain(possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]); } } }); cb_rtlsdr_agc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ((RtlsdrSource) source).setAutomaticGainControl(isChecked); } }); sb_rtlsdr_gain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_rtlsdr_gain.setText("" + possibleGainValues[progress]); ((RtlsdrSource) source).setGain(possibleGainValues[progress]); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_rtlsdr_ifGain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[progress]); ((RtlsdrSource) source).setIFGain(possibleIFGainValues[progress]); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Disable gui elements if gain cannot be adjusted: if (possibleGainValues.length <= 1) ll_rtlsdr_gain.setVisibility(View.GONE); if (possibleIFGainValues.length <= 1) ll_rtlsdr_ifgain.setVisibility(View.GONE); if (!sw_rtlsdr_manual_gain.isChecked()) { sb_rtlsdr_gain.setEnabled(false); tv_rtlsdr_gain.setEnabled(false); sb_rtlsdr_ifGain.setEnabled(false); tv_rtlsdr_ifGain.setEnabled(false); } // Show dialog: AlertDialog rtlsdrDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings") .setView(view_rtlsdr).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putBoolean(getString(R.string.pref_rtlsdr_manual_gain), sw_rtlsdr_manual_gain.isChecked()); edit.putBoolean(getString(R.string.pref_rtlsdr_agc), cb_rtlsdr_agc.isChecked()); edit.putInt(getString(R.string.pref_rtlsdr_gain), possibleGainValues[sb_rtlsdr_gain.getProgress()]); edit.putInt(getString(R.string.pref_rtlsdr_ifGain), possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]); edit.apply(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).create(); rtlsdrDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { boolean manualGain = preferences.getBoolean(getString(R.string.pref_rtlsdr_manual_gain), false); boolean agc = preferences.getBoolean(getString(R.string.pref_rtlsdr_agc), false); int gain = preferences.getInt(getString(R.string.pref_rtlsdr_gain), 0); int ifGain = preferences.getInt(getString(R.string.pref_rtlsdr_ifGain), 0); ((RtlsdrSource) source).setGain(gain); ((RtlsdrSource) source).setIFGain(ifGain); ((RtlsdrSource) source).setManualGain(manualGain); ((RtlsdrSource) source).setAutomaticGainControl(agc); if (manualGain) { // Note: This is a workaround. After setting manual gain to true we must // rewrite the manual gain values: ((RtlsdrSource) source).setGain(gain); ((RtlsdrSource) source).setIFGain(ifGain); } } }); rtlsdrDialog.show(); rtlsdrDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); break; default: Log.e(LOGTAG, "adjustGain: Invalid source type: " + sourceType); break; } }
From source file:edu.berkeley.boinc.PrefsActivity.java
public void onItemClick(View view) { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Object item = view.getTag();//ww w. j av a2 s . co m if (item instanceof PrefsListItemWrapperValue) { final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item; if (Logging.DEBUG) Log.d(Logging.TAG, "PrefsActivity onItemClick Value " + valueWrapper.ID); if (valueWrapper.isPct) { // show dialog with slider dialog.setContentView(R.layout.prefs_layout_dialog_pct); // setup slider TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(valueWrapper.status.intValue() + " " + getString(R.string.prefs_unit_pct)); Double seekBarDefault = valueWrapper.status / 10; SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); slider.setProgress(seekBarDefault.intValue()); slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { String progressString = (progress * 10) + " " + getString(R.string.prefs_unit_pct); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } else if (valueWrapper.isNumber) { if (!getHostInfo()) { if (Logging.WARNING) Log.w(Logging.TAG, "onItemClick missing hostInfo"); return; } // show dialog with slider dialog.setContentView(R.layout.prefs_layout_dialog_pct); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText("" + valueWrapper.status.intValue()); SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); // slider setup depending on actual preference if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) { slider.setMax(hostinfo.p_ncpus); slider.setProgress(valueWrapper.status.intValue()); slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (progress == 0) progress = 1; // do not allow 0 cpus String progressString = String.valueOf(progress); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) { slider.setMax(5); slider.setProgress(valueWrapper.status.intValue()); slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { String progressString = String.valueOf(progress); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } } else { // show dialog with edit text dialog.setContentView(R.layout.prefs_layout_dialog); } // show preference name ((TextView) dialog.findViewById(R.id.pref)).setText(valueWrapper.ID); // setup buttons Button confirm = (Button) dialog.findViewById(R.id.confirm); confirm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { double value = 0.0; Boolean clientPref = true; if (valueWrapper.isPct) { SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); value = slider.getProgress() * 10; } else if (valueWrapper.isNumber) { SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); int sbProgress = slider.getProgress(); if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) { if (sbProgress == 0) sbProgress = 1; value = numberCpuCoresToPct(sbProgress); } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) { appPrefs.setLogLevel(sbProgress); updateValuePref(valueWrapper.ID, (double) sbProgress); clientPref = false; // avoid writing client prefs via rpc updateLayout(); } } else { EditText edit = (EditText) dialog.findViewById(R.id.Input); String input = edit.getText().toString(); Double valueTmp = parseInputValueToDouble(input); if (valueTmp == null) return; value = valueTmp; } if (clientPref) writeClientValuePreference(valueWrapper.ID, value); dialog.dismiss(); } }); Button cancel = (Button) dialog.findViewById(R.id.cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } else { // instance of PrefsListItemWrapper, i.e. client log flags PrefsListItemWrapper wrapper = (PrefsListItemWrapper) item; if (Logging.DEBUG) Log.d(Logging.TAG, "PrefsActivity onItemClick super " + wrapper.ID); dialog.setContentView(R.layout.prefs_layout_dialog_selection); final ArrayList<ClientLogOption> options = new ArrayList<ClientLogOption>(); String[] array = getResources().getStringArray(R.array.prefs_client_log_flags); for (String option : array) options.add(new ClientLogOption(option)); ListView lv = (ListView) dialog.findViewById(R.id.selection); new PrefsLogOptionsListAdapter(this, lv, R.id.selection, options); // setup buttons Button confirm = (Button) dialog.findViewById(R.id.confirm); confirm.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ArrayList<String> selectedOptions = new ArrayList<String>(); for (ClientLogOption option : options) if (option.selected) selectedOptions.add(option.name); if (Logging.DEBUG) Log.d(Logging.TAG, selectedOptions.size() + " log flags selected"); new SetCcConfigAsync().execute(formatOptionsToCcConfig(selectedOptions)); dialog.dismiss(); } }); Button cancel = (Button) dialog.findViewById(R.id.cancel); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); dialog.show(); } }
From source file:edu.berkeley.boinc.PrefsFragment.java
private void setupSliderDialog(PrefsListItemWrapper item, final Dialog dialog) { final PrefsListItemWrapperValue valueWrapper = (PrefsListItemWrapperValue) item; dialog.setContentView(R.layout.prefs_layout_dialog_pct); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); SeekBar slider = (SeekBar) dialog.findViewById(R.id.seekbar); if (valueWrapper.ID == R.string.battery_charge_min_pct_header || valueWrapper.ID == R.string.prefs_disk_max_pct_header || valueWrapper.ID == R.string.prefs_cpu_time_max_header || valueWrapper.ID == R.string.prefs_cpu_other_load_suspension_header || valueWrapper.ID == R.string.prefs_memory_max_idle_header) { Double seekBarDefault = valueWrapper.status / 10; slider.setProgress(seekBarDefault.intValue()); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { final String progressString = NumberFormat.getPercentInstance().format(progress / 10.0); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); }//from w w w .ja va 2 s. c om @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, seekBarDefault.intValue(), false); } else if (valueWrapper.ID == R.string.prefs_cpu_number_cpus_header) { if (!getHostInfo()) { if (Logging.WARNING) Log.w(Logging.TAG, "onItemClick missing hostInfo"); return; } slider.setMax(hostinfo.p_ncpus <= 1 ? 0 : hostinfo.p_ncpus - 1); final int statusValue; slider.setProgress((statusValue = valueWrapper.status.intValue()) <= 0 ? 0 : statusValue - 1 > slider.getMax() ? slider.getMax() : statusValue - 1); Log.d(Logging.TAG, String.format("statusValue == %,d", statusValue)); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { final String progressString = NumberFormat.getIntegerInstance() .format(progress <= 0 ? 1 : progress + 1); // do not allow 0 cpus TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, statusValue - 1, false); } else if (valueWrapper.ID == R.string.prefs_gui_log_level_header) { slider.setMax(5); slider.setProgress(valueWrapper.status.intValue()); final SeekBar.OnSeekBarChangeListener onSeekBarChangeListener; slider.setOnSeekBarChangeListener(onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { String progressString = NumberFormat.getIntegerInstance().format(progress); TextView sliderProgress = (TextView) dialog.findViewById(R.id.seekbar_status); sliderProgress.setText(progressString); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); onSeekBarChangeListener.onProgressChanged(slider, valueWrapper.status.intValue(), false); } setupDialogButtons(item, dialog); }
From source file:jp.co.rediscovery.firstflight.BaseAutoPilotFragment.java
/** * ??// w ww . j av a 2 s . c om * @param root */ private void initConfigFlight(final View root) { mMaxAltitudeFormat = getString(R.string.config_max_altitude); mMaxTiltFormat = getString(R.string.config_max_tilt); mMaxVerticalSpeedFormat = getString(R.string.config_max_vertical_speed); mMaxRotationSpeedFormat = getString(R.string.config_max_rotating_speed); // mMaxAltitudeLabel = (TextView) root.findViewById(R.id.max_altitude_textview); SeekBar seekbar = (SeekBar) root.findViewById(R.id.max_altitude_seekbar); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mMaxAltitude = mFlightController.getMaxAltitude(); try { seekbar.setProgress((int) ((mMaxAltitude.current() - mMaxAltitude.min()) / (mMaxAltitude.max() - mMaxAltitude.min()) * 1000)); } catch (final Exception e) { seekbar.setProgress(0); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateMaxAltitude(mMaxAltitude.current()); // // bebop?5-3050km/hr???13.9m/s/300.46[m/s/] mMaxTiltLabel = (TextView) root.findViewById(R.id.max_tilt_textview); seekbar = (SeekBar) root.findViewById(R.id.max_tilt_seekbar); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mMaxTilt = mFlightController.getMaxTilt(); try { seekbar.setProgress( (int) ((mMaxTilt.current() - mMaxTilt.min()) / (mMaxTilt.max() - mMaxTilt.min()) * 1000)); } catch (final Exception e) { seekbar.setProgress(0); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateMaxTilt(mMaxTilt.current()); // /?, Bebop2?6m/s mMaxVerticalSpeedLabel = (TextView) root.findViewById(R.id.max_vertical_speed_textview); seekbar = (SeekBar) root.findViewById(R.id.max_vertical_speed_seekbar); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mMaxVerticalSpeed = mFlightController.getMaxVerticalSpeed(); try { seekbar.setProgress((int) ((mMaxVerticalSpeed.current() - mMaxVerticalSpeed.min()) / (mMaxVerticalSpeed.max() - mMaxVerticalSpeed.min()) * 1000)); } catch (final Exception e) { seekbar.setProgress(0); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateMaxVerticalSpeed(mMaxVerticalSpeed.current()); // mMaxRotationSpeedLabel = (TextView) root.findViewById(R.id.max_rotation_speed_textview); seekbar = (SeekBar) root.findViewById(R.id.max_rotation_speed_seekbar); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mMaxRotationSpeed = mFlightController.getMaxRotationSpeed(); try { seekbar.setProgress((int) ((mMaxRotationSpeed.current() - mMaxRotationSpeed.min()) / (mMaxRotationSpeed.max() - mMaxRotationSpeed.min()) * 1000)); } catch (final Exception e) { seekbar.setProgress(0); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateMaxRotationSpeed(mMaxRotationSpeed.current()); }
From source file:jp.co.rediscovery.firstflight.BaseAutoPilotFragment.java
/** * ???/*w w w . j a v a 2 s. c om*/ * @param root */ private void initConfigAutopilot(final View root) { mAutopilotScaleXFormat = getString(R.string.config_scale_x); mAutopilotScaleYFormat = getString(R.string.config_scale_y); mAutopilotScaleZFormat = getString(R.string.config_scale_z); mAutopilotScaleRFormat = getString(R.string.config_scale_r); mAutopilotMaxControlValueFormat = getString(R.string.config_control_max); // mAutopilotMaxControlValueLabel = (TextView) root.findViewById(R.id.max_control_value_textview); SeekBar seekbar = (SeekBar) root.findViewById(R.id.max_control_value_seekbar); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mMaxControlValue = mPref.getFloat(APP_CONFIG_KEY_MAX_CONTROL_VALUE, APP_CONFIG_DEFAULT_MAX_CONTROL_VALUE); try { seekbar.setProgress((int) (mMaxControlValue + APP_SCALE_OFFSET)); } catch (final Exception e) { seekbar.setProgress(APP_SCALE_OFFSET); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateAutopilotMaxControlValue(mMaxControlValue); // X mAutopilotScaleXLabel = (TextView) root.findViewById(R.id.scale_x_textview); seekbar = (SeekBar) root.findViewById(R.id.scale_seekbar_x); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mScaleX = mPref.getFloat(APP_CONFIG_KEY_SCALE_X, APP_CONFIG_DEFAULT_SCALE_X); try { seekbar.setProgress((int) (mScaleX * APP_SCALE_FACTOR + APP_SCALE_OFFSET)); } catch (final Exception e) { seekbar.setProgress(APP_SCALE_OFFSET); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateAutopilotScaleX(mScaleX); // Y mAutopilotScaleYLabel = (TextView) root.findViewById(R.id.scale_y_textview); seekbar = (SeekBar) root.findViewById(R.id.scale_seekbar_y); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mScaleY = mPref.getFloat(APP_CONFIG_KEY_SCALE_Y, APP_CONFIG_DEFAULT_SCALE_Y); try { seekbar.setProgress((int) (mScaleY * APP_SCALE_FACTOR + APP_SCALE_OFFSET)); } catch (final Exception e) { seekbar.setProgress(APP_SCALE_OFFSET); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateAutopilotScaleY(mScaleY); // Z mAutopilotScaleZLabel = (TextView) root.findViewById(R.id.scale_z_textview); seekbar = (SeekBar) root.findViewById(R.id.scale_seekbar_z); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mScaleZ = mPref.getFloat(APP_CONFIG_KEY_SCALE_Z, APP_CONFIG_DEFAULT_SCALE_Z); try { seekbar.setProgress((int) (mScaleZ * APP_SCALE_FACTOR + APP_SCALE_OFFSET)); } catch (final Exception e) { seekbar.setProgress(APP_SCALE_OFFSET); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateAutopilotScaleZ(mScaleZ); // R mAutopilotScaleRLabel = (TextView) root.findViewById(R.id.scale_r_textview); seekbar = (SeekBar) root.findViewById(R.id.scale_seekbar_r); seekbar.setOnSeekBarChangeListener(null); seekbar.setMax(1000); mScaleR = mPref.getFloat(APP_CONFIG_KEY_SCALE_R, APP_CONFIG_DEFAULT_SCALE_R); try { seekbar.setProgress((int) (mScaleR * APP_SCALE_FACTOR + APP_SCALE_OFFSET)); } catch (final Exception e) { seekbar.setProgress(APP_SCALE_OFFSET); } seekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateAutopilotScaleR(mScaleR); }