網絡請求:android-async-http
ViewPage添加tab標間:ViewPagerIndicator
shareSdk一鍵分享:http://www.mob.com/#/index
科大訊飛:語音識別
Zxing:二維碼生成和識別 handleDecode
http://code.google.com/p/zxing/
生成二維碼:二維碼其實是
package com.androidzhang.zxingframe;
import java.util.Hashtable;
import android.graphics.Bitmap;
import android.util.Log;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
public class BitmapUtil {
/**
* 生成一個二維碼圖像
*
* @param url
* 傳入的字符串,通常是一個URL
* @param QR_WIDTH
* 寬度(像素值px)
* @param QR_HEIGHT
* 高度(像素值px)
* @return
*/
public static final Bitmap create2DCoderBitmap(String url, int QR_WIDTH,
int QR_HEIGHT) {
try {
// 判斷URL合法性
if (url == null || "".equals(url) || url.length() < 1) {
return null;
}
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 圖像數據轉換,使用了矩陣轉換
BitMatrix bitMatrix = new QRCodeWriter().encode(url,
BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);
int[] pixels = new int[QR_WIDTH * QR_HEIGHT];
// 下面這裏按照二維碼的算法,逐個生成二維碼的圖片,
// 兩個for循環是圖片橫列掃描的結果
for (int y = 0; y < QR_HEIGHT; y++) {
for (int x = 0; x < QR_WIDTH; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * QR_WIDTH + x] = 0xff000000;
} else {
pixels[y * QR_WIDTH + x] = 0xffffffff;
}
}
}
// 生成二維碼圖片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT);
// 顯示到一個ImageView上面
// sweepIV.setImageBitmap(bitmap);
return bitmap;
} catch (WriterException e) {
Log.i("log", "生成二維碼錯誤" + e.getMessage());
return null;
}
}
private static final int BLACK = 0xff000000;
/**
* 生成一個二維碼圖像
*
* @param url
* 傳入的字符串,通常是一個URL
* @param widthAndHeight
* 圖像的寬高
* @return
*/
public static Bitmap createQRCode(String str, int widthAndHeight)
throws WriterException {
//判斷URL合法性
if (str == null || "".equals(str) || str.length() < 1 || widthAndHeight<1)
{
return null;
}
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str,
BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (matrix.get(x, y)) {
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
}
二維碼識別:
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.zxing.view.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
/**
* Handler scan result
*
* @param result
* @param barcode
* 獲取結果
*/
public void handleDecode(Result result, Bitmap barcode) {
inactivityTimer.onActivity();
playBeepSoundAndVibrate();
String resultString = result.getText();
// FIXME
if (resultString.equals("")) {
Toast.makeText(CaptureActivity.this, "掃描失敗!", Toast.LENGTH_SHORT)
.show();
} else {
// System.out.println("Result:"+resultString);
Intent resultIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("result", resultString);
resultIntent.putExtras(bundle);
this.setResult(RESULT_OK, resultIntent);
}
CaptureActivity.this.finish();
}
草料二維碼:在線生成二維碼
SlidingMenu:
1. 導入SlidingMenu_lib庫
2. 繼承修改Activity爲 SlidingXXXActivity
3. 設置主界面
//1.設置主界面
setContentView(R.layout.activity_main);
4. 設置左側菜單界面
//2.設置左側界面
setBehindContentView(R.layout.activity_left);
5. 設置右側菜單
SlidingMenu menu = getSlidingMenu();
//設置右邊側滑菜單的界面
menu.setSecondaryMenu(R.layout.activity_right);
6. 設置菜單模式
三種:left 只有左側 right 只有右側 left_right 左右側都有:menu.setMode(SlidingMenu.LEFT);// 只設置左側可以滑動
7. 設置菜單觸摸方式
三種: TOUCHMODE_FULLSCREEN 任何位置 ,TOUCHMODE_MARGIN 邊界纔可以拖動,TOUCHMODE_NONE不可以拖動
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
8.設置主界面左側滑動後剩餘的空間位置
menu.setBehindOffset(200);// 設置主界面剩餘的位置