Step 1:
public class DataCoupon{
private static final String DATABASE_CREATE =
"create table ram (1 integer primary key, "
+ "2 text,3 text not null,4 text);";
private final Context context;
private DatabaseHelper DBHelper;
private SQLiteDatabase db;
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "ram";
private static final int DATABASE_VERSION = 1;
private static final String TAG = "database";
public DataCoupon(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
public void deleteAll() {
db.delete(DATABASE_TABLE, null, null);
}
private static class DatabaseHelper extends SQLiteOpenHelper
{
DatabaseHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion)
{
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS "+DATABASE_TABLE);
onCreate(db);
}
}
/**---opens the database---*/
public DataCoupon open() throws SQLException
{
db = DBHelper.getWritableDatabase();
return this;
}
/**---closes the database---*/
public void close()
{
DBHelper.close();
}
/**---deletes a particular title---*/
public boolean deleteFeed(long Story_id)
{
return db.delete(DATABASE_TABLE, "Story_id" +
"=" + Story_id, null) > 0;
}
/**---insert a title into the database---
* @param date
* @param avgMealForTwo */
public long insert(int 1, String 2, String 3, String 4){
ContentValues initialValues = new ContentValues();
initialValues.put("1", 1);
initialValues.put("2", 2);
initialValues.put("3", 3);
initialValues.put("4", 4);
return db.insert(DATABASE_TABLE, null, initialValues);
}
/**---Get multiValue Result of user Query--g*/
public Cursor multiValueQuery(String userSQL){
Cursor cursorResult=null;
try{
cursorResult=db.rawQuery(userSQL, null);
}catch(Exception e){
System.out.println("Error in select all--"+e);
return null;
}
if (cursorResult != null) {
cursorResult.moveToFirst();
}
return cursorResult;
}
/**-- Give a single value as result for our give query in compileStatement--g*/
public SQLiteStatement singleValueQuery(String userSQL){
SQLiteStatement result=null;
try{
result=db.compileStatement(userSQL);
return result;
}catch(Exception e){
System.out.println("User Query Error"+e);
return null;
}
}
//---retrieves a particular title---
public Cursor getFeed(Integer 1) throws SQLException
{
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
"1",
"2",
"3",
"4"
},
"1" + "=" + 1,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
}
Step 2:
DataCoupon saved;
saved=new DataCoupon(this);
saved.open();
Cursor res=saved.getFeed(id);
if(res==null || res.getCount()<=0){
saved.open();
try{
saved_coupon.insert(id,2,3,4);
}catch (Exception e) {
Log.e("tag", "Error while Querying - "+e);
}
saved.close();
Toast.makeText(this, "downloaded", Toast.LENGTH_SHORT).show();
res.close();
}
else{
Toast.makeText(getApplicationContext(), "This already downloaded", Toast.LENGTH_SHORT).show();
res.close();
}
saved.close();
Ramachandran
Friday, September 16, 2011
Wednesday, September 14, 2011
, separater android
URL url=new URL("url");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String reader = "";
String[] RowData=null;
while ((reader = in.readLine()) != null){
RowData = reader.split(",");
for(String temp:RowData){
GlobleVariable.list.add(temp);
}
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String reader = "";
String[] RowData=null;
while ((reader = in.readLine()) != null){
RowData = reader.split(",");
for(String temp:RowData){
GlobleVariable.list.add(temp);
}
Asyn Parser
Step 1:
package com.parser;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public abstract class BaseFeedParser implements FeedParser {
private final URL feedUrl1;
protected BaseFeedParser(String feedUrl){
try {
this.feedUrl1 = new URL(feedUrl);
} catch (MalformedURLException e) {
throw new RuntimeException("BasefeedParser wrong url /n"+e);
}
}
protected InputStream getInputStream() {
try {
return feedUrl1.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException("connection failed IO exp "+e);
}
}
}
Step 2:
import java.util.List;
public interface FeedParser {
List parse();
}
Step 3:
public class FeedParserFactory {
static String feedUrl = "";
public FeedParserFactory(String url){
feedUrl=url;
}
public FeedParser getParser(){
return getParser(PARSERType.XML_HOME);
}
public FeedParser getParser(PARSERTypetype){
switch (type) {
case 1:
return new XmlParser(feedUrl);
default:
return null;
}
}
}
Step 4:
public enum PARSERType{
1;
}
Step 5:
public class message {
private String 1="";
public String get1(){
return 1;
}
public void set1(String 1){
this.1=1;
}
Step 6:
package com.parser;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import android.util.Log;
import android.util.Xml;
public class XmlParserHomePage extends BaseFeedParser {
public XmlParserHomePage(String feedUrl) {
// TODO Auto-generated constructor stub
super(feedUrl);
}
public List parse() {
// TODO Auto-generated method stub
List messages = null;
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(getInputStream(), null);
int eventType = parser.getEventType();
message currentMessage = null;
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
messages = new ArrayList();
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("1")){
currentMessage = new message();
} else if (currentMessage != null){
if(name.equalsIgnoreCase("2")){
currentMessage.set1(parser.nextText());
}else if(name.equalsIgnoreCase("3")||name.equalsIgnoreCase("4")){
currentMessage.set2(parser.nextText());
}else if(name.equalsIgnoreCase("5")||name.equalsIgnoreCase("6")){
currentMessage.set3(parser.nextText());
}else if(name.equalsIgnoreCase("distance")){
currentMessage.set4o(parser.nextText());
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("1")&& currentMessage != null){
messages.add(currentMessage);
}
else if(name.equalsIgnoreCase("0")){
done = true;
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
Log.e("Error Mian PullFeedParser", e.getMessage(), e);
//throw new RuntimeException(e);
}
//return messages;
System.out.println("Pass ctrl 2 Main");
return messages;
}
@Override
public List parsecoupen() {
// TODO Auto-generated method stub
return null;
}
}
Step 7:
private void loadparser(PARSERType type) {
try{
new DataProviderCoupon().execute(type);
}catch(Exception e){
ProgressCancel();
System.out.println("Error in Main Load feed method");
}
}
class DataProviderCoupon extends AsyncTask<>{
@Override
protected List doInBackground(PARSERType... params) {
FeedParserFactory f=new FeedParserFactory(url);
FeedParser parser = f.getParser(params[0]);
List messages=parser.parse();
return messages;
}
@Override
protected void onPostExecute(List messages) {
try{
}
catch(Exception e){
System.out.println("Error in getting data...."+e);
}
super.onPostExecute(messages);
}
}
final Handler mHandler = new Handler();
final Runnable mUpdateResults = new Runnable() {
public void run() {
updateUIwithData();
}
};
package com.parser;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public abstract class BaseFeedParser implements FeedParser {
private final URL feedUrl1;
protected BaseFeedParser(String feedUrl){
try {
this.feedUrl1 = new URL(feedUrl);
} catch (MalformedURLException e) {
throw new RuntimeException("BasefeedParser wrong url /n"+e);
}
}
protected InputStream getInputStream() {
try {
return feedUrl1.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException("connection failed IO exp "+e);
}
}
}
Step 2:
import java.util.List;
public interface FeedParser {
List
}
Step 3:
public class FeedParserFactory {
static String feedUrl = "";
public FeedParserFactory(String url){
feedUrl=url;
}
public FeedParser getParser(){
return getParser(PARSERType.XML_HOME);
}
public FeedParser getParser(PARSERTypetype){
switch (type) {
case 1:
return new XmlParser(feedUrl);
default:
return null;
}
}
}
Step 4:
public enum PARSERType{
1;
}
Step 5:
public class message {
private String 1="";
public String get1(){
return 1;
}
public void set1(String 1){
this.1=1;
}
Step 6:
package com.parser;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import android.util.Log;
import android.util.Xml;
public class XmlParserHomePage extends BaseFeedParser {
public XmlParserHomePage(String feedUrl) {
// TODO Auto-generated constructor stub
super(feedUrl);
}
public List
// TODO Auto-generated method stub
List
XmlPullParser parser = Xml.newPullParser();
try {
parser.setInput(getInputStream(), null);
int eventType = parser.getEventType();
message currentMessage = null;
boolean done = false;
while (eventType != XmlPullParser.END_DOCUMENT && !done){
String name = null;
switch (eventType){
case XmlPullParser.START_DOCUMENT:
messages = new ArrayList
break;
case XmlPullParser.START_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("1")){
currentMessage = new message();
} else if (currentMessage != null){
if(name.equalsIgnoreCase("2")){
currentMessage.set1(parser.nextText());
}else if(name.equalsIgnoreCase("3")||name.equalsIgnoreCase("4")){
currentMessage.set2(parser.nextText());
}else if(name.equalsIgnoreCase("5")||name.equalsIgnoreCase("6")){
currentMessage.set3(parser.nextText());
}else if(name.equalsIgnoreCase("distance")){
currentMessage.set4o(parser.nextText());
}
}
break;
case XmlPullParser.END_TAG:
name = parser.getName();
if (name.equalsIgnoreCase("1")&& currentMessage != null){
messages.add(currentMessage);
}
else if(name.equalsIgnoreCase("0")){
done = true;
}
break;
}
eventType = parser.next();
}
} catch (Exception e) {
Log.e("Error Mian PullFeedParser", e.getMessage(), e);
//throw new RuntimeException(e);
}
//return messages;
System.out.println("Pass ctrl 2 Main");
return messages;
}
@Override
public List
// TODO Auto-generated method stub
return null;
}
}
Step 7:
private void loadparser(PARSERType type) {
try{
new DataProviderCoupon().execute(type);
}catch(Exception e){
ProgressCancel();
System.out.println("Error in Main Load feed method");
}
}
class DataProviderCoupon extends AsyncTask<>{
@Override
protected List
FeedParserFactory f=new FeedParserFactory(url);
FeedParser parser = f.getParser(params[0]);
List
return messages;
}
@Override
protected void onPostExecute(List
try{
}
catch(Exception e){
System.out.println("Error in getting data...."+e);
}
super.onPostExecute(messages);
}
}
final Handler mHandler = new Handler();
final Runnable mUpdateResults = new Runnable() {
public void run() {
updateUIwithData();
}
};
Tuesday, August 23, 2011
ImageView Zoom and Scroll
http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/
http://www.anddev.org/large_image_scrolling_using_low_level_touch_events-t11182.html
http://www.anddev.org/large_image_scrolling_using_low_level_touch_events-t11182.html
Friday, July 22, 2011
Android Json Parser Sample code
http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
Thursday, July 21, 2011
sample code : drag and drop and animation view's
http://code.google.com/p/myandroidwidgets/source/browse/#svn%2Ftrunk%2FFlipAnimatorExample%253Fstate%253Dclosed
Subscribe to:
Posts (Atom)