view class
に設定したいカスタムがありactivity
ます。ただし、開始には非常に時間がかかります (ビットマップのロードなど、ほとんどのコードはコンストラクターに配置されます)。したがって、を設定する前にプリローダーをユーザーに表示したいと思いますView
。
最初に読み込み画面を設定し、view
asynctask とハンドラーを使用して別のスレッドで起動しようとしましたが、うまくいきませんでした。1 つ目は私can't create handler inside thread that has not called looper.prepare()
に与えられ、もう 1 つはコードを 1 行ずつ実行するだけです。
たぶん、私は何か間違ったことをしているのかもしれません.ロードプロセスを分割する方法はありますかloading screen
? 2. バックグラウンドでロードview class
(インスタンス化)。3. のview class
代わりに を設定しloading screen
ます。
ありがとう
アップデート
public MainMenuView(Context context) {
super(context);
System.gc();
this.context = context;
sh = new SharedHelper(context);
am = context.getAssets();
sp = new SoundHelper(context,
SoundHelper.CLICK,
SoundHelper.MAIN_MELODY
);
screenWH = Helper.getScreenDimensions(context);
bg = new Background(screenWH, am);
scaleAmount = bg.scaleAmount();
scaleAmount = scaleAmount * 0.9f;
strings = Helper.getStrings((int)sh.getOption(Option.LANGUAGE), new DBHelper(context));
mainTitle = Helper.scaleBMP(Helper.assetImage(am, "Main/title.png"), scaleAmount);
mainTitleM.postTranslate(bg.getMargins()[0], -10);
/**
* Load cloud-like buttons
* */
float top = 0.03f * screenWH[1];
float left = bg.getMargins()[0] + mainTitle.getWidth();
MainButton repeat = new MainButton("Main/Buttons/repeat_on.png", "Main/Buttons/repeat.png", am, scaleAmount);
repeat.setPosition(left, top);
repeat.setType(Helper.REPEAT);
btns.add(repeat);
left += 0.3f * repeat.getBMP().getWidth();
top += repeat.getBMP().getHeight();
MainButton test = new MainButton("Main/Buttons/test_on.png", "Main/Buttons/test.png", am, scaleAmount);
test.setPosition(left, top);
test.setType(Helper.TEST);
btns.add(test);
left -= 0.7f * test.getBMP().getWidth();
top += 0.5f * test.getBMP().getHeight();
MainButton learn = new MainButton("Main/Buttons/learn_on.png", "Main/Buttons/learn.png", am, scaleAmount);
learn.setPosition(left, top);
learn.setType(Helper.LEARN);
btns.add(learn);
/**
* Main control buttons
* */
left = 5;
top = bg.getTopMargin();
buttonClass parent = new buttonClass("Buttons/parents control.png", am, scaleAmount, Helper.PARENTS);
parent.setPosition(left, top);
btns.add(parent);
top += parent.getBMP().getHeight() + 2;
buttonClass facebook = new buttonClass("Buttons/facebook.png", am, scaleAmount, Helper.FACEBOOK);
facebook.setPosition(left, top);
btns.add(facebook);
top += facebook.getBMP().getHeight() + 2;
buttonClass share = new buttonClass("Buttons/share.png", am, scaleAmount, Helper.SHARE);
share.setPosition(left, top);
btns.add(share);
top += share.getBMP().getHeight() + 2;
buttonClass pay = new buttonClass("Buttons/pay.png", am, scaleAmount, Helper.PAY);
pay.setPosition(left, top);
btns.add(pay);
/**
* Sprites
* */
float widthsix = 0;
float widthasix = 0;
float highest = 0;
for(int i=1; i<=11; i++){
mainSprite spr = new mainSprite(i, context, scaleAmount);
if(i <= 6){
widthsix += spr.getBMP().getWidth();
}
else{
widthasix += spr.getBMP().getWidth();
}
if(i == 9){
highest = spr.getBMP().getHeight();
}
sprites.add(spr);
}
float[] margins = bg.getMargins();
left = margins[0] + (margins[2] - margins[0] - widthsix) / 2;
float leftA = margins[0] + (margins[2] - margins[0] - widthasix) / 2;
top = screenWH[1] - highest;
float angle = 0;
float offset = 0.05f * screenWH[1];
float angle_step = 30.0f;
int i = 1;
float topA = 0;
for(mainSprite s : sprites){
float top_mod = top - s.getBMP().getHeight() + (float)Math.sin(Math.toRadians(angle)) * offset - offset;
s.setPosition(left, top_mod);
left += s.getBMP().getWidth();
angle += angle_step;
if(i == 3){
topA = screenWH[1];
}
if(i == 6){
top = topA;
left = leftA;
angle_step = 36f;
angle = 0;
}
i++;
}
sp.playSound(SoundHelper.MAIN_MELODY);
addDialog();
/**
* start animation
* */
currentSpr = 8;
sprites.get(currentSpr).start();
handle.postDelayed(runAnimation, 5000);
}
public void loadMain(){
screenWH = Helper.getScreenDimensions(context);
bg = new Background(screenWH, am);
scaleAmount = bg.scaleAmount();
scaleAmount = scaleAmount * 0.9f;
strings = Helper.getStrings((int)sh.getOption(Option.LANGUAGE), new DBHelper(context));
mainTitle = Helper.scaleBMP(Helper.assetImage(am, "Main/title.png"), scaleAmount);
mainTitleM.postTranslate(bg.getMargins()[0], -10);
/**
* Load cloud-like buttons
* */
float top = 0.03f * screenWH[1];
float left = bg.getMargins()[0] + mainTitle.getWidth();
MainButton repeat = new MainButton("Main/Buttons/repeat_on.png", "Main/Buttons/repeat.png", am, scaleAmount);
repeat.setPosition(left, top);
repeat.setType(Helper.REPEAT);
btns.add(repeat);
left += 0.3f * repeat.getBMP().getWidth();
top += repeat.getBMP().getHeight();
MainButton test = new MainButton("Main/Buttons/test_on.png", "Main/Buttons/test.png", am, scaleAmount);
test.setPosition(left, top);
test.setType(Helper.TEST);
btns.add(test);
left -= 0.7f * test.getBMP().getWidth();
top += 0.5f * test.getBMP().getHeight();
MainButton learn = new MainButton("Main/Buttons/learn_on.png", "Main/Buttons/learn.png", am, scaleAmount);
learn.setPosition(left, top);
learn.setType(Helper.LEARN);
btns.add(learn);
/**
* Main control buttons
* */
left = 5;
top = bg.getTopMargin();
buttonClass parent = new buttonClass("Buttons/parents control.png", am, scaleAmount, Helper.PARENTS);
parent.setPosition(left, top);
btns.add(parent);
top += parent.getBMP().getHeight() + 2;
buttonClass facebook = new buttonClass("Buttons/facebook.png", am, scaleAmount, Helper.FACEBOOK);
facebook.setPosition(left, top);
btns.add(facebook);
top += facebook.getBMP().getHeight() + 2;
buttonClass share = new buttonClass("Buttons/share.png", am, scaleAmount, Helper.SHARE);
share.setPosition(left, top);
btns.add(share);
top += share.getBMP().getHeight() + 2;
buttonClass pay = new buttonClass("Buttons/pay.png", am, scaleAmount, Helper.PAY);
pay.setPosition(left, top);
btns.add(pay);
/**
* Sprites
* */
float widthsix = 0;
float widthasix = 0;
float highest = 0;
for(int i=1; i<=11; i++){
mainSprite spr = new mainSprite(i, context, scaleAmount);
if(i <= 6){
widthsix += spr.getBMP().getWidth();
}
else{
widthasix += spr.getBMP().getWidth();
}
if(i == 9){
highest = spr.getBMP().getHeight();
}
sprites.add(spr);
}
float[] margins = bg.getMargins();
left = margins[0] + (margins[2] - margins[0] - widthsix) / 2;
float leftA = margins[0] + (margins[2] - margins[0] - widthasix) / 2;
top = screenWH[1] - highest;
float angle = 0;
float offset = 0.05f * screenWH[1];
float angle_step = 30.0f;
int i = 1;
float topA = 0;
for(mainSprite s : sprites){
float top_mod = top - s.getBMP().getHeight() + (float)Math.sin(Math.toRadians(angle)) * offset - offset;
s.setPosition(left, top_mod);
left += s.getBMP().getWidth();
angle += angle_step;
if(i == 3){
topA = screenWH[1];
}
if(i == 6){
top = topA;
left = leftA;
angle_step = 36f;
angle = 0;
}
i++;
}
sp.playSound(SoundHelper.MAIN_MELODY);
addDialog();
/**
* start animation
* */
currentSpr = 8;
sprites.get(currentSpr).start();
//handle.postDelayed(runAnimation, 5000);
}
Activity の onCreate メソッドでビューを読み込んでいます
new Handler().post(new Runnable(){
@Override
public void run(){
setContentView(new CustomView(context));
}
});