package com.notificationFramework.sedentary.frontEnd; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.ProgressBar; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.DataPoint; import com.jjoe64.graphview.series.LineGraphSeries; import java.util.List; /** * Created by Peter De Jonckheere on 22/01/2018. * <p> * The activity whihc is used when a notification is clicked on. This currently uses the main * activity layout and is only a class on its own so that a notification click can be recorded * in the logs. * </p> */ public class NotificationClicked extends AppCompatActivity { /** * Called when a notification is clicked on. Sets up the layout using that which is defined in * activity_main.xml and the delegates to further methods to set up the buttons for the page. * * @param savedInstanceState contains information pertaining to previous states of the activity * if it has been used before * @see android.support.v7.app.AppCompatActivity */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setUpButtons(); } /** * When this activity is started regardless of whether it has been created a clicked * notification is recorded. */ @Override protected void onStart() { super.onStart(); SaveFile.recordNotification(0, 1, 0,0, this); } /** * Sets up the buttons for this page and also adds the current minute value to the progress bar. */ private void setUpButtons() { Button settings = findViewById(R.id.settings); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(view.getContext(), Settings.class); startActivity(intent); } }); SharedPreferences shared = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE); ProgressBar progress = findViewById(R.id.progressBar); progress.setMax((shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes))); progress.setProgress(shared.getInt(getString(R.string.daily_progress), 0)); setUpGraph(); } private void setUpGraph(){ GraphView graph = (GraphView) findViewById(R.id.graph); List<Integer> acks = SaveFile.getWeeklyAcks(this.getApplicationContext()); DataPoint[] dataPoints = new DataPoint[7]; int j = 0; for(int i = 0; i < acks.size(); i =+ 2){ DataPoint dp = new DataPoint(acks.get(i), acks.get(i+1)); dataPoints[j] = dp; j++; } for(int i = 0; i < 7; i++){ if(dataPoints[i] == null){ dataPoints[i] = new DataPoint(0, 0); } } LineGraphSeries<DataPoint> series = new LineGraphSeries<>(dataPoints); graph.addSeries(series); graph.setTitle(getString(R.string.your_progress)); } }