Archive for the ‘Google’ Category

29
Apr

If your eclipse shuts down throwing the error,
java.lang.OutOfMemoryError: Java heap space

……………………………………………………………………………
……………………………………………………………………………

at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)

 

Here are the steps to increase the heap space memory.

 

Locate your Eclipse installation folder.

Open ‘eclipse.ini’ file in a text editor and increase the memory as shown in the figure.


 

Restart eclipse and your application should run fine.

, , , , , , , , , , , ,

28
Apr

Lets you spin the selected View canvas in the XY plane.

// Create a rotate animation.

RotateAnimation rotate = new RotateAnimation(0, 360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setFillAfter(true);
rotate.setDuration(1000);

, , , ,

27
Apr

You can use custom fonts in android. For this you have to copy the font file (.ttf ) to the assets folder. Assume your font name is “font1.TTF”. The .ttf will work with all android versions.

Then you have to add a TextView in the main.xml or copy the following text and paste it in your main.xml:

<TextView
android:id="@+id/CustomFontTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="What this font looks like">
</TextView>

Then, copy following code and paste it in the .java file just below the setContentView(R.layout.main) :

Typeface tf = Typeface.createFromAsset(getAssets(), "font1.TTF");
TextView tv = (TextView) findViewById(R.id.CustomFontTV);
tv.setTypeface(tf);

 

That’s it

 

, , , , , , , ,

27
Apr

WordPress 1.4 for android is now available in Android Market. Here’s the features:

1. Post Scheduling:- Users can easily set the publish date and time in the app when creating a post.

2. Post Password:- Password field to protect post content.

3. HTTP Authentication Support:- Support for entering the authentication credentials in the blog settings so that you can manage your blog through the app.

4. Added Today Status option

5. Unapproved comments in yellow tint color.

6. Secure password storage to the local database

, , , ,

27
Apr

The following code will show you how to create a custom dialog or pop up window in android:

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

final CharSequence languages[] = {"Chinese", "Spanish", "English",  "Arabic", "Hindi"};

AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("Select Language");
//Adding icon to dialog
dialog.setIcon(R.drawable.icon);

dialog.setSingleChoiceItems(languages, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int selectedIndex) {
Toast.makeText(getApplicationContext(), languages[selectedIndex], Toast.LENGTH_SHORT).show();

}
});

dialog.setNeutralButton("Done", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
//place your code here

}
});

AlertDialog alert = dialog.create();

alert.show();

}

, , , , , , ,

26
Apr

The following script will attach an image (from sdcard) with email in android:

public class EmailActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button sendBtn = (Button) findViewById(R.id.send_btn_id);
sendBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType(“text/html”);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,  new String[]{ “rajeev@schogini.us”} );

//Take image from sdcard and attach with email
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(“file///sdcard/Images/your_image.jpg)”));

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, “Android Mail” );
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, “Hello from android” );

EmailActivity.this.startActivity(emailIntent);
EmailActivity.this.finish();
}
});

}
}

, , , , , , , ,

26
Apr

Here is a simple example for a message notification with a sound as when you click a button.

package com.notify;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class notify extends Activity {

private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

final Notification notifyDetails = new Notification(R.drawable.icon,"New Alert, Click Me!",System.currentTimeMillis());

long[] vibrate = {100,100,200,300};
notifyDetails.vibrate = vibrate;
notifyDetails.defaults =Notification.DEFAULT_ALL;
Context context = getApplicationContext();

Button start = (Button)findViewById(R.id.btn_showsample);
Button cancel = (Button)findViewById(R.id.btn_clear);

start.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

Context context = getApplicationContext();
CharSequence contentTitle = "Schogini Systems. Simple Notification";
CharSequence contentText = "Get back to Application on clicking me";

Intent notifyIntent = new Intent(context, notify.class);

PendingIntent intent =
PendingIntent.getActivity(notify.this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);

mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

}
});

cancel.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

mNotificationManager.cancel(SIMPLE_NOTFICATION_ID);
}
});
}
}

, , , , ,

26
Apr

There are 2 styles available for progress dialog

ProgressDialog.STYLE_SPINNER
ProgressDialog.STYLE_HORIZONTAL
Default style for progress dialog is ProgressDialog.STYLE_SPINNER. Now we are going to see another progress dialog style ( ProgressDialog.STYLE_HORIZONTAL ) .
Horizontal style helps us to show the progress value. For eg:- 34/100 completed. So user can easily know when the progress will completed.

ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setProgress(10);
progressDialog.setSecondaryProgress(34);
progressDialog.setMax(100);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading .....");
progressDialog.show();

setMax() is used to set the progress maximum value.
setProgressStyle() is used to set style for progress dialog.
setSecondaryProgress() is used to set the progress value.

, , , , , ,

26
Apr
File file = new File("/sdcard/file.txt");
boolean deleted = file.delete();

, ,

26
Apr

ClipboardManager interface to the clipboard service, for placing and retrieving text in the global clipboard.
hasText() is used to check whether the clipboard contains text or not. Return value is boolean.
getText() is used to get clipboard text.
setText() is used to set clipboard text.

ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
if (clipboardManager.hasText()) {
Toast
.makeText(
getApplicationContext(),
"Clipboard Text = "
+ clipboardManager.getText().toString(),
Toast.LENGTH_LONG).show();
clipboardManager.setText(null);
} else {
Toast.makeText(getApplicationContext(),
"No Content in Clipboard. Set some text in clipboard",
Toast.LENGTH_LONG).show();
clipboardManager.setText("Schogini Systems");
Toast
.makeText(
getApplicationContext(),
"Clipboard Text = "
+ clipboardManager.getText().toString(),
Toast.LENGTH_LONG).show();
}

, , , , , , , , , , , , , ,