/* * Copyright (C) 2007 The Android Open Source Project * * 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 com.android.phone; import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ListView; import android.util.Log; import android.widget.Toast; /** * FDN List UI for the Phone app. */ public class FdnList extends ADNList { private static final int MENU_ADD = 1; private static final int MENU_EDIT = 2; private static final int MENU_DELETE = 3; private static final String INTENT_EXTRA_NAME = "name"; private static final String INTENT_EXTRA_NUMBER = "number"; private int mSubId = 0; private static final String[] COLUMN_NAMES = new String[] { "name", "number" }; @Override protected Uri resolveIntent() { Log.i("FdnList","resolveIntent"); Intent intent = getIntent(); //for ds mSubId = intent.getIntExtra(CallSettingOptions.SUB_ID, 0); if (0 == mSubId) { intent.setData(Uri.parse("content://icc/fdn")); } else if (1 == mSubId) { intent.setData(Uri.parse("content://icc1/fdn")); } return intent.getData(); } @Override protected String[] getQueryColumnNames(){ return COLUMN_NAMES; } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); Resources r = getResources(); // Added the icons to the context menu menu.add(0, MENU_ADD, 0, r.getString(R.string.menu_add)) .setIcon(android.R.drawable.ic_menu_add); menu.add(0, MENU_EDIT, 0, r.getString(R.string.menu_edit)) .setIcon(android.R.drawable.ic_menu_edit); menu.add(0, MENU_DELETE, 0, r.getString(R.string.menu_delete)) .setIcon(android.R.drawable.ic_menu_delete); return true; } @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); boolean hasSelection = (getSelectedItemPosition() >= 0); menu.findItem(MENU_ADD).setVisible(true); menu.findItem(MENU_EDIT).setVisible(hasSelection); menu.findItem(MENU_DELETE).setVisible(hasSelection); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_ADD: if (curRecordSize >= maxRecordSize) { Toast.makeText(this, getResources().getText(R.string.adn_full), Toast.LENGTH_SHORT).show(); return false; }else{ addContact(); return true; } case MENU_EDIT: editSelected(); return true; case MENU_DELETE: deleteSelected(); return true; } return super.onOptionsItemSelected(item); } @Override public void onListItemClick(ListView l, View v, int position, long id) { // TODO: is this what we really want? editSelected(position); } private void addContact() { // if we don't put extras "name" when starting this activity, then // EditFdnContactScreen treats it like add contact. Intent intent = new Intent(); intent.setClass(this, EditFdnContactScreen.class); intent.setData(getIntent().getData()); intent.putExtra(CallSettingOptions.SUB_ID, mSubId); startActivity(intent); } /** * Overloaded to call editSelected with the current selection * by default. This method may have a problem with touch UI * since touch UI does not really have a concept of "selected" * items. */ private void editSelected() { editSelected(getSelectedItemPosition()); } /** * Edit the item at the selected position in the list. */ private void editSelected(int position) { if (mCursor.moveToPosition(position)) { String name = mCursor.getString(NAME_COLUMN); String number = mCursor.getString(NUMBER_COLUMN); Intent intent = new Intent(); intent.setClass(this, EditFdnContactScreen.class); intent.putExtra(INTENT_EXTRA_NAME, name); intent.putExtra(INTENT_EXTRA_NUMBER, number); intent.setData(getIntent().getData()); intent.putExtra(CallSettingOptions.SUB_ID, mSubId); startActivity(intent); } } private void deleteSelected() { if (mCursor.moveToPosition(getSelectedItemPosition())) { String name = mCursor.getString(NAME_COLUMN); String number = mCursor.getString(NUMBER_COLUMN); Intent intent = new Intent(); intent.setClass(this, DeleteFdnContactScreen.class); intent.putExtra(INTENT_EXTRA_NAME, name); intent.putExtra(INTENT_EXTRA_NUMBER, number); intent.setData(getIntent().getData()); intent.putExtra(CallSettingOptions.SUB_ID, mSubId); startActivity(intent); } } }