Tuesday, January 28, 2014

Splash Screen flicker on Titanium (TiRootViewController)

While developing an iOS application I had a problem with splash screen which flickers for a certain instance.After searching and posting questions on forum I didn't succeed,so I have to edit the TiRootViewController.


    if([TiUtils isIOS7OrGreater])
    {
        CGRect testFrame = [[UIScreen mainScreen] applicationFrame];
        testFrame.origin.y = -20;
        testFrame.size.height = testFrame.size.height+40;
        newFrame = testFrame;
    }else
    {
        if ((imageSize.width == newFrame.size.width))
        {
            CGFloat overheight;
            overheight = imageSize.height - newFrame.size.height;
            if (overheight > 0.0) {
                newFrame.origin.y -= overheight;
                newFrame.size.height += overheight;
            }
        }
    }

 [defaultImageView setContentMode:contentMode];
 [defaultImageView setImage:defaultImage];
 [defaultImageView setFrame:newFrame];

Thursday, February 14, 2013

Android Custom TimePickerDialog

Yesterday we are facing issues regarding the Custom TimePickerDialog,our main requirement was adjustment in minute field of TimePickerDialog as per user requirement.And here is our solution.



import java.util.Calendar;

import android.app.Activity;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TimePicker;

public class MainActivity extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }

 public void timeAction(View v) {
  CustomTimePickerDialog timePickerDialog = new CustomTimePickerDialog(
    this, timeSetListener, Calendar.getInstance()
      .get(Calendar.HOUR),
    CustomTimePickerDialog.getRoundedMinute(Calendar.getInstance()
      .get(Calendar.MINUTE)
      + CustomTimePickerDialog.TIME_PICKER_INTERVAL), false);
  timePickerDialog.setTitle("2. Select Time");
  timePickerDialog.show();
 }

 private CustomTimePickerDialog.OnTimeSetListener timeSetListener = new CustomTimePickerDialog.OnTimeSetListener() {
  @Override
  public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

  }
 };// using CustomTimePickerDialog
}

class CustomTimePickerDialog extends TimePickerDialog {
 public static final int TIME_PICKER_INTERVAL = 15;
 private boolean mIgnoreEvent = false;

 public CustomTimePickerDialog(Context context, OnTimeSetListener callBack,
   int hourOfDay, int minute, boolean is24HourView) {
  super(context, callBack, hourOfDay, minute, is24HourView);
 }
 @Override
 public void onTimeChanged(TimePicker timePicker, int hourOfDay, int minute) {
  super.onTimeChanged(timePicker, hourOfDay, minute);
  this.setTitle("2. Select Time");
  if (!mIgnoreEvent) {
   minute = getRoundedMinute(minute);
   mIgnoreEvent = true;
   timePicker.setCurrentMinute(minute);
   mIgnoreEvent = false;
  }
 }

 public static int getRoundedMinute(int minute) {
  if (minute % TIME_PICKER_INTERVAL != 0) {
   int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL);
   minute = minuteFloor
     + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0);
   if (minute == 60)
    minute = 0;
  }
  return minute;
 }
}

Android Scheduler based 12AM(Daily)

The concept of BroadcastReceiver is some what which very important for event driven app and it help us a lot its pure object oriented nature is really helpful.Here is small snipped for a small scheduler using BroadcastReceiver.

 import android.os.Bundle;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

public class MainActivity extends Activity {
 static IntentFilter mIntentFilter;
 static {
  mIntentFilter = new IntentFilter();
  mIntentFilter.addAction(Intent.ACTION_DATE_CHANGED);
 }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  registerReceiver(mDateReceiver, mIntentFilter);   
 }
 private final BroadcastReceiver mDateReceiver = new BroadcastReceiver() {
  @Override
  public void onReceive(Context context, Intent intent) {
   scheduleTask();
  }
  private void scheduleTask() {
   Log.i("scheduleTask", "scheduleTask");
  }
 };
}

Wednesday, February 13, 2013

Accessing the Inaccessibles

Today we faced some strange problem where we need DatePicker from DatePickerDialog,our main goal was perform some DatePicker level operation,as we need to override the OnTimeChangedListener.

After some discussion about the possible solution we come across suggested solution such as Custom TimePicker Dialog etc.

But at last we strict to basics.In that moment Java Reflection come to rescue us.And here is our solution.

 
import java.lang.reflect.Field;
import java.util.Calendar;
import android.app.Activity;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.view.View;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.TimePicker.OnTimeChangedListener;

public class MainActivity extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 }
 public void validateAction(View v) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
  showFromPicker();
 }
 private void showFromPicker() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
  Calendar cr = Calendar.getInstance();
  cr.set(Calendar.HOUR_OF_DAY, 12);
  cr.set(Calendar.MINUTE, 45);
  TimePickerDialog picker = new TimePickerDialog(this,
    timeFromPickerListener, cr.get(Calendar.HOUR_OF_DAY),
    cr.get(Calendar.MINUTE), false);
  Field timePickerField = picker.getClass().getDeclaredField("mTimePicker");
  timePickerField.setAccessible(true);
  TimePicker timePicker = (TimePicker) timePickerField.get(picker);
  timePicker.setOnTimeChangedListener(new OnTimeChangedListener() {   
   @Override
   public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
    Toast.makeText(MainActivity.this, "Mamo", Toast.LENGTH_SHORT).show();
   }
  });
  picker.show();
 }
 OnTimeSetListener timeFromPickerListener = new OnTimeSetListener() {
  @Override
  public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
  }
 };
}

Wednesday, February 6, 2013

Wi-Fi Direct in Android

Network base application development is uphill due to its distributed and versatile where are communicating with different devices over different media.We have to very careful about states of each node or device.Our client and server sockets should intelligent enough to handle all unexpected situations.While creating such intelligent client-server model we should be careful about resources as alway IO operations need lot resources.

This situation get worst in case mobile where limited incase memory , processor and power supply.To overcome all these challenges Android came up something very special i-e Wi-Fi Direct.Which is very close to Android Standard model.Where all the socket or low level complexities are hidden from developer.



Monday, October 22, 2012

Performance Evaluation of various Java CSV Parsers

Today I have asked one of my friend to conduct a survey on various Java CSV parser and compare their result,so here are some interesting result.

For survey we have used CSV file containing of more than 4 thousand records

Courtesy Zia

Tuesday, April 24, 2012

Hashmap vs LinkedHashMap

During development of one my project I got confused and annoyed,I was displaying the contents of Hashmap,I was amazed to see the order in which the contents were displayed.
After hours of brain-storming I came to conclusion that there is no guarantee of elements on Hashmap.Here are there few conclusion I had found.

A LinkedHashMap differs from HashMap in that the order of elements is maintained.
A HashMap has a better performance than a LinkedHashMap because a LinkedHashMap needs the expense of maintaining the linked list. The LinkedHashMap implements a normal hashtable, but with the added benefit of the keys of the hashtable being stored as a doubly-linked list.
Both of their methods are not synchronized.
Let's take a look their API documentations:

The HashMap is a hash table with buckets in each hash slot. Like in the API documentation:

This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.

The LinkedHashMap is a linked list implementing the map interface. As said in the API documentation:

Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).