Android – Sliding overlay

Standard

While, I was working on one of the Android App, I needed a layout which offers overlay layer and provides a semi-transparent effect to view controls beneath it. In addition to the look & feel, I was also looking for a smooth transition effect to bring overlay in the view. It should also offer responsive touch to slide it out. The requirement seems to be very simple and my hunt began to implement such control. While I could able to locate many references for transition effect, none of them were perfect and had some flaws in it. The major flaw, I noticed with the implementation was that – Once an overlay view is displayed, sliding it to the right, will sometimes cause controls beneath it receiving events and yielding weird results. The rationale behind it was simple, the usage of setOnTouchListener doesn’t provide enough control over the touch lifecycle of a control and hence the touch event was getting leaked to the controls, visible one layer below.
Continue reading

Extract app icon in Android

Standard

Android has been on my radar for a long time, but I could never proceed with simple hello world program and few basic stuffs. From last couple of months, I have been working with both Hybrid and Native application development for Android. The experience has been enriching as I have explored lot of things in Android App Development. There are still few areas (testing, automation, profiling, game development etc.) that yet to be discovered. While developing one of the functionality, I came across a strange problem. The need was to extract an icon of any installed app and store it. Later the extracted icons must be displayed in GridView for user actions. I started using following code, to extract and save the icon

Drawable appIcon = packageManager.getApplicationIcon("com.xyz.mobile.app");
BitmapDrawable bitmapIcon = (BitmapDrawable)appIcon;
FileOutputStream fosIcon = context.openFileOutput(packageName + ".png", Context.MODE_PRIVATE);
bitmapIcon.getBitmap().compress(Bitmap.CompressFormat.PNG, 100, fosIcon);
//flush stream... close stream...

Continue reading