Skip to main content

Posts

Drag and drop image in android

Ever wonder how to drag and drop in android. Lets check how to drag and drop image in android. MainActivity.java package com.example.dragdrop; import android.app.Activity; import android.content.ClipData; import android.content.ClipDescription; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.os.Bundle; import android.util.Log; import android.view.DragEvent; import android.view.MotionEvent; import android.view.View; import android.view.View.DragShadowBuilder; import android.view.View.OnClickListener; import android.view.View.OnDragListener; import android.view.View.OnTouchListener; import android.widget.ImageView; import android.widget.SeekBar; import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.SeekBar.OnSeekBarChangeListener; public class MainActivity extends Activity { ImageView img_model, img_chain; private static final String IMAGEVI

How to implement a fragment in Android

 We can call fragment as a sub activity. By using fragment navigation will more easier and in tabs layouts look cool.Let us see an example..... Here we have 2 fragment class Details, and Detail2. MainActivity.java import android.app.Activity; import android.app.Fragment; import android.app.FragmentTransaction; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Here we call the first fragment Fragment fragment = null; fragment = new Options(); FragmentTransaction fragmentTransaction = getFragmentManager() .beginTransaction(); fragmentTransaction.replace(R.id.frame1, fragment).commit(); } } Options.java import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View

How to create a flash light on Android

I always wonder the use of a flash light on a phone. This simple app is more useful than anything. So here is the code to build a flashlight app, MainActivity.java import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.Parameters; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageButton; public class MainActivity extends Activity { ImageButton btnSwitch; private Camera camera; private boolean isFlashOn; private boolean hasFlash; Parameters params; MediaPlayer mp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // flash switch button