java: add splashscreen image to Activity

This commit is contained in:
rafal1137 2020-05-17 02:10:24 +02:00
parent 648a5e2fd4
commit c29cb91c49
2 changed files with 45 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View file

@ -2,9 +2,17 @@ package org.etlegacy.app;
import android.app.Activity;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.google.common.io.Files;
import com.loopj.android.http.AsyncHttpClient;
@ -12,17 +20,53 @@ import com.loopj.android.http.FileAsyncHttpResponseHandler;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import cz.msebera.android.httpclient.Header;
public class ETLMain extends Activity {
private Drawable getBitmapFromAsset(String strName) {
AssetManager assetManager = getAssets();
InputStream istr = null;
try {
istr = assetManager.open(strName);
} catch (IOException e) {
e.printStackTrace();
}
// It somehow looks ugly and expensive, find a better solution
Bitmap bitmap = BitmapFactory.decodeStream(istr);
Drawable etl_drawable = new BitmapDrawable(getResources(), bitmap);
//Bitmap resized = Bitmap.createScaledBitmap(bitmap, 80, 80, true);
return etl_drawable;
}
public static int pxToDp(int px) {
return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
ImageView imageView = new ImageView(this);
imageView.setBackground(getBitmapFromAsset("etl_splashscreen.png"));
LinearLayout etl_Layout = new LinearLayout(this);
RelativeLayout.LayoutParams etl_Params = new RelativeLayout.LayoutParams(
600, 300);
etl_Params.leftMargin = pxToDp(Resources.getSystem().getDisplayMetrics().widthPixels / 2);
etl_Params.topMargin = pxToDp(Resources.getSystem().getDisplayMetrics().heightPixels / 2);
etl_Layout.addView(imageView, etl_Params);
setContentView(etl_Layout);
File etl_pak = new File(getExternalFilesDir(null), "/etlegacy/etmain/pak0.pk3");
final Intent intent = new Intent(ETLMain.this, ETLActivity.class);