Featured post

Marshmallow Features Point by Point

Android Runtime (“ART”) Improved application performance and lower memory overhead for faster  multi-tasking. Battery Doze...

Friday, 23 September 2016

Captured Image Rotate Issue





ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
        ExifInterface.ORIENTATION_UNDEFINED);

switch(orientation) {
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotateImage(bitmap, 90);
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotateImage(bitmap, 180);
        break;
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotateImage(bitmap, 270);
        break;
    case ExifInterface.ORIENTATION_NORMAL:
    default:
        break;
}


==========

public static Bitmap rotateImage(Bitmap source, float angle) {
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix,
            true);
}

Wednesday, 3 August 2016

Use Filter/Search with EditText,Spinner

Adapter
===============

public class Adpt_ChartingTemplate extends BaseAdapter implements Filterable {
    private Context context;
    private LayoutInflater mInflater;

    private SHSact_Main shSact_main;
   

    private ArrayList<SHScl_ChartingTemplates> arrayListChartingTemplateMain=new ArrayList<SHScl_ChartingTemplates>() ;
    private ArrayList<SHScl_ChartingTemplates> arrayListChartingTemplateFilter=new ArrayList<SHScl_ChartingTemplates>() ;

    public Adpt_ChartingTemplate(SHSact_Main shSact_main, ArrayList<SHScl_ChartingTemplates> arrayList_ChartingTemplate) {

        this.context = shSact_main.getApplicationContext();
        this.shSact_main = shSact_main;
        mInflater = LayoutInflater.from(context);
        this.arrayListChartingTemplateMain = arrayList_ChartingTemplate;
        this.arrayListChartingTemplateFilter = arrayList_ChartingTemplate;
    }


    @Override    public int getCount() {
        return arrayListChartingTemplateFilter.size();
    }

    @Override    public Object getItem(int position) {
        return arrayListChartingTemplateFilter.get(position);
    }

    @Override    public long getItemId(int position) {
        return position;
    }

    @Override    public View getView(final int position, View convertView, ViewGroup parent) {

        final ListContent holder;
        View v = convertView;
        if (v == null) {
            v = View.inflate(context, R.layout.listitem_charting_template, null);
            holder = new ListContent();

            holder.txt_name = (TextView) v.findViewById(R.id.listitem_charting_template_txt_name);
         

            v.setTag(holder);
        } else {
            holder = (ListContent) v.getTag();
        }

        holder.txt_name.setText(arrayListChartingTemplateFilter.get(position).template_name);
        
        return v;
    }

    @Override    public Filter getFilter() {
        return new ItemFilter();
    }


    private class ListContent {

        TextView txt_name,txt_specialization;
    }
    private class ItemFilter extends Filter {
        @Override        protected FilterResults performFiltering(CharSequence constraint) {

            String filterString = constraint.toString().toLowerCase();

            FilterResults results = new FilterResults();

            final List<SHScl_ChartingTemplates> list = arrayListChartingTemplateMain;

            int count = list.size();
            final ArrayList<SHScl_ChartingTemplates> nlist = new ArrayList<SHScl_ChartingTemplates>(count);

            String filterableString;

            for (int i = 0; i < count; i++) {
                filterableString = list.get(i).template_name;
            
                if (filterableString.toLowerCase().contains(filterString)) {
                    nlist.add(list.get(i));
                }
            }

            results.values = nlist;
            results.count = nlist.size();

            return results;
        }

        @SuppressWarnings("unchecked")
        @Override        protected void publishResults(CharSequence constraint, FilterResults results) {
            arrayListChartingTemplateFilter = (ArrayList<SHScl_ChartingTemplates>) results.values;
            notifyDataSetChanged();
        }

    }

}

EditText
========================

edt_searchByName.addTextChangedListener(new TextWatcher() {

    @Override    public void onTextChanged(CharSequence s, int start, int before, int count) {
        adpt_ChartingTemplate.getFilter().filter(s.toString());
    }

    @Override    public void beforeTextChanged(CharSequence s, int start, int count,
                                  int after) {

    }

    @Override    public void afterTextChanged(Editable s) {
    }
});

// Same like with onItemSelectedLitner method of Spinner you can do.

Friday, 15 July 2016

Get date as your choice date format

Get Date String from Existing/Current String Date  
==================


public String getDateStringFromFormatString(String strdate,String formate,String formate1) {
    Date date = Calendar.getInstance().getTime();

    if (!strdate.equalsIgnoreCase("")) {
        SimpleDateFormat formatCompare = new SimpleDateFormat(formate1);
        try {
            date = formatCompare.parse(strdate);
        } catch (ParseException e) {
            date = Calendar.getInstance().getTime();
            e.printStackTrace();
        }

    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formate, Locale.getDefault());
    return simpleDateFormat.format(date);
}


Call
================

getDateStringFromFormatString("","MMM dd, yyyy",""); // get current date in your format