Java tutorial
/* * Copyright 2016 Simon Zigelli * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ze.client.projecto.database; import android.content.ContentResolver; import android.content.ContentUris; import android.net.Uri; import android.provider.BaseColumns; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; @SuppressWarnings("unused") public class ProjectoContract { static final String CONTENT_AUTHORITY = "com.ze.client.projecto"; static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY); static final String PATH_PROJECTOR = "projector"; public static String convertDateToDatabaseFormat(DateTime date) { if (date != null) { DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); return fmt.print(date); } else return ""; } public static DateTime getDateFromString(String date) { if (date != null && !date.equals("")) { String pattern = "yyyy-MM-dd HH:mm:ss"; return DateTimeFormat.forPattern(pattern).parseDateTime(date); } return null; } public static final class Projector implements BaseColumns { public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_PROJECTOR).build(); public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_PROJECTOR; public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_PROJECTOR; public static final String TABLE_NAME = "projector"; public static final String TYPE_ID = "type_id"; public static final String SCHEME = "scheme"; public static final String HOST = "host"; public static final String PORT = "port"; public static final String NAME = "name"; public static final String CREATE_STRING = "CREATE TABLE " + TABLE_NAME + " (" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + TYPE_ID + " INTEGER, " + SCHEME + " TEXT, " + HOST + " TEXT, " + PORT + " INTEGER, " + NAME + " TEXT NOT NULL" + ");"; public static Uri buildProjectorUri(long id) { return ContentUris.withAppendedId(CONTENT_URI, id); } public static String getIdUri(Uri uri) { return uri.getPathSegments().get(1); } } }