2013-09-16 07:55:01 +00:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2011 Whisper Systems
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.preference.EditTextPreference;
|
|
|
|
import android.preference.Preference;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
2014-09-16 23:21:41 +00:00
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.mms.IncomingMmsConnection;
|
2013-09-16 07:55:01 +00:00
|
|
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
|
|
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
|
|
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
2013-11-18 23:29:19 +00:00
|
|
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
|
|
|
import org.whispersystems.textsecure.crypto.MasterSecret;
|
2013-09-16 07:55:01 +00:00
|
|
|
|
|
|
|
public class MmsPreferencesActivity extends PassphraseRequiredSherlockPreferenceActivity {
|
|
|
|
|
|
|
|
private MasterSecret masterSecret;
|
|
|
|
|
|
|
|
private final DynamicTheme dynamicTheme = new DynamicTheme();
|
|
|
|
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
dynamicTheme.onCreate(this);
|
|
|
|
dynamicLanguage.onCreate(this);
|
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
initializePreferences();
|
|
|
|
|
|
|
|
masterSecret = getIntent().getParcelableExtra("master_secret");
|
|
|
|
|
|
|
|
initializeEditTextSummaries();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
dynamicTheme.onResume(this);
|
|
|
|
dynamicLanguage.onResume(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
MemoryCleaner.clean(masterSecret);
|
|
|
|
MemoryCleaner.clean((MasterSecret) getIntent().getParcelableExtra("master_secret"));
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
handleDownloadMmsPendingApn();
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
handleDownloadMmsPendingApn();
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializePreferences() {
|
2014-09-16 23:21:41 +00:00
|
|
|
if (!IncomingMmsConnection.isConnectionPossible(this, null)) {
|
2014-05-05 18:48:26 +00:00
|
|
|
TextSecurePreferences.setUseLocalApnsEnabled(this, true);
|
2013-09-16 07:55:01 +00:00
|
|
|
addPreferencesFromResource(R.xml.mms_preferences);
|
2013-11-18 23:29:19 +00:00
|
|
|
this.findPreference(TextSecurePreferences.ENABLE_MANUAL_MMS_PREF).setOnPreferenceChangeListener(new OverrideMmsChangeListener());
|
2013-09-16 07:55:01 +00:00
|
|
|
} else {
|
|
|
|
addPreferencesFromResource(R.xml.mms_preferences);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initializeEditTextSummaries() {
|
2013-11-18 23:29:19 +00:00
|
|
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_HOST_PREF));
|
|
|
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF));
|
|
|
|
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF));
|
2013-09-16 07:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void handleDownloadMmsPendingApn() {
|
|
|
|
Intent intent = new Intent(this, SendReceiveService.class);
|
|
|
|
intent.setAction(SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION);
|
|
|
|
startService(intent);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class OverrideMmsChangeListener implements Preference.OnPreferenceChangeListener {
|
|
|
|
@Override
|
|
|
|
public boolean onPreferenceChange(Preference preference, Object o) {
|
2014-05-05 18:48:26 +00:00
|
|
|
TextSecurePreferences.setUseLocalApnsEnabled(MmsPreferencesActivity.this, true);
|
2013-09-16 07:55:01 +00:00
|
|
|
Toast.makeText(MmsPreferencesActivity.this, R.string.mms_preferences_activity__manual_mms_settings_are_required, Toast.LENGTH_SHORT).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|