import [Link].
Activity;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class BookArtGenerator extends Activity {
private Canvas canvas, selectedCanvas;
private Paint ctx, selectedCtx;
private Bitmap userImage, selectedPlaceholder;
private String userFileName;
private Map<String, String> entries = new HashMap<>();
private String[] inputIds = {"projectname", "firstpage", "lastpage", "cm",
"inch", "bookheight", "singleprecision", "smoothe"};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_book_art_generator);
Button fileButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
loadImage();
}
});
for (final String id : inputIds) {
EditText editText = findViewById(getResources().getIdentifier(id, "id",
getPackageName()));
[Link](new [Link]() {
@Override
public void onClick(View v) {
processEntries();
}
});
}
final CheckBox smootheCheckBox = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
showValue(smootheCheckBox);
}
});
final TextView smootheOutput = findViewById([Link]);
Button startButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
processEntries();
}
});
Button imageDownloadButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
downloadImage();
}
});
Button textDownloadButton = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
downloadText();
}
});
canvas = new Canvas();
selectedCanvas = new Canvas();
selectedPlaceholder = [Link](200, 200,
[Link].ARGB_8888);
Canvas g = new Canvas(selectedPlaceholder);
[Link]([Link]);
displaySelectedImage(null, selectedPlaceholder);
}
private void loadImage() {
// Implement image loading logic
}
private void showValue(CheckBox checkBox) {
TextView smootheOutput = findViewById([Link]);
[Link]([Link]([Link]()));
}
private void processEntries() {
deactivateStartButton();
boolean entriesValid = true;
for (String id : inputIds) {
EditText editText = findViewById(getResources().getIdentifier(id, "id",
getPackageName()));
if (!checkEntry(editText)) {
entriesValid = false;
}
}
[Link]("userimage", [Link]());
if (entriesValid) {
activateStartButton();
}
}
private boolean checkEntry(EditText editText) {
[Link]([Link]);
String errorMessage = null;
String id = [Link]() == [Link] ? "projectname" :
[Link]() == [Link] ? "firstpage" :
[Link]() == [Link] ? "lastpage" :
[Link]() == [Link] ? "cm" :
[Link]() == [Link] ? "inch" :
[Link]() == [Link] ? "bookheight" :
[Link]() == [Link] ? "singleprecision" :
[Link]() == [Link] ? "smoothe" : null;
switch (id) {
case "projectname":
[Link]("projectname", [Link]().toString());
break;
case "firstpage":
if ([Link]().toString().isEmpty() || !
[Link]().toString().matches("\\d+")) {
errorMessage = "The first page must be an even, positive
number.";
} else {
[Link]("firstpage", [Link]().toString());
}
break;
case "lastpage":
if ([Link]().toString().isEmpty() || !
[Link]().toString().matches("\\d+") ||
[Link]([Link]().toString()) <=
[Link]([Link]("firstpage"))) {
errorMessage = "The last page must be an even, positive number.
It must be larger than the number of the first page.";
} else {
[Link]("lastpage", [Link]().toString());
}
break;
case "cm":
case "inch":
[Link]("unit", id);
break;
case "bookheight":
if ([Link]().toString().isEmpty() || !
[Link]().toString().matches("\\d+(\\.\\d{1,1})?")) {
errorMessage = "The book's height must be a positive number
with no more than 1 digit after the decimal point.";
} else {
[Link]("bookheight",
[Link]([Link]([Link]().toString()) * 100));
}
break;
case "singleprecision":
[Link]("singleprecision",
[Link]([Link]()));
break;
case "smoothe":
if ([Link]().toString().isEmpty() || !
[Link]().toString().matches("\\d+")) {
errorMessage = "The smoothing value you selected is invalid -
please use a number between 0 and 20.";
} else {
[Link]("smoothe", [Link]().toString());
}
break;
}
if (errorMessage != null) {
[Link]([Link]);
[Link](this, errorMessage, Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
private void activateStartButton() {
Button startButton = findViewById([Link]);
[Link](true);
[Link](1.0f);
}
private void deactivateStartButton() {
Button startButton = findViewById([Link]);
[Link](false);
[Link](0.3f);
}
private void displaySelectedImage(View view, Bitmap img) {
img = img == null ? selectedPlaceholder : img;
[Link]([Link],
[Link]);
int newWidth, newHeight;
if ([Link]() / (double)[Link]() < 1) {
newWidth = (int)([Link]() * [Link]() /
(double)[Link]());
newHeight = [Link]();
} else {
newWidth = [Link]();
newHeight = (int)([Link]() * [Link]() /
(double)[Link]());
}
int newX = ([Link]() - newWidth) / 2;
int newY = ([Link]() - newHeight) / 2;
[Link](img, newX, newY, selectedCtx);
}
private void downloadImage() {
Bitmap image = [Link]([Link](), [Link](),
[Link].ARGB_8888);
Canvas g = new Canvas(image);
[Link](userImage, 0, 0, null);
String fileName = [Link]("\\.\\w+$", ".png");
File file = new File([Link](), fileName);
try {
FileOutputStream out = new FileOutputStream(file);
[Link]([Link], 100, out);
[Link]();
[Link]();
[Link](this, "Image saved to " + [Link](),
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
[Link]();
}
}
private void downloadText() {
String projectName = [Link]("projectname");
if (projectName == null || [Link]()) {
projectName = "pattern";
}
String htmlCode = "<html><body><!-- Your generated HTML code goes here --
></body></html>";
File file = new File([Link](),
[Link](" ", "_").toLowerCase() + ".html");
try {
FileOutputStream out = new FileOutputStream(file);
[Link]([Link]());
[Link]();
[Link]();
[Link](this, "HTML code saved to " + [Link](),
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
[Link]();
}
}
}