codename1 localization don't work - java

I have made a new resourcebundle in the theme.res. I have 2 languages (en, da).
I've written this code:
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
String lang = L10NManager.getInstance().getLanguage();
try {
if (lang != null) {
lang = lang.toLowerCase();
switch (lang) {
case "da":
Map<String, String> localMap = theme.getL10N("local", "da");
UIManager.createInstance().setBundle(localMap);
System.out.println("Entries: " + localMap.size());
break;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When I run the code it does get the bundle and the localMap does keep the 'da' landuage entries as it should.
But nothing happens. The GUI texts are just the keys.
Is there something I miss here?

This is wrong:
UIManager.createInstance().setBundle(localMap);
You should have used:
UIManager.getInstance().setBundle(localMap);

Related

Mismatch of return datatype

i am facing a problem regrading specifying the return data type. I have the FOComp class which implements callabale, the call() method of the 'FOComp' returns data type List<ArrayList<Mat>> as shown in the code of 'FOComp' class below.
and the method 'getResults()' returns data of type ArrayList<Mat> as shown in the code below. and currently, at run time, when I execute the code, I receive the folowing error:
Multiple markers at this line
The return type is incompatible with Callable<ArrayList<Mat>>.call()
The return type is incompatible with Callable<List<Mat>>.call()
kindly please let me know how to fix it.
'FOComp' class:
static class FOComp implements Callable<List<Mat>> {//should return list contains 4 mats(0,45,90,135)
private ArrayList<Mat> gaussianMatList = null;
private List<ArrayList<Mat>> results_4OrientAngles_List = null;
public FOComp(ArrayList<Mat> gaussianMatList) {
// TODO Auto-generated constructor stub
this.gaussianMatList = gaussianMatList;
this.results_4OrientAngles_List = new ArrayList<ArrayList<Mat>>();
}
public List<ArrayList<Mat>> call() throws Exception {
// TODO Auto-generated method stub
try {
featOrient = new FeatOrientation(this.gaussianMatList);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
featOrient.start();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.results_4OrientAngles_List.add(featOrient.getResults());
return results_4OrientAngles_List;
}
}
'getResults':
public ArrayList<Mat> getResults() {
if (this.crossAddOrientMapsList != null) {
if (!this.crossAddOrientMapsList.isEmpty()) {
if (this.crossAddOrientMapsList.size() == 4) {
double[] theta = new double[4];
theta[0] = 0;
theta[1] = 45;
theta[2] = 90;
theta[3] = 135;
for (int i = 0; i < this.crossAddOrientMapsList.size(); i++) {
MatFactory.writeMat(FilePathUtils.newOutputPath("FinalCrossAdd_" + theta[i]+"_degs"), this.crossAddOrientMapsList.get(i));
//ImageUtils.showMat(this.crossAddOrientMapsList.get(i), "OrientMap_" + theta[i] + " degs");
}
return this.crossAddOrientMapsList;
} else {
Log.WTF(TAG, "getResults", "crossAddOrientMapsList != 4 !!");
return null;
}
} else {
Log.E(TAG, "getResults", "crossAddOrientMapsList is empty.");
return null;
}
} else {
Log.E(TAG, "getResults", "crossAddOrientMapsList is null");
return null;
}
}
class FOComp implements Callable<List<Mat>>
and
public List<ArrayList<Mat>> call()
aren't really compatible... Your call() method should be
#Override public List<Mat> call()
Also, it is good practice to avoid implementation classes in method signatures, use the interfaces instead (in this case, use List rather than ArrayList). That will also fix your problem with one of the "multiple markers" :-)
Cheers,
You class declaration says that you are going to return a List of Mat (FOComp implements Callable<List<Mat>>), but your call method signature says you are going to return a List of ArrayList of Mat (List<ArrayList<Mat>>).
You will need to make them consistent.

How can I ignore specifically annotated classes under TestNG?

Goal: Ignore test classes on runtime which have custom annotation set.
What I tried:
public void onStart(ITestContext context) {
if (context instanceof TestRunner) {
Map<Class<?>, ITestClass> notSkippedCl = new HashMap<Class<?>, ITestClass>();
TestRunner tRunner = (TestRunner) context;
Collection<ITestClass> testClasses = tRunner.getTestClasses();
for (Iterator<ITestClass> iterator = testClasses.iterator(); iterator.hasNext();) {
ITestClass rr = iterator.next();
Class<?> realClass = rr.getRealClass();
if (chechAnnotation(realClass))
{
notSkippedCl.put(realClass,rr);
}
}
try {
Field field = TestRunner.class.getDeclaredField("m_classMap");
field.setAccessible(true);
Map<Class<?>, ITestClass> mapClass = (Map<Class<?>, ITestClass>) field.get(tRunner);
mapClass.clear();
mapClass.putAll(notSkippedCl);
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
onStart method is called before all test classes in package, So I get TestRunner here, which contains map of all test classes. I iterate throw each one, checking it Annotation and if I find one I add to new map. Then I override map of TestRunner. I was thinking that this will help me ignore classes without annotation, but I was wrong.
Maybe someone knows right solution, to Ignore test classes depending on custom annotation?
(parameter of the method cannot be changed)
P.S. setting #Test(enabled=false) annotation is not a solution in my situation
--EDIT_FAUND_SOLUTION--
I managed to create solution, not sure if there was easier way, but this works:
#Override
public void onStart(ITestContext context) {
if (context instanceof TestRunner) {
Set<ITestNGMethod> methodstodo = new HashSet<ITestNGMethod>();
TestRunner tRunner = (TestRunner) context;
ITestNGMethod[] allTestMethods = tRunner.getAllTestMethods();
SupportedBrowser currentBrowser = HelperMethod.getCurrentBrowser();
for(ITestNGMethod testMethod : allTestMethods)
{
Class<?> realClass = testMethod.getTestClass().getRealClass();
Set<SupportedBrowser> classBrowsers = getBrowsers(realClass);
if (classBrowsers.contains(currentBrowser)) {
methodstodo.add(testMethod);
}
}
try {
Field field = TestRunner.class.getDeclaredField("m_allTestMethods");
field.setAccessible(true);
field.set(tRunner, methodstodo.toArray(new ITestNGMethod[methodstodo.size()]));
} catch (Exception e) {
e.printStackTrace();
}
}
}
I'd recommend to create org.testng.IMethodInterceptor as a Listener. TestNG calls intercept method just before test suite starts. You get list of all methods as a parameter and have to return modified/new/etc. list with methods you want to run. See documentation http://testng.org/doc/documentation-main.html#methodinterceptors for more details and examples.

NoSuchMethodException loading Build.getRadioVersion() using reflection

I'm trying to load the radio version of the Android device using reflection. I need to do this because my SDK supports back to API 7, but Build.RADIO was added in API 8, and Build.getRadioVersion() was added in API 14.
// This line executes fine, but is deprecated in API 14
String radioVersion = Build.RADIO;
// This line executes fine, but is deprecated in API 14
String radioVersion = (String) Build.class.getField("RADIO").get(null);
// This line executes fine.
String radioVersion = Build.getRadioVersion();
// This line throws a MethodNotFoundException.
Method method = Build.class.getMethod("getRadioVersion", String.class);
// The rest of the attempt to call getRadioVersion().
String radioVersion = method.invoke(null).toString();
I'm probably doing something wrong here. Any ideas?
Try this:
try {
Method getRadioVersion = Build.class.getMethod("getRadioVersion");
if (getRadioVersion != null) {
try {
String version = (String) getRadioVersion.invoke(Build.class);
// Add your implementation here
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
Log.wtf(TAG, "getMethod returned null");
}
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
What Build.getRadioVersion() actually does is return the value of gsm.version.baseband system property. Check Build and TelephonyProperties sources:
static final String PROPERTY_BASEBAND_VERSION = "gsm.version.baseband";
public static String getRadioVersion() {
return SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, null);
}
According to AndroidXref this property is available even in API 4. Thus you may get it on any version of Android through SystemProperties using the reflection:
public static String getRadioVersion() {
return getSystemProperty("gsm.version.baseband");
}
// reflection helper methods
static String getSystemProperty(String propName) {
Class<?> clsSystemProperties = tryClassForName("android.os.SystemProperties");
Method mtdGet = tryGetMethod(clsSystemProperties, "get", String.class);
return tryInvoke(mtdGet, null, propName);
}
static Class<?> tryClassForName(String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
return null;
}
}
static Method tryGetMethod(Class<?> cls, String name, Class<?>... parameterTypes) {
try {
return cls.getDeclaredMethod(name, parameterTypes);
} catch (Exception e) {
return null;
}
}
static <T> T tryInvoke(Method m, Object object, Object... args) {
try {
return (T) m.invoke(object, args);
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getTargetException());
} catch (Exception e) {
return null;
}
}

Loading Sounds With LWJGL and Slick-Util

I'm creating a basic game, and I can load images fine. Now, I'm trying to load sounds but I keep getting NullPointerExceptions. I'm 100% sure the path is correct, I've tried loading more then one sounds and I always get this error. I've only been able to use it once.
Here is my sound bank:
public class SoundBank {
public static Audio oggEffect;
public SoundBank () {
try {
oggEffect = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("Res/ping_pong_8bit_plop.ogg"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
And my execution code:
else if (Keyboard.isKeyDown(Keyboard.KEY_8)) {
SoundBank.oggEffect.playAsSoundEffect(1.0f, 1.0f, true);
}
I'm pretty sure it should be
/res/ping_pong...ogg
not
res/ping_pong...ogg
never initialize a static variable through constructor.
Method 1 (this prevent you from having to call new SoundBank(); to init):
public class SoundBank {
public static Audio oggEffect;
static {
try {
oggEffect = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("Res/ping_pong_8bit_plop.ogg"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Method 2 (I have it working like this):
public class SoundUtils {
public static void playSound(String res) {
try {
Audio a = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("res/sfx/" + res + ".ogg"));
a.playAsSoundEffect(1, 1, false);
} catch (IOException e) {
e.printStackTrace();
//You don't need this.
LoggerSys.get().getCurrentLogger().log("wtf i haz dun err0rz (" + e.toString() + ")");
}
}
}
EDIT: Oh, and make sure the path is correct (Res/... instead of res/... etc.)

Getting SVN Log of a particular Date Range in Java

I am trying to get the log from a SVN repo using SVNKit.
public static void svnLogTest() {
final SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
final SvnLog log = svnOperationFactory.createLog();
SVNURL url = null;
try {
url = SVNURL
.parseURIEncoded("https://svn-repo");
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.setSingleTarget(SvnTarget.fromURL(url));
log.addRange(SvnRevisionRange.create(SVNRevision.create(111),
SVNRevision.create(222)));
log.getRevisionRanges();
SVNLogEntry logEntry = null;
try {
logEntry = log.run();
System.out.println(logEntry.getAuthor() + " " + logEntry.getRevision() + " "
+ logEntry.getDate());
} catch (SVNException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But it will give me only the first revision, How should I iterate to print the log for a particular date range ?
This is because
log.run();
always returns only one log entry (the same is true for other SvnOperation#run methods). To get all entries use receiver:
log.setReceiver(new ISvnObjectReceiver<SVNLogEntry>() {
#Override
public void receive(SvnTarget target, SVNLogEntry logEntry) throws SVNException {
//process logEntry here
}
});
log.run();

Categories

Resources