Java by API/javax.microedition.pim/PIM — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:47, 31 мая 2010

PIM.CONTACT_LIST

 

import java.util.Enumeration;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;
public class PIMMIDlet extends MIDlet implements CommandListener {
  private ContactList contList = null;
  private Enumeration contacts = null;
  private List mNameList;
  private Command mExitCommand= new Command("Exit", Command.EXIT, 0);
  public PIMMIDlet() {
    try {
      PIM pimInst = PIM.getInstance();
      contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
      contacts = contList.items();
    } catch (Exception ex) {
      return;
    }
    if (contacts == null)
      return;
    mNameList = new List("List of contacts", List.EXCLUSIVE);
    while (contacts.hasMoreElements()) {
      Contact tCont = (Contact) contacts.nextElement();
      String[] nameValues = tCont.getStringArray(Contact.NAME, 0);
      String firstName = nameValues[Contact.NAME_GIVEN];
      String lastName = nameValues[Contact.NAME_FAMILY];
      mNameList.append(lastName + ", " + firstName, null);
    }
    mNameList.addCommand(mExitCommand);
    mNameList.setCommandListener(this);
  }
  public void startApp() {
    Display.getDisplay(this).setCurrent(mNameList);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean flg) {
  }
  public void commandAction(Command c, Displayable s) {
    if (c == mExitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}





PIM: openPIMList(int arg0, int arg1) throws PIMException

 

import java.util.Enumeration;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;
public class PIMMIDlet extends MIDlet implements CommandListener {
  private ContactList contList = null;
  private Enumeration contacts = null;
  private List mNameList;
  private Command mExitCommand= new Command("Exit", Command.EXIT, 0);
  public PIMMIDlet() {
    try {
      PIM pimInst = PIM.getInstance();
      contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
      contacts = contList.items();
    } catch (Exception ex) {
      return;
    }
    if (contacts == null)
      return;
    mNameList = new List("List of contacts", List.EXCLUSIVE);
    while (contacts.hasMoreElements()) {
      Contact tCont = (Contact) contacts.nextElement();
      String[] nameValues = tCont.getStringArray(Contact.NAME, 0);
      String firstName = nameValues[Contact.NAME_GIVEN];
      String lastName = nameValues[Contact.NAME_FAMILY];
      mNameList.append(lastName + ", " + firstName, null);
    }
    mNameList.addCommand(mExitCommand);
    mNameList.setCommandListener(this);
  }
  public void startApp() {
    Display.getDisplay(this).setCurrent(mNameList);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean flg) {
  }
  public void commandAction(Command c, Displayable s) {
    if (c == mExitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}





PIM.READ_ONLY

 

import java.util.Enumeration;
import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.pim.Contact;
import javax.microedition.pim.ContactList;
import javax.microedition.pim.PIM;
public class PIMMIDlet extends MIDlet implements CommandListener {
  private ContactList contList = null;
  private Enumeration contacts = null;
  private List mNameList;
  private Command mExitCommand= new Command("Exit", Command.EXIT, 0);
  public PIMMIDlet() {
    try {
      PIM pimInst = PIM.getInstance();
      contList = (ContactList) pimInst.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);
      contacts = contList.items();
    } catch (Exception ex) {
      return;
    }
    if (contacts == null)
      return;
    mNameList = new List("List of contacts", List.EXCLUSIVE);
    while (contacts.hasMoreElements()) {
      Contact tCont = (Contact) contacts.nextElement();
      String[] nameValues = tCont.getStringArray(Contact.NAME, 0);
      String firstName = nameValues[Contact.NAME_GIVEN];
      String lastName = nameValues[Contact.NAME_FAMILY];
      mNameList.append(lastName + ", " + firstName, null);
    }
    mNameList.addCommand(mExitCommand);
    mNameList.setCommandListener(this);
  }
  public void startApp() {
    Display.getDisplay(this).setCurrent(mNameList);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean flg) {
  }
  public void commandAction(Command c, Displayable s) {
    if (c == mExitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
  }
}