Skip to content

Instantly share code, notes, and snippets.

View sprejjs's full-sized avatar
:octocat:

Allan Spreys sprejjs

:octocat:
  • ANZx
  • Sydney/Australia
  • 18:15 (UTC +10:00)
View GitHub Profile
@sprejjs
sprejjs / Cat.java
Last active July 8, 2017 00:52
Custom model class example
package com.company;
//Name of the class
public class Cat {
//Private variables
private int age;
private String name;
//Private constant
private final boolean isMale;
private static final int GALLERY_REQUEST_CODE = 100;
@sprejjs
sprejjs / step2.java
Last active July 26, 2017 11:52
step2.java
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST_CODE);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == GALLERY_REQUEST_CODE) {
try {
Uri selectedImage = data.getData();
InputStream imageStream = getContentResolver().openInputStream(selectedImage);
selectedImageView.setImageBitmap(BitmapFactory.decodeStream(imageStream));
} catch (IOException exception) {
exception.printStackTrace();
private static final int CAMERA_REQUEST_CODE = 200;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}
if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
selectedImageView.setImageBitmap(imageBitmap);
}
private Bitmap image;
public Memory(String title, Bitmap image) {
this.title = title;
this.image = image;
}
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + MemoryContract.MemoryEntry.TABLE_NAME + " (" +
MemoryContract.MemoryEntry._ID + INTEGER_TYPE + " PRIMARY KEY" + COMMA_SEP +
MemoryContract.MemoryEntry.COLUMN_IMAGE + TEXT_TYPE + COMMA_SEP +
MemoryContract.MemoryEntry.COLUMN_TITLE + TEXT_TYPE + " )";