Merge startInstaller into constructor

This commit is contained in:
Manuel Fuhr 2021-10-19 06:13:37 +02:00
parent dd7a2fcd98
commit 64a80e763b
2 changed files with 29 additions and 39 deletions

View file

@ -36,9 +36,6 @@ public class BInstallerActivity extends Activity {
} }
} }
/**
* Called when the activity is first created.
*/
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -52,7 +49,6 @@ public class BInstallerActivity extends Activity {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// instantiate our simulation view and set it as the activity's content
mBInstallerView = new BInstallerView(this); mBInstallerView = new BInstallerView(this);
setContentView(mBInstallerView); setContentView(mBInstallerView);
} }
@ -72,9 +68,6 @@ public class BInstallerActivity extends Activity {
myReceiver = new DownloadReceiver(); myReceiver = new DownloadReceiver();
registerReceiver(myReceiver, filter); registerReceiver(myReceiver, filter);
// Start the download manager
mBInstallerView.startInstaller();
} }
@Override @Override

View file

@ -35,6 +35,12 @@ public class BInstallerView extends View {
private final int imgh; private final int imgh;
private final float[] testVector = new float[2]; private final float[] testVector = new float[2];
private final Matrix matText; private final Matrix matText;
private final File baseDir;
private final File segmentDir;
private final Matrix mat;
private final Bitmap bmp;
private final float viewscale;
private final int[] tileStatus;
Paint pnt_1 = new Paint(); Paint pnt_1 = new Paint();
Paint pnt_2 = new Paint(); Paint pnt_2 = new Paint();
Paint paint = new Paint(); Paint paint = new Paint();
@ -44,20 +50,14 @@ public class BInstallerView extends View {
float tx, ty; float tx, ty;
private float lastDownX; private float lastDownX;
private float lastDownY; private float lastDownY;
private Bitmap bmp;
private float viewscale;
private int[] tileStatus;
private boolean tilesVisible = false; private boolean tilesVisible = false;
private long availableSize; private long availableSize;
private File baseDir;
private File segmentDir;
private boolean isDownloading = false; private boolean isDownloading = false;
private volatile String currentDownloadOperation = ""; private volatile String currentDownloadOperation = "";
private String downloadAction = ""; private String downloadAction = "";
private long totalSize = 0; private long totalSize = 0;
private long rd5Tiles = 0; private long rd5Tiles = 0;
private long delTiles = 0; private long delTiles = 0;
private Matrix mat;
public BInstallerView(Context context) { public BInstallerView(Context context) {
super(context); super(context);
@ -76,6 +76,29 @@ public class BInstallerView extends View {
imgw = (int) (imgwOrig / scaleOrig); imgw = (int) (imgwOrig / scaleOrig);
imgh = (int) (imghOrig / scaleOrig); imgh = (int) (imghOrig / scaleOrig);
baseDir = ConfigHelper.getBaseDir(getContext());
segmentDir = new File(baseDir, "brouter/segments4");
try {
AssetManager assetManager = getContext().getAssets();
InputStream istr = assetManager.open("world.png");
bmp = BitmapFactory.decodeStream(istr);
istr.close();
} catch (IOException io) {
throw new RuntimeException("cannot read world.png from assets");
}
tileStatus = new int[72 * 36];
scanExistingFiles();
float scaleX = imgwOrig / ((float) bmp.getWidth());
float scaley = imghOrig / ((float) bmp.getHeight());
viewscale = Math.min(scaleX, scaley);
mat = new Matrix();
mat.postScale(viewscale, viewscale);
} }
protected String baseNameForTile(int tileIndex) { protected String baseNameForTile(int tileIndex) {
@ -240,32 +263,6 @@ public class BInstallerView extends View {
} }
} }
public void startInstaller() {
baseDir = ConfigHelper.getBaseDir(getContext());
segmentDir = new File(baseDir, "brouter/segments4");
try {
AssetManager assetManager = getContext().getAssets();
InputStream istr = assetManager.open("world.png");
bmp = BitmapFactory.decodeStream(istr);
istr.close();
} catch (IOException io) {
throw new RuntimeException("cannot read world.png from assets");
}
tileStatus = new int[72 * 36];
scanExistingFiles();
float scaleX = imgwOrig / ((float) bmp.getWidth());
float scaley = imghOrig / ((float) bmp.getHeight());
viewscale = Math.min(scaleX, scaley);
mat = new Matrix();
mat.postScale(viewscale, viewscale);
tilesVisible = false;
}
@Override @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);