Monday, April 27, 2015

Tinder swipe functionality with AndTinder

AndTinder provides a nice library which offers a Tinder like swipe functionality.

Since this lib didn't work from the beginning for me, I am writing this blog on my problems.

Main problem was, that in the documentation nothing was mentioned on how to use the onCardDimissedListener, which is being triggered right after a card is being liked/disliked.

Here is the code I used to initialize the adapter

// global variable
CardContainer mCardContainer;

...

// onCreateView function
mCardContainer = (CardContainer) view.findViewById(R.id.cardView);

List<CardModel> cardModelList = new ArrayList<>();

for (int i = 0; i < 10; i++) {
final CardModel cardModel = new CardModel();
cardModel.setTitle("Model " + i);
cardModel.setDescription("model " + i);

cardModel.setOnCardDimissedListener(new CardModel.OnCardDimissedListener() {
@Override
public void onDislike() {
Log.e("Swipeable Card", "I did not like it -- " + cardModel.getTitle() + " - " + cardModel.getDescription());
}

@Override
public void onLike() {
Log.e("Swipeable Card", "I liked it -- " + cardModel.getTitle() + " - " + cardModel.getDescription());
}
});
cardModelList.add(cardModel);
}

SimpleCardStackAdapteradapter = new SimpleCardStackAdapter(getActivity(), cardModelList);
mCardContainer.setAdapter(adapter);


Everything was working fine, except for one problem, that the output in the Log was vice versa. This means, that Pic 10 was showed but in the log it did write Pic 1. And when Pic 9 was shown it did write Pic 2 in the log.

I had to change the source code in the following to make this work. For me this change has no negative side effect so far.

Open CardContainer.java file in the AndTinder project and go all the way down to the onFling() function.

Replace this line of code
CardModel cardModel = (CardModel)getAdapter().getItem(getChildCount() - 1);

by this line of code
CardModel cardModel = (CardModel)getAdapter().getItem(getAdapter().getCount() - getChildCount());

This is all you have to do.

Please comment if you like it or have further questions.

Greetings
Tobias

Saturday, October 5, 2013

Nexus 4 USB Debug Driver

It did cost me two hours to finally install the USB Debugging Driver for my Nexus 4. I got two Laptops with Windows 7 and I didn't have problems installing the driver on one Laptop. But it was a pain installing the driver on the other Laptop and I still don't know why.

Now here comes the workflow that made it work for me.
1. I did change the setup of my Windows 7 and deleted all the drivers that had something to do with Android. For this I had to open the Device Manager and get a list of all hidden / nonpresent devices. Check out this for further information
http://msdn.microsoft.com/en-us/library/windows/hardware/ff553955(v=vs.85).aspx

2. After uninstalling all devices I downloaded the latest USB Debugging version. Doesn't matter whether you use the Eclipse Android SDK Manager or download it directly from Google. Just check out this page.
http://developer.android.com/sdk/win-usb.html

3. I did enable the developer mode on my Nexus 4. Check out this page.
http://www.androidcentral.com/how-enable-developer-settings-android-42

4. I was playing around with plugging in/out and enabling/disabling the DebugMode and the MTP. I think it was the following order.
4.a. Disable DebugMode, Enable MTP, Plugin and select the usb drivers to be installed from <ANDROID-SDK>/extras/usb_drivers
4.b. Enable DebugMode, MTP stays enabled, and select the usb drivers to be installed from <ANDROID-SDK>/extras/usb_drivers
4.c. Once everything is installed correctly an ADB Interface should listed in your DeviceManager and a Popup appears on your phone asking you if the Laptop is authorized to install applications on the Nexus4

I think the most important part was uninstalling all hidden drivers before starting.

Friday, August 9, 2013

Android - NoClassDefFound Exception

I use currently Android 4.1.2 and Eclipse for development. The architecture of my applications is that I use my custom library which contains basic functionality. I do add this library to all my Android project in the libs folder and added it to the BuildPath of the projects.

The problem is that I was able to compile the project but when I was running the project I always got a NoClassDefFound Exception, because android was not able to find the classes in my jar.

After doing some research on the Internet I did find a suggestion by someone who was saying that it would be better to use Java 1.6 instead of Java 1.7. I switched to Java 1.6 and everything is working like a charme again.

Now I will continue developing ...