Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for the java documentation of that library. #52

Open
BoumBam opened this issue Jun 25, 2020 · 23 comments
Open

Looking for the java documentation of that library. #52

BoumBam opened this issue Jun 25, 2020 · 23 comments
Assignees
Labels
question Further information is requested

Comments

@BoumBam
Copy link

BoumBam commented Jun 25, 2020

I'm android learner and I'm using java.
What is the java version of that code ?:
new StfalconImageViewer.Builder<>(context, images, new ImageLoader<String>() { @Override public void loadImage(ImageView imageView, String imageUrl) { Glide.with(context).load(imageUrl).into(imageView) } }).show();

When using it in my java code, <> is red marked with message: Cannot infer arguments(unable to resolve constructor)

Thanks.

@BoumBam BoumBam added the question Further information is requested label Jun 25, 2020
@acgs971
Copy link

acgs971 commented Jun 27, 2020

Same here! I'm really interested using this!

@BoumBam
Copy link
Author

BoumBam commented Jul 8, 2020

Same here! I'm really interested using this!

Have you found a solution to use it ?

I'm still looking for a way.

@amuizz20
Copy link

Have you tried using this code? It works for me.

ArrayList<String> images = new ArrayList<>();
                images.add(bundle.getString("PosterURL")); //your img url here
                new StfalconImageViewer.Builder<String>(context, images, new ImageLoader<String>() {
                    @Override
                    public void loadImage(ImageView imageView, String image) {
                        Glide.with(view.getContext()).load(image).into(imageView);
                    }
                }).show();

@BoumBam
Copy link
Author

BoumBam commented Jul 29, 2020

I tried your solution but it gives the following:

`java.lang.IllegalStateException: Could not execute method for android:onClick
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
        at android.view.View.performClick(View.java:6261)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:696)
        at com.e.files.Main3Activity.d(Main3Activity.java:36)`

@amuizz20
Copy link

The problem lies with XML file of Main3Activity and style.xml. Please share the code for it.

@BoumBam
Copy link
Author

BoumBam commented Jul 29, 2020

Below Main3Activity.xml

`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main3Activity">
    <ImageView
        android:id="@+id/image"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:onClick="d" />
</RelativeLayout>`

below the style.xml

`<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>`

Thanks.

@amuizz20
Copy link

Both of the files are fine. I have given it a try, and it worked.

Activity Code

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.stfalcon.imageviewer.StfalconImageViewer;
import com.stfalcon.imageviewer.loader.ImageLoader;
import java.util.ArrayList;
public class check extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check);
    }
    public void d(View view){
        ArrayList<String> images = new ArrayList<>();
        images.add("https://winaero.com/blog/wp-content/uploads/2019/11/Photos-new-icon.png"); //your img url here
        new StfalconImageViewer.Builder<String>(this, images, new ImageLoader<String>() {
            @Override
            public void loadImage(ImageView imageView, String image) {
                Glide.with(getApplicationContext()).load(image).into(imageView);
            }
        }).show();
    }
}

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".check">
    <ImageView
        android:id="@+id/image"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:onClick="d" />
</RelativeLayout>

build.gradle

dependencies {
    implementation 'com.github.chrisbanes:PhotoView:2.3.0'
    implementation 'com.github.stfalcon:stfalcon-imageviewer:1.0.1'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
 }
allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

Add this in Android Manifest

 <uses-permission android:name="android.permission.INTERNET"/>

@BoumBam
Copy link
Author

BoumBam commented Jul 29, 2020

It works now thanks too much.
That library would be more amazing if it was able to support video files.

If you know a library to suggest me for image and video viewing, please tell me.

Thanks alot for your help.

@amuizz20
Copy link

amuizz20 commented Jul 30, 2020

You can use two different libraries for both purposes. For Image, you can use the current library (StFalconImageViewer). For Video, you can try using this one (https://github.com/fpauer/Full-Screen-Video-Android).

Thank you.

@devroid-solutions
Copy link

Hey I'm trying to implement grid image view using this library using java. Could you please suggest me on how to do it.

I have used your sample code and I am able to bring multiple images in full screen mode. Now I want to have a images grid and on select of images grid, image should be displayed fullscreen

@amuizz20
Copy link

You can create images grid using Recycler View, and in Recyclerview adapter you can add the listener on the image and can add the same code as above.
Give it a try if you can't do it do let me know I will send you the code.

@devroid-solutions
Copy link

Thanks for the suggestion. I have tried this already @amuizz20 . I couldn't load the exact image that was clicked. When I clicke on any image from the grid, it always load the first image in StfalconImageViewer and not the one that I clicked on I have to swipe left to navigate to find the image

@amuizz20
Copy link

Please share the code here. I will help you to make it work.

@devroid-solutions
Copy link

devroid-solutions commented Aug 14, 2020

on the thumbnail onclick listener I am doing this

I have a to display images from a folder in mobile. files will have the list of files

new StfalconImageViewer.Builder<>(context, files, (imageView, file1) -> {
Bitmap myBitmap1 = BitmapFactory.decodeFile(file1.getAbsolutePath());
imageView.setImageBitmap(myBitmap1);
}).show();

Edit :
Instead of passing all files , i have just passed the the image file that was clicked and now I am able to see the clicked image in full screen. But Since I passed only one file, I can't swipe left/right to see rest of images

@amuizz20
Copy link

In this code you should pass complete Images array to StFalconImageViewer so, you can swipe left and right and also pass the position of the selected image.

new StfalconImageViewer.Builder<>(context, files, (imageView, file1) -> {
Bitmap myBitmap1 = BitmapFactory.decodeFile(file1.getAbsolutePath());
imageView.setImageBitmap(myBitmap1);
}).show().setCurrentPosition(position);  //position here. 

This is how I did that. You can do the same with your mobile folder images.

Activitycheck.java


public class check extends AppCompatActivity {

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

        RecyclerView mRecyclerview = findViewById(R.id.mRecyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
        mRecyclerview.setLayoutManager(linearLayoutManager);
        mRecyclerview.setHasFixedSize(true);
        ArrayList<String>image = new ArrayList<>();
        image.add("https://image.shutterstock.com/image-vector/link-icon-digital-marketing-management-260nw-1723576054.jpg");
        image.add("https://www.computerhope.com/jargon/l/link.jpg");
        image.add("https://louisem.com/wp-content/uploads/2013/01/1-facebook-link-share-button.png");
        image_adapter image_adapter = new image_adapter(this,image);
        mRecyclerview.setAdapter(image_adapter);
    }
}

activity_check.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".check">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/mRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        />
</RelativeLayout>

recycler_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    >
    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_marginRight="20dp"
        android:layout_marginLeft="20dp"
        />

</LinearLayout>

image_viewholder.java

public class image_viewholder extends RecyclerView.ViewHolder {
    ImageView image;
    public image_viewholder(@NonNull View itemView) {
        super(itemView);
        image = itemView.findViewById(R.id.image);
    }
}

image_adapter.java

public class image_adapter extends RecyclerView.Adapter<image_viewholder> {
    private List<String> imageslink;
    private Context mContext;
    public image_adapter(Context mContext, List<String> imageslink) {
        this.imageslink=imageslink;
        this.mContext = mContext;
    }
    @NonNull
    @Override
    public image_viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_image_layout,
                parent, false);
        return new image_viewholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull image_viewholder holder, int position) {
        Glide.with(mContext).load(imageslink.get(position)).centerCrop().into(holder.image);
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new StfalconImageViewer.Builder<String>(mContext, imageslink, new ImageLoader<String>() {
                    @Override
                    public void loadImage(ImageView imageView, String image) {
                        Glide.with(mContext).load(image).into(imageView);
                    }
                }).show().setCurrentPosition(position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return imageslink.size();
    }
}

@devroid-solutions
Copy link

This is exactly what I want. Whenever I pass all files, it was always taking to the first image and I wasn't sure how to set position. I was missing the below part in my implementation.

setCurrentPosition(position)

Thanks a million

@BoumBam
Copy link
Author

BoumBam commented Aug 27, 2020

You can use two different libraries for both purposes. For Image, you can use the current library (StFalconImageViewer). For Video, you can try using this one (https://github.com/fpauer/Full-Screen-Video-Android).

Thank you.

But I have a mixed list of images and video.
I want to show them all in an image and video viewer. I want the same like: https://github.com/sachinchoolur/lightGallery/.

For user good experience, I want when user slide an image if the next file is a video, I want play that video in the same library viewer without closing the actual viewer and show the other viewer for video.

I know it is possible because Facebook do it in its app.

Do you understand me ?

Thanks a million.

@amuizz20
Copy link

You can make a custom library for this. You can detect whether the file is an image or video and then to view the photo or video, ImageView and VideoView will be used (Check Android Documentation). In the activity, make the visibility false for VideoView and display ImageView if it is an image, make the visibility false for ImageView and display VideoView if it is a Video. Using this you can achieve what you wanted.

For Help, you can see the code for both of the libraries and can combine them for both purposes (video and photo). It would be a great idea to make a library like that for your own purpose like facebook did.

@BoumBam
Copy link
Author

BoumBam commented Aug 27, 2020

@amuizz20 The thing that makes me fear the most is to have to create a library.
I'm just a beginner I'm working on my first app And I do not know how to make a library. I even dont know where to start.

I started android developpement at April 2020.

I think even for experienced developper, making a library take at least several months.

@BoumBam
Copy link
Author

BoumBam commented Aug 27, 2020

@amuizz20 The thing that makes me fear the most is to have to create a library.
I'm just a beginner I'm working on my first app And I do not know how to make a library. I even dont know where to start.

I started android developpement at April 2020.

I think even for experienced developper, making a library take at least several months.

I'm sad to know that no one thought to make something like that for android community.

@amuizz20
Copy link

amuizz20 commented Aug 27, 2020

Disappointed that no one made the library that can do that. But it is not that difficult to make it, but it just takes time. You can make something like that after six months in android development.

You can look at this Open Source Project. It is a gallery app. They implemented the same thing.
https://github.com/kollerlukas/Camera-Roll-Android-App

Btw I have got an idea. If I have got enough time from my work, I want to make a try to make something like that, as you suggested. It would be helpful for the community.

@BoumBam
Copy link
Author

BoumBam commented Sep 2, 2020

@amuizz20 Sorry to make you back here again.
How could I override the double click and the long press event of each image passed to that library ?

Is it possible ?

I want to close the imageViewer when user double click on an image. I also want to save an image when user long press on it.

Thanks ten millions.

@ashish-d-hh
Copy link

I made it to be used like:

val images: ArrayList<String> = ArrayList()
        images.add(docOfAFolder.path)
        StfalconImageViewer.Builder<String>(this.context, images,
            ImageLoader<String?> { imageView, image ->
                Glide.with(this).load(image)
                    .into(view.your_image)
            }).show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants