Advertisement
nigatigga

Untitled

Aug 14th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.61 KB | None | 0 0
  1. package com.spicycurryman.getdisciplined10.app;
  2.  
  3. import android.app.ActionBar;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.pm.ActivityInfo;
  7. import android.graphics.Typeface;
  8. import android.os.Bundle;
  9. import android.os.CountDownTimer;
  10. import android.support.v7.app.ActionBarActivity;
  11. import android.text.Spannable;
  12. import android.text.SpannableString;
  13. import android.util.Log;
  14. import android.view.Menu;
  15. import android.view.MenuInflater;
  16. import android.view.View;
  17. import android.view.View.OnClickListener;
  18. import android.widget.Button;
  19. import android.widget.CheckBox;
  20. import android.widget.CompoundButton;
  21. import android.widget.SeekBar;
  22. import android.widget.SeekBar.OnSeekBarChangeListener;
  23. import android.widget.TextView;
  24.  
  25. import com.triggertrap.seekarc.SeekArc;
  26.  
  27. public class MainActivity extends ActionBarActivity {
  28.     private SeekArc mSeekArc;
  29.     private SeekBar mRotation;
  30.     private SeekBar mStartAngle;
  31.     private SeekBar mSweepAngle;
  32.     private SeekBar mArcWidth;
  33.     private SeekBar mProgressWidth;
  34.     private CheckBox mRoundedEdges;
  35.     private CheckBox mTouchInside;
  36.     private CheckBox mClockwise;
  37.     private TextView mSeekArcProgress;
  38.     private TextView mSeekArcMinuteProgress;
  39.     private TextView mSeekArcSecondProgress;
  40.  
  41.     private Button block_button_text;
  42.     private Button start_timer_text;
  43.  
  44.     //will show the time
  45.     private TextView number_text;
  46.  
  47.     private TextView minute_text;
  48.     private TextView second_text;
  49.  
  50.  
  51.     private TextView little_hour_text;
  52.     private TextView little_minute_text;
  53.     private TextView little_second_text;
  54.  
  55.     private TextView little_hour_text2;
  56.     private TextView little_minute_text2;
  57.     private TextView little_second_text2;
  58.  
  59.     CountDownTimer countDownTimer;          // built in android class CountDownTimer
  60.     long totalTimeCountInMilliseconds;
  61.     long timeBlinkInMilliseconds;           // start time of start blinking
  62.     boolean blink;
  63.  
  64.  
  65.     // Consider showing drawable scrubber after pressing H M or S
  66.  
  67.  
  68.  
  69.  
  70.     Button block_button1;
  71.     Button start_timer;
  72.  
  73.     int hourint, minuteint,secondint;
  74.  
  75.     public boolean onCreateOptionsMenu(Menu menu){
  76.         MenuInflater inflater = getMenuInflater();
  77.         inflater.inflate(R.menu.main, menu);
  78.         return true;
  79.     }
  80.  
  81.     View previousView;
  82.  
  83.  
  84.     @Override
  85.     protected void onCreate(Bundle savedInstanceState) {
  86.         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  87.         super.onCreate(savedInstanceState);
  88.         setContentView(R.layout.merge);
  89.  
  90.  
  91.         //set views
  92.  
  93.         start_timer = (Button) findViewById(R.id.start_button);
  94.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  95.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  96.         second_text = (TextView) findViewById(R.id.second_progress_number);
  97.  
  98.  
  99.         //getReferenceOfViews ();                         // get all views
  100.         setActionListeners ();
  101.  
  102.         // This determine what the actual "countdown" time will be.
  103.         //totalTimeCountInMilliseconds = 60 * 1000;      // time count for 3 minutes = 180 seconds
  104.         //timeBlinkInMilliseconds = 30 * 1000;
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.         //Make sure you find out why it appears after a whole 1 second after the app appears
  112.         SpannableString s = new SpannableString("GetDisciplined");
  113.         s.setSpan(new TypefaceSpan(this, "roboto-lightitalic.ttf"), 0, s.length(),
  114.                 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  115.  
  116. // Update the action bar title with the TypefaceSpan instance
  117.         ActionBar actionBar = getActionBar();
  118.         actionBar.setTitle(s);
  119.         // set the action bar in this activity as the home
  120.         actionBar.setHomeButtonEnabled(true);
  121.  
  122.  
  123.  
  124.  
  125.         //Listeners for the buttons
  126.         addListenerOnButton();
  127.  
  128.  
  129.  
  130.         //Editing Button Text
  131.  
  132.         block_button_text = (Button)findViewById(R.id.block_button);
  133.         block_button_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/robotocondensed-bold.ttf"));
  134.  
  135.         start_timer_text = (Button)findViewById(R.id.start_button);
  136.         start_timer_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/robotocondensed-bold.ttf"));
  137.  
  138.         number_text = (TextView)findViewById(R.id.hour_progress_number);
  139.         number_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  140.  
  141.         minute_text = (TextView)findViewById(R.id.minute_progress_number);
  142.         minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  143.  
  144.         second_text = (TextView)findViewById(R.id.second_progress_number);
  145.         second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  146.  
  147.         little_hour_text = (TextView)findViewById(R.id.hourtext);
  148.         little_hour_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  149.  
  150.         little_minute_text = (TextView)findViewById(R.id.minutetext);
  151.         little_minute_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  152.  
  153.         little_second_text = (TextView)findViewById(R.id.secondtext);
  154.         little_second_text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  155.  
  156.         little_hour_text2 = (TextView)findViewById(R.id.little_hour_text2);
  157.         little_hour_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  158.  
  159.         little_minute_text2 = (TextView)findViewById(R.id.little_minute_text2);
  160.         little_minute_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  161.  
  162.         little_second_text2 = (TextView)findViewById(R.id.little_second_text2);
  163.         little_second_text2.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/roboto-light.ttf"));
  164.  
  165.  
  166.  
  167.  
  168.         mSeekArc = (SeekArc) findViewById(R.id.seekArc);
  169.  
  170.  
  171. //Here is the actual "hour progress number" aka the TextView that changes as the scrubber is dragged around
  172.         mSeekArcProgress = (TextView) findViewById(R.id.hour_progress_number);
  173.  
  174.         mSeekArcMinuteProgress = (TextView) findViewById(R.id.minute_progress_number);
  175.  
  176.         mSeekArcSecondProgress = (TextView) findViewById(R.id.second_progress_number);
  177.  
  178.  
  179.  
  180.         //make textview selectable
  181.  
  182.         View.OnClickListener clickListener = new View.OnClickListener() {
  183.             @Override
  184.             public void onClick(View v) {
  185.                 TextView previousText = (TextView) previousView;
  186.                 TextView curText = (TextView) v;
  187.                 // If the clicked view is selected, do nothing
  188.                 if (curText.isSelected()) {
  189.                     //curText.setSelected(false);
  190.                     //curText.setTextColor(getResources().getColor(R.color.red_highlight));
  191.                 } else { // If this isn't selected, deselect  the previous one (if any)
  192.                     if (previousText != null && previousText.isSelected()) {
  193.                         previousText.setSelected(false);
  194.                         previousText.setTextColor(getResources().getColor(R.color.red_highlight));
  195.                     }
  196.                     curText.setSelected(true);
  197.                     curText.setTextColor(getResources().getColor(R.color.black));
  198.                     previousView = v;
  199.                 }
  200.  
  201.                 if(v.getId() == R.id.hourtext){
  202.                     //corresponding button logic should below here
  203.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  204.  
  205.                         @Override
  206.                         public void onStopTrackingTouch(SeekArc seekArc) {
  207.                         }
  208.                         @Override
  209.                         public void onStartTrackingTouch(SeekArc seekArc) {
  210.                         }
  211.  
  212.  
  213.                         //This sets the actual string for the hours
  214.                         @Override
  215.                         public void onProgressChanged(SeekArc seekArc, int progress,
  216.                                                       boolean fromUser) {
  217.  
  218.                             int progress_count = 0;
  219.  
  220.                             for (int i=0;i<24;i=i+1)
  221.                             {
  222.  
  223.                                 if (progress ==120) {
  224.                                     mSeekArcProgress.setText("24");
  225.  
  226.                                 }
  227.                                 else if (progress == progress_count)
  228.                                 {
  229.                                     mSeekArcProgress.setText(String.valueOf(String.format("%02d",i)));
  230.                                 }
  231.  
  232.                                 progress_count = progress_count + 5;
  233.  
  234.                             }
  235.                         }
  236.                     });
  237.                 } else if (v.getId() == R.id.minutetext) {
  238.                     //corresponding button logic should below here
  239.  
  240.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  241.  
  242.  
  243.                         @Override
  244.                         public void onStopTrackingTouch(SeekArc seekArc) {
  245.                         }
  246.                         @Override
  247.                         public void onStartTrackingTouch(SeekArc seekArc) {
  248.                         }
  249.  
  250.  
  251.                         //This sets the actual string for the minutes
  252.                         @Override
  253.                         public void onProgressChanged(SeekArc seekArc, int progress,
  254.                                                       boolean fromUser) {
  255.                             int progress_count = 0;
  256.  
  257.                             for (int i=0;i<120;i++)
  258.                             {
  259.  
  260.                                  if (progress ==120) {
  261.                                      mSeekArcMinuteProgress.setText("00");
  262.  
  263.                                  }
  264.                                 else if (progress == progress_count)
  265.                                 {
  266.                                     mSeekArcMinuteProgress.setText(String.valueOf(String.format("%02d",i)));
  267.                                 }
  268.  
  269.                                 progress_count = progress_count + 2;
  270.  
  271.  
  272.                             }
  273.  
  274.                         }
  275.                     });
  276.                 } else if (v.getId() == R.id.secondtext) {
  277.                     //corresponding button logic should below here
  278.                     mSeekArc.setOnSeekArcChangeListener(new SeekArc.OnSeekArcChangeListener() {
  279.  
  280.                         @Override
  281.                         public void onStopTrackingTouch(SeekArc seekArc) {
  282.                         }
  283.                         @Override
  284.                         public void onStartTrackingTouch(SeekArc seekArc) {
  285.                         }
  286.  
  287.  
  288.                         //This sets the actual string for the seconds
  289.                         @Override
  290.                         public void onProgressChanged(SeekArc seekArc, int progress,
  291.                                       boolean fromUser) {
  292.  
  293.  
  294.  
  295.                             // so ur setting it to HALF of what "progress" is = to
  296.  
  297.                             int progress_count = 0;
  298.  
  299.                             for (int i=0;i<60;i++)
  300.                             {
  301.  
  302.  
  303.                                 if (progress ==120) {
  304.                                     mSeekArcSecondProgress.setText("00");
  305.  
  306.                                 }
  307.                                 else if (progress == progress_count)
  308.                                 {
  309.                                     mSeekArcSecondProgress.setText(String.valueOf(String.format("%02d",i)));
  310.                                 }
  311.  
  312.                                 progress_count = progress_count + 2;
  313.  
  314.  
  315.                             }
  316.  
  317.                         }
  318.                     });
  319.                 }
  320.  
  321.             }
  322.         };
  323.         findViewById(R.id.hourtext).setOnClickListener(clickListener);
  324.         findViewById(R.id.minutetext).setOnClickListener(clickListener);
  325.         findViewById(R.id.secondtext).setOnClickListener(clickListener);
  326.  
  327.  
  328.         mRotation = (SeekBar) findViewById(R.id.rotation);
  329.         mStartAngle = (SeekBar) findViewById(R.id.startAngle);
  330.         mSweepAngle  = (SeekBar) findViewById(R.id.sweepAngle);
  331.         mArcWidth = (SeekBar) findViewById(R.id.arcWidth);
  332.         mProgressWidth = (SeekBar) findViewById(R.id.progressWidth);
  333.         mRoundedEdges = (CheckBox) findViewById(R.id.roundedEdges);
  334.         mTouchInside = (CheckBox) findViewById(R.id.touchInside);
  335.         mClockwise = (CheckBox) findViewById(R.id.clockwise);
  336.  
  337.        mRotation.setProgress(mSeekArc.getArcRotation());
  338.        mStartAngle.setProgress(mSeekArc.getStartAngle());
  339.        mSweepAngle.setProgress(mSeekArc.getSweepAngle());
  340.        mArcWidth.setProgress(mSeekArc.getArcWidth());
  341.        mProgressWidth.setProgress(mSeekArc.getProgressWidth());
  342.  
  343.  
  344.         mRotation.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  345.             @Override
  346.             public void onStopTrackingTouch(SeekBar arg0) {
  347.  
  348.             }
  349.             @Override
  350.             public void onStartTrackingTouch(SeekBar arg0) {
  351.             }
  352.  
  353.             @Override
  354.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  355.                 mSeekArc.setArcRotation(progress);
  356.                 mSeekArc.invalidate();
  357.             }
  358.         });
  359.  
  360.         mStartAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  361.             @Override
  362.             public void onStopTrackingTouch(SeekBar arg0) {
  363.  
  364.             }
  365.             @Override
  366.             public void onStartTrackingTouch(SeekBar arg0) {
  367.             }
  368.  
  369.             @Override
  370.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  371.                 mSeekArc.setStartAngle(progress);
  372.                 mSeekArc.invalidate();
  373.             }
  374.         });
  375.  
  376.         mSweepAngle.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  377.             @Override
  378.             public void onStopTrackingTouch(SeekBar arg0) {
  379.  
  380.             }
  381.             @Override
  382.             public void onStartTrackingTouch(SeekBar arg0) {
  383.             }
  384.  
  385.             @Override
  386.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  387.                 mSeekArc.setSweepAngle(progress);
  388.                 mSeekArc.invalidate();
  389.             }
  390.         });
  391.  
  392.         mArcWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  393.             @Override
  394.             public void onStopTrackingTouch(SeekBar arg0) {
  395.  
  396.             }
  397.             @Override
  398.             public void onStartTrackingTouch(SeekBar arg0) {
  399.             }
  400.  
  401.             @Override
  402.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  403.                 mSeekArc.setArcWidth(progress);
  404.                 mSeekArc.invalidate();
  405.             }
  406.         });
  407.  
  408.         mProgressWidth.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
  409.             @Override
  410.             public void onStopTrackingTouch(SeekBar arg0) {
  411.  
  412.             }
  413.             @Override
  414.             public void onStartTrackingTouch(SeekBar arg0) {
  415.             }
  416.  
  417.             @Override
  418.             public void onProgressChanged(SeekBar view, int progress, boolean fromUser) {
  419.                 mSeekArc.setProgressWidth(progress);
  420.                 mSeekArc.invalidate();
  421.             }
  422.         });
  423.  
  424.         mRoundedEdges.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  425.             @Override
  426.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  427.                 mSeekArc.setRoundedEdges(isChecked);
  428.                 mSeekArc.invalidate();
  429.             }
  430.         });
  431.  
  432.         mTouchInside.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  433.             @Override
  434.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  435.                 mSeekArc.setTouchInSide(false);
  436.             }
  437.         });
  438.  
  439.         mClockwise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  440.             @Override
  441.             public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
  442.                 mSeekArc.setClockwise(isChecked);
  443.                 mSeekArc.invalidate();
  444.             }
  445.         });
  446.  
  447.     }
  448.  
  449.     // for the on click activity responses for each of the 3 buttons on the menu
  450.     public void addListenerOnButton() {
  451.  
  452.         final Context context = this;
  453.  
  454.         block_button1 = (Button) findViewById(R.id.block_button);
  455.  
  456.         block_button1.setOnClickListener(new OnClickListener() {
  457.  
  458.             @Override
  459.             public void onClick(View arg0) {
  460.  
  461.                 Intent intent = new Intent(context, BlockActivity.class);
  462.                 startActivity(intent);
  463.  
  464.             }
  465.  
  466.         });
  467.  
  468.     }
  469.  
  470.  
  471.     private void setActionListeners() {
  472.  
  473.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  474.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  475.         second_text = (TextView) findViewById(R.id.second_progress_number);
  476.  
  477.          hourint = Integer.valueOf(number_text.getText().toString());
  478.  
  479.          minuteint = Integer.valueOf(minute_text.getText().toString());
  480.  
  481.          secondint = Integer.valueOf(second_text.getText().toString());
  482.  
  483.         Log.i("YourActivity", "Hours: " + hourint);
  484.  
  485.         Log.i("YourActivity", "Minutes: " + minuteint);
  486.  
  487.         Log.i("YourActivity", "Seconds: " + secondint);
  488.  
  489.  
  490.  
  491.         totalTimeCountInMilliseconds = ((hourint*60*60) +(minuteint*60) + (secondint)) * 1000;      // time count for 3 minutes = 180 seconds
  492.         timeBlinkInMilliseconds = totalTimeCountInMilliseconds/1000;
  493.  
  494.  
  495.         start_timer.setOnClickListener(new View.OnClickListener() {
  496.             @Override
  497.             public void onClick(View view) {
  498.  
  499.                // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.normalText);
  500.  
  501.                 countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
  502.                     // 500 means, onTick function will be called at every 500 milliseconds
  503.  
  504.                     @Override
  505.                     public void onTick(long leftTimeInMilliseconds) {
  506.                         long seconds = leftTimeInMilliseconds / 1000;
  507.                         mSeekArc.setVisibility(View.INVISIBLE);
  508.  
  509.  
  510.                         if ( leftTimeInMilliseconds < timeBlinkInMilliseconds ) {
  511.                            // textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
  512.                             // change the style of the textview .. giving a red alert style
  513.  
  514.                             if ( blink ) {
  515.                                 number_text.setVisibility(View.VISIBLE);
  516.                                 minute_text.setVisibility(View.VISIBLE);
  517.                                 second_text.setVisibility(View.VISIBLE);
  518.  
  519.  
  520.                                 // if blink is true, textview will be visible
  521.                             } else {
  522.                                 number_text.setVisibility(View.INVISIBLE);
  523.                                 minute_text.setVisibility(View.INVISIBLE);
  524.                                 second_text.setVisibility(View.INVISIBLE);
  525.  
  526.  
  527.                             }
  528.  
  529.                             blink = !blink;         // toggle the value of blink
  530.                         }
  531.  
  532.                         second_text.setText(String.format("%02d", seconds % 60));
  533.                         minute_text.setText(String.format("%02d", seconds / 60));
  534.                         number_text.setText(String.format("%02d", seconds / 3600));                     // format the textview to show the easily readable format
  535.                     }
  536.  
  537.  
  538.                     @Override
  539.                     public void onFinish() {
  540.                         // this function will be called when the timecount is finished
  541.                         //textViewShowTime.setText("Time up!");
  542.                         number_text.setVisibility(View.VISIBLE);
  543.                         minute_text.setVisibility(View.VISIBLE);
  544.                         second_text.setVisibility(View.VISIBLE);
  545.                         mSeekArc.setVisibility(View.VISIBLE);
  546.                     }
  547.  
  548.                 }.start();
  549.  
  550.             }
  551.         });
  552.     }
  553.     private void getReferenceOfViews() {
  554.  
  555.         start_timer = (Button) findViewById(R.id.start_button);
  556.         number_text = (TextView) findViewById(R.id.hour_progress_number);
  557.         minute_text = (TextView) findViewById(R.id.minute_progress_number);
  558.         second_text = (TextView) findViewById(R.id.second_progress_number);
  559.  
  560.  
  561.     }
  562.  
  563. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement