Skip to content
Snippets Groups Projects
Commit c3fd5174 authored by Aline Bonnet's avatar Aline Bonnet Committed by gerrit2
Browse files

ringtones: add default ringtone option

This commit adds a button to choose between a default and a custom ringtone.
Default.wav was compressed.

Change-Id: I4d866b837d877fe9220f20d900ffee5b290745be
Tuleap: #1117
parent 649d49f1
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -287,7 +287,7 @@ public class HomeActivity extends AppCompatActivity implements LocalService.Call
protected void onStart() {
Log.d(TAG, "onStart");
String path = getFilesDir().getAbsolutePath() + "/ringtones";
String path = FileUtils.ringtonesPath(this);
if (!(new File(path + "/default.wav")).exists()) {
Log.d(TAG, "default.wav doesn't exist. Copying ringtones.");
FileUtils.copyAssetFolder(getAssets(), "ringtones", path);
......
......@@ -33,6 +33,7 @@ import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.v13.app.FragmentCompat;
import android.support.v14.preference.PreferenceFragment;
import android.support.v14.preference.SwitchPreference;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
......@@ -61,6 +62,7 @@ public class MediaPreferenceFragment extends PreferenceFragment
private CodecPreference audioCodecsPref = null;
private CodecPreference videoCodecsPref = null;
private SwitchPreference mRingtoneCustom = null;
protected AccountCallbacks mCallbacks = DUMMY_CALLBACKS;
......@@ -97,6 +99,7 @@ public class MediaPreferenceFragment extends PreferenceFragment
@Override
public void accountChanged(Account account) {
Log.d(TAG, "accountChanged");
setPreferenceDetails(account.getConfig());
addPreferenceListener(account.getConfig(), changeAudioPreferenceListener);
final ArrayList<Codec> audioCodec = new ArrayList<>();
......@@ -119,6 +122,8 @@ public class MediaPreferenceFragment extends PreferenceFragment
videoCodecsPref.setCodecs(videoCodec);
videoCodecsPref.setOnPreferenceChangeListener(changeCodecListener);
mRingtoneCustom.setOnPreferenceChangeListener(changeAudioPreferenceListener);
}
@Override
......@@ -148,13 +153,17 @@ public class MediaPreferenceFragment extends PreferenceFragment
builder.show();
Log.d(TAG, "The file is too big " + myFile.length() / 1024);
} else {
findPreference(ConfigKey.RINGTONE_PATH.key()).setSummary(myFile.getName());
mCallbacks.getAccount().setDetail(ConfigKey.RINGTONE_PATH, myFile.getAbsolutePath());
mCallbacks.saveAccount();
setRingtonepath(myFile);
}
}
}
private void setRingtonepath(File file) {
findPreference(ConfigKey.RINGTONE_PATH.key()).setSummary(file.getName());
mCallbacks.getAccount().setDetail(ConfigKey.RINGTONE_PATH, file.getAbsolutePath());
mCallbacks.saveAccount();
}
public void performFileSearch(int requestCodeToSet) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
......@@ -164,13 +173,19 @@ public class MediaPreferenceFragment extends PreferenceFragment
@Override
public void onCreatePreferences(Bundle bundle, String s) {
Log.d(TAG, "onCreatePreferences");
addPreferencesFromResource(R.xml.account_media_prefs);
audioCodecsPref = (CodecPreference) findPreference("Account.audioCodecs");
videoCodecsPref = (CodecPreference) findPreference("Account.videoCodecs");
boolean isChecked = Boolean.valueOf(mCallbacks.getAccount().getDetail(ConfigKey.RINGTONE_ENABLED));
findPreference(ConfigKey.RINGTONE_PATH.key()).setEnabled(isChecked);
mRingtoneCustom = (SwitchPreference) findPreference("Account.ringtoneCustom");
boolean isRingtoneEnabled = Boolean.valueOf(mCallbacks.getAccount().getDetail(ConfigKey.RINGTONE_ENABLED));
mRingtoneCustom.setEnabled(isRingtoneEnabled);
boolean isCustomRingtoneEnabled = isRingtoneEnabled && mRingtoneCustom.isChecked();
findPreference(ConfigKey.RINGTONE_PATH.key()).setEnabled(isCustomRingtoneEnabled);
addPreferenceListener(ConfigKey.VIDEO_ENABLED, changeVideoPreferenceListener);
mRingtoneCustom.setOnPreferenceChangeListener(changeAudioPreferenceListener);
final Account acc = mCallbacks.getAccount();
if (acc != null) {
accountChanged(acc);
......@@ -203,9 +218,18 @@ public class MediaPreferenceFragment extends PreferenceFragment
final ConfigKey key = ConfigKey.fromString(preference.getKey());
if (preference instanceof TwoStatePreference) {
if (key == ConfigKey.RINGTONE_ENABLED) {
mRingtoneCustom.setEnabled((Boolean) newValue);
Boolean isEnabled = (Boolean) newValue && mRingtoneCustom.isChecked();
getPreferenceScreen().findPreference(ConfigKey.RINGTONE_PATH.key()).setEnabled(isEnabled);
} else if (preference == mRingtoneCustom) {
getPreferenceScreen().findPreference(ConfigKey.RINGTONE_PATH.key()).setEnabled((Boolean) newValue);
if (newValue.toString().contentEquals("false")) {
setRingtonepath(new File(FileUtils.ringtonesPath(getActivity()) + File.separator + "default.wav"));
}
}
if (key != null) {
account.setDetail(key, newValue.toString());
}
} else if (key == ConfigKey.ACCOUNT_DTMF_TYPE) {
preference.setSummary(((String) newValue).contentEquals("overrtp") ? "RTP" : "SIP");
} else {
......
......@@ -160,4 +160,8 @@ public class FileUtils {
}
return path;
}
public static String ringtonesPath(Context context) {
return context.getFilesDir().getAbsolutePath() + File.separator + "ringtones";
}
}
......@@ -80,6 +80,7 @@ along with this program; if not, write to the Free Software
<string name="account_ringtone_label">Ringtones</string>
<string name="account_ringtone_enabled_label">Activate ringtones</string>
<string name="account_ringtone_path_label">Ringtone path</string>
<string name="account_ringtone_custom_label">Use custom ringtone</string>
<!-- Video Details -->
<string name="account_video_label">Video</string>
......
......@@ -29,6 +29,12 @@ along with this program; if not, write to the Free Software
android:persistent="false"
android:title="@string/account_ringtone_enabled_label" />
<android.support.v14.preference.SwitchPreference
android:id="@+id/audio_ringtone_custom"
android:key="Account.ringtoneCustom"
android:persistent="true"
android:title="@string/account_ringtone_custom_label" />
<android.support.v7.preference.Preference
android:id="@+id/audio_ringtone_path"
android:key="Account.ringtonePath"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment