Files
src
build.gradle
settings.gradle
Code
4 363
src/main/java/com/kodari/googlebuild/MainActivity.java
package com.kodari.googlebuild;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class MainActivity extends Activity {
private static final String PREFERENCES = "googlebuild_preferences";
private static final String API_KEY = "gemini_api_key";
private static final String GEMINI_ENDPOINT =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent";
private final ExecutorService executor = Executors.newSingleThreadExecutor();
private final Handler mainHandler = new Handler(Looper.getMainLooper());
private EditText promptInput;
private EditText apiKeyInput;
private Spinner styleInput;
private Spinner sizeInput;
private Spinner paletteInput;
private Button generateButton;
private TextView statusText;
private TextView resultText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(createScreen());
apiKeyInput.setText(preferences().getString(API_KEY, ""));
}
private View createScreen() {
ScrollView scrollView = new ScrollView(this);
scrollView.setFillViewport(true);
scrollView.setBackgroundColor(Color.rgb(247, 248, 252));
LinearLayout content = new LinearLayout(this);
content.setOrientation(LinearLayout.VERTICAL);
content.setPadding(dp(20), dp(24), dp(20), dp(32));
scrollView.addView(content);
TextView title = new TextView(this);
title.setText("GoogleBuild");
title.setTextColor(Color.rgb(33, 45, 75));
title.setTextSize(28);
title.setTypeface(null, android.graphics.Typeface.BOLD);
content.addView(title);
TextView subtitle = new TextView(this);
subtitle.setText("Turn an idea into a Minecraft-ready house plan.");
subtitle.setTextColor(Color.rgb(92, 101, 120));
subtitle.setTextSize(15);
addView(content, subtitle, 0, 8);
addLabel(content, "DESIGN PROMPT");
promptInput = new EditText(this);
promptInput.setHint("Describe the house you want...");
promptInput.setGravity(android.view.Gravity.TOP | android.view.Gravity.START);
promptInput.setMinLines(4);
promptInput.setPadding(dp(12), dp(12), dp(12), dp(12));
promptInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE
| InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
addView(content, promptInput, 0, 6);
addLabel(content, "ARCHITECTURAL STYLE");
styleInput = addSpinner(content, new String[]{
"Modern", "Victorian", "Cottage", "Medieval", "Japanese", "Futuristic", "Rustic"
});
addLabel(content, "BUILD SIZE");
sizeInput = addSpinner(content, new String[]{
"Small · 12 × 10 blocks", "Medium · 16 × 14 blocks",
"Large · 20 × 18 blocks", "Grand · 24 × 22 blocks"
});
addLabel(content, "MATERIAL PALETTE");
paletteInput = addSpinner(content, new String[]{
"Oak and stone", "Spruce and cobblestone", "Quartz and glass",
"Dark oak and brick", "Cherry wood and sandstone", "Let Gemini choose"
});
addLabel(content, "GEMINI API KEY");
apiKeyInput = new EditText(this);
apiKeyInput.setHint("Paste your Google AI Studio API key");
apiKeyInput.setSingleLine(true);
apiKeyInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
apiKeyInput.setPadding(dp(12), dp(10), dp(12), dp(10));
addView(content, apiKeyInput, 0, 6);
TextView keyNote = new TextView(this);
keyNote.setText("Your key is saved only on this device and sent directly to Google.");
keyNote.setTextColor(Color.rgb(105, 112, 128));
keyNote.setTextSize(12);
addView(content, keyNote, 0, 4);
generateButton = new Button(this);
generateButton.setText("Generate house plan");
addView(content, generateButton, dp(48), 18);
generateButton.setOnClickListener(view -> generatePlan());
statusText = new TextView(this);
statusText.setTextColor(Color.rgb(77, 87, 109));
statusText.setTextSize(14);
addView(content, statusText, 0, 12);
resultText = new TextView(this);
resultText.setTextColor(Color.rgb(40, 47, 64));
resultText.setTextSize(15);
resultText.setTextIsSelectable(true);
resultText.setPadding(dp(14), dp(14), dp(14), dp(14));
resultText.setBackgroundColor(Color.WHITE);
addView(content, resultText, 0, 8);
return scrollView;
}
private void generatePlan() {
String prompt = promptInput.getText().toString().trim();
String apiKey = apiKeyInput.getText().toString().trim();
if (prompt.isEmpty()) {
statusText.setText("Describe your house before generating a plan.");
return;
}
if (apiKey.isEmpty()) {
statusText.setText("Add your Google AI Studio API key to continue.");
return;
}
preferences().edit().putString(API_KEY, apiKey).apply();
String style = styleInput.getSelectedItem().toString();
String size = sizeInput.getSelectedItem().toString();
String palette = paletteInput.getSelectedItem().toString();
generateButton.setEnabled(false);
statusText.setText("Generating your house plan…");
resultText.setText("");
executor.execute(() -> {
try {
String plan = requestPlan(apiKey, prompt, style, size, palette);
mainHandler.post(() -> {
resultText.setText(plan);
statusText.setText("House plan generated.");
generateButton.setEnabled(true);
});
} catch (Exception exception) {
String message = exception.getMessage() == null ? "Request failed." : exception.getMessage();
mainHandler.post(() -> {
statusText.setText(message);
generateButton.setEnabled(true);
});
}
});
}
private String requestPlan(String apiKey, String description, String style, String size, String palette)
throws Exception {
String instructions = "Create a practical Minecraft house blueprint from this request. "
+ "Return readable plain text with sections: Concept, Dimensions, Materials, "
+ "Floor plan, and Build steps. Include a compact top-down ASCII floor plan for each floor, "
+ "label its orientation, and give clear block-placement guidance. Keep the design within "
+ "the selected dimensions.\n"
+ "Architectural style: " + style + ".\n"
+ "Maximum footprint: " + size + ".\n"
+ "Material palette: " + palette + ".\n"
+ "Player's description: " + description;
JSONObject part = new JSONObject().put("text", instructions);
JSONArray parts = new JSONArray().put(part);
JSONObject content = new JSONObject().put("parts", parts);
JSONObject request = new JSONObject().put("contents", new JSONArray().put(content));
HttpURLConnection connection = (HttpURLConnection) new URL(GEMINI_ENDPOINT).openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(15000);