Advertisement
nigatigga

himom

Sep 3rd, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 43.14 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, previousView2;
  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, "miso.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/miso-bold.otf"));
  185.  
  186.         start_timer_text = (Button)findViewById(R.id.start_button);
  187.         start_timer_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso-bold.otf"));
  188.  
  189.         number_text = (TextView)findViewById(R.id.hour_progress_number);
  190.         number_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  191.  
  192.         minute_text = (TextView)findViewById(R.id.minute_progress_number);
  193.         minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  194.  
  195.         second_text = (TextView)findViewById(R.id.second_progress_number);
  196.         second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  197.  
  198.         little_hour_text = (TextView)findViewById(R.id.hourtext);
  199.         little_hour_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  200.  
  201.         little_minute_text = (TextView)findViewById(R.id.minutetext);
  202.         little_minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  203.  
  204.         little_second_text = (TextView)findViewById(R.id.secondtext);
  205.         little_second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso.otf"));
  206.  
  207.         little_hour_text2 = (TextView)findViewById(R.id.little_hour_text2);
  208.         little_hour_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso-light.otf"));
  209.  
  210.         little_minute_text2 = (TextView)findViewById(R.id.little_minute_text2);
  211.         little_minute_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso-light.otf"));
  212.  
  213.         little_second_text2 = (TextView)findViewById(R.id.little_second_text2);
  214.         little_second_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/miso-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.                 TextView previousText2 = (TextView) previousView;
  260.                 TextView curText2 = (TextView) v;
  261.                 // If the clicked view is selected, do nothing
  262.                 if (curText.isSelected()) {
  263.                     //curText.setSelected(false);
  264.                     //curText.setTextColor(getResources().getColor(R.color.red_highlight));
  265.                 } else { // If this isn't selected, deselect  the previous one (if any)
  266.                     if (previousText != null && previousText.isSelected()) {
  267.                         previousText.setSelected(false);
  268.                         previousText.setTextColor(getResources().getColor(R.color.red_highlight));
  269.                         previousText2.setTextColor(getResources().getColor(R.color.red_highlight));
  270.  
  271.                     }
  272.                     curText.setSelected(true);
  273.                     curText.setTextColor(getResources().getColor(R.color.black));
  274.                     previousView = v;
  275.                     previousView2 =v;
  276.                 }
  277.  
  278.                 if((v.getId() == R.id.hourtext)  || (v.getId() == R.id.hour_progress_number)){
  279.                   number_text.setTextColor(getResources().getColor(R.color.black));
  280.                   little_hour_text2.setTextColor(getResources().getColor(R.color.black));
  281.                     little_hour_text.setTextColor(getResources().getColor(R.color.black));
  282.  
  283.  
  284.                     minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  285.                     little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  286.  
  287.                     second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  288.                     little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  289.  
  290.  
  291.                     //corresponding button logic should below here
  292.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  293.  
  294.                         @Override
  295.                         public void onStopTrackingTouch(SeekArc seekArc) {
  296.                         }
  297.                         @Override
  298.                         public void onStartTrackingTouch(SeekArc seekArc) {
  299.                         }
  300.  
  301.  
  302.                         //This sets the actual string for the hours
  303.                         @Override
  304.                         public void onProgressChanged(SeekArc seekArc, int progress,
  305.                                                       boolean fromUser) {
  306.  
  307.                             int progress_count = 0;
  308.  
  309.                             for (int i=0;i<24;i=i+1)
  310.                             {
  311.  
  312.                                 if (progress ==120) {
  313.                                     mSeekArcProgress.setText("24");
  314.  
  315.                                 }
  316.                                 else if (progress == progress_count)
  317.                                 {
  318.                                     mSeekArcProgress.setText(String.valueOf(String.format("%02d",i)));
  319.                                 }
  320.  
  321.                                 progress_count = progress_count + 5;
  322.  
  323.                             }
  324.                         }
  325.                     });
  326.                 } else if((v.getId() == R.id.minutetext)  || (v.getId() == R.id.minute_progress_number)){
  327.  
  328.                     minute_text.setTextColor(getResources().getColor(R.color.black));
  329.                     little_minute_text2.setTextColor(getResources().getColor(R.color.black));
  330.                     little_minute_text.setTextColor(getResources().getColor(R.color.black));
  331.  
  332.  
  333.                     number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  334.                     little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  335.  
  336.                     second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  337.                     little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  338.                     //corresponding button logic should below here
  339.  
  340.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  341.  
  342.  
  343.                         @Override
  344.                         public void onStopTrackingTouch(SeekArc seekArc) {
  345.                         }
  346.                         @Override
  347.                         public void onStartTrackingTouch(SeekArc seekArc) {
  348.                         }
  349.  
  350.  
  351.                         //This sets the actual string for the minutes
  352.                         @Override
  353.                         public void onProgressChanged(SeekArc seekArc, int progress,
  354.                                                       boolean fromUser) {
  355.                             int progress_count = 0;
  356.  
  357.                             for (int i=0;i<120;i++)
  358.                             {
  359.  
  360.                                 if (progress ==120) {
  361.                                     mSeekArcMinuteProgress.setText("00");
  362.  
  363.                                 }
  364.                                 else if (progress == progress_count)
  365.                                 {
  366.                                     mSeekArcMinuteProgress.setText(String.valueOf(String.format("%02d",i)));
  367.                                 }
  368.  
  369.                                 progress_count = progress_count + 2;
  370.  
  371.  
  372.                             }
  373.  
  374.                         }
  375.                     });
  376.                 } else if ((v.getId() == R.id.secondtext) ||( v.getId() == R.id.second_progress_number)) {
  377.  
  378.                     second_text.setTextColor(getResources().getColor(R.color.black));
  379.                     little_second_text2.setTextColor(getResources().getColor(R.color.black));
  380.                     little_second_text.setTextColor(getResources().getColor(R.color.black));
  381.  
  382.                     minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  383.                     little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  384.  
  385.                     number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  386.  
  387.                     little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  388.                     //corresponding button logic should below here
  389.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  390.  
  391.                         @Override
  392.                         public void onStopTrackingTouch(SeekArc seekArc) {
  393.                         }
  394.                         @Override
  395.                         public void onStartTrackingTouch(SeekArc seekArc) {
  396.                         }
  397.  
  398.  
  399.                         //This sets the actual string for the seconds
  400.                         @Override
  401.                         public void onProgressChanged(SeekArc seekArc, int progress,
  402.                                                       boolean fromUser) {
  403.  
  404.  
  405.  
  406.                             // so ur setting it to HALF of what "progress" is = to
  407.  
  408.                             int progress_count = 0;
  409.  
  410.                             for (int i=0;i<60;i++)
  411.                             {
  412.  
  413.  
  414.                                 if (progress ==120) {
  415.                                     mSeekArcSecondProgress.setText("00");
  416.  
  417.                                 }
  418.                                 else if (progress == progress_count)
  419.                                 {
  420.                                     mSeekArcSecondProgress.setText(String.valueOf(String.format("%02d",i)));
  421.                                 }
  422.  
  423.                                 progress_count = progress_count + 2;
  424.  
  425.  
  426.                             }
  427.  
  428.                         }
  429.                     });
  430.                 }
  431.  
  432.             }
  433.         };
  434.         findViewById(R.id.hourtext).setOnClickListener(clickListener);
  435.         findViewById(R.id.minutetext).setOnClickListener(clickListener);
  436.         findViewById(R.id.secondtext).setOnClickListener(clickListener);
  437.         findViewById(R.id.hour_progress_number).setOnClickListener(clickListener);
  438.         findViewById(R.id.minute_progress_number).setOnClickListener(clickListener);
  439.         findViewById(R.id.second_progress_number).setOnClickListener(clickListener);
  440.  
  441.  
  442.         findViewById(R.id.minutetext).performClick();
  443.  
  444.  
  445.  
  446.         mRotation = (SeekBar) findViewById(R.id.rotation);
  447.         mStartAngle = (SeekBar) findViewById(R.id.startAngle);
  448.         mSweepAngle  = (SeekBar) findViewById(R.id.sweepAngle);
  449.         mArcWidth = (SeekBar) findViewById(R.id.arcWidth);
  450.         mProgressWidth = (SeekBar) findViewById(R.id.progressWidth);
  451.         mRoundedEdges = (CheckBox) findViewById(R.id.roundedEdges);
  452.         mTouchInside = (CheckBox) findViewById(R.id.touchInside);
  453.         mClockwise = (CheckBox) findViewById(R.id.clockwise);
  454.  
  455.         mRotation.setProgress(mSeekArc.getArcRotation());
  456.         mStartAngle.setProgress(mSeekArc.getStartAngle());
  457.         mSweepAngle.setProgress(mSeekArc.getSweepAngle());
  458.         mArcWidth.setProgress(mSeekArc.getArcWidth());
  459.         mProgressWidth.setProgress(mSeekArc.getProgressWidth());
  460.  
  461.  
  462.         mRotation.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  463.             @Override
  464.             public void onStopTrackingTouch(SeekBar arg0) {
  465.  
  466.             }
  467.             @Override
  468.             public void onStartTrackingTouch(SeekBar arg0) {
  469.             }
  470.  
  471.             @Override
  472.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  473.                 mSeekArc.setArcRotation(progress);
  474.                 mSeekArc.invalidate();
  475.             }
  476.         });
  477.  
  478.         mStartAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  479.             @Override
  480.             public void onStopTrackingTouch(SeekBar arg0) {
  481.  
  482.             }
  483.             @Override
  484.             public void onStartTrackingTouch(SeekBar arg0) {
  485.             }
  486.  
  487.             @Override
  488.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  489.                 mSeekArc.setStartAngle(progress);
  490.                 mSeekArc.invalidate();
  491.             }
  492.         });
  493.  
  494.         mSweepAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  495.             @Override
  496.             public void onStopTrackingTouch(SeekBar arg0) {
  497.  
  498.             }
  499.             @Override
  500.             public void onStartTrackingTouch(SeekBar arg0) {
  501.             }
  502.  
  503.             @Override
  504.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  505.                 mSeekArc.setSweepAngle(progress);
  506.                 mSeekArc.invalidate();
  507.             }
  508.         });
  509.  
  510.         mArcWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  511.             @Override
  512.             public void onStopTrackingTouch(SeekBar arg0) {
  513.  
  514.             }
  515.             @Override
  516.             public void onStartTrackingTouch(SeekBar arg0) {
  517.             }
  518.  
  519.             @Override
  520.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  521.                 mSeekArc.setArcWidth(progress);
  522.                 mSeekArc.invalidate();
  523.             }
  524.         });
  525.  
  526.         mProgressWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  527.             @Override
  528.             public void onStopTrackingTouch(SeekBar arg0) {
  529.  
  530.             }
  531.             @Override
  532.             public void onStartTrackingTouch(SeekBar arg0) {
  533.             }
  534.  
  535.             @Override
  536.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  537.                 mSeekArc.setProgressWidth(progress);
  538.                 mSeekArc.invalidate();
  539.             }
  540.         });
  541.  
  542.         mRoundedEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  543.             @Override
  544.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  545.                 mSeekArc.setRoundedEdges(isChecked);
  546.                 mSeekArc.invalidate();
  547.             }
  548.         });
  549.  
  550.         mTouchInside.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  551.             @Override
  552.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  553.                 mSeekArc.setTouchInSide(false);
  554.             }
  555.         });
  556.  
  557.         mClockwise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  558.             @Override
  559.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  560.                 mSeekArc.setClockwise(isChecked);
  561.                 mSeekArc.invalidate();
  562.             }
  563.         });
  564.  
  565.  
  566.         if(timerstarted > 0)
  567.         {
  568.             if(reopened <timerends){
  569.                 //start countdown timer with new time.
  570.                 //set countdowntime to timerends-reopen.
  571.  
  572.                 newtotalTimeCountInMilliseconds = timerends-reopened;
  573.  
  574.  
  575.                 number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  576.                 little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  577.  
  578.                 minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  579.                 little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  580.  
  581.                 second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  582.                 little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  583.  
  584.                 little_hour_text.setTextColor(getResources().getColor(R.color.red_highlight));
  585.                 little_minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  586.                 little_second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  587.  
  588.                 // yo
  589.  
  590.                 number_text.setClickable(false);
  591.                 little_hour_text2.setClickable(false);
  592.  
  593.                 minute_text.setClickable(false);
  594.                 little_minute_text2.setClickable(false);
  595.  
  596.                 second_text.setClickable(false);
  597.                 little_second_text2.setClickable(false);
  598.  
  599.                 little_hour_text.setClickable(false);
  600.                 little_minute_text.setClickable(false);
  601.                 little_second_text.setClickable(false);
  602.  
  603.  
  604.  
  605.                 countDownTimer = new CountDownTimer(newtotalTimeCountInMilliseconds, 500) {
  606.                     // 500 means, onTick function will be called at every 500 milliseconds
  607.  
  608.                     @Override
  609.                     public void onTick(long leftTimeInMilliseconds) {
  610.  
  611.                         long seconds = leftTimeInMilliseconds / 1000;
  612.                         mSeekArc.setVisibility(View.INVISIBLE);
  613.                         start_timer.setVisibility(View.INVISIBLE);
  614.                         block_button1.setVisibility(View.INVISIBLE);
  615.  
  616.  
  617.                         if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
  618.                             // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
  619.                             // change the style of the textview .. giving a red alert style
  620.  
  621.                             if (blink) {
  622.                                 number_text.setVisibility(View.VISIBLE);
  623.                                 minute_text.setVisibility(View.VISIBLE);
  624.                                 second_text.setVisibility(View.VISIBLE);
  625.  
  626.  
  627.                                 // if blink is true, textview will be visible
  628.                             } else {
  629.                                 number_text.setVisibility(View.INVISIBLE);
  630.                                 minute_text.setVisibility(View.INVISIBLE);
  631.                                 second_text.setVisibility(View.INVISIBLE);
  632.  
  633.  
  634.                             }
  635.  
  636.                             blink = !blink;         // toggle the value of blink
  637.                         }
  638.  
  639.                         second_text.setText(String.format("%02d", seconds % 60));
  640.                         minute_text.setText(String.format("%02d", (seconds / 60) % 60));
  641.                         number_text.setText(String.format("%02d", seconds / 3600));                     // format the textview to show the easily readable format
  642.                     }
  643.  
  644.  
  645.                     @Override
  646.                     public void onFinish() {
  647.                         // this function will be called when the timecount is finished
  648.                         //textViewShowTime.setText("Time up!");
  649.                         number_text.setVisibility(View.VISIBLE);
  650.                         minute_text.setVisibility(View.VISIBLE);
  651.                         second_text.setVisibility(View.VISIBLE);
  652.                         mSeekArc.setVisibility(View.VISIBLE);
  653.                         start_timer.setVisibility(View.VISIBLE);
  654.                         block_button1.setVisibility(View.VISIBLE);
  655.  
  656.  
  657.                         number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  658.                         little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  659.  
  660.                         minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  661.                         little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  662.  
  663.                         second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  664.                         little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  665.  
  666.                         little_hour_text.setTextColor(getResources().getColor(R.color.red_highlight));
  667.                         little_minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  668.                         little_second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  669.  
  670.  
  671.  
  672.                         number_text.setClickable(true);
  673.                         little_hour_text2.setClickable(true);
  674.  
  675.                         minute_text.setClickable(true);
  676.                         little_minute_text2.setClickable(true);
  677.  
  678.                         second_text.setClickable(true);
  679.                         little_second_text2.setClickable(true);
  680.  
  681.                         little_hour_text.setClickable(true);
  682.                         little_minute_text.setClickable(true);
  683.                         little_second_text.setClickable(true);
  684.  
  685.  
  686.                     }
  687.  
  688.                 }.start();
  689.  
  690.  
  691.  
  692.             }
  693.         }
  694.  
  695.  
  696.  
  697.  
  698.     }
  699.  
  700.     // for the on click activity responses for each of the 3 buttons on the menu
  701.     public void addListenerOnButton() {
  702.  
  703.         final Context context = this;
  704.  
  705.         block_button1 = (Button) findViewById(R.id.block_button);
  706.  
  707.         block_button1.setOnClickListener(new OnClickListener() {
  708.  
  709.             @Override
  710.             public void onClick(View arg0) {
  711.  
  712.                 Intent intent = new Intent(context, InstalledAppActivity.class);
  713.                 startActivity(intent);
  714.  
  715.             }
  716.  
  717.         });
  718.  
  719.     }
  720.  
  721.  
  722.     private void setActionListeners() {
  723.  
  724.  
  725.  
  726.  
  727.  
  728.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  729.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  730.         second_text = (TextView) findViewById(R.id.second_progress_number);
  731.  
  732.  
  733.  
  734.  
  735.         start_timer.setOnClickListener(new View.OnClickListener() {
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.             @Override
  744.             public void onClick(View view) {
  745.  
  746.  
  747.  
  748.  
  749.  
  750.                   AlertDialog.Builder zeroerror = new AlertDialog.Builder(MainActivity.this)
  751.                             .setMessage("Dude, you didn't set a time! :P")
  752.                             .setNegativeButton("Whoops! My bad!", new DialogInterface.OnClickListener() {
  753.                                 public void onClick(DialogInterface dialog, int which) {
  754.                                     Log.d("AlertDialog", "Negative");
  755.                                     dialog.cancel();
  756.                                 }
  757.                             });
  758.  
  759.  
  760.                 AlertDialog alertzero = zeroerror.create();
  761.  
  762.  
  763.                 AlertDialog.Builder noapp = new AlertDialog.Builder(MainActivity.this)
  764.                         .setMessage("Hey silly! You didn't select any apps to block!")
  765.                         .setNegativeButton("Oh, silly me!", new DialogInterface.OnClickListener() {
  766.                             public void onClick(DialogInterface dialog, int which) {
  767.                                 Log.d("AlertDialog", "Negative");
  768.                                 dialog.cancel();
  769.                             }
  770.                         });
  771.  
  772.  
  773.                 AlertDialog zeroapp = noapp.create();
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.                 AlertDialog.Builder timeset = new AlertDialog.Builder(MainActivity.this)
  781.  
  782.  
  783.                 .setMessage("Are you sure you want to block the selected apps for the set amount of time?")
  784.                 .setPositiveButton("Yeah man!", new DialogInterface.OnClickListener() {
  785.  
  786.  
  787.  
  788.                                 public void onClick(DialogInterface dialog, int which) {
  789.  
  790.                                     number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  791.                                     little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  792.  
  793.                                     minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  794.                                     little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  795.  
  796.                                     second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  797.                                     little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  798.  
  799.                                     little_hour_text.setTextColor(getResources().getColor(R.color.red_highlight));
  800.                                     little_minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  801.                                     little_second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  802.  
  803.                                     // yo
  804.  
  805.                                     number_text.setClickable(false);
  806.                                     little_hour_text2.setClickable(false);
  807.  
  808.                                     minute_text.setClickable(false);
  809.                                     little_minute_text2.setClickable(false);
  810.  
  811.                                     second_text.setClickable(false);
  812.                                     little_second_text2.setClickable(false);
  813.  
  814.                                     little_hour_text.setClickable(false);
  815.                                     little_minute_text.setClickable(false);
  816.                                     little_second_text.setClickable(false);
  817.  
  818.  
  819.  
  820.                                     Log.d("AlertDialog", "Positive");
  821.  
  822.                                     hourint = Integer.valueOf(number_text.getText().toString());
  823.  
  824.                                     minuteint = Integer.valueOf(minute_text.getText().toString());
  825.  
  826.                                     secondint = Integer.valueOf(second_text.getText().toString());
  827.  
  828.                                     Log.i("YourActivity", "Hours: " + hourint);
  829.  
  830.                                     Log.i("YourActivity", "Minutes: " + minuteint);
  831.  
  832.                                     Log.i("YourActivity", "Seconds: " + secondint);
  833.  
  834.  
  835.                                     //Make sure it stays alive no matter what until stopservice is called when the timer runs out
  836.  
  837.  
  838.                                     //Intent intent = new Intent(getApplicationContext(), HeartBeat.class);
  839.                                     //startService(intent);
  840.  
  841.                                     Date currenttime = new Date(System.currentTimeMillis());
  842.  
  843.                                     timerstarted = currenttime.getTime();
  844.                                     Log.e("This is the current time:  ", timerstarted + "");
  845.                                     startimerPreferences = getPreferences(MODE_APPEND);
  846.                                     SharedPreferences.Editor starteditor = startimerPreferences.edit();
  847.                                     starteditor.putLong("time", timerstarted);
  848.                                     starteditor.apply();
  849.  
  850.  
  851.                                     Date endtime = new Date(System.currentTimeMillis());
  852.  
  853.                                     //timerends = endtime.getTime() + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);
  854.  
  855.                                     if ((((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000) > 0) {
  856.                                         timerends = endtime.getTime() + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);
  857.  
  858.  
  859.                                     } else {
  860.                                         timerends = 0;
  861.                                     }
  862.  
  863.  
  864.                                     Log.e("This is the end time:  ", timerends + "");
  865.                                     endTimerPreferences = getPreferences(MODE_APPEND);
  866.                                     SharedPreferences.Editor endeditor = endTimerPreferences.edit();
  867.                                     endeditor.putLong("endtime", timerends);
  868.                                     endeditor.apply();
  869.  
  870.                                     endservice = getApplicationContext().getSharedPreferences("endservice", Context.MODE_PRIVATE);
  871.                                     SharedPreferences.Editor serviceeditor = endservice.edit();
  872.                                     serviceeditor.putLong("endservice", timerstarted + (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000));
  873.                                     Log.e("Check out this time:  ", timerends + "");
  874.  
  875.                                     serviceeditor.apply();
  876.  
  877.  
  878.                                     totalTimeCountInMilliseconds = (((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000);      // time count
  879.                                     timeBlinkInMilliseconds = 30 * 1000;
  880.  
  881.                                     countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
  882.                                         // 500 means, onTick function will be called at every 500 milliseconds
  883.  
  884.                                         @Override
  885.                                         public void onTick(long leftTimeInMilliseconds) {
  886.  
  887.                                             long seconds = leftTimeInMilliseconds / 1000;
  888.                                             mSeekArc.setVisibility(View.INVISIBLE);
  889.                                             start_timer.setVisibility(View.INVISIBLE);
  890.                                             block_button1.setVisibility(View.INVISIBLE);
  891.  
  892.  
  893.                                             if (leftTimeInMilliseconds < timeBlinkInMilliseconds) {
  894.                                                 // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
  895.                                                 // change the style of the textview .. giving a red alert style
  896.  
  897.                                                 if (blink) {
  898.                                                     number_text.setVisibility(View.VISIBLE);
  899.                                                     minute_text.setVisibility(View.VISIBLE);
  900.                                                     second_text.setVisibility(View.VISIBLE);
  901.  
  902.  
  903.                                                     // if blink is true, textview will be visible
  904.                                                 } else {
  905.                                                     number_text.setVisibility(View.INVISIBLE);
  906.                                                     minute_text.setVisibility(View.INVISIBLE);
  907.                                                     second_text.setVisibility(View.INVISIBLE);
  908.  
  909.  
  910.                                                 }
  911.  
  912.                                                 blink = !blink;         // toggle the value of blink
  913.                                             }
  914.  
  915.                                             second_text.setText(String.format("%02d", seconds % 60));
  916.                                             minute_text.setText(String.format("%02d", (seconds / 60) % 60));
  917.                                             number_text.setText(String.format("%02d", seconds / 3600));                     // format the textview to show the easily readable format
  918.                                         }
  919.  
  920.  
  921.                                         @Override
  922.                                         public void onFinish() {
  923.                                             // this function will be called when the timecount is finished
  924.                                             //textViewShowTime.setText("Time up!");
  925.                                             number_text.setVisibility(View.VISIBLE);
  926.                                             minute_text.setVisibility(View.VISIBLE);
  927.                                             second_text.setVisibility(View.VISIBLE);
  928.                                             mSeekArc.setVisibility(View.VISIBLE);
  929.                                             start_timer.setVisibility(View.VISIBLE);
  930.                                             block_button1.setVisibility(View.VISIBLE);
  931.  
  932.  
  933.  
  934.                                             number_text.setTextColor(getResources().getColor(R.color.red_highlight));
  935.                                             little_hour_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  936.  
  937.                                             minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  938.                                             little_minute_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  939.  
  940.                                             second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  941.                                             little_second_text2.setTextColor(getResources().getColor(R.color.red_highlight));
  942.  
  943.                                             little_hour_text.setTextColor(getResources().getColor(R.color.red_highlight));
  944.                                             little_minute_text.setTextColor(getResources().getColor(R.color.red_highlight));
  945.                                             little_second_text.setTextColor(getResources().getColor(R.color.red_highlight));
  946.  
  947.  
  948.                                             number_text.setClickable(true);
  949.                                             little_hour_text2.setClickable(true);
  950.  
  951.                                             minute_text.setClickable(true);
  952.                                             little_minute_text2.setClickable(true);
  953.  
  954.                                             second_text.setClickable(true);
  955.                                             little_second_text2.setClickable(true);
  956.  
  957.                                             little_hour_text.setClickable(true);
  958.                                             little_minute_text.setClickable(true);
  959.                                             little_second_text.setClickable(true);
  960.  
  961.  
  962.                                             //Make sure it stops for good.
  963.  
  964.                                             //Intent intent = new Intent(getApplicationContext(), HeartBeat.class);
  965.                                             //stopService(intent);
  966.  
  967.  
  968.                                             NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  969.                                             Notification myNotification = new Notification(R.drawable.ic_launcher, "Time's up!", System.currentTimeMillis());
  970.                                             Context context = getApplicationContext();
  971.                                             String notificationTitle = "Apps are now unlocked!";
  972.                                             String notificationText = "Great job being productive! ;)";
  973.                                             Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
  974.                                             PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0,   myIntent, Intent.FILL_IN_ACTION);
  975.                                             myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
  976.                                             myNotification.setLatestEventInfo(context, notificationTitle, notificationText, pendingIntent);
  977.                                             notificationManager.notify(1, myNotification);
  978.  
  979.  
  980.                                         }
  981.  
  982.                                     }.start();
  983.                                 }
  984.                             });
  985.                 timeset.setNegativeButton("Nope!", new DialogInterface.OnClickListener() {
  986.                                 public void onClick(DialogInterface dialog, int which) {
  987.                                     Log.d("AlertDialog", "Negative");
  988.                                     dialog.cancel();
  989.                                 }
  990.                             });
  991.  
  992.  
  993.                 AlertDialog timerright = timeset.create();
  994.  
  995.                 hourint = Integer.valueOf(number_text.getText().toString());
  996.  
  997.                 minuteint = Integer.valueOf(minute_text.getText().toString());
  998.  
  999.                 secondint = Integer.valueOf(second_text.getText().toString());
  1000.  
  1001.  
  1002.  
  1003.                 sharedPrefsapp = getApplicationContext().getSharedPreferences("appdb", Context.MODE_PRIVATE);
  1004.                 allEntries= null;
  1005.                 allEntries = sharedPrefsapp.getAll();
  1006.                 packagezList= null;
  1007.  
  1008.                 packagezList = new ArrayList<String>();
  1009.  
  1010.                 for (Map.Entry<String, ?> entry : allEntries.entrySet()) {
  1011.                     //Log.e("right key: ", entry.getKey() + "right value: " + entry.getValue().toString()  );
  1012.                     packagezList.add(entry.getKey());
  1013.  
  1014.                 }
  1015.  
  1016.  
  1017.  
  1018.                 if((((hourint * 60 * 60) + (minuteint * 60) + (secondint)) * 1000) == 0)
  1019.                 {
  1020.                     alertzero.show();
  1021.                 }
  1022.  
  1023.                 else if (packagezList.size() ==0){
  1024.                     noapp.show();
  1025.                 }
  1026.  
  1027.  
  1028.  
  1029.                 else
  1030.                 {
  1031.                     timerright.show();
  1032.                 }
  1033.  
  1034.                     // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.normalText);
  1035.                 }
  1036.  
  1037.  
  1038.         });
  1039.     }
  1040.  
  1041.  
  1042. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement