Sunday, August 21, 2016

Android SDK Manager not opening (Solution)

Well, been a crazy week! 5 whole week days, trying to fix the SDK manager bug. Being spatted with the error, "Failed to execute android.bat" and "Cannot find file android.bat". and finally, possibilities come to my rescue.

Here is the solution:

1. Locate "android.bat" in your "..............\Android\sdk\tools" folder
2. Right-click and edit on text editor
3. Change set java_exe=   to set java_exe=%JAVA_HOME%\bin\java.exe
4. Delete for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a. Replace it with set swt_path=lib\x86_64. 86_64, for a 64-bit os.
5. Open terminal cmd and type android. Should open up the SDK manager tool window.

Good luck

Tuesday, May 3, 2016

Dialog Animations in Android

Been working on a project for my client. A value add implementation of  dialog sliding from bottom to middle of screen literally made my day. Too good not to share and so here it goes. For, confidentiality,i'm not sharing the screen shot. But, i can assure you that this code will smooth glide into your layouts and class file elements.

Here is my pusedo code:
1. Create dialog layout and position it over but at bottom of parent screen.
2. The dialog needs to smoothly glide from bottom to middle of the screen.

Here is how it is done:
1. Create a anim folder in res (res/anim).
2. Create two animation resources
2a. Slide_up_dialog
<pre class="brush: csharp">
xml version="1.0" encoding="utf-8"?> <
set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate       
      android:duration="@android:integer/config_mediumAnimTime"     
       android:fromYDelta="0%p"       
    android:interpolator="@android:anim/accelerate_interpolator"     
     android:toXDelta="0" /> 
</set>
</pre>
2a. Slide_up_dialog
<pre class="brush: csharp">

xml version="1.0" encoding="utf-8"?><
set xmlns:android="http://schemas.android.com/apk/res/android" >
 <translate      
    android:duration="@android:integer/config_mediumAnimTime"     
     android:fromYDelta="0%p"      
     android:interpolator="@android:anim/accelerate_interpolator"      
    android:toYDelta="25%p" />
</set>
</pre>
3. Create Style resources in Styles.xml
<pre class="brush: csharp">

<style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_up_dialog</item>
    <item name="android:windowBackground">@null</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowNoTitle">true</item>
</style>
</pre>
4. Extend the DialogAnimation style into your DialogTheme Style (on Same Page)
<pre class="brush: csharp">
<style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
    <item name="android:windowExitAnimation">@anim/slide_out_down</item>
</style>
</pre>
4. Java Code for Animating XML elements of Dialog
<pre class="brush: csharp">
//First the Dialog object creation
final Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.calendar_dialog);
//Second implement the following code to implement the animation
Window window = dialog.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.windowAnimations = R.style.DialogAnimation;
//to keep the dialog window to the bottom of the parent screen
wlp.gravity = Gravity.BOTTOM;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
//Finally
dialog.show();
</pre>
Sit back and treat yourself for the dialog animation you've just created ;-)

Saturday, February 27, 2016

Calculate Age from Date of Birth (Java/Android SourceCode)

Here is the concept for calculating Age from a user defined or selected Date of Birth. I've used Ecplise IDE to develop an android application. But, the MainActivity.class source code can also be used in Java.

Steps in Android:

A. Create XML layout with
  • DataPicker (pre-defined data object)
  • Button (onClick that will handle setting values within respective text view objects)
  • TextView (object to get DOB)
  • TextView (object to show Age)
B. Create Package-Class called MainActivity

0. Import the necessary widgets
  • import java.util.Calendar;
  • import android.app.Activity;
  • import android.os.Bundle;
  • import android.view.Menu;
  • import android.view.View;
  • import android.view.View.OnClickListener;
  • import android.widget.Button;
  • import android.widget.DatePicker;
  • import android.widget.TextView;
  • import com.example.datedemo.R;
1. Initiate DataPicker, TextView elements by importing declaring and importing pre-defined respective classes
  •  DatePicker picker;
  • TextView tvdob;
  • TextView tvage;
2. Override onCreate bundle and setContentView
  • setContentView(R.layout.date);
3. Allocate Memory for initiated objects within onCreate bundle
  • btnsubmit=(Button)findViewById(R.id.button1);
  • picker =(DatePicker) findViewById(R.id.datePicker1);
  • tvdob=(TextView)findViewById(R.id.tvdob);
  • tvage=(TextView)findViewById(R.id.tvage);


  • 4. Create OnClick event handler within onCreate bundle
  • btnsubmit.setOnClickListener(new OnClickListener() {
  • @Override
    public void onClick(View view) {
    // TODO Auto-generated method stub
    //getDateofBirth() receives values from the custom method declared public below
    tvdob.setText(getDateofBirth());
    //currentDate() receives values from the custom method declared public below
    tvage.setText(currentDate());

    }
    });
    5. Create custom method to receive Date of Birth from the picker object values selected:
    • public String getDateofBirth(){
      StringBuilder builder=new StringBuilder();
    builder.append("DOB: ");
    builder.append((picker.getMonth() + 1)+"/");//month is 0 based
    builder.append(picker.getDayOfMonth()+"/");
    builder.append(picker.getYear());
    return builder.toString();
        }
    5. Create custom method to receive Current Date Values from Calendar Object (CALENDAR WIDGET SHOULD BE IMPORTED):
    • public String currentDate(){
    StringBuilder todaydate=new StringBuilder();
    //get today's date
    Calendar today=Calendar.getInstance();
    //calculate age by subtracting today's date year from the user's (picker object) selected date year 
    int age=today.get(Calendar.YEAR)-picker.getYear();
    if (today.get(Calendar.MONTH) < picker.getYear()) {
     age--;  
    } else if (today.get(Calendar.MONTH) == picker.getYear()
       && today.get(Calendar.DAY_OF_MONTH) < picker.getYear()) {
     age--;  
    }
    todaydate.append("Age: ");
    todaydate.append(String.valueOf(age));
    return todaydate.toString();
    }
    C. Declare the manifest file with the the and details.
    D. Run the application and sip on a cup of coffee, while you take pride in the new bit code you executed and learnt :-)

    ________________________________________________________

    Just in case, the lazy boy in you wants just to copy/paste the code and perform a quick fix, here following is the full source code for MainActivity.class:

    //source beings here
    package com.datepick; //your Gen package name

    import java.util.Calendar;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.TextView;

    import com.example.datedemo.R; //your package name

    public class MainActivity extends Activity{
    //Create Instance 
    DatePicker picker;
    TextView tvdob;
    TextView tvage;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.date);
    //Allocate memory
    Button btnsubmit=(Button)findViewById(R.id.button1);
    picker =(DatePicker) findViewById(R.id.datePicker1);
    tvdob=(TextView)findViewById(R.id.tvdob);
    tvage=(TextView)findViewById(R.id.tvage);
    btnsubmit.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View view) {
    // TODO Auto-generated method stub
    tvdob.setText(getDateofBirth());
    tvage.setText(currentDate());
    }
    });
    }
    public String getDateofBirth(){
      StringBuilder builder=new StringBuilder();
    builder.append("DOB: ");
    builder.append((picker.getMonth() + 1)+"/");//month is 0 based
    builder.append(picker.getDayOfMonth()+"/");
    builder.append(picker.getYear());
    return builder.toString();
        }
    public String currentDate(){
    StringBuilder todaydate=new StringBuilder();
    Calendar today=Calendar.getInstance();
    int age=today.get(Calendar.YEAR)-picker.getYear();
    if (today.get(Calendar.MONTH) < picker.getYear()) {
     age--;  
    } else if (today.get(Calendar.MONTH) == picker.getYear()
       && today.get(Calendar.DAY_OF_MONTH) < picker.getYear()) {
     age--;  
    }
    todaydate.append("Age: ");
    todaydate.append(String.valueOf(age));
    return todaydate.toString();
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
    }

    }
    //Code Ends

    Make sure to create xml layout elements and Manifest file declarations before running the application.

    Wednesday, September 9, 2015

    Anchor tag Click Event on Page Load

    Here is a snippet code sample for click event on DOM Load. There are times when, map <div>'s content text visibility is coded to synchronize with a user's click event. JavaScript code does execution of the code so beautifully, that so often a page loads with a DOM's  <div> space empty waiting for user events.

    Not so, with Jquery's trigger event framework. Try your hands on the following code to have a program to automatically trigger a click event on your first anchor tag. The page loads in with your intended anchor tag by default and of course avoid having to present empty <div> space.

    <script>
        $(document).ready(function(){
            $('The ID/Class name of the intended a href tag').trigger('click');
        });
    </script>



    Friday, July 3, 2015

    GIS Web Services

    First, lets define the generic term Web services. Applications or components that can be published, found and used on the World Wide Web are called Web services.  Webservices are XML based (Now, to understand that, you don't need to study XML, I promise!) and the pudding of using web services is that it is highly inter-operable and is designed to  handle specific or limited set of tasks.

    So, from the above snippet, the obvious things are

    a) Web services communicates between applications
    b) Information can be published or distributed to a large audience or users
    c) Web Services can be reused for existing services
    d) Great in handling specific task


    Now, with the above four things let me show you, how this model of web services can be replicated for GIS Mapping.

    a) Web Services are building block of any mapping software. Take for example ArcMap which is nothing but clusters of ArcObjects tools and components, integrated to provide users with Geo-spatial analysis capabilities. One step further, Sharing map services between application of ArcMap to ArcServer (and Web Adaptors between, indeed), that's another classic case of demostrating Web Services framework

    b)  The ArcServer, ArcOnline, Portal for ArcGis all come with capabilities to publish mapping services to large user base, either on web or within organizations or between organisations.

    c) The map services so published, can be constantly overwritten over existing services, so for the spatial data sets to be up to date or current.

    d) Specific Task. This is my favorite and i would prefer to elaborate it the ESRI way!!! The user/client capabilities on the mapping interface, like

    •  downloading maps for a specific location (Map Services)
    • enabling the client to use all the ArcMap tool capabilities (Geo-processing Services) 
    • data or feature updates (In DB terms "INSERT"), performed by the client (Feature Services)
    • enabling the user to convert descriptive address or location names into lat/lon coordinates (Geocoding services)
    • enabling the user to perform analysis of published route networks (Network Analysis)
    • enabling clients to generate 3D maps (3D Scene Services)

    • enabling user to measure, create buffers and project (GeoEvent "Extension" but also follows the Services model.
    A Note on Framework:

    Now, we get to the basics of actual Web Mapping. 

    Any application is hosted on an Interface - what a user sees on the web page (Front-end), from the Server (Back-end) through data sets stored in Databases (Middleware). 

    This framework applies for GIS, as well.

    On an Open Source: The maps generated from QGis are stored in PostgreSQL and hosted through Geoserver service directory. These published maps can be either viewed on client viewers like uDig or further processed with OpenLayers and published on Web.

    In ESRI: The maps generated from ArcMap, which of course of stored in Geo-databases, can be published directly are service through Arcserver.  The Service Directory of ArcServer lets you verify and test the web maps (and it's services), after which the map services can be further distributed to target clients.

    The beauty lies in the details!... and i will elaborate on each of the segment and software in the upcoming posts....



    Tuesday, June 30, 2015

    Web mapping with ESRI Cloud (AGOL)

    GIS Analysts, who wish to try their hands on Web Mapping, yet have no programming knowledge or skill!!!! ESRI's cloud could be your best training ground. What i love about ArcGis Online is that it's simple, elegent and yet highly scalable and complex.  First, let me take you through the what you can leverage of this product:

    Free access for limited content:

    1. ArcMap map services need not take the tough route of being prepared as Service Definition Files , to be published on Web. All that is required, to publish limited content, is an Global ESRI Account and spatial Datasets (Either CSV or Zipped Shapefiles).
    2. Configurable Pop-up's, symbology and  to some extent Legend.
    3. Standard Templates, that help users with no HTML or CSS knowledge to pick and choose from the standard interfaces. These Templates are dynamic and are so filled with interactive controls , that it let's your users analyze for information, pattern and trends.
    4. Responsive WebApplications of the map templates that can be shared over mail or embedded into your url.

    Organizational Account:

    Why invest in an expensive ESRI ArcServer when most of it's capabilities can be leveraged through ArcGis Online? Well ya,..... At an enterprise level ArcServer may be the best choice. But for Small to medium workgroups, who intent to publish  only map tiles and Feature services,  AGOL may be the best Choice. The organization has an option to publish maps on Web, Mobile and  Tabs. Geo processing controls are achieved through ESRI API for JavaScript and Like ArcServer, Veiwers of Flex and Silverlight can be used as well. An organizational Account is also powered with Analytics. 

    How to get started with your ESRI AGOL Free Mapping:

    1.  Log on to http://www.arcgis.com/home/ . Create a Global Account for yourself.

    2.  Hover to "MAP" on Header section (Top section) on the Homepage.

    3.  You should now see a base map layer, where you can  "Add Layer" to create overlays. Now, you have two choices. Either to use ESRI layers as map overlay and prepare you webmaps or to choose  your own map layer generated from ArcMap. A custom map service, should ideally be a "csv" format dataset with an spatial context or an zipped shapefile to upto 1000 attributes.

    4. Once you are "Done adding Layers", "Save" the map and click on the "Share" icon, to access the ESRI WebMapping templates. Based on the context of you web map, ESRI has provided templates that you can choose from. 

    5. Test the interface of your map, it's text and legend elements, both on Desktop web and Mobile. Play around with positioning, colors and text. Once you're all done, your first (Basic) web map is all set to be shared.

    The first time, i tried my hands on capabilities of AGOL, i dd not know the creation of web maps can be made possible, relatively this simple. Though, the free mapping option of AGOL, provides limited access to create basic Spatial web services, it surely does open the users into the realm of web mapping. Try your hands on, as much as you can with AGOL!!! This is your sandbox to get a feel of what it takes of Mapping Interfaces and a platform that will gear you up into the real programming world of web mapping.,... I intent to keep the blog updated on the developer training of mapping web services. 
    Until, then:

    Happy Mapping :-)




    Monday, June 29, 2015

    ArcMap Geo-Coding

    Aim:
     To Geo-code the address of Schools.

    Procedure:

    Step 1: Map Input
    Address of Schools in Excel or Stand-alone Table Format (With Road Name, City, State), Reference Data (Census Data or OSM data for Non- US, possibility).

    Step 2: Map Processing
    1.       Enable the Geo-coding Extension with ArcGis
    2.       Build an Address Locator using “Create Address Locator” Tool of Geocoding toolbox or by right-clicking on your geo-database (Feature Dataset).
    3.       On the Address Locator Style Specify “Single Field” (This is mostly for Non-US, where the Address sequence does not follow a nationally uniform sequence. For US it is best to use “Dual Ranges”)
    4.       Add on the Reference Data as the OSM Data set and set the Filed Map with appropriate Field Name and Alias Name. Make sure to set the primary key field to Street Name or House Number, through which the address matching will be processed.
    5.       Now, to initiate Geo-coding of School Address Table, Click on the Geo-code address icon of the extension tool bar. Specify the attribute field name, which will link with the address locator’s primary key field.  One may also specify, Geo-coding Options of Spelling Sensitivity, Minimum Candidate Score,….
    6.       Run Geocoding.  The results page with Matched/Unmatched and Tied Records.

    Step 3: Map Display
    7.        Generate Map Outputs of Geo-coding result, Matched Results (Select by attributes of Table and Export as shapefile) and Screen shot of results page.