ListView with expandable groups (categories)

English: Food2u running on an Android phone. E...

English: Food2u running on an Android phone. Español: Food2u funcionando en un teléfono Android. (Photo credit: Wikipedia)

Discovery one for today: setting table id as  autoincrement crashes code.  According to docs if field is declared as primary key it will autoincrement by itself. I wonder, why did they decide to crash it, they could have ignored the key word. Anyhow.

The next task is to create categories for input. Design considerations:

Input will be dropdown in the Edit screen with predefined enums. How would I show groups on a front screen? List with categories would be nice.  I’d   to reserve tabs for implementation of multi users.

Let’s explore lists with categories.

There is ExpandableListView

Replaced my old

<ListView
android:id=”@android:id/list”
android:layout_width=”match_parent”
android:layout_height=”289dp” >
</ListView>

with

<ExpandableListView
android:id=”@android:id/list”
android:layout_width=”match_parent”
android:layout_height = “match_parent”
android:background=”#00FF00″
android:layout_weight=”1″
android:drawSelectorOnTop=”false”>
</ExpandableListView >

I have to replace ListAdapter with ExpandableListAdapter in java code. reading http://developer.android.com/reference/android/widget/SimpleExpandableListAdapter.html

This example seems to be what I need

http://www.edumobile.org/android/android-game-programming/simple-expandable-list-example/

Lunch stop. Stuck on creating this adapter. WTF is groupFrom and groupTo?

After 2 h successfully implemented expandable adapter. Took while to understand what these maps are but I got it!

After my expandable list started to work each time keyboard comes up at a startup. Found a fix by adding this line to manifest as property of this activity  android:windowSoftInputMode=”stateHidden”.

And

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); or

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Tomorrow is all about stabilization.

Other generally useful

http://developer.android.com/distribute/googleplay/publish/preparing.html

Found info on testing . people say  You should have three (3) different devices:
1. One mobile phone (small screen) with Android 2.3 (e.g. HTC Wildfire)
2. One mobile phone (small screen) with Android 4.0+ (e.g. Samsung galaxy s3, s4)
3. One tablet (big screen > 7”) (e.g. Samasung galaxy Note 10.1)

ANother example of expandable list adapter but even less understandable

Save Bitmap for a future use in the application

Hello again.

Now we learned how to create an image, show thumbnail in the app and zoom it out.  Next step I have to save this image (bitmap) somewhere so that app can use it. Normally in enterprise application this would be saved in Oracle database under another table with userId and itemId. I am tempted to create a new table in SQLite and link it with other tables. Before going for it let’s explore if better alternative exists for android. I am hoping for ability to save image  using content provider and stick URI into my table for allergen descriptors.

What people say..

Uri.fromFile(new File(Environment.getExternalStorageDirectory(), “your_file_name”)))

Save ringtone to sdcard:http://www.stealthcopter.com/blog/2010/01/android-saving-a-sound-file-to-sd-from-resource-and-setting-as-ringtone/ This is asking for a specific folder name on sd card. How do I know if card exists.. and what folders already are there.  They create a folder if it doesn’t exists. Maybe.

This seems more hopeful http://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database  But people say that saving images in SQLite is not a good practice.

This has code for downloading stream and saving into file. Bit I don’t have stream. How would I make a stream out of bitmap?

Going with SQLite database solution though it’s not a good practice I only have few images.

Next issue: database model planning. I already have couple tables. And I had 4 tables in a previous app. Will try to organize it more efficient but prevent complex queries.

Spent 4-6 hours refactoring so I track items by id and can translate individual items not lists. This was my smart caching task. Almost done need more verifications and bugfixes.

I have now images table that are id’ed by group id. Can be saved/restored as byte[]. Still debugging, zoom is not working after a round trip to a database.

Have to finish this before noon.  Next will be drop down for categories, I never did dropdown menus.

 

 

Thumbnail Images and zoom window

My customer asked to be able to take photos and place 2-3 images into a drill down screen.

How do I do that? no idea.

Started with adding 2 ImageView as containers.

Reading how to use camera in the app. http://developer.android.com/training/camera/photobasics.html

 <uses-feature android:name="android.hardware.camera" />

This post has lot of useful info and code

http://stackoverflow.com/questions/2507898/how-to-pick-an-image-from-gallery-sd-card-for-my-app-in-android

I was able to add ImageView and respond to OnClick. It goes now to my gallery and I can pick an image. Then icon is created and displayed ib my Image View. However I can’t enlarge it.

Reading how to zoom an image. And I need to respond to multitouch ( for zoom)

I didn;t find info about capturing multi-touch. Instead I remembered Chase app that makes people take photos.

Found code that allows selecting from Gallery instead of taking photos. Ok for now.

Found code http://developer.android.com/training/camera/cameradirect.html for zoom. Went with this one and it works. 22:52 pm.

Result: I have two areas inside of Relative Layout. One for MedsBottle and one for Rx.  Two Linear Layouts each with textView, button and ImageView. Also one ImageView outside of LinearLayout will be used as zoom window.

Text is for explanations. Button triggers selecting from gallery. Click on image brings up animation with zoom.

Problems (to do tomorrow) (1)selecting second time barfs out.(2)Turning device loses images. (3)Images are not saved in a database. Enable to save and view later (4) try to take picture rather than select from gallery.

 

 

 

 

additional info that could become useful

Icon templates and guidelines:

http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-icon-design/

Providing alternate resources for other screen sizes:

http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

Language translation APIs

Looking for free alternatives to google translation APIs.

Google translation service is great but it’s a paid service. Today I am looking for free alternatives.

Yandex.ru. Easy to integrate, functional. However this service supports limited set of languages and some languages don’t work and for some languages I encountered exceptions on translating some words, not very complex words.

Extended info on google translate

echo GoogleTranslate::staticTranslate("Hello again", "en", "ka");

Found a post on stackoverflow recommending to look into these, no info if they are free or functional.

Alternatives to Google Translate API:

Microsoft Translator APIs this guy is talking about it with a bit of incomplete example: http://web.archive.org/web/20110720142541/http://basharkokash.com/post/2010/04/19/Bin g-Translator-for-developers.aspx

————
Speaklite Translate API – http://www.speaklike.com/plans/ this is 6 cents per word. REST interface
WebServiceX Translate API  – limited set of languages. SOAP interface.

——–

MyGengo  – http://gengo.com/pricing-languages/ This is super expensive. priced per word, no free nothing.

——

http://www.translatorbox.com/google-text-translator-alternative-for-wordpress/ – nonsense. exposes a box for use in web apps.

———————-

MyMemory translation: http://mymemory.translated.net/api/get?q=Hello World!&langpair=en|it

You can find the API docs here: http://mymemory.translated.net/doc/spec.php Free use is limited to 100 requests/day. 

—————-

Summary: no good. will have to pay google translation or pre-build my cache.