diff --git a/android/sample/AndroidManifest.xml b/android/sample/AndroidManifest.xml index 21184172b..96361f720 100644 --- a/android/sample/AndroidManifest.xml +++ b/android/sample/AndroidManifest.xml @@ -51,6 +51,24 @@ + + + + + + + + + + + + + + + + diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/AnimationsActivity.java b/android/sample/src/main/java/com/facebook/flipper/sample/AnimationsActivity.java new file mode 100644 index 000000000..6aa7ab13e --- /dev/null +++ b/android/sample/src/main/java/com/facebook/flipper/sample/AnimationsActivity.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.flipper.sample; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.Button; +import android.widget.TextView; + +public class AnimationsActivity extends Activity { + + Button btnBlink, btnRotate, btnMove, btnBounce, btnSequential; + Animation animBlink, animRotate, animMove, animBounce, animSequential; + TextView txtBlink, txtRotate, txtMove, txtBounce, txtSeq; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_animations); + + btnBlink = (Button) findViewById(R.id.btnBlink); + btnRotate = (Button) findViewById(R.id.btnRotate); + btnMove = (Button) findViewById(R.id.btnMove); + btnBounce = (Button) findViewById(R.id.btnBounce); + btnSequential = (Button) findViewById(R.id.btnSequential); + txtBlink = (TextView) findViewById(R.id.txt_blink); + txtRotate = (TextView) findViewById(R.id.txt_rotate); + txtMove = (TextView) findViewById(R.id.txt_move); + txtBounce = (TextView) findViewById(R.id.txt_bounce); + txtSeq = (TextView) findViewById(R.id.txt_seq); + + animBlink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink); + // blink + btnBlink.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + txtBlink.setVisibility(View.VISIBLE); + txtBlink.startAnimation(animBlink); + } + }); + + animRotate = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate); + + // Rotate + btnRotate.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + txtRotate.startAnimation(animRotate); + } + }); + animMove = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move); + // Move + btnMove.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + txtMove.startAnimation(animMove); + } + }); + + animBounce = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.bounce); + // Slide Down + btnBounce.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + txtBounce.startAnimation(animBounce); + } + }); + animSequential = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.sequential); + // Sequential + btnSequential.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View v) { + + txtSeq.startAnimation(animSequential); + } + }); + } +} diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/FragmentTestFragment.java b/android/sample/src/main/java/com/facebook/flipper/sample/FragmentTestFragment.java index bfba155b6..4bd31be23 100644 --- a/android/sample/src/main/java/com/facebook/flipper/sample/FragmentTestFragment.java +++ b/android/sample/src/main/java/com/facebook/flipper/sample/FragmentTestFragment.java @@ -11,17 +11,51 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import androidx.fragment.app.Fragment; public class FragmentTestFragment extends Fragment { + View mView; + int mTicker; public FragmentTestFragment() { - // Required empty public constructor + mTicker = 0; + } + + private void updateTicker() { + try { + ViewGroup viewGroup = (ViewGroup) mView; + TextView textView = (TextView) viewGroup.getChildAt(1); + String text = String.valueOf(mTicker++); + + textView.setText(text); + } finally { + // 100% guarantee that this always happens, even if + // your update method throws an exception + mView.postDelayed( + new Runnable() { + @Override + public void run() { + updateTicker(); + } + }, + 10000); + } } @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_test, container, false); + mView = inflater.inflate(R.layout.fragment_test, container, false); + mView.postDelayed( + new Runnable() { + @Override + public void run() { + updateTicker(); + } + }, + 1000); + + return mView; } } diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/ListActivity.java b/android/sample/src/main/java/com/facebook/flipper/sample/ListActivity.java new file mode 100644 index 000000000..0f65041c3 --- /dev/null +++ b/android/sample/src/main/java/com/facebook/flipper/sample/ListActivity.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.flipper.sample; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import java.util.ArrayList; + +public class ListActivity extends Activity { + + ListView listView; + ArrayList list; + ArrayAdapter adapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_list); + + listView = (ListView) findViewById(R.id.list); + + list = new ArrayList<>(); + list.add("Apple"); + list.add("Banana"); + list.add("Pineapple"); + list.add("Orange"); + list.add("Lychee"); + list.add("Guava"); + list.add("Peech"); + list.add("Melon"); + list.add("Watermelon"); + list.add("Papaya"); + list.add("Grape"); + list.add("Apricot"); + list.add("Coconut"); + list.add("Banana"); + list.add("Cherry"); + list.add("Pear"); + list.add("Mango"); + list.add("Plum"); + + adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list); + listView.setAdapter(adapter); + } +} diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java b/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java index 18ebb875e..408b3a97b 100644 --- a/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java +++ b/android/sample/src/main/java/com/facebook/flipper/sample/RootComponentSpec.java @@ -24,6 +24,7 @@ import com.facebook.litho.annotations.OnUpdateState; import com.facebook.litho.annotations.State; import com.facebook.litho.fresco.FrescoImage; import com.facebook.litho.widget.Text; +import com.facebook.litho.widget.VerticalScroll; import com.facebook.yoga.YogaEdge; @LayoutSpec @@ -33,79 +34,95 @@ public class RootComponentSpec { static Component onCreateLayout(final ComponentContext c, @State boolean displayImage) { final DraweeController controller = Fresco.newDraweeControllerBuilder().setUri("https://fbflipper.com/img/icon.png").build(); - return Column.create(c) - .child( - Text.create(c) - .text("Send GET request") - .key("1") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.hitGetRequest(c))) - .child( - Text.create(c) - .text("Send POST request") - .key("2") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.hitPostRequest(c))) - .child( - Text.create(c) - .text("Trigger Notification") - .key("3") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.triggerNotification(c))) - .child( - Text.create(c) - .text("Diagnose connection issues") - .key("4") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.openDiagnostics(c))) - .child( - Text.create(c) - .text("Load Fresco image") - .key("5") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.loadImage(c))) - .child( - Text.create(c) - .text("Navigate to another page") - .key("6") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.openAlternateActivityOne(c))) - .child( - Text.create(c) - .text("Navigate to layout test page") - .key("7") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.openAlternateLayoutTestActivity(c))) - .child( - Text.create(c) - .text("Navigate to fragment test page") - .key("8") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.openFragmentTestActivity(c))) - .child( - Text.create(c) - .text("Crash this app") - .key("9") - .marginDip(YogaEdge.ALL, 10) - .textSizeSp(20) - .clickHandler(RootComponent.triggerCrash(c))) - .child( - displayImage - ? FrescoImage.create(c) + + Column col = + Column.create(c) + .child( + Text.create(c) + .text("Send HTTP/GET request") + .key("1") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.hitGetRequest(c))) + .child( + Text.create(c) + .text("Send HTTP/POST request") + .key("2") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.hitPostRequest(c))) + .child( + Text.create(c) + .text("Trigger notification") + .key("3") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.triggerNotification(c))) + .child( + Text.create(c) + .text("Diagnose connection issues") + .key("4") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openDiagnostics(c))) + .child( + Text.create(c) + .text("Load Fresco image") + .key("5") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.loadImage(c))) + .child( + Text.create(c) + .text("Navigate to another page") + .key("6") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openAlternateActivityOne(c))) + .child( + Text.create(c) + .text("Navigate to layout test page") + .key("7") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openAlternateLayoutTestActivity(c))) + .child( + Text.create(c) + .text("Navigate to fragment test page") + .key("8") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openFragmentTestActivity(c))) + .child( + Text.create(c) + .text("Navigate to list activity") + .key("9") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openListActivity(c))) + .child( + Text.create(c) + .text("Navigate to animations activity") + .key("10") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.openAnimationsActivity(c))) + .child( + Text.create(c) + .text("Crash this app") + .key("11") + .marginDip(YogaEdge.ALL, 10) + .textSizeSp(20) + .clickHandler(RootComponent.triggerCrash(c))) + .child( + FrescoImage.create(c) .controller(controller) .marginDip(YogaEdge.ALL, 10) .widthDip(150) - .heightDip(150) - : null) - .build(); + .heightDip(150)) + .build(); + + return VerticalScroll.create(c).childComponent(col).build(); } @OnEvent(ClickEvent.class) @@ -161,4 +178,16 @@ public class RootComponentSpec { static void loadImage(final ComponentContext c) { RootComponent.updateDisplayImageAsync(c); } + + @OnEvent(ClickEvent.class) + static void openListActivity(final ComponentContext c) { + final Intent intent = new Intent(c.getAndroidContext(), ListActivity.class); + c.getAndroidContext().startActivity(intent); + } + + @OnEvent(ClickEvent.class) + static void openAnimationsActivity(final ComponentContext c) { + final Intent intent = new Intent(c.getAndroidContext(), AnimationsActivity.class); + c.getAndroidContext().startActivity(intent); + } } diff --git a/android/sample/src/main/res/anim/blink.xml b/android/sample/src/main/res/anim/blink.xml new file mode 100644 index 000000000..137a7a3f0 --- /dev/null +++ b/android/sample/src/main/res/anim/blink.xml @@ -0,0 +1,8 @@ + + + diff --git a/android/sample/src/main/res/anim/bounce.xml b/android/sample/src/main/res/anim/bounce.xml new file mode 100644 index 000000000..1c9a255c9 --- /dev/null +++ b/android/sample/src/main/res/anim/bounce.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/android/sample/src/main/res/anim/move.xml b/android/sample/src/main/res/anim/move.xml new file mode 100644 index 000000000..542875fe2 --- /dev/null +++ b/android/sample/src/main/res/anim/move.xml @@ -0,0 +1,10 @@ + + + + diff --git a/android/sample/src/main/res/anim/rotate.xml b/android/sample/src/main/res/anim/rotate.xml new file mode 100644 index 000000000..75d2da1d9 --- /dev/null +++ b/android/sample/src/main/res/anim/rotate.xml @@ -0,0 +1,11 @@ + + + + diff --git a/android/sample/src/main/res/anim/sequential.xml b/android/sample/src/main/res/anim/sequential.xml new file mode 100644 index 000000000..827c320d2 --- /dev/null +++ b/android/sample/src/main/res/anim/sequential.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + diff --git a/android/sample/src/main/res/layout/activity_animations.xml b/android/sample/src/main/res/layout/activity_animations.xml new file mode 100644 index 000000000..e53b67722 --- /dev/null +++ b/android/sample/src/main/res/layout/activity_animations.xml @@ -0,0 +1,111 @@ + + + + + + + +