Showing posts with label rahul garg. Show all posts
Showing posts with label rahul garg. Show all posts

Wednesday, November 18, 2015

Parse.com Android : Common Issues faced

If you have just started in the world of BASS service, you might have chosen Parse.com.
Although it has good tutorial for explaining things, still I think community support is not very good.
I also had hard time to try basic things. So let me share a complete tutorial for extracting some data from Parse.com. It will be more towards covering the known issues.

Step 1: Uploading Data
In Tutorial provided by Parse, they talked how you can create a ParseObject, and upload the data by putting.You can follow the Guide provided by Parse to do that. I instead use Import Data option in Data Browser. So create a Json file and upload it there. If you are facing any issue with uploading, like it should be in that particular format, I will suggest to download any existing Table such as User, and open the JSON file. Similar way you can do it. Remember the first name should be "results" only, otherwise it wont let you upload.

Step 2: Creating a subclass of ParseObject
Although you can use normal ParseObject class do that, I will suggest you to use your own customized subclass of ParseObject.
a) Use @ParseClassName("YOUR_CLASS_NAME")  annotation.
b) Keep the file name, class name and Table Name same.
c) There should be default constructor of your customized sub-class.
d) Create set/get method for your fields in the table.

Step3: Registering the subclass
In your Application class's onCreate() method: add this line before calling Parse.initialize() :
ParseObject.registerSubclass(YOUR_CLASS_NAME.class);

Step4: Query using the subclass
 ParseQuery query = Alert.getQuery();
query.findInBackground(); //see the last link to get the full code.

Step5: Manifest changes
a) Please make sure you have defined the name field in tag in AndroidManifest.xml. Better use the complete path.
b) Add android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permission.

I think this covers pretty much all the points.  Let me know if you face any issues with it. Sorry for lousy writing.
Here is link for all code.



Thursday, June 26, 2014

Android : How to Check whether device is rooted or not ?

Many time user go for rooting their phone to break the constraints put by operator and OEMs. 
So Rooting your phone opens a door of new features which could be really useful. 

To root your phone, I will suggest you to go to Xda developers. They have wide range of tutorial specifically for each devices. So once you have followed their steps, and just wanted to confirm whether your device has been rooted, Here is a simple app called Root Verifier Pro Launched by Bitdroid Devz

I will suggest you to try it, it worked fine for me. 

Wednesday, May 28, 2014

Notes on Insertion Sort

Insertion Sort is a way of sorting elements. While using insertion sort, we traverse from right to left element.

Steps :

1. Assume 0th element is already sorted.
2. Starting i from first element till last :
              -  In a loop(j ), check if the previous element is greater than the comparing element( for example for first time, we will be comparing 1st element to 0th element.)
              - If previous element is greater than comparing element, we will replace the j+1th element with j.[Remember before doing this keep array[i] stored in some variable, as it will be compared to all elements].
              - when loops finished, just replace the last index element with array[i] stored value.


Code :

for(i =1; i{
        int val = arr[i];
        int j = i-1;

        while( j >=0 && A[j] > val)
         {
              A[j+1] = A[j];
              j--;
         }
     
         A[j] = val;
}

Sunday, April 20, 2014

Short Note on Android App Signing

I know you will find many articles for mentioned title. But I thought of summarizing it , So Here are the steps :

1. You need Keytool and Jarsigner. If you have java installed in your system, then you have these utilities.

2. Now generate a private key for your app, So here is the command :
 keytool -genkey -v -keystore my-release-key.keystore -alias ANY_NAME -keyalg RSA -keysize 2048 -validity 10000

This will ask you few basic question, answer those. finally it will ask the password, give it, this will encrypt your keystore file.

3. I hope as you are an android developer, you must be having Eclipse with you. So Go to File -> export -> Android -> Export Android Application.

4. Select the project from which you want to export the application.

5.  Select keystore, remember in step 2 you created my-release-key.keystore, give path to this file. And entered the password you have entered at the time of creation.

6. Next it will ask key alias selection, So whatever ANY_NAME you given in step2, choose that and again give the password.

7. Finally it will ask you the location, where the signed application will be exported. So just give the path and click finish.

And you are done.

Thursday, January 16, 2014

SurfaceFlinger Basics

Thank you Guys, For such a great response for my last post on SurfaceFlinger. Here I am trying to add few more things which will help you clear your understanding on SurfaceFlinger. 

Terms User in SurfaceFlinger:

  • Canvas : 2D drawing object, object which used to draw on screen bitmap.
  • Surface : Drawing Buffer
  • Window : A visual area containing some kind of user interface.
  • SurfaceFlinger : Surface Manager
  • View : This is user interface, it’s a rectangular area on the screen for drawing and event handling.
  • ViewGroup : Subclass of view that contain other views(called children). It is the base class for layouts which are invisible containers that hold other views or viewgroups.
How Views are Created: 
  • When view is ready to be drawn it will inform using requestLayout() to the parent to schedule a traversal.
  • Which is turn will traversal up till ViewRoot.
  • scheduleTraversal() will post message to UI thread to start performTraversal().
  • performTraversal() does 3 things.
  1. Measure Pass : It is called to find out how big a view should be and how it should be measured and positioned.
  2. Layout Pass : Each parent will position all of its children using the sizes computed in the measure pass. 
  3. Deawing : ViewRoot will get the canvas by calling surface.lockCanvas(), it updates the canvas by passing it to view.drawCanvas(). 
  • After drawing the ViewRoot will pass the canvas to surface by surface.unlockCanvasAndPost().
As mentioned earlier, whenever there is a change in view, relayoutWindow()[ViewRootImpl.java] will be called. Further flows will be like 

relayoutWindow()[ViewrootImpl.java] ---> relayoutWindow()[WindowManagerService.java]------

-->createSurfaceLocked()[WindowStateAnimator.java] -----> SurfaceControl()[SurfaceControl.java]---

---> nativeCreate()[android_view_SurfaceControl.cpp] -------> createSurface()[Client.cpp] --------

--> createLayer()[SurfaceFlinger.cpp] --------> createNormalLayer()[SurfaceFlinger.cpp] -----------

--> setBuffer()[Layer.cpp] -------> 

setDefaultBufferSize()/ setDefaultBufferFormat()/ setDefaultBufferUsageBits()[BufferQueue.cpp]


How Surface is drawn:

So now as surface has been created, so created surface reference will be returned to ViewRootImpl. Further it will call

draw()[ViewRootImpl.java]----------------------------------------------------------------------------------> drawSoftware()[ViewRootImpl.java] ---------> lockCanvas()[Surface.java]
                                                              ---------> drawColors()[Canvas.java]
                                                              ---------> draw()[View.java]
                                                              ---------> unlockCanvas()[Surface.java]

Here draw() [View.java]draws different things like 1) draw background 2) draw views content 3) draw children(like animation) 4) draw decorations( scrollbars for ex).

lockCanvas() is used to attach the canvas to layer and internally it calls dequeueBuffer() which gets the GraphicBuffer to put the content in it.

And unlockCanvas() is used to detach the canvas from layer and internally it will call queuebuffer() which is used to post the content.

Added one more post on SurfaceFlinger, ,check it out  here 


Friday, June 21, 2013

Munnar : Kerala

In June first week, I was again able to get a weekend off to the nature's lap. And this time it was in God's own country, Kerala. We choose to go to Munnar,As we have heard a lot about it. So here is my experience:

How to go: As there is no raliway station in Munnar, you have to take a bus or cab, Still I will suggest go by train as much as possible. So from Bangalore we took Kanyakumari express which took us to Aluva. From here you can take cab or bus to reach Munnar. But here is a tip, it will be good if you can take a cab from here for your whole stay, as the cab driver charge for both ways even if you want to go for Munnar only. It cost us 2000 for one side.

Where to stay: As Munnar is a major tourist attraction, you will find plenty of hotels, resorts or home stays. But if you are planning in some long weekend, I will suggest you to book in advance, otherwise you might end up in paying a lot for very nominal accomodation. We stayed in WoodPecker Resort, and it was really good. Service, food all were good, the only thing is don't depend on them for your local sight seeing or booking cab.

What places to visit: There are many small places in Munnar, but we cover only 6 places. First day we covered Top Station(really awesome place), Mattupetty Dam, Echo point, Kundala Dam, these all are on same way.
Next day we went to Rajamalai National Park (Eravikulam National Park)[Awesome view],Lakkom waterfalls. On the way to munnar also you will find many small waterfalls, apart from that the spread of green valley and the mist of mountain will always bound you to stop you car for a minute and enjoy the view.
One more place we went was Tata Tea Museum, if you want to be Tea-educated, I think you should go there for sure, and I can assure you that you will love the Tea which they serve in the last..

What else to do: Apart from enjoying the view and major places, you can try trekking over there. And if interested you can go for shopping for different kind of Tea(Kandann devan specially), Home Made chocolate,different Spices, Herbal oils and handicrafts.

Misc: For a foodie, you can try many local items there but mainly for non-veggie, although veggies will always have their usual options. Language will also not be a big issue, as many ppl will be able to understand english.

As it was very short trip, I covered only few places, but there are many other places too. So if you have time go for those also. 

Wednesday, June 19, 2013

Double Ended Queue or Deque : Insertion/ Deletion

Hi All,

one more post coming up about the double ended queue which is also known as deque. A deque is a special type of data-structure in which insertion and deletion can be done at both end. So there are 5 operations for deque.

1. Insert element at front end.
2. Insert element at rear end.
3. Delete element from front end.
4. Delete element from rear end.
5. Display the elements of the deque.

So let me introduce the code for each of these function one by one. Here I will be using f for front index and r for rear index.

1. Insert element at front end.

Here there are 3 cases which needs to be taken care of

case 1. When queue is empty, so here is the code :

if(f == 0 && r == -1)
{
Queue[++r] = val; //value which needs to be added.
return;
}

case 2. when queue have element, but some elements from front has been deleted

if(f != 0)
{
Queue[--f] = val;
return;
}

case 3: when queue is full

if(f ==0 && r != -1)
{
printf("No Space left");
return;
}

2. Insert at rear end

Here only 2 cases needs to take care

case 1. if queue is full

if(r == Queue_SIZE - 1)
{
printf("No Space left");
return;
}

case 2. otherwise

else
{
Queue[++r] = val;
}

3. Delete from front end

Here there will be 3 cases.

case 1 : When front index has larger index than rear, it means there is no elements

if(f>r)
{
printf("No element left to delete");
return;
}

case 2. When there is only one element in the queue

if(f==r)
{
printf("deleted element is = %d",Queue[r]);
f = 0;
r =-1;
return;
}

case 3. otherwise

else
{
printf("deleted element is = %d",Queue[f++]);
}

4. Delete from rear end

Here there will be 2 cases.

case 1. when there is no element

if(f>r)
{
printf("No element to delete");
return;
}

case 2. otherwise

else
{
printf("Deleted element is = %d\n",Queue[r--]);
// now only one element was there in queue then adjust rear and front index
if(f>r)
{
f = 0;
r = -1;
}

5. Display the element

int i;
for(i = f; i
{
printf("%d ",Queue[i]);
}

Hope it will help you to understand the complete logic.