Posts

Android Versions details

Android Version Name / API Level Released Date Released Features 1 Android Alpha - API 1 Sep 23, 2008   1.1 Android Beta – API 2 Feb 9, 2009 Support for third party keyboards Video Recording Playback 1.5 Cupcake – API 3 Apr 27, 2009 Android version get a desert nickname 1.6 Donut – API 4 Sep 15, 2009 Support for CDMA technology Support for different screen sizes Battery usage indicator 2 Eclairs – API 5 to 7 Oct 26, 2009 Improved UI with search bar on the top Support for HTML5 2.2 Froyo – API 8 May 20, 2010 Improved performance than Eclairs 2.3 Gingerbread – API 9 to 10 Dec 6, 2010 Supports VOIP and NFC4 3 Honeycomb – API 11 to 13 Feb 22, 2011 Supports for Android tablets 4 Ice Cream Sandwich – API 14 to 15 Oct 18, 2011 ...

English - Formal and Informal words

 The following English words could be used when you are in official discussion with your customer or supervisors. This is for quick reference.  Informal to Formal  Give - replaced with Provide Can you provide more information?  Childish -  replaced with  Immature Maybe  -  replaced with  Perhaps Hungry -  replaced with  Famished Problems -  replaced with  Challenges Good -  replaced with  Positive Danger -  replaced with  Peril Stubborn -  replaced with  Obstinate Put off -  replaced with  Postpone Here -  replaced with  Present Help  -  replaced with  Assist Start  -  replaced with Commence Mad  -  replaced with Insane Go up  -  replaced with Increase Tough  -  replaced with Difficult Book  -  replaced with Reserve

Android - Adding libraries to gradle file - quick reference

        The following lines of codes, which helps you to add the Gradle dependencies for your project quickly. I have listed out the widely used Gradle dependencies. Please let me know in the comment section if you like to add any other libraries. Let's check.. //Constraint Layout implementation 'androidx.constraintlayout:constraintlayout:1.1.3' //Material Design implementation 'com.google.android.material:material:1.3.0-alpha02' //Kotlin Coroutines implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8" //Retrofit - for async API calls implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' //Lifecycle  implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' //Kodein - Dependency Injection framework implementation 'com.eygraber:kodein-di-generic-jvm:5.2.1' implemen...

Edit text with clear button in Android app

This simple example would help you to create a edit text with clear button EditText editText = (EditText) findViewById(R.id.Editdob); drawable created to assign in edit text (in Activity/Fragment) final Drawable drawable = getResources().getDrawable( R.drawable.clear_edit_text); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); editText.setCompoundDrawables(null, null, drawable, null); ImageView crossImageView = new ImageView(this); crossImageView.setImageDrawable(drawable); On touch listener for edit text (in Activity/Fragment) editText.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent arg1) { if (arg1.getX() > editText.getWidth() - drawable.getIntrinsicWidth() - 10) editText.setText(""); } return false; } });

Java Synchronized Keyword

The synchronized is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the synchronized keyword indicates the following :   ** The synchronized keyword may be applied to statement block or to a method. **  The synchronized keyword provides the protection for the crucial sections   that are required only to be executed by a single thread once at a time. **   The synchronized keyword avoids a critical code from being executed by more than one thread at a time. Its restricts other threads to concurrently access a resource. ** If   the synchronized keyword is applied to a static method, as we will show it with a class having a method SyncStaticMethod through an example below, the entire class get locked while the method under execution and control of a one thread at a time. **   When the synchronized keyword is applie...

Android camera intent using (StartActivityForResult)

private static final int CAMERA_CODE = 0; // This method is used to call the camera activity. private void cameraIntent(){ final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getFile(this)) ); startActivityForResult(intent, CAMERA_CODE); } //create a temporary file in sd card path. private File getFile(Context context){ final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() ); if(!path.exists()){ path.mkdir(); } return new File(path, "image.tmp"); } //This method is used to getresult from another activity. @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == CAMERA_CODE) { final File file = getFile(this); try { Bitmap captureBmp = Media.getBitmap(getContentResolver(), Uri.fromFile(file) ); // do whatever you want with the bitmap (Resize, Rename, Add ...

Android datepicker update current day

private DatePickerDialog datePicker; private TextView _my_text_view; private Calendar _calendar = Calendar.getInstance(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // on start up it will show the date picker dialog. // you can call this method anywhere in your activitiy showDialog(DATE_DIALOG_ID); } /** * Create the date picker Dialog. */ @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID:   datePicker = new DatePickerDialog (this,  dateSetListener, year, month, day);   return datePicker; } return null; } /** * Get the values from the datepicker. */ private DatePickerDialog.OnDateSetListener dateSetListener =  new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth){ year = year; month = monthOfYear; day = dayOfMonth;...

Input filter (space not allowed) for EditText

This example which prevent the user to enter blank space in edit text field in Android app  EditText.setFilters(new InputFilter[] { filter }); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.isSpaceChar(source.charAt(i))) { return ""; } } return null; } }

Android get date after 7 days

Date currentDay = new Date(); // Add milliseconds to your current day Date seventhDay = new Date  (currentDay.getTime + 604800000L ); // 7*24*60*60*1000 or Use the calendar api Calendar calendar = Calendar.getInstance(); calendar.setTime(myDate); calendar.add(Calendar.DAY_OF_YEAR, 7); Date seventhDay = calendar.getTime();

Android button with background

Image
     If you want to create a background for UI components like Buttons or Edit Text etc., First you have to create xml file in your drawable folder. yellow_border_gradient.xml <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#FFEC8B" android:endColor="#FFFFFF" android:angle="90"/> <stroke android:width="1dip" android:color="#8E8E8E" /> <corners android:radius="5dip" /> <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> </shape>      After creating the folder you can use the above code for designing, after saving your xml. you can call your xml in your button or any UI component. for example shown below <Button android:textSize="14...

Android create temporary file in sd card

private File getTemporaryFile(Context context){ //it will return /sdcard/yourImage.tmp final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() ); if(!path.exists()){ path.mkdir(); } return new File(path, "yourImage.tmp"); }

Android Database Example

Database Class import java.util.ArrayList; import java.util.List; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; import android.util.Log; public class DatabaseHelper { private static final String DATABASE_NAME = "firstdatabase.db"; private static final int DATABASE_VERSION = 1; private static final String TABLE_NAME = "mytable"; private Context context; private SQLiteDatabase sqlDb; private SQLiteStatement insertStatement; private static final String INSERT = "insert into " + TABLE_NAME + "(name) values (?)"; public DatabaseHelper(Context context) { this.context = context; OpenHelper openHelper = new OpenHelper(this.context); this.sqlDb = openHelper.getWritableDatabase(); this.insertStatement = this.sqlDb.compileStatement(INSERT); } public long insert(Strin...

Java Singleton Class

The Singleton class’s default constructor is made private,  which prevents the direct instantiation of the object by other classes using the new keyword. The Singleton is a useful Design Pattern for allowing only one instance of your class, but common mistakes can inadvertently allow more than one instance to be created.

JSON Object

JSON (JavaScript Object Notation) is a lightweight computer data interchange format.  It is a text-based, human-readable format for representing simple data structures and  associative arrays (called objects).  The JSON format is often used for transmitting structured data over a network connection  in a process called serialization. Its main application is in AJAX web application  programming, where it serves as an alternative to the traditional use of the XML format. Supported Data types are ( String, Number, Boolean,Array,  Object (Collection of key/value Pairs), null ). Example import net.sf.json.JSONObject; public class MyJSON { public static void main(String args[]){ JSONObject object=new JSONObject(); object.put("name","your Name"); object.put("Max.Marks",new Integer(100)); object.put("Min.Marks",new Double(35)); object.put("Scored",new Double(86.67)); object.put("nickname","your...

Change Apache Tomcat Port Number

 Tomcat runs on port 8080. But there can be situations where there are some other servers running on this same port, forcing you to change the port of one of the servers. Go to your tomcat installed path. C:\..............\Tomcat 6.0\conf\server.xml In the server.xml file; locate the following segment. <Connector port="8080" … /> By Changing this 8080 port number to your new port number.

Android Notes

Activity: Your applications presentation layer.  Every screen in your application will be an extension of activity.  It is nothing but a visible screen. (Layouts, Views) Intent: An inter-application message-passing framework. Intent is an abstract description of an operation  to be performed. Intent provides a facility for performing late runtime binding between the codes  in different applications. Intent Filter: An intent filter declares the capabilities of its parent component. Broadcast receiver: Application - receive and respond to a global event, such as the phone ringing or an  incoming text message. Broadcast Receivers will automatically start your application to  respond to an Incoming Intent, making them perfect for creating event-driven applications. Layouts: Template of view objects.Some Layouts are Absolute Layout, Frame Layout, Linear Layout,  Relative Layout. Android manifest.xml This XML file describes where your appl...

Android menu creation and implementation

To create a menu resource, create an yourmenu.xml  file inside your project's  res/menu/  directory yourmenu.xml   <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_next" android:icon="@drawable/icon_next" android:title="Next" /> <item android:id="@+id/menu_back" android:icon="@drawable/icon_back" android:title="Back" /> </menu> Creation   @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.yourmenu, menu); return true; } If menu item selected.. @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_next: //your code here.. return true; default: return super.onOptionsItemSelected(item)...

Android Progress Dialog using runnable

Following code will create a progress dialog and run using ruunable interface. final ProgressDialog dialog = ProgressDialog.show(Activity.this, "Your Message", "Status Message",true); Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { startActivity(new Intent(MyActivity.this, YourActivity.class)); dialog.dismiss(); } }; handler.postDelayed(runnable, 3000);

Android Button onClickListener

Button button = (Button) findViewById(R.id.your_button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(firstActivity.this, "Message by Donor", Toast.LENGTH_SHORT).show(); } });

Android Intent

Intents are used as a message passing mechanism. It works within your application, between the applications.  One of the most common uses for intents is to start new activities. It is either explicitly (by specifying the class to load) or implicitly (by requesting that an action be performed on a piece of data). Explicit Intent startActivity(new Intent(FirstActivity.this,SecondActivity.class)); Implicit Intent Intent intent = new Intent (Intent.ACTION_DIAL, Uri.parse ("tel: 123-4567")); StartActivity (intent);