Uncategorized Archives

For adding a tweet button as shown above, you just need to add the following code to your page.

<a href=”https://twitter.com/share” data-url=”http://www.google.co.in/”>Tweet</a> <!– Edit your page name here–>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=”//platform.twitter.com/widgets.js”;fjs.parentNode.insertBefore(js,fjs);}}(document,”script”,”twitter-wjs”);</script>

object:stopAtFrame( )

Jumps the animation to the specified frame number or frame label specified by the setLabels()function.

Syntax:

object:stopAtFrame( frame )

eg:

myAnim:stopAtFrame(4)

myAnim:play()

Android Rating Bar Example

1. Rating Bar

Open “res/layout/main.xml” file, add a rating bar component, few textviews and a button.

Note
The rating bar contains many configurable values. In this case, the rating bar contains 4 stars, each increase 1.0 value, so, it contains the minimum of 1.0 (1 star) and maximum value of 4.0 (4 stars). In addition, it made the 2nd star (2.0) selected by default.

File : res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblRateMe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rate Me"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="4"
        android:stepSize="1.0"
        android:rating="2.0" />

    <Button
        android:id="@+id/btnSubmit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Submit" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/lblResult"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Result : "
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/txtRatingValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </LinearLayout>

</LinearLayout>

2. Code Code

Inside activity “onCreate()” method, attach a listener on rating bar, fire when rating value is changed. Another listener on button, fire when button is clicked. Read the code’s comment, it should be self-explanatory.

File : MyAndroidAppActivity.java

package com.mkyong.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MyAndroidAppActivity extends Activity {

  private RatingBar ratingBar;
  private TextView txtRatingValue;
  private Button btnSubmit;

  @Override
  public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);

	addListenerOnRatingBar();
	addListenerOnButton();

  }

  public void addListenerOnRatingBar() {

	ratingBar = (RatingBar) findViewById(R.id.ratingBar);
	txtRatingValue = (TextView) findViewById(R.id.txtRatingValue);

	//if rating value is changed,
	//display the current rating value in the result (textview) automatically
	ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
		public void onRatingChanged(RatingBar ratingBar, float rating,
			boolean fromUser) {

			txtRatingValue.setText(String.valueOf(rating));

		}
	});
  }

  public void addListenerOnButton() {

	ratingBar = (RatingBar) findViewById(R.id.ratingBar);
	btnSubmit = (Button) findViewById(R.id.btnSubmit);

	//if click on me, then display the current rating value.
	btnSubmit.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {

			Toast.makeText(MyAndroidAppActivity.this,
				String.valueOf(ratingBar.getRating()),
					Toast.LENGTH_SHORT).show();

		}

	});

  }
}

If, you get an error like this:

Prestashop Exception: Property Configuration->name length (34) must be between 0 and 32 at line 837 in file classes/ObjectModel.php

Then, it means that one of your module configuration key name is too long. The error message will tell you the current length of the key and how long it can be. It will also tell you the line number where you can find the configuration key. Usually it will be a line like this

Configuration::updateValue(‘THIS_IS_MY_VERY_LONG_CONFIG_KEY_NAME’, ‘Some value’);

Use the exception messages to find the file, the line number and the key and change it.

Incoming search terms:

  • [PrestaShopException] Property CMS->content is not valid at line 878 in file classes/ObjectModel php
  • line 837 in file classes/ObjectModel php
  • category name length prestashop
  • prestashop Property Product->reference length (33) must be between 0 and 32
  • Property ProductSupplier->product_supplier_reference length (34) must be between 0 and 32 prestashop

//let webView be your UIWebview

//Not like other UIViews, the UIWebview’s opaque property is set to true by default. That should be set to false for changing the background color.

[webView setOpaque:NO];

webView.backgroundColor=[UIColor redColor];

Displaying an image on a UIWebview in iPhone Xcode

NSString *myHTML =@”<html><body><img src=\”imagename.png\”  width=\”200\” height=\”200\”></body></html>”;

NSString *path = [[NSBundle mainBundle] bundlePath];//it is the path to where you have added the image

NSURL *baseURL = [NSURL fileURLWithPath:path];

[webView loadHTMLString:myHTML baseURL:baseURL];//webview should be a properly added UIWebview

Sending an image through email in iPhone Xcode

//first you have to import the messageUI framework in the .h file after adding it to the compile resources

#import <MessageUI/MessageUI.h>

//now call the below function

-(void)mail_image

{

mailComposer = [[UIViewController alloc] init];//mailComposer should be declared in the .h file

[self.view addSubview:mailComposer.view];

[mailComposer setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

NSString *imgName = @”myimage”;//name of the image in the resources

UIImage *Foto = [UIImage imageNamed:imgName];

NSData *data = UIImagePNGRepresentation(Foto);

[picker addAttachmentData:data  mimeType:@"image/png" fileName:@"myfilename"];

if (!picker) {

[mailComposer.view removeFromSuperview];

return;

}

[picker setSubject: @"mysubject"];

[picker setMessageBody:emailBody isHTML:NO];

[mailComposer presentViewController:picker animated:YES completion:nil];

}

 

//now add the delegate method

-(void) mailComposeController: (MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError*)error

{

// Notifies users about errors associated with the interface

switch (result)

{

case MFMailComposeResultCancelled:

NSLog(@”MFMailComposeResultCancelled”);

break;

case MFMailComposeResultSaved:

NSLog(@”MFMailComposeResultSaved”);

break;

case MFMailComposeResultSent:

NSLog(@”MFMailComposeResultSent”);

break;

case MFMailComposeResultFailed:

NSLog(@”MFMailComposeResultFailed”);

break;

default:

{

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Email” message:@”Sending Failed – Unknown Error  ”

delegate:self cancelButtonTitle:@”OK” otherButtonTitles: nil];

[alert show];

}

}

break;

}

[mailComposer dismissViewControllerAnimated:YES completion:nil];

[mailComposer.view.superview removeFromSuperview];

}

Taking screenshot in Cocos2d iPhone.

Add the function given below to CCDirectorIOS.m which will be present in cocos2d classes.

- (UIImage*) screenshotUIImage

{

CGSize displaySize = [self displaySizeInPixels];

CGSize winSize = [self winSizeInPixels];

//Create buffer for pixels

GLuint bufferLength = displaySize.width * displaySize.height * 4;

GLubyte* buffer = (GLubyte*)malloc(bufferLength);

//Read Pixels from OpenGL

glReadPixels(0, 0, displaySize.width, displaySize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

//Make data provider with data.

CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);

//Configure image

int bitsPerComponent = 8;

int bitsPerPixel = 32;

int bytesPerRow = 4 * displaySize.width;

CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

CGImageRef iref = CGImageCreate(displaySize.width, displaySize.height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

uint32_t* pixels = (uint32_t*)malloc(bufferLength);

CGContextRef context = CGBitmapContextCreate(pixels, winSize.width, winSize.height, 8, winSize.width * 4, CGImageGetColorSpace(iref), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

CGContextTranslateCTM(context, 0, displaySize.height);

CGContextScaleCTM(context, 1.0f, -1.0f);

switch (self.deviceOrientation)

{

case CCDeviceOrientationPortrait: break;

case CCDeviceOrientationPortraitUpsideDown:

CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(180));

CGContextTranslateCTM(context, -displaySize.width, -displaySize.height);

break;

case CCDeviceOrientationLandscapeLeft:

CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(-90));

CGContextTranslateCTM(context, -displaySize.height, 0);

break;

case CCDeviceOrientationLandscapeRight:

CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(90));

CGContextTranslateCTM(context, displaySize.height-displaySize.width, -displaySize.height);

break;

}

CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, displaySize.width, displaySize.height), iref);

CGImageRef imageRef = CGBitmapContextCreateImage(context);

UIImage *outputImage = [[[UIImage alloc] initWithCGImage:imageRef] autorelease];

//Dealloc

CGImageRelease(imageRef);

CGDataProviderRelease(provider);

CGImageRelease(iref);

CGColorSpaceRelease(colorSpaceRef);

CGContextRelease(context);

free(buffer);

free(pixels);

return outputImage;

}

 

//After this you can take the screenshot by using the below line of code

UIImage *screenshot = [[CCDirector sharedDirector] screenshotUIImage];

//now save the image by using the following lines

NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Screenshot.png"];

[UIImagePNGRepresentation(screenshot) writeToFile:savePath atomically:YES];

 

Adding Gradient to a UIButton in Xcode

-(void) addGradient:(UIButton *) myButton

{

CALayer *layer = myButton.layer;

layer.cornerRadius = 3.0f;

layer.masksToBounds = YES;

layer.borderColor = [UIColor darkGrayColor].CGColor;

// Add Gradient

CAGradientLayer *gradientLayer = [CAGradientLayer layer];

gradientLayer.frame = layer.bounds;

gradientLayer.colors = [NSArray arrayWithObjects:

(id)[UIColor colorWithWhite:1.0f alpha:0.2f].CGColor,

(id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,

(id)[UIColor colorWithWhite:0.75f alpha:0.1f].CGColor,

(id)[UIColor colorWithWhite:0.4f alpha:0.1f].CGColor,

(id)[UIColor colorWithWhite:1.0f alpha:0.2f].CGColor,

nil];

gradientLayer.locations = [NSArray arrayWithObjects:

[NSNumber numberWithFloat:0.0f],

[NSNumber numberWithFloat:0.5f],

[NSNumber numberWithFloat:0.5f],

[NSNumber numberWithFloat:0.8f],

[NSNumber numberWithFloat:1.0f],

nil];

[layer addSublayer:gradientLayer];

}

Loading a HTML page in to a UIWebview in Xcode

NSString *htmlstring = @”myhtmlString”;//initialize htmlstring with desired HTML string

[myWebview loadHTMLString:myHTML baseURL:nil];

Page 3 of 1112345...10...Last »
We Can Build Your App for You. Lets Get Started !