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

📄 contexttest.java

📁 270的linux说明
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*

Copyright (c) 2008, Intel Corporation. 

All rights reserved.

 

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:


    * Redistributions of source code must retain the above copyright notice, 
this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
this list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution.

    * Neither the name of Intel Corporation nor the names of its contributors 
may be used to endorse or promote products derived from this software without 
specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.

*/import com.intel.mobile.base.IntelMobileException;import com.intel.mobile.context.*;import com.intel.mobile.battery.ConditionEnum;import com.intel.mobile.display.OrientationEnum;//import java.util.StringTokenizer;import java.net.*;//import java.io.*;/** * <class or interface desc> */public class ContextTest{    private static final String pszDestination = "http://www.intel.com";	private static final String sProxyURL = "http://proxy01.pd.intel.com:911";	private static final String sProxyUsername = "123";	private static final String sProxyPassword = "123";	private static final int sTimeOut = 15000;	private static final int sRetryCount = 1;	private static final String path = "C:/";    private ContextClass myClass;    public ContextTest(ContextClass myClass)    {        this.myClass = myClass;    }        public void printDisplay() throws IntelMobileException	{    	DisplayInstance myDisplayInstance = (DisplayInstance) myClass.GetInstance("Display");    	    	StringBuffer strBuf = new StringBuffer();    	strBuf.append("\n-------------  Output Display Context ----------------\n");    	    	String type = myDisplayInstance.GetType();    	strBuf.append("Type: ").append(type).append("\n");    	    	String Key = myDisplayInstance.GetKey();    	strBuf.append("Key: ").append(Key).append("\n");    	    	//if (!myDisplayInstance.Orientation.IsNull())    	{    		//OrientationEnum value = myDisplayInstance.Orientation.GetValue();    		//strBuf.append("Orientation: ").append(value.toString()).append("\n");    	}    		    	if (!myDisplayInstance.PixelDensity.IsNull())    	{    		int value = myDisplayInstance.PixelDensity.GetValue();    		strBuf.append("PixelDensity: ").append(value).append("\n");    	}    	    	if (!myDisplayInstance.VerticalResolution.IsNull())    	{    		int value = myDisplayInstance.VerticalResolution.GetValue();    		strBuf.append("VerticalResolution: ").append(value).append("\n");    	}    	    	if (!myDisplayInstance.HorizontalResolution.IsNull())    	{    		int value = myDisplayInstance.HorizontalResolution.GetValue();    		strBuf.append("HorizontalResolution: ").append(value).append("\n");    	}    	    	if (!myDisplayInstance.ColorDepth.IsNull())    	{    		int value = myDisplayInstance.ColorDepth.GetValue();    		strBuf.append("ColorDepth: ").append(value).append("\n");    	}    	strBuf.append("\n-------------  Display Context ----------------\n\n");    	System.out.print( strBuf.toString() );	}        public void printPowerInfo() throws IntelMobileException    {    	PowerInstance myPowerInstance = (PowerInstance) myClass.GetInstance("Power");    	    	StringBuffer strBuf = new StringBuffer();    	strBuf.append("\n-------------  Output Power Context ----------------\n");    	    	String type = myPowerInstance.GetType();    	strBuf.append("Type: ").append(type).append("\n");    	    	String Key = myPowerInstance.GetKey();    	strBuf.append("Key: ").append(Key).append("\n");    	    	if (!myPowerInstance.Source.IsNull())    	{    		SourceEnum value = myPowerInstance.Source.GetValue();    		strBuf.append("Source: ").append(value).append("\n");    	}    		    	if (!myPowerInstance.Capacity.IsNull())    	{    		long value = myPowerInstance.Capacity.GetValue();    		strBuf.append("Capacity: ").append(value).append("\n");    	}    	if (!myPowerInstance.State.IsNull())    	{    		StateEnum value = myPowerInstance.State.GetValue();    		strBuf.append("State: ").append(value).append("\n");    		/*switch (value)    		{    			case 1: 	strBuf.append("InternalPowerStatus: ").append("Charging").append("\n"); break;    			case 2: 	strBuf.append("InternalPowerStatus: ").append("Discharging").append("\n"); break;    			case 3: 	strBuf.append("InternalPowerStatus: ").append("Charged").append("\n"); break;    			case 4: 	strBuf.append("InternalPowerStatus: ").append("Discharged").append("\n"); break;    			default: 	strBuf.append("InternalPowerStatus: ").append("UnknownCondition").append("\n"); break;    		}*/    	}    	if (!myPowerInstance.EstimatedTimeRemaining.IsNull())    	{    		long value = myPowerInstance.EstimatedTimeRemaining.GetValue();    		strBuf.append("EstimatedTimeRemaining: ").append(value).append("\n");    	}    	if (!myPowerInstance.FullCapacity.IsNull())    	{    		long value = myPowerInstance.FullCapacity.GetValue();    		strBuf.append("FullCapacity: ").append(value).append("\n");    	}    	    	if (!myPowerInstance.PercentRemaining.IsNull())    	{    		long value = myPowerInstance.PercentRemaining.GetValue();    		strBuf.append("PercentRemaining: ").append(value).append("\n");    	}    	if (!myPowerInstance.Rate.IsNull())    	{    		long value = myPowerInstance.Rate.GetValue();    		strBuf.append("Rate: ").append(value).append("\n");    	}    	if (!myPowerInstance.TimeRemaining.IsNull())    	{    		long value = myPowerInstance.TimeRemaining.GetValue();    		strBuf.append("TimeRemaining: ").append(value).append("\n");    	}    		  		    	strBuf.append("\n-------------  Power Context ----------------\n\n");    	System.out.print( strBuf.toString() );    }            public void printConnectivityInfo() throws IntelMobileException    {				ConnectivityInstance myConnectivityInstance = (ConnectivityInstance) myClass.GetInstance("Connectivity");                StringBuffer strBuf = new StringBuffer();        strBuf.append("\n------------  Output Connectivity Context ------------\n");        String type = myConnectivityInstance.GetType();        strBuf.append("Type: ").append(type).append("\n");        String key = myConnectivityInstance.GetKey();        strBuf.append("Key: ").append(key).append("\n");        if ( !myConnectivityInstance.IsConnected.IsNull() )        {            boolean value = myConnectivityInstance.IsConnected.GetValue();            strBuf.append("Connected: ").append(value).append("\n");        }        // methods                boolean bReachable = myConnectivityInstance.IsReachable( pszDestination );        strBuf.append("Reachable (").append(pszDestination).append("): ")            .append(bReachable).append("\n");//		bReachable = myConnectivityInstance.IsReachableEx( pszDestination,sProxyURL,sProxyUsername, sProxyPassword, sTimeOut, sRetryCount );//		strBuf.append("ReachableEx (").append(pszDestination).append("): ")//			.append(bReachable).append("\n");        String pszNetworkAdapter = myConnectivityInstance.GetNetworkAdapterKey( pszDestination );        if ( pszNetworkAdapter != null && !pszNetworkAdapter.equals("") )        {            strBuf.append("NetworkAdapter for ").append(pszDestination).append(": ")                .append(pszNetworkAdapter).append("\n");        }                String pszLinkProtocol = myConnectivityInstance.GetNetworkLinkProtocolKey( pszDestination );        if ( pszLinkProtocol != null && !pszLinkProtocol.equals("") )        {            strBuf.append("LinkProtocol for ").append(pszDestination).append(": ")                .append(pszLinkProtocol).append("\n");        }                int iLatency = myConnectivityInstance.GetLatency( pszDestination );        if ( iLatency == ConnectivityInstance.TIMEOUT )        	strBuf.append("Latency for ").append(pszDestination).append(": Time out.\n");		        else        	strBuf.append("Latency for ").append(pszDestination).append(": ")            .append(iLatency).append("\n");//		iLatency = myConnectivityInstance.GetLatencyEx( pszDestination,sProxyURL,sProxyUsername, sProxyPassword, sTimeOut, sRetryCount  );//		if ( iLatency == ConnectivityInstance.TIMEOUT )//			strBuf.append("LatencyEx for ").append(pszDestination).append(": Time out.\n");//		else//			strBuf.append("LatencyEx for ").append(pszDestination).append(": ")//			.append(iLatency).append("\n");              strBuf.append("------------ Connectivity Context ------------\n\n");        System.out.print( strBuf.toString() );    }    	public void printStorageInfo() throws IntelMobileException	{				StorageInstance myStorageInstance = (StorageInstance) myClass.GetInstance("Storage");        		StringBuffer strBuf = new StringBuffer();		strBuf.append("\n------------  Output Storage Context ------------\n");		String type = myStorageInstance.GetType();		strBuf.append("Type: ").append(type).append("\n");		String key = myStorageInstance.GetKey();		strBuf.append("Key: ").append(key).append("\n");		if ( !myStorageInstance.PersistentCapacity.IsNull() )		{			long value = myStorageInstance.PersistentCapacity.GetValue();			strBuf.append("PersistentCapacity: ").append(value).append("\n");		}		if ( !myStorageInstance.PersistentFreeSpace.IsNull() )		{			long value = myStorageInstance.PersistentFreeSpace.GetValue();			strBuf.append("PersistentFreeSpace: ").append(value).append("\n");		}

⌨️ 快捷键说明

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