`
苹果超人
  • 浏览: 195979 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ebooks

阅读更多
ebooks
http://www.myexception.cn/j2se/36961.html
http://blog.sina.com.cn/s/blog_6fa4ebf401016k07.html
http://my.eoe.cn/fashr314/archive/10358.html
http://wenku.baidu.com/link?url=NKuh_joeXwS3pKVTie88WElzPGaHCLEAiRgqqfiE3xiVpCGwYn-oas7RmMBmll1pRubRlDpA7MDSeSUyy4uRcsdX8GDSegA0fogzBMSWFhq

http://blog.csdn.net/luoshengyang/article/details/6946067

android源码下载
http://blog.csdn.net/hudashi/article/details/7080056

package com.denong.app.plusplus.util;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.denong.app.plusplus.Constants;
import com.denong.app.plusplus.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;

/**
 * 调用相机和相册辅助工具类
 * 
 * @author Patrick.Li
 *
 */
public class CameraUtil {

	/**
	 * 打开选择相机和相册对话框
	 * 
	 * @param fragment
	 */
	public static void showSelectDialog(final Fragment fragment) {
	    String[] options = {
	    			fragment.getResources().getString(R.string.photo_camera),
	    			fragment.getResources().getString(R.string.photo_gallery)
	    			};
	    final ListAdapter adapter = new ArrayAdapter<String>(fragment.getActivity(),  
                android.R.layout.simple_list_item_1, options); 
	    
	    AlertDialog.Builder cameraSelectDialog = new AlertDialog.Builder(fragment.getActivity());
	    cameraSelectDialog.setTitle(R.string.photo_title);
	    cameraSelectDialog.setSingleChoiceItems(adapter, -1,  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int which) {  
                        dialog.dismiss();
                        switch (which) {  
                        case 0: {
                            // 相机拍照
                        	Intent cameraIntent = getCameraIntent();
    	                	fragment.startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST);
                            break;
                        }
                        case 1:
                            // 相册选择
                        	Intent galleryIntent = getGalleryIntent();
    	                	fragment.startActivityForResult(galleryIntent, Constants.GALLERY_REQUEST);
                            break;
                        }
                    }
                });
	    cameraSelectDialog.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {  
            @Override  
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
	    cameraSelectDialog.show();
	}

	/**
	 * 打开选择相机和相册对话框
	 * 
	 * @param activity
	 */
	public static void showSelectDialog(final Activity activity) {
		String[] options = {
				activity.getResources().getString(R.string.photo_camera),
				activity.getResources().getString(R.string.photo_gallery)
    			};
	    final ListAdapter adapter = new ArrayAdapter<String>(activity,  
	            android.R.layout.simple_list_item_1, options); 
	    
	    AlertDialog.Builder cameraSelectDialog = new AlertDialog.Builder(activity);
	    cameraSelectDialog.setTitle(R.string.photo_title);
	    cameraSelectDialog.setSingleChoiceItems(adapter, -1,  
	            new DialogInterface.OnClickListener() {  
	                public void onClick(DialogInterface dialog, int which) {  
	                    dialog.dismiss();
	                    switch (which) {  
	                    case 0: {
	                        // 相机拍照
	                    	Intent cameraIntent = getCameraIntent();
	                    	activity.startActivityForResult(cameraIntent, Constants.CAMERA_REQUEST);
	                        break;
	                    }
	                    case 1:
	                        // 相册选择
	                    	Intent galleryIntent = getGalleryIntent();
	                    	activity.startActivityForResult(galleryIntent, Constants.GALLERY_REQUEST);
	                        break;
	                    }
	                }
	            });
	    cameraSelectDialog.setNegativeButton(R.string.common_cancel, new DialogInterface.OnClickListener() {  
	        @Override  
	        public void onClick(DialogInterface dialog, int which) {
	            dialog.dismiss();
	        }
	    });
	    cameraSelectDialog.show();
	}
	
	/**
	 * 打开相机Intent
	 * 
	 * @return
	 */
	public static Intent getCameraIntent() {
		Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        return cameraIntent;
	}
	
	/**
	 * 打开相册Intent
	 * 
	 * @return
	 */
	public static Intent getGalleryIntent() {
		Intent cameraIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
		cameraIntent.setType("image/*");
		cameraIntent.putExtra("return-data", true);
		return cameraIntent;
	}
	
	/**
	 * 返回编辑图片的Intent
	 * 
	 * @param photoUri
	 * @return
	 */
	public static Intent getCropImageIntent(Uri photoUri) {  
        Intent intent = new Intent("com.android.camera.action.CROP");  
        intent.setDataAndType(photoUri, "image/*");  
        intent.putExtra("crop", "true");
//        intent.putExtra("aspectX", 1);
//        intent.putExtra("aspectY", 1);
//        intent.putExtra("outputX", 80);
//        intent.putExtra("outputY", 80);
        intent.putExtra("return-data", true);
        return intent;  
    }
	
	/**
	 * 打开相册并且带编辑的Intent
	 * 
	 */
    public static Intent getGalleryCropIntent() {  
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);  
        intent.setType("image/*");  
        intent.putExtra("crop", "true");  
//        intent.putExtra("aspectX", 1);  
//        intent.putExtra("aspectY", 1);  
//        intent.putExtra("outputX", 80);  
//        intent.putExtra("outputY", 80);  
        intent.putExtra("return-data", true);  
        return intent;  
    }
	
	/**
	 * 取得拍照或者相册返回的结图片对象
	 * 
	 * @param activity
	 * @param data
	 * @return
	 */
	public static Bitmap getBitmapFromActivityForResult(final Activity activity, Intent data) {
		Bitmap bitmap = null;
		ContentResolver resolver = activity.getContentResolver();
        // 照片的原始资源地址
        Uri imgUri = data.getData();
        // 使用ContentProvider通过Uri获取原始图片  
        try {
        	bitmap = MediaStore.Images.Media.getBitmap(resolver, imgUri);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
        return bitmap;
	}
	
	/**
	 * 压缩Bitmap
	 * 
	 * @param bitmap
	 * @return
	 */
	public static Bitmap compressBitmap(Bitmap bitmap) {
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
		byte[] bitmapData = stream.toByteArray();
		Bitmap compressed = BitmapFactory.decodeByteArray(bitmapData , 0, bitmapData.length);
		return compressed;
	}
	
	/**
	 * 压缩Bitmap返回字符串
	 * 
	 * @param bitmap
	 * @return
	 */
	public static String compressBitmap2String(Bitmap bitmap) {
		return new String(compressBitmap2Byte(bitmap));
	}
	
	/**
	 * 压缩Bitmap返回字符数组
	 * 
	 * @param bitmap
	 * @return
	 */
	public static byte[] compressBitmap2Byte(Bitmap bitmap) {
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
		return stream.toByteArray();
	}
	
	/**
	 * 旋转图片
	 * 
	 * @param bitmap
	 * @param angle
	 * @return
	 */
	public static Bitmap rotateBitmap(Bitmap bitmap, float angle) {
		// 旋转图片 动作
		Matrix matrix = new Matrix();
		matrix.postRotate(angle);
		// 创建新的图片
		Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
				bitmap.getWidth(), bitmap.getHeight(), matrix, true);
		return resizedBitmap;
	}
	
	/**
	 * 返回缩略图
	 * 
	 * @param bitmap
	 * @return
	 */
	public static Bitmap createThumbnails(Bitmap bitmap) {
		BitmapFactory.Options options = new BitmapFactory.Options();
        //options.inJustDecodeBounds = true;
        options.inSampleSize = 4;
        
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
		byte[] bitmapData = stream.toByteArray();
        Bitmap image = BitmapFactory.decodeByteArray(bitmapData, 0, bitmapData.length, options);
        return image;
	}

}


BEGIN
	declare  currentDate varchar;
	DECLARE 'maxNo' int default 0;
	DECLARE 'oldOrderNo' varchar(25) default '';
	
	if num = 8 then
		SELECT DATE_FORMAT(NOW(), '%Y%m%d') INTO currentDate;
	else if num = 14 then
		SELECT DATE_FORMAT(NOW(), '%Y%m%d%H%i%s') INTO currentDate;
	else 
		SELECT DATE_FORMAT(NOW(), '%Y%m%d%H%i') INTO currentDate;
	end if;
	
	SELECT 
		IFNULL(orderNo, '') INTO oldOrderNo 
	FROM 
		orderNoSequence 
	WHERE
		SUBSTRING(orderNo, 3, num) = currentDate
	AND
		SUBSTRING(orderNo, 1, 2) = orderNamePrefix
	AND
		LENGTH(orderNo) = 7 + num
	ORDER BY
		id DESC
	LIMIT
		1;
		
	if oldOrderNo != '' then
		SET maxNo = CONVERT(SUBSTRING(oldOrderNo, -5), DECIMAL);
	end if;
	
	SELECT CONCAT(orderNamePrefix, currentDate, LPAD((maxNo + 1), 5, '0') into newOrderNo;
	
	INSERT INTO orderNoSequence(orderNo, orderName) VALUES (newOrderNo);
	
	SELECT newOrderNo;
END;


CREATE TABLE orderNoSequence(
id int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
orderNo varchar(25) NOT NULL DEFAULT ''
);
  • git.zip (736.2 KB)
  • 下载次数: 1
  • cxf.zip (38.1 KB)
  • 下载次数: 1
  • jmx.zip (923.2 KB)
  • 下载次数: 1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics