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

📄 profile.java

📁 基于SKYPE API 控件的开发示例 JSkype is an JNI implementation which enables Java clients to use the Skyp API
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
 * Copyright (c) 2006 Koji Hisano <hisano@gmail.com> - UBION Inc. Developer
 * Copyright (c) 2006 UBION Inc. <http://www.ubion.co.jp/>
 * 
 * Copyright (c) 2006 Skype Technologies S.A. <http://www.skype.com/>
 * 
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Common Public License v1.0 which accompanies
 * this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 * Koji Hisano - initial API and implementation
 ******************************************************************************/
package com.skype;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The <code>Profile</code> class contains the current user's information.
 * <p>
 * For example, you can get the mood message of the current user by this code:
 * <pre>String moodMessage = Skype.getProfile().getMoodMessage();</pre>
 * And you can change it by the following code:
 * <pre>Skype.getProfile().setMoodMessage("Happy!");</pre>
 * </p>
 * @author Koji Hisano
 */
public final class Profile {
    /**
     * The <code>Status</code> enum contains the online status constants of the current user.
     * @see Profile#getStatus()
     * @see Profile#setStatus(Status)
     */
    public enum Status {
        /**
         * The <code>UNKNOWN</code> constant indicates the user status is unknown.
         */
        UNKNOWN,
        /**
         * The <code>ONLINE</code> constant indicates the user is online.
         */
        ONLINE,
        /**
         * The <code>OFFLINE</code> constant indicates the user is offline.
         */
        OFFLINE,
        /**
         * The <code>SKYPEME</code> constant indicates the user is in SkypeMe mode.
         */
        SKYPEME,
        /**
         * The <code>AWAY</code> constant indicates the user is away.
         */
        AWAY,
        /**
         * The <code>NA</code> constant indicates the user is not available.
         */
        NA,
        /**
         * The <code>DND</code> constant indicates the user is in do not disturb mode.
         */
        DND,
        /**
         * The <code>INVISIBLE</code> constant indicates the user is invisible to others.
         */
        INVISIBLE,
        /**
         * The <code>LOGGEDOUT</code> constant indicates the user is logged out.
         */
        LOGGEDOUT;
    }

    /**
     * The <code>Sex</code> enum contains the sex constants of the current user.
     * @see Profile#getSex()
     * @see Profile#setSex(Sex)
     */
    public enum Sex {
        /**
         * The <code>UNKNOWN</code> constant indicates the sex of the current user is unknown.
         */
        UNKNOWN,
        /**
         * The <code>MALE</code> constant indicates the current user is male.
         */
        MALE,
        /**
         * The <code>FEMALE</code> constant indicates the current user is female.
         */
        FEMALE;
    }

    /**
     * The <code>CallForwardingRule</code> class contains the information of a call forwarding rule.
     */
    public static final class CallForwardingRule {
        /** startSecond value. */
    	private final int startSecond;
    	/** endSecond value. */
    	private final int endSecond;
        /** target String. */
    	private final String target;

        /**
         * Constructs a call forwarding rule.
         * @param newStartSecond the time in seconds when connecting to this number/user starts.
         * @param newEndSecond the time in seconds when ringing to this number/user ends.
         * @param newTarget the target Skype username to forward calls to, or the PSTN number to forward a call.
         */
        public CallForwardingRule(int newStartSecond, int newEndSecond, String newTarget) {
            this.startSecond = newStartSecond;
            this.endSecond = newEndSecond;
            if (newTarget.startsWith("+")) {
                newTarget = newTarget.replaceAll("-", "");
            }
            this.target = newTarget;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public int hashCode() {
            return toString().hashCode();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean equals(Object compared) {
            if (compared instanceof CallForwardingRule) {
                return toString().equals(((Profile)compared).toString());
            }
            return false;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return startSecond + "," + endSecond + "," + target;
        }

        /**
         * Gets the time in seconds when connecting to this number/user starts.
         * @return the time in seconds when connecting to this number/user starts.
         */
        public int getStartSecond() {
            return startSecond;
        }

        /**
         * Gets the time in seconds when ringing to this number/user ends.
         * @return the time in seconds when ringing to this number/user ends.
         */
        public int getEndSecond() {
            return endSecond;
        }

        /**
         * Gets the target Skype username to forward calls to, or the PSTN number to forward a call.
         * @return the target Skype username to forward calls to, or the PSTN number to forward a call.
         */
        public String getTarget() {
            return target;
        }
    }

    /**
     * Constructor.
     *
     */
    Profile() {
    }

    /**
     * Gets the Skype ID (username) of the current user. 
     * @return the Skype ID (username) of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public String getId() throws SkypeException {
        return Utils.getProperty("CURRENTUSERHANDLE");
    }

    /**
     * Gets the online status of the current user.
     * @return the online status of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #setStatus(Status)
     */
    public Status getStatus() throws SkypeException {
        return Status.valueOf(Utils.getProperty("USERSTATUS"));
    }

    /**
     * Sets the online status of the current user by the {@link Status} enum.
     * @param newStatus the new online status of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #getStatus()
     */
    public void setStatus(Status newStatus) throws SkypeException {
        Utils.setProperty("USERSTATUS", newStatus.toString());
    }

    /**
     * Indicates whether the current user can do SkypeOut.
     * @return <code>true</code> if the current user can do SkypeOut; <code>false</code> otherwise.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public boolean canDoSkypeOut() throws SkypeException {
        return canDo("SKYPEOUT");
    }

    /**
     * Indicates whether the current user can do SkypeIn.
     * @return <code>true</code> if the current user can do SkypeIn; <code>false</code> otherwise.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public boolean canDoSkypeIn() throws SkypeException {
        return canDo("SKYPEIN");
    }

    /**
     * Indicates whether the current user can do VoiceMail.
     * @return <code>true</code> if the current user can do VoiceMail; <code>false</code> otherwise.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public boolean canDoVoiceMail() throws SkypeException {
        return canDo("VOICEMAIL");
    }

    /**
     * Check for a privilege.
     * @param name The name of the privilege to check.
     * @return true if this privilege is ok.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    private boolean canDo(String name) throws SkypeException {
        return Boolean.parseBoolean(Utils.getProperty("PRIVILEGE", name));
    }

    /**
     * Gets the balance of the current user.
     * @return the balance of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public int getPSTNBalance() throws SkypeException {
        return Integer.parseInt(getProperty("PSTN_BALANCE"));
    }

    /**
     * Gets the currency code of the current user.
     * @return the currency code of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     */
    public String getPSTNBalanceCurrencyUnit() throws SkypeException {
        return getProperty("PSTN_BALANCE_CURRENCY");
    }

    /**
     * Gets the full name of the current user.
     * @return the full name of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #setFullName(String)
     */
    public String getFullName() throws SkypeException {
        return getProperty("FULLNAME");
    }

    /**
     * Sets the full name of the current user.
     * @param newValue the new full name of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #getFullName()
     */
    public void setFullName(String newValue) throws SkypeException {
        setProperty("FULLNAME", newValue);
    }

    /**
     * Gets the birth day of the current user.
     * @return the birth day of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #setBirthDay(Date)
     */
    public Date getBirthDay() throws SkypeException {
        String value = getProperty("BIRTHDAY");
        if ("0".equals(value)) {
            return null;
        } else {
            try {
                return new SimpleDateFormat("yyyyMMdd").parse(value);
            } catch (ParseException e) {
                throw new IllegalStateException("library developer should check Skype specification.");
            }
        }
    }

    /**
     * Sets the birth day of the current user.
     * @param newValue the new birth day of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #getBirthDay()
     */
    public void setBirthDay(Date newValue) throws SkypeException {
        String newValueString;
        if (newValue == null) {
            newValueString = "0";
        } else {
            newValueString = new SimpleDateFormat("yyyyMMdd").format(newValue);
        }
        setProperty("BIRTHDAY", newValueString);
    }

    /**
     * Gets the sex of the current user.
     * @return the sex of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #setSex(Sex)
     */
    public Sex getSex() throws SkypeException {
        return Sex.valueOf((getProperty("SEX")));
    }

    /**
     * Sets the sex of the current user by the {@link Sex} enum.
     * @param newValue the new sex of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #getSex()
     */
    public void setSex(Sex newValue) throws SkypeException {
        setProperty("SEX", newValue.toString());
    }

    /**
     * Gets the all languages of the current user.
     * @return the all languages of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #setAllLanguages(String[])
     */
    public String[] getAllLauguages() throws SkypeException {
        return getProperty("LANGUAGES").split(" ");
    }

    /**
     * Sets the all languages of the current user.
     * @param newValues the all new languages of the current user.
     * @throws SkypeException when the connection has gone bad or an ERROR message is received.
     * @see #getAllLauguages()
     */
    public void setAllLanguages(String[] newValues) throws SkypeException {

⌨️ 快捷键说明

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