Skip to content

Commit b970e93

Browse files
committed
Message Service Added
1 parent 7c6ae82 commit b970e93

11 files changed

+115
-6
lines changed

app/debug/app-debug.apk

1.53 MB
Binary file not shown.

app/debug/output.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-debug.apk","fullName":"debug","baseName":"debug"},"path":"app-debug.apk","properties":{}}]

app/release/Body Fitness App.apk

1.33 MB
Binary file not shown.

app/release/Body Fitness Zone.apk

-1.33 MB
Binary file not shown.

app/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.SEND_SMS" />
88
<uses-permission android:name="android.permission.RECEIVE_SMS" />
99
<uses-permission android:name="android.permission.CAMERA" />
10+
<uses-permission android:name="android.permission.INTERNET"/>
1011
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1112
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
1213

app/src/main/java/com/aina/dummydatabase/AddPerson.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public class AddPerson extends AppCompatActivity {
6666

6767
String mode_operation = "insert";
6868

69+
Boolean isServiceMessage;
70+
6971
String custIDUpdate = "";
7072

7173
Spinner spinner1,spinner2;
@@ -81,6 +83,8 @@ protected void onCreate(Bundle savedInstanceState) {
8183
profilepicView.setImageResource(R.drawable.ic_launcher_background);
8284
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
8385

86+
isServiceMessage = sharedpreferences.getBoolean("serviceMessage", false);
87+
8488
nameField = (EditText) findViewById(R.id.nameText);
8589
phoneField = (EditText) findViewById(R.id.mobileText);
8690
fatherField = (EditText) findViewById(R.id.fatherText);
@@ -537,7 +541,13 @@ public void onClickSubmit(View v) {
537541
String nameCustomer = nameField.getText().toString();
538542
String message = "Dear " + nameCustomer + ", Thank you for joining Body Fitness Zone! Have a Happy and Healthy Life!";
539543
if (phoneNo.length() > 0 && message.length() > 0) {
540-
sendSms(phoneNo, message);
544+
if(isServiceMessage){
545+
SendMessage sendSM = new SendMessage();
546+
sendSM.execute(phoneNo, message);
547+
}
548+
else{
549+
sendSms(phoneNo, message);
550+
}
541551
} else
542552
Toast.makeText(getBaseContext(),
543553
"Please enter both phone number and message.",

app/src/main/java/com/aina/dummydatabase/Detail.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.content.ContentValues;
77
import android.content.Context;
88
import android.content.Intent;
9+
import android.content.SharedPreferences;
910
import android.content.pm.PackageManager;
1011
import android.database.Cursor;
1112
import android.database.sqlite.SQLiteDatabase;
@@ -51,16 +52,20 @@ public class Detail extends AppCompatActivity {
5152

5253
String dtm_consider;
5354
EditText editText2;
55+
Boolean isSeviceMessage;
56+
SharedPreferences sharedpreferences;
57+
public static final String MyPREFERENCES = "MyPrefs" ;
5458

5559

5660
@Override
5761
protected void onCreate(Bundle savedInstanceState) {
5862
super.onCreate(savedInstanceState);
5963
setContentView(R.layout.activity_detail);
6064
custid= getIntent().getStringExtra("CUSTOMER_ID_Name");
61-
6265
custDB=openOrCreateDatabase("CustomerDB", Context.MODE_PRIVATE, null);
6366
feeDB = openOrCreateDatabase("feesDB", Context.MODE_PRIVATE, null);
67+
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
68+
isSeviceMessage = sharedpreferences.getBoolean("serviceMessage", false);
6469

6570
int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);
6671

@@ -104,7 +109,13 @@ public void onClick(View view) {
104109
String nameCustomer = nameView.getText().toString();
105110
String message = "Dear " + nameCustomer + ",\nYou have successfully deposited "+ amountfees +"/-" +"\nThanks,\nBody Fitness Zone";
106111
if (phoneNumber.length() > 0 && message.length() > 0) {
107-
sendSms(phoneNumber, message);
112+
if(isSeviceMessage){
113+
SendMessage sendSM = new SendMessage();
114+
sendSM.execute(phoneNumber, message);
115+
}
116+
else{
117+
sendSms(phoneNumber, message);
118+
}
108119
} else
109120
Toast.makeText(getBaseContext(),
110121
"Please enter both phone number and message.",
@@ -358,7 +369,13 @@ public void onSendReminder(View v){
358369
String nameCustomer = nameView.getText().toString();
359370
String message = "Dear " + nameCustomer + ",\nPlease accept this message as a soft reminder for the pending fees of this month."+ "\nThanks,\nBody Fitness Zone.";
360371
if (phoneNumber.length() > 0 && message.length() > 0) {
361-
sendSms(phoneNumber, message);
372+
if(isSeviceMessage){
373+
SendMessage sendSM = new SendMessage();
374+
sendSM.execute(phoneNumber, message);
375+
}
376+
else{
377+
sendSms(phoneNumber, message);
378+
}
362379
} else
363380
Toast.makeText(getBaseContext(),
364381
"Please enter both phone number and message.",

app/src/main/java/com/aina/dummydatabase/Functionality.java

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.os.Bundle;
1515
import android.util.Log;
1616
import android.view.View;
17+
import android.widget.CompoundButton;
18+
import android.widget.Switch;
1719
import android.widget.TextView;
1820
import android.widget.Toast;
1921

@@ -39,6 +41,7 @@ public class Functionality extends AppCompatActivity {
3941

4042
TextView activeMale, activeFemale, total_inactive, feecollected, feepending;
4143
private static final int PERMISSION_REQUEST_CODE = 1;
44+
Switch serviceSwitch;
4245

4346

4447
@Override
@@ -61,6 +64,9 @@ protected void onCreate(Bundle savedInstanceState) {
6164
total_inactive = (TextView)findViewById(R.id.inactiveView);
6265
feecollected = (TextView)findViewById(R.id.collectedView);
6366
feepending = (TextView)findViewById(R.id.pendingView);
67+
serviceSwitch = (Switch) findViewById(R.id.serviceMessage);
68+
69+
6470

6571
if (Build.VERSION.SDK_INT >= 23)
6672
{
@@ -75,6 +81,15 @@ protected void onCreate(Bundle savedInstanceState) {
7581
}
7682
}
7783

84+
serviceSwitch.setChecked(sharedpreferences.getBoolean("serviceMessage",false));
85+
86+
serviceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
87+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
88+
SharedPreferences.Editor mEditor2 = sharedpreferences.edit();
89+
mEditor2.putBoolean("serviceMessage", isChecked).commit();
90+
}
91+
});
92+
7893
prepareSpinner();
7994
fillDetails();
8095

app/src/main/java/com/aina/dummydatabase/SendCommonMessage.java

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.DatePickerDialog;
44
import android.content.Context;
5+
import android.content.SharedPreferences;
56
import android.database.Cursor;
67
import android.database.sqlite.SQLiteDatabase;
78
import android.support.v7.app.AppCompatActivity;
@@ -11,13 +12,17 @@
1112
import android.view.View;
1213
import android.widget.DatePicker;
1314
import android.widget.EditText;
15+
import android.widget.Switch;
1416
import android.widget.Toast;
1517

1618
import java.text.SimpleDateFormat;
1719
import java.util.Calendar;
1820
import java.util.Locale;
1921

2022
public class SendCommonMessage extends AppCompatActivity {
23+
SharedPreferences sharedpreferences;
24+
public static final String MyPREFERENCES = "MyPrefs" ;
25+
Boolean isSeviceMessage;
2126

2227
@Override
2328
protected void onCreate(Bundle savedInstanceState) {
@@ -86,16 +91,20 @@ public void onClick(View v) {
8691
}
8792
});
8893

94+
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
95+
isSeviceMessage = sharedpreferences.getBoolean("serviceMessage", false);
96+
97+
8998
}
9099

91100
public void sendCommonMessage(View v){
92101
EditText reasonField = (EditText) findViewById(R.id.reason);
93102
EditText fromField = (EditText) findViewById(R.id.fromdate);
94103
EditText toField = (EditText) findViewById(R.id.todate);
95-
96104
SQLiteDatabase mydb=openOrCreateDatabase("CustomerDB", Context.MODE_PRIVATE, null);
97105
String query_active = "SELECT name,mobile FROM customer WHERE activestat=1";
98106
Cursor c=mydb.rawQuery(query_active, null);
107+
99108
while(c.moveToNext()) {
100109
String nameCustomer = c.getString(0);
101110
String phoneNumber = c.getString(1);
@@ -107,7 +116,15 @@ public void sendCommonMessage(View v){
107116
message = "Dear " + nameCustomer + ",\nDue to " + reasonField.getText().toString() +", gym will be closed from " + fromField.getText().toString() + " to " + toField.getText().toString() + ".\nSorry for the inconvenience :(\nThanks,\nBody Fitness Zone";
108117
}
109118
if (phoneNumber.length() > 0 && message.length() > 0) {
110-
sendSms(phoneNumber, message);
119+
Log.d("here","here");
120+
if(isSeviceMessage){
121+
SendMessage sendSM = new SendMessage();
122+
sendSM.execute(phoneNumber, message);
123+
}
124+
else{
125+
sendSms(phoneNumber, message);
126+
}
127+
111128
} else
112129
Toast.makeText(getBaseContext(),
113130
"Please enter both phone number and message.",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.aina.dummydatabase;
2+
import android.os.AsyncTask;
3+
import android.util.Log;
4+
5+
import java.io.BufferedReader;
6+
import java.io.InputStreamReader;
7+
import java.net.HttpURLConnection;
8+
import java.net.URL;
9+
10+
11+
class SendMessage extends AsyncTask<String, Void, Void> {
12+
13+
private Exception exception;
14+
15+
protected Void doInBackground(String... params) {
16+
try {
17+
// Construct data
18+
String apiKey = "apikey=" + "yLfTYJ4iajg-dwj4lcYRfgizQyySeY8BYgxaFWmVcB";
19+
String message = "&message=" + params[1];
20+
String sender = "&sender=" + "TXTLCL";
21+
String numbers = "&numbers=" + params[0];
22+
23+
// Send data
24+
HttpURLConnection conn = (HttpURLConnection) new URL("https://api.textlocal.in/send/?").openConnection();
25+
String data = apiKey + numbers + message + sender;
26+
conn.setDoOutput(true);
27+
conn.setRequestMethod("POST");
28+
conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
29+
conn.getOutputStream().write(data.getBytes("UTF-8"));
30+
final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
31+
final StringBuffer stringBuffer = new StringBuffer();
32+
String line;
33+
while ((line = rd.readLine()) != null) {
34+
stringBuffer.append(line);
35+
}
36+
rd.close();
37+
} catch (Exception e) {
38+
Log.d("Error: ",e.toString());
39+
}
40+
return null;
41+
}
42+
}

app/src/main/res/layout/activity_functionality.xml

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@
6969
android:onClick="logoutClick"
7070
android:text="Log Out" />
7171

72+
<Switch
73+
android:id="@+id/serviceMessage"
74+
android:layout_width="match_parent"
75+
android:layout_height="wrap_content"
76+
android:text="Service Message" />
77+
7278
<LinearLayout
7379
android:layout_width="match_parent"
7480
android:layout_height="wrap_content"

0 commit comments

Comments
 (0)