forked from google/blockly-android
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a demo for alternative configuration of the Blockly fragments. (…
…google#440) Specifically, showing a toolbox on top that is always open. Fixing a bug in configuration of BlockList block spacing when no tabs are present.
- Loading branch information
Showing
7 changed files
with
216 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<toolbox> | ||
<block type="controls_if"></block> | ||
<block type="logic_compare"></block> | ||
<block type="logic_operation"></block> | ||
<block type="controls_repeat_ext"> | ||
<value name="TIMES"> | ||
<shadow type="math_number"> | ||
<field name="NUM">10</field> | ||
</shadow> | ||
</value> | ||
</block> | ||
<block type="logic_operation"></block> | ||
<block type="logic_negate"></block> | ||
<block type="logic_boolean"></block> | ||
</toolbox> |
76 changes: 76 additions & 0 deletions
76
blocklydemo/src/main/java/com/google/blockly/android/demo/AlwaysOpenToolboxActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.google.blockly.android.demo; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v4.app.Fragment; | ||
import android.view.View; | ||
|
||
import com.google.blockly.android.AbstractBlocklyActivity; | ||
import com.google.blockly.android.codegen.CodeGenerationRequest; | ||
import com.google.blockly.android.codegen.LoggingCodeGeneratorCallback; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Demonstration of how to replace {@code blockly_unified_layout} with a custom layout. | ||
* This alternative layout that places the toolbox on top, configured to always remain open. | ||
*/ | ||
|
||
public class AlwaysOpenToolboxActivity extends AbstractBlocklyActivity { | ||
private static final String TAG = "SimpleActivity"; | ||
|
||
private static final List<String> BLOCK_DEFINITIONS = Arrays.asList( | ||
"default/logic_blocks.json", | ||
"default/loop_blocks.json", | ||
"default/math_blocks.json" | ||
); | ||
private static final List<String> JAVASCRIPT_GENERATORS = Arrays.asList( | ||
// Custom block generators go here. Default blocks are already included. | ||
// TODO(#99): Include Javascript defaults when other languages are supported. | ||
); | ||
|
||
CodeGenerationRequest.CodeGeneratorCallback mCodeGeneratorCallback = | ||
new LoggingCodeGeneratorCallback(this, TAG); | ||
|
||
/** | ||
* Inflates a layout for the contents of the app that includes a toolbox that is always open. | ||
* | ||
* @param containerId The container id to target if using a {@link Fragment} | ||
* @return The {@link View} constructed. If using a {@link Fragment}, return null. | ||
*/ | ||
protected View onCreateContentView(int containerId) { | ||
return getLayoutInflater().inflate(R.layout.always_open_toolbox, null); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected List<String> getBlockDefinitionsJsonPaths() { | ||
return BLOCK_DEFINITIONS; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected String getToolboxContentsXmlPath() { | ||
return "simple_playground_toolbox.xml"; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected List<String> getGeneratorsJsPaths() { | ||
return JAVASCRIPT_GENERATORS; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected CodeGenerationRequest.CodeGeneratorCallback getCodeGenerationCallback() { | ||
// Uses the same callback for every generation call. | ||
return mCodeGeneratorCallback; | ||
} | ||
|
||
@Override | ||
protected void onInitBlankWorkspace() { | ||
// Initialize variable names. | ||
// TODO: (#22) Remove this override when variables are supported properly | ||
getController().addVariable("item"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- A Blockly workspace layout which places the toolbox on the top edge, | ||
- and is configured to always be open. | ||
--> | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:blockly="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
> | ||
|
||
<fragment android:name="com.google.blockly.android.ToolboxFragment" | ||
android:id="@+id/blockly_toolbox" | ||
android:layout_width="match_parent" | ||
android:layout_height="140dp" | ||
android:layout_alignParentTop="true" | ||
blockly:closeable="false" | ||
blockly:scrollOrientation="horizontal"/> | ||
|
||
<!-- This frame contains the workspace and closeable trash. --> | ||
<FrameLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_below="@id/blockly_toolbox"> | ||
|
||
<fragment android:name="com.google.blockly.android.WorkspaceFragment" | ||
android:id="@+id/blockly_workspace" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
/> | ||
|
||
<fragment android:name="com.google.blockly.android.TrashFragment" | ||
android:id="@+id/blockly_trash" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom" | ||
blockly:closeable="true" | ||
blockly:scrollOrientation="vertical" | ||
tools:ignore="MissingPrefix" | ||
/> | ||
|
||
<LinearLayout android:id="@+id/blockly_overlay_buttons" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:orientation="vertical"> | ||
|
||
<ImageButton android:id="@+id/blockly_zoom_in_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:background="@color/translucent" | ||
android:padding="2dp" | ||
android:src="@drawable/zoom_in"/> | ||
|
||
<ImageButton android:id="@+id/blockly_zoom_out_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:background="@color/translucent" | ||
android:padding="2dp" | ||
android:src="@drawable/zoom_out"/> | ||
|
||
<ImageButton android:id="@+id/blockly_center_view_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:background="@color/translucent" | ||
android:padding="2dp" | ||
android:src="@drawable/reset_view"/> | ||
|
||
<ImageButton android:id="@+id/blockly_trash_icon" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentRight="true" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentBottom="true" | ||
android:background="@color/translucent" | ||
android:padding="2dp" | ||
android:src="@drawable/trash"/> | ||
</LinearLayout> | ||
</FrameLayout> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters