mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-24 01:32:16 -05:00
dropping gmail support, k9 mail support is more important, in any case gmail support is not working as of android 2.3 and later
This commit is contained in:
parent
328da74eb2
commit
9ce7842ac9
@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingLeft="5dip"
|
|
||||||
android:paddingRight="5dip">
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/input"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="textEmailAddress"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@ -35,7 +35,6 @@
|
|||||||
<string name="title_sendEmail">"Send Mail..."</string>
|
<string name="title_sendEmail">"Send Mail..."</string>
|
||||||
<string name="title_encryptToFile">Encrypt To File</string>
|
<string name="title_encryptToFile">Encrypt To File</string>
|
||||||
<string name="title_decryptToFile">Decrypt To File</string>
|
<string name="title_decryptToFile">Decrypt To File</string>
|
||||||
<string name="title_addAccount">Add Account</string>
|
|
||||||
<string name="title_importKeys">Import Keys</string>
|
<string name="title_importKeys">Import Keys</string>
|
||||||
<string name="title_exportKey">Export Key</string>
|
<string name="title_exportKey">Export Key</string>
|
||||||
<string name="title_exportKeys">Export Keys</string>
|
<string name="title_exportKeys">Export Keys</string>
|
||||||
@ -203,7 +202,6 @@
|
|||||||
<string name="selectEncryptionOrSignatureKey">Select at least one encryption key or a signature key.</string>
|
<string name="selectEncryptionOrSignatureKey">Select at least one encryption key or a signature key.</string>
|
||||||
<string name="specifyFileToEncryptTo">Please specify which file to encrypt to.\nWARNING! File will be overwritten if it exists.</string>
|
<string name="specifyFileToEncryptTo">Please specify which file to encrypt to.\nWARNING! File will be overwritten if it exists.</string>
|
||||||
<string name="specifyFileToDecryptTo">Please specify which file to decrypt to.\nWARNING! File will be overwritten if it exists.</string>
|
<string name="specifyFileToDecryptTo">Please specify which file to decrypt to.\nWARNING! File will be overwritten if it exists.</string>
|
||||||
<string name="specifyGoogleMailAccount">Specify the Google Mail account you want to add.</string>
|
|
||||||
<string name="specifyFileToImportFrom">Please specify which file to import keys from. (.asc or .gpg)</string>
|
<string name="specifyFileToImportFrom">Please specify which file to import keys from. (.asc or .gpg)</string>
|
||||||
<string name="specifyFileToExportTo">Please specify which file to export to.\nWARNING! File will be overwritten if it exists.</string>
|
<string name="specifyFileToExportTo">Please specify which file to export to.\nWARNING! File will be overwritten if it exists.</string>
|
||||||
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
|
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
|
||||||
@ -236,8 +234,6 @@
|
|||||||
<string name="error_noSecretKeyFound">no suitable secret key found</string>
|
<string name="error_noSecretKeyFound">no suitable secret key found</string>
|
||||||
<string name="error_noKnownEncryptionFound">no known kind of encryption found</string>
|
<string name="error_noKnownEncryptionFound">no known kind of encryption found</string>
|
||||||
<string name="error_externalStorageNotReady">external storage not ready</string>
|
<string name="error_externalStorageNotReady">external storage not ready</string>
|
||||||
<string name="error_accountNotFound">account \'%s\' not found</string>
|
|
||||||
<string name="error_accountReadingNotAllowed">no permission to read the account</string>
|
|
||||||
<string name="error_addingAccountFailed">adding account \'%s\' failed</string>
|
<string name="error_addingAccountFailed">adding account \'%s\' failed</string>
|
||||||
<string name="error_invalidEmail">invalid email \'%s\'</string>
|
<string name="error_invalidEmail">invalid email \'%s\'</string>
|
||||||
<string name="error_keySizeMinimum512bit">key size must be at least 512bit</string>
|
<string name="error_keySizeMinimum512bit">key size must be at least 512bit</string>
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.apg.provider;
|
|
||||||
|
|
||||||
import android.provider.BaseColumns;
|
|
||||||
|
|
||||||
public class Accounts implements BaseColumns {
|
|
||||||
public static final String TABLE_NAME = "accounts";
|
|
||||||
|
|
||||||
public static final String _ID_type = "INTEGER PRIMARY KEY";
|
|
||||||
public static final String NAME = "c_name";
|
|
||||||
public static final String NAME_type = "TEXT";
|
|
||||||
}
|
|
@ -116,9 +116,6 @@ public class Database extends SQLiteOpenHelper {
|
|||||||
UserIds.USER_ID + " " + UserIds.USER_ID_type + "," +
|
UserIds.USER_ID + " " + UserIds.USER_ID_type + "," +
|
||||||
UserIds.RANK + " " + UserIds.RANK_type + ");");
|
UserIds.RANK + " " + UserIds.RANK_type + ");");
|
||||||
|
|
||||||
db.execSQL("CREATE TABLE " + Accounts.TABLE_NAME + " (" +
|
|
||||||
Accounts._ID + " " + Accounts._ID_type + "," +
|
|
||||||
Accounts.NAME + " " + Accounts.NAME_type + ");");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,22 +22,14 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.apg.Apg;
|
import org.apg.Apg;
|
||||||
import org.apg.Id;
|
import org.apg.Id;
|
||||||
import org.apg.Id.dialog;
|
|
||||||
import org.apg.Id.menu;
|
|
||||||
import org.apg.Id.menu.option;
|
|
||||||
import org.apg.provider.Accounts;
|
|
||||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.apg.R;
|
import org.apg.R;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.SQLException;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
import android.text.util.Linkify.TransformFilter;
|
import android.text.util.Linkify.TransformFilter;
|
||||||
@ -48,25 +40,14 @@ import android.view.Menu;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CursorAdapter;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class MainActivity extends BaseActivity {
|
public class MainActivity extends BaseActivity {
|
||||||
static {
|
static {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListView mAccounts = null;
|
|
||||||
private AccountListAdapter mListAdapter = null;
|
|
||||||
private Cursor mAccountCursor;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -76,7 +57,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
Button decryptMessageButton = (Button) findViewById(R.id.btn_decryptMessage);
|
Button decryptMessageButton = (Button) findViewById(R.id.btn_decryptMessage);
|
||||||
Button encryptFileButton = (Button) findViewById(R.id.btn_encryptFile);
|
Button encryptFileButton = (Button) findViewById(R.id.btn_encryptFile);
|
||||||
Button decryptFileButton = (Button) findViewById(R.id.btn_decryptFile);
|
Button decryptFileButton = (Button) findViewById(R.id.btn_decryptFile);
|
||||||
mAccounts = (ListView) findViewById(R.id.accounts);
|
|
||||||
|
|
||||||
encryptMessageButton.setOnClickListener(new OnClickListener() {
|
encryptMessageButton.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -110,25 +90,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAccountCursor =
|
|
||||||
Apg.getDatabase().db().query(Accounts.TABLE_NAME,
|
|
||||||
new String[] {
|
|
||||||
Accounts._ID,
|
|
||||||
Accounts.NAME,
|
|
||||||
}, null, null, null, null, Accounts.NAME + " ASC");
|
|
||||||
startManagingCursor(mAccountCursor);
|
|
||||||
|
|
||||||
mListAdapter = new AccountListAdapter(this, mAccountCursor);
|
|
||||||
mAccounts.setAdapter(mListAdapter);
|
|
||||||
mAccounts.setOnItemClickListener(new OnItemClickListener() {
|
|
||||||
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
|
|
||||||
String accountName = (String) mAccounts.getItemAtPosition(index);
|
|
||||||
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
|
||||||
.putExtra(MailListActivity.EXTRA_ACCOUNT, accountName));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
registerForContextMenu(mAccounts);
|
|
||||||
|
|
||||||
if (!mPreferences.hasSeenHelp()) {
|
if (!mPreferences.hasSeenHelp()) {
|
||||||
showDialog(Id.dialog.help);
|
showDialog(Id.dialog.help);
|
||||||
}
|
}
|
||||||
@ -141,103 +102,30 @@ public class MainActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case Id.dialog.new_account: {
|
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
|
||||||
|
|
||||||
alert.setTitle(R.string.title_addAccount);
|
|
||||||
alert.setMessage(R.string.specifyGoogleMailAccount);
|
|
||||||
|
|
||||||
LayoutInflater inflater =
|
|
||||||
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
View view = inflater.inflate(R.layout.add_account_dialog, null);
|
|
||||||
|
|
||||||
final EditText input = (EditText) view.findViewById(R.id.input);
|
|
||||||
alert.setView(view);
|
|
||||||
|
|
||||||
alert.setPositiveButton(android.R.string.ok,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
MainActivity.this.removeDialog(Id.dialog.new_account);
|
|
||||||
String accountName = "" + input.getText();
|
|
||||||
|
|
||||||
try {
|
|
||||||
Cursor testCursor =
|
|
||||||
managedQuery(Uri.parse("content://gmail-ls/conversations/" +
|
|
||||||
accountName),
|
|
||||||
null, null, null, null);
|
|
||||||
if (testCursor == null) {
|
|
||||||
Toast.makeText(MainActivity.this,
|
|
||||||
getString(R.string.errorMessage,
|
|
||||||
getString(R.string.error_accountNotFound,
|
|
||||||
accountName)),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
Toast.makeText(MainActivity.this,
|
|
||||||
getString(R.string.errorMessage,
|
|
||||||
getString(R.string.error_accountReadingNotAllowed)),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(Accounts.NAME, accountName);
|
|
||||||
try {
|
|
||||||
Apg.getDatabase().db().insert(Accounts.TABLE_NAME,
|
|
||||||
Accounts.NAME, values);
|
|
||||||
mAccountCursor.requery();
|
|
||||||
mListAdapter.notifyDataSetChanged();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Toast.makeText(MainActivity.this,
|
|
||||||
getString(R.string.errorMessage,
|
|
||||||
getString(R.string.error_addingAccountFailed,
|
|
||||||
accountName)),
|
|
||||||
Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alert.setNegativeButton(android.R.string.cancel,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
MainActivity.this.removeDialog(Id.dialog.new_account);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return alert.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
case Id.dialog.change_log: {
|
case Id.dialog.change_log: {
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||||
|
|
||||||
alert.setTitle("Changes " + Apg.getFullVersion(this));
|
alert.setTitle("Changes " + Apg.getFullVersion(this));
|
||||||
LayoutInflater inflater =
|
LayoutInflater inflater = (LayoutInflater) this
|
||||||
(LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View layout = inflater.inflate(R.layout.info, null);
|
View layout = inflater.inflate(R.layout.info, null);
|
||||||
TextView message = (TextView) layout.findViewById(R.id.message);
|
TextView message = (TextView) layout.findViewById(R.id.message);
|
||||||
|
|
||||||
message.setText("Changes:\n" +
|
message.setText("Changes:\n" + "* \n" + "\n"
|
||||||
"* \n" +
|
+ "WARNING: be careful editing your existing keys, as they "
|
||||||
"\n" +
|
+ "WILL be stripped of certificates right now.\n" + "\n"
|
||||||
"WARNING: be careful editing your existing keys, as they " +
|
+ "Also: key cross-certification is NOT supported, so signing "
|
||||||
"WILL be stripped of certificates right now.\n" +
|
+ "with those keys will get a warning when the signature is " + "checked.\n"
|
||||||
"\n" +
|
+ "\n" + "I hope APG continues to be useful to you, please send "
|
||||||
"Also: key cross-certification is NOT supported, so signing " +
|
+ "bug reports, feature wishes, feedback.");
|
||||||
"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.setView(layout);
|
||||||
|
|
||||||
alert.setCancelable(false);
|
alert.setCancelable(false);
|
||||||
alert.setPositiveButton(android.R.string.ok,
|
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainActivity.this.removeDialog(Id.dialog.change_log);
|
MainActivity.this.removeDialog(Id.dialog.change_log);
|
||||||
mPreferences.setHasSeenChangeLog(
|
mPreferences.setHasSeenChangeLog(Apg.getVersion(MainActivity.this), true);
|
||||||
Apg.getVersion(MainActivity.this), true);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -249,8 +137,8 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
alert.setTitle(R.string.title_help);
|
alert.setTitle(R.string.title_help);
|
||||||
|
|
||||||
LayoutInflater inflater =
|
LayoutInflater inflater = (LayoutInflater) this
|
||||||
(LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View layout = inflater.inflate(R.layout.info, null);
|
View layout = inflater.inflate(R.layout.info, null);
|
||||||
TextView message = (TextView) layout.findViewById(R.id.message);
|
TextView message = (TextView) layout.findViewById(R.id.message);
|
||||||
message.setText(R.string.text_help);
|
message.setText(R.string.text_help);
|
||||||
@ -275,8 +163,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
alert.setView(layout);
|
alert.setView(layout);
|
||||||
|
|
||||||
alert.setPositiveButton(android.R.string.ok,
|
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainActivity.this.removeDialog(Id.dialog.help);
|
MainActivity.this.removeDialog(Id.dialog.help);
|
||||||
mPreferences.setHasSeenHelp(true);
|
mPreferences.setHasSeenHelp(true);
|
||||||
@ -294,20 +181,20 @@ public class MainActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
menu.add(0, Id.menu.option.manage_public_keys, 0, R.string.menu_managePublicKeys)
|
menu.add(0, Id.menu.option.manage_public_keys, 0, R.string.menu_managePublicKeys).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_manage);
|
android.R.drawable.ic_menu_manage);
|
||||||
menu.add(0, Id.menu.option.manage_secret_keys, 1, R.string.menu_manageSecretKeys)
|
menu.add(0, Id.menu.option.manage_secret_keys, 1, R.string.menu_manageSecretKeys).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_manage);
|
android.R.drawable.ic_menu_manage);
|
||||||
menu.add(1, Id.menu.option.create, 2, R.string.menu_addAccount)
|
menu.add(1, Id.menu.option.create, 2, R.string.menu_addAccount).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_add);
|
android.R.drawable.ic_menu_add);
|
||||||
menu.add(2, Id.menu.option.preferences, 3, R.string.menu_preferences)
|
menu.add(2, Id.menu.option.preferences, 3, R.string.menu_preferences).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_preferences);
|
android.R.drawable.ic_menu_preferences);
|
||||||
menu.add(2, Id.menu.option.key_server, 4, R.string.menu_keyServer)
|
menu.add(2, Id.menu.option.key_server, 4, R.string.menu_keyServer).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_search);
|
android.R.drawable.ic_menu_search);
|
||||||
menu.add(3, Id.menu.option.about, 5, R.string.menu_about)
|
menu.add(3, Id.menu.option.about, 5, R.string.menu_about).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_info_details);
|
android.R.drawable.ic_menu_info_details);
|
||||||
menu.add(3, Id.menu.option.help, 6, R.string.menu_help)
|
menu.add(3, Id.menu.option.help, 6, R.string.menu_help).setIcon(
|
||||||
.setIcon(android.R.drawable.ic_menu_help);
|
android.R.drawable.ic_menu_help);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,64 +243,4 @@ public class MainActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
|
||||||
AdapterView.AdapterContextMenuInfo info =
|
|
||||||
(AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
|
|
||||||
|
|
||||||
switch (menuItem.getItemId()) {
|
|
||||||
case Id.menu.delete: {
|
|
||||||
Apg.getDatabase().db().delete(Accounts.TABLE_NAME,
|
|
||||||
Accounts._ID + " = ?",
|
|
||||||
new String[] { "" + info.id });
|
|
||||||
mAccountCursor.requery();
|
|
||||||
mListAdapter.notifyDataSetChanged();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
return super.onContextItemSelected(menuItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static class AccountListAdapter extends CursorAdapter {
|
|
||||||
private LayoutInflater mInflater;
|
|
||||||
|
|
||||||
public AccountListAdapter(Context context, Cursor cursor) {
|
|
||||||
super(context, cursor);
|
|
||||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getItem(int position) {
|
|
||||||
Cursor c = getCursor();
|
|
||||||
c.moveToPosition(position);
|
|
||||||
return c.getString(c.getColumnIndex(Accounts.NAME));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return super.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
||||||
return mInflater.inflate(R.layout.account_item, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
|
||||||
TextView nameTextView = (TextView) view.findViewById(R.id.accountName);
|
|
||||||
int nameIndex = cursor.getColumnIndex(Accounts.NAME);
|
|
||||||
final String account = cursor.getString(nameIndex);
|
|
||||||
nameTextView.setText(account);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int position) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user