Post Top Ad

September 13, 2014

Optical Character Recognition (OCR)


For the 3rd year SEP project we  had to create a management dashboard. The requirement was the management  dashboard should give you the high level over view of the existing system. so there i wanted to read existing data of the repots and show them in the dashboard. I achieved using OCR technology. 

Requirements

This solution requires that you have Microsoft Office 2003 or above  installed. Since office 2010 do not support this method you will need to have previous version of office packages installed.  Office has included a library called, Microsoft Office Document Imaging, (MODI . The dll file what we really needs to reference from our code is called MDIVWCTL.DLL. 
And also this library needs to be installed in any client machine, if we want to use the office document imaging facilities to do the OCR functionality

Assumptions

Here, we’ll assume that you already have an Image to work with. we need a area where we want to extract the image details and show them in the dashboard so lets take values as X1, Y1, X2, Y2. Let the (X1,Y1) be the top left corner of the area, and that (X2, Y2)  be the  right corner of the area.

How solution Works

  private void btn_View(object sender, RoutedEventArgs e)
    {
        string result = "";
        Bitmap b = new Bitmap("..\\..\\Priyankara\\testBMP.jpeg");

        //calling Extract method
        // var newBmp = Extract(b , 1, 88, 290, 126);
        Bitmap newBmp = Extract(b, 816, 584, 1161, 612);
        if (newBmp == null)
        {
            result = string.Empty;
        }
        else
        {
            String tempFile = CreateTempFile(newBmp);
            result = OcrTempFile(tempFile);


            TextWriter tsw = new StreamWriter(@"..\\..\\Priyankara\\xmlWriter.txt"); // true without overriting


            //Writing text to the file.
            tsw.WriteLine(result);


            //Close the file.
            tsw.Close();
          //  MessageBox.Show("File written Successfully");


        }

        //converting text File to XML

        String[] data = File.ReadAllLines(@"..\\..\\Priyankara\\xmlWriter.txt");
             XElement root = new XElement("orders",
                                        from item in data
                                        select new XElement("Values", item));
             root.Save(@"..\\..\\Priyankara\\xmlWriter.xml");

        //Loading text File

             XDocument xmlDoc = XDocument.Load(@"..\\..\\Priyankara\\xmlWriter.xml");
             String[] test = xmlDoc.Descendants("orders").Elements("Values").Select(r => r.Value).ToArray();
             String result1 = string.Join("|", test);

            

             string fullName = result1;
             var names = fullName.Split('|');
             string firstName = names[0];
            string lastName = names[1];
            string ccc = names[2];
       // TextBox1.t
             txtUsername.Text = names[0];
             txtUsername1.Text = names[1];
             txtUsername2.Text = names[2];
          //  MessageBox.Show(ccc);

        // Early
        //string[] letters = result.Select(c => c.ToString()).ToArray();

        //textBox1.Text = Convert.ToString(result[0]);       

        }

        //Extracting part of the image
        Bitmap Extract(Bitmap bmp, int x1, int y1, int x2, int y2)
        {
            try
            {
                int width = x2 - x1;
                int height = y2 - y1;
                if (bmp == null || width < 1 || height < 1)
                {
                    return null;
                }
                Bitmap subImage = bmp.Clone(new System.Drawing.Rectangle(x1, y1, width, height), bmp.PixelFormat);
                return subImage;
            }
            catch
            {
                return null;
            }
        }

        // save the newly created image into a temp file.
        private string CreateTempFile(Bitmap img)
        {
            String fId = Guid.NewGuid().ToString("N");
            String path = string.Format("{0}{1}.tiff", System.IO.Path.GetTempPath(), fId);
            img.Save(path, ImageFormat.Tiff);
          //  Globals.TempFiles.Add(path);
            return path;
        }

     // read the data from the image.
        [HandleProcessCorruptedStateExceptions]
        string OcrTempFile(string path) {
            try {

                MODI.Document Modi = new MODI.Document();
                Modi.Create(path);
                Modi.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
                MODI.Image img = (MODI.Image)Modi.Images[0];
                MODI.Layout layout = img.Layout;
                String str = layout.Text;
                Modi.Close();
                return str.Trim();

            } catch
            {
                return string.Empty;
            }
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

        }


September 13, 2014

How to send GPS cordinates from android app to web server

First of all this is my solution for a one of my SE project @ SLIIT. 

Here this solution sends the gps cordinaes of the users location in to the server and the server will be abele to capture the signels and show them in the defined page.

Later we can manipulate these data in the server and display them in a separate place. Ex: a dashboard



LocationGPSTrackerActivity class 

This class checkes wheter the network is availabale and the gps is working corretly in the device. if not it will
display on screen messages based on the results

public class LocationGPSTrackerActivity extends Activity implements LocationListener {

    private final static String CONNECTIVITY = "android.net.conn.CONNECTIVITY_CHANGE";

    private LocationManager locationManager;
    private ConnectivityManager connectivityManager;

    SharedPreferences preferences;
    private EditText edit_url;
    private TextView text_gps_status;
    private TextView text_network_status;
    private ToggleButton button_toggle;
    private TextView text_running_since;

    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(LocationGPSTrackerService.NOTIFICATION)) {
                updateServiceStatus();
            }
            if (action.equals(CONNECTIVITY)) {
                updateNetworkStatus();
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gpstracker);

        edit_url = (EditText)findViewById(R.id.edit_url);
        text_gps_status = (TextView)findViewById(R.id.text_gps_status);
        text_network_status = (TextView)findViewById(R.id.text_network_status);
        button_toggle = (ToggleButton)findViewById(R.id.button_toggle);
        text_running_since = (TextView)findViewById(R.id.text_running_since);

        preferences = PreferenceManager.getDefaultSharedPreferences(this);
        if (preferences.contains("URL") && ! preferences.getString("URL", "").equals("")) {
            edit_url.setText(preferences.getString("URL", getString(R.string.hint_url)));
            edit_url.clearFocus();
        } else {
            edit_url.requestFocus();
        }
        edit_url.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                SharedPreferences.Editor editor = preferences.edit();
                editor.putString("URL", s.toString().trim());
                editor.commit();
            }
        });
       
        registerReceiver(receiver, new IntentFilter(LocationGPSTrackerService.NOTIFICATION));
        registerReceiver(receiver, new IntentFilter(LocationGPSTrackerActivity.CONNECTIVITY));
       
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

        int pref_gps_updates = Integer.parseInt(preferences.getString("pref_gps_updates", "30"));   
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, pref_gps_updates * 1000, 1, this);
    }

    @Override
    public void onResume() {
        super.onResume();

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            onProviderEnabled(LocationManager.GPS_PROVIDER);
        } else {
            onProviderDisabled(LocationManager.GPS_PROVIDER);
        }

        updateNetworkStatus();
       
        updateServiceStatus();
    }


private void updateServiceStatus() {
       
        if (LocationGPSTrackerService.isRunning) {
            Toast.makeText(this, getString(R.string.toast_service_running), Toast.LENGTH_SHORT).show();
            button_toggle.setChecked(true);
            text_running_since.setText(getString(R.string.text_running_since) + " "
                    + DateFormat.getDateTimeInstance().format(LocationGPSTrackerService.runningSince.getTime()));
        } else {
            Toast.makeText(this, getString(R.string.toast_service_stopped), Toast.LENGTH_SHORT).show();
            button_toggle.setChecked(false);
            if (preferences.contains("stoppedOn")) {
                long stoppedOn = preferences.getLong("stoppedOn", 0);
                if (stoppedOn > 0) {
                    text_running_since.setText(getString(R.string.text_stopped_on) + " "
                            + DateFormat.getDateTimeInstance().format(new Date(stoppedOn)));
                } else {
                    text_running_since.setText(getText(R.string.text_killed));
                }
            }
        }
    }
   
    private void updateNetworkStatus() {
        NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
        if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
            text_network_status.setText(getString(R.string.text_network_status_enabled));
            text_network_status.setTextColor(Color.BLACK);
        } else {
            text_network_status.setText(getString(R.string.text_network_status_disabled));
            text_network_status.setTextColor(Color.RED);
        }
    }
    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        locationManager.removeUpdates(this);
        unregisterReceiver(receiver);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menue, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent i;
        switch (item.getItemId()) {
        case R.id.menu_settings:
            i = new Intent(this, LocationGPSTrackerPrefs.class);
            startActivity(i);
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    public void onToggleClicked(View view) {
        Intent intent = new Intent(this, LocationGPSTrackerService.class);
        if (((ToggleButton) view).isChecked()) {
            startService(intent);
        } else {
            stopService(intent);
        }
    }

    @Override
    public void onLocationChanged(Location location) {
    }

    @Override
    public void onProviderDisabled(String provider) {
        text_gps_status.setText(getString(R.string.text_gps_status_disabled));
        text_gps_status.setTextColor(Color.RED);
    }

    @Override
    public void onProviderEnabled(String provider) {
        text_gps_status.setText(getString(R.string.text_gps_status_enabled));
        text_gps_status.setTextColor(Color.BLACK);
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }

}

LocationGPSTrackerService

This class is used to display tracking details on the tracker app and to call the LocationGPSTrackerRequest class to open a Http request to the server

public class LocationGPSTrackerService extends IntentService implements LocationListener {

    public static final String NOTIFICATION = "com.example.testmapv2";

    public static boolean isRunning;
    public static Calendar runningSince;
    public Calendar stoppedOn;

    private final static String MY_TAG = "LocationGPSTrackerService";
   
    private SharedPreferences preferences;
    private String urlText;
    private LocationManager locationManager;
    private int pref_gps_updates;
    private long latestUpdate;
    private int pref_max_run_time;

    public LocationGPSTrackerService() {
        super("LocationGPSTrackerService");
    }
   
    @Override
    public void onCreate() {
        super.onCreate();       
        Log.d(MY_TAG, "in onCreate, init GPS stuff");
       
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            onProviderEnabled(LocationManager.GPS_PROVIDER);
        } else {
            onProviderDisabled(LocationManager.GPS_PROVIDER);
        }
       
        preferences = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong("stoppedOn", 0);
        editor.commit();
        pref_gps_updates = Integer.parseInt(preferences.getString("pref_gps_updates", "30"));
        pref_max_run_time = Integer.parseInt(preferences.getString("pref_max_run_time", "24"));
        urlText = preferences.getString("URL", "");
        if (urlText.contains("?")) {
            urlText = urlText + "&";
        } else {
            urlText = urlText + "?";
        }
       
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, pref_gps_updates * 1000, 1, this);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.d(MY_TAG, "in onHandleIntent, run for maximum time set in preferences");
        new LocationGPSTrackerRequest().execute(urlText + "tracker=start");
               
        isRunning = true;
        runningSince = Calendar.getInstance();
        Intent i = new Intent(NOTIFICATION);
        sendBroadcast(i);
   
        Notification notification = new Notification(R.drawable.ic_launcher, getText(R.string.toast_service_running), System.currentTimeMillis());
        Intent notificationIntent = new Intent(this, LocationGPSTrackerActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.toast_service_running), pendingIntent);
        startForeground(R.id.logo, notification);
               
    }
   
    @Override
    public void onDestroy() {
        // destroy when user clicked the stop button or maximum run time has been reached
        Log.d(MY_TAG, "in onDestroy, stop listening to the GPS");
        new LocationGPSTrackerRequest().execute(urlText + "tracker=stop");
       
        locationManager.removeUpdates(this);
       
        isRunning = false;
        stoppedOn = Calendar.getInstance();
       
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong("stoppedOn", stoppedOn.getTimeInMillis());
        editor.commit();
       
        Intent intent = new Intent(NOTIFICATION);
        sendBroadcast(intent);
    }

    @Override
    public void onLocationChanged(Location location) {
        Log.d(MY_TAG, "in onLocationChanged, latestUpdate == " + latestUpdate);
       
        if ((System.currentTimeMillis() - latestUpdate) < pref_gps_updates*1000) {
            return;
        } else {
            latestUpdate = System.currentTimeMillis();
        }
       
        new LocationGPSTrackerRequest().execute(urlText + "lat=" + location.getLatitude() + "&lon=" + location.getLongitude());
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}

 Sending Http request to the server

 public class LocationGPSTrackerRequest extends AsyncTask<String, Void, Void> {
    private final static String MY_TAG = "LocationGPSTrackerRequest";
  
    protected Void doInBackground(String... urlText) {
        try {
            URL url = new URL(urlText[0]);  
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000 );
            conn.setConnectTimeout(15000 );
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            conn.connect();
            int response = conn.getResponseCode();
            Log.d(MY_TAG, "HTTP request done : " + response);
          
        } catch (Exception e) {
            // whrn network down
            Log.d(MY_TAG, "HTTP request failed");
        }
        return null;
    }
}







July 22, 2014

Android Google Maps Chapter 2

This is the second chapter about creating a android google map with google map api v2




In the previous chapter i have explained about main layout file and the manifest file to load a map inside the emulator. Now this chapter will explain about the main activity of the map.

public class MainActivity extends FragmentActivity {
   
    private static final int GPS_ERRORDIALOG_REQUEST = 9001;
    private GoogleMap mMap;
    private static final double SEATTLE_LAT = 6.939378, // if you want to enable satellite views
            SEATTLE_LNG = 79.840336;
        //    SYDNEY_LAT =  ;
        //    SYDNEY_LNG = 151.20699,
        //    NEWYORK_LAT = 40.714353,
        //    NEWYORK_LNG = -74.005973;
    private static final float DEFAULTZOOM = 7; // to set the zoom level

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        if (servicesOK()) {
            setContentView(R.layout.activity_main);
       
            if (initMap()) {
                Toast.makeText(this, "Ready to map!", Toast.LENGTH_SHORT).show();
            //    gotoLocation(SEATTLE_LAT, SEATTLE_LNG,DEFAULTZOOM);
                mMap.setMyLocationEnabled(true); 
            }
            else {
                Toast.makeText(this, "Map not available!", Toast.LENGTH_SHORT).show();
            }
        }
        else {
            setContentView(R.layout.activity_main);
        }
             mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
//        if(mMap!=null)
//            mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
       
    }

    private void hideSoftKeyboard(View v) {
        InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
   
    public void geoLocate(View v){ //Geocoder may return IOException
        hideSoftKeyboard(v);

        EditText et = (EditText) findViewById(R.id.editText1);
        String location = et.getText().toString();

        try {
            Geocoder gc = new Geocoder(this); //    when you search you will get back a java list
            List<Address> list = gc.getFromLocationName(location, 1); // Address is Android thing
            //getFromLocationName is a method of Geocoder class
            // i only want a single  item
            Address add = list.get(0); // give me the first and only item in the list
            String locality = add.getLocality();
           
            Toast.makeText(this, locality, Toast.LENGTH_LONG).show(); // To check whether Geocoder  is working or not
            //Toast.makeText(this, locality, Toast.LENGTH_LONG).show();

/*    double lat = add.getLatitude();
            double lng = add.getLongitude();

            gotoLocation(lat, lng, DEFAULTZOOM);
*/
        } catch (IOException e) {

            Log.d("EXCEPTION:", "Failed to do something: " + e.getMessage());
            Log.d("EXCEPTION: " + method,  message);
        }
    }
   
    private void gotoLocation(double lat, double lng,float zoom) {
        LatLng ll = new LatLng(lat, lng);
        CameraUpdate update = CameraUpdateFactory.newLatLngZoom(ll, zoom);
        mMap.moveCamera(update);
       
    }
   
    public boolean servicesOK() {
        int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
       
        if (isAvailable == ConnectionResult.SUCCESS) {
            return true;
        }
        else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
            dialog.show();
        }
        else {
            Toast.makeText(this, "Can't connect to Google Play services", Toast.LENGTH_SHORT).show();
        }
        return false;
    }
   
    private boolean initMap() {
        if (mMap == null) {
            SupportMapFragment mapFrag =
                    (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            mMap = mapFrag.getMap();
        }
        return (mMap != null);
    }
   

    private void messageBox(String method, String message)
    {
        Log.d("EXCEPTION: " + method,  message);

        AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
        messageBox.setTitle(method);
        messageBox.setMessage(message);
        messageBox.setCancelable(false);
        messageBox.setNeutralButton("OK", null);
        messageBox.show();
    }

// if you want to load different map versions according to user selection

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.mapTypeNone:
            mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
            break;
        case R.id.mapTypeNormal:
            mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
            break;
        case R.id.mapTypeSatellite:
            mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
            break;
        case R.id.mapTypeHybrid:
            mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            break;
        default:
            break;
        }
        return super.onOptionsItemSelected(item);
    }
}

Most probably when you run this code you will not see any output in the default android emulator and it will ask to update google play services. The simple answer for this problem is to try and run your map using a mobile phone. otherwise you can use install the google play services into your android emulator which shoud be done in a simple work around.
July 21, 2014

How to change the name of an iOS app?

Once, I began an iPhone project with a dummy development code name, and then I wanted to change the name of the project since its nearly finished. But I was not sure how to do this with Xcode, trying the obvious of changing the application's name in the pinfo, causes the signing process to go wrong  and my app didn't launch giving me a Launcher error.

I thought of making a  new project and copy paste everything over, but it seemed so primitive.Finally i found the solution after trying different ways.

Here are the steps to follow.
  1. Go to Targets in Xcode
  2. "Get Info" on your project's target (your current dummy development name)
  3. Search for "Product Name" under "Packaging". Change the value of that what you want the new program name is going to be.
June 20, 2014

Temporarily disable Eclipse plugin

For my friends project i wanted to restart eclipse plugin disabled so that it is possible to understand whether plugins cause the problems in the code. So i hare post that tip and hope someone would save there time finding bugs with plugins.

Some plugins allow controlling their load-on-startup behavior. These will be listed in the preferences, under General → Startup and Shutdown. If the plugin provides view, you will need to close those views (in all perspectives) for this to work.

You can simply uptick and select only the necessary plugins to be loaded.

June 16, 2014

Install Google Play on Genymotion 2.0

So the new Genymotion 2.0 no longer comes with Google API’s and for me that just a buzz kill and I admit I have enjoyed the luxuries of having the Play Store in my virtual devices. So I have a solution for you!

In Genymotion create a new device. In my test case I created a
Nexus One – 4.3 – API 18 480×800
Download  Google Apps zip file. For my virtual device I used the latest Universal package ( 20130813)
Start the virtual device and once it is up and running drag and drop the zip file onto the device.



Next you will get a file flashable dialog click ok.


You will continue to see the File Transfer dialog let it run. You will (may) get errors that pop up just ignore them for now. When you get a file flashed successful dialog, click ok.


Errors may be something related to a Google App like Search or Play. Click Ok.

Restart the virtual device. You may still be getting error dialogs like the one below. just click ok and carry on.




 If the Add Google Account Screen does not come up right away go to the apps and open up Play Store this should trigger the Add a Google Account screen.  go ahead and select the option appropriate for you and sign in or create an account. During the process you still may get errors like before just ignore it and click OK.



You will be prompted to agree with license agreement and so forth. Continue on.
Next you should see the Play Store open.
First thing I recommend doing is updating Google apps:
Menu button>My apps>update all



From this point on you should be good to go.
I went through this process a number of times and sometimes the apps did not show up in “My apps” section however if I searched for the app it would allow me to update.

If you are working with a different API this may work or you can try one of the other versions of Google Apps.   I hope this has been helpful.











June 16, 2014

How to get the real URL Target of a Short URL or Tiny URL?



Important Reasons to use a Unshort Tool

To use a Unshort Tool, UnShortener or DeShortener is always a good idea. Don't forget all the Pishing and Malware out there. The tools help you to find out the real target of any link and helps you not to end up on a Trojan site or any site which tries to install software you don't need and want.

Make a short URL long again

Find out the real URL of a Short Tiny URL

If you use Twitter, Facebook, Google or any other popular website, you find Short Url's everywhere. There are different names for this kind of links:
Short URL, Small URL, Tiny URL, but it's all the same.
If you see a link like this url.xy/123 you can't see the web site target, either you click on it, or you try to unshort such a short url. If you use a tool like real-url.org or unshort.me , it's easy and simple. The unshort tools find out the target address of a short link.

NOTE: You will only see the Final Target! What does this mean?
The used example is perfect to explain it.

(The links didn't work, this is only for example!)

(1) url.xy/123 links to ->
(2) url2.xy
this links to ->
(3) url3.xy

As you can see shows a unshort tool as target address (3), even if the first target was (2) and not (3).
Today internet marketers use tracking tools from different companies with long cryptical url's. The good news is that you can use a unshort tool also to find out the real target of such links.

During testing i noticed, that not all free URL Unshortener work correct.
Best results i got with the tools you find listed here.

Best Free Unshort URL Tools - Unshort any URL

real-url.org
unshort.me .....my recommendation
unshorten.com
May 29, 2014

Android 3rd Tutorial: Layout Options FILL_PARENT, MATCH_PARENT , WRAP_CONTENT


• FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the View wants to be as big as its parent (minus padding)
•WRAP_CONTENT, which means that the View wants to be just big enough to enclose its content (plus padding)
Either attribute can be applied to View's (visual control) horizontal or vertical size. It's used to set a View or Layouts size based on either it's contents or the size of it's parent layout rather than explicitly specifying a dimension.

fill_parent
(deprecated and renamed MATCH_PARENT in API Level 8 and higher)
Setting the layout of a widget to fill parent will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dock style of a Windows Form Control to Fill.
Setting a top level layout or control to fill parent will force it to take up the whole screen.

wrap_content
Setting a View's size to wrap content will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown. For layout elements it will resize the layout to fit the controls / layouts added as its children.
It's roughly the equivalent of setting a Windows Form Control's Auto size property to True.

Online Documentation
There's some details in the Android code documentation here


May 29, 2014

Styling Android: Online Tools

As mobile developers Styling Android Application is the biggest pain. But thanks to this Online tool
you can reduce your hard times.

Try it,


Android Asset Studio

Icon generators — Make icons for your app

Icon generators allow you to quickly and easily generate icons from existing source images, clipart, or text.

My Instagram