Pages

Search This Blog

Tuesday, 26 January 2016

Android Studio - HAXM is not working and emulator runs in emulation mode

This error occurs when your Android Virtual Device (AVD) memory is larger than the space that was specified for Hardware Accelerated Execution Manager (HAXM).






How to Resolve?

Step1: Click SDK Manager and see whether HAXM is installed


If it’s not installed get it installed from Android Studio. If it’s already installed feel free

Step2: Go to the path highlighted in the error log. In my case it’s C:\Android\sdk
Navigate to C:\Android\sdk\extras\intel\Hardware_Accelerated_Execution_Manager and start the setup file



Don’t change the memory size here. Just note down the space used by it



Step3: Click AVD Manager in Android Studio and check the size of your AVD
a.       Select AVD Manager from Toolbar and select the AVD (Nexus/Your test AVD) and click Edit and then choose Advance Settings. 


Change the memory size to the space that was specified in HAXM (1024 MB = 1 GB) and click on Finish

Running your project again will do the trick.



 

Sunday, 9 March 2014

COND PARAMETER IN JCL - OVERRIDE

COND parameters in JCL used to bypass selective steps in a job based on the condition returned by previous step. It can be coded in both JOB and EXEC statement.
//MYJOB  JOB  (U3369),'RAJESH', COND=(4,GT)
//STEP1  EXEC  PGM=PROG1
//STEP2  EXEC  PGM=COBPROG,COND=(8,EQ)
 
 The first step in a job will not check for conditions at any time. 
With the above example consider 
if step 1 returns 0:
STEP2 first checks it with the JOB card condition.

4> 0 true, so no step is executed halts execution
If first step returns 8:

4>8 false, now step condition is verified. 8=8 true, so step 2 is not executed because
of the step condition
If first step returns 12:

4> 12 false, now step condition is verified, 8=12 false, so step 2 is executed.

This means JOB COND overrides STEP condition. 

Sunday, 9 February 2014

VB.NET/MySql- Access Denied @localhost(using password:NO)

This error when your code looks like:

con.Open();
con.ConnectionString="server=localhost;database=sample;username=root;password=****";

The statement con.ConnectionString should come before con.Open(). So the actual correct code is:

con.ConnectionString="server=localhost;database=sample;username=root;password=****";
con.Open();

con is an object of Connection class.

SKIP AND EXECUTE SELECTIVE STEPS IN A JOB - JCL

Using IEBEDIT utility you can take control of the steps that has to be executed in a job. You have the option of executing selective steps and also few steps can be skipped. The below is a sample JCL which skips STEP04 in a job

//JOBCARD
//          EXEC PGM=IEBEDIT
//SYSUT1 DD DSN=JOBS.ALL(JOB001),DISP=SHR
//SYSUT2 DD SYSOUT=(*,INTRDR)
//SYSIN DD *
  EDIT TYPE=EXCLUDE,STEPNAME=(STEP04)
/*
//SYSPRINT DD SYSOUT=*


EDIT TYPE=EXCLUDE will exclude a particular step of a job from execution and if many steps has to excluded it can be done by separating the step names with comma.

EDIT TYPE=INCLUDE will allow only that step to be executed.

INTRDR - refers to internal reader where all jobs are submitted for execution

Saturday, 18 January 2014

JCL to count the number of duplicate records in a dataset

Say you have an input file with transaction details and want to count the number of records with same transaction ID.
 
Input File
TRN1
TRN1
TRN1
TRN2
TRN2
TRN3
 
Output File
TRN1  3
TRN2  2
TRN3  1 
 
JCL
//STEP10 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*

//DFSMSG DD SYSOUT=*

//OUTFILE DD DSN=TRNCNT.PS,DISP=SHR
//INFILE DD DSN=TNFIL.PS,DISP=SHR
//TOOLIN DD *
OCCUR FROM(INFILE) LIST(OUTFILE) -
NOHEADER NOCC-

ON(1,4,CH) -

ON(VALCNT,N06)

/*
 
 
The duplicate values will be looked only in the first 4 bytes of each record and count will be displayed in the 6th position. 
 
If you want compare records with 80 bytes change 4 as 80 and 6 to the position where you want to display your count

Tuesday, 7 January 2014

jQuery to trim text

I spent hours and hours to fix a small problem. It is because the way I used the trim function is wrong and it didn't throw any error messages and it was working on few cases. later I found the correct way of trimming spaces in a text using jQuery.

Wrong Way

var customerNo = $("#<%=lblCustomerNo.ClientID%>").text();
customerNo = customerNo.trim();

Right Method

var customerNo = $("#<%=lblCustomerNo.ClientID%>").text();
customerNo = $.trim(customerNo);



 

Close the jQuery dialog when clicked anywhere on the page

You would have created a jQuery dialog and it will be opened on few cases. there will be requirement where the dialog should be closed when user clicks anywhere on the page. The following code piece does the trick:

$(document).ready(function () {
         //the dialog should close when clicking anywhere else on the page
             $('body').on('click', function (event) {
                     $("#dialog").dialog("close");
             });
});

The above code will work fine but the dialog will be closed even when the click event occurs on the dialog. So to avoid that check whether the click event is not on the dialog. Code below works as expected.

$(document).ready(function () {
      //the dialog should close when clicking anywhere else on the page
      $('body').on('click', function (event) {
                  var parent = $(event.target).closest("div");
                   if (!(parent.attr('id') == "dialog"))
                          $("#dialog").dialog("close");
});
});


Usually Dialog is created with help of an div tag, so check the ID of the closest div where the click event occured

 

Convert JSON Date to the format MM/DD/YYYY

When searching for a way to convert the JSON date to format MM/DD/YYYY, I came accross the below code and this is not coded by me. Hope this post will help few who are still searching.

var newFormattedDate = ConvertJsonDateString(installDate);
$('#datepicker').val(newFormattedDate);


//function definition
function ConvertJsonDateString(jsonDate) {
             var shortDate = null;
             if (jsonDate) {
                 var regex = /-?\d+/;
                 var matches = regex.exec(jsonDate);
                 var dt = new Date(parseInt(matches[0]));
                 var month = dt.getMonth() + 1;
                 var monthString = month > 9 ? month : '0' + month;
                 var day = dt.getDate();
                 var dayString = day > 9 ? day : '0' + day;
                 var year = dt.getFullYear();
                 shortDate = monthString + '/' + dayString + '/' + year;
             }
             return shortDate;
 }  

jQuery to loop through a DropDown and change the Selected Index

In this example we will see how to loop through all items in a DropDown (HTML Select) and change the Selected Index when a particular condition is met. There will be cases where an index change has to be triggered explicitly which in turn loads the data for second DropDown. These expectations will be met in this post.

HTML Select Element:

<select id="ddlCars" runat="server">
     <option>Volvo</option>
     <option>Saab</option>
     <option>Mercedes</option>
     <option>Audi</option>
</select>


jQuery to change Selected Index and trigger change event

var carToBeSelected = "Mercedes";
$('#ddlCars option').each(function () {
                 var item = $(this).val().toString();
                 if (item == carToBeSelected)

                {
                     $(this).attr("selected", "selected");  //select the current item                                     $('#ddlCars').trigger('change');  //explicit trigger of change event                                    
                 }
                 index++;

});

When any change event is associated with the DropDown that piece of code will be executed when trigger('change') is triggered.

When all the items in a DropDown is associated with a value attribute then the following one line of code will do the trick.

<select id="ddlCars">
     <option value="volvo">Volvo</option>
     <option value="saab">Saab</option>
     <option value="mercedes">Mercedes</option>
     <option value="audi">Audi</option>
</select>


$('#ddlCars').val("mercedes");

Monday, 6 January 2014

jQuery/Javascript to hide and make the controls visible

For some users the controls should not be visible. For instance only the administrator user should have approve access and for other users the approve option should not be visible. In this case the following sample will help:
 <input id="approve" type="button" class="btn btn-primary" runat="server" style="visibility:hidden; background-color:#688A08" value="Approve"/>

The above html code is for a button and it is not visible while page load. To make it visible at run time using Javascript the following will help:

document.getElementById("approve").style.visibility = 'visible';

jQuery to disable html controls (Label, Text box, Dropdown, etc.,)

There will be scenarios where you want your html controls (say label, button, text box, drop down) to be disabled. The following code does the trick.
 <input type="text" id="txtCustomerName" runat="server" />

$('#txtCustomerName').prop("disabled",true);

Add Hours to a DateTime object

This post is about adding some hours to a DateTime object. For instance when the time is 12.00 am and if you wish to add 23 hours the following code snippet can be used for reference. The below code gets the current date with time and adds 23 hours

DateTime today = DateTime.Now;today = today.AddHours(23); 

Friday, 7 September 2012

ANDROID APP - Fonalyzer

Click to download Fonalyzer App

This app helps user to know the number of calls made, received and missed in the current day, in past 15 days and in past 1 month. This app can also be used to identify the memory used and level of battery. The greatest advantage is that the user can view all these details in one streamlined interface.

Screenshots:




Sunday, 2 September 2012

CREATING, USING AND TESTING SD CARD IN ANDROID EMULATORS

App developers can rely on android emulators to test their application which uses SD-card. Here are the steps which are required to create SD card in emulators.

Step 1: Open Android AVD (Android Virtual Device) Manager.
Step 2: Select the device and click Edit
Step 3: In SD Card panel enter size for memory card say 500MB and File field is optional which is the location for SD card image file.
Step 4: In Hardware panel click new and select SD Card Support property.
Step 5: Click Edit AVD.

To check whether SD card is created or not follow the below steps:
Step 6: Open Eclipse
Step 7: Keep emulator running
Step 8: Now click Window->Short View->Other->Android->File Explorer
Step 9: Navigate to mnt->android->sdcard folder using file explorer loaded at the bottom
Step 10: Add/remove files to SD card using PUSH buttons at the top of file explorer panel.       

Monday, 13 August 2012

RETRIEVING DATE FROM CALLLOG IN ANDROID

When android app developers are in a need to get the date of a particular call the following stuff works very fine.

               try
{
'fields to retrieve from callLog
                               String[] strFields = {
       android.provider.CallLog.Calls.NUMBER, 
       android.provider.CallLog.Calls.TYPE,
       android.provider.CallLog.Calls.DATE        
       };

'form a query
Cursor mCallCursor = getContentResolver().query(
       android.provider.CallLog.Calls.CONTENT_URI,
       strFields,
       null,
       null,
      null
       );

while (mCallCursor.moveToNext()) 
{
                   int dateColumn = mCallCursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
           long callDate = mCallCursor.getLong(dateColumn);
           SimpleDateFormat datePattern = new SimpleDateFormat ("yyyy-MM-dd");
           datePattern.setTimeZone(TimeZone.getTimeZone("GMT"));
           String datestr = datePattern.format(new Date(callDate));
           Toast.makeText(this, datestr, 50).show();
}
In some cases when getting date it will display something like 1970-01-01. In this situation you would have used int instead of long. So replace long callDate = mCallCursor.getInt(dateColumn); as long callDate = mCallCursor.getLong(dateColumn);
Recommended packages:

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

Sunday, 12 August 2012

IN ANDROID MAKING A BUTTON TRANSPARENT

In few occasion button should be made transparent i.e. the background should be visible and no color should be made on button. When button is made transparent the background image will be visible even after placing the button. The following code also applies border for button in android, it also makes the button rounded rectangle.
Creating layout and button

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:background="@drawable/and4">
'and4 is an image in drawable folder

<Button
    android:id="@+id/buttonStart"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@drawable/button_shape" 
'button_shape is an xml file which applies style for button
    android:textColor="#FFFFFF"
    android:textStyle="bold|normal"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:text="Start" />
Button Style
button_shape.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#0000"/>
'use only 4 zeros to make button transparent
<gradient
            android:startColor="#3300FF"
            android:endColor="#3300FF"
            android:angle="270" />
    <corners
     android:bottomRightRadius="20dp"
     android:bottomLeftRadius="20dp"
     android:topLeftRadius="20dp"
     android:topRightRadius="20dp"/>
  <stroke android:width="6px" android:color="#6600FF"/>
'stroke applies border for button in android
</shape>


SENDING A MESSAGE AND MAKING A CALL TO ANDROID EMULATOR

Developers creating applications for android mobiles may be in situation to test it by sending messages. Developers has the possibility of sending messages to android emulator without installing it in a device and testing it.
Step 1: Open Eclipse and keep the emulator in running state.
Step 2: Keep the emulator running and open DBMS Perspective
Step 3: To open DBMS perspective click Window->Open Perspective->Other->DBMS
Step 4: In Devices window select your emulator

Step 5: Give a number, select SMS and type your message and click Send (To make a call select Voice and click Call)
Step 6: Open Inbox in emulator to view the message

Note: If you open DBMS perspective before running your emulator, in Devices window no emulator name will be displayed.

Thursday, 9 August 2012

CREATING ALERT DIALOG BOX IN ANDROID

Dialogs are normally used for notifications that should interrupt the user and to perform short tasks that directly relate to the application in progress.
AlertDialog
Consider a user sending a message, if user clicks Send button before specifying a phone number the application should display a dialog box.

//text filed is named as phoneno, where user types phone no.
EditText phn=(EditText)findViewById(R.id.phoneno);
String no=phn.getText().toString();

if (no.isEmpty())
{
   AlertDialog diabox=makeAndShowDialogBox();
   diabox.show();
}
//creating dialog box

public AlertDialog makeAndShowDialogBox()
    {
    final AlertDialog nonumberDialogBox=new AlertDialog.Builder(this).create();
    nonumberDialogBox.setTitle("Alert!");//sets title for dialog
    nonumberDialogBox.setMessage("Please specify a phone number");//sets message for dialog
    nonumberDialogBox.setIcon(R.drawable.no);//sets icon for dialog,icon file is placed under drawable folder
    nonumberDialogBox.setButton("OK", new DialogInterface.OnClickListener() {
//adds a OK button to dialog
@Override
public void onClick(DialogInterface arg0, int arg1) {
nonumberDialogBox.cancel();//closes dialog when Ok button is pressed
}
});
    return nonumberDialogBox;
    }
Output

Application developers can also add two or three buttons to a dialog box, each performing a different function


Friday, 27 July 2012

3 SIMPLE STEPS IN ANDROID TO ACCESS CONTACTS

This post helps you to access contacts in android and get the selected phone number from the contacts


Step 1: Create your User Interface using layout file


For this example two controls are required, A EditText field named phoneno to display selected phone number and a Button named Contacts to launch contact picker.
<RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <EditText  
        android:layout_height="wrap_content"  
        android:id="@+id/phoneno"  
        android:inputType="text|phone"  
        android:layout_width="wrap_content"  
        android:layout_toLeftOf="@+id/Contacts"  
        android:layout_alignParentLeft="true"></EditText>  
    <Button  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:id="@+id/Contacts"  
        android:text="Contacts"  
        android:layout_alignParentRight="true" 
        android:onClick="doLaunchContactPicker"></Button>  
    </RelativeLayout>

Step 2: doLaunchContactPicker will launch the contacts. Here's code for its implementation
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;  
[Import statements are must]


private static final int CONTACT_PICKER_RESULT = 1001;
public void doLaunchContactPicker(View view) 
    {  
        Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,Contacts.CONTENT_URI);  
        startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);  
        
    }
 Intent is used along with the startActivityForResult() method to launch another Android application and retrieve the result.  

Step 3: Handle results by implementing onActivityResult()
  1. protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  2.     {  
  3.      String phone="";
  4.      Cursor contacts=null;
  5.      try
  6.      {
  7.         if (resultCode == RESULT_OK) 
  8.         {  
  9.             switch (requestCode) 
  10.             {  
  11.             case CONTACT_PICKER_RESULT:  
  12.                 // gets the uri of selected contact
  13.              Uri result = data.getData();
  14.              // get the contact id from the Uri (last part is contact id) 
  15.              String id = result.getLastPathSegment(); 
  16.                  //queries the contacts DB for phone no
  17.              contacts=getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + "=?", new String[] { id },  null);
  18.                 //gets index of phone no
  19.              int phoneIdx = contacts.getColumnIndex(Phone.DATA); 
  20.              if (contacts.moveToFirst()) 
  21.              {
  22.                    //gets the phone no  
  23.                    phone = contacts.getString(phoneIdx);  
  24.                    EditText phoneTxt=(EditText)findViewById(R.id.phoneno);
  25.                    //assigns phone no to EditText field phoneno
  26.                    phoneTxt.setText(phone);                   
  27.                 } 
  28.              else 
  29.              {  
  30.              Toast.makeText(this, "error", 100).show();
  31.                 }  
  32.              break;  
  33.             }  
  34.       
  35.         } 
  36.         else 
  37.         {  
  38.             // gracefully handle failure  
  39.             Toast.makeText(this, "Warning: activity result not ok",50).show();  
  40.         }  
  41.     }
  42.      catch (Exception e) 
  43.      {  
  44.         Toast.makeText(this, e.getMessage(), 50).show();  
  45.         } 
  46.      finally 
  47.      {  
  48.         if (contacts != null) 
  49.         {  
  50.             contacts.close();  
  51.         }
  52.      }
  53.     }

IN ANDROID FINDING WHICH BUTTON IS CLICKED

This post helps you to learner about listening to click events in android

1.Create two buttons using XML file under /res/layout
2.I named two buttons as sendBtn and cancelBtn
3.Make buttons to listen to click events by following code


public class CreateMessage extends Activity implements OnClickListener
{
public void onCreate(Bundle savedInstanceState) 
{
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button sendBtn=(Button)findViewById(R.id.sendMsg);
          sendBtn.setOnClickListener(this);
           Button cancelBtn=(Button)findViewById(R.id.cancelMsg);
           cancelBtn.setOnClickListener(this);
       }
}
4.Using getId() find which button is clicked


public void onClick(View v)
    {
    Button clickedButton=(Button)v;
    switch(clickedButton.getId())
    {
    case R.id.sendMsg:
    Toast.makeText(this, "Message Sent",50).show(); //it displays a message
    break;
    case R.id.cancelMsg:
    finish(); //it closes current activity
    break;
    default:
    throw new RuntimeException("Unknow button ID");
   
    }
    }


NOTE: Include these header files import android.view.View;
import android.view.View.OnClickListener;