Monday 17 July 2017

Image Slider

                                                  Image Slider Android



-----------activity_main.xml--------------------- 
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="200dp">
 
<android.support.v4.view.ViewPager
android:id="@+id/vp_slider"
android:layout_width="match_parent"
android:layout_height="match_parent" />
 
<LinearLayout
android:id="@+id/ll_dots"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
 
 
 
 
 
 
 
 
 --------SliderPagerAdapter.java------------------------
public class SliderPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
    Activity activity;
    ArrayList<String> image_arraylist;
 
    public SliderPagerAdapter(Activity activity, ArrayList<String> image_arraylist) {
        this.activity = activity;
        this.image_arraylist = image_arraylist;
    }
 
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
        View view = layoutInflater.inflate(R.layout.layout_slider, container, false);
        ImageView im_slider = (ImageView) view.findViewById(R.id.im_slider);
        Picasso.with(activity.getApplicationContext())
                .load(image_arraylist.get(position))
                .placeholder(R.mipmap.ic_launcher) // optional
                .error(R.mipmap.ic_launcher)         // optional
                .into(im_slider);
 
 
        container.addView(view);
 
        return view;
    }
 
    @Override
    public int getCount() {
        return image_arraylist.size();
    }
 
 
    @Override
    public boolean isViewFromObject(View view, Object obj) {
        return view == obj;
    }
 
 
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = (View) object;
        container.removeView(view);
    }
}
 
 
 
----------------layout_slider.xml-----------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <ImageView
        android:id="@+id/im_slider"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"/>
 
</LinearLayout>
 
 
 
 
 
 
 
 
 
 
----------------MainActivity.java----------------
public class MainActivity extends AppCompatActivity{
 
    private ViewPager vp_slider;
    private LinearLayout ll_dots;
    SliderPagerAdapter sliderPagerAdapter;
    ArrayList<String> slider_image_list;
    private TextView[] dots;
    int page_position = 0;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
 
// method for initialisation
        init();
 
// method for adding indicators
        addBottomDots(0);
 
        final Handler handler = new Handler();
 
        final Runnable update = new Runnable() {
            public void run() {
                if (page_position == slider_image_list.size()) {
                    page_position = 0;
                } else {
                    page_position = page_position + 1;
                }
                vp_slider.setCurrentItem(page_position, true);
            }
        };
 
        new Timer().schedule(new TimerTask() {
 
            @Override
            public void run() {
                handler.post(update);
            }
        }, 100, 5000);
 
 
    }
 
    private void init() {
 
        setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
        getSupportActionBar().hide();
        vp_slider = (ViewPager) findViewById(R.id.vp_slider);
        ll_dots = (LinearLayout) findViewById(R.id.ll_dots);
 
        slider_image_list = new ArrayList<>();
 
//Add few items to slider_image_list ,this should contain url of images which should be displayed in slider
// here i am adding few sample image links, you can add your own
 
 
 
        sliderPagerAdapter = new SliderPagerAdapter(MainActivity.this, slider_image_list);
        vp_slider.setAdapter(sliderPagerAdapter);
 
        vp_slider.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
 
            }
 
            @Override
            public void onPageSelected(int position) {
                addBottomDots(position);
            }
 
            @Override
            public void onPageScrollStateChanged(int state) {
 
            }
        });
    }
 
    private void addBottomDots(int currentPage) {
        dots = new TextView[slider_image_list.size()];
 
        ll_dots.removeAllViews();
        for (int i = 0; i < dots.length; i++) {
            dots[i] = new TextView(this);
            dots[i].setText(Html.fromHtml("&#8226;"));
            dots[i].setTextSize(35);
            dots[i].setTextColor(Color.parseColor("#000000"));
            ll_dots.addView(dots[i]);
        }
 
        if (dots.length > 0)
            dots[currentPage].setTextColor(Color.parseColor("#FFFFFF"));
    }
}
 
 
 ------------------build.gradle file------------------
 
 
compile 'com.squareup.picasso:picasso:2.3.3'
 
 
 

Friday 14 July 2017

Alert Dialog

                                Alert Dialog



------------------------Simple alert dialog------------------------------

 YourMethod Name

AlertDialog.Builder alertDialogBuilder;
alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder.setMessage("Are you want to Logout!");

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.isDrawerOpen(GravityCompat.START);
drawer.closeDrawer(GravityCompat.START);

alertDialogBuilder.setPositiveButton("no", new DialogInterface.OnClickListener() {
    @Override    public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();
    }
});
alertDialogBuilder.setNegativeButton("yes", new DialogInterface.OnClickListener() {
    @Override    public void onClick(DialogInterface dialog, int which) {
        logoutForEveryWhere();


    }
});

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();




------------------- Xml support Dialog-----------------------------

    private void notificationAlertDialog() {
        final Dialog dialog = new Dialog(MainActivity.this);
        dialog.setContentView(R.layout.notificationdialog);
//            dialog.setTitle("Notificatio");
        // get the Refferences of views 
 final TextView subjectname = (TextView) dialog.findViewById(R.id.notificationdialog_text);

//            final String subject = subjectname.getText().toString(); 
//            final String mark = marks.getText().toString();
 //            Log.e("before click", ".................subject............." + subject);
 //            Log.e("before", "................marks......................." + mark);
        final Button btnok = (Button) dialog.findViewById(R.id.notificationdialog_ok_button);
        final Button btnCancel = (Button) dialog.findViewById(R.id.notificationdialog_cancel_button);
        final ImageView imageView = (ImageView) dialog.findViewById(R.id.notificationdialog_cross_image);

//        Button btnSign=(Button)dialog.findViewById(R.id.buttonSign);
        // Set On ClickListener        btnok.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                dialog.dismiss();

            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                dialog.dismiss();

            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                dialog.dismiss();

            }
        });

        dialog.show();
    }

-------------notificationdialog.xml-----------

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:orientation="vertical"
 android:layout_width="match_parent" 
 android:layout_height="match_parent">
    <ImageView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:src="@drawable/ic_clear_black_24dp" 
 
 android:layout_alignParentRight="true" 
 android:id="@+id/notificationdialog_cross_image"/>
    <LinearLayout
 
        android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_margin="30dp" 
 android:orientation="vertical">
        <ImageView 
 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content"/>
   <TextView 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:text="You Have New Notification" 
 android:id="@+id/notificationdialog_text" 
 android:textSize="16sp" 
 android:textStyle="bold"/>
        <TextView 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="5dp" 
 
 android:text="(1)Your Transaction Completed" 
 android:textSize="16sp" />
        <LinearLayout 
 
             android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_marginTop="10dp" 
 android:weightSum="2" 
 android:orientation="horizontal">
            <Button 
 android:layout_width="0dp" 
 android:layout_weight="1" 
 
 android:id="@+id/notificationdialog_ok_button" 
 android:layout_height="wrap_content" 
 android:text="ok"/>
            <Button 
 android:layout_width="0dp" 
 android:layout_weight="1" 
 android:id="@+id/notificationdialog_cancel_button" 
 android:layout_height="wrap_content" 
 android:text="Cancel"/>
        </LinearLayout>
    </LinearLayout>
    </RelativeLayout>

 

Tuesday 4 July 2017

Time Picker And DatePicker





 -----------------AddtimetablenewActivity.java------------------------

package com.dollop.bankapp.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
import com.dollop.bankapp.R;

import java.util.Calendar;

import butterknife.ButterKnife;

public class AddtimetablenewActivity extends AppCompatActivity implements
 DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener{


    EditText type_reminder,date,times,description;
    Calendar calendar;
    String id, mMimeType, time;
    static int flag = -1;

@Override 
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    calendar = Calendar.getInstance();
    setContentView(R.layout.activity_addtimetablenew);
        type_reminder = (EditText) findViewById(R.id.type_reminder);
        date = (EditText) findViewById(R.id.date);
        times = (EditText) findViewById(R.id.time);
        description = (EditText) findViewById(R.id.description);
        date.setOnClickListener(Bankdate);
        times.setOnClickListener(Banktime);

    }
    View.OnClickListener Bankdate = new View.OnClickListener() {
        @Override        public void onClick(View v) {
            flag = 1;
            datepicker();
        }
    };
    View.OnClickListener Banktime = new View.OnClickListener() {
        @Override        public void onClick(View v) {
            flag = 2;
            timepicker();
        }
    };

    private void timepicker() {
        com.wdullaer.materialdatetimepicker.time.TimePickerDialog timePickerDialog =
 com.wdullaer.materialdatetimepicker.time.TimePickerDialog.newInstance(this,
                calendar.HOUR_OF_DAY,
                calendar.MINUTE,
                calendar.SECOND,
                false);
        timePickerDialog.setThemeDark(true);
        timePickerDialog.setVersion(com.wdullaer.materialdatetimepicker.time.TimePickerDialog.Version.VERSION_2);
        /*timePickerDialog.setMinTime(Calendar.getInstance().HOUR_OF_DAY, 
 Calendar.getInstance().MINUTE,                Calendar.getInstance().SECOND);*/ 
 Log.e("setMinDate", " == " + calendar.toString());
        timePickerDialog.show(getFragmentManager(), "Time Picker");
    }


 @Override 
 public void onTimeSet(com.wdullaer.materialdatetimepicker.time.TimePickerDialog view, int hourOfDay, int minute, int second) {
        String hourString = hourOfDay < 10 ? "0" + hourOfDay : "" + hourOfDay;
        String minuteString = minute < 10 ? "0" + minute : "" + minute;
        String secondString = second < 10 ? "0" + second : "" + second;
        if (hourOfDay < 12 && hourOfDay >= 0) {
            time = hourString + ":" + minuteString + ":" + secondString + "  AM";
        } else {
            time = hourString + ":" + minuteString + ":" + secondString + "  PM";
        }
        if (flag == 2) {
            times.setText(time);
        }

    }
    private void datepicker() {
        DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this,
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.setThemeDark(true);
        datePickerDialog.setVersion(DatePickerDialog.Version.VERSION_2);
        datePickerDialog.setMinDate(calendar);
        Log.e("setMinDate", " == " + calendar.toString());
        datePickerDialog.show(getFragmentManager(), "Date Picker");
    }
    @Override 
 public void onDateSet(DatePickerDialog view, int eventYear, int monthOfYear, int dayOfMonth) {
        if (flag == 1) {
            date.setText("0" + dayOfMonth + "-" + "0" + (monthOfYear + 1) + "-" + eventYear);
            if (monthOfYear > 10 && dayOfMonth < 10)
                date.setText("0" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + eventYear);
            if (monthOfYear > 10 && dayOfMonth > 10)
                date.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + eventYear);
            if (monthOfYear < 10 && dayOfMonth > 10)
                date.setText(dayOfMonth + "-" + "0" + (monthOfYear + 1) + "-" + eventYear);
        }

    }



}
 
 
 
 
 
 
------------------activity_addtimetablenew.xml--------- 
<?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 tools:context="com.dollop.bankapp.activity.AddReminderActivity">

    <LinearLayout 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:layout_below="@+id/tool_bar" 
 android:layout_marginLeft="10dp" 
 android:layout_marginRight="10dp" 
 android:layout_marginTop="20dp" 
 android:orientation="vertical">

        <EditText 
 android:id="@+id/type_reminder" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:hint="Type Reminder" 
 android:textSize="16sp" />

        <EditText 
 android:id="@+id/date" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:hint="Date" 
 android:textSize="16sp" />

        <EditText 
 android:id="@+id/time" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content" 
 android:hint="Time" 
 android:textSize="16sp" />

        <EditText 
 android:id="@+id/description" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content"
 android:hint="Description" 
 android:textSize="16sp" />
    </LinearLayout>
</RelativeLayout>
 

SQLITE DATABASE CLASS

                                                     SQLITE DATABASE



   ----------------------Appcontroller class-----------------------


package com.httpabcdefapp1123.databasenewlogin;

import android.app.Application;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.DiskBasedCache;
import com.android.volley.toolbox.Volley;



public class AppController extends Application {

    public static final String TAG = AppController.class.getSimpleName();

    private RequestQueue mRequestQueue;

    private static AppController mInstance;
    DiskBasedCache cache;

    @Override    public void onCreate() {
        super.onCreate();
        mInstance = this;
        new LoginDataHelper(this);
//        new UserDetailDataHelper(this);        // Create global configuration and initialize ImageLoader with this config    }

    public DiskBasedCache getDiskCache()
    {
        if (cache == null)
        {
            cache = new DiskBasedCache(getExternalCacheDir(), 209715200);
        }
        return cache;
    }

    public static synchronized AppController getInstance() {
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }

        return mRequestQueue;
    }

    public <T> void addToRequestQueue(Request<T> req, String tag) {
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        getRequestQueue().add(req);
    }

    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }

    public void cancelPendingRequests(Object tag) {
        if (mRequestQueue != null) {
            mRequestQueue.cancelAll(tag);
        }
    }
}

-------DataManager.class---------------------
 
package com.httpabcdefapp1123.databasenewlogin;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;




public class DataManager extends SQLiteOpenHelper {
    public static final int DATABASE_VERSION = 2;
    public static final String DATABASE_NAME = "CollegeLife";

    public DataManager(Context context, String name, CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override    public void onCreate(SQLiteDatabase db) {
        LoginModel.creteTable(db);
//        UserDetailModel.creteTable(db);    }

    @Override    public void onUpgrade(SQLiteDatabase db, int paramInt1, int paramInt2) {
        LoginModel.dropTable(db);
//        UserDetailModel.dropTable(db);//        SavedData.clear();        onCreate(db);
    }


}



----------LoginDataHelper.class----------
 
package com.httpabcdefapp1123.databasenewlogin;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;


import java.util.ArrayList;

/** * Created by Meenakshi on 21/03/2017. */
public class LoginDataHelper {

    private static LoginDataHelper instance;
    private SQLiteDatabase db;
    private DataManager dm;
    Context cx;

    public LoginDataHelper(Context cx) {
        instance = this;
        this.cx = cx;
        dm = new DataManager(cx, DataManager.DATABASE_NAME, null, DataManager.DATABASE_VERSION);
    }



    public static LoginDataHelper getInstance() {
        return instance;
    }

    public void open() {
        db = dm.getWritableDatabase();
    }

    public void close() {
        db.close();
    }

    public void read() {
        db = dm.getReadableDatabase();
    }

    public void delete(String email) {
        open();
        db.delete(LoginModel.TABLE_NAME, LoginModel.KEY_USER_EMAIL + " = '" + email + "'", null);
//        db.execSQL("DELETE FROM " + CartModel.TABLE_NAME + " WHERE " + CartModel.KEY_PACKAGE_ID + "= '" + packageId); 
 close();
    }

    public boolean isExist(String email) {
        Cursor clientCur = db.rawQuery("SELECT * FROM " + LoginModel.TABLE_NAME + " WHERE email = '" + email + "'", null);
        boolean exist = (clientCur.getCount() > 0);
        clientCur.close();
        return exist;
    }

    public void insertClientDetail(LoginModel loginModel) {
        open();
        ContentValues values = new ContentValues();
        values.put(loginModel.KEY_USER_EMAIL, loginModel.getEmail());
        values.put(loginModel.KEY_USER_PASSWORD, loginModel.getPassword());
        values.put(loginModel.KEY_LOGIN_TYPE, loginModel.getLoginType());

        if (!isExist(loginModel.getEmail()))
            db.insert(loginModel.TABLE_NAME, null, values);
        close();
    }
    public void  updateEntry(LoginModel loginModel)
    {
        // Define the updated row content.        ContentValues updatedValues = new ContentValues();
        // Assign values for each row.        updatedValues.put(loginModel.KEY_USER_EMAIL, loginModel.getEmail());
        updatedValues.put(loginModel.KEY_USER_PASSWORD, loginModel.getPassword());
        updatedValues.put(loginModel.KEY_LOGIN_TYPE, loginModel.getLoginType());

        String where="EMAIL = ?";
        db.update(loginModel.TABLE_NAME,updatedValues, where, new String[]{loginModel.getEmail()});
    }
    public void updateClientDetail(LoginModel loginModel) {
        open();
        ContentValues updatedValues = new ContentValues();
        updatedValues.put(loginModel.KEY_USER_EMAIL, loginModel.getEmail());
        updatedValues.put(loginModel.KEY_USER_PASSWORD, loginModel.getPassword());
        updatedValues.put(loginModel.KEY_LOGIN_TYPE, loginModel.getLoginType());

        String where="EMAIL = ?";
        db.update(loginModel.TABLE_NAME, updatedValues, " EMAIL  = '" + loginModel.getEmail() + "'", null);
        close();
    }
    public ArrayList<LoginModel> getLoginDetail() {
        ArrayList<LoginModel> userItem = new ArrayList<LoginModel>();
        read();
        Cursor clientCur = db.rawQuery("select * from LoginModel", null);
        if (clientCur != null && clientCur.getCount() > 0) {
            clientCur.moveToFirst();
            do {
                LoginModel loginModel = new LoginModel();
                loginModel.setEmail(clientCur.getString(clientCur.getColumnIndex(loginModel.KEY_USER_EMAIL)));
                loginModel.setPassword(clientCur.getString(clientCur.getColumnIndex(loginModel.KEY_USER_PASSWORD)));
                loginModel.setLoginType(clientCur.getString(clientCur.getColumnIndex(loginModel.KEY_LOGIN_TYPE)));

                userItem.add(loginModel);
            } while ((clientCur.moveToNext()));
            clientCur.close();
        }
        close();
        return userItem;
    }
}

 ------------------LoginModel.class---------------------------
package com.httpabcdefapp1123.databasenewlogin;

import android.database.sqlite.SQLiteDatabase;

/** * Created by Meenakshi on 21/03/2017. */
public class LoginModel {


    public static final String TABLE_NAME = "LoginModel";
    public static final String KEY_ID = "_id";
    public static String KEY_USER_EMAIL = "email";
    public static String KEY_USER_PASSWORD = "password";
    public static String KEY_LOGIN_TYPE = "loginType";



    public static void creteTable(SQLiteDatabase db) {
        String CREATE_CLIENTTABLE = "create table " + TABLE_NAME + " (" 
 + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," 
 + KEY_USER_EMAIL + " text, " 
 + KEY_USER_PASSWORD + " text, " 
 + KEY_LOGIN_TYPE + " text " +
                ")";
        db.execSQL(CREATE_CLIENTTABLE);
    }

    public static void dropTable(SQLiteDatabase db) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getLoginType() {
        return loginType;
    }

    public void setLoginType(String loginType) {
        this.loginType = loginType;
    }

    //setter gater    private String email,password,loginType;


}

           /////Thanks to Sohel Khan(Sir) for this Code.///////////

AutoComplete Address (Updated)

-------------------------------------Activity---------------------------------- package placeautocomplete.iteritory.com; import androi...