Thursday, November 21, 2019

Common Hide Keyboard in an application

public static void hideKeyboard(Context context) {
        try {
            InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {
            Log.e(TAG, "Sigh, can't even hide keyboard " + e.getMessage());
        }
    }

Saturday, November 9, 2019

Sending data from one activity to other using Intent



To send data from activity one


                Intent intent=new Intent(this,nextactivity.class);
                intent.putExtra("key ",value);
                context.startActivity(intent);

 To receive data in activity two

Intent intent=getIntent().getextras();

String s =intent.getstring("key provided in class one");


Showing pdf in a webview without downloading


import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.renderscript.Sampler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.ViewGroup;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.amazonaws.Request;

import javax.security.auth.callback.Callback;

public class WebViewActivity extends AppCompatActivity {
    String url;
    WebView webView;
    ProgressDialog progressBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview_pdf);
        url = getIntent().getStringExtra("url");
        webView = findViewById(R.id.webViewpdf);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        progressBar=ProgressDialog.show(this,"","loading");

//"https://docs.google.com/gview?embedded=true&url="  this is the online google viewer

        webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + url);


        webView.setWebViewClient(new WebViewClient() {

// this is used for showing the progress until the page stops loading
            public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }
        });


    }
}

Round image corners at runtime using Glide #android #Glide


Round image corners at runtime using Glide library

In this post, we will check how to make Image corners round at runtime.
               

 RequestOptions requestOptions = new RequestOptions();
   requestOptions = requestOptions.transforms(new CenterCrop(),newRoundedCornersTransformation(39,0,RoundedCornersTransformation.CornerType.TOP_RIGHT));
              
  Glide.with(this)
                        .load(userData.getCoverpicture())
                        .apply(requestOptions)
                        .into(coverpic);

Sending data from one activity to other using bundle

Send data from  Activity

Intent intent =new Intent(this,nextactvitiy.class);
Bundle bundle=new Bundle();
bundle.putString("key",value);
bundle.putString("another key",another value);
intent.putExtras(bundle);
startactivity(intent);


Get data in another Activity

Bundle bundle=getIntent().getExtras();
String s =bundle.getString("key");
String s2=bundle.getString("key2");

Friday, November 1, 2019

Comparing Two dates in Android

 SimpleDateFormat  simpledateformat  = new SimpleDateFormat("yyyy-MM-dd"); 
        Date d1 = simpledateformat  .parse("2018-03-31"); 
        Date d2 = simpledateformat  .parse("2012-03-31"); 
  
        if (d1before  d2) { 
  
            System.out.println("Date1 is before Date2"); 
        } 
  
        else if (d1 after d2) { 
              System.out.println("Date1 is afterrDate2"); 
  
        }



Kindly note:The date formats of both the dates must be same.

Alert Dialog Box

Alert Dialog Box Android AlertDialog   can be used to display the dialog message with OK and Cancel buttons. It can be used to inter...