package com.example.qr_code;
import java.util.Hashtable;
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 android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
public class MainActivity extends Activity {
private EditText et_only_company;
private EditText et_only_position;
private EditText et_only_phone;
private EditText et_only_email;
private EditText et_only_web1;
private EditText et_only_add;
private EditText et_only_note;
private EditText et_only_name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_only_name =(EditText) findViewById(R.id.et_only_name);
et_only_company =(EditText) findViewById(R.id.et_only_company);
et_only_position =(EditText) findViewById(R.id.et_only_position);
et_only_phone=(EditText) findViewById(R.id.et_only_phone);
et_only_email =(EditText) findViewById(R.id.et_only_email);
et_only_web1 =(EditText) findViewById(R.id.et_only_web1);
et_only_add=(EditText) findViewById(R.id.et_only_add);
et_only_note=(EditText) findViewById(R.id.et_only_note);
findViewById(R.id.but).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String name = et_only_name.getText().toString().trim() ;
String company=et_only_company.getText().toString().trim() ;
String position = et_only_position.getText().toString().trim() ;
String phone =et_only_phone .getText().toString().trim() ;
String email = et_only_email.getText().toString().trim() ;
String web1 = et_only_web1.getText().toString().trim() ;
String add =et_only_add.getText().toString().trim() ;
String note = et_only_note.getText().toString().trim() ;
String contents= "BEGIN:VCARD\nVERSION:3.0\n" "N:" name "\nORG:" company "\nTITLE:" position "\nNOTE:" note "\nTEL:" phone "\nADR:" add "\nURL:" web1 "\nEMAIL:" email "\nEND:VCARD";
try {
Bitmap bm= qr_code(contents, BarcodeFormat.QR_CODE);
ImageView img= (ImageView)findViewById(R.id.img_only) ;
img.setImageBitmap(bm);
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public Bitmap qr_code(String string, BarcodeFormat format)
throws WriterException {
MultiFormatWriter writer = new MultiFormatWriter();
Hashtable<EncodeHintType, String> hst = new Hashtable<EncodeHintType, String>();
hst.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix matrix = writer.encode(string, format, 400, 400, hst);
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] = 0xff000000;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
// 通过像素数组生成bitmap,具体参考api
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
}
资源文件列表
QR_Code/.classpath , 466
QR_Code/.project , 810
QR_Code/.settings/org.eclipse.jdt.core.prefs , 173
QR_Code/AndroidManifest.xml , 903
QR_Code/bin/AndroidManifest.xml , 903
QR_Code/bin/classes.dex , 1318016
QR_Code/bin/classes/com/example/qr_code/BuildConfig.class , 347
QR_Code/bin/classes/com/example/qr_code/MainActivity$1.class , 2610
QR_Code/bin/classes/com/example/qr_code/MainActivity.class , 3772
QR_Code/bin/classes/com/example/qr_code/R$attr.class , 343
QR_Code/bin/classes/com/example/qr_code/R$dimen.class , 464
QR_Code/bin/classes/com/example/qr_code/R$drawable.class , 410
QR_Code/bin/classes/com/example/qr_code/R$id.class , 777
QR_Code/bin/classes/com/example/qr_code/R$layout.class , 406
QR_Code/bin/classes/com/example/qr_code/R$menu.class , 391
QR_Code/bin/classes/com/example/qr_code/R$string.class , 475
QR_Code/bin/classes/com/example/qr_code/R$style.class , 434
QR_Code/bin/classes/com/example/qr_code/R.class , 683
QR_Code/bin/dexedLibs/android-support-v4-37e7686d1f79361b8121c81e832606b1.jar , 211326
QR_Code/bin/dexedLibs/core-06e030cead9235576ce3d8d7055baef0.jar , 192203
QR_Code/bin/jarlist.cache , 120
QR_Code/bin/QR_Code.apk , 448619
QR_Code/bin/resources.ap_ , 41822
QR_Code/bin/res/drawable-hdpi/ic_launcher.png , 5964
QR_Code/bin/res/drawable-mdpi/ic_launcher.png , 3112
QR_Code/bin/res/drawable-xhdpi/ic_launcher.png , 9355
QR_Code/bin/res/drawable-xxhdpi/ic_launcher.png , 17889
QR_Code/gen/com/example/qr_code/BuildConfig.java , 161
QR_Code/gen/com/example/qr_code/R.java , 3038
QR_Code/ic_launcher-web.png , 51394
QR_Code/libs/android-support-v4.jar , 556198
QR_Code/libs/core.jar , 449685
QR_Code/proguard-project.txt , 781
QR_Code/project.properties , 563
QR_Code/res/drawable-hdpi/ic_launcher.png , 7658
QR_Code/res/drawable-mdpi/ic_launcher.png , 3777
QR_Code/res/drawable-xhdpi/ic_launcher.png , 12516
QR_Code/res/drawable-xxhdpi/ic_launcher.png , 24777
QR_Code/res/layout/activity_main.xml , 6378
QR_Code/res/menu/main.xml , 254
QR_Code/res/values-sw600dp/dimens.xml , 196
QR_Code/res/values-sw720dp-land/dimens.xml , 269
QR_Code/res/values-v11/styles.xml , 324
QR_Code/res/values-v14/styles.xml , 381
QR_Code/res/values/dimens.xml , 213
QR_Code/res/values/strings.xml , 217
QR_Code/res/values/styles.xml , 680
QR_Code/src/com/example/qr_code/MainActivity.java , 3461
