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

What is the way to store android app resources on a server?
Toolbar crashing on Kitkat
Cordova Socket.Io connection refused localhost:3000
Failed to implement TTS on Android wear Emulator
Material fastscroll thumb with GridView and ArrayAdapter
Custom listview item xml disabling onitemclicklistener
Import errors on Android app after upgrading to Gradle 2.3.0
React Native compilation for Android fails on Windows due to 'build' folder issue
add a imageView below existing textview PROGRAMMATICALLY
Pending Intent and Alarm Manager
Is there any way to connect android device to a credit / debit card reader and pass billing information?
How to get child of child value from firebase in android?
Android getParcelableExtra object always returns null
Pass query params to redirect url from Branch
Which xamarin android apk to publish on google store?
Failed to resolve: com.android.support:support-core-utils:25.3.1

Categories

HOME
shell
algorithm
grok
adal
developer-tools
linkedin
3d
static
hessian
rendering
appcelerator
seo
database-normalization
carousel
babeljs
zip
p2p
openpyxl
linear-algebra
jersey-1.0
topology
libigl
react-toolbox
postscript
angular-routing
exit
onload
opentk
fat
stackexchange
firebase-analytics
genexus-sd
rpgle
aws-codecommit
python-2.6
clickjacking
python-import
lubridate
numpy-broadcasting
google-earth-engine
ideascript
protein-database
verifiable-c
google-data-api
signals-slots
apache-stanbol
numberpicker
comparison-operators
stringtokenizer
apache-spark-dataset
plan-9
double-click
launchctl
mongotemplate
payara-micro
pair-programming
amq
boxing
subnet
filehandle
visual-studio-2008-sp1
cubism.js
meteor-packages
pacemaker
rspec2
jquery-jscrollpane
nullable
piracy-prevention
highland.js
libvlc
xenomai
xvim
coda
viola-jones
ocra
rdflib
diff3
apache-spark-1.3
structuremap3
linkedin-jsapi
strawberry-perl
ignite-ui
reflector
visual-studio-express
printdialog
wimax
device-width
robotlegs
android-loadermanager
redis-py
gobject-introspection
procedures
promotion-code
creole
clrstoredprocedure
socketserver
qtabbar
alsb

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App