Sunday, November 25, 2012

List of Good Android Stuff (Tutorials)




http://www.vogella.de/android.html

http://www.droidnova.com/first-list-application,37.html

http://www.youtube.com/watch?v=QL5uaaOJQiE&feature=mfu_in_order&list=UL

^ really good tutorial

http://www.learn-android.com/2010/01/05/android-layout-tutorial/2/

free icon : http://www.softicons.com/free-icons/computer-icons/iphone-4g-icons-by-mike-demetriou/
iphone-4g-headphones-icon

Different layouts: http://www.learn-android.com/2010/01/05/android-layout-tutorial/4/

calling GPS : http://www.helloandroid.com/tutorials/calling-system-settings-android-app-gps-example

fancy Menu : http://stackoverflow.com/questions/4997166/how-to-make-a-fancy-transparent-menu-
like-the-share-menu-in-android-gallery

Gallery Example: http://saigeethamn.blogspot.com/2010/05/gallery-view-android-developer-
tutorial.html

http://www.cs.umd.edu/class/fall2011/cmsc436/CMSC436/Source_Code_Examples.html

Android Icons: http://androiddrawableexplorer.appspot.com/

Android Simple web service example:

http://sarangasl.blogspot.com/2011/10/android-web-service-access-tutorial.html

Multithreading http://www.youtube.com/watch?v=i4EzFb7m_cQ&feature=relatedal

Tutorial Series for Music Player with Service Tutorial:

http://www.youtube.com/watch?v=J3kwFMkAsJ0&feature=relmfu

Login screen with Database:

http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

Custom layout:

http://www.xoriant.com/blog/mobile-application-development/android-ui-design-
pattern-%E2%80%93-quick-action-bar.html

Android Dashboard Design Tutorial:

http://www.androidhive.info/2011/12/android-dashboard-design-tutorial/

Android Gallery tutorial:

http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-
select-multiple/

Android Color code:

http://www.ceveni.com/2009/08/set-rgb-color-codes-for-android-and-rgb.html

Android All widget example

http://www.droiddraw.org/widgetguide.html

interview question:

http://www.javacodegeeks.com/2011/08/android-interview-questions-answers.html

Android Custom object list tutorial (VVImportant)

http://www.learn-android.com/2011/11/22/lots-of-lists-custom-adapter/2/

Android Slider:

http://blog.codeus.net/dateslider-1-0-an-alternative-datepicker-for-android/rial

Spinner Tutorial

http://www.dcpagesapps.com/developer-resources/android/23-android-spinner-tips

upload Image on server

http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-
part/

Good Android Tutorial:

http://p-xr.com/

Custom Array Adaptor:

http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-
custom-arrayadapter

http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/

http://coenraets.org/blog/android-samples/androidtutorial/

android Image Gallery:

http://dev.tscolari.me/2011/10/10/android-camera-and-image-gallery/

Android Sample tutorial list :

http://portiaplante.com/android/

Android Tutorial for Radio Group and shared preferances:

http://www.kaloer.com/android-preferences

Thursday, May 3, 2012

post request in JSON




 private String getResponseData() throws Exception {
  String path = "";

  JSONObject jObjAssetDetails = new JSONObject();
  jObjAssetDetails.put("id", "5343377");// 671003");
  // jObjAssetDetails.put("id","671003");
  String strPostBody = jObjAssetDetails.toString();

  DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpPost postMethod = new HttpPost(path);

  StringEntity sEntity;
  sEntity = new StringEntity(strPostBody, "UTF-8");
  postMethod.setEntity(sEntity);
  HttpResponse httpResponse = httpClient.execute(postMethod);

  InputStream ins = httpResponse.getEntity().getContent();

  GZIPInputStream data = new GZIPInputStream(ins);

  BufferedReader r = new BufferedReader(new InputStreamReader(data));

  StringBuilder total = new StringBuilder();
  String line;
  while ((line = r.readLine()) != null) {
   total.append(line);
  }
  Log.w("urloutput", "startshere");
  Log.w("urloutput", total.toString());

  return total.toString();
 }


Sunday, April 22, 2012

A short and simple explanation about Threads in java

Multi-tasking :  it involves having multiple process (playing music and using text editor) -- Heavy weight

Multi-threading: it involves having mulitple threads(in text editor editing and printing) -- Light Weight

Creating a thread
- Runnable Interface
- Thread Class

- Using Runnable Interface

    Extend Runnable interface and use run method in it.

ex :


class B
{
       PSVM()
     {
          A a_ref= new A();
         a_ref.UseThread();
    }
}





  class A implements Runnable
{

    public void UseThread()
      {
              Thread new_thread = Thread(this, "new thread");
                 new_thread.start();
       }
       private void run()
      {
                // some code
      }
}



- Using Thread Class


  class A extends Thread
{

    public void UseThread()
      {
                 start();
       }
       private void run()
      {
                // some code
      }
}



// its better to implement runnable





Multiple Threads




class B
{
       PSVM()
     {
          A a_ref= new A();
         a_ref.UseThread("one");
             a_ref.UseThread("two");
         a_ref.UseThread("three");

    }
}





  class A implements Runnable
{

    public void UseThread(String threadname)
      {
              Thread new_thread = Thread(this, threadname);
                 new_thread.start();
       }
       private void run()
      {
                // some code
      }
}



using isalive and join methods


// Using join() to wait for threads to finish.
class NewThread implements Runnable {
String name; // name of thread
Thread t;
NewThread(String threadname) {
name = threadname;
t = new Thread(this, name);
System.out.println("New thread: " + t);
t.start(); // Start the thread
}
// This is the entry point for thread.
public void run() {
try {
for(int i = 5; i > 0; i--) {
System.out.println(name + ": " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println(name + " interrupted.");
}
System.out.println(name + " exiting.");
}
}
class DemoJoin {
public static void main(String args[]) {
NewThread ob1 = new NewThread("One");
NewThread ob2 = new NewThread("Two");
NewThread ob3 = new NewThread("Three");
System.out.println("Thread One is alive: "
+ ob1.t.isAlive());
System.out.println("Thread Two is alive: "
+ ob2.t.isAlive());
System.out.println("Thread Three is alive: "
+ ob3.t.isAlive());
// wait for threads to finish
try {
System.out.println("Waiting for threads to finish.");
ob1.t.join();
ob2.t.join();
ob3.t.join();
} catch (InterruptedException e) {
System.out.println("Main thread Interrupted");
}
System.out.println("Thread One is alive: "
+ ob1.t.isAlive());
System.out.println("Thread Two is alive: "
+ ob2.t.isAlive());
System.out.println("Thread Three is alive: "
+ ob3.t.isAlive());
System.out.println("Main thread exiting.");
}
}






Do synchronize with  synchronized keyword or use synchrnoized(object) {  // some code }








Friday, April 20, 2012

Changing Size of SeekBar programatically in android


I had a scienario to change size of seekbar by changing the visibility of surrounding views. Took a while but below is small code snipped which may be helpful for sme1...


RelativeLayout.LayoutParams abc=new RelativeLayout.LayoutParams(526,30);
abc.addRule(RelativeLayout.CENTER_VERTICAL); abc.addRule(RelativeLayout.RIGHT_OF,R.id.pause);
mSeekBar.setLayoutParams(abc);

Friday, March 23, 2012

xml parser

writing a parser to read xml data.

 Below is a simple script for reading data from any xml file. all you need to know is send a xml file and reading output data from a hashmap.





ParserActivity.java


package com.example.parsers;
import java.net.URL;
import java.util.HashMap;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ParserActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String url_value = "   ";
try {
URL url = new URL(url_value);
SAXParserFactory sf = SAXParserFactory.newInstance();
SAXParser sp = sf.newSAXParser();

HandlerData handler = new HandlerData();
sp.parse(new InputSource(url.openStream()), handler);

getData outdata = handler.getParseddata();
HashMap<String, String> finalhash = new HashMap<String, String>();
finalhash = outdata.gethashdata();

TextView txt = (TextView) findViewById(R.id.text);
txt.setText("abcd");
} catch (Exception e) {
// TODO Auto-generated catch block

}

}
}








HandlerData.java



package com.example.parsers;

import java.util.ArrayList;
import java.util.HashMap;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

class HandlerData extends DefaultHandler {

getData data = new getData();

public getData getParseddata() {
return this.data;
}

HashMap<String, String> outcontent = new HashMap<String, String>();

HashMap<String, Boolean> ischeck = new HashMap<String, Boolean>();
String temp = null;

@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
super.characters(ch, start, length);
String middle_content = new String(ch, start, length);

if (ischeck.get(temp)) {
outcontent.put(temp, middle_content);
ischeck.put(temp, false);
}

}

@Override
public void endDocument() throws SAXException {
// TODO Auto-generated method stub
super.endDocument();
data.sethashdata(outcontent);
ArrayList<String> keys= new ArrayList<String>(outcontent.keySet());
for(String key : keys)
{
Log.w("outputdata",key+"-"+outcontent.get(key));
}


}

@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
}

@Override
public void startDocument() throws SAXException {
// TODO Auto-generated method stub
super.startDocument();
}

@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
super.startElement(uri, localName, qName, attributes);
int total_attributes = attributes.getLength();
if (total_attributes > 0) {
while (total_attributes > 0) {
total_attributes--;
String att = "" + attributes.getQName(total_attributes);
String value = attributes.getValue(att);
outcontent.put(att, value);
}
}
ischeck.put(qName, true);
temp = qName;
}

}








getData.java


package com.example.parsers;

import java.util.HashMap;

public class getData {

HashMap<String, String> content = new HashMap<String, String>();

public void sethashdata(HashMap<String, String> input) {
this.content = input;

}

public HashMap<String, String> gethashdata() {
return content;
}
}








Thursday, March 1, 2012

using git

installing : 
sudo apt-get install git

 setting up:
git config --global user.name "prashanthmadi"
git config --global user.email "prashanthrmadi@gmail.com"

 this will generate ~/.gitconfig file

initiallize git :

 you can clone existing git project by using

  •  git clone url
create  a new project by entering into a directory and enter
  • git init


to add files to git use

  •  git add file1 file2


 or else add all of them at once by

 -> git commit -a // this will add all the files at once
 -> git add . // not sure check this command

You are now ready to commit. You can see what is about to be committed using git diff with the --cached option:
$ git diff --cached
(Without --cached, git diff will show you any changes that you've made but not yet added to the index.) You can also get a brief summary of the situation with git status:


ignoring some files

 get into top level of working directory and create file named .gitignore

  foo.txt // to remove any file named as foo.txt
*.html // to remove all files ending with html






creating new branch
  • git branch new_branch_name
to watch all the branches

  • git branch

to switch between branches

  • git checkout branch_name



merge two branches using merge option

  • git merge branch_name   // do this when u are in another branch


two people working on same project

                   A         -----   >            B

Scenario  1:

consider two users as above.  A has a git  and B wants to make changes to it.

  • B will clone the project using clone command
  • B will make required changes and commit them
  • B says A about his changes.
  • A will issue a pull command   as    git pull project_url_of_b
Scenario 2: (defining remote repository)
  • git remote add new_user new_user_url
  • git fetch
this is a bit confusing update this scenario later.....

To get only the changes from previously existing git
  • git pull URL
A general scenario of working with team  happens as we release a public version in some repository. while we still work on current repository and someone else sends you changes

DEV-REPO  ---  >   PUBLIC-REPO
PUBLIC_REPO --- downloaded by another person -- >  DEV2-REPO
after some changes in DEV2-REPO
DEV2-REPO --- > PUBLIC2-REPO
PUBLIC2-REPO --- > DEV-REPO  // merge
  • git push public-repo master // to send into public repositories