parent
44a4570870
commit
e650349bb7
3 changed files with 80 additions and 22 deletions
|
@ -502,6 +502,9 @@
|
|||
<string name="MmsPreferencesFragment__manual_mms_settings_are_required">Manual MMS settings are required for your phone.</string>
|
||||
<string name="MmsPreferencesFragment__enabled">Enabled</string>
|
||||
<string name="MmsPreferencesFragment__disabled">Disabled</string>
|
||||
<string name="MmsPreferencesFragment__not_set">Not set</string>
|
||||
<string name="MmsPreferencesFragment__invalid_uri">The text entered was not a valid URI</string>
|
||||
<string name="MmsPreferencesFragment__invalid_host">The text entered was not a valid host</string>
|
||||
|
||||
<!-- prompt_passphrase_activity -->
|
||||
<string name="prompt_passphrase_activity__unlock">Unlock</string>
|
||||
|
|
|
@ -20,12 +20,17 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMmsConnection;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
|
||||
public class MmsPreferencesFragment extends PreferenceFragment {
|
||||
|
||||
|
@ -47,22 +52,15 @@ public class MmsPreferencesFragment extends PreferenceFragment {
|
|||
} else {
|
||||
addPreferencesFromResource(R.xml.preferences_manual_mms);
|
||||
}
|
||||
this.findPreference(TextSecurePreferences.MMSC_HOST_PREF).setOnPreferenceChangeListener(new ValidUriVerificationListener());
|
||||
this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF).setOnPreferenceChangeListener(new ValidHostnameVerificationListener());
|
||||
this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF).setOnPreferenceChangeListener(new EditTextVerificationListener());
|
||||
this.findPreference(TextSecurePreferences.MMSC_USERNAME_PREF).setOnPreferenceChangeListener(new EditTextVerificationListener());
|
||||
this.findPreference(TextSecurePreferences.MMSC_PASSWORD_PREF).setOnPreferenceChangeListener(new EditTextVerificationListener());
|
||||
}
|
||||
|
||||
private void initializeEditTextSummary(final EditTextPreference preference) {
|
||||
if (preference.getText() == null) {
|
||||
preference.setSummary("Not set");
|
||||
} else {
|
||||
preference.setSummary(preference.getText());
|
||||
}
|
||||
|
||||
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference pref, Object newValue) {
|
||||
preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
preference.setSummary(TextUtils.isEmpty(preference.getText()) ? getString(R.string.MmsPreferencesFragment__not_set) : preference.getText());
|
||||
}
|
||||
|
||||
private void initializeEditTextSummaries() {
|
||||
|
@ -89,4 +87,57 @@ public class MmsPreferencesFragment extends PreferenceFragment {
|
|||
|
||||
return context.getString(TextSecurePreferences.isUseLocalApnsEnabled(context) ? enabledResId : disabledResId);
|
||||
}
|
||||
|
||||
private class EditTextVerificationListener implements OnPreferenceChangeListener {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String newString = (String)newValue;
|
||||
if (isValid(newString)) {
|
||||
preference.setSummary(TextUtils.isEmpty(newString) ? getString(R.string.MmsPreferencesFragment__not_set) : newString);
|
||||
return true;
|
||||
} else {
|
||||
Toast.makeText(getActivity(), getErrorMessage(), Toast.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isValid(String newString) { return true; }
|
||||
protected int getErrorMessage() { return 0; }
|
||||
}
|
||||
|
||||
private class ValidUriVerificationListener extends EditTextVerificationListener {
|
||||
@Override
|
||||
protected boolean isValid(String newString) {
|
||||
if (TextUtils.isEmpty(newString)) return true;
|
||||
try {
|
||||
new URI(newString);
|
||||
return true;
|
||||
} catch (URISyntaxException mue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getErrorMessage() {
|
||||
return R.string.MmsPreferencesFragment__invalid_uri;
|
||||
}
|
||||
}
|
||||
|
||||
private class ValidHostnameVerificationListener extends EditTextVerificationListener {
|
||||
@Override
|
||||
protected boolean isValid(String newString) {
|
||||
if (TextUtils.isEmpty(newString)) return true;
|
||||
try {
|
||||
URI uri = new URI(null, newString, null, null);
|
||||
return true;
|
||||
} catch (URISyntaxException mue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getErrorMessage() {
|
||||
return R.string.MmsPreferencesFragment__invalid_host;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class OutgoingMmsConnection extends MmsConnection {
|
|||
protected HttpUriRequest constructRequest(boolean useProxy)
|
||||
throws IOException
|
||||
{
|
||||
try {
|
||||
HttpPostHC4 request = new HttpPostHC4(apn.getMmsc());
|
||||
request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
|
||||
request.addHeader("x-wap-profile", "http://www.google.com/oha/rdf/ua-profile-kila.xml");
|
||||
|
@ -57,6 +58,9 @@ public class OutgoingMmsConnection extends MmsConnection {
|
|||
request.setConfig(RequestConfig.custom().setProxy(proxy).build());
|
||||
}
|
||||
return request;
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw new IOException(iae);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendNotificationReceived(boolean usingMmsRadio, boolean useProxyIfAvailable)
|
||||
|
|
Loading…
Add table
Reference in a new issue