Android Open Source - Joetz-Android-V2 Image Pager Fragment From Project Back to project page Joetz-Android-V2 .
License The source code is released under:
GNU General Public License
If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.example.jens.myapplication.camps;
/ / w w w . j a v a 2 s . c o m
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.example.jens.myapplication.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
/**
* Created by Jens on 19/11/2014.
*/
public class ImagePagerFragment extends Fragment {
public static final String IMAGE_POSITION ="image_postion" ;
public static final String IMAGE_ARRAY ="image_array" ;
int [] imageUrls;
int position;
DisplayImageOptions options;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
options = new DisplayImageOptions.Builder()
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.build();
imageUrls = getActivity().getIntent().getExtras().getIntArray(IMAGE_ARRAY);
position = getActivity().getIntent().getExtras().getInt(IMAGE_POSITION);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_image_pager, container, false);
ViewPager pager = (ViewPager) rootView.findViewById(R.id.pager3);
pager.setAdapter(new ImageAdapter());
pager.setCurrentItem(position);
return rootView;
}
private class ImageAdapter extends PagerAdapter {
private LayoutInflater inflater;
ImageAdapter() {
inflater = LayoutInflater.from(getActivity());
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = inflater.inflate(R.layout.item_pager_image, view, false);
assert imageLayout != null;
ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);
ImageLoader.getInstance().displayImage("http://joetzdev.azurewebsites.net/api/images/" +Integer.toString(imageUrls[position]), imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error" ;
break ;
case DECODING_ERROR:
message = "Image can't be decoded" ;
break ;
case NETWORK_DENIED:
message = "Downloads are denied" ;
break ;
case OUT_OF_MEMORY:
message = "Out Of Memory error" ;
break ;
case UNKNOWN:
message = "Unknown error" ;
break ;
}
Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
view.addView(imageLayout, 0);
return imageLayout;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
}
@Override
public Parcelable saveState() {
return null;
}
}
}
Java Source Code List com.example.jens.myapplication.ApplicationTest.java com.example.jens.myapplication.account.FragmentAccount.java com.example.jens.myapplication.account.LoginDialogActivity.java com.example.jens.myapplication.account.LoginFragment.java com.example.jens.myapplication.account.PersonsFragment.java com.example.jens.myapplication.account.ProfileFragment.java com.example.jens.myapplication.account.RegisterDialogActivity.java com.example.jens.myapplication.account.RegisterFragment.java com.example.jens.myapplication.account.TabsPagerAdapter.java com.example.jens.myapplication.activities.ActivityDetailActivity.java com.example.jens.myapplication.activities.ActivityDetailFragment.java com.example.jens.myapplication.activities.FragmentListActivities.java com.example.jens.myapplication.activities.JoetzActivitiesAdapter.java com.example.jens.myapplication.activities.JoetzActivity.java com.example.jens.myapplication.activities.StartActivity.java com.example.jens.myapplication.apimanager.ApiConnection.java com.example.jens.myapplication.apimanager.CancellableTask.java com.example.jens.myapplication.apimanager.JSONParsingTask.java com.example.jens.myapplication.apimanager.PostRequestTask.java com.example.jens.myapplication.apimanager.RequestParams.java com.example.jens.myapplication.apimanager.SimpleRequestTask.java com.example.jens.myapplication.apimanager.filter.PersonFilter.java com.example.jens.myapplication.apimanager.manager.ActivityManager.java com.example.jens.myapplication.apimanager.manager.AuthToken.java com.example.jens.myapplication.apimanager.manager.BookingManager.java com.example.jens.myapplication.apimanager.manager.CampManager.java com.example.jens.myapplication.apimanager.manager.ImageManager.java com.example.jens.myapplication.apimanager.manager.LoginManager.java com.example.jens.myapplication.apimanager.manager.ProfileManager.java com.example.jens.myapplication.apimanager.manager.RegisterManager.java com.example.jens.myapplication.booking.AddPersonActivity.java com.example.jens.myapplication.booking.BookingActivity.java com.example.jens.myapplication.booking.BookingBondFragment.java com.example.jens.myapplication.booking.BookingContactFragment.java com.example.jens.myapplication.booking.BookingExtraFragment.java com.example.jens.myapplication.booking.BookingParticipantsFragment.java com.example.jens.myapplication.bookingHistory.BookingHistoryDetailActivity.java com.example.jens.myapplication.bookingHistory.BookingHistoryDetailFragment.java com.example.jens.myapplication.bookingHistory.BookingHistoryOverviewFragment.java com.example.jens.myapplication.bookingHistory.BookingsAdapter.java com.example.jens.myapplication.calendar.FragmentCalendar.java com.example.jens.myapplication.calendar.KalenderAdapter.java com.example.jens.myapplication.calendar.KalenderItem.java com.example.jens.myapplication.camps.CampAdapter.java com.example.jens.myapplication.camps.CampDetailActivity.java com.example.jens.myapplication.camps.CampFilterActivity.java com.example.jens.myapplication.camps.FilterFragment.java com.example.jens.myapplication.camps.FragmentListCamps.java com.example.jens.myapplication.camps.ImageActivity.java com.example.jens.myapplication.camps.ImagePagerFragment.java com.example.jens.myapplication.camps.InfoFragment.java com.example.jens.myapplication.camps.PhotoFragment.java com.example.jens.myapplication.camps.RecyclerItemClickListener.java com.example.jens.myapplication.camps.SquareImageView.java com.example.jens.myapplication.camps.TabsPagerAdapter.java com.example.jens.myapplication.domain.BookingStatus.java com.example.jens.myapplication.domain.Booking.java com.example.jens.myapplication.domain.Camp.java com.example.jens.myapplication.domain.PeriodCategory.java com.example.jens.myapplication.domain.Person.java com.example.jens.myapplication.domain.UserRole.java com.example.jens.myapplication.domain.User.java com.example.jens.myapplication.domain.binding.PersonValidatorBinding.java com.example.jens.myapplication.domain.binding.UserValidatorBinding.java com.example.jens.myapplication.domain.binding.ValidatorBinding.java com.example.jens.myapplication.domain.converter.ErrorConverter.java com.example.jens.myapplication.domain.converter.MyStringParser.java com.example.jens.myapplication.domain.converter.UnixDateTimeConverter.java com.example.jens.myapplication.domain.validator.PersonValidator.java com.example.jens.myapplication.domain.validator.UserValidator.java com.example.jens.myapplication.domain.validator.Validator.java com.example.jens.myapplication.home.AanbevolenAdapter.java com.example.jens.myapplication.home.HomeFragment.java com.example.jens.myapplication.home.ImageSlideAdapter.java com.example.jens.myapplication.home.Reclame.java com.example.jens.myapplication.lib.RangeSeekBar.java com.example.jens.myapplication.main.MainActivity.java com.example.jens.myapplication.main.NavDrawerAdapter.java com.example.jens.myapplication.main.NavDrawerItem.java com.example.jens.myapplication.main.NavMenuItem.java com.example.jens.myapplication.main.NavMenuSection.java com.example.jens.myapplication.sam.JoetzApplication.java com.example.jens.myapplication.sam.MyFragment.java com.example.jens.myapplication.sam.MySaveableFragment.java com.example.jens.myapplication.util.AESEncryption.java com.example.jens.myapplication.util.ActivityUtils.java com.example.jens.myapplication.util.BindingUtils.java com.example.jens.myapplication.util.DateTimeStringConverter.java com.example.jens.myapplication.util.JsonUtils.java com.example.jens.myapplication.util.MyMonths.java com.example.jens.myapplication.util.StringUtils.java com.example.jens.myapplication.view.MyLinearLayout.java