Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Tuesday, June 18, 2013

google maps v2 illegalStateException

java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

This happens when you request for locationupdates before the actual location connection is established. Instead use a boolean variable to check if connection is established or call for locationupdates as below in onConnected.

@Override
        public void onConnected(Bundle connectionHint) {
                Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
                mLocationClient.requestLocationUpdates(mLocationRequest, this);
         
        }

Wednesday, March 20, 2013

Creating HyperLinks in Large Text (TextView) - Android

String.xml

------------

<string name="totalText">Hello <u>World</u></string>



public void hyperlinkWordsInText()
{
 Spanned sequence = html.fromhtml (context.getstring (r.string.totalText));
 Spanablestringbuilder strbuilder = new Spanablestringbuilder(sequence);

 Underlinespan [] underlines = strbuilder.getspans (0, sequence.length (), Underlinespan.class);
  For (Underlinespan span : underlines)
  {
  int start = strBuilder.getSpanStart(span);
  int end = strBuilder.getSpanEnd(span);
  int flags = strBuilder.getSpanFlags(span);
  ClickableSpan myActivityLauncher = new ClickableSpan()
  {
   public void onClick(View view)
   {
    // do wat ever u want on click
   }
  
  };
  strBuilder.setSpan(myActivityLauncher,start,end,flags);
   
   
  }
txt.setText(strBuilder);
txt.setMovementMethod(LinkMovementMethod.getInstance());
}

Tuesday, March 5, 2013

Reading styled data from String.xml - Android


<string name="my_text">
  <![CDATA[
    <b>Autor:</b>Prashanth Madi<br/>
    <b>Contact:</b>prm0080@gmail.com<br/>
    <i>Copyright © 2012-2013  </i>
  ]]>
</string> 
From our Java code we could now utilize it like this:
TextView tv = (TextView) findViewById(R.id.myTextView);
tv.setText(Html.fromHtml(getString(R.string.my_text))); 

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

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;
}
}