Escolar Documentos
Profissional Documentos
Cultura Documentos
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:
//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;
//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)));
//insert
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
//insert
//insert
//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();
}
//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
}
EditText
EditText
TextView
TextView
//keyboard type
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));
}
public void countSMSCelcomOther(){
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(){
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(){
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(){
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();
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
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
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();
}
}
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
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
@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();
EditText
EditText
EditText
EditText
TextView
TextView
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
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() {
myDb.getWritableDatabase();
Cursor getDataOut = myDb.getDataOutgoing();
nToday = getDataOut.getCount();
getDataOut.close();
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() {
myDb.getWritableDatabase();
Cursor getDataOut = myDb.getDataSMSOut();
nToday = getDataOut.getCount();
getDataOut.close();
Cursor getDataOut7 = myDb.getDataSMSOut7();
nWeek = getDataOut7.getCount();
getDataOut7.close();
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
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() {
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");
time = System.currentTimeMillis();
resultTime = (time - Long.valueOf(msgDate));
day1 = Long.valueOf("86400000");
day7 = Long.valueOf("604800000");
day30 = Long.valueOf("2592000000");
//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
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);
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() {