Você está na página 1de 67

BILL

MANAGER

About.java

Coding:
public class About extends android.app.Fragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.about, container, false);
return v;
}
}

Compare.java

Coding:

public class Compare extends Fragment {


DatabaseHelper myDb;
TextView txtTotalSame, txtTotalOther, txtNetwork, txtTotalAll, txtTotalSMS,
txtSameSMS,txtOtherSMS;
@Override
public View onCreateView(LayoutInflater inflater,@Nullable ViewGroup container,
@Nullable Bundle bundle){
final View v = inflater.inflate(R.layout.compare, container, false);
myDb = new DatabaseHelper(getActivity());
myDb.getWritableDatabase();
txtTotalSame = (TextView) v.findViewById(R.id.txtTotalSame);
txtTotalOther = (TextView) v.findViewById(R.id.txtTotalOther);
txtNetwork = (TextView) v.findViewById(R.id.txtNetwork);
txtTotalAll = (TextView) v.findViewById(R.id.txtTotalAll);
txtTotalSMS = (TextView) v.findViewById(R.id.txtTotalSMSAll);
txtSameSMS = (TextView) v.findViewById(R.id.txtTotalSMSSame);
txtOtherSMS = (TextView) v.findViewById(R.id.txtTotalSMSOther);
Cursor getData = myDb.getRate();
if( getData.getCount() == 0){
//remove "RateNumber" from sharedpreferences
final SharedPreferences preferences =
getActivity().getPreferences(getActivity().MODE_PRIVATE);
preferences.edit().remove("RateNumber").commit();
}
//check if first time
if(isFirstTime()){
}
Cursor hpCelcom = myDb.getCelcomHp();
Cursor hpDigi = myDb.getDigiHp();
Cursor hpMaxis = myDb.getMaxisHp();
//get the count of rows inside the table phone
int decideCelcom = hpCelcom.getCount();
int decideMaxis = hpMaxis.getCount();

int decideDigi = hpDigi.getCount();


hpCelcom.close();
hpDigi.close();
hpMaxis.close();
//check if there's a row inside
if (decideCelcom == 1){
txtNetwork.setText("Network
}else if (decideMaxis == 1){
txtNetwork.setText("Network
}else if (decideDigi == 1){
txtNetwork.setText("Network
}else{
txtNetwork.setText("Network
}

the table, then display the network type


Type: Celcom");
Type: Maxis");
Type: Digi");
Type: Unknown");

//execute the process


try{
doProcess();
doProcess2();
}catch (Exception e){
e.printStackTrace();
}
//setting up the format
final DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
//get the
String sa
String sb
float a =
float b =

total cost for both same and other


= txtTotalOther.getText().toString();
= txtTotalSame.getText().toString();
Float.parseFloat(sa.substring(sa.lastIndexOf("M") + 1));
Float.parseFloat(sb.substring(sb.lastIndexOf("M") + 1));

//animation for the textview


ValueAnimator animator = new ValueAnimator();
animator.setFloatValues(0, b);
animator.setDuration(5000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtTotalSame.setText("RM" + df.format(animation.getAnimatedValue()));
}
});
animator.start();
//animation for the textview
ValueAnimator animatorTotal = new ValueAnimator();
animatorTotal.setFloatValues(0,(a+b));
animatorTotal.setDuration(5000);
animatorTotal.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtTotalAll.setText("RM" + df.format(animation.getAnimatedValue()));
}
});
animatorTotal.start();
//animation for the textview
//get total values for sms
String d1 = txtSameSMS.getText().toString();
String d2 = txtOtherSMS.getText().toString();
int da = Integer.parseInt(d1.replaceAll("\\D+",""));
int db = Integer.parseInt(d2.replaceAll("\\D+",""));
int total = da+db;

//if the total is higher than 100, convert from sen to RM


if(total > 100){
ValueAnimator anim = new ValueAnimator();
anim.setFloatValues(0,(float)(total/100));
anim.setDuration(5000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtTotalSMS.setText("RM" +
df.format(animation.getAnimatedValue()));
}
});
anim.start();
}
//shows the value in sen
else if(total < 100){
ValueAnimator anim = new ValueAnimator();
anim.setObjectValues(0, da + db);
anim.setDuration(5000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtTotalSMS.setText(animation.getAnimatedValue() + " Sen");
}
});
anim.start();
}
ValueAnimator animTotalSMS = new ValueAnimator();
animTotalSMS.setObjectValues(0, da);
animTotalSMS.setDuration(5000);
animTotalSMS.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtSameSMS.setText(animation.getAnimatedValue() + " Sen");
}
});
animTotalSMS.start();
ValueAnimator animSameSMS = new ValueAnimator();
animSameSMS.setObjectValues(0, db);
animSameSMS.setDuration(5000);
animSameSMS.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
txtOtherSMS.setText(animation.getAnimatedValue() + " Sen");
}
});
animSameSMS.start();
return v;
}
public void doProcess(){ //untuk call
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
String
String
String
String

//format setter

selectedId = txtNetwork.getText().toString();
celcom = "Network Type: Celcom";
digi = "Network Type: Digi";
maxis = "Network Type: Maxis";

myDb.getWritableDatabase();
String tCost, finalValue;
float val;

Cursor getData = myDb.totalCost();


if (selectedId == celcom) { //if celcom
countSMSCelcomSame();
//calculate call cost
calculateSameCelcom(); //calculate sms cost
getData.moveToFirst();
tCost = getData.getString(0).toString();
val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
txtTotalSame.setText("RM" + finalValue);
myDb.deleteCost();
getData.close();
}
else if(selectedId == digi) {

//if digi

calculateSameDigi();
//calculate call cost
getData.moveToFirst(); //calculate sms cost
tCost = getData.getString(0).toString();
val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
txtTotalSame.setText("RM" + finalValue);
countSMSDigiSame();
myDb.deleteCost();
getData.close();
}
else if(selectedId == maxis) {

//if maxis

calculateSameMaxis();
//calculate call cost
countSMSMaxisSame();
//calculate sms cost
getData.moveToFirst();
tCost = getData.getString(0).toString();
val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
txtTotalSame.setText("RM" + finalValue);
myDb.deleteCost();
getData.close();
}
}
public void doProcess2(){

//untuk sms

//format setter
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
//get the type of network
String selectedId = txtNetwork.getText().toString();
String celcom = "Network Type: Celcom";
String digi = "Network Type: Digi";
String maxis = "Network Type: Maxis";
myDb.getWritableDatabase();
String tCost, finalValue;
float val;
Cursor getData = myDb.totalCost();
//check the type of network then execute the proper function
if (selectedId == celcom) {
calculateOtherCelcom(); //calculate call cost
countSMSCelcomOther(); //calculate sms cost
getData.moveToFirst();
tCost = getData.getString(0).toString();

val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
String msg = "RM" + finalValue;
txtTotalOther.setText(msg);
myDb.deleteCost();
getData.close();
}
else if(selectedId == digi) {
calculateOtherDigi();
//calculate call cost
countSMSDigiOther();
//calculate sms cost
getData.moveToFirst();
tCost = getData.getString(0).toString();
val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
String msg = "RM" + finalValue;
txtTotalOther.setText(msg);
myDb.deleteCost();
getData.close();
}
else if(selectedId == maxis) {
calculateOtherMaxis(); //calculate call cost
getData.moveToFirst();
countSMSMaxisOther();
//calculate sms cost
tCost = getData.getString(0).toString();
val = Float.parseFloat(tCost);
finalValue = String.valueOf(df.format(val / 100));
String msg = "RM" + finalValue;
txtTotalOther.setText(msg);
myDb.deleteCost();
getData.close();
}
}
//calculate rate to celcom number if you're celcom
public void calculateSameCelcom(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(0));
String stime = getData.getString(1);
final int time = (Integer.valueOf(stime)) * (60);
//uses cursor to get data
Cursor celcom = myDb.getDataCelcom();
//for the integer formatting
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
while (celcom.moveToNext()) {
int dur = Integer.parseInt(celcom.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost);
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));

} else if (dur > time) {


float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
}
}
}
//calculate charge to other number if you're celcom
public void calculateOtherCelcom(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(2));
String stime = getData.getString(3);
final int time = (Integer.valueOf(stime)) * (60);
getData.close();
//using cursor to get data
Cursor maxis = myDb.getDataMaxis();
Cursor digi = myDb.getDataDigi();
//for the integer formatting
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
//get cost for maxis
while (maxis.moveToNext()) {
int dur = Integer.parseInt(maxis.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
//insert
data into total data table
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
data into total data table
}
}

//insert

//get cost for digi


while (digi.moveToNext()) {
int dur = Integer.parseInt(digi.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
//insert
data into total data table
} else if (dur > time) {

float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
data into total data table
}
}
//closing the cursor
maxis.close();
digi.close();
}

//insert

//calculate if the user network is digi


public void calculateSameDigi(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(0));
String stime = getData.getString(1);
final int time = (Integer.valueOf(stime)) * (60);
getData.close();
//use a cursor to get data inside the database
Cursor digi = myDb.getDataDigi();
//for the integer formatting
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
while (digi.moveToNext()) {
int dur = Integer.parseInt(digi.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf((price) * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
//insert
data into total data table
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
data into total data table
}
}
//close cursor
digi.close();
}
//calculate charge to other number if you're digi
public void calculateOtherDigi(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(2));
String stime = getData.getString(3);
final int time = (Integer.valueOf(stime)) * (60);
getData.close();

//insert

//use a cursor to get data inside the database


Cursor maxis = myDb.getDataMaxis();
Cursor celcom = myDb.getDataCelcom();
//for the integer formatting
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
//get cost for maxis
while (maxis.moveToNext()) {
int dur = Integer.parseInt(maxis.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
//insert
data into total data table
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
data into total data table
}
}

//insert

//get cost for celcom


while (celcom.moveToNext()) {
int dur = Integer.parseInt(celcom.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost);
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
}
}
//close the cursor
maxis.close();
celcom.close();
}
//calculate charge to maxis if you're maxis
public void calculateSameMaxis(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(0)); //get price from rate
table
String stime = getData.getString(1);

//get minutes from rate table

final int time = (Integer.valueOf(stime)) * (60);


getData.close();
Cursor maxis = myDb.getDataMaxis();
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);
while (maxis.moveToNext()) {
int dur = Integer.parseInt(maxis.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost);
} else if (dur <= time) {
float cost;
cost = Float.valueOf((price) * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
}
}
}
//calculate charge to other number if you're maxis
public void calculateOtherMaxis(){
myDb.getWritableDatabase();
Cursor getData = myDb.getRate();
getData.moveToFirst();
int price = Integer.parseInt(getData.getString(2)); //get price from rate
table
String stime = getData.getString(3);
//get minutes from rate table
final int time = (Integer.valueOf(stime)) * (60);
getData.close();
Cursor digi = myDb.getDataDigi();
Cursor celcom = myDb.getDataCelcom();
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.DOWN);

//format setter

while (digi.moveToNext()) {
//calculate cost for digi
int dur = Integer.parseInt(digi.getString(1));
if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
}
}
while (celcom.moveToNext()) {
//calculate cost for celcom
int dur = Integer.parseInt(celcom.getString(1));

if (dur == 0) {
int cost;
cost = 0;
myDb.insertTotalData(cost); //insert data into total data table
} else if (dur <= time) {
float cost;
cost = Float.valueOf(price * 2);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
} else if (dur > time) {
float cost;
int val = dur / time;
int calculated = price;
cost = Float.valueOf(calculated * val);
myDb.insertTotalData(Integer.parseInt(df.format(cost)));
}
}
digi.close();
celcom.close();
}

//check if it is the first time user installed the apps


//if its true, this funtion will execute the function displayRate()
private boolean isFirstTime(){
//set a boolean value false into the preferences "RateNumber"
final SharedPreferences preferences =
getActivity().getPreferences(getActivity().MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RateNumber", false);
if (!ranBefore){
//if never ran before, execute displayrate and smsrate function
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RateNumber", true);
editor.commit();
displayRate();
SMSRate();
}
return ranBefore;
}
public void displayRate(){
//declaring the textbox for data input
final EditText txtInput = new EditText(getActivity());
final EditText txtDur = new EditText(getActivity());
final EditText otherInput = new EditText(getActivity());
final EditText otherDur = new EditText(getActivity());
final TextView string1 = new TextView(getActivity());
final TextView string2 = new TextView(getActivity());
string1.setText("Same Network :");
string1.setPadding(30, 8, 0, 0);
//adjusting the padding
string1.setTextColor(Color.parseColor("#000000")); //setting the text color
string2.setText("Other Network :");
string2.setPadding(30, 8, 0, 0);
//adjusting the padding
string2.setTextColor(Color.parseColor("#000000")); //setting the text color
txtInput.setHint("Cost in Sen");
txtInput.setInputType(InputType.TYPE_CLASS_NUMBER); //setting the keyboard type
txtDur.setHint("Duration in Minutes");
txtDur.setInputType(InputType.TYPE_CLASS_NUMBER);
//setting the keyboard type
otherDur.setHint("Duration in Minutes");

otherDur.setInputType(InputType.TYPE_CLASS_NUMBER); //setting the keyboard type


otherInput.setHint("Cost in Sen");
otherInput.setInputType(InputType.TYPE_CLASS_NUMBER);
//setting the keyboard type
//creating an interface inside here instead of using the xml
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(string1);
linearLayout.addView(txtInput);
linearLayout.addView(txtDur);
linearLayout.addView(string2);
linearLayout.addView(otherInput);
linearLayout.addView(otherDur);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

//declaring dialog

box
builder
.setTitle("Rate Charges")
.setView(linearLayout) //set the linearLayout as the view of the dialog box
.setPositiveButton("Save", new DialogInterface.OnClickListener() { //on save
click
@Override
public void onClick(DialogInterface dialog, int which) {
myDb.getWritableDatabase();
int d1 = Integer.parseInt(txtInput.getText().toString());
String d2 = txtDur.getText().toString();
int d3 = Integer.parseInt(otherInput.getText().toString());
String d4 = otherDur.getText().toString();
if (txtInput.length() > 0 && txtDur.length() > 0 && otherInput.length() >
0 && otherDur.length() > 0) {
//inserting data into the database using query "insert"
boolean result = myDb.insertRate(d1, d2, d3, d4);
if (result == true) {
//hoping to refresh the view after the data have been inserted
Toast.makeText(getActivity(), "Rate Inserted",
Toast.LENGTH_SHORT).show();
Fragment newFragment =
getFragmentManager().findFragmentByTag("compare");
FragmentTransaction transaction =
getFragmentManager().beginTransaction();
transaction.detach(newFragment);
transaction.attach(newFragment);
transaction.commit();
}
} else {
Toast.makeText(getActivity(), "Please complete all the field !",
Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//get the sharedpreferences with the specific string, then remove it.
final SharedPreferences preferences =
getActivity().getPreferences(getActivity().MODE_PRIVATE);
preferences.edit().remove("RateNumber").commit();
}
})
.show();
//show the dialog box
}

public void SMSRate(){


final
final
final
final

EditText
EditText
TextView
TextView

txtInput = new EditText(getActivity());


otherInput = new EditText(getActivity());
string1 = new TextView(getActivity());
string2 = new TextView(getActivity());

string1.setText("Same Network : ");


string1.setPadding(30, 8, 0, 0);
//adjusting the padding
string1.setTextColor(Color.parseColor("#000000")); //set text color
string2.setText("Other Network : ");
string2.setPadding(30, 8, 0, 0);
//adjusting the padding
string2.setTextColor(Color.parseColor("#000000")); //set text color
txtInput.setHint("Price (in sen)/ SMS");
txtInput.setInputType(InputType.TYPE_CLASS_NUMBER); //keyboard type
otherInput.setHint("Price (in sen) / SMS");
otherInput.setInputType(InputType.TYPE_CLASS_NUMBER);

//keyboard type

//creating the interface hardcoded


LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(string1);
linearLayout.addView(txtInput);
linearLayout.addView(string2);
linearLayout.addView(otherInput);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
//dialog box
builder.setTitle("SMS Rate Charges")
.setView(linearLayout)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int d1 = Integer.parseInt(txtInput.getText().toString());
int d2 = Integer.parseInt(otherInput.getText().toString());
if (txtInput.length() > 0 && otherInput.length() > 0) {
boolean result = myDb.insertSMSRate(d1, d2);
//insert data into
table
if (result == true) {
Toast.makeText(getActivity(), "SMS Rate Inserted",
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(),"Complete all the
field !",Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", null)
.show();
}
public void countSMSCelcomSame(){

//get the sms cost for celcom

myDb.getWritableDatabase();
Cursor getDataSMS = myDb.getCelcomSMS();
int celcomSms = getDataSMS.getCount();
getDataSMS.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(0));
int totalSum = celcomSms * rate;

txtSameSMS.setText(String.valueOf(totalSum));

//set the total value into textview

}
public void countSMSCelcomOther(){

//get sms cost to other telco if you're celcom

myDb.getWritableDatabase();
Cursor maxis = myDb.getMaxisSMS();
int maxisCount = maxis.getCount();
maxis.close();
Cursor digi = myDb.getDigiSMS();
int digiCount = digi.getCount();
digi.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(1));
int totalMaxis = (maxisCount * rate);
int totalDigi = (digiCount * rate);
int totalRest = totalDigi + totalMaxis;
txtOtherSMS.setText(String.valueOf(totalRest));
}
public void countSMSDigiSame(){ //get sms cost if you're using digi
myDb.getWritableDatabase();
Cursor getDataSMS = myDb.getDigiSMS();
int digiSms = getDataSMS.getCount();
getDataSMS.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(0));
int totaldigi = (digiSms * rate)/100;
TextView txtTotalSame = (TextView) getActivity().findViewById(R.id.txtTotalSMSSame);
txtTotalSame.setText("RM"+String.valueOf(totaldigi));
}
public void countSMSDigiOther(){

//get sms cost to other telco

myDb.getWritableDatabase();
Cursor maxis = myDb.getMaxisSMS();
int maxisCount = maxis.getCount();
maxis.close();
Cursor celcom = myDb.getCelcomSMS();
int celcomCount = celcom.getCount();
celcom.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(1));
int totalMaxis = (maxisCount * rate)/100;
int totalCelcom = (celcomCount * rate)/100;
int totalRest = totalCelcom + totalMaxis;
TextView txtTotalOther = (TextView) getActivity().findViewById(R.id.txtTotalSMSOther);
txtTotalOther.setText("RM" + String.valueOf(totalRest));
}
public void countSMSMaxisSame(){

//get sms cost if you're maxis

myDb.getWritableDatabase();
Cursor getDataSMS = myDb.getMaxisSMS();
int maxisSms = getDataSMS.getCount();
getDataSMS.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(0));
int totalMaxis = (maxisSms * rate)/100;
TextView txtTotalSame = (TextView) getActivity().findViewById(R.id.txtTotalSMSSame);
txtTotalSame.setText("RM"+String.valueOf(totalMaxis));
}
public void countSMSMaxisOther(){

//get sms cost to other telco

myDb.getWritableDatabase();
Cursor celcom = myDb.getCelcomSMS();
int celcomCount = celcom.getCount();
celcom.close();
Cursor digi = myDb.getDigiSMS();
int digiCount = digi.getCount();
digi.close();
Cursor getRate = myDb.getDataSMSRate();
getRate.moveToFirst();
int rate = Integer.parseInt(getRate.getString(1));
int totalCelcom = (celcomCount * rate)/100;
int totalDigi = (digiCount * rate)/100;
int totalRest = totalDigi + totalCelcom;
TextView txtTotalOther = (TextView) getActivity().findViewById(R.id.txtTotalSMSOther);
txtTotalOther.setText("RM"+String.valueOf(totalRest));
}
}

DataUsage.java

Coding:
public class DataUsage extends Fragment {
CharSequence Titles[] = {"WIFI","ROAMING"};
int Numboftabs = 2;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.datausage, container, false);
//set the sliding tab animation for the DataUsage layout
ViewPager viewPager = (ViewPager) v.findViewById(R.id.pager);
viewPager.setAdapter(new ViewPagerAdapter(getFragmentManager(), Titles,
Numboftabs));
return v;
}
}

Details.java

Coding:
public class Details {
private String _phone,_type,_date,_duration,_name,_country;
public Details(String phone, String type, String date, String duration, String
name,String country){
_phone = phone;
_type = type;
_date = date;
_duration = duration;
_name = name;
_country = country;
}
public String getPhone(){
return _phone;
}
public String getType(){
return _type;
}
public String getDate(){
return _date;
}
public String getDuration(){
return _duration;
}
public String getName(){
return _name;
}
public String getCountry(){
return _country;
}
}

Incoming.java

Coding:
public class Incoming extends AppCompatActivity {
private PieChart mChart;
int nToday, nWeek, nMonth;
String[] xData = {"Today", "Week", "Month"};
DatabaseHelper myDb;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.incoming);
//just to ensure the connection is not null
myDb = new DatabaseHelper(this);
myDb.getWritableDatabase();
mChart = new PieChart(this);
//set the toolbar to have the back button enabled when user open this layout
//set the title of the toolbar to change
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Incoming Calls");
mChart = (PieChart) findViewById(R.id.incomingPie);
Button btnDay = (Button) findViewById(R.id.btnInToday);
btnDay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open the IncomingToday layout
Intent openday = new Intent(getApplicationContext(),
IncomingToday.class);
startActivity(openday);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnWeek = (Button) findViewById(R.id.btnIn7);
btnWeek.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
//open the IncomingWeek layout
Intent openWeek = new Intent(getApplicationContext(),
IncomingWeek.class);
startActivity(openWeek);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnMonth = (Button) findViewById(R.id.btnInMonth);
btnMonth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open the IncomingMonth layout
Intent openMonth = new Intent(getApplicationContext(),
IncomingMonth.class);
startActivity(openMonth);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
//add pie chart to intended layout
//configure pie chart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(20);
mChart.setTransparentCircleRadius(10);
//enable rotation of the chart by touch
mChart.setRotationAngle(0);
mChart.setRotationEnabled(true);
mChart.setDescription("");
//set a chart value selected listener
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(Incoming.this, xData[e.getXIndex()] + " " + e.getVal()
+ " in total ", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {
}
});
//Add data
addData();
// customize legends
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
}
private void addData() {
myDb.getWritableDatabase();

//get total row of 3 of these table


Cursor getDataIn = myDb.getDataIncoming();
nToday = getDataIn.getCount();
getDataIn.close();
Cursor getDataIn7 = myDb.getDataIncoming7();
nWeek = getDataIn7.getCount();
getDataIn7.close();
Cursor getDataIn30 = myDb.getDataIncoming30();
nMonth = getDataIn30.getCount();
getDataIn30.close();
int[] yData = {nToday, nWeek, nMonth};
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setSliceSpace(5);
dataSet.setSelectionShift(15);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//instantiate pie data object now
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);
//undo all highlights
mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
}

IncomingMonth.java & IncomingWeek.java & IncomingToday.java

Coding:
public class IncomingMonth extends AppCompatActivity {
DatabaseHelper myDb;
ListView outgoinglv;
List<Details> detailList = new ArrayList<Details>();
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.outgoing_today);
//just to ensure the connection is not null
myDb = new DatabaseHelper(this);
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
//set the toolbar to have the back button enabled when user open this layout
//set the title of the toolbar to change
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Monthly Log");
outgoinglv = (ListView) findViewById(R.id.outgoinglv1); //declaring the
listview
Cursor getData = myDb.getDataIncoming30();
getData.moveToFirst();
//get data inside the table Incoming30
while(!getData.isAfterLast()){
String phone = getData.getString(0);
String type = getData.getString(1);
String date = getData.getString(2);
String duration = getData.getString(3);
String name = getData.getString(4);
String country = getData.getString(5);
addIncomingDetails(phone,type,date,duration,name,country);
getData.moveToNext();
}
getData.close();
//inserting data of arrayadapter inside the adapter

final ArrayAdapter<Details> adapter = new OutgoingTodayAdapter();


//set the adapter for the listview
outgoinglv.setAdapter(adapter);
//if the data is empty, it will show this layout
outgoinglv.setEmptyView(findViewById(R.id.empty));
}
private void addIncomingDetails(String phone,String type,String date,String
duration,String name,String country){
//insert data into the class Details
detailList.add(new Details(phone,type,date,duration,name,country));
}
private class OutgoingTodayAdapter extends ArrayAdapter<Details>{
public OutgoingTodayAdapter(){
super(IncomingMonth.this,R.layout.lvtrackdetails,detailList);
}
@Override
public View getView(int pos,View view,ViewGroup parent){
if(view == null)
view =
getLayoutInflater().inflate(R.layout.lvtrackdetails,parent,false);
//get the array values with respective postion
Details currentDetails = detailList.get(pos);
//set data to each textview
TextView phone = (TextView) view.findViewById(R.id.txtNum);
phone.setText(currentDetails.getPhone());
TextView type = (TextView) view.findViewById(R.id.txtType);
type.setText(currentDetails.getType());
TextView date = (TextView) view.findViewById(R.id.txtDate);
date.setText(currentDetails.getDate());
TextView duration = (TextView) view.findViewById(R.id.txtDuration);
duration.setText(currentDetails.getDuration());
TextView name = (TextView) view.findViewById(R.id.txtName);
if(currentDetails.getName() == null){
//if theres no name for the
contact, set name to 'Not Set'
name.setText("Not Set");
}else{
name.setText(currentDetails.getName());
}
TextView country = (TextView) view.findViewById(R.id.txtCountry);
country.setText(currentDetails.getCountry());
return view;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
//when arrow button on the
toolbar pressed, current layout is destroyed
finish();
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
return super.onOptionsItemSelected(menuItem);
}
}

IncomingSMS.java

Coding:
public class IncomingSMS extends AppCompatActivity {
private PieChart mChart;
int nToday, nWeek, nMonth;
String[] xData = {"Today", "Week", "Month"};
DatabaseHelper myDb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.incomingsms);
myDb = new DatabaseHelper(this);
myDb.getWritableDatabase();
mChart = new PieChart(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
//animate the
hamburger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //animate the
hamburger icon
getSupportActionBar().setTitle("Incoming SMS");
mChart = (PieChart) findViewById(R.id.incomingPie);
Button btnDay = (Button) findViewById(R.id.btnInToday);
btnDay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open the IncomingToday layout
Intent openday = new Intent(getApplicationContext(),
IncomingSMSToday.class);
startActivity(openday);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnMonth = (Button) findViewById(R.id.btnInMonth);
btnMonth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open the IncomingMonth layout

Intent openMonth = new Intent(getApplicationContext(),


IncomingSMSMonth.class);
startActivity(openMonth);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnWeek = (Button) findViewById(R.id.btnIn7);
btnWeek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//open the IncomingWeek layout
Intent openWeek = new Intent(getApplicationContext(),
IncomingSMSWeek.class);
startActivity(openWeek);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
//add pie chart to intended layout
//configure pie chart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(20);
mChart.setTransparentCircleRadius(10);
//enable rotation of the chart by touch
mChart.setRotationAngle(0);
mChart.setRotationEnabled(true);
mChart.setDescription("");
//set a chart value selected listener
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(IncomingSMS.this, xData[e.getXIndex()] + " " +
e.getVal() + " in total ", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {
}
});
//Add data
addData();
// customize legends
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
}
private void addData() {
myDb.getWritableDatabase();
//get total row of 3 of these table
Cursor getDataIn = myDb.getDataSMSIn();
nToday = getDataIn.getCount();

getDataIn.close();
Cursor getDataIn7 = myDb.getDataSMSIn7();
nWeek = getDataIn7.getCount();
getDataIn7.close();
Cursor getDataIn30 = myDb.getDataSMSIn30();
nMonth = getDataIn30.getCount();
getDataIn30.close();
int[] yData = {nToday, nWeek, nMonth};
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setSliceSpace(5);
dataSet.setSelectionShift(15);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//instantiate pie data object now
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);
//undo all highlights
mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
}

IncomingSMSToday.java & IncomingSMSWeek.java &


IncomingSMSMonth.java

Coding:
public class IncomingSMSToday extends AppCompatActivity{
DatabaseHelper myDb;
ListView outgoinglv;
List<SMSDetails> detailList = new ArrayList<SMSDetails>();
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.smslistview);
myDb = new DatabaseHelper(this);
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
//set the toolbar to have the back button enabled when user open this layout
//set the title of the toolbar to change
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Daily Log");
outgoinglv = (ListView) findViewById(R.id.smslv);
Cursor getData = myDb.getDataSMSIn();
getData.moveToFirst();
while (!getData.isAfterLast()){
String phone = getData.getString(0);
String date = getData.getString(1);
String text = getData.getString(3);
addIncomingDetails(phone,date,text);
getData.moveToNext();
}
getData.close();
//inserting data of arrayadapter inside the adapter

final ArrayAdapter<SMSDetails> adapter = new IncomingSMSTodayAdapter();


//set the adapter for the listview
outgoinglv.setAdapter(adapter);
//if the data is empty, it will show this layout
outgoinglv.setEmptyView(findViewById(R.id.empty));
outgoinglv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
TextView smscontent = (TextView) view.findViewById(R.id.txtMsg);
AlertDialog.Builder builder = new
AlertDialog.Builder(IncomingSMSToday.this);
builder.setTitle("Message Content")
.setMessage(smscontent.getText().toString())
.setNeutralButton("Close", null)
.show();
}
});
}
private void addIncomingDetails(String phone,String date,String msg){
//insert data into the class Details
detailList.add(new SMSDetails(phone,date,msg));
}
private class IncomingSMSTodayAdapter extends ArrayAdapter<SMSDetails>{
public IncomingSMSTodayAdapter(){
super(IncomingSMSToday.this,R.layout.smstrackdetails,detailList);
}
@Override
public View getView(int pos,View view,ViewGroup parent){
if(view == null)
view =
getLayoutInflater().inflate(R.layout.smstrackdetails,parent,false);
//get the array values with respective postion
SMSDetails currentDetails = detailList.get(pos);
//set data to each textview
TextView phone = (TextView) view.findViewById(R.id.txtNum);
phone.setText(currentDetails.getPhone());
TextView date = (TextView) view.findViewById(R.id.txtDate);
date.setText(currentDetails.getDate());
TextView msg = (TextView) view.findViewById(R.id.txtMsg);
msg.setText(currentDetails.getMsg());
return view;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
//destroy the layout when
back button pressed
finish();
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
return super.onOptionsItemSelected(menuItem);
}
}

MainActivity.java

Coding:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ActionBarDrawerToggle toggle;
Toolbar toolbar;
DatabaseHelper myDb;
String num;
int costsame,costother;
//NOTE:
//this is not the MainActivity of the application
//The Main Activity for the apps is SplashScreen
//Refer to manifest for more info
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//set animation for the toolbar when the apps start
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(500).translationY(0).alpha(1);
for toolbar
setSupportActionBar(toolbar);

//animation

myDb = new DatabaseHelper(this);


//set the main fragment that will pop first
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, new Track(), "track");
ft.commit();
getSupportActionBar().setTitle("Track Calls");
//declaring the navigation drawer
final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView nv = (NavigationView) findViewById(R.id.nav_view);
nv.setItemIconTintList(null);
toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close){

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
//when drawer open, the toolbar title will change
getSupportActionBar().setTitle("Bill Manager");
}
@Override
public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);
}
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
//check the fragment name, then when drawer closed. The toolbar title
will change
Track track = (Track)getFragmentManager().findFragmentByTag("track");
Compare compare =
(Compare)getFragmentManager().findFragmentByTag("compare");
TrackSMS sms =
(TrackSMS)getFragmentManager().findFragmentByTag("sms");
About about = (About)getFragmentManager().findFragmentByTag("about");
DataUsage du =
(DataUsage)getSupportFragmentManager().findFragmentByTag("data");
if(track != null && track.isVisible()){
getSupportActionBar().setTitle("Track Calls");
}
if(compare != null && compare.isVisible()){
getSupportActionBar().setTitle("Compare Charge");
}
if(sms != null && sms.isVisible()){
getSupportActionBar().setTitle("Track SMS");
}
if(about != null && about.isVisible()){
getSupportActionBar().setTitle("About");
}
if(du != null && du.isVisible()){
getSupportActionBar().setTitle("Data Usage");
}
}
};
//set the background color to transparent when the drawer open
drawer.setScrimColor(getResources().getColor(android.R.color.transparent));
//adding the drawer
drawer.setDrawerListener(toggle);
toggle.syncState();
//check if its the first time user open the apps
if(isFirstTime()){
//do nothing
}
nv.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
//when back button is pressed, the drawer will open/close
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else{
drawer.openDrawer(GravityCompat.START);
}

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
Fragment newFragment;
FragmentTransaction transaction = getFragmentManager().beginTransaction();
switch (item.getItemId()) {
case R.id.action_settings:
//open dialog box to update phone number
displayNumUpdate();
return true;
case R.id.action_rate:
//open dialog box to update rate charges
displayRateUpdate();
return true;
case R.id.action_smsrate:
//open dialog box to update sms rate
SMSRateUpdate();
return true;
case R.id.action_exit:
//exit the apps
this.finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return true;
case R.id.action_about:
//open the about layout
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("About");
newFragment = new About();
transaction.replace(R.id.content_frame,newFragment);
transaction.addToBackStack(null);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
transaction.commit();
return true;
default:
return false;
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment newFragment;
android.support.v4.app.Fragment newFragment1;
FragmentTransaction transaction = getFragmentManager().beginTransaction();
android.support.v4.app.FragmentTransaction transaction1 =
getSupportFragmentManager().beginTransaction();
int id = item.getItemId();
RelativeLayout relativeLayout =
(RelativeLayout)findViewById(R.id.content_frame);
if (id == R.id.nav_trackCalls) {
relativeLayout.removeAllViews();
//clear the views
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("Track Calls");
//change the toolbar
title
newFragment = new Track();

transaction.replace(R.id.content_frame,newFragment,"track");
//replace the views and set fragment id
transaction.addToBackStack(null);
//add the fragment to the
backstack
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
//transition animation
transaction.commit();
} else if (id == R.id.nav_trackSMS) {
relativeLayout.removeAllViews();
//clear the views
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("Track SMS");
//change the toolbar title
newFragment = new TrackSMS();
transaction.replace(R.id.content_frame,newFragment,"sms"); //replace the
views and set fragment id
transaction.addToBackStack(null);
//add the fragment to the
backstack
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
//transition animation
transaction.commit();
} else if (id == R.id.nav_compare) {
relativeLayout.removeAllViews();
//clear the views
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setTitle("Compare Charges");
//set toolbar
title
newFragment = new Compare();
transaction.replace(R.id.content_frame,newFragment,"compare");
//replace the view and set fragment id
transaction.addToBackStack(null);
//add the fragment to the
backstack
overridePendingTransition(R.animator.fadein,R.animator.fadeout);
//transition animation
transaction.commit();
} else if (id == R.id.nav_data) {
relativeLayout.removeAllViews();
//clear the views
getSupportActionBar().setHomeButtonEnabled(false);
//animate the
burger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
//animate the
burger icon
getSupportActionBar().setTitle("Data Usage");
//change the toolbar
title
newFragment1 = new DataUsage();
transaction1.replace(R.id.content_frame,newFragment1,"data");
//replace the view and set fragment id
transaction1.addToBackStack(null);
//add the fragment to the
backstack
overridePendingTransition(R.animator.fadein,R.animator.fadeout);
//transition animation
transaction1.commit();
} else if (id == R.id.nav_about) {
relativeLayout.removeAllViews();
//clear the views
getSupportActionBar().setHomeButtonEnabled(false);
//animate the
burger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
//animate the
burger icon
getSupportActionBar().setTitle("About");
//change the toolbar title
newFragment = new About();
transaction.replace(R.id.content_frame,newFragment,"about");
//replace the view and set the fragment id
transaction.addToBackStack(null);
//add the fragment to the

backstack
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
//transition animation
transaction.commit();
} else if (id == R.id.nav_exit){
//exit the apps
this.finish();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void displayNum(){
final EditText txtInput = new EditText(this);
txtInput.setHint("Insert Number Here ");
txtInput.setInputType(InputType.TYPE_CLASS_PHONE);
//open the dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Confirm Number")
.setMessage("Insert your Phone Number: \n*example: 0123456789")
.setView(txtInput)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String hp = txtInput.getText().toString();
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
//insert phone number to respective table
boolean result = myDb.insertNumber(hp);
if (result) {
Toast.makeText(getApplicationContext(), "Number
Inserted", Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
//remove "RanNumber" from the sharedpreferences
final SharedPreferences preferences =
getPreferences(MODE_PRIVATE);
preferences.edit().remove("RanNumber").commit();
}
})
.show();
}
public void displayNumUpdate(){
final EditText txtInput = new EditText(this);
txtInput.setHint("Insert Number Here ");
//set the keyboard type
txtInput.setInputType(InputType.TYPE_CLASS_PHONE);
Cursor getNum = myDb.getHp();
getNum.moveToFirst();
try{
num = getNum.getString(0);
}catch (Exception ignored){}
getNum.close();

//open the dialog box


AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Confirm Number")
.setMessage("Insert your Phone Number: \n\nCurrent: " + num)
.setView(txtInput)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myDb.deleteHP();
//delete the previoud data inside the
number table
String hp = txtInput.getText().toString();
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
boolean result = myDb.insertNumber(hp);
//insert data to
number table
if (result) {
Toast.makeText(getApplicationContext(), "Number Updated",
Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", null)
.show();
}
private boolean isFirstTime(){
//set boolean value of "RanNumber" to false
final SharedPreferences preferences = getPreferences(MODE_PRIVATE);
boolean ranBefore = preferences.getBoolean("RanNumber", false);
if (!ranBefore){
//set the boolean value of "RanNumber" to true
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean("RanNumber", true);
editor.commit();
displayNum();
}
return ranBefore;
}
public void displayRateUpdate(){
final
final
final
final
final
final

EditText
EditText
EditText
EditText
TextView
TextView

txtInput = new EditText(this);


txtDur = new EditText(this);
otherInput = new EditText(this);
otherDur = new EditText(this);
string1 = new TextView(this);
string2 = new TextView(this);

//use cursor to get rate data


Cursor getRate = myDb.getRate();
getRate.moveToFirst();
String costData = getRate.getString(0);
String costDur = getRate.getString(1);
String costOData = getRate.getString(2);
String costODur = getRate.getString(3);
getRate.close();
String text1 = "Same Network : "+costData+" sen/"+costDur+" minute";
string1.setText(text1);
string1.setPadding(30, 8, 0, 0);
string1.setTextColor(Color.parseColor("#000000"));
String text2 = "Other Network : "+costOData+" sen/"+costODur+" minute";

string2.setText(text2);
string2.setPadding(30, 8, 0, 0);
string2.setTextColor(Color.parseColor("#000000"));
txtInput.setHint("New Price (in sen)");
txtInput.setInputType(InputType.TYPE_CLASS_NUMBER);
txtDur.setHint("New Duration (in minute)");
txtDur.setInputType(InputType.TYPE_CLASS_NUMBER);
otherInput.setHint("New Price (in sen)");
otherInput.setInputType(InputType.TYPE_CLASS_NUMBER);
otherDur.setHint("New Duration (in minute)");
otherDur.setInputType(InputType.TYPE_CLASS_NUMBER);
//creating the interface hardcoded
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(string1);
linearLayout.addView(txtInput);
linearLayout.addView(txtDur);
linearLayout.addView(string2);
linearLayout.addView(otherInput);
linearLayout.addView(otherDur);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setTitle("Call Rate Charges")
.setView(linearLayout)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (txtDur.length() > 0 && txtInput.length() > 0 &&
otherDur.length() > 0 && otherInput.length() > 0) {
myDb.getWritableDatabase();
myDb.deleteRate();
//delete all the data inside the
rate table
int d1 = Integer.parseInt(txtInput.getText().toString());
String d2 = txtDur.getText().toString();
int d3 =
Integer.parseInt(otherInput.getText().toString());
String d4 = otherDur.getText().toString();
boolean result = myDb.insertRate(d1, d2, d3, d4);
//insert data to rate table
if (result) {
Toast.makeText(getApplicationContext(), "Rate
Changed", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(),"Complete all the
field!",Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", null)
.show();
}
public void SMSRateUpdate(){
myDb.getWritableDatabase();
final
final
final
final

EditText
EditText
TextView
TextView

txtInput = new EditText(this);


otherInput = new EditText(this);
string1 = new TextView(this);
string2 = new TextView(this);

//accessing the sms rate table


Cursor getData = myDb.getDataSMSRate();
getData.moveToFirst();
costsame = Integer.parseInt(getData.getString(0));
costother = Integer.parseInt(getData.getString(1));
//setting the text for text box
String text1 = "Same Network : " + costsame + " sen/SMS";
string1.setText(text1);
string1.setPadding(30, 8, 0, 0);
string1.setTextColor(Color.parseColor("#000000"));
String text2 = "Other Network : "+costother+" sen/SMS";
string2.setText(text2);
string2.setPadding(30, 8, 0, 0);
string2.setTextColor(Color.parseColor("#000000"));
txtInput.setHint("New Price (in sen)/ SMS");
txtInput.setInputType(InputType.TYPE_CLASS_NUMBER);
otherInput.setHint("New Price (in sen) / SMS");
otherInput.setInputType(InputType.TYPE_CLASS_NUMBER);
//creating the interface hardcoded
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.addView(string1);
linearLayout.addView(txtInput);
linearLayout.addView(string2);
linearLayout.addView(otherInput);
AlertDialog.Builder builder = new AlertDialog.Builder(this); //create a dialog
box
builder.setTitle("Update SMS Rate Charges")
.setView(linearLayout)
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
myDb.deleteSMSRate();
int d1 = Integer.parseInt(txtInput.getText().toString());
int d2 = Integer.parseInt(otherInput.getText().toString());
if (txtInput.length() > 0 && otherInput.length() > 0) {
boolean result = myDb.insertSMSRate(d1, d2);
if (result) { //check if the data is successfully
inserted inside the db
Toast.makeText(getApplicationContext(), "Rate
Updated", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Please try
again", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(),"Fill in all the
field!",Toast.LENGTH_SHORT).show();
}
}
})
.setNegativeButton("Cancel", null)
.show();
}
}

MyValueFormatter.java

Coding:
public class MyValueFormatter implements ValueFormatter {
private DecimalFormat mFormat;
public MyValueFormatter(){
mFormat = new DecimalFormat("##");
}
@Override
public String getFormattedValue(float v, Entry entry, int i, ViewPortHandler
viewPortHandler) {
return mFormat.format(v);
}
}

Outgoing.java

Coding:
public class Outgoing extends AppCompatActivity {
private PieChart mChart;
int nToday, nWeek, nMonth;
String[] xData = {"Today", "Week", "Month"};
DatabaseHelper myDb;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.outgoing);
myDb = new DatabaseHelper(this);
myDb.getWritableDatabase();
mChart = new PieChart(this);
mChart = (PieChart) findViewById(R.id.outgoingPie);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(500).translationY(0).alpha(1);

//animate

toolbar
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
//animate hamburger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //aniamte hamburger
icon
getSupportActionBar().setTitle("Outgoing Calls");
Button btnOutToday = (Button) findViewById(R.id.btnOutToday);
btnOutToday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoing = new Intent(getApplicationContext(),
OutgoingToday.class);
startActivity(outgoing);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnOutWeek = (Button) findViewById(R.id.btnOut7);
btnOutWeek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoingweek = new Intent(getApplicationContext(),
OutgoingWeek.class);
startActivity(outgoingweek);

overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnOutMonth = (Button) findViewById(R.id.btnOutMonth);
btnOutMonth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoingmonth = new Intent(getApplicationContext(),
OutgoingMonth.class);
startActivity(outgoingmonth);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
//configure pie chart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(20);
mChart.setTransparentCircleRadius(10);
//enable rotation of the chart by touch
mChart.setRotationAngle(0);
mChart.setRotationEnabled(true);
mChart.setDescription("");
//set a chart value selected listener
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(Outgoing.this, xData[e.getXIndex()] + " " + e.getVal()
+ " in total ", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {
}
});
//Add data
addData();
// customize legends
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
}
private void addData() {

//handle pie chart data

myDb.getWritableDatabase();
Cursor getDataOut = myDb.getDataOutgoing();
nToday = getDataOut.getCount();
getDataOut.close();

Cursor getDataOut7 = myDb.getDataOutgoing7();


nWeek = getDataOut7.getCount();
getDataOut7.close();
Cursor getDataOut30 = myDb.getDataOutgoing30();
nMonth = getDataOut30.getCount();
getDataOut30.close();
int[] yData = {nToday, nWeek, nMonth};
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setSliceSpace(5);
dataSet.setSelectionShift(15);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//instantiate pie data object now
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);
//undo all highlights
mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
}

OutgoingToday.java & OutgoingWeek.java & OutgoingMonth.java

Coding:
public class OutgoingToday extends AppCompatActivity {
DatabaseHelper myDb;
ListView outgoinglv;
List<Details> detailList = new ArrayList<Details>();
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.outgoing_today);
myDb = new DatabaseHelper(this);
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
//toolbar
animation
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
//hamburger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //hamburger icon
getSupportActionBar().setTitle("Daily Log");
outgoinglv = (ListView) findViewById(R.id.outgoinglv1);
Cursor getData = myDb.getDataOutgoing();
getData.moveToFirst();
while(!getData.isAfterLast()){
String phone = getData.getString(0);
String type = getData.getString(1);
String date = getData.getString(2);
String duration = getData.getString(3);
String name = getData.getString(4);
String country = getData.getString(5);
addOutgoingDetails(phone,type,date,duration,name,country);
getData.moveToNext();
}
getData.close();
final ArrayAdapter<Details> adapter = new OutgoingTodayAdapter();
//set
array to adapter
outgoinglv.setAdapter(adapter); //data adapter
outgoinglv.setEmptyView(findViewById(R.id.empty)); //view when data is null

}
private void addOutgoingDetails(String phone,String type,String date,String
duration,String name,String country){
detailList.add(new Details(phone,type,date,duration,name,country)); //uses
Details class
}
private class OutgoingTodayAdapter extends ArrayAdapter<Details>{
public OutgoingTodayAdapter(){
super(OutgoingToday.this,R.layout.lvtrackdetails,detailList);
}
@Override
public View getView(int pos,View view,ViewGroup parent){
if(view == null)
view =
getLayoutInflater().inflate(R.layout.lvtrackdetails,parent,false);
Details currentDetails = detailList.get(pos);
//set value for textview
TextView phone = (TextView) view.findViewById(R.id.txtNum);
phone.setText(currentDetails.getPhone());
TextView type = (TextView) view.findViewById(R.id.txtType);
type.setText(currentDetails.getType());
TextView date = (TextView) view.findViewById(R.id.txtDate);
date.setText(currentDetails.getDate());
TextView duration = (TextView) view.findViewById(R.id.txtDuration);
duration.setText(currentDetails.getDuration());
TextView name = (TextView) view.findViewById(R.id.txtName);
if(currentDetails.getName() == null){
//set name to 'Not Set' when value
is null
name.setText("Not Set");
}else{
name.setText(currentDetails.getName());
}
TextView country = (TextView) view.findViewById(R.id.txtCountry);
country.setText(currentDetails.getCountry());
return view;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
//destroy layout when back
button pressed
finish();
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
return super.onOptionsItemSelected(menuItem);
}
}

OutgoingSMS.java

Coding:
public class OutgoingSMS extends AppCompatActivity {
private PieChart mChart;
int nToday, nWeek, nMonth;
String[] xData = {"Today", "Week", "Month"};
DatabaseHelper myDb;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.outgoingsms);
myDb = new DatabaseHelper(this);
myDb.getWritableDatabase();
mChart = new PieChart(this);
mChart = (PieChart) findViewById(R.id.outgoingPie);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(500).translationY(0).alpha(1);

//animate

toolbar
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
//animate hamburger icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //animate hamburger
icon
getSupportActionBar().setTitle("Outgoing SMS");
Button btnOutToday = (Button) findViewById(R.id.btnOutToday);
btnOutToday.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoing = new Intent(getApplicationContext(),
OutgoingSMSToday.class);
startActivity(outgoing);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnOutWeek = (Button) findViewById(R.id.btnOut7);
btnOutWeek.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoingweek = new Intent(getApplicationContext(),
OutgoingSMSWeek.class);
startActivity(outgoingweek);

overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
Button btnOutMonth = (Button) findViewById(R.id.btnOutMonth);
btnOutMonth.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoingmonth = new Intent(getApplicationContext(),
OutgoingSMSMonth.class);
startActivity(outgoingmonth);
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
});
//configure pie chart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(20);
mChart.setTransparentCircleRadius(10);
//enable rotation of the chart by touch
mChart.setRotationAngle(0);
mChart.setRotationEnabled(true);
mChart.setDescription("");
//set a chart value selected listener
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(OutgoingSMS.this, xData[e.getXIndex()] + " " +
e.getVal() + " in total ", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected() {
}
});
//Add data
addData();
// customize legends
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
}
private void addData() {

//handle pie chart data

myDb.getWritableDatabase();
Cursor getDataOut = myDb.getDataSMSOut();
nToday = getDataOut.getCount();
getDataOut.close();
Cursor getDataOut7 = myDb.getDataSMSOut7();
nWeek = getDataOut7.getCount();
getDataOut7.close();

Cursor getDataOut30 = myDb.getDataSMSOut30();


nMonth = getDataOut30.getCount();
getDataOut30.close();
int[] yData = {nToday, nWeek, nMonth};
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setSliceSpace(5);
dataSet.setSelectionShift(15);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//instantiate pie data object now
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);
//undo all highlights
mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
//destroy layout when back
button pressed
finish();
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
return super.onOptionsItemSelected(menuItem);
}
}

OutgoingSMSToday.java & OutgoingSMSWeek.java &


OutgoingSMSMonth.java

Coding:
public class OutgoingSMSToday extends AppCompatActivity {
DatabaseHelper myDb;
ListView outgoinglv;
List<SMSDetails> detailList = new ArrayList<SMSDetails>();
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.smslistview);
myDb = new DatabaseHelper(this);
myDb = new DatabaseHelper(getApplicationContext());
myDb.getWritableDatabase();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setAlpha(0);
toolbar.setTranslationY(-300);
toolbar.animate().setDuration(1000).translationY(0).alpha(1);
//toolbar
animation
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
//aniamte hamburger
icon
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //animate hamburger
icon
getSupportActionBar().setTitle("Daily Log");
outgoinglv = (ListView) findViewById(R.id.smslv);
Cursor getData = myDb.getDataSMSOut();
getData.moveToFirst();
while(!getData.isAfterLast()){
String phone = getData.getString(0);
String date = getData.getString(1);
String msg = getData.getString(3);
addOutgoingDetails(phone,date,msg);
getData.moveToNext();
}
getData.close();
final ArrayAdapter<SMSDetails> adapter = new OutgoingSMSTodayAdapter(); //set
array to adapter
outgoinglv.setAdapter(adapter); //listview data adapter
outgoinglv.setEmptyView(findViewById(R.id.empty)); //view when data is empty

//open dialog box containing sms body


outgoinglv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
TextView smscontent = (TextView) view.findViewById(R.id.txtMsg);
AlertDialog.Builder builder = new
AlertDialog.Builder(OutgoingSMSToday.this);
builder.setTitle("Message Content")
.setMessage(smscontent.getText().toString())
.setNeutralButton("Close", null)
.show();
}
});
}
private void addOutgoingDetails(String phone,String date,String msg){
detailList.add(new SMSDetails(phone,date,msg)); //uses SMSDetails class
}
private class OutgoingSMSTodayAdapter extends ArrayAdapter<SMSDetails>{
public OutgoingSMSTodayAdapter(){
super(OutgoingSMSToday.this,R.layout.smstrackdetails,detailList);
}
@Override
public View getView(int pos,View view,ViewGroup parent){
if(view == null)
view =
getLayoutInflater().inflate(R.layout.lvtrackdetails,parent,false);
SMSDetails currentDetails = detailList.get(pos);
//set value for each textview
TextView phone = (TextView) view.findViewById(R.id.txtNum);
phone.setText(currentDetails.getPhone());
TextView date = (TextView) view.findViewById(R.id.txtDate);
date.setText(currentDetails.getDate());
TextView msg = (TextView) view.findViewById(R.id.txtMsg);
msg.setText(currentDetails.getMsg());
return view;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
//destroy layout when
back button pressed
finish();
overridePendingTransition(R.animator.fadein, R.animator.fadeout);
}
return super.onOptionsItemSelected(menuItem);
}
}

RoamingUsage.java

Coding:
public class RoamingUsage extends Fragment {
private PieChart mChart;
int Upload, Download;
String[] xData = {"Upload(MB)","Download(MB)"};
DatabaseHelper myDb;
TextView totalRoam;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.roamdata, container, false);
mChart = new PieChart(getActivity());
mChart = (PieChart) v.findViewById(R.id.incomingPie);
totalRoam = (TextView) v.findViewById(R.id.txtTotalRoam);
//enable hole at the piechart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(18);
mChart.setTransparentCircleRadius(10);
//enable the pie chart to rotate
mChart.setRotationAngle(0);
mChart.setRotationEnabled(false);
//set the description of piechart
mChart.setDescription("");
mChart.setNoDataText("No Data Usage");
//act when the piechart section is clicked
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(getActivity(), xData[e.getXIndex()] + " " + e.getVal()
+ " in total ", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected() {
}
});
addData();
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
return v;
}
private void addData() {

//handle pie chart data

long mobUpload = TrafficStats.getMobileTxBytes()/1048576;


long mobDownload = TrafficStats.getMobileRxBytes()/1048576;
Upload = (int)(long) mobUpload;
Download = (int)(long) mobDownload;
int[] yData = {Upload, Download};
String msg = String.valueOf(mobDownload+mobUpload)+"MB";
totalRoam.setText(msg);
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "Data Manager");
dataSet.setSliceSpace(3);
dataSet.setSelectionShift(13);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);
//instantiate pie data object now
PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);

//undo all highlights


mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
}

SMSDetails.java

Coding:
public class SMSDetails {
private String _phone,_date,_msg,_name;
public SMSDetails(String hp,String date,String text){
_phone = hp;
_date = date;
_msg = text;
}
public String getPhone(){
return _phone;
}
public String getDate(){
return _date;
}
public String getMsg(){
return _msg;
}
}

SplashScreen.java

Coding:
public class SplashScreen extends Activity {
DatabaseHelper myDb;
private ProgressBar loadBar = null;
@Override
protected void onCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.splash_screen);
myDb = new DatabaseHelper(this);
//declaring the loading bar
loadBar = (ProgressBar) findViewById(R.id.loadBar);
//setting the max value for the loading bar
loadBar.setMax(100);
//set the initial prograss
loadBar.setProgress(0);
new FetchData().execute(99);
}
private class FetchData extends AsyncTask<Integer,Integer,Void>{
@Override
protected void onPreExecute(){
super.onPreExecute();
loadBar.setVisibility(View.VISIBLE);
loadBar.setProgress(0);
try {
deleteData();
deleteSMS();
}catch (Exception ignored){}
}
@Override
protected Void doInBackground(Integer... params){
for(int i = 0; i <= params[0]; i++){
try{
//pausing the thread for 40 miliseconds
Thread.sleep(40);
publishProgress(i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//run all the function to extract data from the phone and store it inside
the database
getCallDetails();
getSMSDetails();
getTelcoCelcom();
getTelcoDigi();
getTelcoMaxis();
getCelcomInc();
getDigiInc();
getMaxisInc();
getCelcomSMS();
getDigiSMS();
getMaxisSMS();
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {

super.onProgressUpdate(values);
//set the loadbar to move for every 40 miliseconds
loadBar.setProgress(values[0]);
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute(result);
//when the apps have finished running all the function. the load bar will
be set to 100
loadBar.setProgress(100);
Intent i = new Intent(SplashScreen.this,MainActivity.class);
startActivity(i);
finish();
}
}
private void deleteData() {
//delet all the data inside the table everytime the apps run to get the latest
updated data
myDb.deleteOutgoing();
myDb.deleteOutgoing7();
myDb.deleteOutgoing30();
myDb.deleteIncoming();
myDb.deleteIncoming7();
myDb.deleteIncoming30();
myDb.deleteCelcom();
myDb.deleteMaxis();
myDb.deleteDigi();
myDb.deleteCelcomInc();
myDb.deleteDigiInc();
myDb.deleteMaxisInc();
}
private void getCallDetails() {
myDb = new DatabaseHelper(this);
//Use a cursor to obtain data inside the CallLog.Calls
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
null, null, null, null);
//getting the value of column index for respective variable
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int country = managedCursor.getColumnIndex(CallLog.Calls.COUNTRY_ISO);
while (managedCursor.moveToNext()) {
//uses the index value to obtain the string value
String hpnum = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDateTime = new Date(Long.valueOf(callDate));
String tsdate = String.valueOf(callDateTime);
String callDuration = managedCursor.getString(duration);
String contactName = managedCursor.getString(name);
String countryName = managedCursor.getString(country);
String dir = null;
long time = System.currentTimeMillis();
int dircode = Integer.parseInt(callType);
long resultTime = (time - Long.valueOf(callDate));
long day1 = Long.valueOf("86400000");
long day7 = Long.valueOf("604800000");

long day30 = Long.valueOf("2592000000");


//switch statement to differentiate between outgoing and incoming
//also specify the data according to day,week and month
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "Outgoing";
if (resultTime <= day1) {
myDb.getWritableDatabase();
myDb.insertOutgoingLog(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertOutgoingLog7(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertOutgoingLog30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else if (resultTime <= day7) {
myDb.getWritableDatabase();
myDb.insertOutgoingLog7(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertOutgoingLog30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else if (resultTime <= day30) {
myDb.getWritableDatabase();
myDb.insertOutgoingLog30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else {
}
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "Incoming";
if (resultTime <= day1) {
myDb.getWritableDatabase();
myDb.insertIncoming(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertIncoming7(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertIncoming30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else if (resultTime <= day7) {
myDb.getWritableDatabase();
myDb.insertIncoming7(hpnum, dir, tsdate, callDuration,
contactName,countryName);
myDb.insertIncoming30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else if (resultTime <= day30) {
myDb.getWritableDatabase();
myDb.insertIncoming30(hpnum, dir, tsdate, callDuration,
contactName,countryName);
} else {
}
break;
case CallLog.Calls.MISSED_TYPE:
break;
}
}
managedCursor.close();
}
private void getSMSDetails(){
myDb = new DatabaseHelper(this);
//get data from the sms log using cursor
Uri sms_Content = Uri.parse("content://sms");
Cursor managedCursor = getContentResolver().query(sms_Content, null, null,
null, null);
managedCursor.moveToFirst();
//obtain the index column
int number = managedCursor.getColumnIndexOrThrow("address");

int date = managedCursor.getColumnIndexOrThrow("date");


int type = managedCursor.getColumnIndexOrThrow("type");
int text = managedCursor.getColumnIndexOrThrow("body");
while(managedCursor.moveToNext()){
//uses the index to get the string value
String hpNumber = managedCursor.getString(number);
String msgDate = managedCursor.getString(date);
String msgType = managedCursor.getString(type);
Date dateMsg = new Date(Long.valueOf(msgDate));
String msgText = managedCursor.getString(text);
String tsdate = String.valueOf(dateMsg);
String dir;
int dircode = Integer.parseInt(msgType);
long
long
long
long
long

time = System.currentTimeMillis();
resultTime = (time - Long.valueOf(msgDate));
day1 = Long.valueOf("86400000");
day7 = Long.valueOf("604800000");
day30 = Long.valueOf("2592000000");

//switch to differentiate between received and sent


//sort it based on the time
switch(dircode){
case 1:
dir = "Received";
if (resultTime <= day1) {
myDb.getWritableDatabase();
myDb.insertSMSIn(hpNumber, tsdate, dir,msgText);
myDb.insertSMSIn7(hpNumber, tsdate, dir,msgText);
myDb.insertSMSIn30(hpNumber, tsdate, dir,msgText);
} else if (resultTime <= day7) {
myDb.getWritableDatabase();
myDb.insertSMSIn7(hpNumber, tsdate, dir,msgText);
myDb.insertSMSIn30(hpNumber, tsdate, dir,msgText);
} else if (resultTime <= day30) {
myDb.getWritableDatabase();
myDb.insertSMSIn30(hpNumber, tsdate, dir,msgText);
} else {
}
break;
case 2:
dir = "Sent";
if (resultTime <= day1) {
myDb.getWritableDatabase();
myDb.insertSMSOut(hpNumber, tsdate, dir,msgText);
myDb.insertSMSOut7(hpNumber, tsdate, dir,msgText);
myDb.insertSMSOut30(hpNumber, tsdate, dir,msgText);
} else if (resultTime <= day7) {
myDb.getWritableDatabase();
myDb.insertSMSOut7(hpNumber, tsdate, dir,msgText);
myDb.insertSMSOut30(hpNumber, tsdate, dir,msgText);
} else if (resultTime <= day30) {
myDb.getWritableDatabase();
myDb.insertSMSOut30(hpNumber, tsdate, dir,msgText);
} else {
}
}
}
managedCursor.close();
}

//get all data of all the number begin with digi number and insert it inside the
digi table
public void getTelcoDigi(){
myDb.getWritableDatabase();
Cursor getDataDigi = myDb.getDigiNum();
while (getDataDigi.moveToNext()){
String num = getDataDigi.getString(0);
Integer dur = Integer.parseInt(getDataDigi.getString(3));
myDb.insertDigi(num, dur);
}
getDataDigi.close();
}
//get all data of all the number begin with celcom number and insert it inside the
celcom table
public void getTelcoCelcom(){
myDb.getWritableDatabase();
Cursor getDataCelcom = myDb.getCelcomNum();
while (getDataCelcom.moveToNext()){
String num = getDataCelcom.getString(0);
Integer dur = Integer.parseInt(getDataCelcom.getString(3));
myDb.insertCelcom(num, dur);
}
getDataCelcom.close();
}
//get all data of all the number begin with maxis number and insert it inside the
digi table
public void getTelcoMaxis(){
myDb.getWritableDatabase();
Cursor getDataMaxis = myDb.getMaxisNum();
while (getDataMaxis.moveToNext()){
String num = getDataMaxis.getString(0);
Integer dur = Integer.parseInt(getDataMaxis.getString(3));
myDb.insertMaxis(num, dur);
}
getDataMaxis.close();
}
//get calls received from any maxis number
public void getMaxisInc(){
myDb.getWritableDatabase();
Cursor getData = myDb.getMaxisIncoming();
while (getData.moveToNext()){
String num = getData.getString(0);
Integer dur = Integer.parseInt(getData.getString(3));
myDb.insertMaxisIncoming(num, dur);
}
getData.close();
}
//get calls received from any digi number
public void getDigiInc(){
myDb.getWritableDatabase();
Cursor getData = myDb.getDigiIncoming();
while (getData.moveToNext()){
String num = getData.getString(0);
Integer dur = Integer.parseInt(getData.getString(3));
myDb.insertDigiIncoming(num, dur);
}
getData.close();
}
//get calls received from any celcom number
public void getCelcomInc(){

myDb.getWritableDatabase();
Cursor getData = myDb.getCelcomIncoming();
while (getData.moveToNext()){
String num = getData.getString(0);
Integer dur = Integer.parseInt(getData.getString(3));
myDb.insertCelcomIncoming(num, dur);
}
getData.close();
}
//get sms received from any celcom number
public void getCelcomSMS(){
myDb.getWritableDatabase();
Cursor getData = myDb.getCelcomSMSIncoming();
while (getData.moveToNext()){
String num = getData.getString(0);
myDb.insertSMSCelcom(num);
}
getData.close();
}
//get sms received from any maxis number
public void getMaxisSMS(){
myDb.getWritableDatabase();
Cursor getData = myDb.getMaxisSMSIncoming();
while (getData.moveToNext()){
String num = getData.getString(0);
myDb.insertSMSMaxis(num);
}
getData.close();
}
//get sms received from any digi number
public void getDigiSMS(){
myDb.getWritableDatabase();
Cursor getData = myDb.getDigiSMSIncoming();
while(getData.moveToNext()){
String num = getData.getString(0);
myDb.insertSMSDigi(num);
}
getData.close();
}
//delete all data of all sms table
public void deleteSMS(){
myDb.getWritableDatabase();
myDb.deleteSMSIn();
myDb.deleteSMSIn7();
myDb.deleteSMSIn30();
myDb.deleteSMSOut();
myDb.deleteSMSOut7();
myDb.deleteSMSOut30();
myDb.deleteSMSCelcom();
myDb.deleteSMSMaxis();
myDb.deleteSMSDigi();
}
}

Track.java

Coding:
public class Track extends android.app.Fragment {
DatabaseHelper myDb;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.track_call, container, false);
myDb = new DatabaseHelper(getActivity());
myDb.getWritableDatabase();
Button btnIncoming = (Button) v.findViewById(R.id.btnIncoming);
btnIncoming.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent incoming = new Intent(getActivity(), Incoming.class);
startActivity(incoming);
//run the incoming class
getActivity().overridePendingTransition(R.animator.fadein,
R.animator.fadeout);
}
});
Button btnOutgoing = (Button) v.findViewById(R.id.btnOutgo);
btnOutgoing.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent outgoing = new Intent(getActivity(), Outgoing.class);
startActivity(outgoing);
//run the outgoing class
getActivity().overridePendingTransition(R.animator.fadein,
R.animator.fadeout);
}
});
//uses row count to get value of total incoming call and outgoing call
Cursor celcom = myDb.getDataCelcom();
final int celcomRow = celcom.getCount();
celcom.close();
final TextView celcomTxt = (TextView) v.findViewById(R.id.txtTotalCelcom);
ValueAnimator animator1 = new ValueAnimator(); //animate the value when
layout is displayed
animator1.setObjectValues(0,celcomRow);
animator1.setDuration(5000);
//duration for the animation
animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
celcomTxt.setText(msg);
}

});
animator1.start();
Cursor digi = myDb.getDataDigi();
int digiRow = digi.getCount();
digi.close();
final TextView digiTxt = (TextView) v.findViewById(R.id.txtTotalDigi);
ValueAnimator animator2 = new ValueAnimator(); //animate the value when
layout is displayed
animator2.setObjectValues(0,digiRow);
animator2.setDuration(5000);
//duration for the animation
animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
digiTxt.setText(msg);
}
});
animator2.start();
Cursor maxis = myDb.getDataMaxis();
int maxisRow = maxis.getCount();
maxis.close();
final TextView maxisTxt = (TextView) v.findViewById(R.id.txtTotalMaxis);
ValueAnimator animator3 = new ValueAnimator(); //animate the value when
layout is displayed
animator3.setObjectValues(0,maxisRow);
animator3.setDuration(5000);
//duration for the animation
animator3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
maxisTxt.setText(msg);
}
});
animator3.start();
Cursor celcomInc = myDb.getCelcomInc();
int celcomIncRow = celcomInc.getCount();
celcomInc.close();
final TextView cInc = (TextView) v.findViewById(R.id.txtCelcomInc);
ValueAnimator animator4 = new ValueAnimator(); //animate the value when
layout is displayed
animator4.setObjectValues(0,celcomIncRow);
//set initial value and final
value
animator4.setDuration(5000);
//duration for the animation
animator4.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
cInc.setText(msg);
}
});
animator4.start();
Cursor digiInc = myDb.getDigiInc();
int digiIncRow = digiInc.getCount();
digiInc.close();
final TextView dInc = (TextView) v.findViewById(R.id.txtDigiInc);
ValueAnimator animator5 = new ValueAnimator(); //animate the value when
layout is displayed
animator5.setObjectValues(0,digiIncRow);
//set initial value and final
value
animator5.setDuration(5000);
//duration for the animation
animator5.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override

public void onAnimationUpdate(ValueAnimator animation) {


String msg = animation.getAnimatedValue() + "";
dInc.setText(msg);
}
});
animator5.start();
Cursor maxisInc = myDb.getMaxisInc();
int maxisIncRow = maxisInc.getCount();
maxisInc.close();
final TextView mInc = (TextView) v.findViewById(R.id.txtMaxisInc);
ValueAnimator animator6 = new ValueAnimator(); //animate the value when
layout is displayed
animator6.setObjectValues(0,maxisIncRow);
//set initial value and final
value
animator6.setDuration(5000);
//duration for the animation
animator6.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
mInc.setText(msg);
}
});
animator6.start();
//get other calls receive and made
Cursor getTotalCall = myDb.getDataIncoming30();
int Inc = getTotalCall.getCount();
int totalInc = Inc - (digiIncRow+maxisIncRow+celcomIncRow);
getTotalCall.close();
final TextView txtInc = (TextView) v.findViewById(R.id.txtOtherReceive);
ValueAnimator animator7 = new ValueAnimator(); //animate the value when
layout is displayed
animator7.setObjectValues(0,totalInc);
//set initial value and final value
animator7.setDuration(5000);
//duration for the animation
animator7.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtInc.setText(msg);
}
});
animator7.start();
Cursor getTotalCall2 = myDb.getDataOutgoing30();
int Out = getTotalCall2.getCount();
int totalOut = Out - (maxisRow+digiRow+celcomRow);
getTotalCall2.close();
final TextView txtOut = (TextView) v.findViewById(R.id.txtOtherMade);
ValueAnimator animator8 = new ValueAnimator(); //animate the value when
layout is displayed
animator8.setObjectValues(0,totalOut);
//set initial value and final value
animator8.setDuration(5000);
//duration for the animation
animator8.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtOut.setText(msg);
}
});
animator8.start();
return v;
}
}

TrackSMS.java

Coding:
public class TrackSMS extends android.app.Fragment {
DatabaseHelper myDb;
TextView
madeDigi,madeCelcom,madeMaxis,txtTotalMade,txtDigi,txtCelcom,txtMaxis,txtTotalIn;
ValueAnimator anim1,anim2,anim3,anim4,anim5,anim6,anim7,anim8;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.track_sms, container, false);
//uses row count to get value of total sms receive and set
myDb = new DatabaseHelper(getActivity());
myDb.getWritableDatabase();
Cursor getDataIn30 = myDb.getDataSMSIn30();
int smsIn30 = getDataIn30.getCount();
getDataIn30.close();
Cursor getDataOut30 = myDb.getDataSMSOut30();
int smsOut30 = getDataOut30.getCount();
getDataOut30.close();
Cursor getDataSMS = myDb.getMaxisSMS();
int maxisSms = getDataSMS.getCount();
getDataSMS.close();
Cursor getDataSMS1 = myDb.getDigiSMS();
int digiSms = getDataSMS1.getCount();
getDataSMS1.close();
Cursor getDataSMS2 = myDb.getCelcomSMS();
int celcomSms = getDataSMS2.getCount();
getDataSMS2.close();
Cursor getDataDigi = myDb.getDataSMSDigi();
int digiCount = getDataDigi.getCount();
getDataDigi.close();
Cursor getDataCelcom = myDb.getDataSMSCelcom();
int celcomCount = getDataCelcom.getCount();
getDataCelcom.close();
Cursor getDataMaxis = myDb.getDataSMSMaxis();
int maxisCount = getDataMaxis.getCount();
getDataMaxis.close();
txtMaxis = (TextView) v.findViewById(R.id.txtMaxisInc);
txtCelcom = (TextView) v.findViewById(R.id.txtCelcomInc);
txtDigi = (TextView) v.findViewById(R.id.txtDigiInc);

madeCelcom = (TextView) v.findViewById(R.id.txtSMSCelcom);


madeDigi = (TextView) v.findViewById(R.id.txtSMSDigi);
madeMaxis = (TextView) v.findViewById(R.id.txtSMSMaxis);
anim1 = new ValueAnimator(); //animate the value when layout is displayed
anim1.setObjectValues(0, celcomSms);
//set initial value and final value
anim1.setDuration(5000);
//duration for the animation
anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
madeCelcom.setText(msg);
}
});
anim1.start();
anim2 = new ValueAnimator(); //animate the value when layout is displayed
anim2.setObjectValues(0, digiSms);
//set initial value and final value
anim2.setDuration(5000);
//duration for the animation
anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
madeDigi.setText(msg);
}
});
anim2.start();
anim3 = new ValueAnimator(); //animate the value when layout is displayed
anim3.setObjectValues(0, maxisSms);
//set initial value and final value
anim3.setDuration(5000);
//duration for the animation
anim3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
madeMaxis.setText(msg);
}
});
anim3.start();
anim4 = new ValueAnimator(); //animate the value when layout is displayed
anim4.setObjectValues(0, digiCount);
//set initial value and final value
anim4.setDuration(5000);
//duration for the animation
anim4.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtDigi.setText(msg);
}
});
anim4.start();
anim5 = new ValueAnimator(); //animate the value when layout is displayed
anim5.setObjectValues(0, celcomCount);
//set initial value and final value
anim5.setDuration(5000);
//duration for the animation
anim5.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtCelcom.setText(msg);
}
});
anim5.start();
anim6 = new ValueAnimator(); //animate the value when layout is displayed
anim6.setObjectValues(0, maxisCount);
//set initial value and final value
anim6.setDuration(5000);
//duration for the animation

anim6.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtMaxis.setText(msg);
}
});
anim6.start();
final int totalOtherMade = smsOut30 - (celcomSms+digiSms+maxisSms);
txtTotalMade = (TextView) v.findViewById(R.id.txtOtherMade);
anim7 = new ValueAnimator(); //animate the value when layout is displayed
anim7.setObjectValues(0, totalOtherMade);
//set initial value and final
value
anim7.setDuration(5000);
//duration for the animation
anim7.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtTotalMade.setText(msg);
}
});
anim7.start();
int totalOtherReceive = smsIn30 - (digiCount+maxisCount+celcomCount);
txtTotalIn = (TextView) v.findViewById(R.id.txtOtherReceive);
anim8 = new ValueAnimator(); //animate the value when layout is displayed
anim8.setObjectValues(0,totalOtherReceive);
//set initial value and final
value
anim8.setDuration(5000);
//duration for the animation
anim8.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
String msg = animation.getAnimatedValue() + "";
txtTotalIn.setText(msg);
}
});
anim8.start();
Button btnInc = (Button) v.findViewById(R.id.btnReceiveSMS);
btnInc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(),IncomingSMS.class);
startActivity(i);
//run incomingsms class
getActivity().overridePendingTransition(R.animator.fadein,
R.animator.fadeout);
}
});
Button btnOut = (Button) v.findViewById(R.id.btnSMSMade);
btnOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getActivity(),OutgoingSMS.class);
startActivity(i);
//run outgoingsms class
getActivity().overridePendingTransition(R.animator.fadein,
R.animator.fadeout);
}
});
return v;
}
}

ViewPagerAdapter.java

Coding:
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
CharSequence Titles[];
int NumbOfTabs;
public ViewPagerAdapter(FragmentManager fm, CharSequence mTitles[], int
mNumbOfTabsumb) {
super(fm);
this.Titles = mTitles;
this.NumbOfTabs = mNumbOfTabsumb;
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
//first tab
return new WifiUsage();
} else {
//second tab
return new RoamingUsage();
}
}
@Override
public CharSequence getPageTitle(int position) {
return Titles[position];
}
@Override
public int getCount() {
return NumbOfTabs;
}
}

WifiUsage.java

Coding:
public class WifiUsage extends Fragment {
private PieChart mChart;
int Upload, Download;
String[] xData = {"Upload(MB)","Download(MB)"};
DatabaseHelper myDb;
TextView wifiUsage;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.wifidata, container, false);
mChart = new PieChart(getActivity());
mChart = (PieChart) v.findViewById(R.id.incomingPie);
wifiUsage = (TextView) v.findViewById(R.id.txtTotalWifi);
//enable hole at the piechart
mChart.setDrawHoleEnabled(true);
mChart.setHoleColorTransparent(true);
mChart.setHoleRadius(18);
mChart.setTransparentCircleRadius(10);
//enable the pie chart to rotate
mChart.setRotationAngle(0);
mChart.setRotationEnabled(false);
//set the description of piechart
mChart.setDescription("");
mChart.setNoDataText("No Data Usage");
//act when the piechart section is clicked
mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int index, Highlight h) {
//display msg when value selected
if (e == null)
return;
Toast.makeText(getActivity(), xData[e.getXIndex()] + " " + e.getVal()
+ " in total ", Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected() {
}
});
addData();
//configuring the piechart legend
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
l.setXEntrySpace(3);
l.setYEntrySpace(3);
return v;
}
private void addData() {

//handle pie chart data

//get overall internet usage since the phone starts


long rxBytes = TrafficStats.getTotalRxBytes()/1048576;
long txBytes = TrafficStats.getTotalTxBytes()/1048576;
//get overall roaming data usage
long mobUpload = TrafficStats.getMobileRxBytes()/1048576;
long mobDownload = TrafficStats.getMobileTxBytes()/1048576;
//to obtain the wifi upload and download usage
long wifiUpload = txBytes-(mobUpload);
long wifiDownload = rxBytes-(mobDownload);
//coverting the long value into a integer value
Upload = (int)(long) wifiUpload;
Download = (int)(long) wifiDownload;
//data for total usage used
wifiUsage.setText(String.valueOf(wifiUpload+wifiDownload+"MB"));
int[] yData = {Upload, Download};
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
for (int i = 0; i < yData.length; i++)
yVals1.add(new Entry(yData[i], i));
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < xData.length; i++)
xVals.add(xData[i]);
// create pie data set
PieDataSet dataSet = new PieDataSet(yVals1, "Data Manager");
dataSet.setSliceSpace(3);
dataSet.setSelectionShift(13);
//add many colors according to your array in
ArrayList<Integer> colors = new ArrayList<Integer>();
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
dataSet.setColors(colors);

//instantiate pie data object now


PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new MyValueFormatter());
data.setValueTextSize(12f);
data.setValueTextColor(Color.DKGRAY);
mChart.setData(data);
//undo all highlights
mChart.highlightValue(null);
//update pie chart
mChart.invalidate();
}
}

Você também pode gostar