Posts

Showing posts from January, 2016

How To Get Current Location GPS Using GPSTracker In Android

This project consists of two part, First get current location using GPSTracker to get location by Latitude and Longitude. The location Base on Device or Mobile current location with turn on The GPS on settting Device. Lets begin to build GPSTracker project, First create new android aplication project. Create new java class in your project package GPSTracker.java package sepdian.blog.gpstracker; import java.io.IOException; import java.util.List; import java.util.Locale; import android.app.AlertDialog; import android.app.Service; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.location.Address; import android.location.Geocoder; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.IBinder; import android.provider.Settings; import android.util.Log; ...

Source Code Algorithm String Matching Boyer Moore in Java Android

BoyerMoore.java /** Class BoyerMoore **/ public class BoyerMoore { /** Function to calculate index of pattern substring **/ public static int indexOf(char[] text, char[] pattern) { if (pattern.length == 0) return 0; int charTable[] = makeCharTable(pattern); int offsetTable[] = makeOffsetTable(pattern); for (int i = pattern.length - 1, j; i < text.length;) { for (j = pattern.length - 1; pattern[j] == text[i]; --i, --j) if (j == 0) return i; // i += pattern.length - j; // For naive method i += Math.max(offsetTable[pattern.length - 1 - j], charTable[text[i]]); } return -1; } /** Makes the jump table based on the mismatched character information **/ private static int[] makeCharTable(char[] pattern) { final int ALPHABET_SIZE...

MargeAdapter ListView in Android

This will help you when populate listview data with one or two even more adapter. Combine two adapter in listview with diferent data. Create new android project and make new xml file in your layout folder. activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.margeadapter.MainActivity" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent...

How To Generate Random String Without Duplicate Values In Java Android

Random string is needed when testing some variable in java. Random String without duplicate values will help vaeriable more valid while testing. This code below will string and put them in TextView widget. public static String getRandomString(int length) { StringBuilder result = new StringBuilder(); String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; Random rand = new Random(); while(length > 0) { String h = String.valueOf(characters.charAt(rand.nextInt(characters.length()))); if(!result.toString().contains(h)){ result.append(h); length--; } Log.d ("yy",characters); } return result.toString(); } This java code below is how to use that function textView.setText(getRandomString(20));

How To Generate A Random String Alphabet And Number in Java Android

The following java code below used to generate random string in java android. This function can use Alphabet or number format as string. Random string can be helpful when need to runing unit test. public static String getRandomString(int length) { StringBuilder result = new StringBuilder(); String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; Random rand = new Random(); while(length > 0) { String h = String.valueOf(characters.charAt(rand.nextInt(characters.length()))); result.append(h); length--; } return result.toString(); }

How To Scaling Bitmap To Screen Density in Android

Sometimes when loading an image that you are working with limited memory, ideally you only want to load a lower resolution drawable image in memory. The lower resolution of image should match the size of the screen displays it. An image with a higher resolution does not provide any visible benefit, but still takes up precious memory and incurs additional performance overhead due to additional on the fly scaling. Now i will share how to scaling image with any kind size to without losing quality of the bitmap image , Hope will save your time for code . Scalling Bitmap Codes for Java Android Add code bellow inside your class public void loadBitmap(int resId, ImageView imageView) { final String imageKey = String.valueOf(resId); final Bitmap bitmap = getBitmapFromMemCache(imageKey); if (bitmap != null) { imageView.setImageBitmap(bitmap); } else { imageView.setImageResource(R.drawable.ic_launcher); Bi...

How To Create And Use Custom Shape in Android Drawable

One of the beauties of the Android resource system is that the background of any view like Button, TextView, ListView and other views, can be a Drawable an XML File. Drawables can be images, colors, transitions, shapes, gradient, border, corner and a variety of other powerful sources. It is often possible to create a really nice looking background images just by using Shape Drawables. Shape Drawables are XML declarations of a graphical shape which is interpreted at run-time by the Android system and rendered as a graphic. It's very simple to create and used shape in android drawable. First create new android project and make new folder under res folder called drawable res/drawable. Create new xml file you give name as your needed. btn_shape_rectangle.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color=...

How To Create Layerlist in Drawable Android

Create custom drawable xml using layerlist in android to make our layout more interesting. Not only use shape background button image as background button and sometimes combine between drawable gardient , drawable selector amd layerlist to make shadows effect in android layout linearlayout or relativelayout and listview item background using layerlist.  Now we will make new android project to implement drawables xml with layerlist and use it to button background. First you need to create new android project and make new folder under res folder  in your project. Create new XML File with name btn_layerlist.xml btn_layerlist.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle"> <solid android:color="#1C59A9"/> </shape> </item> </layer-list...

Read/Write Csv File in Android

Android function for getting csv file data and inserting them to array. First step create java file inside your package CscArray.java CsvArray.java com.example.loadcsvfile public class CsvArray { private String Name; private String Age; private String Gender; public CsvArray (String Name, String Age, String Gender){ this.Name= Name; this.Age= Age; this.Gender= Gender; } public String getName() { return Name;} public void setName(String Name) {this.Name = Name;} public String getAge() { return Age;} public void setAge(String Age) {this.Age = Age;} public String getGender() { return Gender;} public void setGender(String Gender) {this.Gender = Gender;} } Now put source code bellow to your adapter class if you want to use csv data as listview item private void loadCsvFile(){ try { InputStream is = ctx.getAssets...