0

I want to use the progress variable of onProgressChanged method outside of the inner class. I tried to use a method defined in outer class and called from inner class to get that value. But every-time I get 0.
No updated value of progress variable. It is basically an android app to get the updated value of SeekBar.
Have a look at the code for better understanding. Currently I am only getting previous/last value of progress. Not getting updated value immediately as I change it.

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();
            }

        }
    });
}

}

JDurstberger
  • 4,127
  • 8
  • 31
  • 68
K.Malu
  • 11
  • 10
  • So what you say is that `am.setStreamVolume` does not work? I just copied your code and it works fine for me. – JDurstberger Jan 17 '17 at 17:32
  • @Altoyyr My concern is not with this one. I just want the value of progress as i am generating QR for the changed progress value. But i don't get the latest progress value that i changed now. I only get value which i changed last time. ring_bar.getProgress() is giving me this last progress value but i need the latest one. Got my point? – K.Malu Jan 17 '17 at 17:41

1 Answers1

0

Your problem is, that you save the progress in onCreate to your variable but you never update the value after that.

@Override
protected void onCreate(Bundle savedInstanceState) {
//....

int ring = ring_bar.getProgress();//Progress at the time of onCreate

gene.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
        try{
           //collect is still the same value since onCreate 
            BitMatrix bitMatrix = multiFormatWriter.encode(collect, BarcodeFormat.QR_CODE,200,200);
            //....
        }
        catch (WriterException e){
            e.printStackTrace();
        }

    }
});

In order to create a QR for the current value you have to call getProgress() in the onClickListener. This will return you the current value of the progress bar.

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();
        }

    }
});
JDurstberger
  • 4,127
  • 8
  • 31
  • 68