Browse Author: smita.kale

How to compress Image in gzip format

Some times the Size of images are too large and in some of the applications images are needed to save on particular server but because off large size it takes lots off time to save into server.If we compress that image into a particular format then we can save some space of server.

Step 1 – Create one Category and add libz.dylib library.

Step 2 – in .h file i.e in interface file mention the list of methods.

here the name of category is GZIP.

@interface NSData (GZIP)

and mention the list of methods.

– (NSData *)gzippedDataWithCompressionLevel:(float)level;

– (NSData *)gzippedData;

and end the interface using

@end

Step 3 – in .m file i.e in implementation file

#import <zlib.h>

#define CHUNK_SIZE 16384

add the implementation of listed methods.

@implementation NSData (GZIP)

– (NSData *)gzippedDataWithCompressionLevel:(float)level{

if ([self length]){

z_stream stream;

stream.zalloc = Z_NULL;

stream.zfree = Z_NULL;

stream.opaque = Z_NULL;

stream.avail_in = (uint)[self length];

stream.next_in = (Bytef *)[self bytes];

stream.total_out = 0;

stream.avail_out = 0;

int compression = (level < 0.0f)? Z_DEFAULT_COMPRESSION: (int)roundf(level * 9);

if (deflateInit2(&stream, compression, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) == Z_OK){

NSMutableData *data = [NSMutableData dataWithLength:CHUNK_SIZE];

while (stream.avail_out == 0){

if (stream.total_out >= [data length]){

data.length += CHUNK_SIZE;

}

stream.next_out = [data mutableBytes] + stream.total_out;

stream.avail_out = (uint)([data length] – stream.total_out);

deflate(&stream, Z_FINISH);

}

deflateEnd(&stream);

data.length = stream.total_out;

return data;

}

}

return nil;

}

– (NSData *)gzippedData{

return [self gzippedDataWithCompressionLevel:-1.0f];

}

@end

Step 4 – import category where we want to compress image

#import “NSData+GZIP.h”

Step 5 – Convert image into NSData

NSData *userFile = UIImageJPEGRepresentation(img, 1.0f);

Step 6 – call the gzippedData method.

NSData *compressedData = [userFile gzippedData];

Now Compressed image is in compressedData variable.

 

Thank You.

Custom Fonts in Blackberry Application

Download the .ttf (True Type Font)file and include it in src folder.

Include this code into the constructor.

EditField edField1 = new EditField (“”, “TestEditField”, 30, EditField.READONLY| EditField.FIELD_VCENTER){
protected void layout(int width, int height)
{
super.layout(customWidth, customHeight);
setExtent(customWidth, customHeight);
}
};

Font fo3 = loadCustomFonts(“digital-7.ttf”, “ThirdFont”, 0, 40);
edField1.setFont(fo3);

 

Include this function.

public Font loadCustomFonts (String path, String fontname,int fontStyle, int fontSize){
InputStream stream = this.getClass().getResourceAsStream(path);
if (FontManager.getInstance().load(stream, fontname,                 FontManager.APPLICATION_FONT) == FontManager.SUCCESS){
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
else {
try{
FontFamily family;
add(new LabelField(“”));
family = FontFamily.forName(fontname);
Font myFont = family.getFont(fontStyle,fontSize);
return myFont;
}
catch (ClassNotFoundException e){System.out.println(e.getMessage());}
}
return null;
}

By Using this we can add custom font into our Application.

thank you.

How to signed Blackberry Application

Code Signing in not required when applications are loaded and tested on a BlackBerry Smartphone Simulator.
Developers order code signing keys from RIM, and receive a set of files that are then installed on their development machine.  The BlackBerry development tools are then able to provide these key files to the BlackBerry Signature Tool when the developer requests that their application be signed.  The BlackBerry Signature applies a unique signature, representing the identity of the developer, to all *.cod files that compose a BlackBerry application.  Developers should not share their code signing keys with others.

As explained below, the complete steps for setting up and using BlackBerry code signing process are:

1.Order Code Signing Keys from RIM

Developers can register there code signing keys online using this link.

https://www.blackberry.com/SignedKeys/

2.Install Code Signing Keys

An email will be sent to the address used during the registration process.  This email will include attached code signing key files, and instructions for how these files should be installed.

All code signing keys received need to be installed on the same PC.  The same password must be specified for all keys on the same PC.You should receive each key/.csi file in a separate email message.

To register the attachment, please follow the instructions below:

  1. Save all 3 .csi files, sent via email, into the same directory.
  2. Start Eclipse®.
  3. Click on the Window® menu item and then Preferences.  Expand the BlackBerry Java Plug-in and select “Install new Keys…”.
  4. Select one of the 3 .csi files saved in step 1 and click Open.
  5. Click “Yes” to create a new key pair file.
  6. Type a password for your private key of at least 8 characters, and type it again to confirm.  This is your private key password, which protects your private key. Please remember this password as you will be prompted for it each time signing is attempted or a signature key is installed.
  7. Move your mouse to generate date for a new private key.
  8. In the “Registration PIN” field, type the PIN number that you supplied when purchasing signature keys.
  9. In the Private Key password field, type the password created in step 6.
  10. Click “Register”.
  11. Click “Exit”.
  12. Repeat this process for the other csi files.

3. Sign Application using blackberry Developement tool.

  1. Right click on your project in the Package Explorer window
  2. Expand the “BlackBerry” menu item
  3. Select “Sign with Signature Tool”
  4. Enter the signing password you defined when installing your signature keys.

 

By using this we can Signed our Blackberry Application.

Thank you.

 

How to Send Email through Simulator in blackberry

If you are using Blackberry Java Eclipse Plugins then follow the steps.

Step-1:   a) Sending Email Without Attachment.

//Get the Store from the default mail Session.
Store store = Session.getDefaultInstance().getStore();

//retrieve the sent folder
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];

//create a new message and store it in the sent folder
Message msg = new Message(sentfolder);
Address recipients[] = new Address[1];

try
{
recipients[0]= new Address(“testmail@gmail.com”, “testmail”);

//add the recipient list to the message
msg.addRecipients(Message.RecipientType.TO, recipients);

//set a subject for the message
msg.setSubject(“Test email”);

//sets the body of the message
msg.setContent(“This is a test email from my BlackBerry device”);

//sets priority
msg.setPriority(Message.Priority.HIGH);

//send the message
Transport.send(msg);

Dialog.alert(“Email sent successfully..”);
}

catch (Exception me)
{
System.err.println(me);
}

b) Sending Email With Attachment:-

//create a multipart
Multipart mp = new Multipart();

//data for the content of the file
String fileData = “just a simple test n just a simple test”;
String messageData = “WelCome”;

//create the file
SupportedAttachmentPart sap = new
SupportedAttachmentPart(mp,”text/txt”,”test.txt”, fileData.getBytes());

TextBodyPart tbp = new TextBodyPart(mp,messageData);

//add the message and file to the multipart
mp.addBodyPart(tbp);
mp.addBodyPart(sap);

//create a message in the sent items folder
Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);

Message message = new Message(folders[0]);

//add recipients to the message and send
try
{
Address toAdd = new Address(“smita.kale3789@gmail.com”,”smita”);
Address[] toAdds = new Address[1];
toAdds[0] = toAdd;
message.addRecipients(Message.RecipientType.TO,toAdds);
message.setContent(mp);
Transport.send(message);
Dialog.alert(“Email sent successfully..”);
}

catch (Exception e)
{
Dialog.inform(e.toString());
}

 

Step-2:  Follow this path

C:Eclipsepluginsnet.rim.ejde.componentpack7.0.0_7.0.0.33componentsESS

and run “load.bat” file.

fill the required things for example email id, incomming – outgoing server name. and click Load Test.The Load Test Window will open.

Step-3: Run your application.

By using this we can send our email on any account like gmail,yahoo,etc.through simulator.

Thank you.

 

 

 

Set Timer in Blackberry Application

This Code shows how to set Timer in your blackberry Application.

Step-1: Implement Runnable interface.And add unimplemented methods.And set this fields.

private long startTime;
private Thread updater;
private boolean isRunning= false;
private final static SimpleDateFormat timerFormat = new SimpleDateFormat(“ss.SSS”);
private final Runnable displayUpdater= new Runnable()
{
public void run()
{
displayElapsedTime(System.currentTimeMillis() – SecondScreen.this.startTime);
}
};

Step-2: Add this Method.

private void displayElapsedTime(long elapsedTime)
{
edField1.setText(”        “+timerFormat.format(new Date(elapsedTime)));
}

step-3:

public void run() {
try
{
while(isRunning)
{
UiApplication.getUiApplication().invokeAndWait(displayUpdater);
Thread.sleep(50);
}
}
catch(InterruptedException ie) {}
}

Step-4: Inside the FieldChanged Method.

To Start the timer –

if(start == field){
startTime= System.currentTimeMillis();
isRunning= true;
updater= new Thread(this);
updater.start();
}

To Stop the Timer –

if(stop == field){
if(isRunning)
{
long elapsed= System.currentTimeMillis() – startTime;
isRunning= false;
displayElapsedTime(elapsed);
Thread.yield();
currentTime = edField1.getOriginal().toString();
}
}

 

 


Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at info@nanostuffs.com, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box