2012年10月21日 星期日

Android take picture, crop picture, select picture by using intent

Take Picture
public static Uri takePhoto( Activity act )
 {
  //Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  //act.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
  
  Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  Uri mImageCaptureUri = Uri.fromFile( new File( Environment.getExternalStorageDirectory(), "tmp_contact_" + String.valueOf(System.currentTimeMillis()) + ".jpg") );
  
  cameraIntent.putExtra( android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri );
  
  try
  {
   cameraIntent.putExtra( "return-data", true);
   act.startActivityForResult(cameraIntent, PICK_FROM_CAMERA);
  }
  catch( ActivityNotFoundException e )
  {
   
  }
  
  return mImageCaptureUri;
 
 }
Crop Picture
@Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
      
      if ( resultCode != RESULT_OK )
      {
       File f = new File( _imageCaptureUri.getPath() );
       if ( f.exists() )
       {
        f.delete();
       }
       
       return;
      }
      
      switch ( requestCode )
      {
      case CameraCaptureAPI.CROP_FROM_CAMERA:
       
       final Bundle extras = data.getExtras();
       
       if ( extras != null )
       {
        final Bitmap photo = extras.getParcelable("data");
        
         AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
         alert.setTitle( getString( R.string.confirm ) );  

          alert.setPositiveButton( R.string.confirm, new DialogInterface.OnClickListener() {  
             public void onClick(DialogInterface dialog, int whichButton) {  
              
              PictureUploadAPI.uploadPicture( photo, ProfileViewActivity.this );
             }           
               
           });  

           alert.setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() {

                 public void onClick(DialogInterface dialog, int which) {
                     // TODO Auto-generated method stub
                        
                 }
             });
                     
             alert.show();
       
       }
       
       File f = new File( _imageCaptureUri.getPath() );
       if ( f.exists() )
       {
        f.delete();
       }
      
       break;
      
      case CameraCaptureAPI.PICK_FROM_FILE:
      Intent intent = new Intent( "com.android.camera.action.CROP" );
      _imageCaptureUri = data.getData();
      intent.setDataAndType( _imageCaptureUri, "image/*"); //!!! important
      intent.putExtra("outputX", 96);
      intent.putExtra("outputY", 96);
      intent.putExtra("aspectX", 1);
      intent.putExtra("aspectY", 1);
      intent.putExtra("scale", true);
      intent.putExtra("return-data", true);
      
      try
      {
         startActivityForResult(intent, CameraCaptureAPI.CROP_FROM_CAMERA);
      }
      catch ( Exception e )
      {
       Log.d("pick picture", e.getMessage());
      }
      
      break;
      
      case CameraCaptureAPI.PICK_FROM_CAMERA:
      Intent intent1 = new Intent( "com.android.camera.action.CROP" );
      intent1.setDataAndType(_imageCaptureUri, "image/*"); //!!! important
      intent1.putExtra("outputX", 96);
      intent1.putExtra("outputY", 96);
      intent1.putExtra("aspectX", 1);
      intent1.putExtra("aspectY", 1);
      intent1.putExtra("scale", true);
      intent1.putExtra("return-data", true);
      
      try
      {
         startActivityForResult(intent1, CameraCaptureAPI.CROP_FROM_CAMERA);
      }
      catch ( Exception e )
      {
       Log.d("pick picture", e.getMessage());
      }
      
      break;
      }
     }
Select Picture
 Intent intent = new Intent( Intent.ACTION_GET_CONTENT );
 intent.setType( "image/*" );
           
 try{
      startActivityForResult( intent, CameraCaptureAPI.PICK_FROM_FILE );
 }
 catch( Exception e )
 {
     Log.d("browse picture", e.getMessage());
 }

http://www.technotalkative.com/android-launch-native-camera-application-to-capture-image-and-use-it-inside-imageview/

2012年10月14日 星期日

The San Francisco Games Revolution Is Over

舊金山一直都是產業革命的出生地,遊戲曾經是他們最感興趣的投資項目,Facebook、iOS、Android、Social game,甚至後來的Gamification應用無不都帶來了巨大的成功。不過它已經被改變了:
Social: 被過於高估,不持久。
Price: 開始有了削價競爭。
Scale: 規模太大,平台太多。
Behaviourism: 有些模式沒辦法一直反覆使用,玩家發覺後,這東西價值就變低了。

最後的競爭利器: Graphics! Graphics! Graphics! 九零年代到2006年,Graphics一直都是工作室彼此的主要競爭項目,成本不斷被堆高,到了現在竄出頭的mobile game、social game,還是要靠Graphics來決鬥。

不過誰又能知道下一代的舊金山遊戲革命會是甚麼呢?


2012年10月12日 星期五

Performance tips on JavaScriptV8

2012年10月7日 星期日

中國手機上網用戶行為研究

中國大陸使用手機上網的行為研究: 中國大陸使用手機上網的比例已經超過70%,特別是1~3小時的破碎時間,如果仍在做桌上型裝置的網路遊戲我個人覺得有點堪憂。不過他研究的手機上網行為內,遊戲並沒有排進他的排名,可見想用手機上網玩遊戲的比例亦不高(但另外一篇則排進10%),再者如果有看網路女王的趨勢分析,其實另外一點需要再挑戰,就是ARPU還是有3:1的差距...

http://www.docin.com/p-414448925.html
http://www.cnnic.cn/hlwfzyj/hlwxzbg/ydhlwbg/201209/P020120917506527612622.pdf


2012年10月6日 星期六

Android GridView ImageAdapter

public class ImageAdapter extends BaseAdapter {
 
 private Context _context = null;
 private PhotoItem[] _photoArray = null;
 
 public ImageAdapter( Context ctx, PhotoItem[] imageArray )
 {
  _context = ctx;
  _photoArray = imageArray;
 }

 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  return _photoArray.length;
 }

 @Override
 public PhotoItem getItem(int pos) {
  // TODO Auto-generated method stub
  return _photoArray[ pos ];
 }

 @Override
 public long getItemId(int position) {
  // TODO Auto-generated method stub
  return 0;
 }

 @Override
 public View getView(int pos, View convertView, ViewGroup parent) {
  // TODO Auto-generated method stub
  View gridView;

  if ( convertView == null ) // if it's not recycled, initialize some attribute
  { 
   LayoutInflater vi = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   gridView = vi.inflate( R.layout.image_item, null);
   
   ImageView imageView = (ImageView)gridView.findViewById( R.id.imageItemView );
   imageView.setImageDrawable( _photoArray[ pos ].getPhoto() );
  }
  else
  {
   gridView = (View)convertView;
  }
 
  return gridView;
 }

}

http://www.mkyong.com/android/android-gridview-example/