Advertisement
Guest User

Untitled

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