Java tutorial
/* * Project: Woody * Purpose: Mobile application for trees mapping. * Author: Dmitry Baryshnikov, dmitry.baryshnikov@nextgis.com * ***************************************************************************** * Copyright (c) 2016 NextGIS, info@nextgis.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.nextgis.woody.util; import android.content.Context; import android.graphics.drawable.Drawable; import android.support.v4.graphics.drawable.DrawableCompat; import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; public final class UiUtil { public static String formatDate(long timestamp, int style) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp); Date calendarTime = calendar.getTime(); DateFormat df = DateFormat.getDateInstance(style, Locale.getDefault()); return df.format(calendarTime); } public static float dpToPx(Context context, float dp) { return dp * context.getResources().getDisplayMetrics().density; } public static Drawable tintIcon(Drawable drawable, int color) { Drawable result = DrawableCompat.wrap(drawable); result.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); DrawableCompat.setTint(result, color); return result; } public static boolean isEmailValid(String email) { if (email == null) email = ""; Pattern pattern = Pattern.compile(Constants.EMAIL_PATTERN); Matcher matcher = pattern.matcher(email); return matcher.matches(); } }