Skip to main content

Posts

Showing posts from February, 2013

Android Database Example1

Project Name : SQLiteStorageOption  Activity Name :MainActivity  PackageName : com.rakesh.sqlitestorageoption  we need to create 4 java classes and 4 xml files .     MainActivity.java    package com.rakesh.sqlitestorageoption; import java.util.ArrayList; import java.util.HashMap; import com.rakesh.sqlitestorageoption.DBController; import com.rakesh.sqlitestorageoption.NewAnimal; import android.os.Bundle; import android.app.ListActivity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ListAdapter; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.ListView; public class MainActivity extends ListActivity {     Intent intent;     TextView animalId; ...

Toast With Image

package com.AndroidImageToast; import android.app.Activity; import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class AndroidImageToast extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Toast ImageToast = new Toast(getBaseContext()); LinearLayout toastLayout = new LinearLayout(getBaseContext()); toastLayout.setOrientation(LinearLayout.HORIZONTAL); ImageView image = new ImageView(getBaseContext()); TextView text = new TextView(getBaseContext()); image.setImageResource(R.drawable.icon); text.setText("Hello!"); toastLayout.addView(image); toastLayout.addView(text); ImageToast.setView(toastLayout); ImageToas...

Get Battery Level in your app

I've searched and found a sample to get battery level in the screen . What is Broadcast Receivers? Broadcast Receivers is an Android implementation of system-wide publish/subscribe mechanism. The system itself broadcasts events all the time. For example, when an SMS arrives, or call comes in, or battery runs low, or system gets booted, all those events are broadcasted and any number of receivers could be triggered by them. You can also send your own broadcasts from one part of your application to another, or a totally different application. Broadcast receivers themselves do not have any visual representation nor are they actively running in memory. But when triggered, they get to execute some code, such as start an activity, a service, or something else what we defined. To know battery level , I used the following snippet in onCreate() method, registerReceiver("put your Broadcast receiver object here", new IntentFilter(Intent.ACTION_BATTER...

Rotate an Image using Bitmap

I've tried to findout the solution to tilt the Image for 45 degree .I found in a few minutes. Here is one of the way we can do, In XML create your Imageview and set your desired attributes as shown below, and then our Java file will be , public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* this.requestWindowFeature(Window.FEATURE_NO_TITLE); */ setContentView(R.layout.activity_main); ImageView im=(ImageView)findViewById(R.id.imageButton1); /* this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);*/ im.setImageDrawable(rotateImage(this)); } public Drawable rotateImage(Context ctx) { // load the origial Bitmap Bitmap BitmapOrg = BitmapF...

Draw Shapes using XML

we can draw the Shape using ShapeDrawable class . I've here Created a class which Inherited View Class. We can do View our shape using setContentView() Method. we can call our view(shape) inside that method using xml or java Lets Start to do one by one , Now we need to create our view, package com.example.drawwithxml; import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.util.AttributeSet; import android.view.View; public class MyView extends View { private ShapeDrawable mDrawable; public MyView(Context context,AttributeSet a) { super(context,a); int x = 10; int y = 10; int width = 300; int height = 50; mDrawable = new ShapeDrawable(new OvalShape()); mDrawable.getPaint().setColor(0xff74AC23); mDrawable.setBounds(x, y, x + width, y + height); } protected void onDraw(Canvas canvas) { mDrawable.draw(canvas); } } onDraw() method is very Important. ...