Skip to content

Commit 7e0cc66

Browse files
author
artjom404
committed
CATROID-754 - JSON extractor dialog
- implements CATROID-753 - JsonExtractorDialog.java: Creation of new class for JSON extractor - strings.xml: Creation of new string for JSON extractor - dialog_regex_json_extractor.xml: Creation of new layout for JSON extractor
1 parent d509d49 commit 7e0cc66

File tree

7 files changed

+215
-9
lines changed

7 files changed

+215
-9
lines changed

.idea/codeStyles/Project.xml

-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Catroid: An on-device visual programming system for Android devices
3+
* Copyright (C) 2010-2020 The Catrobat Team
4+
* (<http://developer.catrobat.org/credits>)
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* An additional term exception under section 7 of the GNU Affero
12+
* General Public License, version 3, is available at
13+
* http://developer.catrobat.org/license_additional_term
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
package org.catrobat.catroid.uiespresso.ui.dialog;
25+
26+
import org.catrobat.catroid.R;
27+
import org.catrobat.catroid.content.Script;
28+
import org.catrobat.catroid.content.bricks.ChangeSizeByNBrick;
29+
import org.catrobat.catroid.ui.SpriteActivity;
30+
import org.catrobat.catroid.uiespresso.content.brick.utils.BrickTestUtils;
31+
import org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper;
32+
import org.catrobat.catroid.uiespresso.util.UiTestUtils;
33+
import org.catrobat.catroid.uiespresso.util.rules.FragmentActivityTestRule;
34+
import org.junit.Before;
35+
import org.junit.Rule;
36+
import org.junit.Test;
37+
import org.junit.runner.RunWith;
38+
39+
import androidx.test.ext.junit.runners.AndroidJUnit4;
40+
41+
import static org.catrobat.catroid.uiespresso.content.brick.utils.BrickDataInteractionWrapper.onBrickAtPosition;
42+
import static org.catrobat.catroid.uiespresso.formulaeditor.utils.FormulaEditorWrapper.onFormulaEditor;
43+
44+
import static androidx.test.espresso.Espresso.onView;
45+
import static androidx.test.espresso.action.ViewActions.click;
46+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
47+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
48+
import static androidx.test.espresso.matcher.ViewMatchers.withHint;
49+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
50+
import static androidx.test.espresso.matcher.ViewMatchers.withText;
51+
52+
@RunWith(AndroidJUnit4.class)
53+
public class JsonExtractorDialogTest {
54+
@Rule
55+
public FragmentActivityTestRule<SpriteActivity> baseActivityTestRule = new
56+
FragmentActivityTestRule<>(SpriteActivity.class, SpriteActivity.EXTRA_FRAGMENT_POSITION, SpriteActivity.FRAGMENT_SCRIPTS);
57+
@Before
58+
public void setUp() {
59+
Script script = BrickTestUtils.createProjectAndGetStartScript("HtmlExtractorDialogTest");
60+
script.addBrick(new ChangeSizeByNBrick(0));
61+
baseActivityTestRule.launchActivity();
62+
63+
onBrickAtPosition(1).onChildView(withId(R.id.brick_change_size_by_edit_text))
64+
.perform(click());
65+
openJsonExtractor();
66+
}
67+
68+
private void openJsonExtractor() {
69+
String regularExpressionAssistant =
70+
"\t\t\t\t\t" + UiTestUtils.getResourcesString(R.string.formula_editor_function_regex_assistant);
71+
onFormulaEditor().performOpenCategory(FormulaEditorWrapper.Category.FUNCTIONS).performSelect(regularExpressionAssistant);
72+
onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).perform(click());
73+
}
74+
75+
@Test
76+
public void testHtmlExtractorDialogTitle() {
77+
onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).check(matches(isDisplayed()));
78+
}
79+
80+
@Test
81+
public void testHtmlExtractorDialogKeywordHint() {
82+
onView(withHint(R.string.keyword_label)).check(matches(isDisplayed()));
83+
}
84+
85+
@Test
86+
public void testHtmlExtractorDialogOkButton() {
87+
onView(withText(R.string.ok)).check(matches(isDisplayed()));
88+
}
89+
90+
@Test
91+
public void testHtmlExtractorDialogCancelButton() {
92+
onView(withText(R.string.cancel)).check(matches(isDisplayed()));
93+
}
94+
}

catroid/src/androidTest/java/org/catrobat/catroid/uiespresso/ui/dialog/RegularExpressionAssistantDialogTest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ public void testOpenWikipageOnWikiButtonClick() {
143143
public void testDoesHtmlExtractorOpensCorrectDialog() {
144144
clickOnAssistantInFunctionList();
145145

146-
onView(withText(R.string.formula_editor_regex_html_extractor_dialog_title)).perform(click()); //click on HTML Extractor
146+
onView(withText(R.string.formula_editor_regex_html_extractor_dialog_title)).perform(click());
147147
onView(withText(R.string.formula_editor_regex_html_extractor_dialog_title)).check(matches(isDisplayed()));
148148
}
149+
@Test
150+
public void testDoesJsonExtractorOpensCorrectDialog() {
151+
clickOnAssistantInFunctionList();
152+
153+
onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).perform(click());
154+
onView(withText(R.string.formula_editor_function_regex_json_extractor_title)).check(matches(isDisplayed()));
155+
}
149156
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Catroid: An on-device visual programming system for Android devices
3+
* Copyright (C) 2010-2020 The Catrobat Team
4+
* (<http://developer.catrobat.org/credits>)
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* An additional term exception under section 7 of the GNU Affero
12+
* General Public License, version 3, is available at
13+
* http://developer.catrobat.org/license_additional_term
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
24+
package org.catrobat.catroid.ui.dialogs.regexassistant;
25+
26+
import android.content.Context;
27+
import android.content.DialogInterface;
28+
29+
import org.catrobat.catroid.R;
30+
import org.catrobat.catroid.ui.recyclerview.dialog.TextInputDialog;
31+
32+
import androidx.annotation.Nullable;
33+
34+
public class JsonExtractorDialog extends RegularExpressionFeature {
35+
public JsonExtractorDialog() {
36+
this.titleId = R.string.formula_editor_function_regex_json_extractor_title;
37+
}
38+
@Override
39+
public void openDialog(Context context) {
40+
createDialog(context);
41+
}
42+
public void createDialog(Context context) {
43+
TextInputDialog.Builder builder = new TextInputDialog.Builder(context);
44+
45+
builder.setView(R.layout.dialog_regex_json_extractor);
46+
builder.setTitle(R.string.formula_editor_function_regex_json_extractor_title);
47+
builder.setNegativeButton(R.string.cancel, null);
48+
builder.setHint(context.getString(R.string.keyword_label));
49+
builder.setTextWatcher(new TextInputDialog.TextWatcher() {
50+
@Nullable
51+
@Override
52+
public String validateInput(String input, Context context) {
53+
return null;
54+
}
55+
});
56+
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
57+
@Override
58+
public void onClick(DialogInterface dialog, int which) {
59+
}
60+
});
61+
62+
builder.show();
63+
}
64+
}

catroid/src/main/java/org/catrobat/catroid/ui/dialogs/regexassistant/RegularExpressionAssistantDialog.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public void onClick(DialogInterface dialog, int indexInList) {
7676

7777
private void createListOfFeatures() {
7878
listOfFeatures = new ArrayList<>();
79-
8079
if (BuildConfig.FEATURE_REGULAR_EXPRESSION_ASSISTANT_ENABLED) {
8180
listOfFeatures.add(new HtmlExtractorDialog());
81+
listOfFeatures.add(new JsonExtractorDialog());
8282
}
8383
listOfFeatures.add(new WikiWebPage());
8484
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Catroid: An on-device visual programming system for Android devices
4+
~ Copyright (C) 2010-2020 The Catrobat Team
5+
~ (<http://developer.catrobat.org/credits>)
6+
~
7+
~ This program is free software: you can redistribute it and/or modify
8+
~ it under the terms of the GNU Affero General Public License as
9+
~ published by the Free Software Foundation, either version 3 of the
10+
~ License, or (at your option) any later version.
11+
~
12+
~ An additional term exception under section 7 of the GNU Affero
13+
~ General Public License, version 3, is available at
14+
~ http://developer.catrobat.org/license_additional_term
15+
~
16+
~ This program is distributed in the hope that it will be useful,
17+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
~ GNU Affero General Public License for more details.
20+
~
21+
~ You should have received a copy of the GNU Affero General Public License
22+
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
-->
24+
25+
<LinearLayout
26+
xmlns:android="http://schemas.android.com/apk/res/android"
27+
xmlns:app="http://schemas.android.com/apk/res-auto"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:padding="@dimen/dialog_content_area_padding_input"
31+
android:orientation="vertical">
32+
33+
<com.google.android.material.textfield.TextInputLayout
34+
android:id="@+id/input"
35+
android:layout_width="match_parent"
36+
android:layout_height="wrap_content"
37+
app:errorEnabled="true"
38+
app:hintEnabled="true">
39+
40+
<com.google.android.material.textfield.TextInputEditText
41+
android:id="@+id/input_edit_text"
42+
android:layout_width="match_parent"
43+
android:layout_height="wrap_content"
44+
android:selectAllOnFocus="true" />
45+
46+
</com.google.android.material.textfield.TextInputLayout>
47+
</LinearLayout>

catroid/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ needs read and write access to it. You can always change permissions through you
17801780
<string name="formula_editor_function_regex_html_extractor_not_found">The keyword could not be found.</string>
17811781
<string name="formula_editor_function_regex_html_extractor_found">Search was successful
17821782
.</string>
1783+
<string name="formula_editor_function_regex_json_extractor_title">JSON extractor</string>
17831784
<string name="formula_editor_function_arduino_read_pin_value_digital">arduino digital pin</string>
17841785
<string name="formula_editor_function_arduino_read_pin_value_analog">arduino analog pin</string>
17851786
<string name="formula_editor_function_raspi_read_pin_value_digital">raspberry pi pin</string>

0 commit comments

Comments
 (0)