Skip to main content

Posts

Showing posts from 2013

Blackberry 10 Application Deployment failed

When you  try to deploy Blackberry 10 application on your simulator or device, you may get these type of errors many times before application is deployed successfully. Deployment Failed: Info: Failed to obtain QConn connection, sync disabled Info: Sync not enabled, packaging full bar required for installation Info: Sending request: INSTALL_AND_LAUNCH Info: Action: Install and Launch Info: Debug native: on Info: File size: 304312 Info: Installing com.example.BB10TrackerSample.testDev_ackerSamplea7864132... Info: Processing 304312 bytes OR Deployment Failed: Info: Attempt to use sync failed: Connection reset Info: Sync not enabled, packaging full bar required for installation Info: Sending request: INSTALL_AND_LAUNCH Info: Action: Install and Launch Info: Debug native: on Info: File size: 304312 Info: Installing com.example.BB10TrackerSample.testDev_ackerSamplea7864132... Info: Processing 304312 bytes This issue is resolved in Blackberry 10.2 SDK. But for those who have not yet

Intercepting Sent and Received SMS in Android

Android API provides a very easy to way to get applications notified for phone related events such as SMS received and SMS sent. In this blog post we will learn how our app can receive these two notifications. Getting notified for Received SMS BroadcastReceiver  class allows applications to get notified for any android defined filter they want. All you have to do is to extend your class with BroadcastReceiver class and overrides its onReceive method. This method is called when Intent broadcast is received by this BroadcastReceiver. It has two parametes, first is a Context in which the receiver is running , second is the Intent which is being received. Its prototype in BroadcastReceiver class is like this public abstract void onReceive(Context context,Intent intent); So lets write our simple class whose onReceive method will be called on broadcast for any filter we are interested (in our case it is  android.provider.Telephony.SMS_RECEIVED  ). public class MyReceivedSmsRece

C Windows API - Enumerate Windows and some manipulation

Few years back I wrote a program in C language using Windows API that displays the list of all "Windows" opened on my PC (Windows) and I can make any of them visible/invisible. I decided to share the part of code which Enumerate windows, find a window and make them visible/invisible. Enumerating Windows Windows API provide a function EnumWindows  which takes a pointer to Callback function which it calls for each window found. Second parameter is a LPARAM which you can use to pass any argument you want, this LPARAM will be passed to our callback function. Here is how to use EnumWindows BOOL isSuccess=EnumWindows(OurAppCallback,(LPARAM)userDefinedVariable); Syntax of callback (OurAppCallback) will be like this BOOL CALLBACK OurAppCallback(HWND h,LPARAM l)  Important Remarks about EnumWindows from MSDN:  The EnumWindows function does not enumerate child windows, with the exception of a few top-level windows owned by the system that have the WS_CHILD style.   F

Drag and Move image using jQuery and crop using PHP - Part2

In Part 1 we discussed how to make image draggable using simple jQuery. In this part we will learn how to save the dragged image using PHP . We will crop the part that is outside our  view port div (which is of resolution 850x600 ). First retrieve the original width and height of image. To do this we will use getimagesize function of PHP . It takes file path as input and return the array containing width at index 0 and height at index 1 $file_path="movable.jpg" $size=getimagesize($file_path); $width=$size[0]; $height=$size[1]; Get current x and y of image. In the HTML FORM written in Part 1 we have hidden fields with name locationX and locationY containing X and Y co-ordinates respectively. $x=$_POST["locationX"]; $y=$_POST["locationY"]; Next step is to check if any part of image is outside our bounding box (div). We will do this separately for width(horizontal view) and height (vertical view). For horizontal view If sum of curren

Drag and Move image using jQuery and crop using PHP - Part1

Web developers on some occasions are required to give user the ability to move image to fit the view or crop some part of image. In this blog post we will see how to allow user to drag/move image using jQuery and save the result (cropped) in new image file using PHP. I have break this in two posts. Part 1 will contain client side part. Part 2 will contain server side (PHP) part. Client side part (HTML+ jQuery) Add a reference to jQuery library. I am using version 1.8 for this example <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> Display image inside a div. Div will be of fixed width and height which will be our viewport. Part of image outside this div will be cropped . For this example lets keep it to 850x600 . First write a simple css to apply on this div #imgContainer {     width:850px;     height:600px;     overflow:hidden; /* part of image outside this div should be hidden */     border-width:2px;

Indexers in C#

Definition of Indexers from MSDN Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters. Whenever you are accessing individual element from List<T> or Hashtable<T,T> etc you are using Indexers . For example List<string> str=new List<string>(); str.Add("Rameez"); str.Add("Usmani"); string firstName=str[0];  //[0] is implying that you are calling indexer on instance of List class How Indexer is added to a class To add an indexer to a class you have to expose a property named "this(actually a keyword)" followed by "data type of index" in square brackets . Like this public ReturnDataType this[indexDataType] {     get { //logic to return the correct value }     set { //logic to set the correct value } } Lets say you have collection of Students and you want to access Student by name using Indexer , here is h

HTTP requests and response in Java

Java has excellent support of HTTP client side. In this blog post we will have a look at how to make HTTP request in Java and download the response , saving it in a buffer. Java implements a simple HTTP client in a class java.net.HttpURLConnection . So our first step is to make an instance of java.net.HttpURLConnection. To do this we need java.net.URL class. We will use its constructor which takes url in a form of string as a parameter and then call its openConnection method casting the returned object to HttpURLConnection. Here is how it is done String strUrl="http://google.com"; URL url=new URL(strUrl); HttpURLConnection httpConn=(HttpURLConnection)url.openConnection(); We now have HttpURLConnection object to use. Please note right now no request has been sent to the server (in our case google.com). To complete the process of sending actual request and start getting response we have to use getInputStream  method of HttpURLConnection class. Actually getInputStr

Resizing image in C#

In this blog post I will explain in short how to load and re size an image in C# and save the resulting image in a file. Actually the process is very easy. Lets break it in chunks Loading image from a file .NET has multiple ways to load an image. 1) From a file 2) From a Stream object 3) From a GDI Bitmap object For this post we will only load image from a File.Loading image from file is straight forward. It requires calling static method FromFile of Image class , passing the file path as a parameter. Here is how Image myImage=Image.FromFile(sourcePath); Re-sizing image As we now have Image instance we have to re size it. For re-sizing we will use one overload of Bitmap class constructor which takes Image instance and new width and height for scaling. So here is the one liner to do this job Bitmap bmp=new Bitmap(myImage,newWidth,newHeight); Saving the resulting image We have a Bitmap containing scaled version of our original image.Now we will save it to a

Blackberry round corner TextField with place holder text

While working on a blackberry project I was required to display a round corner text field with a place holder text. The logic was to display place holder text when TextField is not in focus and no text is entered by user (or text is cleared by user). As soon as TextField receives focus, placeholder text should be removed. Displaying place holder text when TextField is empty is very easy . You can just override TextField's  paint method and check if text is empty you can set text to place holder text. Here is a simple example protected void paint(Graphics g){     if (getText().compareTo("")==0){         setText( "Place holder text.." );     }     super.paint(g); } But displaying and removing of placeholder text on focus and unfocus was a bit of task so I came up with my own class and want to share with other fellow coders. import net.rim.device.api.ui.Color; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.component.TextField;