I've created a localization table in my project's res-file using LWUIT Resource editor. But it turns out, that I don't know how to switch through different localizations. How can I set up a global language for my program?
This code can merge two diffrent localizations to one.(the default save in bundle and merge with new localization mergeL10N(these objects are hashTable))
if (themeName != null && !themeName.equals(this.currThemeName)) {
try {
if (themeName.equals(DEFAULT_THEME_NAME)) {
defaultTheme = Resources.open(DEFAULT_THEME_NAME);
bundle = null;
} else {
defaultTheme = Resources.open(DEFAULT_THEME_NAME);
bundle = Resources.open(themeName);
}
mergeL10N = defaultTheme.getL10N("Localization (L10N) 1", "iw");
if (bundle != null) {
mergeHashtable(mergeL10N, bundle.getL10N("Localization (L10N) 1", "iw"));
}
UIManager.getInstance().setResourceBundle(mergeL10N);
}
} catch (Exception e) {
e.printStackTrace();
}
}
You must open your res and use the table that you want to use, here you can find an example
try {
Constants.res = Resources.open("/Lang.res");
} catch (Exception e){
System.err.println("can't load resource file:" + e);
}
Hashtable h = Constants.res.getL10N("English.res","en");
Related
We have 2 cisco phones: one for call manager and another for his superviser.
We need to create a conference when the manager answers and put the supervisor's phone on mute. We are trying to achieve it using JTApi: wait for event TermConnActiveEv, then trying to create conference.
Here is the code sample.
if (callEv instanceof TermConnActiveEv) {
CiscoCall thisCall = (CiscoCall) callEv.getCall();
TerminalConnection connection = ((TermConnActiveEv) callEv).getTerminalConnection();
if (thisCall.getState() != Call.ACTIVE)
{
System.out.println("call is not active");
return;
}
try {
CiscoCall newCall = (CiscoCall) provider.createCall();
newCall.consult(connection);
newCall.conference(thisCall);
....
However, PreConditionException is thrown. What are we doing wrong?
You don't need to use Barge to create a conference.
You can try to do something like that:
if (callEv instanceof TermConnActiveEv) {
CiscoCall thisCall = (CiscoCall) callEv.getCall();
TerminalConnection tc = thisCall.getConferenceController();
Connection[] connections = thisCall.getConnections();
TerminalConnection[] tcs = connections[0].getTerminalConnections();
if (tcs.length > 0 && tc == null) {
tc = tcs[0];
}
if (tc == null) {
System.out.println("Conference controller is null.");
} else {
try {
Call call = provider.createCall();
call.connect(thisAddress.getTerminals()[0], thisAddress, superVisorAddress);
thisCall.conference(call);
} catch (Exception ex) {
System.out.println("Exception " + ex);
ex.printStackTrace();
}
}
}
To set mute you can use:
((CiscoTerminal)termConnections[i].getTerminal().sendData("<CiscoIPPhoneExecute><ExecuteItem Priority=\"0\"URL=\"Key:Mute\"/></CiscoIPPhoneExecute>");
Before the application can make use of this feature, it must add TerminalObserver on the terminal.
My app has main.xml and MainActivity. I wanted to convert it to a tabbed styled app. By the help of this tutorial, I've successfully made a UI with a tabbed style.
Now I have to put the codes in my MainActivty(not tabbed style) to the fragments. i don't know how to do it. when i just put the codes to my ToolsFragment.java, it doesn't work.
Here are my codes:
//To get ip address using netcfg
private String ipnc()
{
int e = doNETCFG().indexOf("10.");
if (e == -1)
{
return "";
}
else
{
String ipnc1 = doNETCFG().substring(e, e + 15);
String ipnc2[] = ipnc1.split("/");
String ipnc3 = ipnc2[0];
return ipnc3;
}
}
//To generate netcfg from command line
public String doNETCFG()
{
String str = null;
try
{
Process localProcess = Runtime.getRuntime().exec("/system/bin/netcfg");
BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
char[] arrayOfChar = new char[4096];
StringBuffer localStringBuffer = new StringBuffer();
while (true)
{
int i = localBufferedReader.read(arrayOfChar);
if (i <= 0)
{
localBufferedReader.close();
localProcess.waitFor();
str = localStringBuffer.toString();
break;
}
localStringBuffer.append(arrayOfChar, 0, i);
}
}
catch (IOException localIOException)
{
Log.e("TAG", localIOException.getStackTrace().toString());
}
catch (InterruptedException localInterruptedException)
{
Log.e("TAG", localInterruptedException.getStackTrace().toString());
}
return str;
}
//To enable/disable mobile data
private void setMobileDataEnabled(Context context, boolean enabled)
{
final ConnectivityManager conman;
conman =
(ConnectivityManager)context.getSystemService
(Context.CONNECTIVITY_SERVICE);
final Class conmanClass;
try
{
conmanClass =
Class.forName(conman.getClass
().getName());
final Field
iConnectivityManagerField =
conmanClass.getDeclaredField
("mService");
iConnectivityManagerField.
setAccessible(true);
final Object
iConnectivityManager =
iConnectivityManagerField.get
(conman);
final Class
iConnectivityManagerClass =
Class.forName
(iConnectivityManager.getClass
().getName());
final Method
setMobileDataEnabledMethod =
iConnectivityManagerClass.
getDeclaredMethod
("setMobileDataEnabled", Boolean.TYPE);
setMobileDataEnabledMethod.
setAccessible(true);
setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled);
}
catch
(ClassNotFoundException e)
{
e.printStackTrace();
}
catch
(InvocationTargetException e)
{
e.printStackTrace();
}
catch
(NoSuchMethodException e)
{
e.printStackTrace();
}
catch
(IllegalAccessException e)
{
e.printStackTrace();
}
catch
(NoSuchFieldException e)
{
e.printStackTrace();
}
}
//To play success alert tone
public void playAlertTone()
{
new Thread()
{
public void run()
{
int i = 0;
while (true)
{
if (i >= 1)
return;
MediaPlayer localMediaPlayer = MediaPlayer.create(getApplicationContext(), 0x7f040000);
localMediaPlayer.start();
i++;
try
{
Thread.sleep(100 + localMediaPlayer.getDuration());
localMediaPlayer.release();
}
catch (InterruptedException localInterruptedException)
{
}
}
}
}
.start();
}
What should I do? Do I have to put this into another activity and call it in fragment? If that's the case, how?
Or convert it to a code executable in fragments and run it there? How can I do this?
I'm a newbie in android programming. Thanks!
when you convert an application to fragment based structure, you have to consider one thing that the context is same for all the fragments in an activity. You will get it by calling getActivity(). So save your context first and use it where ever you want the context.
From your question you are developing an application with tabs. So you may have to create fragments as many as the tabs. You can put your code for each tab in the corresponding fragment.
Now to communicate between the fragments the best way is to use callbacks in your parent activity.
A simple tutorial for implementing fragments can be found HERE
The communication between fragments is explained HERE
Fragments do most of the things activities do. The reason why they were introduced (one of the reasons at least) was so you can place the code in them instead of in the activities of your app. If you think this way, you will notice that you will only need a small number of activities.
I am not sure what you mean by "convert it to a code executable in fragments". You can place your code inside your fragments (use methods) and then simply call those methods.
If you are not sure how Fragments work, I would highly recommend reading the documentation.
I hope this gives you an idea of how to get your code to work in fragments.
im working with Java Swing.
Im trying with print method of Jtable...
public void actionPerformed(java.awt.event.ActionEvent ignore) {
MessageFormat header = new MessageFormat("Page {0,number,integer}");
try {
table.print(JTable.PrintMode.FIT_WIDTH, header, null);
} catch (java.awt.print.PrinterException e) {
System.err.format("Cannot print %s%n", e.getMessage());
}
}
To show a printing dialog . Its work fine ..
The printing dialog
But i want to change the text dialog language to Spanish with a Locale class , how can i do it ???
Thanks!
#Diego
I copied your solution here so it can be more easily read.
It was inspire by the old forum entry here: https://forums.oracle.com/thread/1287832
---- Begin ----
Just adding reflection to change the ResourceBlunde before Jtable.print() method...
try {
Class cl = Class.forName("sun.print.ServiceDialog");
if (cl != null) {
Field fld = cl.getDeclaredField("messageRB");
if (fld != null) {
fld.setAccessible(true);
fld.set(cl, ResourceBundle.getBundle("sun.print.resources.serviceui_es"));
}
}
} catch (Exception ex11) {
ex11.printStackTrace();
}
---- End ----
I may want to search and find it someday.
Im using an EM clusterer with an AddCluster Filter in order to see what instances are getting assigned to the different clusters after training. Below is the code that I'm using. I'm faily sure that I am applying the filter correctly but once I have the new Instances I still dont know how to get the cluster info from them. Im sure its just a simple getBlah() call but I'm just not locating it. Thanks in advance.
public Cluster()
{
clusterer = new EM();
filter = new AddCluster();
try
{
clusterer.setMaxIterations(100);
clusterer.setNumClusters(20);
filter.setClusterer(clusterer);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void buildCluster(String fileName)
{
try
{
DataSource source = new DataSource(fileName);
inst = source.getDataSet();
filter.setInputFormat(inst);
inst = AddCluster.useFilter(inst, filter);
}
catch (Exception e)
{
e.printStackTrace();
}
}
I think you should use "Dictionary" Class. Here is my example code:
Enumeration clusteredInst = data_to_use.enumerateInstances();<br>
Dictionary<Integer, ArrayList<Instance>> clusteredSamples = new ashtable<>();
while (clusteredInst.hasMoreElements()) {<br>
Instance ins = (Instance) clusteredInst.nextElement();<br>
int clusterNumb = em.clusterInstance(ins);<br>
ArrayList<Instance> cls = null;<br>
cls = clusteredSamples.get(clusterNumb);<br>
if (cls != null) {<br>
cls.add(ins);<br>
} else {<br>
cls = new ArrayList<>();<br>
cls.add(ins);<br>
//you add elements to dictionary using put method<br>
//put(key, value)<br>
clusteredSamples.put(clusterNumb, cls);<br>
}
}
And you also can retrieval your data from dictionary by call it's Key.
I'm having problem when taking a picture using VideoControl.getSnapshot() method. It always throw the exception: getSnapshot not Supported. I'm using JRE 5.0.0 with Eclipse and BlackBerry® Java® SDK 5.0 Plugin.
What I do first is to list the encoding supported by Blackberry SmartPhone selected (bold 9700) with the command System.getProperty("video.snapshot.encodings") and select one encoding from the list and pass it as the getSnapshot argument.
I've tested on several Blackberry and the same exception is thrown.
Part of the code:
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.realize();
mPlayer = Manager.createPlayer("capture://video?encoding=video/3gpp");
mPlayer.start();
videoControl = (VideoControl)mPlayer.getControl("VideoControl");
Field cameraView = (Field) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
Thread.sleep(1000);
UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
byte[] snapShot = videoControl.getSnapshot("encoding=jpeg&width=480&height=360&quality=superfine");
Bitmap image = Bitmap.createBitmapFromBytes(snapShot, 0, snapShot.length, 1);
UiApplication.getUiApplication().pushScreen(new TempScreen(image));
}catch (MediaException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("Exception: " + e.getMessage())); }
catch (IOException e){
UiApplication.getUiApplication().pushScreen(new TempScreen("IO Exception: " + e.getMessage()));
}
catch (InterruptedException e){UiApplication.getUiApplication().pushScreen(new TempScreen("Interrupted Exception: "+ e.getMessage()));}
Not sure is my answer is actual after more than a half of year, but may be it will be useful.
You may try to use Thread.sleep(1000); before getSnapshot() call.
The problem may be related with that fact: "viewfinder must actually be visible on the screen prior to calling getSnapShot()."
So if you call getSnapshot immediately after UiApplication.getUiApplication().pushScreen(new TempScreen(cameraView));
the camera isn't prepared for the next shot.
Also are you really sure that getSnapshot() API is supported exactly on your device? Some manufacturers may not support it, despite the API defines this method. Did you run System.getProperty("video.snapshot.encodings") exactly on the same device where you test getSnapshot()?
Player _p;
VideoControl _vc ;
RecordControl _rc ;
String PATH;
FileConnection fileconn;
Object canvas= new Object();
public static boolean SdcardAvailabulity() {
String root = null;
Enumeration e = FileSystemRegistry.listRoots();
while (e.hasMoreElements()) {
root = (String) e.nextElement();
if( root.equalsIgnoreCase("sdcard/") ) {
return true;
}else if( root.equalsIgnoreCase("store/") ) {
return false;
}
}
class MySDListener implements FileSystemListener {
public void rootChanged(int state, String rootName) {
if( state == ROOT_ADDED ) {
if( rootName.equalsIgnoreCase("sdcard/") ) {
}
} else if( state == ROOT_REMOVED ) {
}
}
}
return true;
}
protected boolean invokeAction(int action){
boolean handled = super.invokeAction(action);
if(SdcardAvailabulity()){
PATH = System.getProperty("fileconn.dir.memorycard.videos")+"Video_"+System.currentTimeMillis()+".3gpp";//here "str" having the current Date and Time;
} else {
PATH = System.getProperty("fileconn.dir.videos")+"Video_"+System.currentTimeMillis()+".3gpp";
}
if(!handled){
if(action == ACTION_INVOKE){
try{
if(_p!=null)
_p.close();
}catch(Exception e){
}
}
}
return handled;
}
public MyScreen(){
setTitle("Video recording demo");
ButtonField AddPhoto = new ButtonField("push",ButtonField.FOCUSABLE | ButtonField.FIELD_HCENTER | ButtonField.FIELD_VCENTER | DrawStyle.HCENTER | ButtonField.NEVER_DIRTY | Field.USE_ALL_WIDTH);
FieldChangeListener PhotoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField Button = (ButtonField) field;
if (Button.getLabel().equals("push")){
}
}
};
AddPhoto.setChangeListener(PhotoListener);
add(AddPhoto);
}
}