Uncategorized Archives

Android Rating Bar Example

1. Rating Bar

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

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:orientation="vertical" >

        android:text="Rate Me"
        android:textAppearance="?android:attr/textAppearanceMedium" />

        android:rating="2.0" />

        android:text="Submit" />

        android:layout_height="wrap_content" >

            android:text="Result : "
            android:textAppearance="?android:attr/textAppearanceLarge" />

            android:textAppearance="?android:attr/textAppearanceSmall" />



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;

  public void onCreate(Bundle savedInstanceState) {



  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) {



  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() {

		public void onClick(View v) {





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:

  • Property CMS->content is not valid at line 878 in file classes/ObjectModel php
  • Property Carrier->delay is empty at line 878 in file classes/ObjectModel php
  • at line 878 in file classes/ObjectModel php
  • Property FeatureValue->value is not valid at line 878 in file classes/ObjectModel php
  • Property CMS->content is not valid
  • Property Attribute->name length must be between prestashop
  • prestashop product name length
  • prestashop error Property CMS->content is not valid at line 878 in file classes/ObjectModel php
  • prestashop change name length
  • content is not valid at line 878 in file classes/ObjectModel php

//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



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];



[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:



case MFMailComposeResultSaved:



case MFMailComposeResultSent:



case MFMailComposeResultFailed:






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

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

[alert show];





[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);


case CCDeviceOrientationLandscapeLeft:

CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(-90));

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


case CCDeviceOrientationLandscapeRight:

CGContextRotateCTM(context, CC_DEGREES_TO_RADIANS(90));

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



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

CGImageRef imageRef = CGBitmapContextCreateImage(context);

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









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,


gradientLayer.locations = [NSArray arrayWithObjects:

[NSNumber numberWithFloat:0.0f],

[NSNumber numberWithFloat:0.5f],

[NSNumber numberWithFloat:0.5f],

[NSNumber numberWithFloat:0.8f],

[NSNumber numberWithFloat:1.0f],


[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];

Android Application Development For Business

Android Application Development For Business

Android is definitely an free Linux based operating system that contains Java library fully targeted for changing using mobile products. The newest system is fast growing operating system highly modified due its immense features, trimmed costs of possession and facilities that provides endless possibilities for that designers. This favourable OS includes a software stack for that handheld products produced by Google. Being very famous and effective to cater any requirement from varied segments and fields you can use it to avail abounding benefits for business. Android doesn’t make any distinction between 3rd party and mobiles core programs. You will find a lot of companies who provide number of Android web design services from easy to complex business development. Android business database integration is accomplished by designers who’re expert enough in Java together with gathered knowledge of Android SDK, APIs along with other technologies.

For effective android application development for business latest tools, integrated features & enhanced changes may lead for the endless gains. Android business database integration is really a faster process and benefits a shorter period than other platforms or OS. The focused application must have all of the elements within an appropriate manner and targeted towards driving good results in a variety of terms. These various manners for achieving most effective benefits defines operational efficiency, quick achievements of tasks, an advantage leading towards cloud services, considerable saving of your time, efforts & assets, a achieve to promote profits well over time plus much more.

Android application development for business includes undeniable levels that may develop a effective roadmap for just about any business. Primary benefit of availing android business applications is that they are affordable and incredibly helpful for carrying out all of the activities incorporated running a business.

Companies offer flexible and extensive selection of services for clients. Here they identify clients needs in perspective for their business and also the areas they have to concentrate on. Initiation from the development lifecycle starts with creating, architecture, planning & constructing of the effective roadmap to get result-oriented solutions. The immediate step following a above is debugging, testing & deployment. Clients enjoy unequalled programs that perform perfectly, are completely functional & feature wealthy. These capabilities assist them to update their understanding with the occurrences, transactions & activities of the business. Further they are able to maximize their usage, finish any task, making faster choices & response rapidly for their clients. Residing in pace using the technology or trend and giving better performance to match ever changing demands are only able to make any company survive within this most difficult era.

Android application development for business could be advantageous in almost any area/segment including:

-Sales & Marketing
-Planning & Administration
-Process Management
-Overall Management
-Human Assets
-Supply chain management
-Procedures management
-Integration services
-Personalization for unique needs accomplishment

All of these are various fields where Android business application development could be carried out and utilized in any Android device. All business applications are fully guaranteed & private, robust, maintainable, helpful and integrated with assorted additional features or programs to profit greater. Explaining now in a nutshell they may be possessed at pocket friendly prices and rapidly from experienced companies plus they return way over that which was invested.

Here is a workshop in Singapore on Android Apps

Schogini in association with Giann Pte Ltd is organising a 4 hour incredible Android App Mastery Workshop in Singapore. This is one of it’s kind Mobile Programming Workshop in Singapore that can take you to the next level.

You can learn How to build an android game in just 4 Hours. Moreover you get a fully working kit of a game that is live in Google Play. Schogini has created 450+ live apps, from Chess to Khet! You can now learn it from the most prolific app developer. You will get to directly experience our team’s exceptional capability to groom you into a world class professional in a short span. Our intern Unmesh Gangadharan was trained by us on mobile programming during his internship, he went on to receive the best app award and appreciation from UK Prime Minister David Cameroon.

Do not miss this rare opportunity to upgrade your programming skills to reach to the next level: The iPhone and iPad Application Development! Register Now! http://ub.schogini.com/android-app-development-training-learn/

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