Posts

Show Password in EditText

Hi friends, Have a great day. I comeback after long time.

Ok,  now will look up to show password option in edit text.

Now most of login screens comes up with another cool feature, that's show password.

User want to see their password, until they done editing.


You can use it with checkbox option. It's simple, but you can make it by your way.

@Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
        if(!isChecked){
            edit_password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        }else{
            edit_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
    }

My Map Application

Few days before I created one app, It's a map application. It's not a great application, but simple application.

To load the data from the web, data has too be listed, when you select or click particular user data, load the map with marker.

I tried with my knowledge, but don't expect too much. But it will be useful for beginners and peoples who are trying the map at first time.

Get from the my GITHUB

Store and Get the data from Cache in Android.

It's Interesting, most of peoples thinks about the database, shared preferences and content providers for offline data storage.

Some different came like data must be stored in cache, when app offline, retrieve data from the cache.

Just try this, It might be useful for you.


public String temp_filename = "user_data.txt";
public File tempFile;

// To Store the file in Cache
public void storeToCache(Context context, String data) {
        if (data != null && !data.equals("")) {
            FileWriter writer;
            try {
                writer = new FileWriter(getCacheFile(context));
                writer.write(data);
                writer.close();
                Log.d(TAG, "stored to cache");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}

// To Check the file is exist or not
public boolean isCacheExist(Context context) {
        boolean isExist;
        isExist = getCacheFile(context).exists();
        Log…

Validate the URL

Have a great day friends. Today will look up validating the URL. How to do this?

Most of times, your internet will be working, but sometimes URL to be busy or invalid. In this case, we follow this thing.

 public boolean isServerReachable(Context context, String url) {
        ConnectivityManager connMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = connMan.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnected()) {
            try {
                URL urlServer = new URL(url);
                if(url.startsWith("https")){
                    HttpsURLConnection urlConn = (HttpsURLConnection) urlServer.openConnection();
                    TLSSocketFactory socketFactory = new TLSSocketFactory();
                    urlConn.setSSLSocketFactory(socketFactory);
                    urlConn.setConnectTimeout(3000); //<- 3Seconds Timeout
                    urlConn.connect();
                    if (ur…

Send the data to one app to another app using intent and broadcast - Part 2

Previous post I explain about the sharing the data using broadcast. This post about to share the data using the intents.
By using Intent

In First Application

Intent intent = new Intent(); intent.setClassName("com.sample.app", "com.sample.app.MainActivity"); intent.putExtra("EXTRA_ORDERID", "#4FGT784"); intent.putExtra("EXTRA_ORDERNOTES", "No warranty for this product"); intent.putExtra("EXTRA_ORDERAMOUNT", "270");

PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0); boolean isIntentSafe = activities.size() > 0;
if (isIntentSafe) { startActivity(intent); } else { Toast.makeText(MainActivity.this, "Application not installed", Toast.LENGTH_LONG).show(); }
In Second Application
Bundle vals = getIntent().getExtras(); if (vals != null) { String orderId = vals.getString("EXTRA_ORDERID", ""); String orderNotes = val…

Send the data to one app to another app using intent and broadcast - Part 1

Hi Friends, Have a great day. It's my 75th blog. I'm very slow, but I'm post only necessary and important posts only, hope so.

This time we'll look some manual broadcast message sending from another application, best way to for testing the notifications.

By Using send broadcast.
In First Application
ComponentName componentName = new ComponentName("com.sample.app", "com.sample.app.receiver.NotificationReceiver");
Intent intent = new Intent();
intent.setComponent(componentName);
String message = "Order ID:  #AER46798 ";
intent.putExtra("EXTRA_TITLE", "New Order Received");
intent.putExtra("EXTRA_MESSAGE", message);
sendBroadcast(intent);

In Second Application Receiver
public class NotificationReceiver extends BroadcastReceiver {

    public static String TAG = "PCM";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(TAG, "message_received");
        String title = "&…

Patterns and Regular Expressions

In Java usually validate with some specific characters, we should use Regular Expressions.

Same way in Android, here we use Patterns.

More info about the Patterns: Click here

In android EditText, we can use custom input filter to perform this.

This is for maximum input digits before and after decimal pointer.

CustomInputFilter.Java

public class CustomInputFilter implements InputFilter {
    int maxDigitsBeforeDecimalPoint;
    int maxDigitsAfterDecimalPoint;

    public CustomInputFilter(int maxDigitsBeforeDecimalPoint, int maxDigitsAfterDecimalPoint) {
        this.maxDigitsBeforeDecimalPoint = maxDigitsBeforeDecimalPoint;
        this.maxDigitsAfterDecimalPoint = maxDigitsAfterDecimalPoint;
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        StringBuilder builder = new StringBuilder(dest);
        builder.replace(dstart, dend, source
                .subSequence(start, end).toString());
        if (!builder.toStri…