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

When I click the listview button to play the sound on Android [closed]
Unable to delete space in edittext
Android dynamic UI update from AsynchTask/Handler and Thread priorities
How to design the xml layout of given image in android?
How to Start one Activity and two service on notification click
How to find bluetooth mac address programmatically in Android api level 19
How to use ShowCaseView v5 builder with fragments?
Is it good practice to develop a helper network class that is responsible for all network tasks?
Android warning when open: keyBoard, editText and seekBar in one screen
Google maps suddenly not working
Trying to create imageView when click the button
How to know if Show Notification is disabled for my app? [duplicate]
ics-openvpn : how to compile on windows machine
Broadcast a file on wifi local network with Mobile
Making apk with Kivy and Buildozer on Ubuntu 12.04
Native application crashes on Android L

Categories

HOME
android
ns-3
case
powerpoint
apache-spark-mllib
package
error-handling
opendj
telegram-bot
x264
python-multithreading
crystal-lang
openpyxl
fhir
emoji
ycsb
enterprise-architect
android-intent
nim
sencha-touch
googlebot
backpack-for-laravel
question2answer
react-toolbox
mongoid6
event-store
jboss6.x
outliers
entity-relationship-model
fractions
linked-data
ceylon
errbot
testcomplete
dst
sql-server-2000
dumpbin
android-sugarorm
code-snippets
hard-drive
hunspell
pop3
lubridate
navigator
reason
salesforce-communities
openproject
filesystemwatcher
avcapturedevice
signal-strength
vaadin-charts
facebook-social-plugins
optimizely
phpdbg
launchctl
rserve
context-switch
reshape
baidu
rxtx
latin
freepbx
cassia
kango-framework
deep
yajsw
database-relations
jaunt-api
linklabel
ess
rate-limiting
fuelcms
visual-sourcesafe-2005
j-security-check
cryptographichashfunction
nodelist
execve
ghcjs
contrast
ss7
live555
dot42
extjs2
spring-3
windows-phone-8-sdk
jeromq
unit-of-work
scmmanager
facebook-timeline
epiceditor
octal
jquery-1.9
tree-balancing
multiplexing
cross-database
matlab-load
automationelement
strsep
msr
ruby-1.8
ie-compatibility-mode
sifr
filesystemobject
skype4java
visualj#
complex-event-processing
pnrp

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