Asynchronous Download images from Url And Save into Documents Directory in iphone

.h//—————————–
@interface ViewController : UIViewController
{
UIActivityIndicatorView *ProccessIndicator;
NSMutableArray *imgnmarr,*imgurlarr;
}
– (void) loadImageInBackground:(NSArray *)urlAndTagReference
– (void) assignImageToImageView:(NSArray *)imgAndTagReference
.m//—————————–
– (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor blueColor]];
[self LazyLoading];
}
– (void) LazyLoading
{
imgnmarr = [[NSMutableArray alloc] init];
imgurlarr = [[NSMutableArray alloc] init];

//Mutable Array of images Url
[imgurlarr addObject:@”http://demos.nanostuffs.com/Cab/uploads/Paddy_dest_1.png”];
[imgurlarr addObject:@”http://demos.nanostuffs.com/Cab/uploads/Paddy_dest_2.png”];
[imgurlarr addObject:@”http://demos.nanostuffs.com/Cab/uploads/Paddy_dest_3.png”];
[imgurlarr addObject:@”http://demos.nanostuffs.com/Cab/uploads/Paddy_dest_4.png”];

//Mutable Array of Image Names To Save In DOcuments Directory
[imgnmarr addObject:@”Paddy_dest_1.png”];
[imgnmarr addObject:@”Paddy_dest_2.png”];
[imgnmarr addObject:@”Paddy_dest_3.png”];
[imgnmarr addObject:@”Paddy_dest_4.png”];

int flag = 0;

for (int i = 0; i < 2; i++)
{
for (int j = 0 ; j < 2; j++)
{
flag++;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[imgnmarr objectAtIndex:flag-1]];
UIImage *img1 = [UIImage imageWithContentsOfFile:savedImagePath];

if (!img1 || [UIImagePNGRepresentation(img1) length] <=0)
{
id path =[imgurlarr objectAtIndex:flag-1];
path = [path stringByReplacingOccurrencesOfString:@" "
withString:@"%20"];
NSURL *url = [NSURL URLWithString:path];
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:url, [NSString stringWithFormat:@"%d", flag], nil];
[self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr];

ProccessIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
ProccessIndicator.frame = CGRectMake(55+ (140 * j), 99 + (125 * i), 68, 55);
ProccessIndicator.hidesWhenStopped = YES;
[self.view addSubview:ProccessIndicator];
[ProccessIndicator startAnimating];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(55+ (140 * j), 99 + (125 * i), 68, 55)];
imageView.tag = flag;

imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 15.0;
imageView.layer.borderWidth = 1.0;
imageView.layer.borderColor = [[UIColor blackColor] CGColor];

imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.layer.shadowRadius = 1.0;

[self.view addSubview:imageView];
}
else
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(55+ (140 * j), 99 + (125 * i), 68, 55)];
imageView.tag = flag-1;
imageView.image = img1;

imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 15.0;
imageView.layer.borderWidth = 1.0;
imageView.layer.borderColor = [[UIColor blackColor] CGColor];

imageView.layer.shadowColor = [UIColor blackColor].CGColor;
imageView.layer.shadowOffset = CGSizeMake(0, 1);
imageView.layer.shadowOpacity = 1;
imageView.layer.shadowRadius = 1.0;

[self.view addSubview:imageView];
}
}
}
}
– (void) loadImageInBackground:(NSArray *)urlAndTagReference
{
NSData *imgData = [NSData dataWithContentsOfURL:[urlAndTagReference objectAtIndex:0]];
UIImage *img = [[UIImage alloc] initWithData:imgData];

NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:img, [urlAndTagReference objectAtIndex:1], nil];

[self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr waitUntilDone:YES];
}
– (void) assignImageToImageView:(NSArray *)imgAndTagReference
{
for (UIImageView *checkView in [self.view subviews] )
{
if ([checkView tag] == [[imgAndTagReference objectAtIndex:1] intValue])
{
[checkView setImage:[imgAndTagReference objectAtIndex:0]];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[imgnmarr objectAtIndex:[[imgAndTagReference objectAtIndex:1] intValue]-1]];
UIImage* imageToSave = [checkView image];
NSData *imageData = UIImagePNGRepresentation(imageToSave);
[imageData writeToFile:savedImagePath atomically:NO];
}
}
}

How to create simple Tabs and Buttons in Sencha

Sencha Touch is used to create HTML5 based mobile apps that work on Android, iOS and Blackberry devices.

– To develope  Sencha Touch Applications,  two things are needed:

1. Sencha Touch 2SDK

2. SDK Tools

-There is a command to develop  Sencha Touch Application:

E:wampwwwsencha-touch-2.0.1>sencha generate app  <Application Name >../<Application Name>

-It will create a Directory-

FirstApp

-app

-controller

-model

-view

-profile

-store

-resource

-sdk

-app.js

-app.json

-index.html

-packager.json

 

We are editing in app.js file. it will create sencha tab-tools and button

Code-

Ext.application({

name: ‘app’,

launch:function(){

var container = Ext.create(‘Ext.Container’, {

fullscreen: true,

layout: {

type: ‘vbox’,

// align: ‘start’,

//pack: ‘start’

},

items: [

{

docked: ‘top’,

xtype: ‘titlebar’,

title: ‘VBox Layout’

},

{

docked: ‘bottom’,

xtype: ‘toolbar’,

items: [

{

xtype: ‘container’,

html: ‘Pack: ‘,

style: ‘color: #fff; padding: 0 10px; width: 85px;’

},

{

xtype: ‘segmentedbutton’,

allowDepress: false,

items: [

{ text: ‘Start’,  handler: function() { layout.setPack(‘start’) }, pressed: true },

{ text: ‘Center’, handler: function() { layout.setPack(‘center’) } },

{ text: ‘End’,    handler: function() { layout.setPack(‘end’) } }

]

}

]

},

{

docked: ‘top’,

xtype: ‘toolbar’,

items: [

{

xtype: ‘container’,

html: ‘Align: ‘,

style: ‘color: #fff; padding: 0 10px; width: 85px;’

},

{

xtype: ‘segmentedbutton’,

allowDepress: false,

items: [

{ text: ‘Start’,   handler: function() { layout.setAlign(‘start’); }, pressed: true },

{ text: ‘Center’,  handler: function() { layout.setAlign(‘center’); } },

{ text: ‘End’,     handler: function() { layout.setAlign(‘end’); } },

{ text: ‘Stretch’, handler: function() { layout.setAlign(‘stretch’); } }

]

}

]

},

{ xtype: ‘button’, text: ‘Btn 1’, margin: 2 },

{ xtype: ‘button’, text: ‘Btn 2’, margin: 2 },

{ xtype: ‘button’, text: ‘Btn 3’, margin: 2 }

]

});

var layout = container.getLayout();

}

});

And Last Run index.html file

How to add an audio file to a button in Unity3D

using UnityEngine;

using System.Collections;

using System;

public class MainMenu : MonoBehaviour {

public AudioSource audioSource;

public AudioClip palySound;

void Start ()  { }

public void OnGUI()

{  if(GUI.Button(new Rect(50,200,100,45),”Play”))  {

audioSource.PlayOneShot(palySound); }

}}

when we attached the script in the inspector.

we have to attach the AudioSource  from the

Components–>Audio–>AudioSource

to the inspector

Five ways to pull yourself out of workaholism

‘In sickness and in health and till death do us part’ – if these are the vows your family and friends think you have exchanged with your Blackberry/keyboard/iPad, then you are a certified workaholic.

The symptoms are many, but some of the significant ones are that you punch away nonstop, receive every call from office and take your meals at odd hours to finish that extra bit at work.

All this leads to anxiety disorders, repetitive stress injury, mental and physical fatigue, and this strong alliance with work is best severed at the start. ET suggests how you can do that.

 

Draw Clear Boundaries

Clocking out of work is just as important as clocking in. Working post-office hours is acceptable if there is an urgent assignment but if it becomes a habit, alarm bells should start ringing. It helps to unplug phones and computers during vacations and non-working hours.

Check on Employees

Employers need to look into the employees’ attendance sheets and office hours. Sabre, for instance, found that despite giving employees access to wellness centres, counselling sessions and discount coupons at gyms, they were still packing in extra hours at work. The firm, therefore, does not offer the option of carrying forward holidays .

Say a Firm ‘No’

‘Workaholics anonymous’ groups don’t exist, but instead, a simple ‘no’ can go a long way. Complete your tasks first, and only if there is time to spare, offer another a helping hand. Once the tasks are done, wait for the next day to start on the new list of chores.

Extra isn’t Always Healthy

The boss often thinks that those who work round the clock are the productive ones. But a smart worker can be someone who punches in the required hours, completes his work and leaves office on time too.

In a recent Randstad survey of state-owned companies, 80% of employees said they received work-related calls and emails beyond office hours. Nearly 69% said they volunteered to work post-office hours while 79% received work-related calls and emails on holidays. Long hours lead to a dip in productivity and creativity.

Watch your Schedule

Often, the employee in the cubicle next to you could be a night owl at the office, but that need not be your style. Excessive breaks, long water-cooler conversations will ultimately lead to more time in the office, and not a very fruitful schedule.

So what’s the moral of the story??
* Very clear, LEAVE ON TIME!!!
* Never put in extra time ‘ unless really needed ‘
* Don’t stay back unnecessarily and spoil your company work culture which will in turn cause inconvenience to you and your colleagues.

QR_CODE Scanner for Android

“QR Codes” also knows as “Quick Response Codes”. Its two dimensional code (also known as Matrix Barcode ), and can be read easily by a mobile phone.
They fetch piece of information from temporary media and push that in your mobile phone. The reason why they are getting popular than normal Barcode is because they are able to capture more information(data, urls, texts and geo coordinates). Another reason for this  to go popular is because it can be scanned easily by mobile phones. You don’t need to have hand-held scanners to scan them.

Sounds really cool but as a developer it is as complicated as qrcode itself  🙂 .

After lot of searching i came across ZXing application  which returns the result via Intent. Most important thing is this is an open source code (pls correct me if i am wrong)

There are two ways of integrating this app

1- import QRCode scanner app from http://code.google.com/p/zxing/source/browse/trunk and start it from some trigger function like button press within your code which will ask you to download Barcode Scanner app from market. download it  and grab the result from onActivityResult() method of your Activity.

2- Copy some of the packages to your project and using camera you can scan the QRCode directly from your app. ( Which i have used 🙂 )

For both of above options the important thing you should do is

* create a .jar file of the source from core folder retrieved from github repo and add to your eclipse project.

for second option you need to add two more .jar files android-integration.jar and android-support-V4.jar (which i have put in the libs folder)

and need to add 5 packages

com.google.zxing.client.android

com.google.zxing.client.android.camera

com.google.zxing.client.android.encode

com.google.zxing.client.android.result

com.google.zxing.client.android.wifi

 

From your Activity start the SCAN activity like

Intent intent = new Intent(“com.google.zxing.client.android.SCAN”);
intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);
startActivityForResult(intent, 0);

And in onActivityResult method add following code

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
 if (requestCode == 0) {
 if (resultCode == RESULT_OK) {
 String contents = intent.getStringExtra("SCAN_RESULT");
 t.setText(contents);
 String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
 // Handle successful scan
 } else if (resultCode == RESULT_CANCELED) {
 t.setText("Unable to scan the code");
 }
 }

That all you need to do to get it done :).

You can find the source code here.

Skype is conflicting Wamp server. OR Wamp server error – though it is online,it is not working properly and showing orange color on quick launch icon.

Wamp server showing above error massage- Could not execute menu item (internal error). [execution ] Could not perform service action: The service has not been started.

This error is fault of Apache  service of Wamp server.

To solve this error-

1. left click on quick launch icon of wamp server .

2.then goto Apache–> Service–>click on Test Port 80. the following screen will appear.

 

In my case the Skype Software is conflicting to Wamp Server .

Then, after Exiting the skype Software , my Wamp Server is working Properly .

Another solution  for this error is  –Change the port number of either Wamp or Skype.

Change Port No of skype–>

In skype if you click “tools ” then “options” and connection down the left,

untick the box ” use port 80 and 443 as alternative incoming ports”

then you wont have this issue anymore

Thanks ..!

 

Uploading a document in apex salesforce using custom controller

sometimes you may want to create a process where uploading a document is mandatory. You can create a single Visualforce page with all of the fields for the record plus the field required to upload a document. code  below is an example

//VISUALFORCE PAGE
<apex:page controller=”docex”>
<apex:outputLabel value=”Document Name”/>
<apex:inputText id=”name” value=”{!d.name}”/>

<apex:outputLabel value=”Upload Document”/>
<apex:inputFile value=”{!file}” />
<apex:commandButton value=”Save” action=”{!insert}” id=”save”/>
</apex:page>

//APEX CLASS
public class docex
{
Document d{get;set;}
public ID folderid{get;set;}

public docex
{
d= new Document();
}
public void insert()
{
//document
folderid=UserInfo.getUserId();    //uses the current user id as folder id
d.body=file;            // body field in document object which holds the file.
d.folderid=folderid;        //folderid where the document will be stored
insert d;
}

}

for further reference you can store the id of an document along with other fields in your custom object . and retrieve the contents of the document object by using soql query:

document d=[select body, id , name from document where id=”<stored 18 character id>”]

Add UIButton on UITableView when drag , Swipe or touches moved on Cell Using UIGestureRecognizerDelegate in iPhone

//——–
.h
//Delegate
UIGestureRecognizerDelegate
UIButton *YourButton;

//——–
.m
– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = @”SimpleTableIdentifier”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

if (cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
UISwipeGestureRecognizer *gestureL = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeL:)];
gestureL.direction = UISwipeGestureRecognizerDirectionLeft;
[cell.contentView addGestureRecognizer:gestureL];
[gestureL release];

UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeR:)];
gestureR.direction = UISwipeGestureRecognizerDirectionRight;
[cell.contentView addGestureRecognizer:gestureR];
[gestureR release];

YourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[YourButton addTarget:self action:@selector(YourButtonMethod:) forControlEvents:UIControlEventTouchDown];
[YourButton setTitle:@”MyButton” forState:UIControlStateNormal];
YourButton.frame = CGRectMake(320, 12.5, 104, 35);
[cell.contentView YourButton];
}

-(void)didSwipeL:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:AppsTable];

NSIndexPath *indexPath = [AppsTable indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@”long press on table view but not on a row”);
else
{
NSLog(@”long press on table view at row %d”, indexPath.row);
UITableViewCell *cell = [AppsTable cellForRowAtIndexPath:indexPath];

CGPoint newLeftCenter = CGPointMake( 198 + AddToFavorities.frame.size.width / 2.0f, AddToFavorities.center.y);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
YourButton.center = newLeftCenter;
[UIView commitAnimations];
YourButton.tag = indexPath.row;
[cell.contentView addSubview:AddToFavorities];
}
}

-(void)didSwipeR:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:AppsTable];

NSIndexPath *indexPath = [AppsTable indexPathForRowAtPoint:p];
if (indexPath == nil)
NSLog(@”long press on table view but not on a row”);
else
{
NSLog(@”long press on table view at row %d”, indexPath.row);
UITableViewCell *cell = [AppsTable cellForRowAtIndexPath:indexPath];

CGPoint newLeftCenter = CGPointMake( 320.0f + AddToFavorities.frame.size.width / 2.0f, AddToFavorities.center.y);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
YourButton.center = newLeftCenter;
[UIView commitAnimations];
YourButton.tag = indexPath.row;
[cell.contentView addSubview:AddToFavorities];
}
}

– (void) YourButtonMethod : (id) sender
{
//[self retriveAPps];

UIButton *clickedbtn = (UIButton *)sender;
NSLog(@”Added to favorities %d”,clickedbtn.tag);
}

Launch the app store app from your application

 

Step 1: Create an empty iPhone application with and add the UIViewController subclass to it.

Step 2: Create a view just like the one given below and the add the view of this view controller into the iPhone window.

Step 3: Create a function for the button and this function will contain the code for launching the app store application of the iOS device from your application. So declare a function with proper name into the your ViewController.h file and implement the same in the yourViewController.m file given below is the code for the same.

 

MyViewController.h file 

 

MyViewController.m file

 

Code Explanation: In the above code since we want to launch the app store we have used the itms-apps: in place of http followed by your application link which is present on the app store.
Step 4: Build your project and deploy the project into the iOS device.
Step 5: After you touch the button you will see the app store app is launched with the application details who’s link you have provided.
You can download the sample project from here.

 

Note: This demo cannot be tested in the iPhone simulator for the testing of this demo you require this application to be deployed into your iOS device.

This kind of requirement is mostly used when a client requests that he wants a review section in his application. You may also use the link maker from apple to get your application url link.

 

How to export leads to excel sheet in salesforce apex

Here is the code for exporting leads to excel in salesforce apex

Class Code:

public class exportExcel {

public string header{get;set;}

public List<wrapper> lstwrapper {get; set;}

public class wrapper{

public string Id{get; set;}

public string Name{get; set;}

public string Email{get; set;}    }

public string Filetype{get;set;}

public boolean isExcel {get;set;}

public boolean isCsv {get;set;}

public exportExcel(){

Filetype = ”;

lstwrapper = new List<wrapper>();

header = ‘Id,Name,Email’;

}

public void exportToExcel(){

string queryString = ‘Select Id, Name, Email from Lead’;

List<Lead> lstLead = DataBase.Query(queryString);
if(lstLead.size() > 0) {

for(Lead ld : lstLead)

{

wrapper w = new wrapper();

w.Id = ld.Id;

w.Name= ld.Name;

w.Email = ld.Email;

lstwrapper.add(w);

}

}

}

}

 

Page Code:

<apex:page controller=”exportExcel” action=”{!exportToExcel}” readOnly=”true”  contentType=”application/vnd.ms-excel#ConsignmentSearchData.xls”>          <apex:pageBlock >

<apex:pageBlockTable value=”{!lstwrapper}” var=”x”>

<apex:column headerValue=”Id”>

{!x.Id}

</apex:column>

<apex:column headerValue=”Name”>

{!x.Name}

</apex:column>

<apex:column headerValue=”Email”>

{!x.Email}

</apex:column>

</apex:pageBlockTable>

</apex:pageBlock>

</apex:page>


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