android


Update seekBar progress on UI


I am working at a flashlight app with stroboscope , at this moment the app is working, the flash is working with a button, and the frequency of the strobe is being incresed with the help of a seekbar.
The problem is that if the flash is on and i drag to the right on the seekbar to start and increse feqency of the strobe effect, but if I turn off the flash and drag on the seekbar at a certain point greaten than 0 and turn on the flash the strobe effect it works, but still when is on it will just not update and increase the freqency, and i have to turn off and onn again flashlight to change the freqency or to stop the strobe effect (of course when the flash is off move the seekBar).
Can you help me and make me understand why it does not update with the flash on, plesase! I would be grateful !
Thanks!
Here is the code :
SeekBar
SeekBar sbar = (SeekBar) findViewById(R.id.seekBar2);
sbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
freq = progress;
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
StroboRunner
private class StroboRunner implements Runnable{
int freq;
boolean stopRunning = false;
volatile int delay = 100;
volatile int delayoff = 200;
#Override
public void run() {
Camera.Parameters paramsOn = camera.getParameters();
Camera.Parameters paramsOff = parameter;
paramsOn.setFlashMode(Parameters.FLASH_MODE_TORCH);
paramsOff.setFlashMode(Parameters.FLASH_MODE_OFF);
try{
while(!stopRunning) {
MainActivity.this.camera.setParameters(paramsOn);
MainActivity.this.camera.startPreview();
Thread.sleep(delay - freq);
// We make the thread sleeping
MainActivity.this.camera.setParameters(paramsOff);
MainActivity.this.camera.startPreview();
Thread.sleep(delayoff-freq);
}
} catch (Exception e){
}
}
}
Also for on and off of the flashlight I am using
private boolean turnOnOff(boolean on) {
if (on) {
if (freq != 0) {
SunetON();
isFlashLightOn = true;
sr = new StroboRunner();
sr.freq = freq;
t = new Thread(sr);
t.start();
return on;
}
else
parameter.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
SunetON();
}
if (!on) {
if (t != null) {
SunetOff();
sr.stopRunning = true;
isFlashLightOff = true;
t = null;
return on;
}
else
parameter.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
SunetOff();
}
camera.setParameters(parameter);
camera.startPreview();
return on;
}
the onClickListener
flashLight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
isChecked = !isChecked;
if (isChecked)
flashLight.setImageResource(R.drawable.on);
else
flashLight.setImageResource(R.drawable.off);
turnOnOff(isChecked);
}
});
EDIT: Nevermind, bad if/else formatting -- turnOnOff was already outside
A good place to start is to move turnOnOff(isChecked) outside of your else statement.
flashLight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
isChecked = !isChecked;
if (isChecked)
flashLight.setImageResource(R.drawable.on);
else
flashLight.setImageResource(R.drawable.off);
}
turnOnOff(isChecked);
});

Related Links

Android Studio .idea and .gradle folders be kept in source control?
when i click the exit button it keep looping
Porting existing Cordova app into Android Studio
Android: VideoView sometimes stop playing videos after some time
Gridview with GridViewAdapter how to set onclick listener in Gridview and not GridViewAdapter
Eclipse does not recognize any methods of BitmapFactory.Options variable
Can we enable pie (i.e. Position Independent Executables) for shared libraries in android-ndk r10c?
Why does crash in Activity DOES NOT crash whole app - Android
Android Notification.MediaStyle not responding to MediaSession updates
How to remove Radiobuttons from RadiopGroup Created by Array String
Eclipse automatically creates a breakpoint in ThreadPoolExecutor class
SQlCipher for android Xamarin
ListView with recent objects at top
How to add a search view on action bar tabs just same as in play store application
Android adapter arrayadapter or cursor?
show Toast mesage till video installation and play it

Categories

HOME
fuelux
pagination
android-studio-2.2
jax-rs
apache-spark-mllib
fftw
appcelerator
newrelic
soa
rom
tail
iis-6
title
octave
fhir
jxl
onedrive-api
flash-player
heat
keytool
symfony-console
asciidoctor-pdf
imagemap
href
qliksense
jquery-callback
beta
moses
motion-detection
licensing
has-and-belongs-to-many
angular-translate
mustache
clickjacking
linkedhashmap
python-import
reverse
yowsup
roblox
raft
alphabetical
google-data-api
xv6
visa
vmware-fusion
angular-http
signal-strength
datamaps
manova
colorbar
opengl-4
janus
cpu-cache
rxtx
rmongo
async.js
embedding
nservicebus5
lua-telegram-bot
toast
character-replacement
fiware-monitoring
toolkit
evolus-pencil
keyup
alloy-ui
typeconverter
mraid
cross-join
document-repository
big-ip
personalization
xml-dsig
functional-java
draw2d-js
maven-scm
getopt
accesscontrolexception
high-resolution
isqlquery
asdf
cardreader
onmousemove
pstack
inline-formset
dot-emacs
filesystemobject
linfu-dynamicproxy
sqlobject
flvplayback
technical-debt
mathematical-typesetting
appliance

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App