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

Chnaged the app to get bookmarks

parent c4f37ea4
Branches
No related tags found
No related merge requests found
Showing
with 255 additions and 185 deletions
......@@ -37,4 +37,5 @@ dependencies {
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
package com.example.taskboxx;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight;
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.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static android.content.ContentValues.TAG;
public class AnalyticsFragment extends Fragment {
private FirebaseAuth mAuth;
private DatabaseReference mDatabase;
private ArrayList<Float> yData = new ArrayList<>();
private ArrayList<String> xData = new ArrayList<>();
PieChart pieChart;
ProgressDialog pd;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.analytics_fragment,container,false);
getActivity().setTitle("Analytics");
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
pd = new ProgressDialog(Dashboard.getContext1());
pieChart = (PieChart) rootView.findViewById(R.id.idPieChart);
pd.setMessage("Loading...");
pd.show();
pieChart.setDescription(null);
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(60f);
pieChart.setUsePercentValues(true);
pieChart.setTransparentCircleAlpha(175);
pieChart.setTransparentCircleRadius(63f);
pieChart.setCenterText("Browsing Content");
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();
}
@Override
public void onCancelled(DatabaseError error) {
Toast.makeText(getActivity(), "Cannot Retrieve Data from Database", Toast.LENGTH_SHORT).show();
}
});
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
int pos1 = e.toString().indexOf("(sum): ");
String percent = e.toString().substring(pos1 + 7);
for(int i = 0; i < yData.size(); i++){
if(yData.get(i) == Float.parseFloat(percent)){
pos1 = i;
break;
}
}
String type = xData.get(pos1);
Toast.makeText(getActivity(), "You browse for " + type + "\n" + "for " + percent + "% of the time", Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected() {
}
});
return rootView;
}
private void addDataSet() {
final ArrayList<PieEntry> yEntrys = new ArrayList<>();
for(int i = 0; i < yData.size(); i++){
yEntrys.add(new PieEntry(yData.get(i) , xData.get(i)));
}
//create the data set
PieDataSet pieDataSet = new PieDataSet(yEntrys, "Your Browsing Content");
pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(0);
//add colors to dataset
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.BLUE);
colors.add(Color.RED);
colors.add(Color.GREEN);
colors.add(Color.DKGRAY);
colors.add(Color.BLACK);
colors.add(Color.MAGENTA);
pieDataSet.setColors(colors);
pd.dismiss();
//create pie data object
PieData pieData = new PieData(pieDataSet);
pieChart.setData(pieData);
pieChart.animateXY(1500,1500, Easing.EasingOption.EaseInOutSine, Easing.EasingOption.EaseInOutSine);
}
}
......@@ -44,8 +44,8 @@ public class Dashboard extends AppCompatActivity
navigationView.getMenu().getItem(1).setChecked(true);
FragmentManager fragmentManager = getFragmentManager();
Fragment dashboardFragment = new DashboardFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,dashboardFragment).commit();
Fragment DashboardFragment = new DashboardFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,DashboardFragment).commit();
new BrowserDataGetter().execute("");
......@@ -98,9 +98,12 @@ public class Dashboard extends AppCompatActivity
if (id == R.id.nav_my_account) {
Fragment myAccountFragment = new MyAccountFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,myAccountFragment).commit();
} else if (id == R.id.nav_analytics) {
Fragment AnalyticsFragment = new AnalyticsFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,AnalyticsFragment).commit();
} else if (id == R.id.nav_dashboard){
Fragment dashboardFragment = new DashboardFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,dashboardFragment).commit();
Fragment DashboardFragment = new DashboardFragment();
fragmentManager.beginTransaction().replace(R.id.content_frame,DashboardFragment).commit();
} else if (id == R.id.nav_logout) {
mAuth.getInstance().signOut();
finish();
......
package com.example.taskboxx;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight;
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.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import static android.content.ContentValues.TAG;
public class DashboardFragment extends Fragment {
private FirebaseAuth mAuth;
private DatabaseReference mDatabase;
private ArrayList<Float> yData = new ArrayList<>();
private ArrayList<String> xData = new ArrayList<>();
PieChart pieChart;
ProgressDialog pd;
ArrayList<String> bookmarks;
ListView bookmarksView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_dashboard_fragment,container,false);
View rootView = inflater.inflate(R.layout.dashboard_fragment,container,false);
getActivity().setTitle("Dashboard");
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
pd = new ProgressDialog(Dashboard.getContext1());
pieChart = (PieChart) rootView.findViewById(R.id.idPieChart);
pd.setMessage("Loading...");
pd.show();
pieChart.setDescription(null);
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(60f);
pieChart.setUsePercentValues(true);
pieChart.setTransparentCircleAlpha(175);
pieChart.setTransparentCircleRadius(63f);
pieChart.setCenterText("Browsing Content");
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();
}
@Override
public void onCancelled(DatabaseError error) {
Toast.makeText(getActivity(), "Cannot Retrieve Data from Database", Toast.LENGTH_SHORT).show();
}
});
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
int pos1 = e.toString().indexOf("(sum): ");
String percent = e.toString().substring(pos1 + 7);
bookmarksView = (ListView) rootView.findViewById(R.id.bookmarks);
bookmarks = new ArrayList<>();
getBookmarks();
for(int i = 0; i < yData.size(); i++){
if(yData.get(i) == Float.parseFloat(percent)){
pos1 = i;
break;
}
}
String type = xData.get(pos1);
Toast.makeText(getActivity(), "You browse for " + type + "\n" + "for " + percent + "% of the time", Toast.LENGTH_LONG).show();
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),android.R.layout.simple_list_item_1,bookmarks);
bookmarksView.setAdapter(arrayAdapter);
bookmarksView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onNothingSelected() {
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
String selectedbookmark = bookmarks.get(position);
Toast.makeText(getActivity().getApplicationContext(), "Bookmark selected: "+selectedbookmark, Toast.LENGTH_SHORT).show();
}
});
return rootView;
}
private void addDataSet() {
final ArrayList<PieEntry> yEntrys = new ArrayList<>();
for(int i = 0; i < yData.size(); i++){
yEntrys.add(new PieEntry(yData.get(i) , xData.get(i)));
public void getBookmarks(){
bookmarks.add("Google");
bookmarks.add("Facebook");
bookmarks.add("Youtube");
bookmarks.add("Gmail");
bookmarks.add("Tinder");
bookmarks.add("Twitch");
}
//create the data set
PieDataSet pieDataSet = new PieDataSet(yEntrys, "Your Browsing Content");
pieDataSet.setSliceSpace(2);
pieDataSet.setValueTextSize(0);
//add colors to dataset
ArrayList<Integer> colors = new ArrayList<>();
colors.add(Color.BLUE);
colors.add(Color.RED);
colors.add(Color.GREEN);
colors.add(Color.DKGRAY);
colors.add(Color.BLACK);
colors.add(Color.MAGENTA);
pieDataSet.setColors(colors);
pd.dismiss();
//create pie data object
PieData pieData = new PieData(pieDataSet);
pieChart.setData(pieData);
pieChart.animateXY(1500,1500, Easing.EasingOption.EaseInOutSine, Easing.EasingOption.EaseInOutSine);
}
}
......@@ -10,7 +10,7 @@ public class MyAccountFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_my_account_fragment,container,false);
View rootView = inflater.inflate(R.layout.my_account_fragment,container,false);
getActivity().setTitle("My Account");
return rootView;
}
......
......@@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M6,7h2.5L5,3.5 1.5,7L4,7v10L1.5,17L5,20.5 8.5,17L6,17L6,7zM10,5v2h12L22,5L10,5zM10,19h12v-2L10,17v2zM10,13h12v-2L10,11v2z"/>
android:fillColor="@color/colorAccent"
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorAccent"
android:pathData="M12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6h1.9c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM18,20L6,20L6,10h12v10z"/>
</vector>
......@@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/LoginPass_textLayout"
android:layout_below="@+id/input_password_login"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginTop="42.5dp"
......@@ -26,39 +26,31 @@
android:text="Sign In" />
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#000000"
android:layout_marginTop="20dp"
android:id="@+id/LoginUname_textLayout"
android:layout_below="@+id/Logo">
<EditText android:id="@+id/input_uname_login"
android:layout_width="match_parent"
android:layout_below="@+id/Logo"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:drawableLeft="@drawable/ic_email"
android:drawablePadding="10dp"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="40dp"
android:inputType="textEmailAddress"
android:hint="Registered Email" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#000000"
android:layout_marginTop="20dp"
android:id="@+id/LoginPass_textLayout"
android:layout_below="@+id/LoginUname_textLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText android:id="@+id/input_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_password"
android:layout_below="@+id/input_uname_login"
android:drawablePadding="10dp"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:inputType="textPassword"
android:hint="Password" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="@+id/Logo"
......@@ -72,7 +64,7 @@
<TextView
android:id="@+id/launch_signup"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_height="35dp"
android:gravity="center"
android:textColor="@color/colorAccent"
android:layout_alignParentBottom="true"
......@@ -91,4 +83,5 @@
android:layout_above="@+id/launch_signup"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp" />
</RelativeLayout>
......@@ -30,8 +30,7 @@
android:layout_below="@+id/Explanation"
android:layout_marginTop="20dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout">
android:layout_alignParentStart="true">
<EditText android:id="@+id/input_Name_SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -49,8 +48,7 @@
android:layout_marginTop="20dp"
android:layout_below="@+id/SignUpName_textLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout">
android:layout_alignParentStart="true">
<EditText android:id="@+id/input_Username_SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -68,8 +66,7 @@
android:layout_marginTop="20dp"
android:layout_below="@+id/SignUpName_textLayout"
android:layout_toEndOf="@+id/SignUpUsername_textLayout"
android:layout_toRightOf="@+id/SignUpUsername_textLayout"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout">
android:layout_toRightOf="@+id/SignUpUsername_textLayout">
<EditText android:id="@+id/input_Age_SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -87,8 +84,7 @@
android:layout_marginTop="20dp"
android:layout_below="@+id/SignUpUsername_textLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout1">
android:layout_alignParentStart="true">
<EditText
android:id="@+id/input_email_SignUp"
......@@ -108,8 +104,7 @@
android:layout_marginTop="20dp"
android:layout_below="@+id/SignUpemail_textLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout1">
android:layout_alignParentStart="true" >
<EditText android:id="@+id/input_NewPass_SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -127,8 +122,7 @@
android:layout_marginTop="20dp"
android:layout_below="@+id/SignUpNewPass_textLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:hintTextAppearance="@style/TextAppearance.TextInputLayout1">
android:layout_alignParentStart="true">
<EditText android:id="@+id/input_RePass_SignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
......@@ -8,7 +8,7 @@
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:paddingBottom="16dp"
tools:context="com.example.taskboxx.DashboardFragment">
tools:context="com.example.taskboxx.AnalyticsFragment">
<TextView
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?actionBarSize"
tools:context="com.example.taskboxx.DashboardFragment">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bookmarks">
</ListView>
</RelativeLayout>
......@@ -9,7 +9,9 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="16dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="My Account"/>
......
......@@ -10,12 +10,9 @@
android:id="@+id/nav_dashboard"
android:icon="@drawable/ic_dashboard_"
android:title="Dashboard" />
<item
android:id="@+id/nav_recsys"
android:icon="@drawable/recsys"
android:title="Recommendations" />
android:id="@+id/nav_analytics"
android:title="Analytics" />
</group>
<item android:title="Account">
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#795548</color>
<color name="colorPrimaryDark">#5D4037</color>
<color name="colorAccent">#EEEEEE</color>
<color name="colorPrimaryDark">#5d4037</color>
<color name="colorAccent">#f9a825</color>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment