yashsingh1/xdaforums huggingface dataset:
[Java for Android App Development] nikwen:
The app looks nice. :good:
[Java for Android App Development] Androguide.fr:
Thanks a lot.

It's an app inspired by http://codecademy.com, it will basically allow people to learn & teach android development through interactive tutorials and exercises, and maybe even allow the user to build the apks written during the tutorials.

Here is what a lesson looks like, currently :

The reset code button spins the editor while resetting the code:
[Java for Android App Development] jetx2x:
this is awesome... was wanting to build a calendar app with google's new design concepts... makes it so much easier now... thinking maybe I should contribute by releasing a similarly themed grid view implementation
[Java for Android App Development] Androguide.fr:
Actually, there's already a multi-column implementation, but it's buggy with stacks.

To change the amount of columns simply modify the mColumnNumber variable in /views/CardUI.java (it's set to 1 by default).

If you wanna take a shot at fixing stacks in multi-columns, go ahead, would be much appreciated :good:
[Java for Android App Development] jetx2x:
I'm not all that experienced yet but ill give it a shot :D
[Java for Android App Development] nikwen:
It will be a great learning experience. :good:
[Java for Android App Development] Wetzel402:
Has anyone had trouble importing the library? Eclipse will not recognize it for me :confused:
[Java for Android App Development] jetx2x:
I had no issues... Although I am using android studio... I think it worked OK in eclipse before I made the switch

Taptalked u see ... əəs n pəʞlɐʇdɐʇ
[Java for Android App Development] Androguide.fr:
Can you elaborate the doesn't recognize part ?

If you mean it's not in the list of available libraries when adding one to your project, then right-click the cardsui lib --> properties --> Android, and tick the "Library project" checkbox.
[Java for Android App Development] Wetzel402:
I import it as a library but eclipse doesn't recognize any of the code to import it. I also tried manually importing which also fails to compile. Maybe I am doing something wrong during the import process? I have google admob imported and that works fine though.
[Java for Android App Development] D-FUSE:
What is you api set at. Is your projects api the same has the libray?

Also right click on your project and add libray support

One more thing. Right click your project go to properties. Delete the library and add it again. Because it was made on another device it won't recognize and yours.
[Java for Android App Development] Wetzel402:
I haven't seen any minimum SDK info for the library but my app is set at 7 and I see the example app also is at 7 so that isn't my problem.

Edit:

I was working with my project again today and noticed my .jar doesn't seem to have the proper resources. Perhaps it is from a bad branch? The included .jar is supposed to work correct?
[Java for Android App Development] Wetzel402:
So noob mistake. I have never built a library so I didn't realize I needed to do that first. I was using the nineoldandroids.jar file :silly:

I now have it mostly working. :victory: I am just running into problems with the MyCard and MyPlayCard. Android studio doesn't know what to do with them.
[Java for Android App Development] Androguide.fr:
What do you mean by "doesn't know what to do with them"? Does it throw errors? (if it does, which?)

I'll try to convert the lib to make proper use of gradle and commit it in a separate branch sometime soon.
[Java for Android App Development] Wetzel402:
I am getting "can not resolve symbol". Right now I am only trying to run the example code so it should work just fine and my imports match.

Edit: I was missing the MyCard and MyPlayCard classes now all the java looks good but my xml crashes when opened. Android Studio reports:

Rendering Problems The following classes could not be found:
-*com.fima.cardsui.views.CardUI (Change to com.fima.cardsui.views.CardUI, Fix Build Path, Create Class)
Tip: Try to build the project

Just to make sure it is the xml causing the problem I also tried removing all java except setContentView and tried running it.

Sorry I'm filling the thread with my rookie developer issues :eek:
[Java for Android App Development] Androguide.fr:
Please post the content of your build.gradle file, looks like the library isn't referenced as such in your project.
[Java for Android App Development] Wetzel402:
I don't have such a file in my project. I see an option to set a path for gradle so I downloaded v1.6 and setup the path now. Is the file supposed to be auto generated?
[Java for Android App Development] Androguide.fr:
Import your project in Eclipse after making sure you have updated your SDK to v17 (the latest), then right click it and choose 'Export' --> 'Gradle build files'.

Afterwards, your project is ready to be imported in Android Studio, otherwise you won't be able to build the project in Studio as it uses the new build system exclusively.

You can alternatively write your own build.gradle & settings.gradle files.

I suggest you read this quick start guide & watch the following videos to get up-to-date with the new build system and IntelliJ/Studio (or to stick with Eclipse until Studio is at a stable/finished stage) :

Gradle for Android quick start : http://www.gradleware.com/resources/tech/android

What's new in Android Developer Tools (I/O 2013) :

[YOUTUBE]lmv1dTnhLH4[/YOUTUBE]

The new android build system (I/O 2013) :

[YOUTUBE]LCJAgPkpmR0[/YOUTUBE]
[Java for Android App Development] Wetzel402:
Thank you for the information, it is very helpful. I did get my project exported with Gradle files so that is a good step :) Of course I still have issues though :silly: Apparently libraries can be difficult to use for a newbie...

Rendering Problems The following classes could not be instantiated:
-*com.fima.cardsui.views.CardUI (Open Class, Show Exception)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.ClassNotFoundException: com.fima.cardsui.R$layout **
at java.net.URLClassLoader$1.run **
at java.net.URLClassLoader$1.run **
at java.security.AccessController.doPrivileged **
at java.net.URLClassLoader.findClass **
at java.lang.ClassLoader.loadClass **
at java.lang.ClassLoader.loadClass **
at com.fima.cardsui.views.CardUI.initData(CardUI.java:105) **
at com.fima.cardsui.views.CardUI.<init>(CardUI.java:88) *
at java.lang.reflect.Constructor.newInstance **
at android.view.LayoutInflater.rInflate_Original **
at android.view.LayoutInflater_Delegate.rInflate *
at android.view.LayoutInflater.rInflate **
at android.view.LayoutInflater.inflate *
at android.view.LayoutInflater.inflate

A library compile error perhaps?
[Java for Android App Development] Androguide.fr:
I really don't see how you get all these errors, I even re-cloned the library from my repo as I modified my local one, and there's no build errors.

Make sure the library has NineOldAndroids referenced as a library, and that your project references the library but not NineOldAndroids.

If you still have errors try adding the v4 support library to the lib and/or your project.

Also, did you trigger a build since you imported it into Studio? The ClassNotFoundException is from R, so it looks like you didn't build the lib, thus R.java hasn't been generated.
[Java for Android App Development] Wetzel402:
Sorry for the long delay (work :eek:). I finally have CardsUI working in Eclipse now. I was not using the library correctly in the first place.

Thank you so much for the help! :highfive:
[Java for Android App Development] Androguide.fr:
No problem, glad you got it sorted out ;)
[Java for Android App Development] Wetzel402:
Get card info from resources

Added to Card.java in library:

public Card(int titleStrobe,int imageStrobe, int cardColor, Boolean isClickable ){

this.titleStrobe = titleStrobe;
this.imageStrobe = imageStrobe;
this.cardColor = cardColor;
this.isClickable = isClickable;

}

Added to AbstractCard.java in library:

protected int image, cardColor, titleStrobe, imageStrobe, textCardText;

public int getTitleStrobe(){
return titleStrobe;
}

public int getImageStrobe(){
return imageStrobe;
}

public int getResource(){
return cardColor;
}

MyStrobeCard class:

public class MyStrobeCard extends Card {

public MyStrobeCard(int titleStrobe,int imageStrobe, int cardColor, Boolean isClickable) {
super(titleStrobe,imageStrobe, cardColor, isClickable);
}

[MENTION=439709]override[/MENTION]
public View getCardContent(Context context) {
View v = LayoutInflater.from(context).inflate(R.layout.strobe_card, null);

((TextView) v.findViewById(R.id.strobe_card_text)).setText(titleStrobe);
((TextView) v.findViewById(R.id.strobe_card_text))
.setTextColor(context.getResources().getColor(cardColor));
((ImageView) v.findViewById(R.id.strobe_image)).setImageResource(imageStrobe);
((ImageView) v.findViewById(R.id.strobe_image)).setColorFilter(context.getResources().getColor(cardColor));

if (isClickable == true)
((LinearLayout) v.findViewById(R.id.contentLayout))
.setBackgroundResource(R.drawable.selectable_background_cardbank);
((ImageView) v.findViewById(R.id.strobe_image))
.setBackgroundResource(R.drawable.selectable_background_cardbank);
return v;
}
}

In use:

MyStrobeCard normalStrobeCard = new MyStrobeCard(R.string.normal_strobe, R.drawable.play_button, R.color.jays_blue, true);
[Java for Android App Development] Androguide.fr:
Nice, thanks a lot for contributing :good:

Would you mind submitting a pull-request so I can merge this into the lib, please?
[Java for Android App Development] Wetzel402:
It is the least I can do after your help :)

I know this is going to sound dumb but how do I do said pull-request? I assume this would be via Git?
[Java for Android App Development] Androguide.fr:
Sure, just fork it on my github, make your edits, then go back to my repo, click the "Pull requests" thumbnail then hit the "New Pull Request" button ;)
[Java for Android App Development] kshark27:
Seeing the starting Question to be "how to implement Google Play like List View ? " . It was solved by implementing a PlayView by GadgetCheck but still the question that was unanswered was the " Listview actually behaving like the one in Google Play ? ". I believe behavior is as much important to UI as the UI elements so in Google Play the ListView was actually behaving like a GridView that is, it was auto adjusting and adding cards to the ListItem View according to screen orientation and resolution . I found the solution in Bucket List Adapter . I have shown a demo of the UI that can be easily implemented using a Bucket List Adapter by @rzsombor but still i found that bucket list adapter has lots of optimization issues like it lack the ability to recycle views and doesn't have a View Holder patter. It would be super cool if some developers can come up and contribute and help delivering us an optimized version of Bucket List Adapter . It would be an ultimate tool in Android arsenal. Thanks :angel:

Check out the thread and contribute

Play Cards Grid View
[Java for Android App Development] Wetzel402:
I believe that should do it :) Note that my MyStrobeCard class uses a color filter on the image which could easily be removed.

The grid view looks good.
[Java for Android App Development] Androguide.fr:
There is already a multi column implementation in the library (it's based on a FrameLayout instead of GridView), the only thing that doesn't work in it is the stacks, but for the Google Play-like screenshot you posted you can do the exact same thing with the lib in its current state.

It's set to 1 by default, the variable you need to modify is in com/fima/cardsui/views/CardUI.java :

private int mColumnNumber = 1;

You could quite simply make the lib switch from a one column layout on small screens to a multi-column layout on bigger screens with some static method you'd call on your activity's horientation change for example.
[Java for Android App Development] kshark27:
Thanks [MENTION=4752917]Androguide.fr[/MENTION] i will check the library and modify my implementation. :laugh: :angel:
[Java for Android App Development] David 617:
Hey,

First off, great work here. This looks really cool and I'm excited to use it in my app

I'm new to this framework, and I can use a bit of help. First of all I cant seem to create an app and use the cardsUI.

I've tried a bunch of stuff, but I can't seem to get it... I'm probably missing something simple..

Second, I eventually want a UI similar to this.

Am I able to create a card with a share and like button and wire them up to work?

Any help is appreciated.

Thank you so much ;)
[Java for Android App Development] 4bh1nav:
Hey

, Awesome library!
[Java for Android App Development] RED_:
Tried to search the thread but couldn't find a solution. Is there a way I can implement this library with ActionBarSherlock tabs? Right now my classes extend SherlockFragments but the example codes all ask for the classes to extend Card.

I saw the screenshot in the opening post, it shows exactly what I'm after. Down to a tee frankly. The 'picture card' and ActionBarSherlock tabs.
[Java for Android App Development] Androguide.fr:
You're confused, your fragments don't need to extend Card at all, the Cards Objects do though.

Just declare a CardUI inside a LinearLayout in your fragment layout like you would with a TextView or whatever :

i.e: fragment.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.fima.cardsui.views.CardUI
android:id="@+id/cardsui"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />

</LinearLayout>

Then, in your SherlockFragment's onCreate() method, get a reference to this view, create a new instance of the Card Object you want, and add it to the CardUI :

public class YourFragment extends SherlockFragment {

[MENTION=439709]override[/MENTION]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.fragment,
container, false);

CardUI cardsView = (CardUI) ll.findViewById(R.id.cardsui);
MyPlayCard card = new MyPlayCard("Title", "This is a description", "#96AA39", "#33B6EA", false, false);
cardsView.addCard(card, true);
}
}

---------- Post added at 09:42 PM ---------- Previous post was at 09:37 PM ----------

That's most likely because you don't pass your Activity's context to the card's constructor.

You need to change :

public MyTddeCard(String title){
super(title);
}

to

public MyTddeCard(String title, Context context){
super(title, context);
}

And replace all occurences of view.getContext() with the context variable

Also, in the library's com.fima.cardsui.objects.AbstractCard class, add setters and getters for a Context if there isn't already one :

public abstract class AbstractCard {

protected Context context;

public Context getContext() {
return context;
}

public void setContext(Context context) {
this.context = context;
}

}

Finally, in com.fima.cardsui.objects.Card, modify your MyTddeCard's constructor :

public MyTddeCard(String title, Context context) {
this.title = title;
this.context = context;
}

Additionally, I recommend you do the least work possible in the Card, instead, add constructors for everything you need (i.e OnClickListener) and do the actual logic in your Activity or Fragment. This allows you to have much more generic cards that you can re-use for a lot of different purposes.
[Java for Android App Development] RED_:
Thank you kindly. Only started looking at this today so I was definitely confused. Got a basic card working now. Going to try a picture one now in a sec.

Looking at the other guys question that you answered helped too. Looked like I missed some stuff out myself too.
[Java for Android App Development] RED_:
Does this library work with SQLite? My SQLite code works because I can pull information into a TextView but when I try to pull it into a string and then add the string to part of the Card's details I get an error.

MyPlayCard myCard = new MyPlayCard("Title", SQLiteStringHere, "#96AA39", "#33B6EA", false, false);
cardsView.addCard(myCard);

That's what I have. SQLiteString is the description of course. Anyway yeah it doesn't work. Googling or searching this forum didn't come up with anything.

Anyone got any ideas?

EDIT: Fixed it. I'm an idiot. should be (myCard, true);
[Java for Android App Development] Androguide.fr:
Please add the error logcat spits out.

And damn xda for not giving us syntax highlighting in the code tags^^
[Java for Android App Development] Wetzel402:
I added the logcat output to my previous post.

I've noticed that (about the code highlighting). It is odd that XDA of all places doesn't have it. It would make reading everyone's code much easier. :)
[Java for Android App Development] RED_:
Has anyone had memory problems with this library?

I have 30 cards in one activity. They are the cards which have an image with them. The 30 jpgs all add up to 1mb so I don't think that's the issue. It's when I combine them both together that I get the OutOfMemory exception.

Any ideas of how to get around this?
[Java for Android App Development] tmka:
I'm loading15-20 cards with images and haven't had a problem.

Do you mean the jpg file sizes add up to 1 mb or the in-memory bitmaps for them?
[Java for Android App Development] Androguide.fr:
I've been stumbling on this issue too.

I'm working on an app which list youtube videos from a channel and I load the thumbnails with Picasso.

If you scroll up and down too fast it ends up lagging really bad and force closes after a while due to OOM.

I am investigating the issue at the moment, and it seems that the cards's getCardContent() method gets called only once the card becomes visible on screen, and this probably leads to each card being reloaded when we scroll back and forth, consuming a whole lot of memory, especially when the asynchronous loading of an image consumes a new background thread.

-------------------------------------

On a side note, I've merged a very nice pull request a couple weeks ago.

These commits allow to use the library with an MVC (Model-View-Controller) pattern, to serialize cards and to attach any kind of data to any Card instance.

You guys should check it out, huge thanks to @FLamparsky for the pull-request
[Java for Android App Development] RED_:
I managed to reproduce my OOM exception without this library so I think it's a limitation with having many images rather than specifically with this library. I have to find a way around it so I'll keep working on the issue.
[Java for Android App Development] tmka:
I've been looking into it a little too. For what it's worth, I have a version of CardsUI that works with ListView recycling. The downside is that I only have it working for single-card CardStacks. I don't know that recycling really makes sense if you're trying to convert an old 2-card stack into a new 3-card stack or vice versa.

Recycling seems to help a lot but there are still processing spikes when a card comes onscreen. I'm new to Android profiling/etc so I'm not yet sure how much of the time is due to CardsUI and how much is due to the specific cards I'm using.

If you'd like, I can clean up the code some then make a pull request.
[Java for Android App Development] Androguide.fr:
Very nice, view recycling is already at least 50% of the job required to get this sorted out :good:

I'd really like to take a look at your code but I don't want to break multi-card stacks in the mainstream repo, so if you make a pull-request, please make it in a separate branch called "recycling" or whatever.

Otherwise please post a link to your repo.

I believe the processing peeks you see in the profiler when a card appears on screen is due to the CardUI behaviour or calling getCardContent() only once the card is visible on screen.

This will need some refactoring so that the full list gets loaded at once.

That's a possibility as well, but there's definitely something wrong with the library in that with Picasso, the images load only when the cards are on screen, while in a regular listview it loads all the images directly (afaik, didn't test it tbh).
[Java for Android App Development] tmka:
It doesn't break multi card stacks but it just isn't optimized for them. If you want to peek at the code, https://github.com/ktrnka/cardsui-for-android

I could swear I updated the example cards for recycling but I must not have. If you want some examples of how I coded it, take a look at https://github.com/ktrnka/droidling for Interpersonal card or personal card.
[Java for Android App Development] avi.rakesh:
Make one card Swipeable

Hey guys,

Using this library, pretty cool and easy to work with.

Just wanted to ask if there's any way to make one one card swipeable and others unswipeable(if that's a word)?

Nice work with the forks.

Thanks

Avi
[Java for Android App Development] Androguide.fr:
Sorry for the late reply.

Great work, please make a pull-request, I'll merge it :good:

EDIT: I just tested your changes and returning true in the convert() method of the cards completely gets rid of the OOM issue and scrolling is almost perfectly smooth.

You nailed it! :good:

This is currently not doable, only the CardUI view itself can be set to swipeable or not.

You can however cheat a little if you don't need stacked cards by using multiple CardUIs, each containing a single card, this way you can choose which cards you want to be swipeable.
[Java for Android App Development] tmka:
Cool, I'll set that up soon. Another thing I was thinking about is making an abstract class like RecyclableCard that handles inflating or recycling and the implementer would code something like getLayoutId and apply(View). That way the person using the API wouldn't have to do as much work. What do you think?
[Java for Android App Development] Androguide.fr:
Yeah, that could be nice.

However, there's an issue I didn't notice yesterday with the current recycling implementation, the first 5 items or so are repeated over and over instead of having the list properly displaying all its items (i.e my list of 50 youtube videos is made of the same 5 videos repeated 10 times when convert() returns true).

It might just be a matter of setting setHasTransientState(true) on the views, I'll investigate that later today when I got some time.

EDIT: Yeah, that's what I was thinking, setting setHasTransientState(true) on the view in getView(), getViewFirst() and getViewLast() from Card.java does the trick, all the items are now displayed & recycled properly.
[Java for Android App Development] tmka:
I'm not sure I understand transient state. Is it related to onRestoreInstanceState?

Sent the pull request. After I sent it, I realized another thing that might help would be example card layouts that are based on RelativeLayout for a flatter view hierarchy. I've been using RelativeLayout but I didn't profile the change to see if it helped much. Recycling was the biggest change, though I still haven't gotten it entirely below the framerate latency when a card scrolls onscreen.
[Java for Android App Development] Wetzel402:
Androguide.fr,

How does the end user modify the top margin of the first card? Currently my first card touches the actionbar.

I tried modifying setMargins but it had no effect:

public View getViewFirst(Context context) {

View view = LayoutInflater.from(context).inflate(getFirstCardLayout(),
null);

mCardLayout = view;

try {
((FrameLayout) view.findViewById(R.id.cardContent))
.addView(getCardContent(context));
} catch (NullPointerException e) {
e.printStackTrace();
}

// ((TextView) view.findViewById(R.id.title)).setText(this.title);

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int bottom = Utils.convertDpToPixelInt(context, 12);
lp.setMargins(0, 0, 0, bottom);

view.setLayoutParams(lp);

return view;
}

Thank you for the awesome library. :D