Advertisement
Ghureg

Advanced Project Java

May 12th, 2021 (edited)
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.73 KB | None | 0 0
  1. ### Passcode java
  2.  
  3. package com.example.bootstraps;
  4.  
  5. import androidx.appcompat.app.AppCompatActivity;
  6.  
  7. import android.content.Intent;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11.  
  12. import java.util.ArrayList;
  13. import java.util.Arrays;
  14. import java.util.List;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.     List<Integer> pass = new ArrayList<Integer>();
  18.     List<Integer> mass = new ArrayList();
  19.  
  20.     @Override
  21.     protected void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_main);
  24.         mass.add(1);
  25.         mass.add(1);
  26.         mass.add(1);
  27.         mass.add(1);
  28.     }
  29.     public void passkey1(View view) {
  30.         pass.add(1);
  31.         if(pass.size() >= 4) {
  32.             if (pass.equals(mass)) {
  33.                 Intent load = new Intent(this, ShowData.class);
  34.                 load.putExtra("PIN", pass.toString());
  35.                 startActivity(load);
  36.             } else {
  37.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  38.                 pass = new ArrayList<Integer>();
  39.             }
  40.         }
  41.     }
  42.     public void passkey2(View view) {
  43.         pass.add(2);
  44.         if(pass.size() >= 4) {
  45.             if (pass.equals(mass)) {
  46.                 Intent load = new Intent(this, ShowData.class);
  47.                 load.putExtra("PIN", pass.toString());
  48.                 startActivity(load);
  49.             } else {
  50.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  51.                 pass = new ArrayList<Integer>();
  52.             }
  53.         }
  54.     }
  55.     public void passkey3(View view) {
  56.         pass.add(3);
  57.         if(pass.size() >= 4) {
  58.             if (pass.equals(mass)) {
  59.                 Intent load = new Intent(this, ShowData.class);
  60.                 load.putExtra("PIN", pass.toString());
  61.                 startActivity(load);
  62.             } else {
  63.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  64.                 pass = new ArrayList<Integer>();
  65.             }
  66.         }
  67.     }
  68.     public void passkey4(View view) {
  69.         pass.add(4);
  70.         if(pass.size() >= 4) {
  71.             if (pass.equals(mass)) {
  72.                 Intent load = new Intent(this, ShowData.class);
  73.                 load.putExtra("PIN", pass.toString());
  74.                 startActivity(load);
  75.             } else {
  76.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  77.                 pass = new ArrayList<Integer>();
  78.             }
  79.         }
  80.     }
  81.     public void passkey5(View view) {
  82.         pass.add(5);
  83.         if(pass.size() >= 4) {
  84.             if (pass.equals(mass)) {
  85.                 Intent load = new Intent(this, ShowData.class);
  86.                 load.putExtra("PIN", pass.toString());
  87.                 startActivity(load);
  88.             } else {
  89.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  90.                 pass = new ArrayList<Integer>();
  91.             }
  92.         }
  93.     }
  94.     public void passkey6(View view) {
  95.         pass.add(6);
  96.         if (pass.equals(mass)) {
  97.             Intent load = new Intent(this, ShowData.class);
  98.             load.putExtra("PIN", pass.toString());
  99.             startActivity(load);
  100.         } else {
  101.             Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  102.             pass = new ArrayList<Integer>();
  103.         }
  104.     }
  105.  
  106.     public void passkey7(View view) {
  107.         pass.add(7);
  108.         if(pass.size() >= 4) {
  109.             if (pass.equals(mass)) {
  110.                 Intent load = new Intent(this, ShowData.class);
  111.                 load.putExtra("PIN", pass.toString());
  112.                 startActivity(load);
  113.             } else {
  114.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  115.                 pass = new ArrayList<Integer>();
  116.             }
  117.         }
  118.     }
  119.     public void passkey8(View view) {
  120.         pass.add(8);
  121.         if(pass.size() >= 4) {
  122.             if (pass.equals(mass)) {
  123.                 Intent load = new Intent(this, ShowData.class);
  124.                 load.putExtra("PIN", pass.toString());
  125.                 startActivity(load);
  126.             } else {
  127.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  128.                 pass = new ArrayList<Integer>();
  129.             }
  130.         }
  131.     }
  132.     public void passkey9(View view) {
  133.         pass.add(9);
  134.         if(pass.size() >= 4) {
  135.             if (pass.equals(mass)) {
  136.                 Intent load = new Intent(this, ShowData.class);
  137.                 load.putExtra("PIN", pass.toString());
  138.                 startActivity(load);
  139.             } else {
  140.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  141.                 pass = new ArrayList<Integer>();
  142.             }
  143.         }
  144.     }
  145.     public void passkey0(View view) {
  146.         pass.add(0);
  147.         if(pass.size() >= 4) {
  148.             if (pass.equals(mass)) {
  149.                 Intent load = new Intent(this, ShowData.class);
  150.                 load.putExtra("PIN", pass.toString());
  151.                 startActivity(load);
  152.             } else {
  153.                 Log.e("Exception", "Invalid Pass" + pass.toString() + mass.toString());
  154.                 pass = new ArrayList<Integer>();
  155.             }
  156.         }
  157.     }
  158. }
  159.  
  160. ###Report form Java
  161.  
  162. package com.example.bootstraps;
  163.  
  164. import androidx.annotation.RequiresApi;
  165. import androidx.appcompat.app.AppCompatActivity;
  166.  
  167. import android.content.Context;
  168. import android.content.DialogInterface;
  169. import android.content.Intent;
  170. import android.icu.text.SimpleDateFormat;
  171. import android.os.Build;
  172. import android.os.Bundle;
  173. import android.os.Environment;
  174. import android.util.Log;
  175. import android.view.View;
  176. import android.widget.Button;
  177. import android.widget.EditText;
  178. import android.widget.RadioButton;
  179. import android.widget.RadioGroup;
  180. import android.widget.RatingBar;
  181. import android.widget.Toast;
  182.  
  183. import java.io.File;
  184. import java.io.FileOutputStream;
  185. import java.io.IOException;
  186. import java.io.OutputStreamWriter;
  187. import java.util.Date;
  188. import java.util.Locale;
  189. import java.util.Scanner;
  190.  
  191. import java.util.ArrayList;
  192. import java.util.List;
  193.  
  194. public class report_form extends AppCompatActivity {
  195.  
  196.     @Override
  197.     protected void onCreate(Bundle savedInstanceState) {
  198.         super.onCreate(savedInstanceState);
  199.         setContentView(R.layout.activity_report_form);
  200.  
  201.         String Stringpass = getIntent().getStringExtra("PIN");
  202.         Scanner scanner = new Scanner(Stringpass);
  203.         List<Integer> pass = new ArrayList<Integer>();
  204.         while (scanner.hasNextInt()) {
  205.             pass.add(scanner.nextInt());
  206.         }
  207.         addListenerOnButton();
  208.     }
  209.     public void addListenerOnButton() {
  210.         RadioGroup radioHWTGroup = (RadioGroup) findViewById(R.id.Dep_Form_HWT_RadialGroup);
  211.         RadioGroup radioHGroup = (RadioGroup) findViewById(R.id.Dep_Form_H_RadialGroup);
  212.         Button btnSubmit = (Button) findViewById(R.id.Dep_Form_button);
  213.         btnSubmit.setOnClickListener(new View.OnClickListener() {
  214.             @RequiresApi(api = Build.VERSION_CODES.O)
  215.             @Override
  216.             public void onClick(View v) {
  217.                 //get selected radio button from radio group
  218.                 int SelectedId = radioHWTGroup.getCheckedRadioButtonId();
  219.                 RadioButton radioHWTButton = (RadioButton) findViewById(SelectedId);
  220.                 RadioButton radioHButton = (RadioButton) findViewById(SelectedId);
  221.                 EditText commentbox = (EditText) findViewById(R.id.Dep_form_comment);
  222.                 String comment = commentbox.getText().toString();
  223.                 String HWTText = radioHWTButton.getText().toString();
  224.                 String HText = radioHButton.getText().toString();
  225.                 String currentDate = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
  226.                 String data = String.join("\t", currentDate, HWTText, HText, comment);
  227.                 try {
  228.                     writeToFile(data);
  229.                 } catch (IOException e) {
  230.                     Log.e("Exception", "File write failed: " + e.toString());
  231.                 }
  232.                 ChangeData();
  233.  
  234.             }
  235.  
  236.  
  237.         });
  238.  
  239.  
  240.     }
  241.     public void ChangeData() {
  242.         Intent load = new Intent(this, ShowData.class);
  243.         startActivity(load);
  244.     }
  245.     public void SwtichtoReprotForm(View view) {
  246.         Intent load = new Intent(this, report_form.class);
  247.         startActivity(load);
  248.     }
  249.     public void SwtichtoData(View view) {
  250.         Intent load = new Intent(this, ShowData.class);
  251.         startActivity(load);
  252.     }
  253.     public void writeToFile(String data) throws IOException {
  254.         // Get the directory for the user's public pictures directory.
  255.         final File file = new File(this.getFilesDir(), "DataLogs.tsv");
  256.  
  257.  
  258.         // Save your stream, don't forget to flush() it before closing it.
  259.         if (!file.exists()){
  260.             file.createNewFile();
  261.         }
  262.         try
  263.         {
  264.             FileOutputStream fOut = openFileOutput("DataLogs.tsv", MODE_APPEND);
  265.             OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
  266.             myOutWriter.append(data);
  267.  
  268.             myOutWriter.close();
  269.  
  270.             fOut.flush();
  271.             fOut.close();
  272.  
  273.             Log.e("Exception", "It Worked ");
  274.         }
  275.         catch (IOException e)
  276.         {
  277.             Log.e("Exception", "File write failed: " + e.toString());
  278.         }
  279.     }
  280. }
  281.  
  282.  
  283. ###ShowData
  284. package com.example.bootstraps;
  285.  
  286. import androidx.annotation.RequiresApi;
  287. import androidx.appcompat.app.AppCompatActivity;
  288.  
  289. import android.content.Intent;
  290. import android.graphics.Color;
  291. import android.icu.text.SimpleDateFormat;
  292. import android.os.Build;
  293. import android.os.Bundle;
  294. import android.util.Log;
  295. import android.view.View;
  296. import android.widget.TextView;
  297.  
  298. import com.softmoore.android.graphlib.Graph;
  299. import com.softmoore.android.graphlib.GraphView;
  300. import com.softmoore.android.graphlib.Point;
  301.  
  302. import java.io.BufferedReader;
  303. import java.io.File;
  304. import java.io.FileOutputStream;
  305. import java.io.FileReader;
  306. import java.io.IOException;
  307. import java.io.OutputStreamWriter;
  308. import java.text.ParseException;
  309. import java.time.Duration;
  310. import java.util.ArrayList;
  311. import java.util.Arrays;
  312. import java.util.Date;
  313. import java.util.LinkedList;
  314. import java.util.List;
  315.  
  316. public class ShowData extends AppCompatActivity {
  317.  
  318.     @RequiresApi(api = Build.VERSION_CODES.O)
  319.     @Override
  320.     protected void onCreate(Bundle savedInstanceState) {
  321.         super.onCreate(savedInstanceState);
  322.         setContentView(R.layout.activity_show_data);
  323.         ArrayList<String> Data = readFile();
  324.         Log.e("Exception", "File : " + Data.size());
  325.         List<Point> catPoints = new LinkedList<Point>();
  326.         for (int i = 0; i < Data.size()-1 ; i++) {
  327.             String How = (Data.get(i));
  328.             int valuething = Integer.parseInt(How);
  329.             catPoints.add(new Point(i,valuething));
  330.         }
  331.         Log.e("Exception", "PointValues : "+ catPoints);
  332.         Date past = readDate();
  333.         Date now = new Date();
  334.         Duration diff = Duration.between(past.toInstant(), now.toInstant());
  335.         long diffDays = diff.toDays();
  336.         Log.e("Exception", "Number of days : "+past + "-"+now + diffDays);
  337.         setContentView(R.layout.activity_show_data);
  338.         TextView textView = (TextView) findViewById(R.id.counter);
  339.         textView.setText(String.valueOf(diffDays) + " Days Sober");
  340.         Point[] points =
  341.                 {
  342.                         new Point(0, 2),  new Point(1, 5),  new Point(2, 6),
  343.                         new Point(3, 8), new Point(4, 7), new Point(5, 4),
  344.                         new Point(6, 7), new Point(7, 6), new Point(8, 1),
  345.                         new Point(9, 1), new Point(9, 4)
  346.                 };
  347.         Graph graph = new Graph.Builder()
  348.                 .setWorldCoordinates(-0, 7, 0, 9)
  349.                 .setAxes(0, 167)
  350.                 .setXTicks(new double[] {5, 10, 15, 20, 25, 30})
  351.                 .setYTicks(new double[] {170, 175, 180, 185, 190})
  352.                 .setBackgroundColor(Color.rgb(30, 30, 36))
  353.                 .setAxesColor(Color.rgb(191, 172, 181))
  354.                 .addLineGraph(points,Color.rgb(244, 241, 187)) //rgb(244, 241, 187)
  355.                 .build();
  356.  
  357.         GraphView graphView = findViewById(R.id.graph_view);
  358.         graphView.setGraph(graph);
  359.         setTitle("Tracker");
  360.  
  361.     }
  362.     public void SwtichtoReprotForm(View view) {
  363.         Intent load = new Intent(this, report_form.class);
  364.         load.putExtra("PIN", "1111");
  365.         startActivity(load);
  366.     }
  367.     public void SwtichtoData(View view) {
  368.         Intent load = new Intent(this, ShowData.class);
  369.         startActivity(load);
  370.     }
  371.     private ArrayList<String> readFile() {
  372.         File fileEvents = new File(this.getFilesDir(), "DataLogs.tsv");
  373.         ArrayList<String> text = new ArrayList<>();
  374.         try {
  375.             BufferedReader br = new BufferedReader(new FileReader(fileEvents));
  376.             String line;
  377.             while ((line = br.readLine()) != null) {
  378.                 String[] lineItems = line.split("\t"); //splitting the line and adding its items in String[]
  379.                 text.add(lineItems[1]);
  380.             }
  381.             br.close();
  382.         } catch (IOException e) { }
  383.         Log.e("Exception", "Data: " + text);
  384.  
  385.         return text;
  386.  
  387.     }
  388.  
  389.     private Date readDate() {
  390.         File fileEvents = new File(this.getFilesDir(), "CounterLogs.tsv");
  391.         ArrayList<String> text = new ArrayList<>();
  392.         try {
  393.             BufferedReader br = new BufferedReader(new FileReader(fileEvents));
  394.             String line;
  395.             while ((line = br.readLine()) != null) {
  396.                 String lineItems = line; //splitting the line and adding its items in String[]
  397.                 text.add(lineItems);
  398.             }
  399.             br.close();
  400.         } catch (IOException e) { }
  401.         String tex = String.valueOf(text.get(0));
  402.  
  403.         Log.e("Exception", "Thingymicthing : "+tex);
  404.  
  405.         System.out.println("Current Date Time : " + tex);
  406.         String dtStart = "2021-05-05T09:27:37Z";
  407.         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  408.         try {
  409.             Date date = format.parse(tex);
  410.             System.out.println(date);
  411.             return date;
  412.         } catch (ParseException e) {
  413.             e.printStackTrace();
  414.         }
  415.  
  416.         return null;
  417.     }
  418.  
  419.     public void resetdate(View view) throws IOException {
  420.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  421.         Date date = new Date();
  422.         String dateTime = dateFormat.format(date);
  423.         System.out.println("Current Date Time : " + dateTime);
  424.         // Get the directory for the user's public pictures directory.
  425.         final File file = new File(this.getFilesDir(), "CounterLogs.tsv");
  426.  
  427.  
  428.         // Save your stream, don't forget to flush() it before closing it.
  429.         if (!file.exists()){
  430.             file.createNewFile();
  431.         }
  432.         try
  433.         {
  434.             FileOutputStream fOut = new FileOutputStream(file);
  435.             OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
  436.             myOutWriter.append(dateTime);
  437.  
  438.             myOutWriter.close();
  439.  
  440.             fOut.flush();
  441.             fOut.close();
  442.  
  443.             Log.e("Exception", "It Worked ");
  444.         }
  445.         catch (IOException e)
  446.         {
  447.             Log.e("Exception", "File write failed: " + e.toString());
  448.         }
  449.         this.recreate();
  450.     }
  451.     public void SecretTestDate(View view) throws IOException {
  452.         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
  453.         Date date = new Date(01,05,02);
  454.         String dateTime = dateFormat.format(date);
  455.         System.out.println("Current Date Time : " + dateTime);
  456.         // Get the directory for the user's public pictures directory.
  457.         final File file = new File(this.getFilesDir(), "CounterLogs.tsv");
  458.  
  459.  
  460.         // Save your stream, don't forget to flush() it before closing it.
  461.         if (!file.exists()){
  462.             file.createNewFile();
  463.         }
  464.         try
  465.         {
  466.             FileOutputStream fOut = new FileOutputStream(file);
  467.             OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
  468.             myOutWriter.append(dateTime);
  469.  
  470.             myOutWriter.close();
  471.  
  472.             fOut.flush();
  473.             fOut.close();
  474.  
  475.             Log.e("Exception", "It Worked ");
  476.         }
  477.         catch (IOException e)
  478.         {
  479.             Log.e("Exception", "File write failed: " + e.toString());
  480.         }
  481.         this.recreate();
  482.     }
  483. }
  484.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement