2010-04-06 19:54:51 +00: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-03-09 16:27:29 +01:00
|
|
|
package org.apg.ui;
|
2010-04-06 19:54:51 +00:00
|
|
|
|
2011-10-17 10:07:37 +09:00
|
|
|
import java.security.Security;
|
2010-07-24 16:30:38 +00:00
|
|
|
|
2012-03-09 16:27:29 +01:00
|
|
|
import org.apg.Apg;
|
|
|
|
|
import org.apg.Id;
|
2011-10-17 10:07:37 +09:00
|
|
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
2012-03-09 16:27:29 +01:00
|
|
|
import org.apg.R;
|
2010-04-06 19:54:51 +00:00
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
import com.actionbarsherlock.app.ActionBar;
|
2012-03-11 17:33:40 +01:00
|
|
|
import com.actionbarsherlock.view.Menu;
|
|
|
|
|
import com.actionbarsherlock.view.MenuItem;
|
|
|
|
|
|
2010-04-06 19:54:51 +00:00
|
|
|
import android.app.Dialog;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.view.ContextMenu;
|
2010-07-09 20:55:17 +00:00
|
|
|
import android.view.ContextMenu.ContextMenuInfo;
|
2010-04-06 19:54:51 +00:00
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
major restructuring, moving dialog, message, menu, option menu, task, type IDs into Id in a similar structure as the generated R, also introducing a BaseActivity class that almost all activities derive from, which generates some common dialogs, handles the progress update, thread management, and thread communication
also adding first draft of encrypt file activity, not very functional yet
2010-04-19 02:12:13 +00:00
|
|
|
public class MainActivity extends BaseActivity {
|
2011-10-17 10:07:37 +09:00
|
|
|
static {
|
|
|
|
|
Security.addProvider(new BouncyCastleProvider());
|
|
|
|
|
}
|
2010-04-06 19:54:51 +00:00
|
|
|
|
2012-03-11 16:33:47 +01:00
|
|
|
public void manageKeysOnClick(View view) {
|
|
|
|
|
startActivity(new Intent(this, PublicKeyListActivity.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void myKeysOnClick(View view) {
|
|
|
|
|
startActivity(new Intent(this, SecretKeyListActivity.class));
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
public void encryptOnClick(View view) {
|
2012-03-11 16:33:47 +01:00
|
|
|
Intent intent = new Intent(MainActivity.this, EncryptActivity.class);
|
2012-03-12 00:12:19 +01:00
|
|
|
intent.setAction(Apg.Intent.ENCRYPT);
|
2012-03-11 16:33:47 +01:00
|
|
|
startActivity(intent);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
public void decryptOnClick(View view) {
|
2012-03-12 01:58:24 +01:00
|
|
|
Intent intent = new Intent(MainActivity.this, DecryptActivity.class);
|
2012-03-12 00:12:19 +01:00
|
|
|
intent.setAction(Apg.Intent.DECRYPT);
|
2012-03-11 16:33:47 +01:00
|
|
|
startActivity(intent);
|
2012-03-12 00:12:19 +01:00
|
|
|
}
|
2012-03-11 16:33:47 +01:00
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
public void scanQrcodeOnClick(View view) {
|
|
|
|
|
Intent intent = new Intent(this, ImportFromQRCodeActivity.class);
|
|
|
|
|
intent.setAction(Apg.Intent.IMPORT_FROM_QR_CODE);
|
|
|
|
|
startActivityForResult(intent, Id.request.import_from_qr_code);
|
2012-03-11 16:33:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void helpOnClick(View view) {
|
2012-03-12 15:10:26 +01:00
|
|
|
startActivity(new Intent(this, HelpActivity.class));
|
2012-03-11 16:33:47 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-06 19:54:51 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.main);
|
|
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
final ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(false);
|
2012-04-11 19:29:27 +02:00
|
|
|
actionBar.setHomeButtonEnabled(false);
|
2012-03-12 00:12:19 +01:00
|
|
|
|
|
|
|
|
// if (!mPreferences.hasSeenHelp()) {
|
|
|
|
|
// showDialog(Id.dialog.help);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (Apg.isReleaseVersion(this) && !mPreferences.hasSeenChangeLog(Apg.getVersion(this))) {
|
|
|
|
|
// showDialog(Id.dialog.change_log);
|
|
|
|
|
// }
|
2010-04-06 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Dialog onCreateDialog(int id) {
|
|
|
|
|
switch (id) {
|
|
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
// case Id.dialog.change_log: {
|
|
|
|
|
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
|
|
|
|
//
|
|
|
|
|
// alert.setTitle("Changes " + Apg.getFullVersion(this));
|
|
|
|
|
// LayoutInflater inflater = (LayoutInflater) this
|
|
|
|
|
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
// View layout = inflater.inflate(R.layout.info, null);
|
|
|
|
|
// TextView message = (TextView) layout.findViewById(R.id.message);
|
|
|
|
|
//
|
|
|
|
|
// message.setText("Changes:\n" + "* \n" + "\n"
|
|
|
|
|
// + "WARNING: be careful editing your existing keys, as they "
|
|
|
|
|
// + "WILL be stripped of certificates right now.\n" + "\n"
|
|
|
|
|
// + "Also: key cross-certification is NOT supported, so signing "
|
|
|
|
|
// + "with those keys will get a warning when the signature is " + "checked.\n"
|
|
|
|
|
// + "\n" + "I hope APG continues to be useful to you, please send "
|
|
|
|
|
// + "bug reports, feature wishes, feedback.");
|
|
|
|
|
// alert.setView(layout);
|
|
|
|
|
//
|
|
|
|
|
// alert.setCancelable(false);
|
|
|
|
|
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
// public void onClick(DialogInterface dialog, int id) {
|
|
|
|
|
// MainActivity.this.removeDialog(Id.dialog.change_log);
|
|
|
|
|
// mPreferences.setHasSeenChangeLog(Apg.getVersion(MainActivity.this), true);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// return alert.create();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// case Id.dialog.help: {
|
|
|
|
|
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
|
|
|
|
//
|
|
|
|
|
// alert.setTitle(R.string.title_help);
|
|
|
|
|
//
|
|
|
|
|
// LayoutInflater inflater = (LayoutInflater) this
|
|
|
|
|
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
// View layout = inflater.inflate(R.layout.info, null);
|
|
|
|
|
// TextView message = (TextView) layout.findViewById(R.id.message);
|
|
|
|
|
// message.setText(R.string.text_help);
|
|
|
|
|
//
|
|
|
|
|
// TransformFilter packageNames = new TransformFilter() {
|
|
|
|
|
// public final String transformUrl(final Matcher match, String url) {
|
|
|
|
|
// String name = match.group(1).toLowerCase();
|
|
|
|
|
// if (name.equals("astro")) {
|
|
|
|
|
// return "com.metago.astro";
|
|
|
|
|
// } else if (name.equals("k-9 mail")) {
|
|
|
|
|
// return "com.fsck.k9";
|
|
|
|
|
// } else {
|
|
|
|
|
// return "org.openintents.filemanager";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// };
|
|
|
|
|
//
|
|
|
|
|
// Pattern pattern = Pattern.compile("(OI File Manager|ASTRO|K-9 Mail)");
|
|
|
|
|
// String scheme = "market://search?q=pname:";
|
|
|
|
|
// message.setAutoLinkMask(0);
|
|
|
|
|
// Linkify.addLinks(message, pattern, scheme, null, packageNames);
|
|
|
|
|
//
|
|
|
|
|
// alert.setView(layout);
|
|
|
|
|
//
|
|
|
|
|
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
|
// public void onClick(DialogInterface dialog, int id) {
|
|
|
|
|
// MainActivity.this.removeDialog(Id.dialog.help);
|
|
|
|
|
// mPreferences.setHasSeenHelp(true);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
//
|
|
|
|
|
// return alert.create();
|
|
|
|
|
// }
|
2010-07-24 16:30:38 +00:00
|
|
|
|
2012-03-10 21:36:08 +01:00
|
|
|
default: {
|
|
|
|
|
return super.onCreateDialog(id);
|
|
|
|
|
}
|
2010-04-06 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2012-03-12 00:12:19 +01:00
|
|
|
menu.add(0, Id.menu.option.preferences, 0, R.string.menu_preferences)
|
2012-03-12 14:28:35 +01:00
|
|
|
.setIcon(R.drawable.ic_menu_settings)
|
|
|
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
|
|
|
|
menu.add(0, Id.menu.option.about, 1, R.string.menu_about).setIcon(R.drawable.ic_menu_about)
|
2012-03-12 00:12:19 +01:00
|
|
|
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
2010-04-06 19:54:51 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
switch (item.getItemId()) {
|
2012-03-12 00:12:19 +01:00
|
|
|
case Id.menu.option.about: {
|
|
|
|
|
startActivity(new Intent(this, AboutActivity.class));
|
2012-03-10 21:36:08 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-04-28 23:35:11 +00:00
|
|
|
|
2012-03-12 00:12:19 +01:00
|
|
|
case Id.menu.option.preferences: {
|
|
|
|
|
startActivity(new Intent(this, PreferencesActivity.class));
|
2012-03-10 21:36:08 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-08-17 01:02:39 +00:00
|
|
|
|
2012-03-10 21:36:08 +01:00
|
|
|
default: {
|
2012-03-12 00:12:19 +01:00
|
|
|
break;
|
2012-03-10 21:36:08 +01:00
|
|
|
}
|
2010-04-06 19:54:51 +00:00
|
|
|
}
|
2012-03-12 00:12:19 +01:00
|
|
|
return false;
|
2010-04-06 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
|
|
|
super.onCreateContextMenu(menu, v, menuInfo);
|
|
|
|
|
|
2010-05-13 20:41:32 +00:00
|
|
|
TextView nameTextView = (TextView) v.findViewById(R.id.accountName);
|
2010-04-06 19:54:51 +00:00
|
|
|
if (nameTextView != null) {
|
|
|
|
|
menu.setHeaderTitle(nameTextView.getText());
|
2010-05-13 20:41:32 +00:00
|
|
|
menu.add(0, Id.menu.delete, 0, R.string.menu_deleteAccount);
|
2010-04-06 19:54:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|