import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Thursday, 1 May 2014
Android Activity Creation without XML Design
How to Get Thunderbird Email Messages Into Outlook
- Open Thunder bird. Mail
- Select the messages you want to export to Outlook.
How many you can export will depend on the size of each message and its
attachments as well as the capability of your Internet connection and
provider.
- After selecting the messages, right click and select "Forward as Attachments." A new mail message will open up with the email messages you selected as attachments. Enter the email address you are using with Outlook and press send.
- Open the email containing the
email message attachments and move this active window down a bit on
your screen so you can see your main inbox area in Outlook.
- Select All Attachments that contains ThunderBird mails as Attachments then Drag it into your Inbox or any Folder . Finally you got it.
How to Delete All Lines Containing a Unwanted Words from Text File?
- Go to Search menu > Find... > Select "Mark" Tab. Enter Search Text in Find what Search Box or Activate regular expressions. Search for
^<Path>(^is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"
==> All Rows you want to keep got a Bookmark - Go to Menu "Search - Bookmark - Remove Bookmarked lines"
==> All Bookmarked lines are deleted.
How to delete lines except lines which containing wanted word?
- Go to Search menu > Find... > Select "Mark" Tab. Enter a Text in Find what search box or Activate regular expressions. Search for
^<Path>(^is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"
==> All Rows you want to keep got a Bookmark - Go to Menu "Search - Bookmark - Inverse Bookmark"
==> All Line you want to delete are bookmarked. - Go to Menu "Search - Bookmark - Remove Bookmarked lines"
==> All Bookmarked lines are deleted.
Saturday, 11 January 2014
Android Fundamentals
- Activity
- Service
- Broadcast Receiver
- Content Provider.
An activity represents a single screen with a user interface.
The user can interact with the activity i.e. click the button.
A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.
Example:
Listening Music is the service. Because no user interaction is neccessary to play music. Once you start it will playing all the songs.
A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access.
Example:
Consider that you are going to develop message sending application. For choosing the contacts you need to add contacts one by one in your application.
Instead of that you just share the contact which is in your phone contacts.
A broadcast receiver is a component that responds to system-wide broadcast announcements.
Example:
It reacts some thing, when the phone receive any messages or phone etc.
Thursday, 9 January 2014
MD5 Encryption in Android
MD5 Encryption in Android
1.Md5.javapackage com.JavaPages4All.md5encryption;
import java.security.MessageDigest;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Md5 extends Activity
{
EditText textview;
Button get;
TextView textlbl;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.md5);
textview=(EditText)findViewById(R.id.textview);
get=(Button)findViewById(R.id.get);
textlbl=(TextView)findViewById(R.id.textlbl);
get.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
String strpassword=textview.getText().toString();
if(strpassword!=null && strpassword.trim().length()!=0)
{
String md5=getMD5Encryption(strpassword);
textlbl.setText(md5);
}
}
});
}
public String getMD5Encryption(String strpassword)
{
try
{
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(strpassword.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++)
{
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (Exception e)
{
e.printStackTrace();
}
return "";
}
}
|
2.md5.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter String"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/get"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get MD5" />
<TextView
android:id="@+id/textlbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Md5 string"
android:textColor="#ff00ff"
android:textSize="20sp" />
</LinearLayout>
Hide the Title Bar and Status Bar in Android
Hide the Title Bar and Status Bar in Android
1.Hide the Title Bar Using AndroidManifest.xml
If you want to hide the title bar for particular Activity
use the below code in AndroidManifest.xml within the <activity> tag.
android:theme="@android:style/Theme.Black.NoTitleBar"
android:theme="@android:style/Theme.Black.NoTitleBar"
Example:
<activity
android:name=" MainScreen"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar " >
Hide the Title Bar and Status Bar Using XML code.
If you want to hide the Title Bar and Status Bar for particular activity, use the below code in AndroidManifest.xml within the <activity> tag.
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
Example:
<activity
android:name=" MainScreen"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen " >
Hide the Title Bar and Status Bar for entire Application Using XML code.
If you want to hide the Title Bar and Status Bar for entire application,just use the above code in <application> tag.
Example:
for hiding title bar:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" >
for hiding title and status bar:
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
Working in Java file using java code
Hide the Title Bar Using java code.
If you want to hide the title bar for particular activity, use this java code above the setContentView() method.
requestWindowFeature(Window.FEATURE_NO_TITLE);
Android Spinner View Text Not Visible
Android Spinner View Text Not Visible
(White background on Text Also showing White Color)
---------------------------------------------------------------------------------------------------------------------------------
|
Replace getApplicationContext() to getBaseContext()
(OR)
Replace getApplicationContext() to this (if above is not working)
(OR)
Replace getApplicationContext() to getActivity() (if you are Using Fragment)
Wednesday, 8 January 2014
Mutable and Immutable Object in Java
package raja.JavaPages4All;
import java.util.Date;
/**
* @author Raja(JavaPages4All)
*/
public class TestPojo
{
private String blogName;
private Date date;
public TestPojo(String blogName,Date date)
{
this.blogName=blogName;
this.date = date;
}
public String getBlogName()
{
return this.blogName;
}
public Date getDate()
{
return this.date;
}
}
|
package raja.JavaPages4All;
import java.util.Date;
public class ImmutableTest
{
/**
* @author Raja(JavaPages4All)
*/
public static void main(String[] args)
{
/*
* String Class is Immutable.
* Date Class is Mutable.
*/
String str="JavaPages4All";
Date myDate = new Date();
TestPojo pojo =new TestPojo(str,myDate);
/**
* Getting Values from TestPojo Reference Object(When First Time)
*/
System.out.println(pojo.getBlogName());
System.out.println( pojo.getDate() );
/**
* String str Object value changing so it is Creating Newly(Immutable).
* Date myDate Object value changing so it is Updated the
* Previous Object myDate Value(Mutable)
*/
str="Raja";
myDate.setMonth( myDate.getMonth() + 1 );
/**
* Getting Values from TestPojo Reference Object
* (When Second Time object Values Changed)
*/
System.out.println(pojo.getBlogName()+" "+str);
System.out.println( pojo.getDate() );
}
}
|
Mutable vs Immutable in Java
Mutable Objects: When you have a reference to an instance of an object, the contents of that instance can be altered
Immutable Objects: When you have a reference to an instance of an object, the contents of that instance cannot be altered
(OR)
Immutable objects are simply objects whose state (the object's data) cannot change after construction
Immutability and Instances
To demonstrate this behaviour, we'll use java.lang.String as the immutable class and java.awt.Point as the mutable class.package raja.JavaPages4all;
import java.awt.Point;
public class Immutability
{
/**
* @author Raja(JavaPages4All)
* @param args
*/
public static void main(String[] args)
{
Point pt= new Point( 0, 0 );
System.out.println( pt);
pt.setLocation( 1.0, 0.0 );
System.out.println( pt);
String str= new String( "old String" );
System.out.println( str);
str.replaceAll( "old", "new" );
System.out.println( str);
}
}
|
java.awt.Point[0.0, 0.0] java.awt.Point[1.0, 0.0] old String old String
We are only looking at a single instance of each object, but we can see that the contents of pt has changed, but the contents of str did not. To show what happens when we try to change the value of str, we'll extend the previous example.
package raja.JavaPages4all;
import java.awt.Point;
public class Immutability
{
/**
* @author Raja(JavaPages4All)
* @param args
*/
public static void main(String[] args)
{
Point pt= new Point( 0, 0 );
System.out.println( pt);
pt.setLocation( 1.0, 0.0 );
System.out.println( pt);
String str= new String( "old String" );
System.out.println( str );
str= new String( "new String" );
System.out.println( str );
}
}
|
old String new StringNow we find that the value displayed by the str variable has changed. We have defined immutable objects as being unable to change in value, so what is happening? Let's extend the example again to watch the str variable closer.
package raja.JavaPages4all;
public class Immutability
{
/**
* @author Raja(JavaPages4All)
* @param args
*/
public static void main(String[] args)
{
//Comparison
String str = new String( "old String" );
String myCache = str ;
System.out.println( "String Comparison: " + str.equals( myCache ) );
System.out.println( "Object Comparison: " + ( str == myCache ) );
str = "not " + str ;
System.out.println( "String Comparison: " + str.equals( myCache ) );
System.out.println( "Object Comparison: " + ( str == myCache ) );
}
}
|
String Comparison: true Object Comparison: true String Comparison: false Object Comparison: falseWhat this shows is that variable str is referencing a new instance of the String class. The contents of the object didn't change; we discarded the instance and changed our reference to a new one with new contents.
Subscribe to:
Posts (Atom)