This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
values.put(MemoryContract.MemoryEntry.COLUMN_IMAGE, memory.getImageAsString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getImageAsString() { | |
return bitmapToString(this.image); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String bitmapToString(Bitmap bitmap) { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); | |
byte[] b = baos.toByteArray(); | |
return Base64.encodeToString(b, Base64.DEFAULT); | |
} | |
private static Bitmap stringToBitmap(String encodedString) { | |
try { | |
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.image = cursor.getString(COL_IMAGE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
holder.imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.placeholder)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final float PREFERRED_WIDTH = 250; | |
private static final float PREFERRED_HEIGHT = 250; | |
public static Bitmap resizeBitmap(Bitmap bitmap) { | |
int width = bitmap.getWidth(); | |
int height = bitmap.getHeight(); | |
float scaleWidth = PREFERRED_WIDTH / width; | |
float scaleHeight = PREFERRED_HEIGHT / height; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NonNull | |
@Override | |
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | |
if (convertView == null) { | |
convertView = LayoutInflater.from(getContext()) | |
.inflate(R.layout.contact_item, parent, false); | |
} | |
Contact contact = contacts.get(position); | |
((TextView)convertView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListViewActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_list_view); | |
ListView listView = (ListView) findViewById(R.id.list); | |
listView.setAdapter(new ContactsAdapter(this)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_list_view); | |
ListView listView = (ListView) findViewById(R.id.list); | |
listView.setAdapter(new ContactsAdapter(this)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ContactsAdapter(Context context) { | |
super(context, -1); | |
this.contacts = MockDataGenerator.getMockContacts(1000); | |
} |