android


Progress Bar while seekbar fills up as well as when switching images


So I am currently using glide to load images from a server into a imageView. To switch between the images, I am using a seekbar. That seekbar is populated by the time duration of the drive (so beginning would be 0 and the end would be the end time of the drive). If a user picks a new drive, I was a progress bar to show while the seekbar fills up. Then when the user moves the seekbar around, I want a vertical progress bar until the image loads. Here is what I have so far, and what currently happens is the spinner only shows when I load the fragment, not when a user selects a drive.
public class SecondFragment extends Fragment implements APIRequestsUtil.APIRequestResponseListener
{
View myView;
Map<String, Route> drives;
ImageView imageView;
SeekBar mySeekBar;
ProgressBar myProgress;
int totalImages = 0;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.second_layout, container, false);
APIRequestsUtil.setOnAPIResponseListener(this);
imageView = (ImageView) myView.findViewById(R.id.driveImageView);
mySeekBar = (SeekBar) myView.findViewById(R.id.seekBar);
mySeekBar.setMax(1);
myProgress = (ProgressBar) myView.findViewById(R.id.progress);
return myView;
}
#Nullable
private void populateView() {
this.getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
drives = APIRequestsUtil.getRoutes();
// edit: you need to generate your List data from the entrySet
// the ArrayAdapter cannot take a Set argument - needs to be a List
List<Drive> list = new ArrayList<Drive>();
for (Map.Entry drive : drives.entrySet()) {
Drive d = new Drive(drive.getKey().toString(), (Route) drive.getValue());
list.add(d);
}
// populate the ListView
// may need to change "getActivity()" to something else
// this constructor needs the "this" context of the activity
DriveURLAdapter drivesURLAdapter = new DriveURLAdapter(getActivity(), list);
final Spinner spinner = (Spinner) myView.findViewById(R.id.spinner);
drivesURLAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(
new NothingSelectedSpinnerAdapter(
drivesURLAdapter,
R.layout.spinner_row_nothing_selected,
getActivity()));
if (spinner.getTag() != null) {
spinner.setSelection((int) spinner.getTag());
}
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long l) {
if (spinner.getTag() != null && pos != (int) spinner.getTag()) {
spinner.setTag(pos);
final String url = DriveURLAdapter.DriveURL;
int driveTime = (int) DriveURLAdapter.driveSeconds;
final List<String> URLs = new ArrayList<String>();
for (int x = 0; x < driveTime; x++) {
URLs.add(url + "/sec" + x + ".jpg");
}
downloadOnlyImages(URLs);
mySeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Glide.with(getActivity())
.load(URLs.get(progress))
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
myProgress.setVisibility(View.GONE);
return false;
}
})
.override(480,270)
.fitCenter()
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
spinner.setTag(pos);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
Toast.makeText(getActivity(), "Please select a drive to display.", Toast.LENGTH_SHORT).show();
}
});
}
});
}
#Override
public void onFailure(Request request, Throwable throwable) {
}
#Override
public void onResponse(Response response) {
populateView();
}
#Override
public void onResume() {
super.onResume();
try {
APIRequestsUtil.run();
} catch (Exception e) {
e.printStackTrace();
}
}
private void downloadOnlyImages(List<String> URLs){
totalImages = 0;
for(final String url: URLs){
Glide.with(this)
.load(url)
.downloadOnly(new SimpleTarget<File>(480,270) {
#Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
Log.i("glide", "image downloaded" + url);
mySeekBar.setMax(totalImages++);
}
});
}
}
}

Related Links

Android and SQLite - select datetime error
Data Transfer Rate
Do works in background indefinitely
How to Scroll GridView in Full Screen
Lolipop toolbar drawer toggle not clickable
Error by using Gson class [STACKOVERFLOW ERROR]
Passing URL string to AsyncTask
Phonegap instalation - 'phonegap is not recognized as an internal or'
How to set background color for dropdown arrow spinner programatically
Google IAP verification has failed for many purchases
No resource found after update my project API to 21 and AppCompat to 21.02
Separate TouchPhase.Began and TouchPhase.Moved
Datastore Entities not showing
get rid of ContentProvider per database table
Can't Install Apache ant on Mac OS X 10.10
How to import Android library project in Android Studio RC 2

Categories

HOME
service-worker
batch-file
url-redirection
cygwin
twitter-bootstrap-3
css3
ns-3
battery
pclxl
opendj
access
soa
x264
python-multithreading
nfs
drop-down-menu
datastage
scrolltop
parameter-passing
coin3d
keytool
entitymanager
production
named-entity-recognition
aggregation
draft-js-plugins
data.stackexchange.com
slidetoggle
licensing
8051
android-things
cppreference
tizen-tv
jaws
linkedhashmap
getlasterror
fiware-cygnus
lint
metaprogramming
ogc
portforwarding
ssrs-2014
insight
page-replacement
template-toolkit
google-photos
cd-burning
vibrate
builtins
redistributable
segment-io
tinkerpop3
resourcemanager
watch-os-2
model-associations
android-wake-lock
query-by-example
bizagi
findfirst
toast
phpgrid
spring-retry
dynamics-nav-2016
sciruby
xenomai
vigenere
microsoft-reporting
sha512
mirror
botan
teamcity-9.1
zxspectrum
gamekit
ssis-data-flow
universal-image-loader
angular-carousel
parallel-testing
reflector
eclipse-kepler
mongohq
kogrid
cffile
font-awesome-4.0.0
wp7test
device-width
xcode3.2
adobe-media-server
thttpd
database-create
cross-database
jqote
dot-emacs
zen
opml
blender-2.49
duplex
echo3
glui
entitykey
flvplayback
soappy

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