stfalcon-studio / StfalconImageViewer

A simple and customizable Android full-screen image viewer with shared image transition support, "pinch to zoom" and "swipe to dismiss" gestures
http://stfalcon.com
Apache License 2.0
1.99k stars 255 forks source link

Usage in Java only Project #4

Closed mr-mohit closed 5 years ago

mr-mohit commented 5 years ago

I have a java-only Android Project and I wanted to use this library but android studio is giving me error , 'Identitfier expected' in this line StfalconImageViewer.Builder(this, images ) Please provide a comprehensive documentation for its use in java project or include a java sample with this library's use it will be of great help

troy379 commented 5 years ago

Hey @mr-mohit Looks like you forgot to pass the ImageLoader implementation. This snippet works well:

new StfalconImageViewer.Builder<>(context, images, new ImageLoader<String>() {
            @Override
            public void loadImage(ImageView imageView, String image) {
                //load your image here
            }
        });
mr-mohit commented 5 years ago

@troy379 I tried the code that you suggested but the argument for the constructor is empty like between these <> brackets . Please see the attached screenshot below. All my images are in the drawable folder that I want to display and I tried to put Integer or string as argument like this

new StfalconImageViewer.Builder<Integer>(this, images, new ImageLoader<String>() {  
// **Its giving me cannot resolve constructor Builder error**
            @Override
            public void loadImage(ImageView imageView, String image) {
                //load your image here
            }
        });

But it is not working. allofit d__android_allofit - _app_src_main_java_com_example_mv_allofit_diet_plan_experiment_activity java app - android studio 07-01-2019 01_21_54 pm

troy379 commented 5 years ago

The generic type of the ImageViewer must be the same as the type of the images list you're passing to the Builder So, in your case, you need to replace String of the loader type with Integer like this:

new StfalconImageViewer.Builder<>(context, listOfDrawableResources, new ImageLoader<Integer>() {
            @Override
            public void loadImage(ImageView imageView, Integer drawableRes) {
                //load your image here
            }
        });
schelbin commented 5 years ago

I have a java-only Android Project and I wanted to use this library but android studio is giving me error , 'Identitfier expected' in this line StfalconImageViewer.Builder(this, images ) Please provide a comprehensive documentation for its use in java project or include a java sample with this library's use it will be of great help

I am so confused about the Java implementation. Could be possible to have the same example in Java?

mr-mohit commented 5 years ago

@troy379 I changed the generic type of Imageviewer to Integer as you instructed but it is still giving me the same Unable to resolve Constructor which is there in the screenshot above in my previous comment. I request you to implement your code snippet in a java file and then post the working code here , it will be of great help to me and all others who are trying to use your library in their Java only projects.

schelbin commented 5 years ago

Hello. This is my JAVA code: private static final String POSTERS_PATH = "https://raw.githubusercontent.com/stfalcon-studio/StfalconImageViewer/master/images/posters/Vincent.jpg";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        TextView textView = rootView.findViewById(R.id.section_label);
        textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
        final ImageView imageView1 = rootView.findViewById(R.id.imageViewTest);

        List<String> PATH = new ArrayList<>();
        PATH.add(POSTERS_PATH);

        new StfalconImageViewer.Builder<>(getContext(), PATH, new ImageLoader<String>() {
            @Override
            public void loadImage(ImageView imageView, String image) {
                Glide.with(getContext())
                        .load(image)
                        .into(imageView);
            }

        }).show();

        return rootView;
    }

And this is my XML code:

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity$PlaceholderFragment">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="@dimen/activity_horizontal_margin"
    android:layout_marginTop="@dimen/activity_vertical_margin"
    android:layout_marginEnd="@dimen/activity_horizontal_margin"
    android:layout_marginBottom="@dimen/activity_vertical_margin"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="@+id/constraintLayout"
    tools:layout_constraintLeft_creator="1"
    tools:layout_constraintTop_creator="1" />

<ImageView
    android:id="@+id/imageViewTest"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:clickable="false"
    android:scaleType="fitStart"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Where I must to relate the image id with the glide?

troy379 commented 5 years ago

@schelbin why do you need the image id? And what is the problem with the provided code snippet? Doesn't it work?

troy379 commented 5 years ago

@mr-mohit here is the working sample:

    private static final Integer[] RESOURCES = new Integer[]{R.mipmap.ic_launcher};

    private void showViewer() {
        new StfalconImageViewer.Builder<>(this, RESOURCES, new ImageLoader<Integer>() {
            @Override
            public void loadImage(ImageView imageView, Integer drawableRes) {
                imageView.setBackgroundResource(drawableRes);
            }
        }).show();
    }

Does it work for you?

schelbin commented 5 years ago

It is a simple code that now is working for me, but I want to use the overlay function and was not possible to me. I need to overlay the two images there:

`public class MainActivity extends AppCompatActivity {

private static final String PATH1 = "https://firebasestorage.googleapis.com/v0/b/acupuntura10-210104.appspot.com/o/AcuPoint%2FImages%2FRenders%2Fp1_ren.jpg?alt=media&token=01698031-8c4c-4280-a491-46dccd3e4dae";
private static final String PATH2 = "https://firebasestorage.googleapis.com/v0/b/acupuntura10-210104.appspot.com/o/AcuPoint%2FImages%2FIlustraciones%2Fp1.png?alt=media&token=ea01eb99-4b4a-4cd9-8c4d-2fe52bec3dd2";

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

    final ImageView render = findViewById(R.id.ivRender_esquema);
    final ImageView ilustracion = findViewById(R.id.ivIlustracion_esquema);

    Glide.with(this)
            .load(PATH1)
            .into(render);

    Glide.with(this)
            .load(PATH2)
            .into(ilustracion);
}

public void onBtnZoom(View view) {

    List<String> RENDER = new ArrayList<>();
    RENDER.add(PATH1);
    RENDER.add(PATH2);

    new StfalconImageViewer.Builder<>(this, RENDER, new ImageLoader<String>() {
        @Override
        public void loadImage(ImageView imageView, String image) {

            Glide.with(getApplicationContext())
                    .load(image)
                    .into(imageView);

        }
    }).withOverlayView(view).show();
}

}

`

And this is the XML:

`<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:selectableItemBackground"
    android:onClick="onBtnZoom">

    <ImageView
        android:id="@+id/ivRender_esquema"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart" />

    <ImageView
        android:id="@+id/ivIlustracion_esquema"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart" />

</RelativeLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>`

troy379 commented 5 years ago

@schelbin This feature isn't stated in the description and it is not possible to overlay two images in the viewer at the same time using the viewer. As a workaround, you can use the overlay view to achieve this. Or you can try to play with the bitmaps while loading the images into the target ImageView. For this kind of question please go to the StackOverflow, as this is not related to the current issue. As a start point, you can check this thread

mr-mohit commented 5 years ago
    private static final Integer[] RESOURCES = new Integer[]{R.mipmap.ic_launcher};

    private void showViewer() {
        new StfalconImageViewer.Builder<>(this, RESOURCES, new ImageLoader<Integer>() {
            @Override
            public void loadImage(ImageView imageView, Integer drawableRes) {
                imageView.setBackgroundResource(drawableRes);
            }
        }).show();
    }

Does it work for you?

Thanks @troy379 it worked for me . At last I will suggest you to do include some java based samples in future releases of your library. It will make it easier for all to use the library for complex use cases.

91coders commented 4 years ago

This is the working code for me for single image and using glide Finally I found something similar to whatsapp. I was digging over internet for three days now I found solution.

new StfalconImageViewer.Builder<String>(context, new ArrayList<>(Arrays.asList(messageModel.get(position).getUrl().trim())), new ImageLoader<String>() { @Override public void loadImage(ImageView imageView, String image) { Glide.with(context) .load(image) .into(imageView); } }).show();