溫馨提示:您的每一次轉載,體現(xiàn)了我寫此文的意義!!!煩請您在轉載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          雪山飛鵠

          溫馨提示:您的每一次轉載,體現(xiàn)了我寫此文的意義!!!煩請您在轉載時注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

          #

          需求:在界面上有兩個按鈕,一個開始,一個停止。點擊開始按鈕,更新應用的標題為當前時間。按停止按鈕停止更新時間。
          考察:handler的使用。
          這里借助Handler+Timer+TimerTask來實現(xiàn)

          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:
                      //創(chuàng)建一個定時器
                      Timer timer=new Timer();
                      //創(chuàng)建TimerTask
                      task=new TimerTask() {
                          
                          //實現(xiàn)run方法,這里存放需要實時更新時間的代碼
                          @Override
                          public void run() {
                              //創(chuàng)建一個消息體
                              Message message=new Message();
                              //標記消息
                              message.what=UPDATA_TITIE;
                              //傳遞數(shù)據(jù)
                              message.obj=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss").format(new Date());
                              //發(fā)送消息
                              handler.sendMessage(message);
                          }
                      };
                      //調度,每隔一秒中執(zhí)行一次
                      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 雪山飛鵠 閱讀(1694) | 評論 (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);
                  
          //創(chuàng)建桌面快捷方式
                  
          //若第一次啟動則創(chuàng)建,下次啟動則不創(chuàng)建
                  if (!exists) {
                      setUpShortCut();
                  }
                  
                  Intent intent
          =getIntent();
                  String action
          =intent.getAction();
                  
          //長按桌面 創(chuàng)建快捷方式
                  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();
                      }
                  });
              }

              
              
              
              
          /**
               * 啟動時創(chuàng)建桌面快捷方式
               
          */
              
          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");

                  
          // 設置是否允許重復創(chuàng)建快捷方式 false表示不允許
                  intent.putExtra("duplicate"false);

                  
                  
                  
          // 設置快捷方式要打開的intent
                  
                  
          // 第一種方法創(chuàng)建快捷方式要打開的目標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);
                  

                  
          // 第二種方法創(chuàng)建快捷方式要打開的目標intent
                  /*
                   * Intent
                   * targetIntent=getPackageManager().getLaunchIntentForPackage(getPackageName
                   * ());
                   
          */
                  intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);

                  
          // 發(fā)送廣播
                  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" />
              
          <!-- 創(chuàng)建桌面快捷方式的權限 -->
              
          <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 雪山飛鵠 閱讀(1749) | 評論 (0)編輯 收藏

          創(chuàng)建快捷方式的主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();
                  
                  
          //設置允許創(chuàng)建快捷方式
                  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);
              }

              
          //創(chuàng)建快捷方式
              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>
                  
                  
          <!-- 創(chuàng)建桌面快捷方式 -->            
                  
          <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系統(tǒng)檢索到

          posted @ 2011-12-13 14:03 雪山飛鵠 閱讀(1397) | 評論 (0)編輯 收藏

          在Android中創(chuàng)建ShortCut大概有兩種方法。
          第一種方法就是參照api demos中寫的那個,通過設置setResult(RESULT_OK, intent);來創(chuàng)建ShortCut,這種方式在稍后分析。
          本文以Broadcast方式方式來介紹Android中ShortCut的創(chuàng)建。
          在創(chuàng)建或刪除ShortCut的時候先需要在AndroidManifest.xml中增加兩個權限
          <!-- 創(chuàng)建桌面快捷方式的權限 -->
          <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
          <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/>

          另外記得在創(chuàng)建或刪除ShortCut的Intent中設置Action為
          com.android.launcher.action.INSTALL_SHORTCUT(創(chuàng)建)
          com.android.launcher.action.UNINSTALL_SHORTCUT(刪除)
          這樣發(fā)送出去的廣播才能被Android系統(tǒng)接受到

          詳細的代碼:
          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);
                  
          //創(chuàng)建桌面快捷方式
                  
          //若第一次啟動則創(chuàng)建,下次啟動則不創(chuàng)建
                  if (!exists) {
                      setUpShortCut();
                  }
                  setContentView(R.layout.main);

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

                  button.setOnClickListener(
          new OnClickListener() {

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

              
          /**
               * 創(chuàng)建桌面快捷方式
               
          */
              
          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");

                  
          // 設置是否允許重復創(chuàng)建快捷方式 false表示不允許
                  intent.putExtra("duplicate"false);

                  
                  
                  
          // 設置快捷方式要打開的intent
                  
                  
          // 第一種方法創(chuàng)建快捷方式要打開的目標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);
                  

                  
          // 第二種方法創(chuàng)建快捷方式要打開的目標intent
                  /*
                   * Intent
                   * targetIntent=getPackageManager().getLaunchIntentForPackage(getPackageName
                   * ());
                   
          */
                  intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);

                  
          // 發(fā)送廣播
                  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" />
              
          <!-- 創(chuàng)建桌面快捷方式的權限 -->
              
          <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>

          注意:該方式創(chuàng)建的ShortCut會在啟動應用的時候就創(chuàng)建ShortCut。下一講中的創(chuàng)建方式,僅僅只是在長按Android桌面后你的當前應用創(chuàng)建的快捷方式可以在這里檢索到,需要你手動創(chuàng)建出來。
          posted @ 2011-12-13 13:56 雪山飛鵠 閱讀(4737) | 評論 (0)編輯 收藏

           核心JavaScript代碼

          <script type="text/javascript">
                  
          function bringToExcel(){  
                       
          var pasteText="全部統(tǒng)計表 ";     
                       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 雪山飛鵠 閱讀(2188) | 評論 (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 雪山飛鵠 閱讀(1436) | 評論 (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>節(jié)點下指定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 雪山飛鵠 閱讀(4603) | 評論 (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 雪山飛鵠 閱讀(806) | 評論 (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、多個參數(shù)之間的連接符要用&amp;而不是&
          2、匹配從應用程序的名稱開始匹配

          瀏覽器中顯示的請求地址(請求鏈接中填寫的地址)
          /content/91/list
          真正的請求地址
          /IssuedContentAction.do?dispatch=vContentListBySubid&scope=vmcontent&columninfoid=91


          posted @ 2011-11-24 11:48 雪山飛鵠 閱讀(942) | 評論 (0)編輯 收藏

          偶爾寫寫php感覺心情還是蠻舒暢的(Java里的Struts+Hibernate+Spring寫久了),寫寫php才知道,這種被解放的感覺真好。不得不說,php是一種服務器端比較精辟的語言,難怪崇拜者這么多。就來整整flex基于php的交互,看好了,這里要介紹的不是通過flex里面的HttpService組件與php交互,而是借助AMFPHP通過RemoteObject方式來交互。
          關于amfphp環(huán)境的搭建,請參考本人寫的amfphp環(huán)境搭建教程,當然里面寫的比較粗略,有不清粗的可以聯(lián)系我。
          先來看看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)里面內容很簡單,一個是全部查詢商品,一個是根據(jù)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()發(fā)送請求,在send中可傳遞參數(shù),多個參數(shù)之間用逗號分隔,參數(shù)名要與服務器端的參數(shù)名一致
              
          -->
              
          <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>

          需要將該文件編譯到環(huán)境中去

          效果圖

          點我下載代碼
          posted @ 2011-10-28 11:52 雪山飛鵠 閱讀(2203) | 評論 (0)編輯 收藏

          僅列出標題
          共22頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 密云县| 博乐市| 阿图什市| 石景山区| 夹江县| 乐昌市| 民县| 德清县| 辽阳市| 尚义县| 汉阴县| 牡丹江市| 库尔勒市| 罗田县| 江北区| 洪泽县| 东安县| 牟定县| 满洲里市| 德清县| 满城县| 崇左市| 武宣县| 浠水县| 黎川县| 休宁县| 界首市| 海城市| 西乌珠穆沁旗| 宣威市| 永修县| 温宿县| 布拖县| 安仁县| 梅州市| 南投县| 永康市| 姚安县| 沈阳市| 瑞昌市| 涟源市|