daily pastebin goal
44%
SHARE
TWEET

UsersAdapter.java

a guest Jun 18th, 2016 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. UsersAdapter.java
  2.  
  3. public class UsersAdapter extends RecyclerView.Adapter<UsersAdapter.UserViewHolder> {
  4. private ArrayList<User> mDataSet;
  5. private Context context;
  6.  
  7. private SQLiteDatabase db;
  8.  
  9. public UsersAdapter(ArrayList<User> mDataSet, Context context) {
  10.     this.context = context;
  11.     this.mDataSet = mDataSet;
  12.  
  13.     createDatabase();
  14.  
  15. }
  16.  
  17. public void createDatabase(){
  18.     db=context.openOrCreateDatabase("xxx", Context.MODE_PRIVATE, null);
  19.     db.execSQL("CREATE TABLE IF NOT EXISTS faces(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR,url VARCHAR);");
  20. }
  21.  
  22.  
  23. @Override
  24. public UserViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  25.     View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_favorites2, parent, false);
  26.     UserViewHolder userViewHolder = new UserViewHolder(v);
  27.     return userViewHolder;
  28. }
  29.  
  30. @Override
  31. public void onBindViewHolder(UserViewHolder holder, int position) {
  32.  
  33.  
  34.     holder.name_entry.setText(mDataSet.get(position).getName());
  35.     holder.email_entry.setText(mDataSet.get(position).getEmail());
  36.     holder.icon_entry.setText(""+mDataSet.get(position).getName().charAt(0));
  37.  
  38.     String name = mDataSet.get(position).getName();
  39.     String url = mDataSet.get(position).getEmail();
  40.  
  41.     Glide.with(context)
  42.             .load(url)
  43.             .asBitmap()
  44.             .placeholder(R.drawable.ic_blank)
  45.             .error(R.drawable.ic_blank)
  46.             .into(holder.ivFavorites);
  47. }
  48.  
  49. @Override
  50. public int getItemCount() {
  51.     return mDataSet.size();
  52. }
  53.  
  54. public class UserViewHolder extends RecyclerView.ViewHolder {
  55.     CardView cardView;
  56.     TextView name_entry, email_entry, icon_entry;
  57.     ImageView ivFavorites;
  58.  
  59.     UserViewHolder(View itemView) {
  60.         super(itemView);
  61.         cardView = (CardView) itemView.findViewById(R.id.user_layout);
  62.         name_entry = (TextView) itemView.findViewById(R.id.name_entry);
  63.         email_entry = (TextView) itemView.findViewById(R.id.email_entry);
  64.         icon_entry = (TextView) itemView.findViewById(R.id.icon_entry);
  65.         ivFavorites = (ImageView) itemView.findViewById(R.id.ivFavorites);
  66.  
  67.         Typeface fontFamily2 = Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome-webfont.ttf");
  68.         TextView fontFamilyText2 = (TextView) itemView.findViewById(R.id.fontAwesomeDirectLink);
  69.         fontFamilyText2.setTypeface(fontFamily2);
  70.         fontFamilyText2.setText("\uf0c1");
  71.         fontFamilyText2.setTextColor(ContextCompat.getColor(context, R.color.bg_screen3));
  72.         fontFamilyText2.setOnClickListener(new View.OnClickListener() {
  73.             public void onClick(View view) {
  74.                 context = view.getContext();
  75.                 final User mDataSet2 = mDataSet.get(getAdapterPosition());;
  76.                 String url = mDataSet2.getEmail();
  77.                 String name = mDataSet2.getName();
  78.                 ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  79.                 ClipData clip = ClipData.newPlainText("xxx direct link", url);
  80.                 clipboard.setPrimaryClip(clip);
  81.                 Snackbar snackbar = Snackbar
  82.                         .make(view, "Copied " + name + "!", Snackbar.LENGTH_LONG)
  83.                         .setActionTextColor(context.getResources().getColor(R.color.bg_screen3))
  84.                         .setAction("ADD IMG TAGS", new View.OnClickListener() {
  85.                             @Override
  86.                             public void onClick(View view) {
  87.                                 context = view.getContext();
  88.                                 final User mDataSet2 = mDataSet.get(getAdapterPosition());;
  89.                                 String url = mDataSet2.getEmail();
  90.                                 String name = mDataSet2.getName();
  91.                                 ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
  92.                                 ClipData clip = ClipData.newPlainText("xxx direct link with image tags", "[img]" + url + "[/img]");
  93.                                 clipboard.setPrimaryClip(clip);
  94.                                 Snackbar snackbar1 = Snackbar.make(view, "Added image tags!", Snackbar.LENGTH_SHORT);
  95.                                 snackbar1.show();
  96.                             }
  97.                         });
  98.  
  99.                 snackbar.show();
  100.             }
  101.         });
  102.  
  103.         Typeface fontFamily3 = Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome-webfont.ttf");
  104.         TextView fontFamilyText3 = (TextView) itemView.findViewById(R.id.fontAwesomeImageTagLink);
  105.         fontFamilyText3.setTypeface(fontFamily3);
  106.         fontFamilyText3.setText("\uf00d");
  107.         fontFamilyText3.setTextColor(ContextCompat.getColor(context, R.color.dot_dark_screen1));
  108.         fontFamilyText3.setOnClickListener(new View.OnClickListener() {
  109.             public void onClick(View view) {
  110.                 context = view.getContext();
  111.                 final User mDataSet3 = mDataSet.get(getAdapterPosition());;
  112.                 String url = mDataSet3.getEmail();
  113.                 String name = mDataSet3.getName();
  114.                 String query = "DELETE FROM faces WHERE url = ('"+url+"');";
  115.                 db.execSQL(query);
  116.                 mDataSet.remove(getAdapterPosition());
  117.                 notifyDataSetChanged();
  118.                 Snackbar snackbar = Snackbar
  119.                         .make(view, name + " Removed!", Snackbar.LENGTH_LONG)
  120.                         .setActionTextColor(context.getResources().getColor(R.color.dot_dark_screen1))
  121.                         .setAction("UNDO", new View.OnClickListener() {
  122.                             @Override
  123.                             public void onClick(View view) {
  124.                                 context = view.getContext();
  125.                                 final User mDataSet3 = mDataSet.get(getAdapterPosition());;
  126.                                 String url = mDataSet3.getEmail();
  127.                                 String name = mDataSet3.getName();
  128.                                 String query = "INSERT INTO faces (name,url) VALUES('"+name+"', '"+url+"');";
  129.                                 db.execSQL(query);
  130.                                 Snackbar snackbar3 = Snackbar.make(view, name + " Favorited!", Snackbar.LENGTH_SHORT);
  131.                                 snackbar3.show();
  132.                             }
  133.                         });
  134.                 snackbar.show();
  135.             }
  136.         });
  137.  
  138.  
  139.         Typeface fontFamily4 = Typeface.createFromAsset(context.getAssets(), "fonts/fontawesome-webfont.ttf");
  140.         TextView fontFamilyText4 = (TextView) itemView.findViewById(R.id.fontAwesomeShare);
  141.         fontFamilyText4.setTypeface(fontFamily4);
  142.         fontFamilyText4.setText("\uf1e0");
  143.         fontFamilyText4.setTextColor(ContextCompat.getColor(context, R.color.bg_screen3));
  144.         fontFamilyText4.setOnClickListener(new View.OnClickListener() {
  145.             public void onClick(View view) {
  146.                 context = view.getContext();
  147.                 final User mDataSet2 = mDataSet.get(getAdapterPosition());;
  148.                 String url = mDataSet2.getEmail();
  149.                 String name = mDataSet2.getName();
  150.                 Drawable mDrawable = ivFavorites.getDrawable();
  151.                 Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
  152.                 Bitmap imageWithBG = Bitmap.createBitmap(600, 600, mBitmap.getConfig());  // Create another image the same size
  153.                 imageWithBG.eraseColor(Color.WHITE);  // set its background to white, or whatever color you want
  154.                 Canvas canvas = new Canvas(imageWithBG);  // create a canvas to draw on the new image
  155.                 canvas.drawBitmap(mBitmap, 175, 100, null); // draw old image on the background
  156.                 String path = MediaStore.Images.Media.insertImage(context.getContentResolver(),
  157.                         imageWithBG, "xxx", null);
  158.                 Uri uri = Uri.parse(path);
  159.                 final Intent shareIntent = new Intent(Intent.ACTION_SEND); // THIS IS SLOW
  160.                 shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
  161.                 shareIntent.setType("image/*");
  162.                 context.startActivity(shareIntent);
  163.             }
  164.         });
  165.  
  166.     }
  167. }
  168.  
  169. @Override
  170. public void onAttachedToRecyclerView(RecyclerView recyclerView) {
  171.     super.onAttachedToRecyclerView(recyclerView);
  172. }
  173. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top