无法为 android 中更改的 SeekBar 值生成 QR 码
Unable to generate QR Code for changed SeekBar value in android
我想 create/generate QRCode
为 Stream_Ring
更改的 SeekBar
值。但问题是我无法 get/save onProgressChanged 方法的 progress 生成 QR 所需的值。
我试图找出问题所在,但无法找到。为了您的方便,我上传了整个二维码生成代码。
Button gene;
ImageView image;
SeekBar ring_bar;
String collect;
private AudioManager am;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prof);
gene = (Button) findViewById(R.id.gene);
image = (ImageView) findViewById(R.id.image);
ring_bar = (SeekBar) findViewById(R.id.ring_bar);
am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int maxV = am.getStreamMaxVolume(AudioManager.STREAM_RING);
int curV = am.getStreamVolume(AudioManager.STREAM_RING);
ring_bar.setMax(maxV);
ring_bar.setProgress(curV);
ring_bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
am.setStreamVolume(AudioManager.STREAM_RING, progress, 0);
}
});
int ring = ring_bar.getProgress();
String ringgg = Integer.toString(ring);
collect = ringgg;
gene.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try{
BitMatrix bitMatrix = multiFormatWriter.encode(collect, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
image.setImageBitmap(bitmap);
}
catch (WriterException e){
e.printStackTrace();
}
}
});
}
}
问题是,我在 onCreate 中保存了进度,但之后我从未更新过该值。为了为当前值创建一个二维码,我不得不在 onClickListener 中调用 getProgress() ,它返回了进度条的当前值。
gene.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try{
int ringtoneVolumeValue = ring_bar.getProgress();
String ringtoneVolume = Integer.toString(ringtoneVolumeValue);
BitMatrix bitMatrix = multiFormatWriter.encode(ringtoneVolume, BarcodeFormat.QR_CODE,200,200);
//....
}
catch (WriterException e){
e.printStackTrace();
}
}
});
我想 create/generate QRCode
为 Stream_Ring
更改的 SeekBar
值。但问题是我无法 get/save onProgressChanged 方法的 progress 生成 QR 所需的值。
我试图找出问题所在,但无法找到。为了您的方便,我上传了整个二维码生成代码。
Button gene;
ImageView image;
SeekBar ring_bar;
String collect;
private AudioManager am;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prof);
gene = (Button) findViewById(R.id.gene);
image = (ImageView) findViewById(R.id.image);
ring_bar = (SeekBar) findViewById(R.id.ring_bar);
am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
int maxV = am.getStreamMaxVolume(AudioManager.STREAM_RING);
int curV = am.getStreamVolume(AudioManager.STREAM_RING);
ring_bar.setMax(maxV);
ring_bar.setProgress(curV);
ring_bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar arg0) {
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
}
@Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2) {
am.setStreamVolume(AudioManager.STREAM_RING, progress, 0);
}
});
int ring = ring_bar.getProgress();
String ringgg = Integer.toString(ring);
collect = ringgg;
gene.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try{
BitMatrix bitMatrix = multiFormatWriter.encode(collect, BarcodeFormat.QR_CODE,200,200);
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
image.setImageBitmap(bitmap);
}
catch (WriterException e){
e.printStackTrace();
}
}
});
}
}
问题是,我在 onCreate 中保存了进度,但之后我从未更新过该值。为了为当前值创建一个二维码,我不得不在 onClickListener 中调用 getProgress() ,它返回了进度条的当前值。
gene.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
try{
int ringtoneVolumeValue = ring_bar.getProgress();
String ringtoneVolume = Integer.toString(ringtoneVolumeValue);
BitMatrix bitMatrix = multiFormatWriter.encode(ringtoneVolume, BarcodeFormat.QR_CODE,200,200);
//....
}
catch (WriterException e){
e.printStackTrace();
}
}
});