Thursday, March 16, 2017

ios sdwebimage

display image from url using sdwebimage. download

#import "UIImageView+WebCache.h"

 UIImageView *imgView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 25, 80, 80)];
    imgView.backgroundColor=[UIColor clearColor];
     [imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMAGE_URL,imageUrl]] placeholderImage:[UIImage imageNamed:[NSString stringWithFormat:@"images.png"]]];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:imgView];

ios Webservice class

class for handling webservices download

[[Services sharedInstance]login:usernameTextField.text password:passwordTextField.text andListener:self];


#pragma mark- Service call back method
-(void)ServicesResult:(NSString *)success withResult:(NSDictionary *)result statusCode:(NSString *)statusCode{
  
    if([statusCode isEqualToString:@"200"]){
    
    }
    else if([statusCode isEqualToString:@"1"]){
       
        [util alertViewShow:STRING_No_Network_ERROR withTag:0];
       
    }else{
       
    }
   
}

Friday, June 10, 2016

Blackberry get IP Address

    String ip = new String("");

    try {
        int cni = RadioInfo.getCurrentNetworkIndex();
        int apnId = cni + 1;
        byte[] ipaddr = RadioInfo.getIPAddress(apnId);
        for (int i = 0; i < ipaddr.length; i++) {
        int temp = (ipaddr[i] & 0xff);
        if (i < 3) {
            ip = ip.concat("" + temp + ".");
        } else {
            ip = ip.concat("" + temp);
        }
        }
        System.out.println("ipaddress " + ip);
    } catch (Exception e) {
        ip = null;
    }

Blackberry Get User Address from Lattitude and Longitude

  getLocationFromGoogleMaps(43.4631,-80.5207);

  private static void getLocationFromGoogleMaps(double _lattitude, double _longitude) {

    String fullAddress = "";
    HttpConnection conn = null;
    InputStream in = null;
    ByteArrayOutputStream out = null;
    try {
        String url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + _lattitude + "," + _longitude;
        conn = (HttpConnection) Connector.open(url, Connector.READ);
        conn.setRequestMethod(HttpConnection.GET);
        int code = conn.getResponseCode();
        if (code == HttpConnection.HTTP_OK) {
        in = conn.openInputStream();
        out = new ByteArrayOutputStream();
        byte[] buffer = new byte[in.available()];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer);
        }
        out.flush();
        String response = new String(out.toByteArray());
        JSONObject resObject = new JSONObject(response);
        JSONArray result = resObject.getJSONArray("results");

        if (result.length() > 0) {
            JSONObject dict = result.getJSONObject(0);
            System.out.println("**Resp :**" + dict.getString("formatted_address"));
            fullAddress = dict.getString("formatted_address");
            Dialog.alert(fullAddress);
        } else {
           //error
        }

        }
    } catch (Exception e) {
        Dialog.alert(e.getMessage());
       }

    }