List of usage examples for android.widget Switch setTextOn
public void setTextOn(CharSequence textOn)
From source file:android.support.v14.preference.SwitchPreference.java
private void syncSwitchView(View view) { if (view instanceof Switch) { final Switch switchView = (Switch) view; switchView.setOnCheckedChangeListener(null); }//from ww w .ja v a2 s.co m if (view instanceof Checkable) { ((Checkable) view).setChecked(mChecked); } if (view instanceof Switch) { final Switch switchView = (Switch) view; switchView.setTextOn(mSwitchOn); switchView.setTextOff(mSwitchOff); switchView.setOnCheckedChangeListener(mListener); } }
From source file:com.urbantamil.projmadurai.CustomWebViewClient.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.book_detail, container, false); final View book_use_pdf = rootView.findViewById(R.id.book_use_pdf); setHasOptionsMenu(true);/*from w w w . j a v a 2 s . c o m*/ // book-use-PDF is not featured for the app book_use_pdf.setVisibility(View.INVISIBLE); if (getArguments().containsKey(ARG_ITEM_OPEN)) { m_open_book = getArguments().getBoolean(ARG_ITEM_OPEN); Log.d(TAG, "ARG_ITEM_OPEN was requested as " + m_open_book); } // Show the dummy content as text in a TextView. if (mItem != null) { ((TextView) rootView.findViewById(R.id.book_detail)).setText(mItem.getTitle()); ((TextView) rootView.findViewById(R.id.book_author)).setText(mItem.getAuthor()); ((CheckBox) rootView.findViewById(R.id.book_use_pdf)).setChecked(true); ((TextView) rootView.findViewById(R.id.book_genre)).setText(mItem.getGenre()); final Switch sw = (Switch) rootView.findViewById(R.id.book_bookmark); if (Build.VERSION.SDK_INT >= 14) { sw.setTextOn(getResources().getString(R.string.mark)); sw.setTextOff(getResources().getString(R.string.clear)); } //load current state of bookmarking for the book boolean isBookMarked = false; try { MaduraiBookmark mgr = MaduraiBookmark.getManager(getActivity()); if (mgr != null) { isBookMarked = mgr.findBook(mItem) >= 0; } } catch (Exception e) { //pass } if (Build.VERSION.SDK_INT >= 14) { sw.setChecked(isBookMarked); } sw.postInvalidate(); sw.setOnClickListener(m_bookmarkListener); final Button btn = (Button) rootView.findViewById(R.id.book_open_browser); mWebView = (ObservableWebView) rootView.findViewById(R.id.book_webView); final ObservableWebView wv = (ObservableWebView) rootView.findViewById(R.id.book_webView); wv.getSettings().setJavaScriptEnabled(true); fontSize = wv.getSettings().getDefaultFontSize(); wv.setKeepScreenOn(true); wv.setWebViewClient(new CustomWebViewClient(btn)); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = MaduraiOrg.getFullUrlAssetsHTML(mItem.getUrl_html().next()); //update book : on recent list MaduraiRecentBook.getManager(getActivity()).add(mItem); wv.setVisibility(View.VISIBLE); wv.invalidate(); wv.loadUrl(url); btn.setEnabled(false); btn.setText(R.string.projmad_please_wait); } }); wv.setOnScrollChangedCallback(new ObservableWebView.OnScrollChangedCallback() { public void onScroll(int l, int t) { //Do stuff Log.d(TAG, "We Scrolled by " + l + " and t = " + t); } }); if (m_open_book) { Log.d(TAG, "Book requested to be opened"); // delayed open book wv.setVisibility(View.VISIBLE); wv.invalidate(); String url = MaduraiOrg.getFullUrlAssetsHTML(mItem.getUrl_html().next()); wv.loadUrl(url); } else { Log.d(TAG, "Book requested cannot be opened"); } } else { Log.d(TAG, "mItem - cannot be loaded - some error occured on dispatch"); } return rootView; }
From source file:net.opendasharchive.openarchive.ReviewMediaActivity.java
private void deleteMedia() { final Switch swDeleteLocal = new Switch(this); final Switch swDeleteRemote = new Switch(this); LinearLayout linearLayoutGroup = new LinearLayout(this); linearLayoutGroup.setOrientation(LinearLayout.VERTICAL); linearLayoutGroup.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); swDeleteLocal.setTextOn(getString(R.string.answer_yes)); swDeleteLocal.setTextOff(getString(R.string.answer_no)); TextView tvLocal = new TextView(this); tvLocal.setText(R.string.delete_local); LinearLayout linearLayout = new LinearLayout(this); linearLayout.setOrientation(LinearLayout.HORIZONTAL); linearLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setGravity(Gravity.CENTER_HORIZONTAL); linearLayout.addView(tvLocal);/*from w ww. ja v a 2s . c om*/ linearLayout.addView(swDeleteLocal); linearLayoutGroup.addView(linearLayout); if (mMedia.getServerUrl() != null) { swDeleteRemote.setTextOn(getString(R.string.answer_yes)); swDeleteRemote.setTextOff(getString(R.string.answer_no)); TextView tvRemote = new TextView(this); tvRemote.setText(R.string.delete_remote); LinearLayout linearLayoutRemote = new LinearLayout(this); linearLayoutRemote.setOrientation(LinearLayout.HORIZONTAL); linearLayoutRemote.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayoutRemote.setGravity(Gravity.CENTER_HORIZONTAL); linearLayoutRemote.addView(tvRemote); linearLayoutRemote.addView(swDeleteRemote); linearLayoutGroup.addView(linearLayoutRemote); } AlertDialog.Builder build = new AlertDialog.Builder(ReviewMediaActivity.this).setTitle(R.string.menu_delete) .setMessage(R.string.alert_delete_media).setView(linearLayoutGroup).setCancelable(true) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //do nothing } }) .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { deleteMedia(swDeleteLocal.isChecked(), swDeleteRemote.isChecked()); finish(); } }); build.create().show(); }
From source file:com.coinblesk.client.MainActivity.java
private void initSwitch(Menu menu) { MenuItem item = menu.findItem(R.id.myswitch); View view = item.getActionView(); final Switch mySwitch = (Switch) view.findViewById(R.id.switchAB); final AtomicReference<CountDownTimer> ref = new AtomicReference<>(); mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*from www.j a v a2 s . com*/ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { //enable BT ref.set(new CountDownTimer(30000, 1000) { int i = 0; public void onTick(final long millisUntilFinished) { mySwitch.setButtonDrawable( (i++ % 2) == 0 ? R.drawable.bluetooth_onon : R.drawable.bluetooth_on); mySwitch.setTextOn("" + millisUntilFinished / 1000); } public void onFinish() { mySwitch.setButtonDrawable(R.drawable.bluetooth_on); mySwitch.setChecked(false); } }); ref.get().start(); LocalBroadcastManager.getInstance(MainActivity.this) .sendBroadcast(new Intent(Constants.START_CLIENTS_ACTION)); } else { //mySwitch.setShowText(false); CountDownTimer tmp; if ((tmp = ref.getAndSet(null)) != null) { tmp.cancel(); } LocalBroadcastManager.getInstance(MainActivity.this) .sendBroadcast(new Intent(Constants.STOP_CLIENTS_ACTION)); } } }); }