public class MainActivity extends AppCompatActivity {
private TextView tv_result;
private EditText et_text;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
tv_result = (TextView) findViewById(R.id.tv_result);
et_text = (EditText) findViewById(R.id.et_text);
imageView = (ImageView) findViewById(R.id.imageView);
}
public void scan(View view) {
startActivityForResult(new Intent(MainActivity.this,
CaptureActivity.class), 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
String result = bundle.getString("result");
tv_result.setText(result);
}
}
private void submit() {
// validate
String text = et_text.getText().toString().trim();
if (TextUtils.isEmpty(text)) {
Toast.makeText(this, "Input", Toast.LENGTH_SHORT).show();
return;
}
// TODO validate success, do something
}
public void makeqrcode(View view) {
if (et_text.equals("")){
Toast.makeText(this, "输入不能为空", Toast.LENGTH_SHORT).show();
}else{
Bitmap bitmap = EncodingUtils.createQRCode(et_text.getText().toString(),500,500,null);
imageView.setImageBitmap(bitmap);
}
}
}
private TextView tv_result;
private EditText et_text;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
tv_result = (TextView) findViewById(R.id.tv_result);
et_text = (EditText) findViewById(R.id.et_text);
imageView = (ImageView) findViewById(R.id.imageView);
}
public void scan(View view) {
startActivityForResult(new Intent(MainActivity.this,
CaptureActivity.class), 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
String result = bundle.getString("result");
tv_result.setText(result);
}
}
private void submit() {
// validate
String text = et_text.getText().toString().trim();
if (TextUtils.isEmpty(text)) {
Toast.makeText(this, "Input", Toast.LENGTH_SHORT).show();
return;
}
// TODO validate success, do something
}
public void makeqrcode(View view) {
if (et_text.equals("")){
Toast.makeText(this, "输入不能为空", Toast.LENGTH_SHORT).show();
}else{
Bitmap bitmap = EncodingUtils.createQRCode(et_text.getText().toString(),500,500,null);
imageView.setImageBitmap(bitmap);
}
}
}