How to show text in blackberry in other languages? - blackberry

I want to show malayalam script in my application in blackberry 5.0.i tried with following code. but it shows text in english only.
try {
alphaSerifFamily = FontFamily.forName("BBAlpha Serif");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Font appFont = alphaSerifFamily.getFont(Font.MALAYALAM_SCRIPT, 9, Ui.UNITS_pt);
setFont(appFont);

Check the following links:
http://yamspog.wordpress.com/2009/08/30/how-to-use-resource-files-in-your-blackberry-app/
http://docs.blackberry.com/en/developers/deliverables/12002/Create_resource_file_for_BlackBerry_Application_655978_11.jsp
When done with creating the ressource files, use the following code to retrieve the KEY value:
public static ResourceBundle _res = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
_res.getString(yourKey)

Related

Mime Type detection of Office files is resulting in application/x-tika-ooxml

I am trying to detect the mime types of the file input stream.
I just have tika core in my classpath. I am using 2.0.0 version.
However for a docx file "application/x-tika-ooxml" is always detected. Office file detection is always resulting in x-tika-ooxml.
I tried wrapping the input stream in TikaInputStream also but the same result.
Below is my code
public class TikaTester {
public static void main (String a[]) {
try {
FileInputStream stream = new FileInputStream("/Users/<>/Downloads/Test DMS.docx");
detectMimeType(stream);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void detectMimeType(InputStream stream) {
Tika tika = new Tika();
try {
String mimeType = tika.detect(stream);
System.out.println("Mime type detected " + mimeType);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This works if i add tika-parsers in the classpath and with TikaInputStream needs to be used.
May be tika core does not have the parser for office files.

add webview links to favorites

I am developing News app which shows over 50 News sites in webview and users can open links and read the news. I want to save some news as headlines or their links and show them in favourite page. and in favourite page can be clicked and deleted after reading it.
I worked on an thought with long press on page write link to a file and then read the file and make list of favorites. I tested with text view and writing file seems OK but reading it does not. my codes are:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myInflater= inflater.inflate(R.layout.fragment_main, container, false);
TextView txtView = (TextView) myInflater.findViewById(R.id.txtView);
txtView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(),
"You have pressed it long :)", Toast.LENGTH_LONG).show();
String filename ="favoritessss.txt";
File file = new File(getActivity().getFilesDir(), filename);
File directory = getActivity().getDir("SunShine", Context.MODE_WORLD_READABLE);
//String filename = "myfile";
String string = "Hello world000000000!"+"\r\n";
FileOutputStream outputStream;
try {
outputStream = getActivity().openFileOutput(filename, Context.MODE_WORLD_WRITEABLE);
outputStream.write(string.getBytes());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
});
//Find the view by its id
final TextView tv = (TextView)myInflater.findViewById(R.id.text_view);
txtView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Find the directory for the SD Card using the API
//Don't hardcode "/sdcard"
File sdcard = getActivity().getFilesDir();
//Get the text file
File file = new File(sdcard,"favoritessss.txt");
String[] text = new String[15];
try {
BufferedReader br = new BufferedReader(new FileReader(file));
for (int j=0; j>15; j++) text[j] = br.readLine();
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Set the text
tv.setText(text[0]);
Toast.makeText(getActivity(), text[0],
Toast.LENGTH_SHORT).show();
}
});
return myInflater;
}
any comments?

using custom fonts on blackberry application

I'm developing a BB app where I need to use some custom fonts. I was trying to load them as "statics"
public class MyFontTool
{
public static FontFamily fontSolanoGothicMVBLt = Font.getDefault().getFontFamily();
try {
if (FontManager.getInstance().load("font/SolanoGothicMVB-Lt.ttf",
"SolanoGothicMVB-Lt", FontManager.APPLICATION_FONT) == FontManager.SUCCESS) {
fontSolanoGothicMVBLt = FontFamily
.forName("SolanoGothicMVB-Lt");
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
not sure if this is possible but when I run the application I got this message:
Error Starting ... : Class 'net.rim.device.api.ui.FontManager' not found.
I'm using Blackberry SDK 5.0
Any idea why this doesn't work?

how to creat a hyperlink url string in a Java MessageDialog?

a simple MessageDialog(or MessageBox,any method can open a dialog )like follows:
MessageDialog.openInformation(shell, "Test", "Get help form this link www.google.com");
is there any way to make www.google.com a hyperlink? click the url and open browser.
thats not possible out of the box. I created a class of my own, named MyMessageDialog to do this:
https://gist.github.com/andydunkel/8914008
Its basically all the source code from MessageDialog. Then I overwrote the createMessageArea method and added a Link instead of a label and added an event listener:
protected Control createMessageArea(Composite composite) {
// create composite
// create image
Image image = getImage();
if (image != null) {
imageLabel = new Label(composite, SWT.NULL);
image.setBackground(imageLabel.getBackground());
imageLabel.setImage(image);
//addAccessibleListeners(imageLabel, image);
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING)
.applyTo(imageLabel);
}
// create message
if (message != null) {
linkLabel = new Link(composite, getMessageLabelStyle());
linkLabel.setText(message);
linkLabel.addSelectionListener(new SelectionAdapter(){
#Override
public void widgetSelected(SelectionEvent e) {
System.out.println("You have selected: "+e.text);
try {
// Open default external browser
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(e.text));
}
catch (PartInitException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
catch (MalformedURLException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
}
});
GridDataFactory
.fillDefaults()
.align(SWT.FILL, SWT.BEGINNING)
.grab(true, false)
.hint(
convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH),
SWT.DEFAULT).applyTo(linkLabel);
}
return composite;
}
The MessageDialog can be called with HTML code in it now:
MyMessageDialog.openError(parent.getShell(), "Hehe", "Google.com Test");
Not a very optimal solution, but it works:
Andy

Access Blackberry "Send To" Menu

I'd like access the "Send To" menu, that features all the, apparently registered recipients of that action.
On my phone, this menu contains
* Email
* PIN
* SMS
* MMS
* BBM Contact
How can I do this from Java?
EDIT: For BB OS 4.0+ platforms.
Here's what I've used so far by overriding the getMenu method.
At getAppName() in the simulator, I've been getting values like:
* net_rim_bb_sendusingbluetoothapp
* net_rim_bb_sendasemailapp
* net_rim_bb_sendtomessengercontactapp
So I expect I'll use some String.replace() with that, but when I use the
reg.invoke(inv);
call below, though the mail application starts up, no arguments like subject or message content appears. How should I go about setting that?
Also, for setData(), I just pass in a random string. (I'm pretty sure that's where I should be setting more meaningful stuff, but I don't know what).
public Menu getMenu(int instance) {
Menu menu = super.getMenu(instance);
final Registry reg = Registry.getRegistry(CLASSNAME);
ContentHandler[] handles = reg.forAction(ContentHandler.ACTION_SEND);
for (int i=0;i<handles.length;i++)
{
String name = handles[i].getAppName();
final Invocation inv = new Invocation();
inv.setURL(sendToUrl);
inv.setResponseRequired(false);
inv.setType(handles[i].getType(0));
inv.setID(handles[i].getID());
inv.setData(sendToUrl.getBytes());
inv.setAction(handles[i].getAction(0));
inv.setArgs(new String[]{sendToUrl});
MenuItem mit = new MenuItem(new StringProvider(name), i, i)
{
public void run() {
try {
reg.invoke(inv);
//inv.open(false);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
//ContentHandlerMenu contentHandlerMenu
//= new ContentHandlerMenu(inv, reg, "Send to "+ name, i,i);
//menu.add(contentHandlerMenu);
menu.add(mit);
}
return menu;
}
Is this what you need? Send Menu API. I found it searching in Google... It was not too difficult.

Resources