2011年12月5日

[Android]Activity返回上一頁

page1

package Demo;
 
/* import相關class */
import java.text.DecimalFormat;
import java.text.NumberFormat;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
 
public class Page1 extends Activity 
{
  Intent intent;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    /* 載入mylayout.xml Layout */
    setContentView(R.layout.myalyout);
     
     
    Button b1 = (Button) findViewById(R.id.button1);
    b1.setOnClickListener(new Button.OnClickListener()
    {
      public void onClick(View v)
      {
       /* 回傳result回上一個activity */
       Page1.this.setResult(RESULT_OK, intent);
        
       /* 關閉activity */
       Page1.this.finish();
      }
    });
  }
}

page2
package Demo;

/* import相關class */
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class Page2 extends Activity 
{
    
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    /* 載入main.xml Layout */
    setContentView(R.layout.main);
   
        /*new一個Intent物件,並指定class*/
     Intent intent = new Intent();
        intent.setClass(Page2.this,Page1.class);
     
     /*呼叫Activity EX03_11_1*/
     startActivityForResult(intent,0);
      }
  
  /* 覆寫 onActivityResult()*/
  @Override
  protected void onActivityResult(int requestCode, int resultCode,
                                  Intent data)
  {
    switch (resultCode)
    { 
      case RESULT_OK:
//回上一頁囉
        break;       
      default: 
        break; 
     } 
   } 
}

2011年11月27日

[PHP] 程式小技巧

[迴圈的使用]

//PHP3 or old
reset($attributes);
while (list($key, $value) = each($attributes)) {
    //do something
}
//PHP4
foreach ($attributes as $key => $value){
   //do something
}



[簡查重覆的資料]
SELECT username,COUNT(*)/*重複出現的次數*/ FROM member GROUP BY username HAVING COUNT(*) > 1 /*列出重複出現一次以上的資料*/

2011年11月24日

[Android] 取得檔案位置

package tw.Goocue;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {
   @Override 
   public void onCreate(Bundle icicle)
   {
     // TODO Auto-generated method stub 
     super.onCreate(icicle);
        setContentView(R.layout.main);
        
        Button b = (Button)this.findViewById(R.id.b1);
        
        b.setOnClickListener( new OnClickListener(){
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                
                // 建立 "選擇檔案 Action" 的 Intent
                Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
                
                // 過濾檔案格式
                intent.setType( "*/*" );
                
                // 建立 "檔案選擇器" 的 Intent  (第二個參數: 選擇器的標題)
                Intent destIntent = Intent.createChooser( intent, "選擇檔案" );
                
                // 切換到檔案選擇器 (它的處理結果, 會觸發 onActivityResult 事件)
                startActivityForResult( destIntent, 0 );
            }
        });
   }
   
   @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         
         // TODO Auto-generated method stub
         super.onActivityResult(requestCode, resultCode, data);
         
         // 有選擇檔案
         if ( resultCode == RESULT_OK )
         {
             // 取得檔案的 Uri
             Uri uri = data.getData();
             if( uri != null )
             {
               Cursor cursor = this.getContentResolver().query(uri, null, null, null, null);
                  cursor.moveToFirst();
                  
                  for (int i = 0; i < cursor.getColumnCount(); i++) {
                   
                   
                   setTitle( i+"-"+cursor.getString(1));
                   }
                 // 利用 Uri 顯示 ImageView 圖片
                // setTitle( uri.toString() );
             }
             else
             {
                 setTitle("無效的檔案路徑 !!");
             }
         }
         else
         {
             setTitle("取消選擇檔案 !!");
         }
     }

}

[PHP] 清除網頁快取



//變成Function
function nocache_headers() {
@ header('Expires: Thu, 01 Jan 1970 00:00:01 GMT');
@ header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
@ header('Cache-Control: no-cache, must-revalidate, max-age=0');
@ header('Pragma: no-cache');
}
nocache_headers();

2011年10月2日

[Android]直向、橫向的設定


問題:
Android 螢幕的直向?橫向?




一、程式碼

Activity.java

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //強置為橫向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //強置為直向
        

[Android] 動畫的實現





一、程式碼

Activity.java

package tw.G000E004;

import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class G000E004Activity extends Activity {
    Animation myanimation;
    ImageView img;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        myanimation=AnimationUtils.loadAnimation(this, R.anim.myanim);
        img=(ImageView)findViewById(R.id.img);
        
        img.startAnimation(myanimation);
    }
}


myanim.xml(記得加入)


android:fillafter="false"
android:fromxscale="0.0"
android:fromyscale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotx="50%"
android:pivoty="50%"
android:toxscale="1.4"
android:toyscale="1.4">
android:fromxdelta="30"
android:fromydelta="30"
android:toxdelta="0"
android:toydelta="50">
android:fromdegrees="0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotx="50%"
android:pivoty="50%"
android:todegrees="+350">

main.xml(記得加入)

android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
android:layout_width="fill_parent"
android:text="@string/hello">
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/icon">


2011年9月25日

[PHP]在網頁中加入 Google Map

  1. [ 按此進入 ] Google Maps API Key申請頁面。
  2. 申請Google Mass API的網址填入
  3.  取得 Key。
  4. 最後會出現三個方塊,分別是你取得的 Key,你指定的 URL,以及一個範例。
  5. 將JavaScript需放至之間。