Skip to content

Latest commit

 

History

History
72 lines (57 loc) · 2.68 KB

ScChecker.md

File metadata and controls

72 lines (57 loc) · 2.68 KB

ScChecker

This is very simple class utility that periodically repeat a check method. This is an abstract class and cannot be instanced directly.
Through the listener implementation you can know when the status of check changed. This can be very useful in some case. For example when you must check the internet connection status or all kind of checks when the user must be advised only when some changed happen.

Getter and Setter

  • get/setStartDelay() -> long value, default: 100 milliseconds
    When start to check the delay in milliseconds
  • get/getCheckRate() -> long value, default: 1000 milliseconds
    The waiting millisecond between a check and the next
  • get/getMode() -> Modes value, default: FIXED_DELAY
    The waiting mode between a check and the next.
    Modes.FIXED_DELAY: start to wait once check is finished
    Modes.FIXED_RATE: check at fixed rate time

Methods

  • boolean check()
    Abstract method must be overridden. This method will be called periodically in according with the specified settings.
  • void start()
    Start to check.
  • void stop()
  • void stop(boolean force)
    Stop to check. If force the check will be interrupted even if not finished.
  • void setCheckerListener(CheckerListener listener)
    Attach the listener.

Listener

    public interface CheckerListener {

        void onSuccess();

        void onFail();

        void onChangeState(boolean result);
        
    }

Overridable methods

Since this class must be extended you can override some methods for your scope.

  • public void onSuccess()
    Called on success (when check() methods return true).
  • public void onFail()
    Called on fail (when check() methods return false).
  • public void onChangeState(boolean result)
    Called on status change. The result variable contain the check() returned value.

Example

For an example please take a look the demo section in the project structure.

#License

 Copyright 2015 Samuele Carassai

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in  writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,  either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.