Skip to content
Snippets Groups Projects
Commit f74faf3c authored by Shubham Maheshwari's avatar Shubham Maheshwari
Browse files

Next Commit

parent a939f761
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
} }
}, },
"oauth_client": [ "oauth_client": [
{
"client_id": "23719170467-51202fnm9h4h6ivrgogg4v01fnqb2icu.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.taskboxx",
"certificate_hash": "285fcf22338e948e2b7d81454813f491b7fb5d78"
}
},
{ {
"client_id": "23719170467-9gbikc8ea63o0cc95d8re0stigfc68vh.apps.googleusercontent.com", "client_id": "23719170467-9gbikc8ea63o0cc95d8re0stigfc68vh.apps.googleusercontent.com",
"client_type": 3 "client_type": 3
...@@ -29,8 +37,13 @@ ...@@ -29,8 +37,13 @@
"status": 1 "status": 1
}, },
"appinvite_service": { "appinvite_service": {
"status": 1, "status": 2,
"other_platform_oauth_client": [] "other_platform_oauth_client": [
{
"client_id": "23719170467-9gbikc8ea63o0cc95d8re0stigfc68vh.apps.googleusercontent.com",
"client_type": 3
}
]
}, },
"ads_service": { "ads_service": {
"status": 2 "status": 2
......
package com.example.taskboxx; package com.example.taskboxx;
import android.app.Fragment; import android.app.Fragment;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
...@@ -9,6 +11,7 @@ import android.view.View; ...@@ -9,6 +11,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
...@@ -17,14 +20,28 @@ import com.github.mikephil.charting.data.PieDataSet; ...@@ -17,14 +20,28 @@ import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry; import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static android.content.ContentValues.TAG;
public class DashboardFragment extends Fragment { public class DashboardFragment extends Fragment {
private float[] yData = {25.3f, 10.6f, 66.76f, 44.32f, 46.01f, 16.89f}; private FirebaseAuth mAuth;
private String[] xData = {"Information", "Academic" , "Entertainment" , "Social Media", "News", "e-Commerce"}; private DatabaseReference mDatabase;
private ArrayList<Float> yData = new ArrayList<>();
private ArrayList<String> xData = new ArrayList<>();
PieChart pieChart; PieChart pieChart;
@Override @Override
...@@ -32,18 +49,48 @@ public class DashboardFragment extends Fragment { ...@@ -32,18 +49,48 @@ public class DashboardFragment extends Fragment {
View rootView = inflater.inflate(R.layout.activity_dashboard_fragment,container,false); View rootView = inflater.inflate(R.layout.activity_dashboard_fragment,container,false);
getActivity().setTitle("Dashboard"); getActivity().setTitle("Dashboard");
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
pieChart = (PieChart) rootView.findViewById(R.id.idPieChart); pieChart = (PieChart) rootView.findViewById(R.id.idPieChart);
pieChart.setDescription(null); pieChart.setDescription(null);
pieChart.setRotationEnabled(true); pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(60f); pieChart.setHoleRadius(60f);
pieChart.setUsePercentValues(true);
pieChart.setTransparentCircleAlpha(175); pieChart.setTransparentCircleAlpha(175);
pieChart.setTransparentCircleRadius(62f); pieChart.setTransparentCircleRadius(63f);
pieChart.setCenterText("Browsing\nContent"); pieChart.setCenterText("Browsing Content");
pieChart.setCenterTextSize(15); pieChart.setCenterTextSize(15);
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
HashMap<String,Float> values = (HashMap)dataSnapshot.child("users").child(mAuth.getCurrentUser().getUid()).child("Data").getValue();
Log.d(TAG, "Hashmap values: "+values);
Set mapSet = (Set) values.entrySet();
Iterator mapIterator = mapSet.iterator();
int i=0;
while(mapIterator.hasNext())
{
Map.Entry mapEntry = (Map.Entry) mapIterator.next();
xData.add(mapEntry.getKey().toString());
yData.add(Double.valueOf((Double)mapEntry.getValue()).floatValue());
i++;
}
Log.d(TAG, "String Tags: "+xData);
Log.d(TAG, "String Values: "+yData);
addDataSet(); addDataSet();
}
@Override
public void onCancelled(DatabaseError error) {
Toast.makeText(getActivity(), "Cannot Retrieve Data from Database", Toast.LENGTH_SHORT).show();
}
});
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override @Override
...@@ -52,13 +99,13 @@ public class DashboardFragment extends Fragment { ...@@ -52,13 +99,13 @@ public class DashboardFragment extends Fragment {
int pos1 = e.toString().indexOf("(sum): "); int pos1 = e.toString().indexOf("(sum): ");
String percent = e.toString().substring(pos1 + 7); String percent = e.toString().substring(pos1 + 7);
for(int i = 0; i < yData.length; i++){ for(int i = 0; i < yData.size(); i++){
if(yData[i] == Float.parseFloat(percent)){ if(yData.get(i) == Float.parseFloat(percent)){
pos1 = i; pos1 = i;
break; break;
} }
} }
String type = xData[pos1]; String type = xData.get(pos1);
Toast.makeText(getActivity(), "You browse for " + type + "\n" + "for " + percent + "% of the time", Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), "You browse for " + type + "\n" + "for " + percent + "% of the time", Toast.LENGTH_LONG).show();
} }
...@@ -72,42 +119,32 @@ public class DashboardFragment extends Fragment { ...@@ -72,42 +119,32 @@ public class DashboardFragment extends Fragment {
} }
private void addDataSet() { private void addDataSet() {
ArrayList<PieEntry> yEntrys = new ArrayList<>();
ArrayList<String> xEntrys = new ArrayList<>();
for(int i = 0; i < yData.length; i++){ final ArrayList<PieEntry> yEntrys = new ArrayList<>();
yEntrys.add(new PieEntry(yData[i] , i));
}
for(int i = 1; i < xData.length; i++){ for(int i = 0; i < yData.size(); i++){
xEntrys.add(xData[i]); yEntrys.add(new PieEntry(yData.get(i) , xData.get(i)));
} }
//create the data set //create the data set
PieDataSet pieDataSet = new PieDataSet(yEntrys, "Your Browsing Content"); PieDataSet pieDataSet = new PieDataSet(yEntrys, "Your Browsing Content");
pieDataSet.setSliceSpace(2); pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(12); pieDataSet.setValueTextSize(0);
//add colors to dataset //add colors to dataset
ArrayList<Integer> colors = new ArrayList<>(); ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.GRAY);
colors.add(Color.BLUE); colors.add(Color.BLUE);
colors.add(Color.RED); colors.add(Color.RED);
colors.add(Color.GREEN); colors.add(Color.GREEN);
colors.add(Color.CYAN); colors.add(Color.DKGRAY);
colors.add(Color.YELLOW); colors.add(Color.BLACK);
colors.add(Color.MAGENTA); colors.add(Color.MAGENTA);
pieDataSet.setColors(colors); pieDataSet.setColors(colors);
//add legend to chart
Legend legend = pieChart.getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART);
//create pie data object //create pie data object
PieData pieData = new PieData(pieDataSet); PieData pieData = new PieData(pieDataSet);
pieChart.setData(pieData); pieChart.setData(pieData);
pieChart.invalidate(); pieChart.animateXY(1500,1500, Easing.EasingOption.EaseInOutSine, Easing.EasingOption.EaseInOutSine);
} }
} }
...@@ -81,7 +81,7 @@ public class SignUpActivity extends AppCompatActivity { ...@@ -81,7 +81,7 @@ public class SignUpActivity extends AppCompatActivity {
mDatabase.child("users").child(userId).child("Name").setValue(u_name); mDatabase.child("users").child(userId).child("Name").setValue(u_name);
mDatabase.child("users").child(userId).child("Username").setValue(u_username); mDatabase.child("users").child(userId).child("Username").setValue(u_username);
mDatabase.child("users").child(userId).child("Age").setValue(u_age); mDatabase.child("users").child(userId).child("Age").setValue(u_age);
pd.hide(); pd.dismiss();
Toast.makeText(SignUpActivity.this, "Registered Successfully!", Toast.LENGTH_SHORT).show(); Toast.makeText(SignUpActivity.this, "Registered Successfully!", Toast.LENGTH_SHORT).show();
Toast.makeText(SignUpActivity.this, "Please Log in to proceed", Toast.LENGTH_SHORT).show(); Toast.makeText(SignUpActivity.this, "Please Log in to proceed", Toast.LENGTH_SHORT).show();
finish(); finish();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment