List of usage examples for android.widget Switch setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_tools_cpu_control)); setContentView(R.layout.card_cpu_control); bootPrefs = getSharedPreferences("BOOT_PREFS", 0); graph = (LineGraph) findViewById(R.id.graph); line = new Line(); LinePoint point = new LinePoint(); point.setX(currX);/* w ww.j a va2 s .c om*/ point.setY(1); line.addPoint(point); line.setColor(Color.parseColor("#FFBB33")); graph.addLine(line); graph.setLineToFill(0); availableFrequencies = new String[0]; String availableFrequenciesLine; mCoresOnline = (TextView) findViewById(R.id.cores_online); mGeneralGovernor = (Spinner) findViewById(R.id.general_governor); mGovernor = (Spinner) findViewById(R.id.governor); mGovernor2 = (Spinner) findViewById(R.id.governor2); mGovernor3 = (Spinner) findViewById(R.id.governor3); mGovernor4 = (Spinner) findViewById(R.id.governor4); Button customizeGov = (Button) findViewById(R.id.governor_customize_btn); customizeGov.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getSupportFragmentManager(); GovernorDialog editNameDialog = new GovernorDialog(); editNameDialog.show(fm, "governor_fragment"); } }); if (Helpers.doesFileExist(STEPS)) { availableFrequenciesLine = CPUHelper.readOneLineNotRoot(STEPS); if (availableFrequenciesLine != null) { availableFrequencies = availableFrequenciesLine.split(" "); Arrays.sort(availableFrequencies, new Comparator<String>() { @Override public int compare(String object1, String object2) { return Integer.valueOf(object1).compareTo(Integer.valueOf(object2)); } }); } } Switch snakeCharmer = (Switch) findViewById(R.id.snake_charmer_switch); if (!Helpers.doesFileExist(SNAKE_CHARMER_MAX_FREQ)) { LinearLayout cardSnakeCharmer = (LinearLayout) findViewById(R.id.card_snake_charmer); cardSnakeCharmer.setVisibility(View.GONE); } else { if (Helpers.doesFileExist(SNAKE_CHARMER_VERSION)) { TextView snakeTitle = (TextView) findViewById(R.id.snake_charmer); String snakeVersion = CPUHelper.readOneLineNotRoot(SNAKE_CHARMER_VERSION); snakeVersion = snakeVersion.replaceAll("version: ", "v"); snakeTitle.setText(snakeTitle.getText() + " " + snakeVersion); if (snakeVersion.equals("v1.2")) { TextView snakeDesc = (TextView) findViewById(R.id.snake_charmer_text); snakeDesc.setText(snakeDesc.getText() + "\n" + getString(R.string.snake_charmer_built_in)); snakeCharmer.setEnabled(false); } } if (bootPrefs.getBoolean("SNAKE_CHARMER", true)) { snakeCharmer.setChecked(true); snakeCharmerEnabled = true; } snakeCharmer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isOn) { snakeCharmerEnabled = isOn; } }); } int frequenciesNum = availableFrequencies.length - 1; Switch thermalControl = (Switch) findViewById(R.id.msm_thermal_switch); if (Helpers.doesFileExist(MSM_THERMAL)) { String thermal = CPUHelper.readOneLineNotRoot(MSM_THERMAL); if (thermal.equals("Y")) thermalControl.setChecked(true); else thermalControl.setChecked(false); thermalControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) Helpers.CMDProcessorWrapper.runSuCommand("echo Y > " + MSM_THERMAL); else Helpers.CMDProcessorWrapper.runSuCommand("echo N > " + MSM_THERMAL); bootPrefs.edit().putBoolean("MSM_THERMAL", isChecked).commit(); } }); } thermalControl.setChecked(bootPrefs.getBoolean("MSM_THERMAL", true)); perCoreGovernor = (Switch) findViewById(R.id.per_core_governors_switch); perCoreGovernor.setChecked(bootPrefs.getBoolean("PER_CORE_GOV", true)); if (perCoreGovernor.isChecked()) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); } perCoreGovernor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); handleGovernors(); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); handleGovernors(); } bootPrefs.edit().putBoolean("PER_CORE_GOV", isChecked).commit(); } }); String currentIo = ""; if (Helpers.doesFileExist(IO_SCHEDULER)) currentIo = CPUHelper.getIOScheduler(); String currentTcp = ""; if (Helpers.doesFileExist(CURR_TCP_ALGORITHM)) currentTcp = Helpers.getCurrentTcpAlgorithm(); String curMaxSpeed = "NaN"; if (Helpers.doesFileExist(MAX_FREQ_ALL_CORES)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MAX_FREQ)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ); String curMinSpeed = "NaN"; if (Helpers.doesFileExist(MIN_FREQ_ALL_CORES)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MIN_FREQ)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ); if (mIsTegra3) { String curTegraMaxSpeed = "NaN"; if (Helpers.doesFileExist(TEGRA_MAX_FREQ)) { curTegraMaxSpeed = CPUHelper.readOneLineNotRoot(TEGRA_MAX_FREQ); int curTegraMax = 0; try { curTegraMax = Integer.parseInt(curTegraMaxSpeed); if (curTegraMax > 0) { curMaxSpeed = Integer.toString(curTegraMax); } } catch (NumberFormatException ex) { curTegraMax = 0; } } } if (Helpers.doesFileExist(NUM_OF_CPUS)) mNumOfCpus = Helpers.getNumOfCpus(); mCurFreq = (TextView) findViewById(R.id.currspeed); mMaxSlider = (SeekBar) findViewById(R.id.max_slider); mMaxSlider.setMax(frequenciesNum); mMaxSpeedText = (TextView) findViewById(R.id.max_speed_text); mMaxSpeedText.setText(toMHz(curMaxSpeed)); mMaxSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMaxSpeed)); mMaxSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMaxSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MAX_FREQ", mMaxFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMaxFreqSetting + " > " + MAX_FREQ.replace("cpu0", "cpu" + i)); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } if (mIsTegra3) { if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + TEGRA_MAX_FREQ); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); mMinSlider = (SeekBar) findViewById(R.id.min_slider); mMinSlider.setMax(frequenciesNum); mMinSpeedText = (TextView) findViewById(R.id.min_speed_text); mMinSpeedText.setText(toMHz(curMinSpeed)); mMinSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMinSpeed)); mMinSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMinSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMinFreqSetting != null && !mMinFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MIN_FREQ", mMinFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMinFreqSetting + " > " + MIN_FREQ.replace("cpu0", "cpu" + i)); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); handleGovernors(); /** TCP Congestion Spinner */ Spinner mTcp = (Spinner) findViewById(R.id.tcp); ArrayAdapter<CharSequence> tcpAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); tcpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayList<String> algorithms = Helpers.getTcpAlgorithms(); for (String algorithm : algorithms) tcpAdapter.add(algorithm); mTcp.setAdapter(tcpAdapter); mTcp.setSelection(algorithms.indexOf(currentTcp)); mTcp.setOnItemSelectedListener(new TCPListener()); onlineCoresPolling(); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
public void TimeLapseDialog() { if (isRecording) return;//from w ww . j av a 2s. c om SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext()); interval = Integer.valueOf(prefs.getString("timelapseInterval", "0")); measurementVal = Integer.valueOf(prefs.getString("timelapseMeasurementVal", "0")); // show time lapse settings timeLapseDialog = new TimeLapseDialog(ApplicationScreen.instance); timeLapseDialog.setContentView(R.layout.plugin_capture_video_timelapse_dialog); final NumberPicker np = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker1); np.setMaxValue(16); np.setMinValue(0); np.setValue(interval); np.setDisplayedValues(stringInterval); np.setWrapSelectorWheel(false); np.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final NumberPicker np2 = (NumberPicker) timeLapseDialog.findViewById(R.id.numberPicker2); np2.setMaxValue(2); np2.setMinValue(0); np2.setValue(measurementVal); np2.setWrapSelectorWheel(false); np2.setDisplayedValues(stringMeasurement); np2.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); final Switch sw = (Switch) timeLapseDialog.findViewById(R.id.timelapse_switcher); // disable/enable controls in dialog sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!sw.isChecked()) { swChecked = false; } else { swChecked = true; } } }); np2.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); np.setOnScrollListener(new NumberPicker.OnScrollListener() { @Override public void onScrollStateChange(NumberPicker numberPicker, int scrollState) { sw.setChecked(true); } }); // disable control in dialog by default if (!swChecked) { sw.setChecked(false); } else { sw.setChecked(true); } timeLapseDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (swChecked) { measurementVal = np2.getValue(); interval = np.getValue(); SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(ApplicationScreen.getMainContext()); Editor editor = prefs.edit(); editor.putString("timelapseMeasurementVal", String.valueOf(measurementVal)); editor.putString("timelapseInterval", String.valueOf(interval)); editor.commit(); timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_active)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } else { timeLapseButton.setImageDrawable(ApplicationScreen.getAppResources() .getDrawable(R.drawable.plugin_capture_video_timelapse_inactive)); ApplicationScreen.getGUIManager().setShutterIcon(ShutterButton.RECORDER_START); } } }); timeLapseDialog.show(); }
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.UtilityOnClickListeners.java
@Override public OnClickListener getSubscriptionCheckBoxOnClickListener(final PropertyDescription subscription, final Subscription activeSubscription, final User user) { return new OnClickListener() { @Override/*from www . ja v a 2s. com*/ public void onClick(final View v) { UtilityRowsInterface utilityRowsInterface = new UtilityRows(); final FiskInfoUtility fiskInfoUtility = new FiskInfoUtility(); final Dialog dialog; int iconId = fiskInfoUtility.subscriptionApiNameToIconId(subscription.ApiName); if (iconId != -1) { dialog = new UtilityDialogs().getDialogWithTitleIcon(v.getContext(), R.layout.dialog_manage_subscription, subscription.Name, iconId); } else { dialog = new UtilityDialogs().getDialog(v.getContext(), R.layout.dialog_manage_subscription, subscription.Name); } final Switch subscribedSwitch = (Switch) dialog.findViewById(R.id.manage_subscription_switch); final LinearLayout formatsContainer = (LinearLayout) dialog .findViewById(R.id.manage_subscription_formats_container); final LinearLayout intervalsContainer = (LinearLayout) dialog .findViewById(R.id.manage_subscription_intervals_container); final EditText subscriptionEmailEditText = (EditText) dialog .findViewById(R.id.manage_subscription_email_edit_text); final Button subscribeButton = (Button) dialog.findViewById(R.id.manage_subscription_update_button); Button cancelButton = (Button) dialog.findViewById(R.id.manage_subscription_cancel_button); final boolean isSubscribed = activeSubscription != null; final Map<String, String> subscriptionFrequencies = new HashMap<>(); dialog.setTitle(subscription.Name); if (isSubscribed) { subscriptionEmailEditText.setText(activeSubscription.SubscriptionEmail); subscribedSwitch.setVisibility(View.VISIBLE); subscribedSwitch.setChecked(true); subscribedSwitch .setText(v.getResources().getString(R.string.manage_subscription_subscription_active)); subscribedSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { System.out.println("This is checked:" + isChecked); String switchText = isChecked ? v.getResources().getString(R.string.manage_subscription_subscription_active) : v.getResources() .getString(R.string.manage_subscription_subscription_cancellation); subscribedSwitch.setText(switchText); } }); } else { subscriptionEmailEditText.setText(user.getUsername()); } for (String format : subscription.Formats) { final RadioButtonRow row = utilityRowsInterface.getRadioButtonRow(v.getContext(), format); if (isSubscribed && activeSubscription.FileFormatType.equals(format)) { row.setSelected(true); } formatsContainer.addView(row.getView()); } for (String interval : subscription.SubscriptionInterval) { final RadioButtonRow row = utilityRowsInterface.getRadioButtonRow(v.getContext(), SubscriptionInterval.getType(interval).toString()); if (activeSubscription != null) { row.setSelected(activeSubscription.SubscriptionIntervalName.equals(interval)); } subscriptionFrequencies.put(SubscriptionInterval.getType(interval).toString(), interval); intervalsContainer.addView(row.getView()); } if (intervalsContainer.getChildCount() == 1) { ((RadioButton) intervalsContainer.getChildAt(0) .findViewById(R.id.radio_button_row_radio_button)).setChecked(true); } subscribeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View subscribeButton) { String subscriptionFormat = null; String subscriptionInterval = null; String subscriptionEmail; BarentswatchApi barentswatchApi = new BarentswatchApi(); barentswatchApi.setAccesToken(user.getToken()); final IBarentswatchApi api = barentswatchApi.getApi(); for (int i = 0; i < formatsContainer.getChildCount(); i++) { if (((RadioButton) formatsContainer.getChildAt(i) .findViewById(R.id.radio_button_row_radio_button)).isChecked()) { subscriptionFormat = ((TextView) formatsContainer.getChildAt(i) .findViewById(R.id.radio_button_row_text_view)).getText().toString(); break; } } if (subscriptionFormat == null) { Toast.makeText(v.getContext(), v.getContext().getString(R.string.choose_subscription_format), Toast.LENGTH_LONG).show(); return; } for (int i = 0; i < intervalsContainer.getChildCount(); i++) { if (((RadioButton) intervalsContainer.getChildAt(i) .findViewById(R.id.radio_button_row_radio_button)).isChecked()) { subscriptionInterval = ((TextView) intervalsContainer.getChildAt(i) .findViewById(R.id.radio_button_row_text_view)).getText().toString(); break; } } if (subscriptionInterval == null) { Toast.makeText(v.getContext(), v.getContext().getString(R.string.choose_subscription_interval), Toast.LENGTH_LONG).show(); return; } subscriptionEmail = subscriptionEmailEditText.getText().toString(); if (!(new FiskInfoUtility().isEmailValid(subscriptionEmail))) { Toast.makeText(v.getContext(), v.getContext().getString(R.string.error_invalid_email), Toast.LENGTH_LONG).show(); return; } if (isSubscribed) { if (subscribedSwitch.isChecked()) { if (!(subscriptionFormat.equals(activeSubscription.FileFormatType) && activeSubscription.SubscriptionIntervalName .equals(subscriptionFrequencies.get(subscriptionInterval)) && user.getUsername().equals(subscriptionEmail))) { SubscriptionSubmitObject updatedSubscription = new SubscriptionSubmitObject( subscription.ApiName, subscriptionFormat, user.getUsername(), user.getUsername(), subscriptionFrequencies.get(subscriptionInterval)); Subscription newSubscriptionObject = api.updateSubscription( String.valueOf(activeSubscription.Id), updatedSubscription); if (newSubscriptionObject != null) { ((CheckBox) v).setChecked(true); } } } else { Response response = api.deleteSubscription(String.valueOf(activeSubscription.Id)); if (response.getStatus() == 204) { ((CheckBox) v).setChecked(false); Toast.makeText(v.getContext(), R.string.subscription_update_successful, Toast.LENGTH_LONG).show(); } else { Toast.makeText(v.getContext(), R.string.subscription_update_failed, Toast.LENGTH_LONG).show(); } } } else { SubscriptionSubmitObject newSubscription = new SubscriptionSubmitObject( subscription.ApiName, subscriptionFormat, user.getUsername(), user.getUsername(), subscriptionFrequencies.get(subscriptionInterval)); Subscription response = api.setSubscription(newSubscription); if (response != null) { ((CheckBox) v).setChecked(true); // TODO: add to "Mine abonnementer" Toast.makeText(v.getContext(), R.string.subscription_update_successful, Toast.LENGTH_LONG).show(); } else { Toast.makeText(v.getContext(), R.string.subscription_update_failed, Toast.LENGTH_LONG).show(); } } dialog.dismiss(); } }); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View cancelButton) { ((CheckBox) v).setChecked(isSubscribed); dialog.dismiss(); } }); dialog.show(); } }; }
From source file:jp.co.rediscovery.firstflight.BaseAutoPilotFragment.java
private void initColorExtraction(final View rootView) { Switch sw; Button btn;/*ww w . j av a 2 s. co m*/ mExtractRangeHFormat = getString(R.string.trace_config_extract_range_h); mExtractRangeSFormat = getString(R.string.trace_config_extract_range_s); mExtractRangeVFormat = getString(R.string.trace_config_extract_range_v); // OpenGL|ES?????? mEnableGLESExtraction = mPref.getBoolean(KEY_ENABLE_EXTRACTION, DEFAULT_ENABLE_EXTRACTION); sw = (Switch) rootView.findViewById(R.id.use_extract_sw); sw.setChecked(mEnableGLESExtraction); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // ? btn = (Button) rootView.findViewById(R.id.update_extraction_color_btn); btn.setOnClickListener(mOnClickListener); // btn = (Button) rootView.findViewById(R.id.reset_extraction_color_btn); btn.setOnClickListener(mOnClickListener); // mExtractH = mPref.getFloat(KEY_EXTRACT_H, DEFAULT_EXTRACT_H); mExtractRangeH = mPref.getFloat(KEY_EXTRACT_RANGE_H, DEFAULT_EXTRACT_RANGE_H); mExtractS = mPref.getFloat(KEY_EXTRACT_S, DEFAULT_EXTRACT_S); mExtractRangeS = mPref.getFloat(KEY_EXTRACT_RANGE_S, DEFAULT_EXTRACT_RANGE_S); mExtractV = mPref.getFloat(KEY_EXTRACT_V, DEFAULT_EXTRACT_V); mExtractRangeV = mPref.getFloat(KEY_EXTRACT_RANGE_V, DEFAULT_EXTRACT_RANGE_V); mExtractRangeHLabel = (TextView) rootView.findViewById(R.id.extract_range_h_textview); mExtractRangeHSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_h_seekbar); mExtractRangeHSeekbar.setMax(100); mExtractRangeHSeekbar.setProgress((int) (mExtractRangeH * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeHSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeH(mExtractRangeH); mExtractRangeSLabel = (TextView) rootView.findViewById(R.id.extract_range_s_textview); mExtractRangeSSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_s_seekbar); mExtractRangeSSeekbar.setMax(100); mExtractRangeSSeekbar.setProgress((int) (mExtractRangeS * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeSSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeS(mExtractRangeS); mExtractRangeVLabel = (TextView) rootView.findViewById(R.id.extract_range_v_textview); mExtractRangeVSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_v_seekbar); mExtractRangeVSeekbar.setMax(100); mExtractRangeVSeekbar.setProgress((int) (mExtractRangeV * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeVSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeV(mExtractRangeV); }
From source file:de.baumann.browser.Browser_right.java
@SuppressLint("SetJavaScriptEnabled") @Override// w w w .j a v a2 s.c o m public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_search) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_right.this, editText, 3, "", getString(R.string.app_search_hint)); } if (id == R.id.action_history) { helper_main.switchToActivity(Browser_right.this, Popup_history.class, "", false); } if (id == R.id.action_search_chooseWebsite) { helper_editText.editText_searchWeb(editText, Browser_right.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser_right.this, Popup_pass.class, "", false); sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply(); } if (id == R.id.action_toggle) { sharedPref.edit().putString("started", "yes").apply(); if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(mWebView.getUrl()).getHost(); } final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser_right.this); View dialogView = View.inflate(Browser_right.this, R.layout.dialog_toggle, null); Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1); Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2); Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3); Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4); final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js); if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.check_green); } else { whiteList_js.setImageResource(R.drawable.close_red); } if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) { sw_java.setChecked(true); } else { sw_java.setChecked(false); } if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) { sw_pictures.setChecked(true); } else { sw_pictures.setChecked(false); } if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) { sw_location.setChecked(true); } else { sw_location.setChecked(false); } if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) { sw_cookies.setChecked(true); } else { sw_cookies.setChecked(false); } whiteList_js.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.close_red); String removed = whiteList.replaceAll(domain, ""); sharedPref.edit().putString("whiteList", removed).apply(); } else { whiteList_js.setImageResource(R.drawable.check_green); sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply(); } } }); sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setJavaScriptEnabled(true); } else { sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setJavaScriptEnabled(false); } } }); sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(true); } else { sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(false); } } }); sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(Browser_right.this); } else { sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setGeolocationEnabled(false); } } }); sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); } else { sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); } } }); builder.setView(dialogView); builder.setTitle(R.string.menu_toggle_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mWebView.reload(); } }); builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("lastActivity", "browser_right").apply(); helper_main.switchToActivity(Browser_right.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.menu_save_screenshot) { screenshot(); } if (id == R.id.menu_save_bookmark) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.editText_saveBookmark(editText, Browser_right.this, mWebView); } if (id == R.id.menu_save_readLater) { DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (id == R.id.menu_save_pass) { helper_editText.editText_savePass(Browser_right.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (id == R.id.menu_createShortcut) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser_right.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(mWebView.getUrl())); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(Browser_right.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser_right.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.menu_share_screenshot) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } if (id == R.id.menu_share_link) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (id == R.id.menu_share_link_copy) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser_right.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.action_downloads) { helper_main.switchToActivity(Browser_right.this, Popup_files.class, "", false); } if (id == R.id.action_search_go) { String text = editText.getText().toString(); helper_webView.openURL(Browser_right.this, mWebView, editText); helper_editText.hideKeyboard(Browser_right.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } if (id == R.id.action_search_onSite) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_right.this, editText, 1, "", getString(R.string.app_search_hint)); helper_editText.editText_FocusChange_searchSite(editText, Browser_right.this); helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar); } if (id == R.id.action_search_onSite_go) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser_right.this, editText, 1, getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site)); } } if (id == R.id.action_prev) { mWebView.findNext(false); } if (id == R.id.action_next) { mWebView.findNext(true); } if (id == R.id.action_cancel) { urlBar.setVisibility(View.VISIBLE); urlBar.setText(mWebView.getTitle()); editText.setVisibility(View.GONE); helper_editText.editText_FocusChange(editText, Browser_right.this); helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar); helper_editText.hideKeyboard(Browser_right.this, editText, 0, mWebView.getTitle(), getString(R.string.app_search_hint)); } if (id == R.id.action_save_bookmark) { helper_editText.editText_saveBookmark_save(editText, Browser_right.this, mWebView); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } return super.onOptionsItemSelected(item); }
From source file:de.baumann.browser.Browser_left.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from ww w . j a va 2 s . c o m*/ public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_search) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_left.this, editText, 3, "", getString(R.string.app_search_hint)); } if (id == R.id.action_history) { helper_main.switchToActivity(Browser_left.this, Popup_history.class, "", false); } if (id == R.id.action_search_chooseWebsite) { helper_editText.editText_searchWeb(editText, Browser_left.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser_left.this, Popup_pass.class, "", false); sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply(); } if (id == R.id.action_toggle) { sharedPref.edit().putString("started", "yes").apply(); if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(mWebView.getUrl()).getHost(); } final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser_left.this); View dialogView = View.inflate(Browser_left.this, R.layout.dialog_toggle, null); Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1); Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2); Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3); Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4); final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js); if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.check_green); } else { whiteList_js.setImageResource(R.drawable.close_red); } if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) { sw_java.setChecked(true); } else { sw_java.setChecked(false); } if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) { sw_pictures.setChecked(true); } else { sw_pictures.setChecked(false); } if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) { sw_location.setChecked(true); } else { sw_location.setChecked(false); } if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) { sw_cookies.setChecked(true); } else { sw_cookies.setChecked(false); } whiteList_js.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.close_red); String removed = whiteList.replaceAll(domain, ""); sharedPref.edit().putString("whiteList", removed).apply(); } else { whiteList_js.setImageResource(R.drawable.check_green); sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply(); } } }); sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setJavaScriptEnabled(true); } else { sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setJavaScriptEnabled(false); } } }); sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(true); } else { sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(false); } } }); sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(Browser_left.this); } else { sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setGeolocationEnabled(false); } } }); sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); } else { sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); } } }); builder.setView(dialogView); builder.setTitle(R.string.menu_toggle_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mWebView.reload(); } }); builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("lastActivity", "browser_left").apply(); helper_main.switchToActivity(Browser_left.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.menu_save_screenshot) { screenshot(); } if (id == R.id.menu_save_bookmark) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.editText_saveBookmark(editText, Browser_left.this, mWebView); } if (id == R.id.menu_save_readLater) { DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (id == R.id.menu_save_pass) { helper_editText.editText_savePass(Browser_left.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (id == R.id.menu_createShortcut) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser_left.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(mWebView.getUrl())); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(Browser_left.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser_left.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.menu_share_screenshot) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } if (id == R.id.menu_share_link) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (id == R.id.menu_share_link_copy) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser_left.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.action_downloads) { helper_main.switchToActivity(Browser_left.this, Popup_files.class, "", false); } if (id == R.id.action_search_go) { String text = editText.getText().toString(); helper_webView.openURL(Browser_left.this, mWebView, editText); helper_editText.hideKeyboard(Browser_left.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } if (id == R.id.action_search_onSite) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_left.this, editText, 1, "", getString(R.string.app_search_hint)); helper_editText.editText_FocusChange_searchSite(editText, Browser_left.this); helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar); } if (id == R.id.action_search_onSite_go) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser_left.this, editText, 1, getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site)); } } if (id == R.id.action_prev) { mWebView.findNext(false); } if (id == R.id.action_next) { mWebView.findNext(true); } if (id == R.id.action_cancel) { urlBar.setVisibility(View.VISIBLE); urlBar.setText(mWebView.getTitle()); editText.setVisibility(View.GONE); helper_editText.editText_FocusChange(editText, Browser_left.this); helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar); helper_editText.hideKeyboard(Browser_left.this, editText, 0, mWebView.getTitle(), getString(R.string.app_search_hint)); } if (id == R.id.action_save_bookmark) { helper_editText.editText_saveBookmark_save(editText, Browser_left.this, mWebView); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } return super.onOptionsItemSelected(item); }
From source file:com.example.android.lightcontrol.MainActivity.java
private void setupChat() { Log.d(TAG, "setupChat()"); seekBar = (SeekBar) findViewById(R.id.seekBar1); seekBar.setMax(Max_Value);//ww w.ja v a2 s . c o m textView_progress = (TextView) findViewById(R.id.textView1); textView_progress.setText(seekBar.getProgress() + "%"); seekBar.setProgress(0); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) { // progress = progresValue; } textView_progress.setText(String.valueOf(progress1) + "%"); if (seekBar.getProgress() == Min_Value) { progress1 = Min_Value; progrss_change_1(); } else if (progress1 <= Max_Value) { progress1 = seekBar.getProgress(); progrss_change_1(); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { textView_progress.setText(String.valueOf(progress1) + "%"); } @Override public void onStopTrackingTouch(SeekBar seekBar) { textView_progress.setText(String.valueOf(progress1) + "%"); } }); mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message); ListView mConversationViewnew = (ListView) findViewById(R.id.Query_log); mConversationViewnew.setAdapter(mConversationArrayAdapter); Button light_off = (Button) findViewById(R.id.light_off); Button light_on = (Button) findViewById(R.id.light_on); // Button light_query = (Button) findViewById(R.id.light_query); Button send_free = (Button) findViewById(R.id.sendfreetyping); final EditText free_typing = (EditText) findViewById(R.id.freetyping); Switch ON_OFF = (Switch) findViewById(R.id.switch1); ON_OFF.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if (isChecked) { light_on(); } else { light_off(); } } }); send_free.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) { Toast.makeText(MainActivity.this, R.string.not_connected, Toast.LENGTH_SHORT).show(); return; } mConversationArrayAdapter.clear(); String free = free_typing.getText().toString(); sendMessage(free); try { Thread.sleep(300); } catch (InterruptedException ignored) { } //freetyping.setText(""); } }); light_on.setOnClickListener(new OnClickListener() { public void onClick(View v) { light_on(); } }); light_off.setOnClickListener(new OnClickListener() { public void onClick(View v) { light_off(); } }); /* light_query.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) { Toast.makeText(MainActivity.this, R.string.not_connected, Toast.LENGTH_SHORT).show(); return; } //new Query_Short().execute(); new query_is_zigbee_exist_or_not_Async().execute(); } });*/ }
From source file:tv.piratemedia.flightcontroller.BluetoothControlFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { timeoutHandler = new Handler(); throttle = (VerticalSeekBar) view.findViewById(R.id.throttle); final ColorPicker ledColor = (ColorPicker) view.findViewById(R.id.ledColor); final Switch ledOn = (Switch) view.findViewById(R.id.ledSwitch); throttle.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override/* w w w . j av a 2 s . c o m*/ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { ThrottleCache = progress; if (!blocking) { JSONObject msg = new JSONObject(); try { msg.put("action", "throttle"); msg.put("value", progress); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); timeoutHandler.postDelayed(new Runnable() { @Override public void run() { blocking = false; JSONObject msg = new JSONObject(); try { msg.put("action", "throttle"); msg.put("value", ThrottleCache); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); } }, 150); blocking = true; } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { JSONObject msg = new JSONObject(); try { msg.put("action", "throttle"); msg.put("value", seekBar.getProgress()); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); } }); ledColor.setShowOldCenterColor(false); ledColor.setOnColorChangedListener(new ColorPicker.OnColorChangedListener() { @Override public void onColorChanged(int i) { if (!blocking) { JSONObject msg = new JSONObject(); try { msg.put("action", "led"); msg.put("color", i); msg.put("on", ledOn.isChecked()); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); timeoutHandler.postDelayed(new Runnable() { @Override public void run() { blocking = false; } }, 150); blocking = true; } } }); ledOn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { JSONObject msg = new JSONObject(); try { msg.put("action", "led"); msg.put("color", ledColor.getColor()); msg.put("on", isChecked); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); } }); longitude = (TextView) view.findViewById(R.id.longitude); latitude = (TextView) view.findViewById(R.id.latitude); altitude = (TextView) view.findViewById(R.id.altitude); pitchCorrection = (TextView) view.findViewById(R.id.picth_correction); rollCorrection = (TextView) view.findViewById(R.id.roll_correction); LeftStick = (JoystickView) view.findViewById(R.id.left_stick); RightStick = (JoystickView) view.findViewById(R.id.right_stick); LeftStick.setOnJoystickMoveListener(new JoystickView.OnJoystickMoveListener() { @Override public void onValueChanged(int angle, int power, int direction) { JSONObject msg = new JSONObject(); try { msg.put("action", "movement"); msg.put("pitch", 0); msg.put("roll", 0); } catch (JSONException e) { e.printStackTrace(); } if (power == 0) { sendMessage(msg.toString()); } else { if (angle > -10 && angle < 10) { //just pitch forwards try { msg.put("pitch", Math.round((double) power / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } } else if (angle < -170 || angle > 170) { //just pitch backwards try { msg.put("pitch", -Math.round((double) power / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } } else if (angle < -80 && angle > -100) { //just roll Left try { msg.put("roll", -Math.round((double) power / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } } else if (angle > 80 && angle < 100) { //just roll right try { msg.put("roll", Math.round((double) power / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } } else { // combination int pitch = 0; int roll = 0; if (angle > 0 && angle < 90) { //forwards and right roll = Math.round(power * (float) angle / 90.0f); pitch = Math.round(power - roll); } else if (angle > 90 && angle < 180) { angle = angle - 90; //backwards and right pitch = Math.round(power * (float) angle / 90.0f); roll = Math.round(power - pitch); pitch = -pitch; } else if (angle < 0 && angle > -90) { angle = -angle; //forwards and left roll = Math.round(power * (float) angle / 90.0f); pitch = Math.round(power - roll); roll = -roll; } else { angle = (-angle) - 90; // backwards and right pitch = Math.round(power * (float) angle / 90.0f); roll = -Math.round(power - pitch); pitch = -pitch; } try { msg.put("pitch", Math.round((double) pitch / SpeedDivider)); msg.put("roll", Math.round((double) roll / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } } sendMessage(msg.toString()); } } }, 150); RightStick.setOnJoystickMoveListener(new JoystickView.OnJoystickMoveListener() { @Override public void onValueChanged(int angle, int power, int direction) { JSONObject msg = new JSONObject(); try { msg.put("action", "movement"); msg.put("yaw", 0); } catch (JSONException e) { e.printStackTrace(); } int yaw = 0; int pitch = 0; if (angle > 0 && angle < 90) { //forwards and right yaw = Math.round(power * (float) angle / 90.0f); pitch = Math.round(power - yaw); } else if (angle > 90 && angle < 180) { angle = angle - 90; //backwards and right pitch = Math.round(power * (float) angle / 90.0f); yaw = Math.round(power - pitch); pitch = -pitch; } else if (angle < 0 && angle > -90) { angle = -angle; //forwards and left yaw = Math.round(power * (float) angle / 90.0f); pitch = Math.round(power - yaw); yaw = -yaw; } else { angle = (-angle) - 90; // backwards and right pitch = Math.round(power * (float) angle / 90.0f); yaw = -Math.round(power - pitch); pitch = -pitch; } try { msg.put("yaw", Math.round((double) yaw / SpeedDivider)); } catch (JSONException e) { e.printStackTrace(); } sendMessage(msg.toString()); } }, 150); }
From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
private void initColorExtraction(final View rootView) { Switch sw; Button btn;/*from w ww . j a v a2 s . c o m*/ mExtractRangeHFormat = getString(R.string.trace_config_extract_range_h); mExtractRangeSFormat = getString(R.string.trace_config_extract_range_s); mExtractRangeVFormat = getString(R.string.trace_config_extract_range_v); // OpenGL|ES?????? mEnableGLESExtraction = mPref.getBoolean(KEY_ENABLE_EXTRACTION, DEFAULT_ENABLE_EXTRACTION); sw = (Switch) rootView.findViewById(R.id.use_extract_sw); sw.setChecked(mEnableGLESExtraction); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // // Native??????? // mEnableNativeExtraction = mPref.getBoolean(KEY_ENABLE_NATIVE_EXTRACTION, false); // sw = (Switch)rootView.findViewById(R.id.use_native_extract_sw); // sw.setChecked(mEnableNativeExtraction); // sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // ? btn = (Button) rootView.findViewById(R.id.update_extraction_color_btn); btn.setOnClickListener(mOnClickListener); // ? btn = (Button) rootView.findViewById(R.id.select_extraction_color_btn); btn.setOnClickListener(mOnClickListener); // btn = (Button) rootView.findViewById(R.id.reset_extraction_color_btn); btn.setOnClickListener(mOnClickListener); // mExtractH = mPref.getFloat(KEY_EXTRACT_H, DEFAULT_EXTRACT_H); mExtractRangeH = mPref.getFloat(KEY_EXTRACT_RANGE_H, DEFAULT_EXTRACT_RANGE_H); mExtractS = mPref.getFloat(KEY_EXTRACT_S, DEFAULT_EXTRACT_S); mExtractRangeS = mPref.getFloat(KEY_EXTRACT_RANGE_S, DEFAULT_EXTRACT_RANGE_S); mExtractV = mPref.getFloat(KEY_EXTRACT_V, DEFAULT_EXTRACT_V); mExtractRangeV = mPref.getFloat(KEY_EXTRACT_RANGE_V, DEFAULT_EXTRACT_RANGE_V); mExtractRangeHLabel = (TextView) rootView.findViewById(R.id.extract_range_h_textview); mExtractRangeHSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_h_seekbar); mExtractRangeHSeekbar.setMax(100); mExtractRangeHSeekbar.setProgress((int) (mExtractRangeH * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeHSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeH(mExtractRangeH); mExtractRangeSLabel = (TextView) rootView.findViewById(R.id.extract_range_s_textview); mExtractRangeSSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_s_seekbar); mExtractRangeSSeekbar.setMax(100); mExtractRangeSSeekbar.setProgress((int) (mExtractRangeS * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeSSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeS(mExtractRangeS); mExtractRangeVLabel = (TextView) rootView.findViewById(R.id.extract_range_v_textview); mExtractRangeVSeekbar = (SeekBar) rootView.findViewById(R.id.extract_range_v_seekbar); mExtractRangeVSeekbar.setMax(100); mExtractRangeVSeekbar.setProgress((int) (mExtractRangeV * 100)); // [0.0f, 1.0f] => [0.0f, 100f] mExtractRangeVSeekbar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateExtractRangeV(mExtractRangeV); }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user adjust gain settings *//*from w ww . j a va2 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; } }