Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday 29 December 2016

Difference between two date in android



package com.samset.user.sample;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.TimeUtils;
import android.view.View;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String first="12/29/2016 09:29:58 AM"
        String second="12/29/2016 09:29:58 PM"

        String SubscriptionEndTime = first;
        String currentTime = "12/29/2016 04:31:48 PM";

        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a", Locale.ENGLISH);

        try {
            Date date = dateFormat.parse(currentTime);
            Date date1 = dateFormat.parse(SubscriptionEndTime);

             Log.d("difference>>>",computeDiff(date,date1).toString());


        } catch (ParseException e) {
            e.printStackTrace();
        }

    }


    public static Map<TimeUnit,Long> computeDiff(Date date1, Date date2) {
        long diffInMillies = date2.getTime() - date1.getTime();
        List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
        Collections.reverse(units);
        Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
        long milliesRest = diffInMillies;
        for ( TimeUnit unit : units ) {
            long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
            long diffInMilliesForUnit = unit.toMillis(diff);
            milliesRest = milliesRest - diffInMilliesForUnit;
            result.put(unit,diff);
        }
        return result;
    }

}


output:-

Result 1:-  difference>>>:

DAYS=0,
HOURS=-7,
MINUTES=-1,
SECONDS=-50,
MILLISECONDS=0,
MICROSECONDS=0,
NANOSECONDS=0


Result 2:- difference>>>:

DAYS=0,
HOURS=4,
 MINUTES=58,
 SECONDS=10,
 MILLISECONDS=0,
 MICROSECONDS=0,
 NANOSECONDS=0



Monday 26 December 2016

Android icon size



Launcher icons    
                             
48 × 48 (mdpi)
72 × 72 (hdpi)
96 × 96 (xhdpi)
144 × 144 (xxhdpi)
192 × 192 (xxxhdpi)
512 × 512 (Google Play store)

Action bar, Dialog & Tab icons

24 × 24 area in 32 × 32 (mdpi)
36 × 36 area in 48 × 48 (hdpi)
48 × 48 area in 64 × 64 (xhdpi)
72 × 72 area in 96 × 96 (xxhdpi)
96 × 96 area in 128 × 128 (xxxhdpi)
Optical image size 24dip

Small Contextual Icons

16 × 16 (mdpi)
24 × 24 (hdpi)
32 × 32 (xhdpi)
48 × 48 (xxhdpi)
64 × 64 (xxxhdpi)
Optical image size 16dip

SH1 release and debug mode in android


Hello friends

Debug mode

keytool -list -alias androiddebugkey -keystore "C:\Users\user\Desktop\tickeystore.keystore" -storepass android -keypass android

above highlighted point replace your keystore path


When you are upload sign apk in play store then need to generate release mode sh1 code 

Release mode

keytool -list -alias Tiktokgames -keystore "C:/Users/user/Desktop/tickeystore.jks" -storepass indian -keypass indian


above highlighted point replace your keystore path

Thank you

Saturday 10 December 2016

Sectional recyclerview android

Hello friends
Today i am introduced how to make sectional recyclerview without use any external library
If you search in google sectional recyclerview then you find more sample with external lib but i am find better solution. So lets start and improve our programming performance....

activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

ActvityMain.java

package com.samset.headerrecyclerviewsample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;

import com.samset.headerrecyclerviewsample.adapter.SectionalAdapter;
import com.samset.headerrecyclerviewsample.model.model.CountryState;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        super.onStart();

        SectionalAdapter adapter = new SectionalAdapter(getData());

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, OrientationHelper.VERTICAL, false);
        RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setAdapter(adapter);
    }

    public List<CountryState> getData() {
        List<CountryState> list = new ArrayList<>();

        list.add(new CountryState("India", null, CountryState.COUNTRY_TYPE));
        list.add(new CountryState("Allahabad", "1", CountryState.CITY_TYPE));
        list.add(new CountryState("Bharatpur", "2", CountryState.CITY_TYPE));
        list.add(new CountryState("Patna", "3", CountryState.CITY_TYPE));
        list.add(new CountryState("Mumbai", "4", CountryState.CITY_TYPE));
        list.add(new CountryState("Jaipur", "5", CountryState.CITY_TYPE));

        list.add(new CountryState("Pakistan", null, CountryState.COUNTRY_TYPE));
        list.add(new CountryState("Karachi", "6", CountryState.CITY_TYPE));
        list.add(new CountryState("Ishlamabad", "7", CountryState.CITY_TYPE));
        list.add(new CountryState("Bluechistan", "8", CountryState.CITY_TYPE));
        list.add(new CountryState("Sindhu", "9", CountryState.CITY_TYPE));
       
        list.add(new CountryState("Russiya", null, CountryState.COUNTRY_TYPE));
        list.add(new CountryState("Mascow", "10", CountryState.CITY_TYPE));
        list.add(new CountryState("Abaza", "11", CountryState.CITY_TYPE));
        list.add(new CountryState("Baley", "12", CountryState.CITY_TYPE));
        list.add(new CountryState("Barysh", "13", CountryState.CITY_TYPE));
        list.add(new CountryState("Bely", "14", CountryState.CITY_TYPE));
        list.add(new CountryState("Bobrov", "15", CountryState.CITY_TYPE));
        list.add(new CountryState("Dolinsk", "16", CountryState.CITY_TYPE));

        return list;
    }
}

SectionalAdapter.java

package com.samset.headerrecyclerviewsample.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.samset.headerrecyclerviewsample.R;
import com.samset.headerrecyclerviewsample.model.model.CountryState;

import java.util.List;

public class SectionalAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    public final int CITY_TYPE = 0;
    public final int COUNTRY_TYPE = 1;
    private List<CountryState> mList;

    public SectionalAdapter(List<CountryState> list) {
        this.mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;

        switch (viewType) {
            case COUNTRY_TYPE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.section, parent, false);
                return new CountryViewHolder(view);
            case CITY_TYPE:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.section_child, parent, false);
                return new CityViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CountryState object = mList.get(position);
        if (object != null) {
            switch (object.getType()) {
                case COUNTRY_TYPE:
                    ((CountryViewHolder) holder).tvCountryName.setText(object.getName());
                    break;
                case CITY_TYPE:
                    ((CityViewHolder) holder).tvCityName.setText(object.getName());
                    //((CityViewHolder) holder).id.setText(object.getDescription());
                    break;
            }
        }
    }

    @Override
    public int getItemCount() {
        if (mList == null)
            return 0;
        return mList.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (mList != null) {
            CountryState object = mList.get(position);
            if (object != null) {
                return object.getType();
            }
        }
        return 0;
    }

    public static class CountryViewHolder extends RecyclerView.ViewHolder {
        private TextView tvCountryName;

        public CountryViewHolder(View itemView) {
            super(itemView);
            tvCountryName = (TextView) itemView.findViewById(R.id.titleTextView);
        }
    }

    public static class CityViewHolder extends RecyclerView.ViewHolder {
        private TextView tvCityName;
        private TextView id;

        public CityViewHolder(View itemView) {
            super(itemView);
            tvCityName = (TextView) itemView.findViewById(R.id.titleTextView);

        }
    }
}

section.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:orientation="vertical">

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#d7666666" />

    <TextView
        android:id="@+id/titleTextView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:text="Section"
        android:textSize="22sp"
        android:textStyle="bold" />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#d7666666" />

</LinearLayout>

Full SourceCodeDownload

Live Sample