Wednesday, September 24, 2014

Installing Maven and JDK on MacOS



Installing maven on Mac OS:
-------------------------------------

a) Copy the maven folder inside "/usr/local” folder , which will look like this after copying
"/usr/local/apache-maven/apache-maven-3.2.1/bin"
b) update the .bash_profile and set the path
    export PATH = {$PATH}: /usr/local/apache-maven/apache-maven-3.2.1/bin
c) type "source ~/.bash_profile” in the terminal window to refresh the .bash_profile.







Installing JDK on Mac OS:
------------------------------------
a) Download and install the latest version of JDK
b) Type the following command on the Terminal
    $ /usr/libexec/java_home -V

c) Now type the following command to check the Java Version
    $java -version







Updating System JDK Version:
-----------------------------------------
System JDK : /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin

Installed JDK : /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin

steps:
--------
a) cd /System/Library/Frameworks/JavaVM.framework/Versions/
b) sudo rm CurrentJDK
c) sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin CurrentJDK





Setting JAVA_HOME environment variable:
---------------------------------------------------------
a) Edit .bash_profile inside  /Users/susantabehera/ folder
b) Type the following to set the environment variable
export JAVA_HOME=$(/usr/libexec/java_home)
c) Reload the .bash_profile by typing the following command on Terminal
source ~/.bash_profile




Tuesday, September 23, 2014

Setting JAVA_HOME environment variable on Mac OS

Steps:
-------
a) Edit .bash_profile inside  /Users/susantabehera/ folder
b) Type the following to set the environment variable
    export JAVA_HOME=$(/usr/libexec/java_home)
c) Reload the .bash_profile by typing the following command on Terminal
    source ~/.bash_profile

Monday, September 22, 2014

Updating JDK on MacOS


Installing JDK on Mac OS:
------------------------------------
a) Download and install the latest version of JDK
b) Type the following command on the Terminal
    $ /usr/libexec/java_home -V

c) Now type the following command on Terminal to check the Java Version
    $java -version




Updating System JDK Version:
-----------------------------------------
System JDK : /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin

Installed JDK : /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin

steps:
--------
a) cd /System/Library/Frameworks/JavaVM.framework/Versions/
b) sudo rm CurrentJDK
c) sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/bin CurrentJDK


Done !!!


Installing maven on Mac OS

Steps:
-------
a) Copy the maven folder inside "/usr/local” folder , which will look like this after copying
"/usr/local/apache-maven/apache-maven-3.2.1/bin"
b) update the .bash_profile and set the path
    export PATH = {$PATH}: /usr/local/apache-maven/apache-maven-3.2.1/bin
c) type "source ~/.bash_profile” in the terminal window to refresh the .bash_profile.

Parse Linker Error in Other Linker Flags

Do the following:

1.Remove -ObjC and -all_load
2.Add -force_load $(SRCROOT)/GoogleAdmob/fileName.a


Sunday, September 21, 2014

Adjusting extra space at top of UITableView


To remove the extra space on the top of the UITableView ,
add the following code in the ViewDidLoad method of the UIViewController.

- (void)viewDidLoad {
    [super viewDidLoad];
   self.automaticallyAdjustsScrollViewInsets = NO;
 }

Friday, September 19, 2014

NSMutableAttributedString Example



NSString *str = self.view2TextLbl.text;
NSRange range = [str rangeOfString:@"#"];


if(range.location != NSNotFound && range.length){


    UIFont *font1 = [UIFont myAlphaFontsBold:13];
    UIFont *font2 = [UIFont myAlphaFontsBold:14];
   
    UIColor *font1Color = [UIColor whiteColor];
    UIColor *font2Color = [UIColor blackColor];
   
    NSRange range1 = NSMakeRange(0, range.location);
    NSRange range2 = NSMakeRange(range.location, (str.length - range.location));
   
   
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:str];
   
    [attributedStr addAttribute:NSFontAttributeName value:font1 range:range1];
    [attributedStr addAttribute:NSFontAttributeName value:font2 range:range2];
   
    [attributedStr addAttribute:NSForegroundColorAttributeName value:font1Color range:range1];
    [attributedStr addAttribute:NSForegroundColorAttributeName value:font2Color range:range2];
   
    self.view2TextLbl.attributedText = attributedStr;
 
}     

NSURLAuthenticationChallenge


#pragma mark - NSURLConnection delegate for Handling HTTPS
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace*)protectionSpace {
  NSLog(@"Authentication String : %@", NSURLAuthenticationMethodServerTrust);
 
  NSLog(@"protectionSpace.authenticationMethod : %@", protectionSpace.authenticationMethod);
 
  //return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
 
  return YES;
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
 
  NSLog(@"challenge.protectionSpace.authenticationMethod : %@", challenge.protectionSpace.authenticationMethod);
 
  if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
    NSLog(@"************ CERTIFICATE DOWNLOADED ***************");
  }
  [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
 
}

Android UI - Inflate from XML

   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final LayoutInflater  inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        Button b = (Button)inflater.inflate(R.layout.buttons,
                null);
      
        lLayout = (LinearLayout)findViewById(R.id.layout1);
        lLayout.addView(b);



    b.setOnClickListener(new OnClickListener() {
          
            public void onClick(View v) {
                  //restrict to adding only 1 textview child element
                  if (lLayout.getChildAt(2) == null)
                  {
                  TextView tv = (TextView)inflater.inflate(R.layout.text, null);
                  lLayout.addView(tv);
                  }
            }
        });
  }


Assume, on the click of the button, you want to show some new text. This TextView is defined in another XML called text.xml which is also in the res/layout folder.

Creating Android UI Programmatically


 public void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);
     
        lLayout = new LinearLayout(this);
        lLayout.setOrientation(LinearLayout.VERTICAL);
        //-1(LayoutParams.MATCH_PARENT) is fill_parent or match_parent since API level 8
        //-2(LayoutParams.WRAP_CONTENT) is wrap_content
        lLayout.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
        tView = new TextView(this);
        tView.setText("Hello, This is a view created programmatically! " +
                  "You CANNOT change me that easily :-)");
        tView.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
        lLayout.addView(tView);
        setContentView(lLayout);
       
  }     

Thursday, September 18, 2014

Identifying iPhone & iPad Models

Identifying iPhone models
http://support.apple.com/kb/HT3939

Identifying iPad models
http://support.apple.com/kb/HT5452

GMT Date

- (NSDate *)dateToGMT:(NSDate *)sourceDate      // To convert current GMT time
{
    NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
    NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:destinationGMTOffset sinceDate:sourceDate] autorelease];
    return destinationDate;
}


GMT and Localtime in ObjectiveC

  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss zzz, zzzz";

  NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  [dateFormatter setTimeZone:gmt];
  NSString *gmtTimeStamp = [dateFormatter stringFromDate:[NSDate date]];
  NSLog(@"GMT Time : %@", gmtTimeStamp);

 
 
  NSTimeZone *localTimeZone = [NSTimeZone localTimeZone];
  //NSTimeZone *localTimeZone = [NSTimeZone systemTimeZone];
  //NSTimeZone *localTimeZone = [NSTimeZone defaultTimeZone];

  [dateFormatter setTimeZone:localTimeZone];
  NSString *localTimeStamp = [dateFormatter stringFromDate:[NSDate date]];
  NSLog(@"Local Time : %@", localTimeStamp);

Date Programming


http://rypress.com/tutorials/objective-c/data-types/dates.html


Wednesday, September 17, 2014

Dismiss Keyboard in Android

private void hideSoftKeyBoard() {
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

    if(imm.isAcceptingText()) { // verify if the soft keyboard is open                     
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}

--------------------------------------------------------------

public static void hideKeyboard(Activity activity) {
    View v = activity.getWindow().getCurrentFocus();
    if (v != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }
}


-------------------------------------------------------------


yourEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        if(!hasFocus){
                            hideKeyboard();
                        }

                    }
                });


private void hideKeyboard() {
    InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
}

Reading from External Storage in Android


Reading from External Storage:
---------------———————————————

<manifest >
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    ...
</manifest>



/* Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        return true;
    }
    return false;
}

/* Checks if external storage is available to at least read */
public boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state) ||
        Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}