eSpeak NG is an open source speech synthesizer that supports more than hundred languages and accents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SeekBarPreference.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2013 Reece H. Dunn
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.reecedunn.espeak;
  17. import android.content.Context;
  18. import android.content.DialogInterface;
  19. import android.content.SharedPreferences;
  20. import android.preference.DialogPreference;
  21. import android.util.AttributeSet;
  22. import android.view.View;
  23. import android.widget.SeekBar;
  24. public class SeekBarPreference extends DialogPreference
  25. {
  26. private SeekBar mSeekBar;
  27. private int mProgress = 0;
  28. private int mMin = 0;
  29. private int mMax = 100;
  30. private String mFormatter = "%s";
  31. public void setProgress(int progress) {
  32. mProgress = progress + mMin;
  33. String text = Integer.toString(mProgress);
  34. callChangeListener(text);
  35. }
  36. public int getProgress() {
  37. return mProgress;
  38. }
  39. public void setMin(int min) {
  40. mProgress -= mMin;
  41. mMin = min;
  42. mProgress += mMin;
  43. String text = Integer.toString(mProgress);
  44. callChangeListener(text);
  45. }
  46. public int getMin() {
  47. return mMin;
  48. }
  49. public void setMax(int max) {
  50. mMax = max;
  51. }
  52. public int getMax() {
  53. return mMax;
  54. }
  55. public void setFormatter(String formatter) {
  56. mFormatter = formatter;
  57. }
  58. public String getFormatter() {
  59. return mFormatter;
  60. }
  61. public SeekBarPreference(Context context, AttributeSet attrs, int defStyle)
  62. {
  63. super(context, attrs, defStyle);
  64. setDialogLayoutResource(R.layout.seekbar_preference);
  65. setPositiveButtonText(android.R.string.ok);
  66. setNegativeButtonText(android.R.string.cancel);
  67. }
  68. public SeekBarPreference(Context context, AttributeSet attrs)
  69. {
  70. this(context, attrs, 0);
  71. }
  72. public SeekBarPreference(Context context)
  73. {
  74. this(context, null);
  75. }
  76. @Override
  77. protected View onCreateDialogView() {
  78. View root = super.onCreateDialogView();
  79. mSeekBar = (SeekBar)root.findViewById(R.id.seekBar);
  80. return root;
  81. }
  82. @Override
  83. protected void onBindDialogView(View view) {
  84. mSeekBar.setMax(mMax - mMin);
  85. mSeekBar.setProgress(mProgress + mMin);
  86. }
  87. @Override
  88. public void onClick(DialogInterface dialog, int which) {
  89. switch (which) {
  90. case DialogInterface.BUTTON_POSITIVE:
  91. mProgress = mSeekBar.getProgress() + mMin;
  92. String text = Integer.toString(mProgress);
  93. callChangeListener(text);
  94. if (shouldCommit()) {
  95. SharedPreferences.Editor editor = getEditor();
  96. editor.putString(getKey(), text);
  97. editor.commit();
  98. }
  99. break;
  100. }
  101. super.onClick(dialog, which);
  102. }
  103. }