Java Question wrapping AndroidImageSlider Issue

Asim A Baki

Active Member
Licensed User
Longtime User
Hi
I'm trying to wrap the AndroidImageSlider from https://github.com/daimajia/AndroidImageSlider
I have an issue in the following code which terminates the program just after initialize calling without any error

would you please tell me whats wrong
B4X:
package AndroidSlider.SliderLibrary;

import java.util.HashMap;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;

import android.content.Context;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
@ActivityObject
@ShortName("Slider")
@Version(1)
@Permissions(values = { "android.permission.INTERNET", "android.permission.WAKE_LOCK" })
@DependsOn(values={"Library"})
@Events(values={"Playing",
        "Stopped",
        "Paused",
        "Resumed",
        "ImageChanged(index as Int)"
        })
public class Slider extends ViewWrapper<SliderLayout>{
    HashMap<String,String> url_maps = new HashMap<String, String>();
    Context mCont;
    HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
    /**
     * AndroidSlider currently wraps version x
     * https://github.com/daimajia/AndroidImageSlider
     */
    public static void LIBRARY_DOC() {
    }
 
    @Override
    public void Initialize(BA pBA, String EventName) {
        super.Initialize(pBA, EventName);
    }
    @Hide
    @Override
    public void innerInitialize(final BA pBA, final String pEventName, boolean pKeepOldObject) {
        if (!pKeepOldObject) {
            SliderLayout mDemoSlider=new SliderLayout(pBA.context);
            mCont=pBA.context;
        
            setObject(mDemoSlider);
            pKeepOldObject=true;
        }
    
        super.innerInitialize(pBA, pEventName, pKeepOldObject);

    }
    public void AddSlide(String Name,String URL)
    {
        url_maps.put(Name, URL);
    

    }
    @Override
    public void SetLayout(int Top, int Left, int Width, int Height) {
        super.SetLayout(Left, Top, Width, Height);
    }


    /**
     * Starts or resumes playing.
     */
    public void Start() {
         for(String name : url_maps.keySet()){
                TextSliderView textSliderView = new TextSliderView(mCont);
                // initialize a SliderLayout
                textSliderView
                        .description(name)
                        .image(url_maps.get(name))
                        .setScaleType(BaseSliderView.ScaleType.Fit);

                //add your extra information
                textSliderView.getBundle()
                        .putString("extra",name);

               getObject().addSlider(textSliderView);
            }
         getObject().setPresetTransformer(SliderLayout.Transformer.Accordion);
         getObject().setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
         getObject().setCustomAnimation(new DescriptionAnimation());
         getObject().setDuration(4000);
    }
    /**
     * Stops the playback.
     */
    public void StopPlayback() {
        getObject().stopAutoCycle();
    }
    /**
     * Resumes the playback.
     */
    public void Resume() {
        getObject().startLayoutAnimation();
    }
    /**
     * Pauses the playback.
     */
    public void Pause() {
        getObject().stopAutoCycle();
    }
}
 

walterf25

Expert
Licensed User
Longtime User
Hi
I'm trying to wrap the AndroidImageSlider from https://github.com/daimajia/AndroidImageSlider
I have an issue in the following code which terminates the program just after initialize calling without any error

would you please tell me whats wrong
B4X:
package AndroidSlider.SliderLibrary;

import java.util.HashMap;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;

import android.content.Context;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
@ActivityObject
@ShortName("Slider")
@Version(1)
@Permissions(values = { "android.permission.INTERNET", "android.permission.WAKE_LOCK" })
@DependsOn(values={"Library"})
@Events(values={"Playing",
        "Stopped",
        "Paused",
        "Resumed",
        "ImageChanged(index as Int)"
        })
public class Slider extends ViewWrapper<SliderLayout>{
    HashMap<String,String> url_maps = new HashMap<String, String>();
    Context mCont;
    HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
    /**
     * AndroidSlider currently wraps version x
     * https://github.com/daimajia/AndroidImageSlider
     */
    public static void LIBRARY_DOC() {
    }

    @Override
    public void Initialize(BA pBA, String EventName) {
        super.Initialize(pBA, EventName);
    }
    @Hide
    @Override
    public void innerInitialize(final BA pBA, final String pEventName, boolean pKeepOldObject) {
        if (!pKeepOldObject) {
            SliderLayout mDemoSlider=new SliderLayout(pBA.context);
            mCont=pBA.context;
       
            setObject(mDemoSlider);
            pKeepOldObject=true;
        }
   
        super.innerInitialize(pBA, pEventName, pKeepOldObject);

    }
    public void AddSlide(String Name,String URL)
    {
        url_maps.put(Name, URL);
   

    }
    @Override
    public void SetLayout(int Top, int Left, int Width, int Height) {
        super.SetLayout(Left, Top, Width, Height);
    }


    /**
     * Starts or resumes playing.
     */
    public void Start() {
         for(String name : url_maps.keySet()){
                TextSliderView textSliderView = new TextSliderView(mCont);
                // initialize a SliderLayout
                textSliderView
                        .description(name)
                        .image(url_maps.get(name))
                        .setScaleType(BaseSliderView.ScaleType.Fit);

                //add your extra information
                textSliderView.getBundle()
                        .putString("extra",name);

               getObject().addSlider(textSliderView);
            }
         getObject().setPresetTransformer(SliderLayout.Transformer.Accordion);
         getObject().setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
         getObject().setCustomAnimation(new DescriptionAnimation());
         getObject().setDuration(4000);
    }
    /**
     * Stops the playback.
     */
    public void StopPlayback() {
        getObject().stopAutoCycle();
    }
    /**
     * Resumes the playback.
     */
    public void Resume() {
        getObject().startLayoutAnimation();
    }
    /**
     * Pauses the playback.
     */
    public void Pause() {
        getObject().stopAutoCycle();
    }
}
I tried wrapping this library also, gave up after a while, Let me know if you get it to work.

Cheers,
Walter
 

Asim A Baki

Active Member
Licensed User
Longtime User
Check the unfiltered logs. There must be an error message.
the error was NULL value exception

I've found the reason is that the library is needing setContentView before creating a new instance

the original code from the demo is
B4X:
        setContentView(R.layout.activity_slideshow);

        slideShowView = (SlideShowView) findViewById(R.id.slideshow);

while as a wrapper I have to use it as follow

B4X:
    public void innerInitialize(final BA pBA, final String pEventName, boolean pKeepOldObject) {
        if (!pKeepOldObject) {
setContentView (......... ????????

            SliderLayout mDemoSlider=new SliderLayout(pBA.context);
            mCont=pBA.context;
     
            setObject(mDemoSlider);
            pKeepOldObject=true;
        }
 
        super.innerInitialize(pBA, pEventName, pKeepOldObject);

    }

I tried to make Eclipse android application and use the code below in it and it was successfull

B4X:
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        SLayout=new SliderLayout( getBaseContext() );

the crash occures in the last line of the following code
B4X:
    public SliderLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.slider_layout, this, true);


I need to know how to use the setContentView and in which library I find it because I think it is not natively existing in
ViewWrapper<SliderLayout> class



any help?
 
Last edited:

Asim A Baki

Active Member
Licensed User
Longtime User
You don't need to call setContentView. B4A calls it internally.

this library has some resources, and layout, when I try to attach the resources to the b4a with
B4X:
#AdditionalRes PATHtoRESfolder,com.daimajia.slider.library

I face this error
B4X:
android.view.InflateException: Binary XML file line #62: Error inflating class com.daimajia.slider.library.Tricks.InfiniteViewPager

the error occures in the library line
B4X:
 LayoutInflater.from(context).inflate(R.layout.slider_layout, this, true);
 

Asim A Baki

Active Member
Licensed User
Longtime User
Can you post the full stack trace?

B4X:
main_activity_create (B4A line: 37)
Slider.Initialize("Slider")
android.view.InflateException: Binary XML file line #62: Error inflating class com.daimajia.slider.library.Tricks.InfiniteViewPager
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:173)
    at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:167)
    at com.daimajia.slider.library.SliderLayout.<init>(SliderLayout.java:163)
    at AndroidSlider.SliderLibrary.Slider.innerInitialize(Slider.java:67)
    at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:65)
    at AndroidSlider.SliderLibrary.Slider.Initialize(Slider.java:53)
    at b4a.example.main._activity_create(main.java:349)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    ... 26 more
Caused by: java.lang.NoClassDefFoundError: android.support.v4.view.ViewConfigurationCompat
    at com.daimajia.slider.library.Tricks.ViewPagerEx.initViewPager(ViewPagerEx.java:364)
    at com.daimajia.slider.library.Tricks.ViewPagerEx.<init>(ViewPagerEx.java:352)
    at com.daimajia.slider.library.Tricks.InfiniteViewPager.<init>(InfiniteViewPager.java:19)
    ... 29 more
 

Asim A Baki

Active Member
Licensed User
Longtime User
[SOLVED]
After some digging, I found this great thread https://www.b4x.com/android/forum/threads/msmaterialdrawer.53883/page-3

I added the following to my code
B4X:
    #AdditionalRes: C:\Users\asim\Downloads\EclipseProject\Library\res, com.daimajia.slider.library
    #AdditionalRes: C:\Users\asim\Downloads\EclipseProject\android-support-v7-appcompat\res

and added the files to my android libs
B4X:
android-support-v4.jar
android-support-v7-appcompat.jar
android-support-v7-mediarouter.jar

now the code run successful, Wait for my wrapper :)
 

Xfood

Expert
Licensed User
Hi
I'm trying to wrap the AndroidImageSlider from https://github.com/daimajia/AndroidImageSlider
I have an issue in the following code which terminates the program just after initialize calling without any error

would you please tell me whats wrong
B4X:
package AndroidSlider.SliderLibrary;

import java.util.HashMap;

import com.daimajia.slider.library.SliderLayout;
import com.daimajia.slider.library.Animations.DescriptionAnimation;
import com.daimajia.slider.library.SliderTypes.BaseSliderView;
import com.daimajia.slider.library.SliderTypes.TextSliderView;

import android.content.Context;
import android.util.Log;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;
@ActivityObject
@ShortName("Slider")
@Version(1)
@Permissions(values = { "android.permission.INTERNET", "android.permission.WAKE_LOCK" })
@DependsOn(values={"Library"})
@Events(values={"Playing",
        "Stopped",
        "Paused",
        "Resumed",
        "ImageChanged(index as Int)"
        })
public class Slider extends ViewWrapper<SliderLayout>{
    HashMap<String,String> url_maps = new HashMap<String, String>();
    Context mCont;
    HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
    /**
     * AndroidSlider currently wraps version x
     * https://github.com/daimajia/AndroidImageSlider
     */
    public static void LIBRARY_DOC() {
    }
 
    @Override
    public void Initialize(BA pBA, String EventName) {
        super.Initialize(pBA, EventName);
    }
    @Hide
    @Override
    public void innerInitialize(final BA pBA, final String pEventName, boolean pKeepOldObject) {
        if (!pKeepOldObject) {
            SliderLayout mDemoSlider=new SliderLayout(pBA.context);
            mCont=pBA.context;
       
            setObject(mDemoSlider);
            pKeepOldObject=true;
        }
   
        super.innerInitialize(pBA, pEventName, pKeepOldObject);

    }
    public void AddSlide(String Name,String URL)
    {
        url_maps.put(Name, URL);
   

    }
    @Override
    public void SetLayout(int Top, int Left, int Width, int Height) {
        super.SetLayout(Left, Top, Width, Height);
    }


    /**
     * Starts or resumes playing.
     */
    public void Start() {
         for(String name : url_maps.keySet()){
                TextSliderView textSliderView = new TextSliderView(mCont);
                // initialize a SliderLayout
                textSliderView
                        .description(name)
                        .image(url_maps.get(name))
                        .setScaleType(BaseSliderView.ScaleType.Fit);

                //add your extra information
                textSliderView.getBundle()
                        .putString("extra",name);

               getObject().addSlider(textSliderView);
            }
         getObject().setPresetTransformer(SliderLayout.Transformer.Accordion);
         getObject().setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
         getObject().setCustomAnimation(new DescriptionAnimation());
         getObject().setDuration(4000);
    }
    /**
     * Stops the playback.
     */
    public void StopPlayback() {
        getObject().stopAutoCycle();
    }
    /**
     * Resumes the playback.
     */
    public void Resume() {
        getObject().startLayoutAnimation();
    }
    /**
     * Pauses the playback.
     */
    public void Pause() {
        getObject().stopAutoCycle();
    }
}
Good morning,
this port looks very interesting,
there is a b4xlib library that does more or less the same things, that would be very interesting
 

DonManfred

Expert
Licensed User
Longtime User
there is a b4xlib library that does more or less the same things, that would be very interesting
You are posting to a seven years old thread. Usually a mistake
 
Last edited:

Xfood

Expert
Licensed User
yes, I know, but this library looks very interesting, do we have a similar library, in b4xlib?
 

DonManfred

Expert
Licensed User
Longtime User
yes, I know, but this library looks very interesting, do we have a similar library, in b4xlib?
You are still posting to the wrong thread. You should always create a new thread for issues.
Additional the forumsearch IS working and there is a B4A Library already.
b4xlib i don´t think will be possible as it is a android java-project. It can not work in B4J and for B4i you have to write it in a different language than java.
 
Top