List of usage examples for android.widget Switch setChecked
@Override public void setChecked(boolean checked)
From source file:de.baumann.browser.Browser.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w . j a v a 2s . 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) { mWebView.stopLoading(); String text = editText.getText().toString(); String searchEngine = sharedPref.getString("searchEngine", "https://startpage.com/do/search?query="); String wikiLang = sharedPref.getString("wikiLang", "en"); if (text.length() > 3) { subStr = text.substring(3); } if (text.equals(mWebView.getTitle()) || text.isEmpty()) { helper_editText.showKeyboard(Browser.this, editText, 3, "", getString(R.string.app_search_hint)); } else { helper_editText.hideKeyboard(Browser.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser.this, mWebView); if (text.startsWith("www")) { mWebView.loadUrl("http://" + text); } else if (text.contains("http")) { mWebView.loadUrl(text); } else if (text.contains(".w ")) { mWebView.loadUrl("https://" + wikiLang + ".wikipedia.org/wiki/Spezial:Suche?search=" + subStr); } else if (text.startsWith(".f ")) { mWebView.loadUrl("https://www.flickr.com/search/?advanced=1&license=2%2C3%2C4%2C5%2C6%2C9&text=" + subStr); } else if (text.startsWith(".m ")) { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + subStr); } else if (text.startsWith(".g ")) { mWebView.loadUrl("https://github.com/search?utf8=&q=" + subStr); } else if (text.startsWith(".s ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl( "https://startpage.com/do/search?query=" + subStr + "&lui=deutsch&l=deutsch"); } else { mWebView.loadUrl("https://startpage.com/do/search?query=" + subStr); } } else if (text.startsWith(".G ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://www.google.de/search?&q=" + subStr); } else { mWebView.loadUrl("https://www.google.com/search?&q=" + subStr); } } else if (text.startsWith(".y ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://www.youtube.com/results?hl=de&gl=DE&search_query=" + subStr); } else { mWebView.loadUrl("https://www.youtube.com/results?search_query=" + subStr); } } else if (text.startsWith(".d ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://duckduckgo.com/?q=" + subStr + "&kl=de-de&kad=de_DE&k1=-1&kaj=m&kam=osm&kp=-1&kak=-1&kd=1&t=h_&ia=web"); } else { mWebView.loadUrl("https://duckduckgo.com/?q=" + subStr); } } else { if (searchEngine.contains("https://duckduckgo.com/?q=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://duckduckgo.com/?q=" + text + "&kl=de-de&kad=de_DE&k1=-1&kaj=m&kam=osm&kp=-1&kak=-1&kd=1&t=h_&ia=web"); } else { mWebView.loadUrl("https://duckduckgo.com/?q=" + text); } } else if (searchEngine.contains("https://metager.de/meta/meta.ger3?focus=web&eingabe=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + text); } else { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + text + "&focus=web&encoding=utf8&lang=eng"); } } else if (searchEngine.contains("https://startpage.com/do/search?query=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl( "https://startpage.com/do/search?query=" + text + "&lui=deutsch&l=deutsch"); } else { mWebView.loadUrl("https://startpage.com/do/search?query=" + text); } } else { mWebView.loadUrl(searchEngine + text); } } } } if (id == R.id.action_history) { helper_main.switchToActivity(Browser.this, Popup_history.class, "", false); } if (id == R.id.action_search3) { helper_editText.editText_searchWeb(editText, Browser.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser.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(); String link = mWebView.getUrl(); int domainInt = link.indexOf("//") + 2; final String domain = link.substring(domainInt, link.indexOf('/', domainInt)); final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser.this); View dialogView = View.inflate(Browser.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.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").apply(); helper_main.switchToActivity(Browser.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.action_save) { final CharSequence[] options = { getString(R.string.menu_save_screenshot), getString(R.string.menu_save_bookmark), getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Browser.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_save_bookmark))) { helper_editText.editText_saveBookmark(editText, Browser.this, mWebView); } if (options[item].equals(getString(R.string.menu_save_pass))) { helper_editText.editText_savePass(Browser.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (options[item].equals(getString(R.string.menu_save_readLater))) { try { final Database_ReadLater db = new Database_ReadLater(Browser.this); db.addBookmark(mWebView.getTitle(), mWebView.getUrl()); db.close(); Snackbar.make(mWebView, R.string.readLater_added, Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } if (options[item].equals(getString(R.string.menu_save_screenshot))) { screenshot(); } if (options[item].equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser.this, "de.baumann.browser.Browser"); 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.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT) .show(); } } }).show(); } if (id == R.id.action_share) { final CharSequence[] options = { getString(R.string.menu_share_screenshot), getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Browser.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.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 (options[item].equals(getString(R.string.menu_share_screenshot))) { screenshot(); if (shareFile.exists()) { 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 (options[item].equals(getString(R.string.menu_share_link_copy))) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } }).show(); } if (id == R.id.action_downloads) { String startDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getPath(); helper_main.openFilePicker(Browser.this, mWebView, startDir); } if (id == R.id.action_searchSite) { mWebView.stopLoading(); helper_editText.editText_FocusChange_searchSite(editText, Browser.this); helper_editText.editText_searchSite(editText, Browser.this, mWebView); } if (id == R.id.action_search2) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser.this, mWebView); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser.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) { helper_editText.editText_FocusChange(editText, Browser.this); helper_editText.editText_EditorAction(editText, Browser.this, mWebView); helper_editText.hideKeyboard(Browser.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.this, mWebView); } return super.onOptionsItemSelected(item); }
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 w w w. j av a 2 s . c o m 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:com.almalence.plugins.capture.video.VideoCapturePlugin.java
public void TimeLapseDialog() { if (isRecording) return;/*from w w w .j a v a2 s. c o m*/ 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:jp.co.rediscovery.firstflight.BaseAutoPilotFragment.java
private void initColorExtraction(final View rootView) { Switch sw; Button btn;//from www . ja v a 2 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); // ? 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:com.moonpi.tapunlock.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get lobster_two asset and create typeface // Set action bar title to lobster_two typeface lobsterTwo = Typeface.createFromAsset(getAssets(), "lobster_two.otf"); int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android"); actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle); if (actionBarTitleView != null) { actionBarTitleView.setTypeface(lobsterTwo); actionBarTitleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28f); actionBarTitleView.setTextColor(getResources().getColor(R.color.blue)); }/*www . jav a 2 s . c o m*/ setContentView(R.layout.activity_main); // Hide keyboard on app launch this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Get NFC service and adapter NfcManager nfcManager = (NfcManager) this.getSystemService(Context.NFC_SERVICE); nfcAdapter = nfcManager.getDefaultAdapter(); // Create PendingIntent for enableForegroundDispatch for NFC tag discovery pIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); readFromJSON(); writeToJSON(); readFromJSON(); // If Android 4.2 or bigger if (Build.VERSION.SDK_INT > 16) { // Check if TapUnlock folder exists, if not, create directory File folder = new File(Environment.getExternalStorageDirectory() + "/TapUnlock"); boolean folderSuccess = true; if (!folder.exists()) { folderSuccess = folder.mkdir(); } try { // If blur var bigger than 0 if (settings.getInt("blur") > 0) { // If folder exists or successfully created if (folderSuccess) { // If blurred wallpaper file doesn't exist if (!ImageUtils.doesBlurredWallpaperExist()) { // Get default wallpaper WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); final Drawable wallpaperDrawable = wallpaperManager.peekFastDrawable(); if (wallpaperDrawable != null) { // Default wallpaper to bitmap - fastBlur the bitmap - store bitmap new Thread(new Runnable() { @Override public void run() { Bitmap bitmapToBlur = ImageUtils.drawableToBitmap(wallpaperDrawable); Bitmap blurredWallpaper = null; if (bitmapToBlur != null) blurredWallpaper = ImageUtils.fastBlur(MainActivity.this, bitmapToBlur, blur); if (blurredWallpaper != null) { ImageUtils.storeImage(blurredWallpaper); } } }).start(); } } } } } catch (JSONException e) { e.printStackTrace(); } } // Initialize layout items pinEdit = (EditText) findViewById(R.id.pinEdit); pinEdit.setImeOptions(EditorInfo.IME_ACTION_DONE); Button setPin = (Button) findViewById(R.id.setPin); ImageButton newTag = (ImageButton) findViewById(R.id.newTag); enabled_disabled = (TextView) findViewById(R.id.enabled_disabled); Switch toggle = (Switch) findViewById(R.id.toggle); seekBar = (SeekBar) findViewById(R.id.seekBar); progressBar = (ProgressBar) findViewById(R.id.progressBar); Button refreshWallpaper = (Button) findViewById(R.id.refreshWallpaper); listView = (ListView) findViewById(R.id.listView); backgroundBlurValue = (TextView) findViewById(R.id.backgroundBlurValue); noTags = (TextView) findViewById(R.id.noTags); // Initialize TagAdapter adapter = new TagAdapter(this, tags); registerForContextMenu(listView); // Set listView adapter to TapAdapter object listView.setAdapter(adapter); // Set click, check and seekBar listeners setPin.setOnClickListener(this); newTag.setOnClickListener(this); refreshWallpaper.setOnClickListener(this); toggle.setOnCheckedChangeListener(this); seekBar.setOnSeekBarChangeListener(this); // Set seekBar progress to blur var try { seekBar.setProgress(settings.getInt("blur")); } catch (JSONException e) { e.printStackTrace(); } // Refresh the listView height updateListViewHeight(listView); // If no tags, show 'Press + to add Tags' textView if (tags.length() == 0) noTags.setVisibility(View.VISIBLE); else noTags.setVisibility(View.INVISIBLE); // Scroll up scrollView = (ScrollView) findViewById(R.id.scrollView); scrollView.post(new Runnable() { public void run() { scrollView.scrollTo(0, scrollView.getTop()); scrollView.fullScroll(View.FOCUS_UP); } }); // If lockscreen enabled, initialize switch, text and start service try { if (settings.getBoolean("lockscreen")) { onStart = true; enabled_disabled.setText(R.string.lockscreen_enabled); enabled_disabled.setTextColor(getResources().getColor(R.color.green)); toggle.setChecked(true); } } catch (JSONException e1) { e1.printStackTrace(); } }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user adjust gain settings *//* w w w .ja va 2s. 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:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
private void initColorExtraction(final View rootView) { Switch sw; Button btn;//from ww w . ja va2 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.serenegiant.autoparrot.BaseAutoPilotFragment.java
private void initPreprocess2(final View rootView) { Switch sw; Spinner spinner;//from w ww . j a va2s . c o m SeekBar sb; mMaxThinningLoopFormat = getString(R.string.trace_max_thinning_loop); // OpenGL|ES?? // mGLESSmoothType = getInt(mPref, KEY_SMOOTH_TYPE, DEFAULT_SMOOTH_TYPE); // spinner = (Spinner)rootView.findViewById(R.id.use_smooth_spinner); // spinner.setAdapter(new SmoothTypeAdapter(getActivity())); // spinner.setOnItemSelectedListener(mOnItemSelectedListener); // // OpenGL|ES?????? // mEnableGLESCanny = mPref.getBoolean(KEY_ENABLE_EDGE_DETECTION, DEFAULT_ENABLE_EDGE_DETECTION); // sw = (Switch)rootView.findViewById(R.id.use_canny_sw); // sw.setChecked(mEnableGLESCanny); // sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // ??????? mFillContour = mPref.getBoolean(KEY_FILL_INNER_CONTOUR, DEFAULT_FILL_INNER_CONTOUR); sw = (Switch) rootView.findViewById(R.id.use_fill_contour_sw); sw.setChecked(mFillContour); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // // Native??Canny????? // mEnableNativeCanny = mPref.getBoolean(KEY_ENABLE_NATIVE_EDGE_DETECTION, DEFAULT_ENABLE_NATIVE_EDGE_DETECTION); // sw = (Switch)rootView.findViewById(R.id.use_native_canny_sw); // sw.setChecked(mEnableNativeCanny); // sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // native??? mNativeSmoothType = getInt(mPref, KEY_NATIVE_SMOOTH_TYPE, DEFAULT_NATIVE_SMOOTH_TYPE); spinner = (Spinner) rootView.findViewById(R.id.use_native_smooth_spinner); spinner.setAdapter(new SmoothTypeAdapter(getActivity())); spinner.setOnItemSelectedListener(mOnItemSelectedListener); // native??? mMaxThinningLoop = getInt(mPref, KEY_NATIVE_MAX_THINNING_LOOP, DEFAULT_NATIVE_MAX_THINNING_LOOP); mMaxThinningLoopLabel = (TextView) rootView.findViewById(R.id.max_thinning_loop_textview); sb = (SeekBar) rootView.findViewById(R.id.max_thinning_loop_seekbar); sb.setMax(20); sb.setProgress(mMaxThinningLoop); sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateMaxThinningLoop(mMaxThinningLoop); }
From source file:com.serenegiant.autoparrot.BaseAutoPilotFragment.java
private void initAutoTrace2(final View rootView) { SeekBar sb;/*from w ww . j a v a 2 s.c o m*/ Switch sw; // mTraceAttitudeYawFormat = getString(R.string.trace_config_trace_attitude_yaw); mTraceSpeedFormat = getString(R.string.trace_config_trace_speed); mTraceAltitudeFormat = getString(R.string.trace_config_trace_altitude); // (yaw) mTraceAttitudeYaw = mPref.getFloat(KEY_TRACE_ATTITUDE_YAW, DEFAULT_TRACE_ATTITUDE_YAW); mTraceAttitudeYawLabel = (TextView) rootView.findViewById(R.id.trace_flight_attitude_yaw_textview); sb = (SeekBar) rootView.findViewById(R.id.trace_flight_attitude_yaw_seekbar); sb.setMax(180); sb.setProgress((int) (mTraceAttitudeYaw + 90)); // [-90,+90] => [0, 180] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateTraceAttitudeYaw(mTraceAttitudeYaw); // mTraceSpeed = mPref.getFloat(KEY_TRACE_SPEED, DEFAULT_TRACE_SPEED); mTraceSpeedLabel = (TextView) rootView.findViewById(R.id.trace_flight_speed_textview); sb = (SeekBar) rootView.findViewById(R.id.trace_flight_speed_seekbar); sb.setMax(200); sb.setProgress((int) (mTraceSpeed + 100)); // [-100,+100] => [0, 200] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateTraceSpeed(mTraceSpeed); // mTraceAltitudeEnabled = mPref.getBoolean(KEY_TRACE_ALTITUDE_ENABLED, DEFAULT_TRACE_ALTITUDE_ENABLED); sw = (Switch) rootView.findViewById(R.id.trace_flight_altitude_enable_switch); sw.setChecked(mTraceAltitudeEnabled); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // mTraceAltitude = Math.min(mPref.getFloat(KEY_TRACE_ALTITUDE, DEFAULT_TRACE_ALTITUDE), mFlightController.getMaxAltitude().current()); mTraceAltitudeLabel = (TextView) rootView.findViewById(R.id.trace_flight_altitude_textview); sb = (SeekBar) rootView.findViewById(R.id.trace_flight_altitude_seekbar); sb.setMax(45); sb.setProgress((int) ((mTraceAltitude - 0.5f) * 10.0f)); // [0.5,+5.0] => [0, 45] sb.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateTraceAltitude(mTraceAltitude); }
From source file:info.corne.performancetool.MainActivity.java
/** * This function will be triggered when the hardware info * is loaded, It will then use that info to fill the view * in the activities. //from w w w . j av a 2s .c om * @param result A array with all the info needed. */ public void hardwareInfoLoaded(String[] result) { // Get the views Spinner governorSpinner = (Spinner) findViewById(R.id.governorSpinner); Spinner frequencyCapSpinner = (Spinner) findViewById(R.id.frequencyCapSpinner); Spinner suspendCapSpinner = (Spinner) findViewById(R.id.suspendCapSpinner); Spinner audioCapSpinner = (Spinner) findViewById(R.id.audioCapSpinner); Spinner ioSchedulerSpinner = (Spinner) findViewById(R.id.ioSchedulerSpinner); SeekBar maxCpusSeek = (SeekBar) findViewById(R.id.maxCpusSeek); Switch ocSwitch = (Switch) findViewById(R.id.overclockSwitch); Switch lpOcSwitch = (Switch) findViewById(R.id.lpOverclockSwitch); Switch gpuScalingSwitch = (Switch) findViewById(R.id.gpuScalingSwitch); Switch gpuQuickOCSwitch = (Switch) findViewById(R.id.gpuOCSwitch); TextView gpuOCValues = (TextView) findViewById(R.id.gpuOCValues); Spinner a2dpCapSpinner = (Spinner) findViewById(R.id.a2dpCapSpinner); // The returned data will be stored in their variables. String[] governors = result[0].split(" "); String[] freqencies = result[1].split(" "); // frequenciesShort will be Disabled + all the frequencies in MHz. String[] frequenciesShort = new String[freqencies.length + 1]; String[] suspendFreqsShort = new String[freqencies.length + 1]; String[] audioFreqsShort = new String[freqencies.length + 1]; String[] a2dpFreqShort = new String[freqencies.length + 1]; Spinner cpqGovernorSpinner = (Spinner) findViewById(R.id.cpqGovernorSpinner); String[] cpqGovernors = result[10].split(" "); frequenciesShort[0] = getResources().getString(R.string.disabled_string); suspendFreqsShort[0] = getResources().getString(R.string.disabled_string); audioFreqsShort[0] = getResources().getString(R.string.disabled_string); a2dpFreqShort[0] = getResources().getString(R.string.disabled_string); ioSchedulers = result[4].split(" "); int currentFrequencyPos = freqencies.length - 1; int currentSuspendPos = 0; int currentAudioPos = 0; int currentA2dpPos = 0; int currentIOScheduler = ioSchedulers.length - 1; // Will loop trough the frequencies and convert them to MHz. for (int i = 0; i < freqencies.length; i++) { if (result[3].indexOf("000") == -1) currentFrequencyPos = 0; else if (result[3].compareTo(freqencies[i]) == 0) currentFrequencyPos = i + 1; if (result[8].indexOf("000") == -1) currentSuspendPos = 0; else if (result[8].compareTo(freqencies[i]) == 0) currentSuspendPos = i + 1; if (result[9].equals("Error")) audioCapSpinner.setVisibility(View.GONE); if (result[9].indexOf("000") == -1) currentAudioPos = 0; else if (result[9].compareTo(freqencies[i]) == 0) currentAudioPos = i + 1; if (result[18].equals("Error")) a2dpCapSpinner.setVisibility(View.GONE); if (result[18].indexOf("000") == -1) currentA2dpPos = 0; else if (result[18].compareTo(freqencies[i]) == 0) currentA2dpPos = i + 1; frequenciesShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz); suspendFreqsShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz); audioFreqsShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz); a2dpFreqShort[i + 1] = freqencies[i].replaceFirst("000", "") + getResources().getString(R.string.mhz); } // And that will also be stored in the adapter. frequencyCapSpinner.setAdapter(generateAdapter(frequenciesShort)); suspendCapSpinner.setAdapter(generateAdapter(suspendFreqsShort)); audioCapSpinner.setAdapter(generateAdapter(audioFreqsShort)); a2dpCapSpinner.setAdapter(generateAdapter(a2dpFreqShort)); // And the current selected freq will be selected. frequencyCapSpinner.setSelection(currentFrequencyPos); suspendCapSpinner.setSelection(currentSuspendPos); audioCapSpinner.setSelection(currentAudioPos); a2dpCapSpinner.setSelection(currentA2dpPos); // All the governors will be add to the spinner. governorSpinner.setAdapter(generateAdapter(governors)); // And the current selected governor will be selected // in the spinner. for (int i = 0; i < governors.length; i++) { if (result[2].compareTo(governors[i]) == 0) governorSpinner.setSelection(i); } // Will search for the currently selected IO scheduler. for (int i = 0; i < ioSchedulers.length; i++) { if (ioSchedulers[i].charAt(0) == '[') { currentIOScheduler = i; ioSchedulers[i] = ioSchedulers[i].substring(1, ioSchedulers[i].length() - 1); } } // And fill the spinners/set selection ioSchedulerSpinner.setAdapter(generateAdapter(ioSchedulers)); ioSchedulerSpinner.setSelection(currentIOScheduler); // If overclock is one turn the switch on. if (result[5].equals("1")) ocSwitch.setChecked(true); else ocSwitch.setChecked(false); onOverclockSwitchClick(ocSwitch); if (!result[6].equals("Error") || !result[7].equals("Error")) { if (!result[6].equals("Error")) { maxCpusSeek.setProgress((int) Float.parseFloat(result[6]) - 1); } if (!result[7].equals("Error")) { maxCpusSeek.setProgress((int) Float.parseFloat(result[7]) - 1); } } else { maxCpusSeek.setVisibility(View.GONE); ((TextView) findViewById(R.id.maxCpusTextView)).setVisibility(View.GONE); } if (!result[11].equals("Error")) { cpqGovernorSpinner.setAdapter(generateAdapter(cpqGovernors)); for (int i = 0; i < cpqGovernors.length; i++) { if (result[11].compareTo(cpqGovernors[i]) == 0) cpqGovernorSpinner.setSelection(i); } } else { cpqGovernorSpinner.setVisibility(View.GONE); ((TextView) findViewById(R.id.cpqGovernorTextView)).setVisibility(View.GONE); } if (!result[12].equals("Error")) { // If lp overclock is one turn the switch on. if (result[12].equals("1")) lpOcSwitch.setChecked(true); else lpOcSwitch.setChecked(false); onLpOverclockSwitchClick(lpOcSwitch); } else { lpOcSwitch.setVisibility(View.GONE); ((TextView) findViewById(R.id.lpOverclockInfo)).setVisibility(View.GONE); } if (!result[13].equals("Error")) { if (result[13].equals("1")) gpuScalingSwitch.setChecked(true); else gpuScalingSwitch.setChecked(false); } else { gpuScalingSwitch.setVisibility(View.GONE); } if (!result[14].equals("Error")) { if (result[14].equals("0")) { cpuHotplugging = true; updateCpuHotpluggingView(true); } else { cpuHotplugging = false; updateCpuHotpluggingView(true); } } else { cpuHotplugging = true; updateCpuHotpluggingView(true); ((RadioButton) findViewById(R.id.cpu_hotplug_mode)).setVisibility(View.GONE); ((RadioButton) findViewById(R.id.cpu_manual_mode)).setVisibility(View.GONE); } if (!result[15].equals("Error")) { updateActiveCpusView(result[15]); } if (!result[16].equals("Error")) { if (result[16].equals("1")) gpuQuickOCSwitch.setChecked(true); else gpuQuickOCSwitch.setChecked(false); } else { gpuQuickOCSwitch.setVisibility(View.GONE); } if (!result[17].equals("Error")) { gpuOCValuesString = result[17]; gpuOCValues.setText(gpuOCValuesString); } else { gpuOCValues.setVisibility(View.GONE); } dialog.dismiss(); updateFromView(); updatePreferences(""); refreshProfilesList(); ListView profilesList = (ListView) findViewById(R.id.profilesListView); registerForContextMenu(profilesList); profilesList.setOnItemClickListener(this); }