Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
mekhti11 committed Jun 12, 2018
1 parent da22be7 commit 438157d
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
android:maxSdkVersion="27"
android:minSdkVersion="19" />

<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="22" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="22" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
Expand Down
30 changes: 29 additions & 1 deletion app/src/main/java/com/mekhti/smartsmsbox/BlackList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.mekhti.smartsmsbox.Entity.Contact;
Expand All @@ -29,6 +31,9 @@ public class BlackList extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ListView mlistView;
private ArrayList<Contact> contacts;
private EditText nameET;
private EditText phoneET;
private Button addBtn;
ContactUtils cu ;
ArrayList<String> Arr ;
ArrayAdapter<String> adapter;
Expand All @@ -38,6 +43,9 @@ public class BlackList extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.black_list);
nameET = findViewById(R.id.bl_name);
phoneET = findViewById(R.id.bl_num);
addBtn = findViewById(R.id.bl_add);
db.open();
cu = new ContactUtils(getApplicationContext());
Arr = new ArrayList<>();
Expand All @@ -62,7 +70,7 @@ private void setData() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
CharSequence colors[] = new CharSequence[] {
contacts.get(position).getPhoneNum(),
"Add to WhiteList"};
"Add to WhiteList","Delete"};
AlertDialog.Builder builder = new AlertDialog.Builder(BlackList.this);
builder.setTitle("");
builder.setItems(colors, new DialogInterface.OnClickListener() {
Expand All @@ -77,6 +85,15 @@ public void onClick(DialogInterface dialog, int which) {
adapter.remove(str);
adapter.notifyDataSetChanged();
}
else if(which == 2){
Contact c = contacts.get(position);
String str = Arr.get(position);
contacts.remove(position);
Arr.remove(str);
adapter.remove(str);
adapter.notifyDataSetChanged();
db.deleteBlackList(c.getName(),c.getPhoneNum());
}
}
});
builder.show();
Expand Down Expand Up @@ -146,4 +163,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public void addToBlackList(View view) {

String name = nameET.getText().toString();
String num = phoneET.getText().toString();
db.addToBlackList(name,num);
adapter.insert(name,0);
//contacts.add(0,new Contact(name,num,ContactType.BlackList));
Arr.add(0,name);
adapter.notifyDataSetChanged();

}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/mekhti/smartsmsbox/utils/DbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public void onCreate(SQLiteDatabase db) {
" phone text ," +
" contact_type text )";
db.execSQL(sql);
sql = "create table sms (id integer primary key autoincrement ," +
" senderNum varchar(16) not null," +
" message text ," +
" sms_type text )";
db.execSQL(sql);
}

@Override
Expand Down
230 changes: 230 additions & 0 deletions app/src/main/java/com/mekhti/smartsmsbox/utils/GpsTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package com.mekhti.smartsmsbox.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;

public class GpsTracker extends Service implements LocationListener
{
private final Context mContext;

// Cihazda gps acik mi?
boolean isGPSEnabled = false;

// Cihazda veri baglantisi aktif mi?
boolean isNetworkEnabled = false;

boolean canGetLocation = false;

// Konum
Location location;
// Enlem
double latitude;
// Boylam
double longitude;

// Konum guncellemesi gerektirecek minimum degisim miktari
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // metre

// Konum guncellemesi gerektirecek minimum sure miktari
private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // dakika

// LocationManager nesnesi
protected LocationManager locationManager;

//
// Kurucu Metod - Constructor
//
public GpsTracker(Context context, Activity activity)
{
this.mContext = context;
getLocation(activity);
}

//
// Konum bilgisini dondurur
//
public Location getLocation(Activity activity)
{
try
{
locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

// GPS acik mi?
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

// Internet acik mi?
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled)
{

}
else
{
this.canGetLocation = true;

// Once internetten alinan konum bilgisi kayitlanir
if (isNetworkEnabled)
{
if ( Build.VERSION.SDK_INT >= 23 &&
ContextCompat.checkSelfPermission( mContext, android.Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission( mContext, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity,
new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},
1);
return null;
}
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// GPS'ten alinan konum bilgisi;
if (isGPSEnabled)
{
if (location == null)
{
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null)
{
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null)
{
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}

return location;
}

// Enlem bilgisini dondurur
public double getLatitude()
{
if(location != null)
{
latitude = location.getLatitude();
}

return latitude;
}

// Boylam bilgisini dondurur
public double getLongitude()
{
if(location != null)
{
longitude = location.getLongitude();
}

return longitude;
}

@Override
public void onLocationChanged(Location location)
{
}

@Override
public void onProviderDisabled(String provider)
{
}

@Override
public void onProviderEnabled(String provider)
{
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}

@Override
public IBinder onBind(Intent arg0)
{
return null;
}

public boolean canGetLocation()
{
return this.canGetLocation;
}

// Konum bilgisi kapali ise kullaniciya ayarlar sayfasina baglanti iceren bir mesaj goruntulenir
public void showSettingsAlert()
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

// Mesaj basligi
alertDialog.setTitle("GPS Kapalı");

// Mesaj
alertDialog.setMessage("Konum bilgisi alınamıyor. Ayarlara giderek gps'i aktif hale getiriniz.");

// Mesaj ikonu
//alertDialog.setIcon(R.drawable.delete);

// Ayarlar butonuna tiklandiginda
alertDialog.setPositiveButton("Ayarlar", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int which)
{
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});

// Iptal butonuna tiklandiginda
alertDialog.setNegativeButton("İptal", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});

// Mesaj kutusunu goster
alertDialog.show();
}

// LocationManager'in gps isteklerini durdurur
public void stopUsingGPS()
{
if(locationManager != null)
{
locationManager.removeUpdates(GpsTracker.this);
}
}
}
36 changes: 23 additions & 13 deletions app/src/main/java/com/mekhti/smartsmsbox/utils/Sqlite_utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,14 @@ public void addContacts(ArrayList<Contact> list){

public void addSMSs(ArrayList<Sms> list){

db.execSQL("drop table if exists sms");
String sql = "create table sms (id integer primary key autoincrement ," +
" senderNum varchar(16) not null," +
" message text ," +
" sms_type text )";
db.execSQL(sql);

// Cursor c = db.rawQuery("select count(*) from sms ",null);
// c.moveToFirst();
// Log.d(TAG, "addContacts: "+c.getInt(0));
// if(c.getInt(0)>0){
// return;
// }
// db.execSQL("drop table if exists sms");


Cursor c = db.rawQuery("select count(*) from sms ",null);
c.moveToFirst();
if(c.getInt(0)>0){
return;
}
Log.d(TAG, "addSMSs: "+list);
ContentValues val = new ContentValues();
for (Sms a : list) {
Expand Down Expand Up @@ -191,4 +186,19 @@ public String getSmsType(String phoneNum,String message){

return SmsTypes.SPAM.toString();
}

public void addToBlackList(String name, String num) {

ContentValues val = new ContentValues();
val.put("name",name);
val.put("phone",num);
val.put("contact_type",ContactType.BlackList.toString());

db.insert("contact_list",null,val);
}

public void deleteBlackList(String name , String phone){
String[] whereArgs = {name , phone} ;
db.delete("contact_list","name = ? AND phone = ?",whereArgs);
}
}
Loading

0 comments on commit 438157d

Please sign in to comment.