Thursday, May 24, 2012

Android Emulator Properties

The downloadable platform includes the following emulator skins:


  • QVGA (240x320, low density, small screen)
  • WQVGA400 (240x400, low density, normal screen)
  • WQVGA432 (240x432, low density, normal screen)
  • HVGA (320x480, medium density, normal screen)
  • WVGA800 (480x800, high density, normal screen)
  • WVGA854 (480x854 high density, normal screen)
  • WXGA720 (1280x720, extra-high density, normal screen)
  • WSVGA (1024x600, medium density, large screen)
  • WXGA (1280x800, medium density, xlarge screen)
To test your application on an emulator that represents the latest Android device, you can create an AVD with the new WXGA720 skin (it's an xhdpi, normal screen device). Note that the emulator currently doesn't support the new on-screen navigation bar for devices without hardware navigation buttons, so when using this skin, you must use keyboard keys Home for the Home button, ESC for the Back button, and F2 or Page-up for the Menu button.
However, due to performance issues in the emulator when running high-resolution screens such as the one for the WXGA720 skin, we recommend that you primarily use the traditional WVGA800 skin (hdpi, normal screen) to test your application.

Wednesday, May 9, 2012

Simple Calendar control android


Hi developers, here the example for simple calendar control in android.

CalendarActivity .java


public class CalendarActivity extends Activity
{
 private EditText Calctrl;
 static final int DATE_DIALOG_ID = 0;
 final Calendar c = Calendar.getInstance();
 private int mYear, mMonth, mDay;
 private String sdate;
 private String[] arrayMonth = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Calctrl = (EditText) findViewById(R.id.datepicker);
   mYear = c.get(Calendar.YEAR);
   mMonth = c.get(Calendar.MONTH);
   mDay = c.get(Calendar.DAY_OF_MONTH);
   sdate = currentDate(mYear, mMonth, mDay);
  Calctrl.setText(sdate);  

  Calctrl.setOnTouchListener(new OnTouchListener()
  {
   @Override
   public boolean onTouch(View v, MotionEvent event)
   {
    showDialog(DATE_DIALOG_ID);
    return true;
   }
  });
 }

 @Override
 protected Dialog onCreateDialog(int id)
 {
  switch (id)
  {
  case DATE_DIALOG_ID:
   return new DatePickerDialog(this, mDateSetListener, mYear, mMonth,mDay);
  }
  return null;
 }

 @Override
 protected void onPrepareDialog(int id, Dialog dialog)
 {
  switch (id)
  {
  case DATE_DIALOG_ID:
   ((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
   break;
  }
 } 

 private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener()
 {
  public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth)
  {
   mYear = year;
   mMonth = monthOfYear;
   mDay = dayOfMonth;
   String sdate = currentDate(mYear, mMonth, mDay);
   Calctrl.setText(sdate);
  }
 };

 private static String LPad(String schar, String spad, int len)
 {
  String sret = schar;
  for (int i = sret.length(); i < len; i++)
  {
   sret = spad + sret;
  }
  return new String(sret);
 }

 private String currentDate(int year, int month, int day)
 {
  String sdate = arrayMonth[month] + " " + LPad(day + "", "0", 2) + ", "+ year;
  return sdate;
 }
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/app_background"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/datepicker"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:editable="false"
        android:inputType="none" />

</LinearLayout>


Android Layout Background Issue


First of all, make sure that your original image looks good so you're not just getting the problem from there.
Then, in your onCreate() method, do:
code1:
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) add the following where you load your views:

code2:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options);

findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));

Comparison between different approaches: (these are all screenshots from the resulting application)
My source images (64 colors to the left, 24 bit to the right):
image1 and image2:
64-color24 bit
1: Raw 64-color image (image1) set as background from layout XML:
Raw image
2: The same image (image1), using code1:
Dithered image
3: The same image (image1) using both code1 and code2:
explicit 32bit
4: image2, loaded with code1 and code2 (in this case the dithering is not really important as both the source and destination use 8 bits per color):
higher original quality
Notice how the resulting artifacts in image 3 already exists in the original image.