Thursday, September 5, 2013

How do you fade in and fade out text in Android?

I had a requirement to make text blink in my Android application.  This came in prety handy:

http://stackoverflow.com/questions/3450839/blinking-text-in-android-view

ViewFlipper is a control available in Android to flip through many controls.  Define all controls within ViewFlipper in layout.  Then call startFlipping() to make ViewFlipper flip.

Now, there is another control called ViewSwitcher.  According to Android docs - "ViewAnimator that switches between two views, and has a factory from which these views are created. You can either use the factory to create the views, or add them yourself. A ViewSwitcher can only have two child views, of which only one is shown at a time."

From what I understand, use ViewSwitcher like you would use themes.  Use ViewFlipper like movie names is displayed in http://www.marcustheatres.com/.

Tuesday, August 20, 2013

My personal Avaniavittam reminders

Avaniavittam is a festival day when we change the sacred thread (poonal).

This time, I had missed a few things and had to get ready quickly.  I thought I would keep a Things to do for my own reference next year.

Week before

  1. Make sure you have
  2. Poonal
  3. Dharbai
  4. Powthiram
  5. Black Sesame
  6. Rice
  7. Sandhyavandhanam book
  8. All mantra details - like greeshma rithu, varsha rithu etc.



Day before

  1. Materials to make vadai and payasam
  2. Vaccum clean the place
  3. Saree for wife
  4. Silk veshti
  5. Alarm



Tuesday, August 13, 2013

The Set

A common pattern in an interview is to ask for a data structure that would store a collection of items.  In Java, there are three types of objects that holds collection of data - Map, Set and List.

Here is a tip that would make sure that you choose an appropriate data type: Set should be your default choice.  A choice for a List should be based on you reasoning yourself out of using a Set.

Why?
Set has this data structure called HashSet.  It is super efficient.  Let us see this table for CURD operations.


HashSetArrayListLinkedList
C - Add to Collection
1
n
1
R - Find in Collection
1
lg n if sorted
n otherwise
n
D - Remove from Collection
1
n remove and move all elements
1 (finding will take n. but removing will be 1)

As you can see, HashSet is super-efficient in all cases.

When should I not use Set?

1. If your collection can allow duplicates
2. If you need to maintain an ordering of some kind.

Always use a Set by default.  Set is wonderful.

Android App not getting published

I created an Android App.  I followed all steps given here

I waited for almost two days.  The App did not get published.  It usually takes 5-24 hrs to get published.

Then I figured out that I had uploaded APKs under Alpha, Beta and Production.  But the App had remained in Alpha.  So, I moved the application to Production.

Here is the screenshot of the page:

Developer Console -> Your App -> APK -> Production tab -> Move to (drop-down)-> Choose Production.

Thursday, August 1, 2013

Android: Wake Up - Mistakes that I made

I had been working on a very simple Android Alarm App.  The users would set up an alarm after certain period of time.  When the time for Alarm arrives, the BroadcastReceiver defined in our application receives a signal.  If the phone is in lock mode, we have to wake the phone up and display to the user that it is time.

To wake the phone up, I am using android.os.PowerManager and PowerManager.WakeLock.

  1. I had tried waking the phone up from inside BroadcastReceiver.  It should be done from Activity's onCreate() method.
  2. The parameters that I passed for getting a new WakeLock were not working right.  In fact, I don't know which is the correct parameter I should use.  I am now using a deprecated parameter which is the only thing that is working for me.  The method is PowerManager'sInstance.newWakeLock().  The first parameter is levelAndFlags - I am using PowerManager.SCREEN_DIM_WAKE_LOCK.  I know I will have to use a combination of different non-deprecated flags.  But, I have not figured it out yet.
  3. Always release the WakeLock in onFinish(), onPause(), onStop() methods.


Thursday, July 11, 2013

HashSet delegates all its functions to HashMap



This is an old one.  In Java, HashSet delegates all its functions to HashMap.

What goes on under the covers of a HashSet<T> is:

  • A member variable, map, of type HashMap<T, Object> is maintained.
  • All operations on HashSet is delegated to a corresponding operation on HashMap - add(), remove(), contains(), etc.
  • A dummy object



add(T objOfTypeT)
Invokes put(objOfTypeT, dummy object)

remove(T objOfTypeT)
Invokes HashMap's remove(objOfTypeT)

size()
returns map's size

contains(T objOfTypeT)
returns map.containsKey(objOfTypeT)

iterator()
returns map's keySet's iterator

Thursday, July 4, 2013

Installing packages from Python

I am new to python.  I am using python 2.7.5.

I was working on writing a screen scrapper for one of my projects.  I am using scrapy framework for screen scrapping.

After setting up and testing my spider, I wanted to test how it could be called from another Python script.  Till this point I had been testing using scrapy's commands.

I looked up online to find an example to call scrapy from another Python script.  Scrapy, it seems, uses a network framework called twisted.  Twisted was not installed in my machine.  So, I proceeded to do a sudo apt-get install python-twisted in my command prompt.  That did not seem to work.

I created a sample twisted script and attempted to run that.  This would help in testing if Python really recognizes Twisted  Obviously, that failed.

So, after a bit of looking around, I stumbled upon this.  Python packages needs to be installed from tar files.  So, download a tar file, un-tar it.  This should create a source directory which is supposed to have a file called setup.py.  To install the package, run python setup.py install 

This is exactly what I did.  I downloaded tar of Twisted from here.  Then un-tar'ed it using tar xjf Twisted-13.1.0.tar.bz2 which created a folder Twisted-13.1.0.  Then changed directory into Twisted-13.1.0 using cd Twisted-13.1.0.  Finally, python setup.py install.  This gave an error.  Twisted required another package called zope.interface.

I downloaded tar of zope.interface from here and then did the above steps first for zop.interface so zope gets installed.  Then proceeded to Twisted-13.1.0 folder to do a python setup.py install in that folder.

So, in general, if you need to install a package in Python, get the tar file and use python install feature on setup.py file of the tar.