⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listmodcontacts.java

📁 goText is a program for mobile phones that allows you to send text messages over GPRS/EDGE/UMTS. It
💻 JAVA
字号:
/**
 * Class : short description
 * @author Michele 'Miccar' Cardinale miccar@gmail.com
 * @author Natale Vinto ebballon@interfree.it
 * @version 1.0
 */

 /*
  *  goText : text messaging over GPRS
  *  Copyright (C) 2006  Natale Vinto <ebballon@interfree.it>
  *  OpenJLab Group www.openjlab.org
  *  Copyright (C) 2006  Michele Cardinale 'Miccar' <miccar@gmail.com>
  *  www.miccar.org
  *
  *  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */

import javax.microedition.lcdui.*;

public class ListModContacts extends List implements CommandListener{
    
    protected goText gotext;
    protected Lang l;
    private static final int MAX_GROUP=5;
    private Command command_back,command_new_c,command_new_g,command_del,command_mod;
    
    public ListModContacts(goText gotext) {
        super("",List.IMPLICIT);
        this.gotext=gotext;
        l=new Lang(gotext.lang);
        this.setTitle(l.LCM_CONTACTS);
        this.start();
    }
    
    private void start(){
        this.setTitle(l.LCM_CONTACTS+": "+gotext.contacts.length);
        if(gotext.contacts.length==0){
            this.setTicker(new Ticker(l.LMC_NOCONTACTS));
        } else {
            Image ico_contact=null;
            Image ico_group=null;
            try{
                ico_contact = Image.createImage("/img/contact.png");
                ico_group = Image.createImage("/img/group.png");
            } catch (Exception e){}
            for(int i=0;i<gotext.contacts.length;i++){
                if(gotext.contacts[i].isGroup())
                    this.append(gotext.contacts[i].getName(), ico_group);
                else
                    this.append(gotext.contacts[i].getName(), ico_contact);
            }
        }
        command_new_c=new Command(l.COMMAND_NEW_C,Command.SCREEN,1);
        command_new_g=new Command(l.COMMAND_NEW_G,Command.SCREEN,2);
        command_mod=new Command(l.COMMAND_MOD,Command.SCREEN,3);
        command_del=new Command(l.COMMAND_DEL,Command.SCREEN,4);
        command_back=new Command(l.COMMAND_BACK,Command.BACK,5);
        if(gotext.contacts.length<Contact.MAX_MEM_CONTACTS) this.addCommand(command_new_c);
        if(gotext.contacts.length<Contact.MAX_MEM_CONTACTS) this.addCommand(command_new_g);
        this.addCommand(command_mod);
        this.addCommand(command_del);
        this.addCommand(command_back);
        this.setCommandListener(this);
        this.show();
    }
    
    public void show(){
        gotext.display.setCurrent(this);
    }
    
    public void commandAction(Command c, Displayable d){
        if (c==List.SELECT_COMMAND){
            if (this.getSelectedIndex()>=0) {
                String temp=gotext.contacts[this.getSelectedIndex()].getName()+"\n";
                String[] number=utils.splitString(gotext.contacts[this.getSelectedIndex()].getNumber(),";");
                for(int i=0;i<number.length;i++)
                    temp+=number[i]+"\n";
                temp+=gotext.contacts[this.getSelectedIndex()].getEmail()+"\n";
                utils.popup(l.ALERT_INFO_TITLE, temp, gotext, AlertType.INFO);
            }
        } else if (c==command_back){
            new ListSettings(gotext);
        } else if (c==command_mod){
            if (this.getSelectedIndex()>=0){
                if(gotext.contacts[this.getSelectedIndex()].isGroup())
                    new FormModGroup(gotext, gotext.contacts[this.getSelectedIndex()]);
                else 
                    new FormModContact(gotext, gotext.contacts[this.getSelectedIndex()]);
            }
        } else if (c==command_new_c){
            new FormNewContact();
        } else if (c==command_new_g){
            new FormNewGroup(gotext);
        } else if (c==command_del){
            if(this.getSelectedIndex()>=0){
                Contact.delContact(gotext.contacts[this.getSelectedIndex()].getRmsId());
                new ListModContacts(gotext);
            }
        }
    }
    
    
    
    public class FormNewContact extends Form implements CommandListener{
        
        private Command command_back,command_ins;
        private TextField textfield_name,textfield_email,textfield_number;
        
        public FormNewContact() {
            super(l.LMC_INSERTCONTACT);
            this.start();
        }
        
        private void start(){
            textfield_name=new TextField(l.LMC_NAME,"",20,TextField.ANY);
            textfield_number=new TextField(l.LMC_NUMBER,"",13,TextField.PHONENUMBER);
            textfield_email=new TextField(l.LMC_EMAIL,"",50,TextField.EMAILADDR);
            this.append(textfield_name);
            this.append(textfield_number);
            this.append(textfield_email);
            command_ins=new Command(l.COMMAND_INS,Command.SCREEN,1);
            command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
            this.addCommand(command_ins);
            this.addCommand(command_back);
            this.setCommandListener(this);
            this.show();
        }
        
        public void show(){
            gotext.display.setCurrent(this);
        }
        
        public void commandAction(Command c, Displayable d){
            if (c==command_back){
                ListModContacts.this.show();
            } else if (c==command_ins){
                switch(Contact.insert(this.textfield_name.getString(), this.textfield_number.getString(), this.textfield_email.getString())){
                    case -2:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING5, gotext, AlertType.WARNING);
                        break;
                    case -1:
                        utils.popup(l.ALERT_ERROR_TITLE, l.ALERT_WARNING6, gotext, AlertType.ERROR);
                        break;
                    case 0:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING7, gotext, AlertType.WARNING);
                        break;
                    default:
                        new ListModContacts(gotext);
                        break;
                }
            }
        }
    }

    
    
    public class FormNewGroup extends Form implements CommandListener{
        
        private Command command_back,command_ins;
        private TextField textfield_name;
        private TextField[] textfield_number;
        
        public FormNewGroup(goText gotext) {
            super(l.LMC_GROUP);
            this.start();
        }
        
        private void start(){
            textfield_name=new TextField(l.LMC_NAME,"",20,TextField.ANY);
            this.append(textfield_name);
            textfield_number=new TextField[MAX_GROUP];
            for (int i=0;i<MAX_GROUP;i++){
                textfield_number[i]=new TextField(l.LMC_NUMBER.substring(0,l.LMC_NUMBER.length()-1)+""+i+":","",13,TextField.PHONENUMBER);
                this.append(textfield_number[i]);
            }
            command_ins=new Command(l.COMMAND_INS,Command.SCREEN,1);
            command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
            this.addCommand(command_ins);
            this.addCommand(command_back);
            this.setCommandListener(this);
            this.show();
        }
        
        public void show(){
            gotext.display.setCurrent(this);
        }
        
        public void commandAction(Command c, Displayable d){
            if (c==command_back){
                ListModContacts.this.show();
            } else if (c==command_ins){
                String number="";
                for (int i=0;i<MAX_GROUP;i++){
                    if(textfield_number[i].getString().length()>0)
                        number+=textfield_number[i].getString()+";";
                }
                if(number.endsWith(";"))
                    number=number.substring(0, number.length()-1);
                switch(Contact.insert(this.textfield_name.getString(), number, "")){
                    case -2:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING5, gotext, AlertType.WARNING);
                        break;
                    case -1:
                        utils.popup(l.ALERT_ERROR_TITLE, l.ALERT_WARNING6, gotext, AlertType.ERROR);
                        break;
                    case 0:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING7, gotext, AlertType.WARNING);
                        break;
                    default:
                        new ListModContacts(gotext);
                        break;
                }
            }
        }
    }
    
    
    
    public class FormModContact extends Form implements CommandListener{
        
        private Command command_back,command_app;
        private TextField textfield_name,textfield_email,textfield_number;
        private Contact contact;
        
        public FormModContact(goText gotext,Contact contact) {
            super(l.LMC_MODCONT);
            this.contact=contact;
            this.start();
        }
        
        private void start(){
            textfield_name=new TextField(l.LMC_NAME,contact.getName(),20,TextField.ANY);
            textfield_number=new TextField(l.LMC_NUMBER,contact.getNumber(),13,TextField.PHONENUMBER);
            textfield_email=new TextField(l.LMC_EMAIL,contact.getEmail(),50,TextField.EMAILADDR);
            this.append(textfield_name);
            this.append(textfield_number);
            this.append(textfield_email);
            command_app=new Command(l.COMMAND_APP,Command.SCREEN,1);
            command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
            this.addCommand(command_app);
            this.addCommand(command_back);
            this.setCommandListener(this);
            this.show();
        }
        
        public void show(){
            gotext.display.setCurrent(this);
        }
        
        public void commandAction(Command c, Displayable d){
            if (c==command_back){
                ListModContacts.this.show();
            } else if (c==command_app){
                switch(contact.set(this.textfield_name.getString(), this.textfield_number.getString(), this.textfield_email.getString())){
                    case -2:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING5, gotext, AlertType.WARNING);
                        break;
                    case -1:
                        utils.popup(l.ALERT_ERROR_TITLE, l.ALERT_WARNING6, gotext, AlertType.ERROR);
                        break;
                    case 0:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING7, gotext, AlertType.WARNING);
                        break;
                    default:
                       new ListModContacts(gotext);
                        break;
                }
            }
        }
    }
    
    
    
    public class FormModGroup extends Form implements CommandListener{
        
        private Command command_back,command_app;
        private TextField textfield_name;
        private TextField[] textfield_number;
        private Contact contact;
        
        public FormModGroup(goText gotext,Contact contact) {
            super(l.LMC_MODGROUP);
            this.contact=contact;
            this.start();
        }
        
        private void start(){
            textfield_name=new TextField(l.LMC_NAME,contact.getName(),20,TextField.ANY);
            this.append(textfield_name);
            String[] numbers=utils.splitString(contact.getNumber(), ";");
            textfield_number=new TextField[MAX_GROUP];
            for (int i=0;i<numbers.length;i++){
                textfield_number[i]=new TextField(l.LMC_NUMBER.substring(0,l.LMC_NUMBER.length()-1)+""+i+":",numbers[i],13,TextField.PHONENUMBER);
                this.append(textfield_number[i]);
            }
            for (int i=numbers.length;i<textfield_number.length;i++){
                textfield_number[i]=new TextField(l.LMC_NUMBER.substring(0,l.LMC_NUMBER.length()-1)+""+i+":","",13,TextField.PHONENUMBER);
                this.append(textfield_number[i]);
            }
            command_app=new Command(l.COMMAND_APP,Command.SCREEN,1);
            command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
            this.addCommand(command_app);
            this.addCommand(command_back);
            this.setCommandListener(this);
            this.show();
        }
        
        public void show(){
            gotext.display.setCurrent(this);
        }
        
        public void commandAction(Command c, Displayable d){
            if (c==command_back){
                ListModContacts.this.show();
            } else if (c==command_app){
                String number="";
                for (int i=0;i<MAX_GROUP;i++){
                    if(textfield_number[i].getString().length()>0)
                        number+=textfield_number[i].getString()+";";
                }
                if(number.endsWith(";"))
                    number=number.substring(0, number.length()-1);
                switch(contact.set(this.textfield_name.getString(), number, "")){
                    case -2:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING5, gotext, AlertType.WARNING);
                        break;
                    case -1:
                        utils.popup(l.ALERT_ERROR_TITLE, l.ALERT_WARNING6, gotext, AlertType.ERROR);
                        break;
                    case 0:
                        utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING7, gotext, AlertType.WARNING);
                        break;
                    default:
                        new ListModContacts(gotext);
                        break;
                }
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -