From 868ae9e36aa22244a6c94503b0baef89a408469f Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Tue, 13 Sep 2022 11:05:42 -0700 Subject: [PATCH] Added dialogs to sample app Summary: This is to allow us to test dialogs from the UI debugger Reviewed By: lblasa Differential Revision: D39468653 fbshipit-source-id: 59c759a794c42b85bc288d60e1b2c6a71e32bb3d --- android/sample/AndroidManifest.xml | 2 +- .../flipper/sample/ButtonsActivity.java | 52 +++++++++++++++++++ .../flipper/sample/IncrementActivity.java | 38 -------------- .../flipper/sample/RootComponentSpec.java | 4 +- .../flipper/sample/TestDialogFragment.java | 24 +++++++++ .../src/main/res/layout/activity_buttons.xml | 42 +++++++++++++++ .../main/res/layout/activity_increment.xml | 26 ---------- 7 files changed, 121 insertions(+), 67 deletions(-) create mode 100644 android/sample/src/main/java/com/facebook/flipper/sample/ButtonsActivity.java delete mode 100644 android/sample/src/main/java/com/facebook/flipper/sample/IncrementActivity.java create mode 100644 android/sample/src/main/java/com/facebook/flipper/sample/TestDialogFragment.java create mode 100644 android/sample/src/main/res/layout/activity_buttons.xml delete mode 100644 android/sample/src/main/res/layout/activity_increment.xml diff --git a/android/sample/AndroidManifest.xml b/android/sample/AndroidManifest.xml index c7e79a8dd..fe4a70646 100644 --- a/android/sample/AndroidManifest.xml +++ b/android/sample/AndroidManifest.xml @@ -60,7 +60,7 @@ - diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/ButtonsActivity.java b/android/sample/src/main/java/com/facebook/flipper/sample/ButtonsActivity.java new file mode 100644 index 000000000..ed54674ff --- /dev/null +++ b/android/sample/src/main/java/com/facebook/flipper/sample/ButtonsActivity.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.os.Bundle; +import android.widget.Button; +import android.widget.TextView; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.FragmentActivity; + +public class ButtonsActivity extends FragmentActivity { + + int count = 0; + TextView text; + Button button; + Button dialogOld; + Button dialogFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_buttons); + + text = (TextView) findViewById(R.id.count); + + button = (Button) findViewById(com.facebook.flipper.sample.R.id.btn_inc); + dialogOld = (Button) findViewById(R.id.dialog_old_api); + dialogFragment = (Button) findViewById(R.id.dialog_fragment); + button.setOnClickListener(view -> ButtonsActivity.this.text.setText(String.valueOf(++count))); + + dialogFragment.setOnClickListener( + btn -> { + TestDialogFragment startGameDialogFragment = new TestDialogFragment(); + startGameDialogFragment.show(getSupportFragmentManager(), "dialog"); + }); + + dialogOld.setOnClickListener( + btn -> { + new AlertDialog.Builder(this) + .setTitle("Old Dialog") + .setMessage("This is an old dialog") + .setNegativeButton(android.R.string.no, null) + .setIcon(android.R.drawable.ic_dialog_alert) + .show(); + }); + } +} diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/IncrementActivity.java b/android/sample/src/main/java/com/facebook/flipper/sample/IncrementActivity.java deleted file mode 100644 index 7e35ac7b3..000000000 --- a/android/sample/src/main/java/com/facebook/flipper/sample/IncrementActivity.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.widget.Button; -import android.widget.TextView; - -public class IncrementActivity extends Activity { - - int count = 0; - TextView text; - Button button; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_increment); - - text = (TextView) findViewById(R.id.count); - - button = (Button) findViewById(com.facebook.flipper.sample.R.id.btn_inc); - button.setOnClickListener( - new View.OnClickListener() { - @Override - public void onClick(View view) { - IncrementActivity.this.text.setText(String.valueOf(++count)); - } - }); - } -} 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 af0fb1ec2..bceadcff3 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 @@ -109,7 +109,7 @@ public class RootComponentSpec { .clickHandler(RootComponent.openAnimationsActivity(c))) .child( Text.create(c) - .text("Navigate to increment activity") + .text("Navigate to buttons activity") .key("11") .marginDip(YogaEdge.ALL, 10) .textSizeSp(20) @@ -200,7 +200,7 @@ public class RootComponentSpec { @OnEvent(ClickEvent.class) static void openIncrementActivity(final ComponentContext c) { - final Intent intent = new Intent(c.getAndroidContext(), IncrementActivity.class); + final Intent intent = new Intent(c.getAndroidContext(), ButtonsActivity.class); c.getAndroidContext().startActivity(intent); } } diff --git a/android/sample/src/main/java/com/facebook/flipper/sample/TestDialogFragment.java b/android/sample/src/main/java/com/facebook/flipper/sample/TestDialogFragment.java new file mode 100644 index 000000000..d47a3a442 --- /dev/null +++ b/android/sample/src/main/java/com/facebook/flipper/sample/TestDialogFragment.java @@ -0,0 +1,24 @@ +/* + * 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.Dialog; +import android.os.Bundle; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + +public class TestDialogFragment extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("This is a dialog fragment").setPositiveButton("Yes", (dialog, id) -> {}); + + return builder.create(); + } +} diff --git a/android/sample/src/main/res/layout/activity_buttons.xml b/android/sample/src/main/res/layout/activity_buttons.xml new file mode 100644 index 000000000..6f9c9c7bb --- /dev/null +++ b/android/sample/src/main/res/layout/activity_buttons.xml @@ -0,0 +1,42 @@ + + + + + + +