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

SQLiteException: near “=”: syntax error (code 1)
Which Json structure suitable for this work?
Why Android Pss increase constantly
Parcelable class with an interface member variable
Duplicate files copied in APK META-INF/BCKEY.SF
Custom GridLayout in Android
Android One-time Login screen using SharedPrefences
Push notification to Android and iOS using signal R in C#
IllegalStateException when the user clicks the Close button to dismiss a DialogFragment
Android Genymotion unable to load virtual device -> no IP Address (Windows 8.1)
How to add Image in window default action bar in android?
android:divider attribute in expandable list view crashes my app in Android 6.01
Android ViewPager display issue
How to set Turkish Language for SpeechRecognizer Google SpeechToText APi
Attempt to invoke virtual method 'android.view.Menu android.support.design.widget.NavigationView.getMenu()' on a null object reference
Error:Execution failed for task ':app:mergeDebugResources'. > java.lang.ArrayIndexOutOfBoundsException (no error message)

Categories

HOME
algorithm
eclipse
microsoftgraph
developer-tools
linkedin
dns
pascal
modal-dialog
endeca
jxl
openbugs
endpoint
scrolltop
cumulocity
docx
coin3d
digital-signature
asciidoctor-pdf
gulp-watch
ember-cli
exploit
google-cloud-print
has-and-belongs-to-many
inversion-of-control
quantlib
gp
mql
magento-1.8
send
event-flow
jmockit
sendbird
indy10
reverse
imx6
parse-tree
node-mssql
projects-and-solutions
watchface
claims
getchar
tf
appdomain
android-testing
check-mk
css-transforms
libjpeg
universal-analytics
django-1.10
reporting-services-2012
myspace
rspec2
synonym
tooleap
xdoclet
udpclient
mediametadataretriever
bizagi
libvlc
maybe
sapi
ess
android-launcher
wso2greg
sha512
alloy-ui
matlab-deployment
fail2ban
pseudo-class
post-commit-hook
punycode
cocos3d
rickshaw
mdichild
template-deduction
rcaller
draw2d-js
mutual-authentication
renderer
cfcache
amslidemenu
high-resolution
android-usb
code-duplication
inputmismatchexception
oocss
ui-select2
poker
cascadingdropdown
pyunit
agility.js
landscape-portrait
fsevents
jqote
resharper-6.0
django-piston
visualj#
pbcopy

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