2010-04-28 19:35:11 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.thialfihar.android.apg;
|
|
|
|
|
|
|
|
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
|
|
|
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
|
|
|
import org.thialfihar.android.apg.utils.Choice;
|
|
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.AdapterView.OnItemSelectedListener;
|
|
|
|
|
|
|
|
public class PreferencesActivity extends BaseActivity {
|
2010-05-15 12:09:49 -04:00
|
|
|
private Spinner mPassPhraseCache = null;
|
2010-04-28 19:35:11 -04:00
|
|
|
private Spinner mEncryptionAlgorithm = null;
|
|
|
|
private Spinner mHashAlgorithm = null;
|
|
|
|
private CheckBox mAsciiArmour = null;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.preferences);
|
|
|
|
|
2010-05-15 12:09:49 -04:00
|
|
|
mPassPhraseCache = (Spinner) findViewById(R.id.passPhraseCache);
|
|
|
|
|
|
|
|
Choice choices[] = {
|
|
|
|
new Choice(15, getString(R.string.choice_15secs)),
|
|
|
|
new Choice(60, getString(R.string.choice_1min)),
|
|
|
|
new Choice(180, getString(R.string.choice_3mins)),
|
|
|
|
new Choice(300, getString(R.string.choice_5mins)),
|
|
|
|
new Choice(600, getString(R.string.choice_10mins)),
|
|
|
|
new Choice(0, getString(R.string.choice_untilQuit)),
|
|
|
|
};
|
|
|
|
ArrayAdapter<Choice> adapter =
|
|
|
|
new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
|
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
mPassPhraseCache.setAdapter(adapter);
|
|
|
|
|
2010-05-16 09:17:45 -04:00
|
|
|
int passPhraseCache = getPassPhraseCacheTtl();
|
2010-05-15 12:09:49 -04:00
|
|
|
for (int i = 0; i < choices.length; ++i) {
|
|
|
|
if (choices[i].getId() == passPhraseCache) {
|
|
|
|
mPassPhraseCache.setSelection(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mPassPhraseCache.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
2010-05-16 09:17:45 -04:00
|
|
|
setPassPhraseCacheTtl(((Choice) mPassPhraseCache.getSelectedItem()).getId());
|
2010-05-15 12:09:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> adapter) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-05-13 16:41:32 -04:00
|
|
|
mEncryptionAlgorithm = (Spinner) findViewById(R.id.encryptionAlgorithm);
|
|
|
|
mHashAlgorithm = (Spinner) findViewById(R.id.hashAlgorithm);
|
|
|
|
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
|
2010-04-28 19:35:11 -04:00
|
|
|
|
|
|
|
mAsciiArmour.setChecked(getDefaultAsciiArmour());
|
|
|
|
|
2010-05-15 12:09:49 -04:00
|
|
|
choices = new Choice[] {
|
2010-04-28 19:35:11 -04:00
|
|
|
new Choice(PGPEncryptedData.AES_128, "AES 128"),
|
|
|
|
new Choice(PGPEncryptedData.AES_192, "AES 192"),
|
|
|
|
new Choice(PGPEncryptedData.AES_256, "AES 256"),
|
|
|
|
new Choice(PGPEncryptedData.BLOWFISH, "Blowfish"),
|
|
|
|
new Choice(PGPEncryptedData.TWOFISH, "Twofish"),
|
|
|
|
new Choice(PGPEncryptedData.CAST5, "CAST5"),
|
|
|
|
new Choice(PGPEncryptedData.DES, "DES"),
|
|
|
|
new Choice(PGPEncryptedData.TRIPLE_DES, "Triple DES"),
|
|
|
|
new Choice(PGPEncryptedData.IDEA, "IDEA"),
|
|
|
|
};
|
2010-05-15 12:09:49 -04:00
|
|
|
adapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
2010-04-28 19:35:11 -04:00
|
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
mEncryptionAlgorithm.setAdapter(adapter);
|
|
|
|
|
2010-05-15 12:09:49 -04:00
|
|
|
int defaultEncryptionAlgorithm = getDefaultEncryptionAlgorithm();
|
2010-04-28 19:35:11 -04:00
|
|
|
for (int i = 0; i < choices.length; ++i) {
|
2010-05-15 12:09:49 -04:00
|
|
|
if (choices[i].getId() == defaultEncryptionAlgorithm) {
|
2010-04-28 19:35:11 -04:00
|
|
|
mEncryptionAlgorithm.setSelection(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mEncryptionAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
|
|
|
setDefaultEncryptionAlgorithm(((Choice) mEncryptionAlgorithm.getSelectedItem()).getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> adapter) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-05-15 12:09:49 -04:00
|
|
|
choices = new Choice[] {
|
2010-04-28 19:35:11 -04:00
|
|
|
new Choice(HashAlgorithmTags.MD5, "MD5"),
|
|
|
|
new Choice(HashAlgorithmTags.RIPEMD160, "RIPEMD160"),
|
|
|
|
new Choice(HashAlgorithmTags.SHA1, "SHA1"),
|
|
|
|
new Choice(HashAlgorithmTags.SHA224, "SHA224"),
|
|
|
|
new Choice(HashAlgorithmTags.SHA256, "SHA256"),
|
|
|
|
new Choice(HashAlgorithmTags.SHA384, "SHA384"),
|
|
|
|
new Choice(HashAlgorithmTags.SHA512, "SHA512"),
|
|
|
|
};
|
2010-05-15 12:09:49 -04:00
|
|
|
adapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
2010-04-28 19:35:11 -04:00
|
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
|
|
mHashAlgorithm.setAdapter(adapter);
|
|
|
|
|
2010-05-15 12:09:49 -04:00
|
|
|
int defaultHashAlgorithm = getDefaultHashAlgorithm();
|
|
|
|
for (int i = 0; i < choices.length; ++i) {
|
|
|
|
if (choices[i].getId() == defaultHashAlgorithm) {
|
2010-04-28 19:35:11 -04:00
|
|
|
mHashAlgorithm.setSelection(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mHashAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
|
|
|
setDefaultHashAlgorithm(((Choice) mHashAlgorithm.getSelectedItem()).getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> adapter) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mAsciiArmour.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
setDefaultAsciiArmour(mAsciiArmour.isChecked());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|