58、微信-我-我的二维码MyCodeActivity
来源:互联网 发布:单片机与plc的区别 编辑:程序博客网 时间:2024/05/16 08:33
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2E3132" >
<include
android:id="@+id/layout_bar"
layout="@layout/layout_title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="30dp"
android:background="@drawable/btn_bg_gray"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<RelativeLayout
android:id="@+id/view_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp" >
<ImageView
android:id="@+id/head"
android:layout_width="60.0dip"
android:layout_height="60.0dip"
android:layout_margin="10dp"
android:src="@drawable/head" />
<TextView
android:id="@+id/tvname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:layout_toRightOf="@+id/head"
android:text="菲儿"
android:textSize="18.0dip" />
<TextView
android:id="@+id/tvmsg"
style="@style/txt_ContextStyle1"
android:layout_below="@+id/tvname"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/head"
android:text="微信号:dada20150625"
android:textSize="14.0dip" />
<ImageView
android:id="@+id/iv_sex"
android:layout_toRightOf="@+id/tvname"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginTop="22dp"
android:layout_marginLeft="5dp"
android:src="@drawable/ic_sex_female" />
</RelativeLayout>
<ImageView
android:id="@+id/img_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/default_image" />
<TextView
style="@style/txt_ContextStyle1"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="扫一扫上面的二维码图案,加我微信"
android:textSize="14.0dip" />
</LinearLayout>
</RelativeLayout>
实现代码:
public class MyCodeActivity extends BaseActivity implements View.OnClickListener {
private TextView txt_title, txt_right, tvname, tv_accout;
private ImageView img_back;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_mycode);
super.onCreate(savedInstanceState);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.img_back:
Utils.finish(MyCodeActivity.this);
break;
default:
break;
}
}
@Override
protected void initControl() {
txt_title = (TextView) findViewById(R.id.txt_title);
txt_title.setText("我的二维码");
img_back = (ImageView) findViewById(R.id.img_back);
img_back.setVisibility(View.VISIBLE);
tvname = (TextView) findViewById(R.id.tvname);
tv_accout = (TextView) findViewById(R.id.tvmsg);
}
@Override
protected void initView() {
img_back.setOnClickListener(this);
}
@Override
protected void initData() {
String id = Utils.getValue(this, Constants.User_ID);
tv_accout.setText("微信号:" + id);
User user = GloableParams.Users.get(id);
if (user != null && !TextUtils.isEmpty(user.getUserName()))
tvname.setText(user.getUserName());
Bitmap qrcode = generateQRCode("JUNS_WeChat@User:" + id);
ImageView imageView = (ImageView) findViewById(R.id.img_code);
imageView.setImageBitmap(qrcode);
}
@Override
protected void setListener() {
// TODO Auto-generated method stub
}
private Bitmap generateQRCode(String content) {
try {
QRCodeWriter writer = new QRCodeWriter();
// MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix matrix = writer.encode(content, BarcodeFormat.QR_CODE, 500, 500);
return bitMatrix2Bitmap(matrix);
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
private Bitmap bitMatrix2Bitmap(BitMatrix matrix) {
int w = matrix.getWidth();
int h = matrix.getHeight();
int[] rawData = new int[w * h];
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
int color = Color.WHITE;
if (matrix.get(i, j)) {
color = Color.BLACK;
}
rawData[i + (j * w)] = color;
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
bitmap.setPixels(rawData, 0, w, 0, 0, w, h);
return bitmap;
}
}
生成二维码的函数generateQRCode可以重用,使用了zxing的QRCodeWriter。
0 0
- 58、微信-我-我的二维码MyCodeActivity
- 扫描二维码,关注我的微信公众帐号:RJXERP
- 我的微信
- 我的二维码
- 我的二维码
- 我的收款二维码
- 我的二维码
- 我的二维码
- 我的二维码
- 我的微信好友
- 我的博客的二维码
- 我的博客的二维码
- 我的自荐信
- 帮我盗取我女友的微信密码
- 帮我盗取我女友的微信密码
- 我的微信公众平台*1*
- 我的微信公众号
- 我的微信后台成长
- 57、微信-我Fragment_Profile
- Android图片缓存
- exFAT 文件系统格式
- 在这个比长的时代,偏偏有人胜在了短小精悍
- 纪念自己菜鸟生涯的一个开始---闰年计算器
- 58、微信-我-我的二维码MyCodeActivity
- jquery tmpl 详解
- HDU 1698 Just a Hook 线段树成段更新
- 【C#】日期时间处理总结
- iOS如何快速解决PCH文件的路径找不到问题
- 页面自动刷新
- 59、微信-我-设置SettingActivity
- php 创建类
- Qt Model/View( 一)