All Projects → wimming → Timerview

wimming / Timerview

a timer which ectends an View

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Timerview

Lvartisan
Laravel artisan command for creating view.
Stars: ✭ 18 (-35.71%)
Mutual labels:  view
Dachshund Tab Layout
Extended Android Tab Layout with animated indicators that have continuous feedback.
Stars: ✭ 853 (+2946.43%)
Mutual labels:  view
Iconswitch
🍭 Custom Android Switch widget
Stars: ✭ 874 (+3021.43%)
Mutual labels:  view
Crab
JavaScript library for building user interfaces with Custom Elements, Shadow DOM and React like API
Stars: ✭ 22 (-21.43%)
Mutual labels:  view
Adaptablebottomnavigation
A simpler way for implementing the Bottom Navigation View on Android
Stars: ✭ 844 (+2914.29%)
Mutual labels:  view
Tabulate
Table Maker for Modern C++
Stars: ✭ 862 (+2978.57%)
Mutual labels:  view
Drab
Remote controlled frontend framework for Phoenix.
Stars: ✭ 833 (+2875%)
Mutual labels:  view
Gcnotificationview
Simplest notification alert view for iOS
Stars: ✭ 27 (-3.57%)
Mutual labels:  view
Html
HTML helper library
Stars: ✭ 8 (-71.43%)
Mutual labels:  view
Mylittlecanvas
🎨Need to create a custom view ? You don't know how to use Canvas, use MyLittleCanvas instead !
Stars: ✭ 870 (+3007.14%)
Mutual labels:  view
Graphview
Android GraphView is used to display data in graph structures.
Stars: ✭ 918 (+3178.57%)
Mutual labels:  view
Modelassistant
Elegant library to manage the interactions between view and model in Swift
Stars: ✭ 26 (-7.14%)
Mutual labels:  view
Trianglelabelview
Show triangle view.
Stars: ✭ 870 (+3007.14%)
Mutual labels:  view
Croppy
Image Cropping Library for Android
Stars: ✭ 906 (+3135.71%)
Mutual labels:  view
Androidlibs
🔥正在成为史上最全分类 Android 开源大全~~~~(长期更新 Star 一下吧)
Stars: ✭ 7,148 (+25428.57%)
Mutual labels:  view
Uuwaveview
[iOS]带有波形效果的UI控件,可自定义波形线条的数量、颜色、振幅、传播速度等各种参数。
Stars: ✭ 18 (-35.71%)
Mutual labels:  view
Fingereyes Xr
FingerEyes-Xr for HTML5, A JavaScript library for building professional GIS System.
Stars: ✭ 9 (-67.86%)
Mutual labels:  view
Viewcomposer
Compose views using enums swiftly: `let label: UILabel = [.text("Hello"), .textColor(.red)]`
Stars: ✭ 27 (-3.57%)
Mutual labels:  view
Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-46.43%)
Mutual labels:  view
Suitlines
[DEPRECATED]一个小巧且高效的线性图表组件。
Stars: ✭ 870 (+3007.14%)
Mutual labels:  view

TimerView

A timer which extends a View, you can use it to start a countdown if you need.

Screen Shoot

image

Usage

Copy the TimerView.java into your project. Then directly use TimerView element in xml like this:

    <com.ym.littleshape.TimerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/timer_view"
        android:padding="0dp" />

Where com.ym.littleshape is your package name

And in Java:

        timerView = (TimerView)findViewById(R.id.timer_view);

And then there will be a basic TimerView in your Activity: a circle and a point in the center.

Now you can use

timerView.startCountDown(long millis);
timerView.cancelCountDown();

to start a timer for countdown or interruput it.

The end of the countdown can be listened: use

setOnEndCountDownListener(OnEndCountDownListener listener)

to set the listener and implement your callback.

Methods

You can use several methods in timerView to customize your TimerView

  • startCountDown(long millis)

  • cancelCountDown()

  • setCountDownInMillis(long countDownInMillis)

  • setGravityEnable(boolean enable)

  • setBallClickEnable(boolean enable)

  • setDefaultStartSettingEnable(boolean enable)

  • setDefaultStartCountDownEnable(boolean enable)

  • setOnStartCountDownListener(OnStartCountDownListener listener)

  • setOnEndCountDownListener(OnEndCountDownListener listener)

  • setOnCancelCountDownListener(OnCancelCountDownListener listener)

  • setOnBallClickListener(OnBallClickListener listener)

  • setOnBallLongClickListener(OnBallLongClickListener listener)

  • setOnStartInteractiveSettingListener(OnStartInteractiveSettingListener listener)

  • setOnConfirmInteractiveSettingListener(OnConfirmInteractiveSettingListener listener)

  • setOnCancelInteractiveSettingListener(OnCancelInteractiveSettingListener listener)

  • registerGravitySensor()

  • unregisterGravitySensor()

  • storeState()

  • restoreState(int rimColor)

  • cancelInteractiveSetting()

  • isSettingState()

Example

Here are some typical usage example:

Ball affected by gravity

The little point in the center of the circle can move under the affect of gravity

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        timerView.setGravityEnable(true);
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        timerView.registerGravitySensor();
    }

    @Override
    protected void onPause() {
        timerView.unregisterGravitySensor();
        super.onPause();
    }

Ball affected by shaking

Shake your phone, the ball bounce. Haha, a little funny?

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        timerView.setShakeEnable(true);
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        timerView.registerGravitySensor();
    }

    @Override
    protected void onPause() {
        timerView.unregisterGravitySensor();
        super.onPause();
    }

Ball can be click or long click

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        ...
        timerView.setBallClickEnable(true);
        
        // then you can set these listeners for click callback
        timerView.setOnBallClickListener(new TimerView.OnBallClickListener() {
            @Override
            public void onBallClick() {
                Toast.makeText(MainActivity.this, "onBallClick", Toast.LENGTH_SHORT).show();
            }
        });
        timerView.setOnBallLongClickListener(new TimerView.OnBallLongClickListener() {
            @Override
            public void onBallLongClick() {
                Toast.makeText(MainActivity.this, "onBallLongClick", Toast.LENGTH_SHORT).show();
            }
        });
    }

Use the default way to start a countdown

In this case, keep touch the TimerView and shake your phone, the count down will start.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        ...
        timerView.setDefaultStartCountDownEnable(true);
        
        // set 5s countdown
        timerView.setCountDownInMillis(5000);
        
        // then you can set these listeners for callback
        timerView.setOnStartCountDownListener(new TimerView.OnStartCountDownListener() {
            @Override
            public void onStartCountDown(View v) {
                Toast.makeText(MainActivity.this, "onStartCountDown", Toast.LENGTH_SHORT).show();
            }
        });
        timerView.setOnEndCountDownListener(new TimerView.OnEndCountDownListener() {
            @Override
            public void onEndCountDown(View v) {
                Toast.makeText(MainActivity.this, "onEndCountDown", Toast.LENGTH_SHORT).show();
            }
        });
        timerView.setOnCancelCountDownListener(new TimerView.OnCancelCountDownListener() {
            @Override
            public void onCancelCountDown(View v) {
                Toast.makeText(MainActivity.this, "onCancelCountDown", Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        timerView.registerGravitySensor();
    }

    @Override
    protected void onPause() {
        timerView.unregisterGravitySensor();
        super.onPause();
    }

Use the default way to set your time for countdown

In this case, keep touch the ball and then you will come into setting mode, slide your finger on the screen can set the coundown(in minute).

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        ...
        timerView.setDefaultStartSettingEnable(true);
        
        // the default way to start settint need to touch the ball
        timerView.setBallClickEnable(true);
        
        // then you can set these listeners for callback, such as a vibrating.
        timerView.setOnStartInteractiveSettingListener(new TimerView.OnStartInteractiveSettingListener() {
            @Override
            public void onStartInteractiveSetting(View v) {
                Toast.makeText(MainActivity.this, "onStartInteractiveSetting", Toast.LENGTH_SHORT).show();

                Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                long [] pattern = {0, 100};
                vibrator.vibrate(pattern, -1);
            }
        });
        timerView.setOnConfirmInteractiveSettingListener(new TimerView.OnConfirmInteractiveSettingListener() {
            @Override
            public void onConfirmInteractiveSetting(View v) {
                Toast.makeText(MainActivity.this, "onConfirmInteractiveSetting", Toast.LENGTH_SHORT).show();

                Vibrator vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
                long [] pattern = {0, 100};
                vibrator.vibrate(pattern, -1);
            }
        });
        timerView.setOnCancelInteractiveSettingListener(null);

    }

    @Override
    public void onBackPressed() {
        // here is a example to cancel setting
        if (timerView.isSettingState()) {
            timerView.cancelInteractiveSetting();
        } else {
            super.onBackPressed();
        }
    }

Keep your countdown state

If you want to continue your countdown after restart the app, here is the example. The method storeState() reStoreState() will keep the necessary data into SharedPrefernce.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
        ...
        // 5 minutes
        timerView.startCountDown(300000);
        
        timerView.restoreState();

    }

    @Override
    protected void onPause() {
    
        timerView.storeState();

        super.onPause();
    }


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].