/*
* miniContacts
* Copyright (C) 2007-2008 Matas Molinas
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.minicontacts;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TableRow;
import android.widget.TextView;
import com.minicontacts.core.actions.contacts.OpenContactListAction;
import com.minicontacts.core.actions.map.OpenMapAction;
import com.minicontacts.core.actions.web.OpenWebAction;
import com.minicontacts.core.common.Action;
import com.minicontacts.core.common.exceptions.BusinessException;
import com.minicontacts.core.ui.base.RowItem;
import com.minicontacts.core.ui.util.Util;
public class MiniContacts extends ListActivity {
public static final int CONTACTS_MENU = 0;
public static final int APPLICATION_MENU = 1;
public static final int MAPS_MENU = 2;
public static final int EXIT_MENU = 3;
protected int selectedMenu;
protected ListAdapter listAdapter;
protected ArrayList<RowItem> contactsMenuItems;
protected ArrayList<RowItem> applicationMenuItems;
protected ArrayList<RowItem> mapsMenuItems;
protected ArrayList<RowItem> exitMenuItems;
protected ImageButton btnSearch = null;
protected ImageButton btnContacts = null;
protected ImageButton btnApplication = null;
protected ImageButton btnMaps = null;
protected ImageButton btnExit = null;
protected ImageView iconTitle = null;
protected TextView txtTitle = null;
protected Action openContactListAction = null;
protected Action openMapAction = null;
protected Action openWebAction = null;
@Override
public void onCreate(Bundle icicle) {
try {
super.onCreate(icicle);
setContentView(R.layout.main);
initializeUI();
selectMenu(CONTACTS_MENU);
} catch (Exception ex) {
Util.showErrorDialog(this, ex);
}
}
protected void selectMenu(int menu){
selectedMenu = menu;
switch (menu) {
case (CONTACTS_MENU): {
iconTitle.setImageDrawable(getResources().getDrawable(R.drawable.system_users));
txtTitle.setText(R.string.menu_contacts);
btnSearch.setBackground(android.R.drawable.btn_default);
btnContacts.setBackground(android.R.drawable.btn_default_selected);
btnApplication.setBackground(android.R.drawable.btn_default);
btnMaps.setBackground(android.R.drawable.btn_default);
btnExit.setBackground(android.R.drawable.btn_default);
break;
}
case (APPLICATION_MENU): {
iconTitle.setImageDrawable(getResources().getDrawable(R.drawable.package_generic));
txtTitle.setText(R.string.menu_application);
btnSearch.setBackground(android.R.drawable.btn_default);
btnContacts.setBackground(android.R.drawable.btn_default);
btnApplication.setBackground(android.R.drawable.btn_default_selected);
btnMaps.setBackground(android.R.drawable.btn_default);
btnExit.setBackground(android.R.drawable.btn_default);
break;
}
case (MAPS_MENU): {
iconTitle.setImageDrawable(getResources().getDrawable(R.drawable.world));
txtTitle.setText(R.string.menu_maps);
btnSearch.setBackground(android.R.drawable.btn_default);
btnContacts.setBackground(android.R.drawable.btn_default);
btnApplication.setBackground(android.R.drawable.btn_default);
btnMaps.setBackground(android.R.drawable.btn_default_selected);
btnExit.setBackground(android.R.drawable.btn_default);
break;
}
case (EXIT_MENU): {
iconTitle.setImageDrawable(getResources().getDrawable(R.drawable.system_logout));
txtTitle.setText(R.string.menu_exit);
btnSearch.setBackground(android.R.drawable.btn_default);
btnContacts.setBackground(android.R.drawable.btn_default);
btnApplication.setBackground(android.R.drawable.btn_default);
btnMaps.setBackground(android.R.drawable.btn_default);
btnExit.setBackground(android.R.drawable.btn_default_selected);
break;
}
}
loadMenu();
}
protected void initializeUI() {
openContactListAction = new OpenContactListAction();
openMapAction = new OpenMapAction();
openWebAction = new OpenWebAction();
TableRow trToolbar = (TableRow) findViewById(R.id.trToolbar);
trToolbar.setBackground(android.R.drawable.statusbar_background);
iconTitle = (ImageView) findViewById(R.id.iconTitle);
txtTitle = (TextView) findViewById(R.id.txtTitle);
btnSearch = (ImageButton) findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Search();
}
});
btnContacts = (ImageButton) findViewById(R.id.btnContacts);
btnContacts.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
selectMenu(CONTACTS_MENU);
}
});
btnApplication = (ImageButton) findViewById(R.id.btnApplication);
btnApplication.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
selectMenu(APPLICATION_MENU);
}
});
btnMaps = (ImageButton) findViewById(R.id.btnMaps);
btnMaps.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
selectMenu(MAPS_MENU);
}
});
btnExit = (ImageButton) findViewById(R.id.btnExit);
btnExit.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
selectMenu(EXIT_MENU);
}
});
TableRow trTitle = (TableRow) findViewById(R.id.trTitle);
trTitle
.setBackground(android.R.drawable.list_selector_background_focus);
contactsMenuItems = new ArrayList<RowItem>();
contactsMenuItems.add(new RowItem(
getResources().getString(R.string.menu_contacts_item_contacts),
getResources().getString(R.string.msg_in_operation),
getResources().getDrawable(R.drawable.system_users)));
applicationMenuItems = new ArrayList<RowItem>();
applicationMenuItems.add(new RowItem(
getResources().getString(R.string.menu_utilities_item_calendar),
getResources().getString(R.string.msg_under_construction),
getResources().getDrawable(R.drawable.office_calendar)));
applicationMenuItems.add(new RowItem(
getResources().getString(R.string.menu_utilities_item_notes),
getResources().getString(R.string.msg_under_construction),
getResources().getDrawable(R.drawable.accessories_text_editor)));
mapsMenuItems = new ArrayList<RowItem>();
mapsMenuItems.add(new RowItem(
getResources().getString(R.string.menu_maps_item_favorite_places),
getResources().getString(R.string.msg_in_operation),
getResources().getDrawable(R.drawable.world)));
exitMenuItems = new ArrayList<RowItem>();
exitMenuItems.add(new RowItem(
getResources().getString(R.string.menu_exit_item_exit),
getResources().getString(R.string.msg_in_operation),
getResources().getDrawable(R.drawable.emblem_unreadable)));
}
protected void Search(){
new AlertDialog.Builder(this)
.setTitle(getResources().getString(R.string.title_search_dialog))
.setItems(R.array.items_global_search_dialog,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int selectedItem) {
String[] syncOptions =
getResources().getStringArray(R.array.items_global_search_dialog);
if (selectedItem==0){
GoogleSearch();
}else{
new AlertDialog.Builder(MiniContacts.this)
.setMessage(
getResources().getString(R.string.msg_search_option)
+ " " + syncOptions[selectedItem]
+ " " + getResources().getString(R.string.msg_not_available))
.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
}
}
})
.show();
}
protected void GoogleSearch(){
try {
openWebAction.perform(this, null);
} catch (BusinessException be) {
Util.showErrorDialog(this, be);
}
}
private void loadMenu() {
switch (selectedMenu) {
case (CONTACTS_MENU): {
listAdapter = new SimpleAdapter(
this,
contactsMenuItems,
R.layout.row,
/*new String[] {RowItem.ICON, RowItem.ROW_TEXT_1, RowItem.ROW_TEXT_2},
new int[]{ R.id.iconRow, R.id.txtRow1, R.id.txtRow2});*/
new String[] {RowItem.ROW_TEXT_1, RowItem.ROW_TEXT_2},
new int[]{R.id.txtRow1, R.id.txtRow2});
break;
}
case (APPLICATION_MENU): {
listAdapter = new SimpleAdapter(
this,
applicationMenuItems,
R.layout.row,
new String[] {RowItem.ROW_TEXT_1, RowItem.ROW_TEXT_2},
new int[]{ R.id.txtRow1, R.id.txtRow2});
break;
}
case (MAPS_MENU): {
listAdapter = new SimpleAdapter(
this,
mapsMenuItems,
R.layout.row,
new String[] {RowItem.ROW_TEXT_1, RowItem.ROW_TEXT_2},
new int[]{R.id.txtRow1, R.id.txtRow2});
break;
}
case (EXIT_MENU): {
listAdapter = new SimpleAdapter(
this,
exitMenuItems,
R.layout.row,
new String[] {RowItem.ROW_TEXT_1, RowItem.ROW_TEXT_2},
new int[]{R.id.txtRow1, R.id.txtRow2});
break;
}
}
// Display it
setListAdapter(listAdapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
selectMenuItem(position);
}
protected void selectMenuItem(int menuItem){
try {
switch (selectedMenu) {
case (CONTACTS_MENU): {
switch (menuItem) {
case 0: {//System Contacts
openContactListAction.perform(this, null);
break;
}
}
break;
}
case (APPLICATION_MENU): {
switch (menuItem) {
case 0: {//Calendar
showUnderConstructionActivity();
break;
}
case 1: {//Notes
showUnderConstructionActivity();
break;
}
}
break;
}
case (MAPS_MENU): {
switch (menuItem) {
case 0: {//Favorite places..
openMapAction.perform(this, null);
break;
}
}
break;
}
case (EXIT_MENU): {
switch (menuItem) {
case 0: {//Exit
new AlertDialog.Builder(MiniContacts.this)
.setTitle(getResources().getString(R.string.dialog_title_question))
.setMessage(getResources().getString(R.string.dialog_exit_question))
.setIcon(R.drawable.help_browser)
.setPositiveButton(getResources().getString(R.string.dialog_button_yes)
, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
})
.setNegativeButton(getResources().getString(R.string.dialog_button_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();
break;
}
}
break;
}
}
} catch (BusinessException be) {
Util.showErrorDialog(this, be);
}
}
protected void showUnderConstructionActivity(){
//TODO:TEMPORAL!!!!!!!!!
Intent i = new Intent();
i.setClassName( "com.minicontacts", "com.minicontacts.core.ui.util.UnderConstructionActivity" );
startActivity( i );
}
}
|