Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Passcode java
- package com.example.bootstraps;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- public class MainActivity extends AppCompatActivity {
- List<Integer> pass = new ArrayList<Integer>();
- List<Integer> mass = new ArrayList();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mass.add(1);
- mass.add(1);
- mass.add(1);
- mass.add(1);
- }
- public void passkey1(View view) {
- pass.add(1);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey2(View view) {
- pass.add(2);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey3(View view) {
- pass.add(3);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey4(View view) {
- pass.add(4);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey5(View view) {
- pass.add(5);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey6(View view) {
- pass.add(6);
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- public void passkey7(View view) {
- pass.add(7);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey8(View view) {
- pass.add(8);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey9(View view) {
- pass.add(9);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- public void passkey0(View view) {
- pass.add(0);
- if(pass.size() >= 4) {
- if (pass.equals(mass)) {
- Intent load = new Intent(this, ShowData.class);
- load.putExtra("PIN", pass.toString());
- startActivity(load);
- } else {
- Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
- pass = new ArrayList<Integer>();
- }
- }
- }
- }
- ###Report form Java
- package com.example.bootstraps;
- import androidx.annotation.RequiresApi;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.icu.text.SimpleDateFormat;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Environment;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.RatingBar;
- import android.widget.Toast;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.util.Date;
- import java.util.Locale;
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.util.List;
- public class report_form extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_report_form);
- String Stringpass = getIntent().getStringExtra("PIN");
- Scanner scanner = new Scanner(Stringpass);
- List<Integer> pass = new ArrayList<Integer>();
- while (scanner.hasNextInt()) {
- pass.add(scanner.nextInt());
- }
- addListenerOnButton();
- }
- public void addListenerOnButton() {
- RadioGroup radioHWTGroup = (RadioGroup) findViewById(R.id.Dep_Form_HWT_RadialGroup);
- RadioGroup radioHGroup = (RadioGroup) findViewById(R.id.Dep_Form_H_RadialGroup);
- Button btnSubmit = (Button) findViewById(R.id.Dep_Form_button);
- btnSubmit.setOnClickListener(new View.OnClickListener() {
- @RequiresApi(api = Build.VERSION_CODES.O)
- @Override
- public void onClick(View v) {
- //get selected radio button from radio group
- int SelectedId = radioHWTGroup.getCheckedRadioButtonId();
- RadioButton radioHWTButton = (RadioButton) findViewById(SelectedId);
- RadioButton radioHButton = (RadioButton) findViewById(SelectedId);
- EditText commentbox = (EditText) findViewById(R.id.Dep_form_comment);
- String comment = commentbox.getText().toString();
- String HWTText = radioHWTButton.getText().toString();
- String HText = radioHButton.getText().toString();
- String currentDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
- String data = String.join("\t", currentDate, HWTText, HText, comment);
- try {
- writeToFile(data);
- } catch (IOException e) {
- Log.e("Exception", "File write failed: " + e.toString());
- }
- ChangeData();
- }
- });
- }
- public void ChangeData() {
- Intent load = new Intent(this, ShowData.class);
- startActivity(load);
- }
- public void SwtichtoReprotForm(View view) {
- Intent load = new Intent(this, report_form.class);
- startActivity(load);
- }
- public void SwtichtoData(View view) {
- Intent load = new Intent(this, ShowData.class);
- startActivity(load);
- }
- public void writeToFile(String data) throws IOException {
- // Get the directory for the user's public pictures directory.
- final File file = new File(this.getFilesDir(), "DataLogs.tsv");
- // Save your stream, don't forget to flush() it before closing it.
- if (!file.exists()){
- file.createNewFile();
- }
- try
- {
- FileOutputStream fOut = openFileOutput("DataLogs.tsv", MODE_APPEND);
- OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
- myOutWriter.append(data);
- myOutWriter.close();
- fOut.flush();
- fOut.close();
- Log.e("Exception", "It Worked ");
- }
- catch (IOException e)
- {
- Log.e("Exception", "File write failed: " + e.toString());
- }
- }
- }
- ###ShowData
- package com.example.bootstraps;
- import androidx.annotation.RequiresApi;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.Intent;
- import android.graphics.Color;
- import android.icu.text.SimpleDateFormat;
- import android.os.Build;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.TextView;
- import com.softmoore.android.graphlib.Graph;
- import com.softmoore.android.graphlib.GraphView;
- import com.softmoore.android.graphlib.Point;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.OutputStreamWriter;
- import java.text.ParseException;
- import java.time.Duration;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.LinkedList;
- import java.util.List;
- public class ShowData extends AppCompatActivity {
- @RequiresApi(api = Build.VERSION_CODES.O)
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_show_data);
- ArrayList<String> Data = readFile();
- Log.e("Exception", "File : " + Data.size());
- List<Point> catPoints = new LinkedList<Point>();
- for (int i = 0; i < Data.size()-1 ; i++) {
- String How = (Data.get(i));
- int valuething = Integer.parseInt(How);
- catPoints.add(new Point(i,valuething));
- }
- Log.e("Exception", "PointValues : "+ catPoints);
- Date past = readDate();
- Date now = new Date();
- Duration diff = Duration.between(past.toInstant(), now.toInstant());
- long diffDays = diff.toDays();
- Log.e("Exception", "Number of days : "+past + "-"+now + diffDays);
- setContentView(R.layout.activity_show_data);
- TextView textView = (TextView) findViewById(R.id.counter);
- textView.setText(String.valueOf(diffDays) + " Days Sober");
- Point[] points =
- {
- new Point(0, 2), new Point(1, 5), new Point(2, 6),
- new Point(3, 8), new Point(4, 7), new Point(5, 4),
- new Point(6, 7), new Point(7, 6), new Point(8, 1),
- new Point(9, 1), new Point(9, 4)
- };
- Graph graph = new Graph.Builder()
- .setWorldCoordinates(-0, 7, 0, 9)
- .setAxes(0, 167)
- .setXTicks(new double[] {5, 10, 15, 20, 25, 30})
- .setYTicks(new double[] {170, 175, 180, 185, 190})
- .setBackgroundColor(Color.rgb(30, 30, 36))
- .setAxesColor(Color.rgb(191, 172, 181))
- .addLineGraph(points,Color.rgb(244, 241, 187)) //rgb(244, 241, 187)
- .build();
- GraphView graphView = findViewById(R.id.graph_view);
- graphView.setGraph(graph);
- setTitle("Tracker");
- }
- public void SwtichtoReprotForm(View view) {
- Intent load = new Intent(this, report_form.class);
- load.putExtra("PIN", "1111");
- startActivity(load);
- }
- public void SwtichtoData(View view) {
- Intent load = new Intent(this, ShowData.class);
- startActivity(load);
- }
- private ArrayList<String> readFile() {
- File fileEvents = new File(this.getFilesDir(), "DataLogs.tsv");
- ArrayList<String> text = new ArrayList<>();
- try {
- BufferedReader br = new BufferedReader(new FileReader(fileEvents));
- String line;
- while ((line = br.readLine()) != null) {
- String[] lineItems = line.split("\t"); //splitting the line and adding its items in String[]
- text.add(lineItems[1]);
- }
- br.close();
- } catch (IOException e) { }
- Log.e("Exception", "Data: " + text);
- return text;
- }
- private Date readDate() {
- File fileEvents = new File(this.getFilesDir(), "CounterLogs.tsv");
- ArrayList<String> text = new ArrayList<>();
- try {
- BufferedReader br = new BufferedReader(new FileReader(fileEvents));
- String line;
- while ((line = br.readLine()) != null) {
- String lineItems = line; //splitting the line and adding its items in String[]
- text.add(lineItems);
- }
- br.close();
- } catch (IOException e) { }
- String tex = String.valueOf(text.get(0));
- Log.e("Exception", "Thingymicthing : "+tex);
- System.out.println("Current Date Time : " + tex);
- String dtStart = "2021-05-05T09:27:37Z";
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- try {
- Date date = format.parse(tex);
- System.out.println(date);
- return date;
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return null;
- }
- public void resetdate(View view) throws IOException {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- Date date = new Date();
- String dateTime = dateFormat.format(date);
- System.out.println("Current Date Time : " + dateTime);
- // Get the directory for the user's public pictures directory.
- final File file = new File(this.getFilesDir(), "CounterLogs.tsv");
- // Save your stream, don't forget to flush() it before closing it.
- if (!file.exists()){
- file.createNewFile();
- }
- try
- {
- FileOutputStream fOut = new FileOutputStream(file);
- OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
- myOutWriter.append(dateTime);
- myOutWriter.close();
- fOut.flush();
- fOut.close();
- Log.e("Exception", "It Worked ");
- }
- catch (IOException e)
- {
- Log.e("Exception", "File write failed: " + e.toString());
- }
- this.recreate();
- }
- public void SecretTestDate(View view) throws IOException {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
- Date date = new Date(01,05,02);
- String dateTime = dateFormat.format(date);
- System.out.println("Current Date Time : " + dateTime);
- // Get the directory for the user's public pictures directory.
- final File file = new File(this.getFilesDir(), "CounterLogs.tsv");
- // Save your stream, don't forget to flush() it before closing it.
- if (!file.exists()){
- file.createNewFile();
- }
- try
- {
- FileOutputStream fOut = new FileOutputStream(file);
- OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
- myOutWriter.append(dateTime);
- myOutWriter.close();
- fOut.flush();
- fOut.close();
- Log.e("Exception", "It Worked ");
- }
- catch (IOException e)
- {
- Log.e("Exception", "File write failed: " + e.toString());
- }
- this.recreate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement