summaryrefslogtreecommitdiff
path: root/samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2013-05-29 14:57:39 -0700
committerChet Haase <chet@google.com>2013-05-30 13:38:02 -0700
commit28b127ec1e5af575a74af679a8542042112d177e (patch)
treec43a15162321869f602f20dca768e18ed85d5e67 /samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java
parentbc1a645f26a30fd95e68043b608038537b7c798f (diff)
New DevBytes animation demos
Change-Id: Ib475ddb109e0e62f0f085b6591ca15af0b79f75b
Diffstat (limited to 'samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java')
-rw-r--r--samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java b/samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java
new file mode 100644
index 000000000..d9f8d5e7d
--- /dev/null
+++ b/samples/devbytes/animation/LiveButton/src/com/example/android/livebutton/LiveButton.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * 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.
+ */
+
+package com.example.android.livebutton;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.animation.DecelerateInterpolator;
+import android.view.animation.OvershootInterpolator;
+import android.widget.Button;
+
+/**
+ * This app shows a simple application of anticipation and follow-through techniques as
+ * the button animates into its pressed state and animates back out of it, overshooting
+ * end state before resolving.
+ *
+ * Watch the associated video for this demo on the DevBytes channel of developer.android.com
+ * or on the DevBytes playlist in the androiddevelopers channel on YouTube at
+ * https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_XOgcRukSoKKjewFJZrKV0.
+ */
+public class LiveButton extends Activity {
+
+ DecelerateInterpolator sDecelerator = new DecelerateInterpolator();
+ OvershootInterpolator sOvershooter = new OvershootInterpolator(10f);
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_overshoot);
+
+ final Button clickMeButton = (Button) findViewById(R.id.clickMe);
+ clickMeButton.animate().setDuration(200);
+
+ clickMeButton.setOnTouchListener(new View.OnTouchListener() {
+
+ @Override
+ public boolean onTouch(View arg0, MotionEvent arg1) {
+ if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
+ clickMeButton.animate().setInterpolator(sDecelerator).
+ scaleX(.7f).scaleY(.7f);
+ } else if (arg1.getAction() == MotionEvent.ACTION_UP) {
+ clickMeButton.animate().setInterpolator(sOvershooter).
+ scaleX(1f).scaleY(1f);
+ }
+ return false;
+ }
+ });
+
+ }
+}