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
static File createTempImageFile(Context context) throws IOException { | |
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", | |
Locale.getDefault()).format(new Date()); | |
String imageFileName = "JPEG_" + timeStamp + "_"; | |
File storageDir = context.getExternalCacheDir(); | |
return File.createTempFile( | |
imageFileName, /* prefix */ | |
".jpg", /* suffix */ | |
storageDir /* directory */ |
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
//process current time in milliseconds into "00:00 am" format | |
Timestamp currentTime = new Timestamp(System.currentTimeMillis()); | |
SimpleDateFormat formatter = new SimpleDateFormat(getString(R.string.timeFormat), Locale.getDefault()); | |
String currentTimeString = formatter.format(currentTime); | |
//process a number of minutes into "hh:mm" format | |
long totalMinutesCount = 123; | |
long hoursCount = TimeUnit.MINUTES.toHours(totalMinutesCount); | |
long minutesLessHoursCount = | |
totalMinutesCount - TimeUnit.HOURS.toMinutes(hoursCount); |
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
Driver driver = new GooglePlayDriver(context); | |
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver); | |
/* Create the Job to periodically create reminders to drink water */ | |
Job constraintReminderJob = dispatcher.newJobBuilder() | |
/* The Service that will be used to write to preferences */ | |
.setService(WaterReminderFirebaseJobService.class) | |
/* | |
* Set the UNIQUE tag used to identify this Job. | |
*/ |
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 int WATER_REMINDER_NOTIFICATION_ID = 1138; | |
/** | |
* This pending intent id is used to uniquely reference the pending intent | |
*/ | |
private static final int WATER_REMINDER_PENDING_INTENT_ID = 3417; | |
private static final int ACTION_DRINK_PENDING_INTENT_ID = 1; | |
private static final int ACTION_IGNORE_PENDING_INTENT_ID = 14; | |
public static void remindUserBecauseCharging(Context context) { |
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
int count = PreferenceUtilities.getChargingReminderCount(this); | |
//the first count parameter selects the appropriate plural string and the second count parameter is inserted into the %d placeholder. | |
String formattedChargingReminders = getResources().getQuantityString(R.plurals.charge_notification_count, count, count); |
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
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { | |
@Override | |
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { | |
return false; | |
} | |
// Called when a user swipes left or right on a ViewHolder | |
@Override | |
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { | |
// Here is where you'll implement swipe to delete |
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
<ImageView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:adjustViewBounds="true" | |
android:scaleType="fitCenter"/> |
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
// save to db | |
private void saveItem() { | |
ContentValues values = new ContentValues(); | |
values.put(InventoryEntry.COLUMN_IMAGE, BitmapUtility.bitmapToBlob(mBitmap)); | |
} | |
// retrieve from db (via CursorLoader) | |
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { | |
int imageIndex = cursor.getColumnIndex(InventoryEntry.COLUMN_IMAGE); | |
byte[] imageBlob = cursor.getBlob(imageIndex); |
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 final class BitmapUtility { | |
private BitmapUtility() { | |
} | |
// scale the bitmap for a given maximum dimension | |
// (width or height depending on the image's aspect ratio) | |
public static Bitmap scaleBitmap(Bitmap bitmap, int dp, Context context) { | |
int width = bitmap.getWidth(); |
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 void pickImage() { | |
Intent i = new Intent(Intent.ACTION_GET_CONTENT); | |
i.setType("image/*"); | |
startActivityForResult(i, PICK_PHOTO_FOR_PRODUCT); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (requestCode == PICK_PHOTO_FOR_PRODUCT && resultCode == Activity.RESULT_OK) { |
NewerOlder