Android Open Source - Scanner-For-Zotero Manage Accounts Activity






From Project

Back to project page Scanner-For-Zotero.

License

The source code is released under:

GNU General Public License

If you think the Android project Scanner-For-Zotero listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/** 
 * Copyright 2011 John M. Schanck//from www  .ja  va2  s .  c o m
 * 
 * ScannerForZotero 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.
 * 
 * ScannerForZotero 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 ScannerForZotero.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.ale.scanner.zotero;

import org.ale.scanner.zotero.data.Account;
import org.ale.scanner.zotero.data.Database;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class ManageAccountsActivity extends ListActivity {

    private Cursor mCursor;

    private SimpleCursorAdapter mAdapter = null;

    private AlertDialog mAlertDialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        registerForContextMenu(getListView());
        
        updateList();
    }

    @Override
    protected void onPause(){
        super.onPause();
        if(mAlertDialog != null){
            mAlertDialog.dismiss();
            mAlertDialog = null;
            Dialogs.displayedDialog = Dialogs.DIALOG_NO_DIALOG;
        }
    }

    @SuppressWarnings("deprecation")
    protected void updateList(){
        String[] projection = new String[] { Account._ID,
                Account.COL_ALIAS, Account.COL_UID, Account.COL_KEY };
        mCursor = getContentResolver().query(Database.ACCOUNT_URI, projection,
                null, null, Account._ID + " ASC");
        startManagingCursor(mCursor);

        if(mAdapter == null){
            mAdapter = new SimpleCursorAdapter(
                    ManageAccountsActivity.this,
                    R.layout.account_row,
                    mCursor,
                    new String[] {Account.COL_ALIAS, Account.COL_UID, Account.COL_KEY},
                    new int[] {R.id.acct_row_alias, R.id.acct_row_id, R.id.acct_row_key});
        }else{
            mAdapter.changeCursor(mCursor);
        }
        setListAdapter(mAdapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int pos, long id) {
        v.showContextMenu();
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.acct_item_context_menu, menu);
        Cursor c = (Cursor) mAdapter.getItem(
                    ((AdapterView.AdapterContextMenuInfo)menuInfo).position);
        String title = c.getString(Database.ACCOUNT_ALIAS_INDEX);
        menu.setHeaderTitle(title);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info = 
            (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        Cursor c = (Cursor) mAdapter.getItem(info.position);
        int row = c.getInt(Database.ACCOUNT_ID_INDEX);
        switch (item.getItemId()) {
        case R.id.ctx_rename:
            String orig = c.getString(Database.ACCOUNT_ALIAS_INDEX);
            mAlertDialog = Dialogs.showRenameKeyDialog(
                                        ManageAccountsActivity.this, orig, row);
            break;
        case R.id.ctx_delete:
            String uid = c.getString(Database.ACCOUNT_UID_INDEX);
            Account.purgeAccount(getContentResolver(), row);
            deleteFile(uid); // Delete the user's shared preferences file

            updateList();
            if(mAdapter.getCount() == 0){
                Toast.makeText(ManageAccountsActivity.this, "No more accounts", Toast.LENGTH_LONG).show();
                finish();
            }
            break;
        }
        return true;
    }
}




Java Source Code List

org.ale.scanner.zotero.BibDetailJSONAdapter.java
org.ale.scanner.zotero.BibItemListAdapter.java
org.ale.scanner.zotero.Dialogs.java
org.ale.scanner.zotero.EditItemActivity.java
org.ale.scanner.zotero.LoginActivity.java
org.ale.scanner.zotero.MainActivity.java
org.ale.scanner.zotero.ManageAccountsActivity.java
org.ale.scanner.zotero.PString.java
org.ale.scanner.zotero.PendingListAdapter.java
org.ale.scanner.zotero.SafeViewFlipper.java
org.ale.scanner.zotero.Util.java
org.ale.scanner.zotero.data.Access.java
org.ale.scanner.zotero.data.Account.java
org.ale.scanner.zotero.data.BibItemDBHandler.java
org.ale.scanner.zotero.data.BibItem.java
org.ale.scanner.zotero.data.Collection.java
org.ale.scanner.zotero.data.CreatorType.java
org.ale.scanner.zotero.data.Database.java
org.ale.scanner.zotero.data.Group.java
org.ale.scanner.zotero.data.ItemField.java
org.ale.scanner.zotero.data.ItemType.java
org.ale.scanner.zotero.web.APIHandler.java
org.ale.scanner.zotero.web.APIRequest.java
org.ale.scanner.zotero.web.HttpsClient.java
org.ale.scanner.zotero.web.RequestQueue.java
org.ale.scanner.zotero.web.googlebooks.GoogleBooksAPIClient.java
org.ale.scanner.zotero.web.googlebooks.GoogleBooksHandler.java
org.ale.scanner.zotero.web.worldcat.WorldCatAPIClient.java
org.ale.scanner.zotero.web.worldcat.WorldCatHandler.java
org.ale.scanner.zotero.web.zotero.ZoteroAPIClient.java
org.ale.scanner.zotero.web.zotero.ZoteroHandler.java