Advertisement
nigatigga

main

Sep 3rd, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 34.19 KB | None | 0 0
  1. package com.spicycurryman.getdisciplined10.app;
  2.  
  3. import android.app.ActionBar;
  4. import android.app.AlarmManager;
  5. import android.app.AlertDialog;
  6. import android.app.Notification;
  7. import android.app.NotificationManager;
  8. import android.app.PendingIntent;
  9. import android.content.Context;
  10. import android.content.DialogInterface;
  11. import android.content.Intent;
  12. import android.content.SharedPreferences;
  13. import android.content.pm.ActivityInfo;
  14. import android.graphics.Typeface;
  15. import android.os.Bundle;
  16. import android.os.CountDownTimer;
  17. import android.support.v7.app.ActionBarActivity;
  18. import android.text.Spannable;
  19. import android.text.SpannableString;
  20. import android.util.Log;
  21. import android.view.Menu;
  22. import android.view.MenuInflater;
  23. import android.view.View;
  24. import android.view.View.OnClickListener;
  25. import android.widget.Button;
  26. import android.widget.CheckBox;
  27. import android.widget.CompoundButton;
  28. import android.widget.SeekBar;
  29. import android.widget.SeekBar.OnSeekBarChangeListener;
  30. import android.widget.TextView;
  31.  
  32. import com.ibc.android.demo.appslist.app.HeartBeat;
  33. import com.triggertrap.seekarc.SeekArc;
  34.  
  35. import java.util.ArrayList;
  36. import java.util.Date;
  37. import java.util.Map;
  38.  
  39. public class MainActivity extends ActionBarActivity {
  40.     private SeekArc mSeekArc;
  41.     private SeekBar mRotation;
  42.     private SeekBar mStartAngle;
  43.     private SeekBar mSweepAngle;
  44.     private SeekBar mArcWidth;
  45.     private SeekBar mProgressWidth;
  46.     private CheckBox mRoundedEdges;
  47.     private CheckBox mTouchInside;
  48.     private CheckBox mClockwise;
  49.     private TextView mSeekArcProgress;
  50.     private TextView mSeekArcMinuteProgress;
  51.     private TextView mSeekArcSecondProgress;
  52.  
  53.     private Button block_button_text;
  54.     private Button start_timer_text;
  55.  
  56.     //will show the time
  57.     private TextView number_text;
  58.  
  59.     private TextView minute_text;
  60.     private TextView second_text;
  61.  
  62.  
  63.     private TextView little_hour_text;
  64.     private TextView little_minute_text;
  65.     private TextView little_second_text;
  66.  
  67.     private TextView little_hour_text2;
  68.     private TextView little_minute_text2;
  69.     private TextView little_second_text2;
  70.  
  71.     CountDownTimer countDownTimer;          // built in android class CountDownTimer
  72.     long totalTimeCountInMilliseconds;
  73.     long timeBlinkInMilliseconds;           // start time of start blinking
  74.     boolean blink;
  75.  
  76.  
  77.     SharedPreferences startimerPreferences;
  78.     SharedPreferences endTimerPreferences;
  79.     SharedPreferences endservice;
  80.  
  81.  
  82.     ArrayList<String> packagezList;
  83.     SharedPreferences sharedPrefsapp;
  84.     Map<String, ?> allEntries;
  85.  
  86.  
  87.     long timerstarted; //this is when the user hit start timer.
  88.     long timerends; //this is the time when the time when the timer will end;
  89.     long reopened; //this is when time when the user reopens the application;
  90.  
  91.  
  92.  
  93.     long newtotalTimeCountInMilliseconds;
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.     // Consider showing drawable scrubber after pressing H M or S
  102.  
  103.  
  104.  
  105.  
  106.     Button block_button1;
  107.     Button start_timer;
  108.  
  109.     int hourint, minuteint,secondint;
  110.  
  111.     public boolean onCreateOptionsMenu(Menu menu){
  112.         MenuInflater inflater = getMenuInflater();
  113.         inflater.inflate(R.menu.main, menu);
  114.         return true;
  115.     }
  116.  
  117.     View previousView;
  118.  
  119.  
  120.     @Override
  121.     protected void onCreate(Bundle savedInstanceState) {
  122.         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  123.         super.onCreate(savedInstanceState);
  124.         setTheme(R.style.Theme_Light_appalled);
  125.  
  126.         setContentView(R.layout.merge);
  127.  
  128.  
  129.         // here is where the service is started.
  130.         //startService(new Intent(this, HeartBeat.class));
  131.  
  132. /*
  133.         Intent iHeartBeatService = new Intent(this, HeartBeat.class);
  134.         PendingIntent piHeartBeatService = PendingIntent.getService(this, 0, iHeartBeatService, PendingIntent.FLAG_UPDATE_CURRENT);
  135.         AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  136.         alarmManager.cancel(piHeartBeatService);
  137.         alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 300000, piHeartBeatService);
  138. */
  139.  
  140.  
  141.         Intent ishintent = new Intent(this, HeartBeat.class);
  142.         PendingIntent pintent = PendingIntent.getService(this, 0, ishintent, 0);
  143.         AlarmManager alarm = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
  144.         alarm.cancel(pintent);
  145.         alarm.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),150000, pintent);
  146.  
  147.  
  148.  
  149.  
  150.         //set views
  151.  
  152.         start_timer = (Button) findViewById(R.id.start_button);
  153.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  154.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  155.         second_text = (TextView) findViewById(R.id.second_progress_number);
  156.  
  157.  
  158.         //getReferenceOfViews ();                         // get all views
  159.         setActionListeners ();
  160.  
  161.         // This determine what the actual "countdown" time will be.
  162.         //totalTimeCountInMilliseconds = 60 * 1000;      // time count for 3 minutes = 180 seconds
  163.         //timeBlinkInMilliseconds = 30 * 1000;
  164.  
  165.         //Make sure you find out why it appears after a whole 1 second after the app appears
  166.         SpannableString s = new SpannableString("GetDisciplined");
  167.         s.setSpan(new TypefaceSpan(this, "ralewaylight.otf"), 0, s.length(),
  168.                 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  169.  
  170. // Update the action bar title with the TypefaceSpan instance
  171.         ActionBar actionBar = getActionBar();
  172.         actionBar.setTitle(s);
  173.         // set the action bar in this activity as the home
  174.         actionBar.setHomeButtonEnabled(true);
  175.  
  176.         //Listeners for the buttons
  177.         addListenerOnButton();
  178.  
  179.  
  180.  
  181.         //Editing Button Text
  182.  
  183.         block_button_text = (Button)findViewById(R.id.block_button);
  184.         block_button_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-bold.otf"));
  185.  
  186.         start_timer_text = (Button)findViewById(R.id.start_button);
  187.         start_timer_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-bold.otf"));
  188.  
  189.         number_text = (TextView)findViewById(R.id.hour_progress_number);
  190.         number_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-semibold.otf"));
  191.  
  192.         minute_text = (TextView)findViewById(R.id.minute_progress_number);
  193.         minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-semibold.otf"));
  194.  
  195.         second_text = (TextView)findViewById(R.id.second_progress_number);
  196.         second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-semibold.otf"));
  197.  
  198.         little_hour_text = (TextView)findViewById(R.id.hourtext);
  199.         little_hour_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-regular.otf"));
  200.  
  201.         little_minute_text = (TextView)findViewById(R.id.minutetext);
  202.         little_minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-regular.otf"));
  203.  
  204.         little_second_text = (TextView)findViewById(R.id.secondtext);
  205.         little_second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-regular.otf"));
  206.  
  207.         little_hour_text2 = (TextView)findViewById(R.id.little_hour_text2);
  208.         little_hour_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-light.otf"));
  209.  
  210.         little_minute_text2 = (TextView)findViewById(R.id.little_minute_text2);
  211.         little_minute_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-light.otf"));
  212.  
  213.         little_second_text2 = (TextView)findViewById(R.id.little_second_text2);
  214.         little_second_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/raleway-light.otf"));
  215.  
  216.  
  217.  
  218.  
  219.         mSeekArc = (SeekArc) findViewById(R.id.seekArc);
  220.  
  221.  
  222. //Here is the actual "hour progress number" aka the TextView that changes as the scrubber is dragged around
  223.         mSeekArcProgress = (TextView) findViewById(R.id.hour_progress_number);
  224.  
  225.         mSeekArcMinuteProgress = (TextView) findViewById(R.id.minute_progress_number);
  226.  
  227.         mSeekArcSecondProgress = (TextView) findViewById(R.id.second_progress_number);
  228.  
  229.         startimerPreferences = getPreferences(MODE_APPEND);
  230.  
  231.         Date startDate = new Date(startimerPreferences.getLong("time", 0));
  232.         timerstarted = startDate.getTime();
  233.         Log.e("This is the start time!!!!!:  ", timerstarted + "");
  234.  
  235.  
  236.         endTimerPreferences = getPreferences(MODE_APPEND);
  237.         Date endDate = new Date(endTimerPreferences.getLong("endtime", 0));
  238.         timerends = endDate.getTime();
  239.         Log.e("This is the end time!!!!!:  ", timerends + "");
  240.  
  241.  
  242.         Date openagain = new Date(System.currentTimeMillis());
  243.         reopened = openagain.getTime();
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.         //make textview selectable
  253.  
  254.         View.OnClickListener clickListener = new View.OnClickListener() {
  255.             @Override
  256.             public void onClick(View v) {
  257.                 TextView previousText = (TextView) previousView;
  258.                 TextView curText = (TextView) v;
  259.                 // If the clicked view is selected, do nothing
  260.                 if (curText.isSelected()) {
  261.                     //curText.setSelected(false);
  262.                     //curText.setTextColor(getResources().getColor(R.color.red_highlight));
  263.                 } else { // If this isn't selected, deselect  the previous one (if any)
  264.                     if (previousText != null && previousText.isSelected()) {
  265.                         previousText.setSelected(false);
  266.                         previousText.setTextColor(getResources().getColor(R.color.red_highlight));
  267.                     }
  268.                     curText.setSelected(true);
  269.                     curText.setTextColor(getResources().getColor(R.color.black));
  270.                     previousView = v;
  271.                 }
  272.  
  273.                 if(v.getId() == R.id.hourtext){
  274.                     //corresponding button logic should below here
  275.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  276.  
  277.                         @Override
  278.                         public void onStopTrackingTouch(SeekArc seekArc) {
  279.                         }
  280.                         @Override
  281.                         public void onStartTrackingTouch(SeekArc seekArc) {
  282.                         }
  283.  
  284.  
  285.                         //This sets the actual string for the hours
  286.                         @Override
  287.                         public void onProgressChanged(SeekArc seekArc, int progress,
  288.                                                       boolean fromUser) {
  289.  
  290.                             int progress_count = 0;
  291.  
  292.                             for (int i=0;i<24;i=i+1)
  293.                             {
  294.  
  295.                                 if (progress ==120) {
  296.                                     mSeekArcProgress.setText("24");
  297.  
  298.                                 }
  299.                                 else if (progress == progress_count)
  300.                                 {
  301.                                     mSeekArcProgress.setText(String.valueOf(String.format("%02d",i)));
  302.                                 }
  303.  
  304.                                 progress_count = progress_count + 5;
  305.  
  306.                             }
  307.                         }
  308.                     });
  309.                 } else if (v.getId() == R.id.minutetext) {
  310.                     //corresponding button logic should below here
  311.  
  312.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  313.  
  314.  
  315.                         @Override
  316.                         public void onStopTrackingTouch(SeekArc seekArc) {
  317.                         }
  318.                         @Override
  319.                         public void onStartTrackingTouch(SeekArc seekArc) {
  320.                         }
  321.  
  322.  
  323.                         //This sets the actual string for the minutes
  324.                         @Override
  325.                         public void onProgressChanged(SeekArc seekArc, int progress,
  326.                                                       boolean fromUser) {
  327.                             int progress_count = 0;
  328.  
  329.                             for (int i=0;i<120;i++)
  330.                             {
  331.  
  332.                                 if (progress ==120) {
  333.                                     mSeekArcMinuteProgress.setText("00");
  334.  
  335.                                 }
  336.                                 else if (progress == progress_count)
  337.                                 {
  338.                                     mSeekArcMinuteProgress.setText(String.valueOf(String.format("%02d",i)));
  339.                                 }
  340.  
  341.                                 progress_count = progress_count + 2;
  342.  
  343.  
  344.                             }
  345.  
  346.                         }
  347.                     });
  348.                 } else if (v.getId() == R.id.secondtext) {
  349.                     //corresponding button logic should below here
  350.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  351.  
  352.                         @Override
  353.                         public void onStopTrackingTouch(SeekArc seekArc) {
  354.                         }
  355.                         @Override
  356.                         public void onStartTrackingTouch(SeekArc seekArc) {
  357.                         }
  358.  
  359.  
  360.                         //This sets the actual string for the seconds
  361.                         @Override
  362.                         public void onProgressChanged(SeekArc seekArc, int progress,
  363.                                                       boolean fromUser) {
  364.  
  365.  
  366.  
  367.                             // so ur setting it to HALF of what "progress" is = to
  368.  
  369.                             int progress_count = 0;
  370.  
  371.                             for (int i=0;i<60;i++)
  372.                             {
  373.  
  374.  
  375.                                 if (progress ==120) {
  376.                                     mSeekArcSecondProgress.setText("00");
  377.  
  378.                                 }
  379.                                 else if (progress == progress_count)
  380.                                 {
  381.                                     mSeekArcSecondProgress.setText(String.valueOf(String.format("%02d",i)));
  382.                                 }
  383.  
  384.                                 progress_count = progress_count + 2;
  385.  
  386.  
  387.                             }
  388.  
  389.                         }
  390.                     });
  391.                 }
  392.  
  393.             }
  394.         };
  395.         findViewById(R.id.hourtext).setOnClickListener(clickListener);
  396.         findViewById(R.id.minutetext).setOnClickListener(clickListener);
  397.         findViewById(R.id.secondtext).setOnClickListener(clickListener);
  398.  
  399.  
  400.         findViewById(R.id.minutetext).performClick();
  401.  
  402.  
  403.  
  404.         mRotation = (SeekBar) findViewById(R.id.rotation);
  405.         mStartAngle = (SeekBar) findViewById(R.id.startAngle);
  406.         mSweepAngle  = (SeekBar) findViewById(R.id.sweepAngle);
  407.         mArcWidth = (SeekBar) findViewById(R.id.arcWidth);
  408.         mProgressWidth = (SeekBar) findViewById(R.id.progressWidth);
  409.         mRoundedEdges = (CheckBox) findViewById(R.id.roundedEdges);
  410.         mTouchInside = (CheckBox) findViewById(R.id.touchInside);
  411.         mClockwise = (CheckBox) findViewById(R.id.clockwise);
  412.  
  413.         mRotation.setProgress(mSeekArc.getArcRotation());
  414.         mStartAngle.setProgress(mSeekArc.getStartAngle());
  415.         mSweepAngle.setProgress(mSeekArc.getSweepAngle());
  416.         mArcWidth.setProgress(mSeekArc.getArcWidth());
  417.         mProgressWidth.setProgress(mSeekArc.getProgressWidth());
  418.  
  419.  
  420.         mRotation.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  421.             @Override
  422.             public void onStopTrackingTouch(SeekBar arg0) {
  423.  
  424.             }
  425.             @Override
  426.             public void onStartTrackingTouch(SeekBar arg0) {
  427.             }
  428.  
  429.             @Override
  430.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  431.                 mSeekArc.setArcRotation(progress);
  432.                 mSeekArc.invalidate();
  433.             }
  434.         });
  435.  
  436.         mStartAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  437.             @Override
  438.             public void onStopTrackingTouch(SeekBar arg0) {
  439.  
  440.             }
  441.             @Override
  442.             public void onStartTrackingTouch(SeekBar arg0) {
  443.             }
  444.  
  445.             @Override
  446.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  447.                 mSeekArc.setStartAngle(progress);
  448.                 mSeekArc.invalidate();
  449.             }
  450.         });
  451.  
  452.         mSweepAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  453.             @Override
  454.             public void onStopTrackingTouch(SeekBar arg0) {
  455.  
  456.             }
  457.             @Override
  458.             public void onStartTrackingTouch(SeekBar arg0) {
  459.             }
  460.  
  461.             @Override
  462.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  463.                 mSeekArc.setSweepAngle(progress);
  464.                 mSeekArc.invalidate();
  465.             }
  466.         });
  467.  
  468.         mArcWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  469.             @Override
  470.             public void onStopTrackingTouch(SeekBar arg0) {
  471.  
  472.             }
  473.             @Override
  474.             public void onStartTrackingTouch(SeekBar arg0) {
  475.             }
  476.  
  477.             @Override
  478.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  479.                 mSeekArc.setArcWidth(progress);
  480.                 mSeekArc.invalidate();
  481.             }
  482.         });
  483.  
  484.         mProgressWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  485.             @Override
  486.             public void onStopTrackingTouch(SeekBar arg0) {
  487.  
  488.             }
  489.             @Override
  490.             public void onStartTrackingTouch(SeekBar arg0) {
  491.             }
  492.  
  493.             @Override
  494.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  495.                 mSeekArc.setProgressWidth(progress);
  496.                 mSeekArc.invalidate();
  497.             }
  498.         });
  499.  
  500.         mRoundedEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  501.             @Override
  502.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  503.                 mSeekArc.setRoundedEdges(isChecked);
  504.                 mSeekArc.invalidate();
  505.             }
  506.         });
  507.  
  508.         mTouchInside.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  509.             @Override
  510.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  511.                 mSeekArc.setTouchInSide(false);
  512.             }
  513.         });
  514.  
  515.         mClockwise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  516.             @Override
  517.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  518.                 mSeekArc.setClockwise(isChecked);
  519.                 mSeekArc.invalidate();
  520.             }
  521.         });
  522.  
  523.  
  524.         if(timerstarted > 0)
  525.         {
  526.             if(reopened <timerends){
  527.                 //start countdown timer with new time.
  528.                 //set countdowntime to timerends-reopen.
  529.  
  530.                 newtotalTimeCountInMilliseconds = timerends-reopened;
  531.  
  532.  
  533.  
  534.                 countDownTimer = new CountDownTimer(newtotalTimeCountInMilliseconds, 500) {
  535.                     // 500 means, onTick function will be called at every 500 milliseconds
  536.  
  537.                     @Override
  538.                     public void onTick(long leftTimeInMilliseconds) {
  539.  
  540.                         long seconds = leftTimeInMilliseconds / 1000;
  541.                         mSeekArc.setVisibility(View.INVISIBLE);
  542.                         start_timer.setVisibility(View.INVISIBLE);
  543.                         block_button1.setVisibility(View.INVISIBLE);
  544.  
  545.  
  546.                         if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
  547.                             // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
  548.                             // change the style of the textview .. giving a red alert style
  549.  
  550.                             if (blink) {
  551.                                 number_text.setVisibility(View.VISIBLE);
  552.                                 minute_text.setVisibility(View.VISIBLE);
  553.                                 second_text.setVisibility(View.VISIBLE);
  554.  
  555.  
  556.                                 // if blink is true, textview will be visible
  557.                             } else {
  558.                                 number_text.setVisibility(View.INVISIBLE);
  559.                                 minute_text.setVisibility(View.INVISIBLE);
  560.                                 second_text.setVisibility(View.INVISIBLE);
  561.  
  562.  
  563.                             }
  564.  
  565.                             blink = !blink;         // toggle the value of blink
  566.                         }
  567.  
  568.                         second_text.setText(String.format("%02d", seconds % 60));
  569.                         minute_text.setText(String.format("%02d", (seconds / 60) % 60));
  570.                         number_text.setText(String.format("%02d", seconds / 3600));                     // format the textview to show the easily readable format
  571.                     }
  572.  
  573.  
  574.                     @Override
  575.                     public void onFinish() {
  576.                         // this function will be called when the timecount is finished
  577.                         //textViewShowTime.setText("Time up!");
  578.                         number_text.setVisibility(View.VISIBLE);
  579.                         minute_text.setVisibility(View.VISIBLE);
  580.                         second_text.setVisibility(View.VISIBLE);
  581.                         mSeekArc.setVisibility(View.VISIBLE);
  582.                         start_timer.setVisibility(View.VISIBLE);
  583.                         block_button1.setVisibility(View.VISIBLE);
  584.  
  585.  
  586.                     }
  587.  
  588.                 }.start();
  589.  
  590.  
  591.  
  592.             }
  593.         }
  594.  
  595.  
  596.  
  597.  
  598.     }
  599.  
  600.     // for the on click activity responses for each of the 3 buttons on the menu
  601.     public void addListenerOnButton() {
  602.  
  603.         final Context context = this;
  604.  
  605.         block_button1 = (Button) findViewById(R.id.block_button);
  606.  
  607.         block_button1.setOnClickListener(new OnClickListener() {
  608.  
  609.             @Override
  610.             public void onClick(View arg0) {
  611.  
  612.                 Intent intent = new Intent(context, InstalledAppActivity.class);
  613.                 startActivity(intent);
  614.  
  615.             }
  616.  
  617.         });
  618.  
  619.     }
  620.  
  621.  
  622.     private void setActionListeners() {
  623.  
  624.  
  625.  
  626.  
  627.  
  628.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  629.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  630.         second_text = (TextView) findViewById(R.id.second_progress_number);
  631.  
  632.  
  633.  
  634.  
  635.         start_timer.setOnClickListener(new View.OnClickListener() {
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.             @Override
  644.             public void onClick(View view) {
  645.  
  646.  
  647.  
  648.  
  649.  
  650.                   AlertDialog.Builder zeroerror = new AlertDialog.Builder(MainActivity.this)
  651.                             .setMessage("Dude, you didn't set a time! :P")
  652.                             .setNegativeButton("Whoops! My bad!", new DialogInterface.OnClickListener() {
  653.                                 public void onClick(DialogInterface dialog, int which) {
  654.                                     Log.d("AlertDialog", "Negative");
  655.                                     dialog.cancel();
  656.                                 }
  657.                             });
  658.  
  659.  
  660.                 AlertDialog alertzero = zeroerror.create();
  661.  
  662.  
  663.                 AlertDialog.Builder noapp = new AlertDialog.Builder(MainActivity.this)
  664.                         .setMessage("Hey silly! You didn't select any apps to block!")
  665.                         .setNegativeButton("Oh, silly me!", new DialogInterface.OnClickListener() {
  666.                             public void onClick(DialogInterface dialog, int which) {
  667.                                 Log.d("AlertDialog", "Negative");
  668.                                 dialog.cancel();
  669.                             }
  670.                         });
  671.  
  672.  
  673.                 AlertDialog zeroapp = noapp.create();
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.                 AlertDialog.Builder timeset = new AlertDialog.Builder(MainActivity.this)
  681.  
  682.  
  683.                 .setMessage("Are you sure you want to block the selected apps for the set amount of time?")
  684.                 .setPositiveButton("Yeah man!", new DialogInterface.OnClickListener() {
  685.  
  686.  
  687.                                 public void onClick(DialogInterface dialog, int which) {
  688.                                     Log.d("AlertDialog", "Positive");
  689.  
  690.                                     hourint = Integer.valueOf(number_text.getText().toString());
  691.  
  692.                                     minuteint = Integer.valueOf(minute_text.getText().toString());
  693.  
  694.                                     secondint = Integer.valueOf(second_text.getText().toString());
  695.  
  696.                                     Log.i("YourActivity", "Hours: " + hourint);
  697.  
  698.                                     Log.i("YourActivity", "Minutes: " + minuteint);
  699.  
  700.                                     Log.i("YourActivity", "Seconds: " + secondint);
  701.  
  702.  
  703.                                     //Make sure it stays alive no matter what until stopservice is called when the timer runs out
  704.  
  705.  
  706.                                     //Intent intent = new Intent(getApplicationContext(), HeartBeat.class);
  707.                                     //startService(intent);
  708.  
  709.                                     Date currenttime = new Date(System.currentTimeMillis());
  710.  
  711.                                     timerstarted = currenttime.getTime();
  712.                                     Log.e("This is the current time:  ", timerstarted + "");
  713.                                     startimerPreferences = getPreferences(MODE_APPEND);
  714.                                     SharedPreferences.Editor starteditor = startimerPreferences.edit();
  715.                                     starteditor.putLong("time", timerstarted);
  716.                                     starteditor.apply();
  717.  
  718.  
  719.                                     Date endtime = new Date(System.currentTimeMillis());
  720.  
  721.                                     //timerends = endtime.getTime() + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);
  722.  
  723.                                     if ((((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000) > 0) {
  724.                                         timerends = endtime.getTime() + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);
  725.  
  726.  
  727.                                     } else {
  728.                                         timerends = 0;
  729.                                     }
  730.  
  731.  
  732.                                     Log.e("This is the end time:  ", timerends + "");
  733.                                     endTimerPreferences = getPreferences(MODE_APPEND);
  734.                                     SharedPreferences.Editor endeditor = endTimerPreferences.edit();
  735.                                     endeditor.putLong("endtime", timerends);
  736.                                     endeditor.apply();
  737.  
  738.                                     endservice = getApplicationContext().getSharedPreferences("endservice", Context.MODE_PRIVATE);
  739.                                     SharedPreferences.Editor serviceeditor = endservice.edit();
  740.                                     serviceeditor.putLong("endservice", timerstarted + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000));
  741.                                     Log.e("Check out this time:  ", timerends + "");
  742.  
  743.                                     serviceeditor.apply();
  744.  
  745.  
  746.                                     totalTimeCountInMilliseconds = (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);      // time count
  747.                                     timeBlinkInMilliseconds = 30 * 1000;
  748.  
  749.                                     countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
  750.                                         // 500 means, onTick function will be called at every 500 milliseconds
  751.  
  752.                                         @Override
  753.                                         public void onTick(long leftTimeInMilliseconds) {
  754.  
  755.                                             long seconds = leftTimeInMilliseconds / 1000;
  756.                                             mSeekArc.setVisibility(View.INVISIBLE);
  757.                                             start_timer.setVisibility(View.INVISIBLE);
  758.                                             block_button1.setVisibility(View.INVISIBLE);
  759.  
  760.  
  761.                                             if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
  762.                                                 // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
  763.                                                 // change the style of the textview .. giving a red alert style
  764.  
  765.                                                 if (blink) {
  766.                                                     number_text.setVisibility(View.VISIBLE);
  767.                                                     minute_text.setVisibility(View.VISIBLE);
  768.                                                     second_text.setVisibility(View.VISIBLE);
  769.  
  770.  
  771.                                                     // if blink is true, textview will be visible
  772.                                                 } else {
  773.                                                     number_text.setVisibility(View.INVISIBLE);
  774.                                                     minute_text.setVisibility(View.INVISIBLE);
  775.                                                     second_text.setVisibility(View.INVISIBLE);
  776.  
  777.  
  778.                                                 }
  779.  
  780.                                                 blink = !blink;         // toggle the value of blink
  781.                                             }
  782.  
  783.                                             second_text.setText(String.format("%02d", seconds % 60));
  784.                                             minute_text.setText(String.format("%02d", (seconds / 60) % 60));
  785.                                             number_text.setText(String.format("%02d", seconds / 3600));                     // format the textview to show the easily readable format
  786.                                         }
  787.  
  788.  
  789.                                         @Override
  790.                                         public void onFinish() {
  791.                                             // this function will be called when the timecount is finished
  792.                                             //textViewShowTime.setText("Time up!");
  793.                                             number_text.setVisibility(View.VISIBLE);
  794.                                             minute_text.setVisibility(View.VISIBLE);
  795.                                             second_text.setVisibility(View.VISIBLE);
  796.                                             mSeekArc.setVisibility(View.VISIBLE);
  797.                                             start_timer.setVisibility(View.VISIBLE);
  798.                                             block_button1.setVisibility(View.VISIBLE);
  799.  
  800.  
  801.                                             //Make sure it stops for good.
  802.  
  803.                                             //Intent intent = new Intent(getApplicationContext(), HeartBeat.class);
  804.                                             //stopService(intent);
  805.  
  806.  
  807.                                             NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  808.                                             Notification myNotification = new Notification(R.drawable.ic_launcher, "Time's up!", System.currentTimeMillis());
  809.                                             Context context = getApplicationContext();
  810.                                             String notificationTitle = "Apps are now unlocked!";
  811.                                             String notificationText = "Great job being productive! ;)";
  812.                                             Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
  813.                                             PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,   myIntent, Intent.FILL_IN_ACTION);
  814.                                             myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
  815.                                             myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
  816.                                             notificationManager.notify(1, myNotification);
  817.  
  818.  
  819.                                         }
  820.  
  821.                                     }.start();
  822.                                 }
  823.                             });
  824.                 timeset.setNegativeButton("Nope!", new DialogInterface.OnClickListener() {
  825.                                 public void onClick(DialogInterface dialog, int which) {
  826.                                     Log.d("AlertDialog", "Negative");
  827.                                     dialog.cancel();
  828.                                 }
  829.                             });
  830.  
  831.  
  832.                 AlertDialog timerright = timeset.create();
  833.  
  834.                 hourint = Integer.valueOf(number_text.getText().toString());
  835.  
  836.                 minuteint = Integer.valueOf(minute_text.getText().toString());
  837.  
  838.                 secondint = Integer.valueOf(second_text.getText().toString());
  839.  
  840.  
  841.  
  842.                 sharedPrefsapp = getApplicationContext().getSharedPreferences("appdb", Context.MODE_PRIVATE);
  843.                 allEntries= null;
  844.                 allEntries = sharedPrefsapp.getAll();
  845.                 packagezList= null;
  846.  
  847.                 packagezList = new ArrayList<String>();
  848.  
  849.                 for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
  850.                     //Log.e("right key: ", entry.getKey() + "right value: " + entry.getValue().toString()  );
  851.                     packagezList.add(entry.getKey());
  852.  
  853.                 }
  854.  
  855.  
  856.  
  857.                 if((((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000) == 0)
  858.                 {
  859.                     alertzero.show();
  860.                 }
  861.  
  862.                 else if (packagezList.size() ==0){
  863.                     noapp.show();
  864.                 }
  865.  
  866.  
  867.  
  868.                 else
  869.                 {
  870.                     timerright.show();
  871.                 }
  872.  
  873.                     // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.normalText);
  874.                 }
  875.  
  876.  
  877.         });
  878.     }
  879.  
  880.  
  881. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement