Android 基於google Zxing實現二維碼、條形碼掃描,仿微信二維碼掃描效果(現在正做個掃描App、收藏)
瞭解二維碼這個東西還是從微信中,當時微信推出二維碼掃描功能,自己感覺挺新穎的,從一張圖片中掃一下竟然能直接加好友,不可思議啊,那時候還不瞭解二維碼,呵呵,然後做專案的時候,老闆說要加上二維碼掃描功能,然後自己的屁顛屁顛的去百度,google啥的,發現很多朋友都有介紹二維碼掃描的功能,然後我就跟著人家的介紹自己搞起了二維碼掃描功能,跟著人家的帖子,很快我的專案就加入了掃描二維碼的功能,然後自己還很開心。
隨著微信的到來,二維碼越來越火爆,隨處能看到二維碼,比如商城裡面,肯德基,餐廳等等,對於二維碼掃描我們使用的是google的開源框架Zxing,我們可以去http://code.google.com/p/zxing/
我們先看下專案的結構
- 如果你專案也想加入此功能,你直接將com.mining.app.zxing.camera,com.mining.app.zxing.decoding,com.mining.app.zxing.view這三個包拷貝到你的專案中,然後引入相對應的資源進去,我也是從我的專案中直接引用過來的,包名都沒改呢,當然還需要引用Zxing.jar
- com.example.qr_codescan包裡面有一個MipcaActivityCapture,也是直接引入我之前專案的程式碼的,這個Activity主要處理掃描介面的類,比如,掃描成功有聲音和振動等等,主要關注裡面的handleDecode(Result
result, Bitmap barcode)方法,掃描完成之後將掃描到的結果和二維碼的bitmap當初引數傳遞到
- /**
- * 處理掃描結果
- * @param result
- * @param barcode
- */
- publicvoid handleDecode(Result result, Bitmap barcode) {
- inactivityTimer.onActivity();
- playBeepSoundAndVibrate();
- String resultString = result.getText();
- if (resultString.equals("")) {
- Toast.makeText(MipcaActivityCapture.this, "Scan failed!", Toast.LENGTH_SHORT).show();
- }else {
- Intent resultIntent = new Intent();
- Bundle bundle = new Bundle();
- bundle.putString("result", resultString);
- bundle.putParcelable("bitmap", barcode);
- resultIntent.putExtras(bundle);
- this.setResult(RESULT_OK, resultIntent);
- }
- MipcaActivityCapture.this.finish();
- }
- 我對MipcaActivityCapture介面的佈局做了自己的改動,先看下效果圖,主要是用到FrameLayout,裡面巢狀RelativeLayout,裡面的圖片也是從微信裡面拿出來的,平常我看到需要什麼圖片就去微信裡面找,沒有美工的公司的程式設計師就是苦逼
佈局程式碼如下
- <?xmlversion="1.0"encoding="utf-8"?>
- <FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <SurfaceView
- android:id="@+id/preview_view"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_gravity="center"/>
- <com.mining.app.zxing.view.ViewfinderView
- android:id="@+id/viewfinder_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <include
- android:id="@+id/include1"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- layout="@layout/activity_title"/>
- </RelativeLayout>
- </FrameLayout>
- <?xmlversion="1.0"encoding="utf-8"?>
- <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@drawable/mmtitle_bg_alpha">
- <Button
- android:id="@+id/button_back"
- android:layout_width="75.0dip"
- android:text="返回"
- android:background="@drawable/mm_title_back_btn"
- android:textColor="@android:color/white"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_marginLeft="2dip"/>
- <TextView
- android:id="@+id/textview_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/button_back"
- android:layout_alignBottom="@+id/button_back"
- android:layout_centerHorizontal="true"
- android:gravity="center_vertical"
- android:text="二維碼掃描"
- android:textColor="@android:color/white"
- android:textSize="18sp"/>
- </RelativeLayout>
- 在我這個demo裡面,有一個主介面MainActivity,裡面一個Button, 一個ImageView和一個TextView,點選Button進入到二維碼掃描介面,當掃描OK的時候,回到主介面,將掃描的結果顯示到TextView,將圖片顯示到ImageView裡面,然後你可以不處理圖片,我這裡隨帶的加上圖片,主介面的佈局很簡單如下
Android 廣告(banner)圖片輪播、圖片瀏覽、仿微信大圖檢視控制元件(支援視訊和gif圖片)、支援動態新增資料
之前專案需要做個仿微信檢視大圖,需要新增圓形下載進度,支援視訊和圖片切換等一系列功能控制元件,自己抽空把開發的自定義控制元件的成果重新構造、整理處理封裝成庫(aar),提供出來,有需要朋友,歡迎使用,如果有什麼建議歡迎留言或者GitHub上提issues
Android 多張圖片展示,仿微信圖片上傳,可以選擇多張圖片
我們經常會遇到需要多張圖片展示上傳的需求 ,如圖 這樣的需求我已經遇到過多次,個人總結一下,希望大家多多指點,支援選擇多張圖片 佈局:一個GridView <com.zuihou.drunkenmonkey.widget.view.Di
Android仿微信呼叫第三方地圖應用導航(高德、百度、騰訊)
好久沒有寫Andorid程式碼啦!最近剛好要實現一個這個功能,順便就在部落格裡分享一下。 實現目標 先來一張微信功能截圖看看要做什麼 其實就是有一個目的地,點選目的地的時候彈出可選擇的應用進行導航。 大腦動一下,要實現這個功能應該大體分成兩步:
基於VCamera,仿微信錄製短視訊
基於VCamera,Android仿微信錄製短視訊,如果喜歡請star,如果覺得有紕漏請提交issue,如果你有更好的點子可以提交pull request。 recoder4.gif 使用 1) 在build.gradle,新增wechatRecoderVideoLibr
Android Zxing實現掃描二維碼條形碼功能仿微信整合閃光燈生成二維碼
最近在做android專案需要用到二維碼條形碼掃描功能,我用的是Eclipse網上原始碼大多是GitHup上的Android studio版本的所以我改了一版整合到專案中去。 效果圖: 左邊版本的掃碼框是自定義的。右邊版本的掃碼框和掃描線是圖片因為太醜所以最終換成左邊
Android實現二維碼掃描(仿微信,輕量Zxing)
前言 要做一個功能,二維碼識別。網上找一堆相關的Demo,但是總不是想要的效果,或者都是多年前的版本,權衡考慮之後,決定親自操刀。不糾結直接選中Zxing框架,https://github.com/zxing/zxing 在網站上直接clone下來,執行,然後就發現問題了.