Skip to content

Commit

Permalink
Added tone for + and - buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
knirirr committed Aug 15, 2015
1 parent 94b3782 commit 5b8d571
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 10 deletions.
2 changes: 1 addition & 1 deletion beecount/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 20
versionCode 108
versionCode 109
}
/*
buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion beecount/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.knirirr.beecount"
android:largeHeap="true"
android:versionName="2.3.8">
android:versionName="2.3.9">


<uses-permission android:name="android.permission.WAKE_LOCK" />
Expand Down
31 changes: 31 additions & 0 deletions beecount/src/main/java/com/knirirr/beecount/CountingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public class CountingActivity extends ActionBarActivity implements SharedPrefere
private boolean awakePref;
private boolean fontPref;
private boolean soundPref;
private boolean buttonSoundPref;
private boolean negPref;
private String alertSound;
private String buttonAlertSound;
private PowerManager.WakeLock wl;

// the actual data
Expand Down Expand Up @@ -123,6 +125,8 @@ private void getPrefs()
soundPref = prefs.getBoolean("pref_sound",false);
negPref = prefs.getBoolean("pref_negative",false);
alertSound = prefs.getString("alert_sound",null);
buttonSoundPref = prefs.getBoolean("pref_button_sound",false);
buttonAlertSound = prefs.getString("alert_button_sound",null);
}

@Override
Expand Down Expand Up @@ -394,6 +398,7 @@ public void countUp(View view)
{
//Log.i(TAG, "View clicked: " + view.toString());
//Log.i(TAG, "View tag: " + view.getTag().toString());
buttonSound();
long count_id = Long.valueOf(view.getTag().toString());
CountingWidget widget = getCountFromId(count_id);
if (widget != null)
Expand All @@ -413,6 +418,7 @@ public void countDown(View view)
{
//Log.i(TAG, "View clicked: " + view.toString());
//Log.i(TAG, "View tag: " + view.getTag().toString());
buttonSound();
long count_id = Long.valueOf(view.getTag().toString());
CountingWidget widget = getCountFromId(count_id);
if (widget != null)
Expand Down Expand Up @@ -534,6 +540,31 @@ public void soundAlert()
}
}

public void buttonSound()
{
if (buttonSoundPref)
{
try
{
Uri notification;
if (StringUtils.isNotBlank(buttonAlertSound) && buttonAlertSound != null)
{
notification = Uri.parse(buttonAlertSound);
}
else
{
notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

public void checkLink(long count_id, int count_value, boolean up)
{
//Log.i(TAG, "STARTING checkLink: " + String.valueOf(count_id));
Expand Down
39 changes: 31 additions & 8 deletions beecount/src/main/java/com/knirirr/beecount/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SettingsActivity extends PreferenceActivity
SharedPreferences prefs;
SharedPreferences.Editor editor;
Uri alert_uri;
Uri alert_button_uri;

@Override
@SuppressLint("CommitPrefEdits")
Expand All @@ -47,17 +48,33 @@ public boolean onPreferenceClick(Preference arg0)

prefs = PreferenceManager.getDefaultSharedPreferences(this);

// Sound for alerts
String strRingtonePreference = prefs.getString("alert_sound", "DEFAULT_SOUND");
alert_uri = Uri.parse(strRingtonePreference);
Log.i(TAG,"ALERT_URI: " + String.valueOf(alert_uri));
//Log.i(TAG,"ALERT_URI: " + String.valueOf(alert_uri));

Preference alert_sound = (Preference) findPreference("alert_sound");
alert_sound.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference arg0)
{
getSound(alert_uri);
getSound(alert_uri,5);
return true;
}
});

// Sound for keypresses
String strButtonSoundPreference = prefs.getString("alert_button_sound", "DEFAULT_SOUND");
alert_button_uri = Uri.parse(strButtonSoundPreference);

Preference alert_button_sound = (Preference) findPreference("alert_button_sound");
alert_button_sound.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference arg0)
{
getSound(alert_button_uri,10);
return true;
}
});
Expand Down Expand Up @@ -89,13 +106,13 @@ public void getImage()
startActivityForResult(pickIntent, SELECT_PICTURE);
}

public void getSound(Uri alert_uri)
public void getSound(Uri tmp_alert_uri, int requestCode)
{
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pref_sound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) alert_uri);
this.startActivityForResult(intent, 5);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) tmp_alert_uri);
this.startActivityForResult(intent, requestCode);
}


Expand Down Expand Up @@ -144,16 +161,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data)
}
}
}
else if (resultCode == Activity.RESULT_OK && requestCode == 5)
else if (resultCode == Activity.RESULT_OK)
{
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
String ringtone = null;
if (uri != null)
{
ringtone = uri.toString();
editor.putString("alert_sound",ringtone);
if (requestCode == 5)
{
editor.putString("alert_sound", ringtone);
}
else if (requestCode == 10)
{
editor.putString("alert_button_sound", ringtone);
}
}
//Log.i(TAG, "RINGTONE: " + ringtone);
}


Expand Down
4 changes: 4 additions & 0 deletions beecount/src/main/res/raw/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
</style>
</head>
<body>
$ 2.3.9
% version 2.3.9
_ 2015-08-15
* Optional sound on + or - button press.
$ 2.3.8
% version 2.3.8
_ 2015-08-12
Expand Down
4 changes: 4 additions & 0 deletions beecount/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<string name="pref_duplicate_summary">Quand cette option est choisi, les noms de comptes pour un projet doivent être uniques.</string>
<string name="pref_count_multiplier">Compte multiplicateur</string>
<string name="pref_count_multiplier_summary">Activer option pour multiplier un compte. </string>
<string name="pref_button_sound">Sonnerie Bouton</string>
<string name="pref_button_sound_summary">Faire sonner un son pendant qu\'on tapote sur les boutons \'+\' ou \'-\'.</string>
<string name="choose_button_alert">Son de bouton</string>
<string name="explain_button_alert">Choisissez une sonnerie pour les boutons \'+\' ou \'-\'.</string>


<!-- CountOptionsActivity -->
Expand Down
4 changes: 4 additions & 0 deletions beecount/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
<string name="pref_duplicate_summary">When selected, the count names in each project must be unique.</string>
<string name="pref_count_multiplier">Count multiplier</string>
<string name="pref_count_multiplier_summary">Show option to multiply a count by a set value. </string>
<string name="pref_button_sound">Count button sounds</string>
<string name="pref_button_sound_summary">Make a sound upon pressing the count up or count down buttons.</string>
<string name="choose_button_alert">Button sound</string>
<string name="explain_button_alert">Choose a sound for buttons.</string>


<!-- CountOptionsActivity -->
Expand Down
9 changes: 9 additions & 0 deletions beecount/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
android:title="@string/choose_alert"
android:key="alert_sound"
android:summary="@string/explain_alert"/>
<CheckBoxPreference
android:key="pref_button_sound"
android:title="@string/pref_button_sound"
android:summary="@string/pref_button_sound_summary"
android:defaultValue="false"/>
<Preference
android:title="@string/choose_button_alert"
android:key="alert_button_sound"
android:summary="@string/explain_button_alert"/>
</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 5b8d571

Please sign in to comment.