mirror of
https://github.com/etlegacy/etlegacy-android.git
synced 2025-04-12 04:00:48 +00:00
java: add splashscreen image to Activity
This commit is contained in:
parent
648a5e2fd4
commit
c29cb91c49
2 changed files with 45 additions and 1 deletions
BIN
app/src/main/assets/etl_splashscreen.png
Normal file
BIN
app/src/main/assets/etl_splashscreen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue