0

I've made a image slider from viewPager. The image shown in viewPager is stored in raw folder inside the project of android studio.

I want to request for the permission of user to download image, display progress bar when image is downloading and finally a tost message when image is downloaded.

Things I've done:
-I have made a imageview button to download on the viewpager.
-Progressbar with android:visibility="invisible"
-My code in MainActivty where image and download option are shown.

public class MainActivity extends AppCompatActivity {
    ViewPager viewPager;
    ProgressBar progressBar;
    private int[] imageUrls = new int[]{
            R.drawable.after_cookie,
            R.drawable.before_cookie,
            R.drawable.androidparty
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressBar = findViewById(R.id.progress);
        viewPager = findViewById(R.id.view_pager);
        final ViewPageAdapter adapter = new ViewPageAdapter(this, imageUrls);
        viewPager.setAdapter(adapter);

        ImageView btnDownload = findViewById(R.id.btnDownload);
        btnDownload.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //what should I do? please help :(
            }
        });
    }
}

code of viewpager adapter:

public class ViewPageAdapter extends PagerAdapter {

    private Context context;
    private int[] imageUrls;
    public View currentImageView;

    ViewPageAdapter(Context context, int[] imageUrls) {
        this.context = context;
        this.imageUrls = imageUrls;
    }

    @Override
    public int getCount() {
        return imageUrls.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView view = new ImageView(context);

        Picasso.get()
                .load(imageUrls[position])
                .into(view);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        currentImageView = (View)object;
    }
}
Dibas Dauliya
  • 639
  • 5
  • 20
  • If the images are as resource in the raw folder you need no permissions. And you dont need to download them as they are already on the device. – blackapps Nov 22 '19 at 22:22
  • the images are in raw folder of my app's PROJECT and user can view it in viewpager. now, I want to add download option so user can download it. @blackapps – Dibas Dauliya Nov 23 '19 at 03:12
  • SO you are talking about imager on your PC which should be downloaded by an Android app on an Android device? Then how can the user of that Android app see them already in a ViewPager before they are downloaded? And you installed a server on your PC ? And is it relavant tnat they are in the raw folder? Normally files in the raw folder of a project are packed with the apk file and reachable at runtime for your app. It is very unclear what you want. You did explain hardly anything. – blackapps Nov 23 '19 at 08:41
  • i am showing user a image of my own and want to give also an download option to them. so they can download their favorite image. do you understood @blackapps sir? – Dibas Dauliya Nov 23 '19 at 10:46

0 Answers0