Skip to content

Commit 171f0fc

Browse files
committed
first commit by nimesh
1 parent 7c66a55 commit 171f0fc

File tree

9 files changed

+117
-48
lines changed

9 files changed

+117
-48
lines changed
340 Bytes
Binary file not shown.

com.mycontacts.Main/bin/classes.dex

976 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

com.mycontacts.Main/bin/jarlist.cache

Lines changed: 0 additions & 3 deletions
This file was deleted.

com.mycontacts.Main/bin/resources.ap_

0 Bytes
Binary file not shown.
Lines changed: 104 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package com.mycontacts;
22

3+
import java.io.File;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.OutputStream;
39
import java.util.ArrayList;
10+
import java.util.Date;
411
import java.util.Random;
512

613
import android.net.Uri;
@@ -12,7 +19,10 @@
1219
import android.annotation.SuppressLint;
1320
import android.app.Activity;
1421
import android.content.ContentResolver;
22+
import android.content.SharedPreferences;
1523
import android.database.Cursor;
24+
import android.text.format.DateFormat;
25+
import android.text.method.DateTimeKeyListener;
1626
import android.util.Log;
1727
import android.view.Menu;
1828
import android.view.MenuItem;
@@ -26,8 +36,10 @@
2636
public class DisplayContacts extends Activity {
2737
private EditText filterText = null;
2838
public ArrayList<Boolean> itemChecked = null;
29-
30-
39+
40+
final boolean tempvar=false;
41+
int k=0;
42+
String d=null;
3143
ArrayAdapter<String> myAdapterInstance;
3244
SimpleCursorAdapter adapter;
3345
String[] projection = new String[] {
@@ -41,7 +53,22 @@ public class DisplayContacts extends Activity {
4153
public void onCreate(Bundle savedInstanceState) {
4254
super.onCreate(savedInstanceState);
4355
setContentView(R.layout.displaycontacts);
44-
56+
try{
57+
String destpath = "/data/data/" + getPackageName()
58+
+ "/databases/dbContacts";
59+
File f = new File(destpath);
60+
if (!f.exists()) {
61+
copyDB(getBaseContext().getAssets().open("dbContacts"),
62+
new FileOutputStream(destpath));
63+
}
64+
} catch (FileNotFoundException e) {
65+
e.printStackTrace();
66+
} catch (IOException e) {
67+
e.printStackTrace();
68+
}
69+
70+
SQLHelper con= new SQLHelper(this);
71+
4572
//Find the random number between 1 to 5
4673
Random r= new Random();
4774
int rndcnt=r.nextInt(5)+1;
@@ -56,34 +83,81 @@ public void onCreate(Bundle savedInstanceState) {
5683
String name[]=new String[size];
5784
String number[]=new String[size];
5885
Log.e("hi","before for loop");
59-
for(int i=0;i<rndcnt;i++)
60-
{
61-
Random r1=new Random();
62-
int index=r1.nextInt(size);
63-
c.moveToPosition(index);
64-
Log.e("hi",index + "in for loop");
65-
id[i]=c.getInt(0);
66-
name[i]=c.getString(1); //8 for name,12 for name
67-
number[i]=c.getString(2);
68-
Log.e("hi", id+" "+name[i]+" "+number[i]);
69-
//insert this records into database;
70-
}
71-
86+
//Here find out if application run for first time or not.
87+
//If not first time then find the last scanned date of application.
7288

7389

74-
final Cursor cursor = managedQuery(Phone.CONTENT_URI, projection, null, null,Phone.DISPLAY_NAME + " ASC");
90+
/*SharedPreferences appSettings=getSharedPreferences("RunAppPreferences", MODE_PRIVATE);
91+
String d=appSettings.getString("Counter",null);
92+
SharedPreferences.Editor editor=appSettings.edit();
7593
76-
final ListView listView1= (ListView)findViewById(R.id.listView1);
77-
78-
adapter = new SimpleCursorAdapter(
79-
this, //Context
80-
R.layout.contactslist, //xml definintion of each listView item
81-
cursor, //Cursor
82-
new String[] {"display_name",Phone.NUMBER,"_id"}, //Columns to select From
83-
new int[] {R.id.textView11,R.id.textView12,R.id.checkBox1} //Object to bind to
84-
);
85-
listView1.setAdapter(adapter);
94+
String d1=d1=appSettings.getString("runDate", null);
95+
if(d1==null)
96+
{
97+
//d=DateFormat.getDateFormat(getApplicationContext()).toString();
98+
//Toast.makeText(this, d+"hi",Toast.LENGTH_LONG);
99+
*/
100+
//if(tempvar==false)
101+
if(k==0)
102+
{
103+
for(int i=0;i<rndcnt;i++)
104+
{
105+
Random r1=new Random();
106+
int index=r1.nextInt(size);
107+
c.moveToPosition(index);
108+
Log.e("hi",index + "in for loop");
109+
id[i]=c.getInt(0);
110+
name[i]=c.getString(1);
111+
number[i]=c.getString(2);
112+
Log.e("hi", id+" "+name[i]+" "+number[i]);
113+
//insert this records into database;
114+
Log.e("hi", "after log e");
115+
con.insertNumber(name[i],number[i], 1);
116+
}
117+
c.close();
118+
//editor.putString("rundate",d);
119+
//editor.commit();
120+
}
121+
else if(k==1)
122+
{
123+
//if App run after 10 days
124+
125+
for(int i=0;i<rndcnt;i++)
126+
{
127+
Random r1=new Random();
128+
int index=r1.nextInt(size);
129+
c.moveToPosition(index);
130+
Log.e("hi",index + "in for loop");
131+
id[i]=c.getInt(0);
132+
name[i]=c.getString(1);
133+
number[i]=c.getString(2);
134+
Log.e("hi", id+" "+name[i]+" "+number[i]);
135+
//insert this records into database;
136+
Log.e("hi", "after log e");
137+
con.insertNumber(name[i],number[i], 1);
138+
}
139+
}
140+
else if(k==2)
141+
{
142+
//if app run before 10 days then just display the active contacts(status=1)
143+
144+
}
145+
146+
Cursor c1=con.getAllContacts();
147+
final ListView listView1= (ListView)findViewById(R.id.listView1);
148+
adapter = new SimpleCursorAdapter(this,R.layout.contactslist,c1,new String[] {"c_name","c_no","_id"},new int[] {R.id.textView11,R.id.textView12,R.id.checkBox1});
149+
listView1.setAdapter(adapter);
150+
c1.close();
86151
}
87-
88-
89-
}
152+
153+
private void copyDB(InputStream inputStream, OutputStream outputStream)
154+
throws IOException {
155+
byte[] buffer = new byte[1024];
156+
int length;
157+
while ((length = inputStream.read(buffer)) > 0) {
158+
outputStream.write(buffer, 0, length);
159+
}
160+
inputStream.close();
161+
outputStream.close();
162+
}
163+
}

com.mycontacts.Main/src/com/mycontacts/SQLHelper.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,22 @@ public class SQLHelper extends SQLiteOpenHelper{
2323
static final String col_Hid="id";//id int autoincrement,c_no , c_name, status
2424
static final String col_lastScanned_Date="lastScanned_Date";
2525

26-
27-
2826
public SQLHelper(Context ctx)
2927
{
30-
super(ctx,dbName,null,33);
28+
super(ctx,dbName,null,1);
3129
}
3230

3331
@Override
3432
public void onCreate(SQLiteDatabase db) {
35-
try{
36-
db.execSQL("CREATE TABLE"+TableMyContacts+
33+
try{
34+
db.execSQL("CREATE TABLE IF NOT EXISTS "+TableMyContacts+
3735
"("+col_ID+" INTEGER PRIMARY KEY AUTOINCREMENT,"
3836
+col_c_name+" VARCHAR,"
3937
+col_c_no+" VARCHAR,"
4038
+col_status+" INTEGER);");
41-
db.execSQL("CREATE TABLE"+TableHistory+
42-
"("+col_Hid+" INTEGER,"
43-
+col_lastScanned_Date+" TIMESTAMP);");
39+
//db.execSQL("CREATE TABLE"+TableHistory+
40+
// "("+col_Hid+" INTEGER,"
41+
// +col_lastScanned_Date+" TIMESTAMP);");
4442
}catch(SQLException e)
4543
{
4644
e.printStackTrace();
@@ -51,16 +49,16 @@ public void onCreate(SQLiteDatabase db) {
5149
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
5250

5351
db.execSQL("DROP TABLE if Exists "+TableMyContacts);
54-
db.execSQL("DROP TABLE if Exists "+TableHistory);
52+
// db.execSQL("DROP TABLE if Exists "+TableHistory);
5553
onCreate(db);
5654
}
5755

5856
public long insertNumber(String c_name,String c_no,int Status)
5957
{
6058
SQLiteDatabase db=this.getWritableDatabase();
61-
ContentValues initialvalues= new ContentValues();
62-
initialvalues.put(col_c_no,c_no);
59+
ContentValues initialvalues= new ContentValues();
6360
initialvalues.put(col_c_name,c_name);
61+
initialvalues.put(col_c_no,c_no);
6462
initialvalues.put(col_status,Status);
6563
return db.insert(TableMyContacts, null, initialvalues);
6664
}
@@ -74,18 +72,18 @@ public long insertHistory(int id,Date date)
7472
return db.insert(TableHistory, null, initialvalues);
7573
}
7674

77-
public boolean activeContact(int id,String status)
75+
public boolean activeContact(int id)
7876
{
7977
SQLiteDatabase db=this.getWritableDatabase();
8078
ContentValues initialvalues=new ContentValues();
81-
initialvalues.put(col_status,0);
79+
initialvalues.put(col_status,1);
8280
return db.update(TableMyContacts,initialvalues,col_ID+"="+id,null)>0;
8381
}
84-
public boolean disableContact(int id,int status)
82+
public boolean disableContact(int id)
8583
{
8684
SQLiteDatabase db=this.getWritableDatabase();
8785
ContentValues initialvalues=new ContentValues();
88-
initialvalues.put(col_status,status);
86+
initialvalues.put(col_status,0);
8987
return db.update(TableMyContacts,initialvalues,col_ID+"="+id,null)>0;
9088
}
9189
public boolean updateHistory(int id,Date date)

0 commit comments

Comments
 (0)