Skip to content

Commit

Permalink
add support for splash images
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Sep 6, 2019
1 parent 54f99a0 commit 0690d7e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
51 changes: 38 additions & 13 deletions androidprojectmodifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,8 @@ void AndroidProjectModifier::addImages(QList<QHash<QString, QString>> images)
QFile imageFile(downloadImage(largestImage.value("url")));
largestImage.insert("path", imageFile.fileName());

QFile mdpi(resizeImage(largestImage, "48"));
QFile hdpi(resizeImage(largestImage, "72"));
QFile xhdpi(resizeImage(largestImage, "96"));
QFile xxhdpi(resizeImage(largestImage, "144"));
QFile xxxhdpi(resizeImage(largestImage, "192"));

const auto movePath = m_directory.absolutePath() + "/app/src/main/res/mipmap-";

QFile::remove(movePath + "mdpi" + "/ic_launcher.png") && mdpi.rename(movePath + "mdpi" + "/ic_launcher.png");
QFile::remove(movePath + "hdpi" + "/ic_launcher.png") && hdpi.rename(movePath + "hdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xhdpi" + "/ic_launcher.png") && xhdpi.rename(movePath + "xhdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xxhdpi" + "/ic_launcher.png") && xxhdpi.rename(movePath + "xxhdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xxxhdpi" + "/ic_launcher.png") && xxxhdpi.rename(movePath + "xxxhdpi" + "/ic_launcher.png");
addIcons(largestImage);
addSplash(largestImage);

imageFile.remove();
}
Expand Down Expand Up @@ -159,3 +148,39 @@ QString AndroidProjectModifier::resizeImage(const QHash<QString, QString> imageD

return tmpFile.fileName();
}

void AndroidProjectModifier::addIcons(QHash<QString, QString> image)
{
// todo rewrite this
QFile mdpi(resizeImage(image, "48"));
QFile hdpi(resizeImage(image, "72"));
QFile xhdpi(resizeImage(image, "96"));
QFile xxhdpi(resizeImage(image, "144"));
QFile xxxhdpi(resizeImage(image, "192"));

const auto movePath = m_directory.absolutePath() + "/app/src/main/res/mipmap-";

QFile::remove(movePath + "mdpi" + "/ic_launcher.png") && mdpi.rename(movePath + "mdpi" + "/ic_launcher.png");
QFile::remove(movePath + "hdpi" + "/ic_launcher.png") && hdpi.rename(movePath + "hdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xhdpi" + "/ic_launcher.png") && xhdpi.rename(movePath + "xhdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xxhdpi" + "/ic_launcher.png") && xxhdpi.rename(movePath + "xxhdpi" + "/ic_launcher.png");
QFile::remove(movePath + "xxxhdpi" + "/ic_launcher.png") && xxxhdpi.rename(movePath + "xxxhdpi" + "/ic_launcher.png");
}

void AndroidProjectModifier::addSplash(QHash<QString, QString> image)
{
// todo rewrite this
QFile mdpi(resizeImage(image, "320"));
QFile hdpi(resizeImage(image, "480"));
QFile xhdpi(resizeImage(image, "640"));
QFile xxhdpi(resizeImage(image, "960"));
QFile xxxhdpi(resizeImage(image, "1280"));

const auto movePath = m_directory.absolutePath() + "/app/src/main/res/drawable-";

QFile::remove(movePath + "mdpi" + "/splash.png") && mdpi.rename(movePath + "mdpi" + "/splash.png");
QFile::remove(movePath + "hdpi" + "/splash.png") && hdpi.rename(movePath + "hdpi" + "/splash.png");
QFile::remove(movePath + "xhdpi" + "/splash.png") && xhdpi.rename(movePath + "xhdpi" + "/splash.png");
QFile::remove(movePath + "xxhdpi" + "/splash.png") && xxhdpi.rename(movePath + "xxhdpi" + "/splash.png");
QFile::remove(movePath + "xxxhdpi" + "/splash.png") && xxxhdpi.rename(movePath + "xxxhdpi" + "/splash.png");
}
2 changes: 2 additions & 0 deletions androidprojectmodifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class AndroidProjectModifier
QString downloadImage(const QString url);
QString randomString(int length = 15);
QString resizeImage(const QHash<QString, QString> imageData, QString size);
void addIcons(QHash<QString, QString> image);
void addSplash(QHash<QString, QString> image);

QDir m_directory;
};
Expand Down
5 changes: 5 additions & 0 deletions inputoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ void InputOutput::write(QString text)
std::cout << text.toStdString();
}

void InputOutput::writeError(QString text)
{
qWarning("%s", text.toStdString().c_str());
}

void InputOutput::writeln(QString text)
{
write(text + "\n");
Expand Down
3 changes: 1 addition & 2 deletions inputoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ class InputOutput
InputOutput();

void write(QString text);
void writeError(QString text);
void writeln(QString text);
//QString readStdin();
//QString ask(QString question);
};

#endif // INPUTOUTPUT_H
12 changes: 7 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ int main(int argc, char *argv[])
try {
QCoreApplication app(argc, argv);

if(app.arguments().count() < 4) {
qCritical() << "Wrong input, usage: pwa-to-twa androidPackageName pwaUrl outputPath [--manifest path-to-manifest]";
qCritical() << "Example: pwa-to-twa com.vendor.pwa https://pwa.vendor.com ./my-cool-pwa";
qCritical() << "Example: pwa-to-twa com.vendor.pwa https://pwa.vendor.com ./my-cool-pwa --manifest relative/path/to/manifest";
return 1;
if(app.arguments().count() < 4 || app.arguments().contains("--help")) {
const QString binaryName = app.arguments().at(0);

io.writeError("Usage: " + binaryName + " androidPackageName pwaUrl outputPath [--manifest path-to-manifest]");
io.writeError("Example: " + binaryName + " com.vendor.pwa https://pwa.vendor.com ./my-cool-pwa");
io.writeError("Example: " + binaryName + " com.vendor.pwa https://pwa.vendor.com ./my-cool-pwa --manifest relative/path/to/manifest");
return app.arguments().contains("--help") ? 0 : 1;
}

QString manifestPath;
Expand Down

0 comments on commit 0690d7e

Please sign in to comment.