Android : Blank screen on splash screen load

on Monday, November 3, 2014


I'm having real trouble trying to work out why this is hanging on a white screen. I could understand more if it setContentView went through and it was hanging on the splash but I really am lost as to why it doesnt even get there. Any help with why it is doing this would be greatly appreciated.



package com.example.cthulhu.ordabankiforandroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;


import org.json.JSONException;

public class SplashActivity extends Activity implements OnDictionariesObtainedListener, OnLanguagesObtainedListener {

public String[][] localisedLangs;
public String[][] localisedDicts;
private boolean dObtained;
private boolean lObtained;
private boolean error;
long startTime;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
startTime = System.currentTimeMillis();
isLocaleSet();
dObtained = false;
lObtained = false;
error =false;
getLocalisedLangs();
getLocalisedDicts();
checkTiming();

}
private void isLocaleSet(){
final LocaleSettings localeSettings = new LocaleSettings(this);
//if no language set in locale go to select language
if (!localeSettings.getLocaleStatus()) {
Intent intent = new Intent(SplashActivity.this, SelectLanguageActivity.class);
SplashActivity.this.startActivity(intent);
SplashActivity.this.finish();
}
}

private void getLocalisedLangs(){
//calls rest client to populate languages array
final String langURL = "http://api.arnastofnun.is/ordabanki.php?list=dicts&agent=ordabankaapp";
LanguageJsonHandler lJsonHandler = new LanguageJsonHandler(this);
OrdabankiRestClientUsage langClient = new OrdabankiRestClientUsage();
try {
//Toast.makeText(getApplicationContext(), "getting languages", Toast.LENGTH_SHORT).show();
langClient.getLanguages(langURL, lJsonHandler);
} catch (JSONException e) {
e.printStackTrace();
}
}
private void getLocalisedDicts(){
//calls rest client to populate dictionaries array
final String dictURL = "http://api.arnastofnun.is/ordabanki.php?list=langs&agent=ordabankaapp";
DictionaryJsonHandler dJsonHandler = new DictionaryJsonHandler(this);
OrdabankiRestClientUsage dictClient = new OrdabankiRestClientUsage();
try {
//Toast.makeText(getApplicationContext(), "getting dictionaries", Toast.LENGTH_SHORT).show();
dictClient.getDictionaries(dictURL, dJsonHandler);
} catch (JSONException e) {
e.printStackTrace();
}
}
private void checkTiming(){
//checks if splash screen has been up for a minimum of 2 seconds then moves to search screen
final LocaleSettings localeSettings = new LocaleSettings(this);
Runnable runnable = new Runnable() {
public void run() {
long endTime = startTime+2000;
while (System.currentTimeMillis() < endTime) {
synchronized (this) {
try {
Thread.sleep(endTime-System.currentTimeMillis());
} catch (Exception e) {e.printStackTrace();}
}
}
//Toast.makeText(getApplicationContext(), "setting locale", Toast.LENGTH_SHORT).show();
localeSettings.setLanguageFromPref(SearchScreen.class);
}
};
Thread timingThread = new Thread(runnable);

while(!error) {
if (dObtained && lObtained) {
//Toast.makeText(getApplicationContext(), "timing thread start", Toast.LENGTH_SHORT).show();
timingThread.start();
}
}
}
@Override
public void onDictionariesObtained (Dictionary[]dictionaries){
localisedDicts = new String[dictionaries.length][2];
int index = 0;
//Toast.makeText(getApplicationContext(), "dLoop", Toast.LENGTH_SHORT).show();
for (Dictionary dict : dictionaries) {
localisedDicts[index][1] = dict.getDictCode();
localisedDicts[index][2] = dict.getDictName();
index++;
}
dObtained=true;
}
@Override
public void onDictionariesFailure ( int statusCode){
error = true;
Toast.makeText(getApplicationContext(), "dictionary error", Toast.LENGTH_SHORT).show();
//todo handle failure: error message, restart quit options
}
@Override
public void onLanguagesObtained (Language[]languages){
localisedLangs = new String[languages.length][2];
int index = 0;
for (Language lang : languages) {
localisedDicts[index][1] = lang.getLangCode();
localisedDicts[index][2] = lang.getLangName();
index++;
}
lObtained=true;
}
@Override
public void onLanguagesFailure (int statusCode){
error= true;
Toast.makeText(getApplicationContext(), "languages error", Toast.LENGTH_SHORT).show();
//todo handle failure: error message, restart quit options
}


}

0 comments:

Post a Comment