温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

雪山飞鹄

温馨提示:您的每一次转载,体现了我写此文的意义!!!烦请您在转载时注明出处http://www.blogjava.net/sxyx2008/谢谢合作!!!

BlogJava 首页 新随笔 联系 聚合 管理
  215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

#

需求:在界面上有两个按钮,一个开始,一个停止。点击开始按钮,更新应用的标题为当前时间。按停止按钮停止更新时间。
考察:handler的使用。
这里借助Handler+Timer+TimerTask来实现

package com.zhy.ui;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import com.zhy.shortcut.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class UpdateUiActivity extends Activity implements OnClickListener{
    
    
    private static final int UPDATA_TITIE=1;
    
    Button start;
    Button stop;
    
    TimerTask task;
    
    Handler handler;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.ui);
        
        start=(Button) findViewById(R.id.start);
        stop=(Button) findViewById(R.id.stop);
        
        //实列化Handler
        handler=new Handler(){
            //处理消息
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                //标记消息
                switch (msg.what) {
                case UPDATA_TITIE:
                    //更新UI
                    updateTitle(msg);
                    break;

                default:
                    break;
                }
            }
        };
        
        start.setOnClickListener(this);
        stop.setOnClickListener(this);
        
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.start:
            //创建一个定时器
            Timer timer=new Timer();
            //创建TimerTask
            task=new TimerTask() {
                
                //实现run方法,这里存放需要实时更新时间的代码
                @Override
                public void run() {
                    //创建一个消息体
                    Message message=new Message();
                    //标记消息
                    message.what=UPDATA_TITIE;
                    //传递数据
                    message.obj=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());
                    //发送消息
                    handler.sendMessage(message);
                }
            };
            //调度,每隔一秒中执行一次
            timer.schedule(task, 1, 1000);
            break;
        case R.id.stop:
            //停止
            if(task!=null){
                task.cancel();
            }
            break;
        default:
            break;
        }
    }
    
    /**
     * 更新应用标题
     * 
@param msg
     
*/
    private void updateTitle(Message msg) {
        UpdateUiActivity.this.setTitle(String.valueOf(msg.obj));
    }
    
    
}
posted @ 2011-12-14 14:57 雪山飞鹄 阅读(1674) | 评论 (0)编辑 收藏

ShortCutActivity
package com.zhy.shortcut;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ShortCutActivity extends Activity {

    
private static final String CREATE_SHORTCUT_ACTION = "com.android.launcher.action.INSTALL_SHORTCUT";

    
private static final String DROP_SHORTCUT_ACTION = "com.android.launcher.action.UNINSTALL_SHORTCUT";

    
private static final String PREFERENCE_KEY_SHORTCUT_EXISTS = "IsShortCutExists";

    Button button;

    
// 获取默认的SharedPreferences
    SharedPreferences sharedPreferences ;

    
// 从SharedPreferences获取是否存在快捷方式 若不存在返回false 程序第一次进来肯定返回false
    boolean exists ;

    @Override
    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
        sharedPreferences 
= PreferenceManager.getDefaultSharedPreferences(this);
        exists 
= sharedPreferences.getBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, false);
        
//创建桌面快捷方式
        
//若第一次启动则创建,下次启动则不创建
        if (!exists) {
            setUpShortCut();
        }
        
        Intent intent
=getIntent();
        String action
=intent.getAction();
        
//长按桌面 创建快捷方式
        if(Intent.ACTION_CREATE_SHORTCUT.equals(action)){
            
            Intent shortCut
=new Intent(Intent.ACTION_MAIN);
            shortCut.setClassName(
thisthis.getClass().getName());
            
            Intent data
=new Intent();
            
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(
this, R.drawable.logo));
            data.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
"sina");
            data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortCut);
            data.putExtra(
"duplicate"false);
            
            setResult(RESULT_OK, data);
            
            finish();
            
            
return;
        }
        
        setContentView(R.layout.main);

        button 
= (Button) findViewById(R.id.dropShortCut);

        button.setOnClickListener(
new OnClickListener() {

            @Override
            
public void onClick(View v) {
                tearDownShortCut();
            }
        });
    }

    
    
    
    
/**
     * 启动时创建桌面快捷方式
     
*/
    
private void setUpShortCut() {

        Intent intent 
= new Intent(CREATE_SHORTCUT_ACTION);

        
// 设置快捷方式图片
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.logo));

        
// 设置快捷方式名称
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

        
// 设置是否允许重复创建快捷方式 false表示不允许
        intent.putExtra("duplicate"false);

        
        
        
// 设置快捷方式要打开的intent
        
        
// 第一种方法创建快捷方式要打开的目标intent
        Intent targetIntent = new Intent();
        
// 设置应用程序卸载时同时也删除桌面快捷方式
        targetIntent.setAction(Intent.ACTION_MAIN);
        targetIntent.addCategory(
"android.intent.category.LAUNCHER");
        
        ComponentName componentName 
= new ComponentName(getPackageName(), this.getClass().getName());
        targetIntent.setComponent(componentName);
        

        
// 第二种方法创建快捷方式要打开的目标intent
        /*
         * Intent
         * targetIntent=getPackageManager().getLaunchIntentForPackage(getPackageName
         * ());
         
*/
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);

        
// 发送广播
        sendBroadcast(intent);

        Editor editor 
= sharedPreferences.edit();
        editor.putBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, 
true);
        editor.commit();

    }

    
/**
     * 删除桌面快捷方式
     
*/
    @Deprecated
    
private void tearDownShortCut() {

        Intent intent 
= new Intent(DROP_SHORTCUT_ACTION);
        
// 指定要删除的shortcut名称
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

        String appClass 
= getPackageName() + "." + this.getLocalClassName();

        ComponentName component 
= new ComponentName(getPackageName(), appClass);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent().setAction(Intent.ACTION_MAIN).setComponent(component));
        sendBroadcast(intent);

    }

    
    
    
    
    
    
    
    
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
="com.zhy.shortcut"
    android:versionCode
="1"
    android:versionName
="1.0" >

    
<uses-sdk android:minSdkVersion="8" />
    
<!-- 创建桌面快捷方式的权限 -->
    
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
    
<application
        
android:icon="@drawable/logo"
        android:label
="@string/app_name" >
        
<activity
            
android:label="@string/app_name"
            android:name
=".ShortCutActivity" >
            
<intent-filter >
                
<action android:name="android.intent.action.MAIN" />
                
<category android:name="android.intent.category.LAUNCHER" />
            
</intent-filter>
        
</activity>
        
<activity-alias
            
android:targetActivity=".ShortCutActivity"
            android:name
=".AliasShortCutActivity" >
            
<intent-filter >
                
<action android:name="android.intent.action.CREATE_SHORTCUT" />
                
<category android:name="android.intent.category.DEFAULT" />
            
</intent-filter>
        
</activity-alias>
    
</application>

</manifest>


posted @ 2011-12-13 14:24 雪山飞鹄 阅读(1723) | 评论 (0)编辑 收藏

创建快捷方式的主Activity
package com.zhy.weather;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;

public class SplashActivity extends Activity {
    
    @Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
        
final Intent intent=getIntent();
        
final String action=intent.getAction();
        
        
//设置允许创建快捷方式
        if(Intent.ACTION_CREATE_SHORTCUT.equals(action)){
            setupShortcut();
            finish();
            
return;
        }
        
        
        setContentView(R.layout.splash);
        
new Handler().postDelayed(new Runnable() {
            
            @Override
            
public void run() {
                SplashActivity.
this.startActivity(new Intent(SplashActivity.this, MainActivity.class));
                SplashActivity.
this.finish();
            }
        }, 
2000);
    }

    
//创建快捷方式
    private void setupShortcut() {
        
//目标Intent 打开快捷方式要启动的那个intent
        Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setClassName(
thisthis.getClass().getName());

        
// Then, set up the container intent (the response to the caller)

        Intent intent 
= new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
"小程序");
        Parcelable iconResource 
= Intent.ShortcutIconResource.fromContext(this,  R.drawable.app);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

        
// Now, return the result to the launcher

        setResult(RESULT_OK, intent);
    }
    
    
    
}

AndroidManifest.xml
<activity
            
android:name=".SplashActivity" >
            
<intent-filter >
                
<action android:name="android.intent.action.MAIN" />
                
<category android:name="android.intent.category.LAUNCHER" />
            
</intent-filter>
        
</activity>
        
        
<!-- 创建桌面快捷方式 -->            
        
<activity-alias android:name=".CreateShortcuts"
            android:targetActivity
=".SplashActivity">
            
<intent-filter>
                
<action android:name="android.intent.action.CREATE_SHORTCUT" />
                
<category android:name="android.intent.category.DEFAULT" />
            
</intent-filter>
        
</activity-alias>   
重点是注意activity-alias中的部分
android:name 就是取个别名的意思
android:targetActivity=".SplashActivity" 指定目标Activity
<action android:name="android.intent.action.CREATE_SHORTCUT" />指定该action才可以被android系统检索到

posted @ 2011-12-13 14:03 雪山飞鹄 阅读(1375) | 评论 (0)编辑 收藏

在Android中创建ShortCut大概有两种方法。
第一种方法就是参照api demos中写的那个,通过设置setResult(RESULT_OK, intent);来创建ShortCut,这种方式在稍后分析。
本文以Broadcast方式方式来介绍Android中ShortCut的创建。
在创建或删除ShortCut的时候先需要在AndroidManifest.xml中增加两个权限
<!-- 创建桌面快捷方式的权限 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>

另外记得在创建或删除ShortCut的Intent中设置Action为
com.android.launcher.action.INSTALL_SHORTCUT(创建)
com.android.launcher.action.UNINSTALL_SHORTCUT(删除)
这样发送出去的广播才能被Android系统接受到

详细的代码:
package com.zhy.shortcut;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ShortCutActivity extends Activity {

    
private static final String CREATE_SHORTCUT_ACTION = "com.android.launcher.action.INSTALL_SHORTCUT";

    
private static final String DROP_SHORTCUT_ACTION = "com.android.launcher.action.UNINSTALL_SHORTCUT";

    
private static final String PREFERENCE_KEY_SHORTCUT_EXISTS = "IsShortCutExists";

    Button button;

    
// 获取默认的SharedPreferences
    SharedPreferences sharedPreferences ;

    
// 从SharedPreferences获取是否存在快捷方式 若不存在返回false 程序第一次进来肯定返回false
    boolean exists ;

    @Override
    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
        sharedPreferences 
= PreferenceManager.getDefaultSharedPreferences(this);
        exists 
= sharedPreferences.getBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, false);
        
//创建桌面快捷方式
        
//若第一次启动则创建,下次启动则不创建
        if (!exists) {
            setUpShortCut();
        }
        setContentView(R.layout.main);

        button 
= (Button) findViewById(R.id.dropShortCut);

        button.setOnClickListener(
new OnClickListener() {

            @Override
            
public void onClick(View v) {
                tearDownShortCut();
            }
        });
    }

    
/**
     * 创建桌面快捷方式
     
*/
    
private void setUpShortCut() {

        Intent intent 
= new Intent(CREATE_SHORTCUT_ACTION);

        
// 设置快捷方式图片
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.logo));

        
// 设置快捷方式名称
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

        
// 设置是否允许重复创建快捷方式 false表示不允许
        intent.putExtra("duplicate"false);

        
        
        
// 设置快捷方式要打开的intent
        
        
// 第一种方法创建快捷方式要打开的目标intent
        Intent targetIntent = new Intent();
        
// 设置应用程序卸载时同时也删除桌面快捷方式
        targetIntent.setAction(Intent.ACTION_MAIN);
        targetIntent.addCategory(
"android.intent.category.LAUNCHER");
        
        ComponentName componentName 
= new ComponentName(getPackageName(), this.getClass().getName());
        targetIntent.setComponent(componentName);
        

        
// 第二种方法创建快捷方式要打开的目标intent
        /*
         * Intent
         * targetIntent=getPackageManager().getLaunchIntentForPackage(getPackageName
         * ());
         
*/
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);

        
// 发送广播
        sendBroadcast(intent);

        Editor editor 
= sharedPreferences.edit();
        editor.putBoolean(PREFERENCE_KEY_SHORTCUT_EXISTS, 
true);
        editor.commit();

    }

    
/**
     * 删除桌面快捷方式
     
*/
    
private void tearDownShortCut() {

        Intent intent 
= new Intent(DROP_SHORTCUT_ACTION);
        
// 指定要删除的shortcut名称
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "sina");

        String appClass 
= getPackageName() + "." + this.getLocalClassName();

        ComponentName component 
= new ComponentName(getPackageName(), appClass);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new Intent().setAction(Intent.ACTION_MAIN).setComponent(component));
        sendBroadcast(intent);

    }

}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
="com.zhy.shortcut"
    android:versionCode
="1"
    android:versionName
="1.0" >

    
<uses-sdk android:minSdkVersion="8" />
    
<!-- 创建桌面快捷方式的权限 -->
    
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>
    
<application
        
android:icon="@drawable/ic_launcher"
        android:label
="@string/app_name" >
        
<activity
            
android:label="@string/app_name"
            android:name
=".ShortCutActivity" >
            
<intent-filter >
                
<action android:name="android.intent.action.MAIN" />
                
<category android:name="android.intent.category.LAUNCHER" />
            
</intent-filter>
        
</activity>
    
</application>

</manifest>

注意:该方式创建的ShortCut会在启动应用的时候就创建ShortCut。下一讲中的创建方式,仅仅只是在长按Android桌面后你的当前应用创建的快捷方式可以在这里检索到,需要你手动创建出来。
posted @ 2011-12-13 13:56 雪山飞鹄 阅读(4713) | 评论 (0)编辑 收藏

 核心JavaScript代码

<script type="text/javascript">
        
function bringToExcel(){  
             
var pasteText="全部统计表 ";     
             pasteText
=pasteText+document.all.ExcelBiao.innerHTML;
             window.clipboardData.setData (
"Text", pasteText);   
             
var oXL = new ActiveXObject("Excel.Application");     
             oXL.Visible 
= true;     
             
var oWB = oXL.Workbooks.Add();     
             
var oSheet = oWB.ActiveSheet;     
             oSheet.Paste();     
             oXL.Visible 
= true;     
             oXL.UserControl 
= true;
        }  
        
//导出word  
        function OpenWord2(){  
            ExcelSheet 
= new ActiveXObject('Word.Application');
            ExcelSheet.Application.Visible 
= true;
            
var mydoc=ExcelSheet.Documents.Add('',0,0);
            myRange 
=mydoc.Range(0,1);
            myRange 
=mydoc.Range(myRange.End-1,myRange.End);//设定起始点    
            var sel=document.body.createTextRange();
            sel.moveToElementText(AoutWord);
//设置要导出的表格名称
            sel.select();
            document.execCommand('Copy');
            sel.moveEnd('character');
            myRange.Paste();
            myRange 
=mydoc.Range(myRange.End-1,myRange.End);
            myRange.InsertAfter(
"\n");
            ExcelSheet.ActiveWindow.View.TableGridlines 
= false;
        } 
        
</script>

具体看附件
ExportWordAndExcel

posted @ 2011-12-13 11:51 雪山飞鹄 阅读(2144) | 评论 (2)编辑 收藏

package com.zhy.weather.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.Drawable;

/**
 * Android图像处理类
 * 
 * 
@author scott
 * 
 
*/
public class ImageUtil {

    
// 放大缩小图片
    public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) {
        
int width = bitmap.getWidth();
        
int height = bitmap.getHeight();
        Matrix matrix 
= new Matrix();
        
float scaleWidht = ((float) w / width);
        
float scaleHeight = ((float) h / height);
        matrix.postScale(scaleWidht, scaleHeight);
        Bitmap newbmp 
= Bitmap.createBitmap(bitmap, 00, width, height,
                matrix, 
true);
        
return newbmp;
    }

    
// 将Drawable转化为Bitmap
    public static Bitmap drawableToBitmap(Drawable drawable) {
        
int width = drawable.getIntrinsicWidth();
        
int height = drawable.getIntrinsicHeight();
        Bitmap bitmap 
= Bitmap.createBitmap(width, height, drawable
                .getOpacity() 
!= PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                : Bitmap.Config.RGB_565);
        Canvas canvas 
= new Canvas(bitmap);
        drawable.setBounds(
00, width, height);
        drawable.draw(canvas);
        
return bitmap;

    }

    
// 获得圆角图片的方法
    public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {

        Bitmap output 
= Bitmap.createBitmap(bitmap.getWidth(),
                bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas 
= new Canvas(output);

        
final int color = 0xff424242;
        
final Paint paint = new Paint();
        
final Rect rect = new Rect(00, bitmap.getWidth(), bitmap.getHeight());
        
final RectF rectF = new RectF(rect);

        paint.setAntiAlias(
true);
        canvas.drawARGB(
0000);
        paint.setColor(color);
        canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

        paint.setXfermode(
new PorterDuffXfermode(Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, rect, paint);

        
return output;
    }

    
// 获得带倒影的图片方法
    public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
        
final int reflectionGap = 4;
        
int width = bitmap.getWidth();
        
int height = bitmap.getHeight();

        Matrix matrix 
= new Matrix();
        matrix.preScale(
1-1);

        Bitmap reflectionImage 
= Bitmap.createBitmap(bitmap, 0, height / 2,
                width, height 
/ 2, matrix, false);

        Bitmap bitmapWithReflection 
= Bitmap.createBitmap(width,
                (height 
+ height / 2), Config.ARGB_8888);

        Canvas canvas 
= new Canvas(bitmapWithReflection);
        canvas.drawBitmap(bitmap, 
00null);
        Paint deafalutPaint 
= new Paint();
        canvas.drawRect(
0, height, width, height + reflectionGap, deafalutPaint);

        canvas.drawBitmap(reflectionImage, 
0, height + reflectionGap, null);

        Paint paint 
= new Paint();
        LinearGradient shader 
= new LinearGradient(0, bitmap.getHeight(), 0,
                bitmapWithReflection.getHeight() 
+ reflectionGap, 0x70ffffff,
                
0x00ffffff, TileMode.CLAMP);
        paint.setShader(shader);
        
// Set the Transfer mode to be porter duff and destination in
        paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
        
// Draw a rectangle using the paint with our linear gradient
        canvas.drawRect(0, height, width, bitmapWithReflection.getHeight()
                
+ reflectionGap, paint);

        
return bitmapWithReflection;
    }

}

//将bitmap转化为drawable
//Drawable drawable=new BitmapDrawable(bitmap);
//imgdrawable.setImageDrawable(drawable);
posted @ 2011-12-12 17:00 雪山飞鹄 阅读(1421) | 评论 (0)编辑 收藏

首先配置AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
="com.zhy.test"
    android:versionCode
="1"
    android:versionName
="1.0" >

    
<uses-sdk android:minSdkVersion="8" />

    
<!-- 
        设置instrumentation
        android:name="android.test.InstrumentationTestRunner"固定值
        android:targetPackage="com.zhy.test" android:targetPackage和manifest中的包名一致
    
-->
    
<instrumentation
        
android:name="android.test.InstrumentationTestRunner"
        android:targetPackage
="com.zhy.test" />


    
<application
        
android:icon="@drawable/ic_launcher"
        android:label
="@string/app_name" >
        
<!-- 指定Android做单元测试用到的library -->
        
<uses-library android:name="android.test.runner" />
    
</application>

</manifest>

android:name="android.test.InstrumentationTestRunner"固定值
android:targetPackage="com.zhy.test" android:targetPackage和manifest中的包名一致

在<application>节点下指定Android做单元测试用到的library
<uses-library android:name="android.test.runner" />

编写Android单元测试类
package com.zhy.test;

import android.test.AndroidTestCase;
import android.util.Log;

public class JunitTest extends AndroidTestCase {
    
    @Override
    
protected void setUp() throws Exception {
        Log.i(
"JunitTest""---------setUp()---------");
        
super.setUp();
    }

    @Override
    
protected void tearDown() throws Exception {
        Log.i(
"JunitTest""---------tearDown()---------");
        
super.tearDown();
    }
    
    
public void testJunit() throws Exception {
        Log.i(
"JunitTest""---------testJunit()---------");
    }
    
}
其中setUp()和tearDown()方法用意跟junit中的作用一样
注意用作单元测试的方法要声明为public否则不能被调用到
其方法原型为:
public void 方法名() throws Exception {
    //do somthing
 }
这里方法的名字可以不必以test开头

注意:
        <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.zhy.weather"
        android:label="Android TestCase"
        >
中android:targetPackage="com.zhy.weather" android:targetPackage必须和<manifest package="com.zhy.weather">保持一致
单元测试可以和应用不在同一个包下。

posted @ 2011-12-12 09:38 雪山飞鹄 阅读(4586) | 评论 (0)编辑 收藏


create temporary tablespace transfer_temp tempfile 'd:\oracle\OracleData\transfer_temp.dbf' size 10m autoextend on next 10m maxsize unlimited extent management local; 

create tablespace transfer_data logging datafile 'd:\oracle\OracleData\transfer_data.dbf' size 20m autoextend on next 20m maxsize unlimited extent management local; 

create user transfer identified by transfer default tablespace transfer_data temporary tablespace transfer_temp; 

grant connect,resource,dba to transfer; 

conn transfer
/transfer;
posted @ 2011-11-25 08:58 雪山飞鹄 阅读(787) | 评论 (0)编辑 收藏

JAR版本:urlrewrite-3.2.0.jar
web.xml配置
    <filter>
        
<filter-name>UrlRewriteFilter</filter-name>
        
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        
<init-param>
            
<param-name>confReloadCheckInterval</param-name>
            
<param-value>60</param-value>
        
</init-param>
        
<init-param>
            
<param-name>confPath</param-name>
            
<param-value>/WEB-INF/urlrewrite.xml</param-value>
        
</init-param>
     
</filter>
     
     
<filter-mapping>
         
<filter-name>UrlRewriteFilter</filter-name>
         
<dispatcher>REQUEST</dispatcher>
         
<dispatcher>FORWARD</dispatcher>
         
<url-pattern>/*</url-pattern>
     
</filter-mapping>
urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"
>

<!--

    Configuration file for UrlRewriteFilter
    http://tuckey.org/urlrewrite/

-->
<urlrewrite> 
    
<!-- 
        匹配地址为
        形如/content/94/list的地址将跳转到
        /IssuedContentAction.do?dispatch=vContentListBySubid&amp;scope=vmcontent&amp;columninfoid=$1
    
-->
    
<rule>
        
<!-- 地址栏显示的地址 -->
        
<from>/content/([0-9]+)/list</from>  
        
<!-- 真实的请求地址 -->
        
<to type="forward">/IssuedContentAction.do?dispatch=vContentListBySubid&amp;scope=vmcontent&amp;columninfoid=$1</to>
    
</rule>
    
<!--

    INSTALLATION

        in your web.xml add

        <filter>
            <filter-name>UrlRewriteFilter</filter-name>
            <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
            <init-param>
                <param-name>logLevel</param-name>
                <param-value>WARN</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>UrlRewriteFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

     EXAMPLES

     Redirect one url
        <rule>
            <from>/some/old/page.html</from>
            <to type="redirect">/very/new/page.html</to>
        </rule>

    Redirect a directory
        <rule>
            <from>/some/olddir/(.*)</from>
            <to type="redirect">/very/newdir/$1</to>
        </rule>

    Clean a url
        <rule>
            <from>/products/([0-9]+)</from>
            <to>/products/index.jsp?product_id=$1</to>
        </rule>
    eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.

    Browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <from>/some/page.html</from>
            <to>/some/page-for-old-browsers.html</to>
        </rule>
    eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
    browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.

    Centralised browser detection
        <rule>
            <condition name="user-agent">Mozilla/[1-4]</condition>
            <set type="request" name="browser">moz</set>
        </rule>
    eg, all requests will be checked against the condition and if matched
    request.setAttribute("browser", "moz") will be called.

    
-->

</urlrewrite>
注意:
1、多个参数之间的连接符要用&amp;而不是&
2、匹配从应用程序的名称开始匹配

浏览器中显示的请求地址(请求链接中填写的地址)
/content/91/list
真正的请求地址
/IssuedContentAction.do?dispatch=vContentListBySubid&scope=vmcontent&columninfoid=91


posted @ 2011-11-24 11:48 雪山飞鹄 阅读(918) | 评论 (0)编辑 收藏

偶尔写写php感觉心情还是蛮舒畅的(Java里的Struts+Hibernate+Spring写久了),写写php才知道,这种被解放的感觉真好。不得不说,php是一种服务器端比较精辟的语言,难怪崇拜者这么多。就来整整flex基于php的交互,看好了,这里要介绍的不是通过flex里面的HttpService组件与php交互,而是借助AMFPHP通过RemoteObject方式来交互。
关于amfphp环境的搭建,请参考本人写的amfphp环境搭建教程,当然里面写的比较粗略,有不清粗的可以联系我。
先来看看php端代码
ProductServices.php
<?php
class ProductServices{
    
/**
    *query product list
    
*/
    
function getProductList(){
        
$link=@mysql_connect("localhost", "root", "") or die("Could not connect");
        
mysql_select_db("compass",$link);
        
mysql_query("set names utf8",$link);
        
$result = mysql_query("SELECT * FROM product",$link);
        
$array=array();
        
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            
array_push($array,$row);
        }
        
mysql_free_result($result);
        
mysql_close($link);
        
return $array;
    }



    
function findProductById($id){
        
$link=@mysql_connect("localhost", "root", "") or die("Could not connect");
        
mysql_select_db("compass",$link);
        
mysql_query("set names utf8",$link);
        
$result = mysql_query("SELECT * FROM product where id= ".$id,$link);
        
$array=array();
        
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            
array_push($array,$row);
        }
        
mysql_free_result($result);
        
mysql_close($link);
        
return $array;
    }

}
?>

在ProductServices.php文件中,定义了一个类ProductServices,里面封装了两个方法,getProductList(),findProductById($id)里面内容很简单,一个是全部查询商品,一个是根据Id查询商品

注意该文件存放的位置C:\inetpub\wwwroot\amfphp\services\ 这样可以被amfphp的资源管理器检索到
 


编写flex端代码
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s
="library://ns.adobe.com/flex/spark" 
               xmlns:mx
="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete
="ro.getOperation('getProductList').send()"
               
>
    
<!-- 
        ro.getOperation('getProductList').send() 
        ro为RemoteObject的Id
        ro.getOperation('getProductList')获取php文件中的方法名,及要调用服务器端的那个方法
        send()发送请求,在send中可传递参数,多个参数之间用逗号分隔,参数名要与服务器端的参数名一致
    
-->
    
<fx:Declarations>
        
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
        
        
<s:RemoteObject id="ro" 
                        destination
="amfphp"  
                        source
="ProductServices" 
                        fault
="getProductList_faultHandler(event)" 
                        result
="getProductList_resultHandler(event)"
                        endpoint
="http://192.168.3.11/amfphp/gateway.php">
        
</s:RemoteObject>
        
        
<!--
            RemoteObject中的destination需要与src目录下的services
-config.xml中定义的destination的Id保持一致
            source
="ProductServices"要调用服务器端的那个php类,如果存在包的话注意包名.类名
            fault 失败时响应的方法
            result 成功时的方法
            endpoint
="http://192.168.3.11/amfphp/gateway.php" 正确访问gateway.php的地址
        
-->
        
    
</fx:Declarations>
    
    
<fx:Script>
        
<![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ArrayUtil;
            
            [Bindable]
            internal 
var dp:ArrayCollection;
            
            
            
            
//amfphp请求成功时调用方法
            protected function getProductList_resultHandler(event:ResultEvent):void
            {
                dp
=new ArrayCollection(ArrayUtil.toArray(event.result));
            }
            
//amfphp请求失败时调用方法
            protected function getProductList_faultHandler(event:FaultEvent):void
            {
                Alert.show(
"失败了",event.fault.message);                
            }
            
        ]]
>
    
</fx:Script>
    
    
    
<s:layout>
        
<s:HorizontalLayout/>
    
</s:layout>
    
<s:DataGrid width="519" height="292" dataProvider="{dp}" requestedRowCount="4">
        
<s:columns>
            
<s:ArrayList>
                
<s:GridColumn dataField="id" headerText="编号"></s:GridColumn>
                
<s:GridColumn dataField="name" headerText="商品名称"></s:GridColumn>
                
<s:GridColumn dataField="price" headerText="单价"></s:GridColumn>
                
<s:GridColumn dataField="descption" headerText="描述"></s:GridColumn>
            
</s:ArrayList>
        
</s:columns>
    
</s:DataGrid>
    
</s:Application>

必须在flex工程的src目录下存放一个名为services-config.xml
<? version="1.0" encoding="UTF-8"?>
<services-config>
    
<services>
        
<service id="sabreamf-flashremoting-service"
                 class
="flex.messaging.services.RemotingService"
                 messageTypes
="flex.messaging.messages.RemotingMessage">
            
<destination id="amfphp">
                
<channels>
                    
<channel ref="my-amfphp"/>
                
</channels>
                
<properties>
                    
<source>*</source>
                
</properties>
            
</destination>
        
</service>
    
</services>

    
<channels>
        
<channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
            
<endpoint uri="http://192.168.3.11/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/>
        
</channel-definition>
    
</channels>
</services-config>

需要将该文件编译到环境中去

效果图

点我下载代码
posted @ 2011-10-28 11:52 雪山飞鹄 阅读(2184) | 评论 (0)编辑 收藏

仅列出标题
共22页: 上一页 1 2 3 4 5 6 7 8 9 下一页 Last