Easy Rating Library – Android – aar – Full Project

 

Easy Rating Library is an aar library to ask your users rate your app in just one line of code.

How to use it?


1 - Copy the aar to the libs folder.

2 - add to gradle the lines below.

 compile(name: 'ratelib', ext: 'aar')

 repositories {
        flatDir {
            dirs 'libs'
        }
    }

3 - call the following line of code where you like to ask for rating.

RateDialog.Show(Activity.this);

* This library is translated in English, Spanish and Portuguese.

 



Download Easy_Rating_Library.zip

Download easy_rating_libary_source_code.zip

 

 

 

PASSWORD KEEPER PROJECT – Sqlite, ListView, Custom Adapter, Search inside ListView, Copy to clipboard – ANDROID

This project is a full working password manager / keeper for your Android device.

Store all your passwords in just one offline App. This project includes sqlite, listview, custom adapter, copy to clipboard and a function to search inside the listview.

——————————————————————————————

DatabaseHandler.java


package keeper.password.passwordkeeper;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

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

public class DatabaseHandler extends SQLiteOpenHelper {

    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
 //   private static final String DATABASE_NAME = "contactsManager";

    private static final String DATABASE_NAME = "passwordManager";

    // Contacts table name
   // private static final String TABLE_CONTACTS = "contacts";

    private static final String TABLE_SERVICE = "service";

    // Contacts Table Columns names
 //   private static final String KEY_ID = "id";
//    private static final String KEY_NAME = "name";
//    private static final String KEY_PH_NO = "phone_number";

    private static final String KEY_ID = "id";
    private static final String KEY_SERVICE = "service";
    private static final String KEY_USERNAME = "username";
    private static final String KEY_EMAIL = "email";
    private static final String KEY_PASSWORD = "password";

    public DatabaseHandler(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_SERVICE + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_SERVICE + " TEXT,"  + KEY_USERNAME + " TEXT,"  + KEY_EMAIL + " TEXT,"
                + KEY_PASSWORD + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }

    // Upgrading database
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_SERVICE);

        // Create tables again
        onCreate(db);
    }

    /**
     * All CRUD(Create, Read, Update, Delete) Operations
     */

    // Adding new contact
    void addService(Servic servic) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_SERVICE, servic.getService()); // Contact Name
        values.put(KEY_USERNAME, servic.getUsername()); // Contact Phone
        values.put(KEY_EMAIL, servic.getEmail()); // Contact Phone
        values.put(KEY_PASSWORD, servic.getPassword()); // Contact Phone

        // Inserting Row
        db.insert(TABLE_SERVICE, null, values);
        db.close(); // Closing database connection
    }

    // Getting single contact
    Servic getServic(int id) {
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.query(TABLE_SERVICE, new String[] { KEY_ID,
                        KEY_SERVICE, KEY_USERNAME,KEY_EMAIL,KEY_PASSWORD }, KEY_ID + "=?",
                new String[] { String.valueOf(id) }, null, null, null, null);
        if (cursor != null)
            cursor.moveToFirst();


        Servic servic = new Servic();
     //   Servic servic = new Servic(Integer.parseInt(cursor.getString(0)),
     //           cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));
        // return contact
        servic.setId(Integer.parseInt(cursor.getString(0)));
        servic.setService( cursor.getString(1));
        servic.setUsername( cursor.getString(2));
        servic.setEmail( cursor.getString(3));
        servic.setPassword( cursor.getString(4));


        return servic;
    }

    public void deleteAllService(){
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("delete from "+ TABLE_SERVICE);
    }

    // Getting All Contacts
    public List<Servic> getAllService() {
        List<Servic> serviceList = new ArrayList<Servic>();
        // Select All Query
        String selectQuery = "SELECT  * FROM " + TABLE_SERVICE;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        // looping through all rows and adding to list
        if (cursor.moveToFirst()) {
            do {
                Servic servic = new Servic();
         //       Servic servic = new Servic(Integer.parseInt(cursor.getString(0)),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4));
                servic.setId(Integer.parseInt(cursor.getString(0)));
                servic.setService(cursor.getString(1));
                servic.setUsername(cursor.getString(2));
                servic.setEmail(cursor.getString(3));
                servic.setPassword(cursor.getString(4));
                // Adding contact to list
                serviceList.add(servic);
            } while (cursor.moveToNext());
        }

        // return contact list
        return serviceList;
    }

    // Updating single contact
    public int updateService(Servic servic) {
        SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_SERVICE, servic.getService());
        values.put(KEY_USERNAME, servic.getUsername());
        values.put(KEY_EMAIL, servic.getEmail());
        values.put(KEY_PASSWORD, servic.getPassword());

        // updating row
        return db.update(TABLE_SERVICE, values, KEY_ID + " = ?",
                new String[] { String.valueOf(servic.getId()) });
    }

    // Deleting single contact
    public void deleteService(Servic servic) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_SERVICE, KEY_ID + " = ?",
                new String[] { String.valueOf(servic.getId()) });
        db.close();
    }


    // Getting contacts Count
    public int getServiceCount() {
        String countQuery = "SELECT  * FROM " + TABLE_SERVICE;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        cursor.close();

        // return count
        return cursor.getCount();
    }

}

Servic.java

package keeper.password.passwordkeeper;

/**
 * Created by Ferran on 18/01/2018.
 */

public class Servic {

    int id;
    String service;
    String username;
    String email;
    String password;

public Servic(String s, String fespuna, String s1, String s2){

}

    public Servic() {
        this.id = id;
        this.service = service;
        this.username = username;
        this.email = email;
        this.password = password;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    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;
    }
}

ServicAdapter.java



package keeper.password.passwordkeeper;

import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

/**
 * Created by Ferran on 18/01/2018.
 */

public class ServicAdapter extends BaseAdapter {

    private Activity activity;
    private LayoutInflater inflater;
    private List<Servic> serviceItems;

    public ServicAdapter(Activity activity, List<Servic> serviceItems) {
        this.activity = activity;
        this.serviceItems = serviceItems;
    }

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

    @Override
    public Object getItem(int location) {
        return serviceItems.get(location);
    }

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

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

        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.list_row, null);

        TextView service = (TextView) convertView.findViewById(R.id.tvservice);
        TextView username = (TextView) convertView.findViewById(R.id.tvusername);
        TextView email = (TextView) convertView.findViewById(R.id.tvemail);
        final TextView password = (TextView) convertView.findViewById(R.id.tvpassword);

        // getting movie data for the row

        ImageView copyme = (ImageView)convertView.findViewById(R.id.ivcopy);
        copyme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText(password.getText().toString(), password.getText().toString());
                clipboard.setPrimaryClip(clip);

                Toast.makeText(activity,"Password has been copied to your clipboard",Toast.LENGTH_LONG).show();
            }
        });

        final Servic servic = serviceItems.get(position);

        service.setText(servic.getService());
        username.setText(servic.getUsername());
        email.setText(servic.getEmail());
        password.setText(servic.getPassword());

        ImageView ivbin = (ImageView) convertView.findViewById(R.id.ivbin);
        ivbin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final Dialog dialog = new Dialog(activity);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.remove);

                Button btncancel = (Button) dialog.findViewById(R.id.btncancel);
                Button btndelete = (Button) dialog.findViewById(R.id.btndelete);
                // if button is clicked, close the custom dialog
                btncancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });

                btndelete.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        DatabaseHandler db = new DatabaseHandler(activity);
                        db.deleteService(servic);
                        serviceItems.remove(position);
                        notifyDataSetChanged();
                        dialog.dismiss();
                    }
                });

                dialog.show();



            }
        });

        return convertView;
    }


    public void clear() {
        // TODO Auto-generated method stub
        serviceItems.clear();
        notifyDataSetChanged();

    }

}

Download PasswordKeeper.zip