14 Commits

Author SHA1 Message Date
Alexander Doerflinger
d3912b3f16 Added GameSelection + Logic
Now First screen is a game selection screen, second screen is the
settings screen where characters, karts, etc can be found.
2017-08-18 14:18:09 +02:00
Alexander Doerflinger
e906031de4 Prepared usage of images (fully working with http-uri) 2017-08-17 16:17:47 +02:00
Alexander Doerflinger
4a6e8d9576 Changed VersionCode 2017-08-17 13:15:29 +02:00
Alexander Doerflinger
cdfb9a946d Fixed an issue where only characters were writte to db
Updates where not delivered / written into db.
Problem was that onCheckedChangeListener did not fire.
Now we simply switched the assigneing of ChangeListener andonClickListener
and everything works fine.
2017-08-17 13:14:06 +02:00
Alexander Doerflinger
7f161a7442 Added Update functionality to toggle availability 2017-08-17 13:03:44 +02:00
Alexander Doerflinger
2b4515c284 Added CustomCursorAdapters for each PagerType
Functional -> Still update and toggle availability need to be implemented.
2017-08-17 12:28:36 +02:00
Alexander Doerflinger
a9fa61bac4 Reached Clean State, NO FUNCTIONALITY ADDED
Only applied some checkstyle and reformated code.
Also modified some warnings
2017-08-17 11:07:25 +02:00
Alexander Doerflinger
2ffb854927 Fully Functional Database loading
Adapter needs to be replaced with custom adapter.
Click needs to be implemented as well.
2017-08-16 16:20:52 +02:00
Alexander Doerflinger
8bf84bf936 Backup for local changes 2017-08-16 12:48:58 +02:00
Alexander Doerflinger
a25a12b8c7 [INTERMEDIATE STATE] Pager implementation started
Seems not to work at all. We need to have a further look into this.
At least it is somehow not crashing anymore...
2017-08-10 16:54:55 +02:00
Alexander Doerflinger
9494c081d1 Added Generic and Specific Fragments
Generic Fragment Layout was defined
Specific Laout Object wer integrated including all object specific handling
FragmentObjects can now be added to ListViews.
Possible clean solution would be to have a PagingAdapter for each object type.
2017-08-10 10:11:29 +02:00
Alexander Doerflinger
8967107045 Fixed some general warnings. 2017-08-09 16:24:19 +02:00
Alexander Doerflinger
8e5791d35e Added support for game and onlyAvailable when retireving data
From now on, it is possible for the API to retrieve only object which
are assigned to a specific game or only objects that are available or both.
This might (pretty sure it is) needed in the future
2017-08-09 16:18:33 +02:00
Alexander Doerflinger
05076a01f1 Added "GetAll" Functions to Database handler
These functions return all items of a single kind.
We need to think of if we should handle more logic within sqlite
queries (eg. more specific like get all characters of this game) or if we would
like to handle this on apps side.
2017-08-09 15:28:22 +02:00
55 changed files with 3317 additions and 260 deletions

2
.idea/misc.xml generated
View File

@@ -56,7 +56,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@@ -7,8 +7,8 @@ android {
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
minSdkVersion 16
targetSdkVersion 25
versionCode 5
versionName "0.1.5"
versionCode 16
versionName "0.1.16"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -24,8 +24,14 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.+'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.afollestad.material-dialogs:core:0.9.4.3'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
compile 'devlight.io:navigationtabbar:1.2.5'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}

View File

@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.de.aldo_apps.aldo.mariokartcircuitselector">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@@ -9,13 +11,45 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".GameSelection">
<activity
android:name=".activities.GameSelectionActivity"
android:label="@string/title_activity_game_selection"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.GameSettingsActivity"/>
<provider
android:name=".CharacterContentProvider"
android:authorities="com.de.aldo_apps.aldo.mariokartcircuitselector"
android:enabled="true"
android:exported="true" />
<provider
android:name=".WheelsContentProvider"
android:authorities="com.de.aldo_apps.aldo.mariokartcircuitselector"
android:enabled="true"
android:exported="true" />
<provider
android:name=".TrackContentProvider"
android:authorities="com.de.aldo_apps.aldo.mariokartcircuitselector"
android:enabled="true"
android:exported="true" />
<provider
android:name=".KartContentProvider"
android:authorities="com.de.aldo_apps.aldo.mariokartcircuitselector"
android:enabled="true"
android:exported="true" />
<provider
android:name=".AccessoryContentProvider"
android:authorities="com.de.aldo_apps.aldo.mariokartcircuitselector"
android:enabled="true"
android:exported="true" />
</application>
</manifest>

View File

@@ -0,0 +1,6 @@
ALTER TABLE track ADD cover_uri TEXT;
ALTER TABLE wheels ADD cover_uri TEXT;
ALTER TABLE kart ADD cover_uri TEXT;
ALTER TABLE accessory ADD cover_uri TEXT;
ALTER TABLE character ADD cover_uri TEXT;

View File

@@ -0,0 +1,60 @@
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Peach.png" WHERE `_rowid_`='1';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Mario.png" WHERE `_rowid_`='2';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Luigi.png" WHERE `_rowid_`='3';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Toad.png" WHERE `_rowid_`='4';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Koopa.png" WHERE `_rowid_`='5';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Bowser.png" WHERE `_rowid_`='6';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Yoshi.png" WHERE `_rowid_`='7';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:SMK_Sprite_Donkey_Kong_Jr..png" WHERE `_rowid_`='8';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Mario.gif" WHERE `_rowid_`='9';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Luigi.gif" WHERE `_rowid_`='10';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Peach.jpg" WHERE `_rowid_`='11';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Toad.jpg" WHERE `_rowid_`='12';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Yoshi.gif" WHERE `_rowid_`='13';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_DK.gif" WHERE `_rowid_`='14';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Wario.jpg" WHERE `_rowid_`='15';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MK64_Artwork_Bowser.gif" WHERE `_rowid_`='16';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Mario.png" WHERE `_rowid_`='17';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Luigi.png" WHERE `_rowid_`='18';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Peach.png" WHERE `_rowid_`='19';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Toad.png" WHERE `_rowid_`='20';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Yoshi.png" WHERE `_rowid_`='21';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Donkey_Kong.png" WHERE `_rowid_`='22';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Wario.png" WHERE `_rowid_`='23';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKSC_Sprite_Bowser.png" WHERE `_rowid_`='24';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Mario.png" WHERE `_rowid_`='25';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Luigi.png" WHERE `_rowid_`='26';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Peach.png" WHERE `_rowid_`='27';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Daisy.png" WHERE `_rowid_`='28';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Yoshi.png" WHERE `_rowid_`='29';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Birdo.png" WHERE `_rowid_`='30';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Baby_Mario.png" WHERE `_rowid_`='31';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Baby_Luigi.png" WHERE `_rowid_`='32';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Toad.png" WHERE `_rowid_`='33';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Toadette.png" WHERE `_rowid_`='34';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Koopa.png" WHERE `_rowid_`='35';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Parakoopa.png" WHERE `_rowid_`='36';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Donkey_Kong.png" WHERE `_rowid_`='37';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Diddy_Kong.png" WHERE `_rowid_`='38';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Bowser.png" WHERE `_rowid_`='39';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Bowser_Jr.png" WHERE `_rowid_`='40';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Wario.png" WHERE `_rowid_`='41';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Waluigi.png" WHERE `_rowid_`='42';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_Mutant-Tyranha.png" WHERE `_rowid_`='43';
UPDATE `character` SET `cover_uri`="http://mariowiki.net/wiki/Datei:MKDD_Sprite_König_Buu_Huu.png" WHERE `_rowid_`='44';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Mario_Artwork.png" WHERE `_rowid_`='45';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Luigi_Artwork.png" WHERE `_rowid_`='46';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Peach_Artwork.png" WHERE `_rowid_`='47';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Yoshi_Artwork.png" WHERE `_rowid_`='48';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Toad_Artwork.png" WHERE `_rowid_`='49';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Donkey_Kong_Artwork.png" WHERE `_rowid_`='50';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Wario_Artwork.png" WHERE `_rowid_`='51';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/File:MKDS-Bowser_Artwork.png" WHERE `_rowid_`='52';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/images/thumb/2/2d/PrincessDaisyMKDS.png/120px-PrincessDaisyMKDS.png" WHERE `_rowid_`='53';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/images/thumb/5/53/MKDS-Dry_Bones_Artwork.png/120px-MKDS-Dry_Bones_Artwork.png" WHERE `_rowid_`='54';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/images/thumb/b/bb/MKDS-Waluigi_Artwork.png/103px-MKDS-Waluigi_Artwork.png" WHERE `_rowid_`='55';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/images/thumb/b/b5/MKDS-ROB_Artwork.png/120px-MKDS-ROB_Artwork.png" WHERE `_rowid_`='56';
UPDATE `character` SET `cover_uri`="https://www.mariowiki.com/images/thumb/6/6b/Shy_Guy_-_MKDS.png/120px-Shy_Guy_-_MKDS.png" WHERE `_rowid_`='57';

View File

@@ -0,0 +1,2 @@
UPDATE `character` SET `cover_uri`="";

View File

@@ -0,0 +1,155 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* The ContentProvider which retrieves the Accessory Data.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class AccessoryContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "AccessoryProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/accessories");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -0,0 +1,154 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* The ContentProvider which retrieves the Character Data.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class CharacterContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "CharacterProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/characters");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -1,21 +1,25 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
/**
* Created by aldo7224 on 07.08.17.
* Constants that are used within the whole project. Therefore we have instantiated them in a single
* centralized class.
*
* @author aldo7224
* @version 0.2
* @since 17.08.2017
*/
public class Constants {
public final class Constants {
/**
* The Version Code of the Database.
*/
public static final Integer DATABASE_VERSION = 1;
static final Integer DATABASE_VERSION = 4;
/**
* As SQLite does not have a native boolean value, we use integers to represent true and false.
* This is the value for a true statement.
*/
public final static Integer TRUE = 1;
public static final Integer TRUE = 1;
/**
* As SQLite does not have a native boolean value, we use integers to represent true and false.
@@ -24,55 +28,94 @@ public class Constants {
public final static Integer FALSE = 0;
/**
* The Path to the Database
* The Base LoaderID.
*/
public static final String DATABASE_PATH
= "/data/data/com.de.aldo_apps.aldo.mariokartcircuitselector/databases/";
public static final int BASE_LOADER_ID = 0;
/**
* LoaderID of the character loader.
*/
public static final int CHARACTER_LOADER_ID = BASE_LOADER_ID;
/**
* LoaderID of the kart loader.
*/
public static final int KART_LOADER_ID = BASE_LOADER_ID + 1;
/**
* LoaderID of the track loader.
*/
public static final int TRACK_LOADER_ID = BASE_LOADER_ID + 2;
/**
* LoaderID of the accessory loader.
*/
public static final int ACCESSORY_LOADER_ID = BASE_LOADER_ID + 3;
/**
* LoaderID of the wheels loader.
*/
public static final int WHEELS_LOADER_ID = BASE_LOADER_ID + 4;
/**
* LoaderID of the game loader.
*/
public static final int GAME_LOADER_ID = BASE_LOADER_ID + 5;
/**
* LoaderID of the ruleset loader.
*/
public static final int RULESET_LOADER_ID = BASE_LOADER_ID + 6;
/**
* The Key for the projection being provided via a bundle.
*/
public static final String PROJECTION_KEY = "projection";
/**
* The Key for the loaderId being provided via a bundle.
*/
public static final String LOADER_ID_KEY = "loader_id";
/**
* The Name of the complete database.
*/
public static final String DATABASE_NAME = "mario_kart_circuit_selector";
/**
* Modificator String to modify path of OLD database.
*/
public static final String DATABASE_OLD = "old_";
static final String DATABASE_NAME = "mario_kart_circuit_selector";
/**
* The name of the table containing all information according accessories.
*/
public static final String TABLE_ACCESSORY = "accessory";
static final String TABLE_ACCESSORY = "accessory";
/**
* The name of the table containing all information according characters.
*/
public static final String TABLE_CHARACTER = "character";
static final String TABLE_CHARACTER = "character";
/**
* The name of the table containing all information according games.
*/
public static final String TABLE_GAME = "game";
static final String TABLE_GAME = "game";
/**
* The name of the table containing all information according karts.
*/
public static final String TABLE_KART = "kart";
static final String TABLE_KART = "kart";
/**
* The name of the table containing all information according rulesets.
*/
public static final String TABLE_RULESET = "ruleset";
static final String TABLE_RULESET = "ruleset";
/**
* The name of the table containing all information according tracks.
*/
public static final String TABLE_TRACK = "track";
static final String TABLE_TRACK = "track";
/**
* The name of the table containing all information according wheels.
*/
public static final String TABLE_WHEELS = "wheels";
static final String TABLE_WHEELS = "wheels";
/**
* The global KEY for the _id field in the database.
@@ -168,4 +211,96 @@ public class Constants {
* The global KEY for the number field in the database.
*/
public static final String KEY_NUMBER = "number";
/**
* Global constant defining the where game is <game_name> clause.
*/
public static final String SELECT_WHERE_GAME = " game = ?";
/**
* The Projection to retrieve all Information of a game object from database.
*/
public static final String[] PROJECTION_GAME = {
KEY_ID,
KEY_NAME,
KEY_COVER_URI
};
/**
* The Projection to retrieve all Information of a track object from database.
*/
public static final String[] PROJECTION_TRACK = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_PACKAGE,
KEY_NUMBER,
KEY_COVER_URI,
KEY_AVAILABLE
};
/**
* The Projection to retrieve all Information of a character object from database.
*/
public static final String[] PROJECTION_CHARACTER = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_WEIGHT,
KEY_COVER_URI,
KEY_AVAILABLE
};
/**
* The Projection to retrieve all Information of a kart object from database.
*/
public static final String[] PROJECTION_KART = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_WEIGHT,
KEY_WHEELS,
KEY_ACCESSORY,
KEY_DEDICATED_DRIVER,
KEY_FREE_FOR_ALL,
KEY_COVER_URI,
KEY_AVAILABLE
};
/**
* The Projection to retrieve all Information of a ruleset object from database.
*/
public static final String[] PROJECTION_RULESET = {
KEY_ID,
KEY_GAME,
KEY_MIRROR_CLASS,
KEY_50_CCM,
KEY_100_CCM,
KEY_150_CCM,
KEY_200_CCM,
KEY_KART_FREE_FOR_ALL,
KEY_BIKES
};
/**
* The Projection to retrieve all Information of a accessory object from database.
*/
public static final String[] PROJECTION_ACCESSORY = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_COVER_URI,
KEY_AVAILABLE
};
/**
* The Projection to retrieve all Information of a wheels object from database.
*/
public static final String[] PROJECTION_WHEELS = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_COVER_URI,
KEY_AVAILABLE
};
}

View File

@@ -3,31 +3,18 @@ package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Game;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_NAME;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_OLD;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_PATH;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_AVAILABLE;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_GAME;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_ID;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_NAME;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.TABLE_TRACK;
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.TABLE_WHEELS;
import java.util.ArrayList;
/**
* The Database Handler class which opens/closes connection and handles all CRUD Operations
@@ -44,8 +31,16 @@ public class DatabaseHandler extends SQLiteAssetHelper {
*/
private static final String TAG = "DatabaseHandler";
/**
* The context from which this Handler was called.
*/
private final Context mContext;
/**
* The default constructor of the DatabaseHandler.
*
* @param context The context from which this Handler was called.
*/
public DatabaseHandler(final Context context) {
super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
mContext = context;
@@ -59,177 +54,211 @@ public class DatabaseHandler extends SQLiteAssetHelper {
/**
* Helper method to update the availability status of a single track.
*
* @param track The track which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeTrackAvailability(final Track track, final boolean isAvailable) {
public int changeTrackAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, track.getGame());
values.put(KEY_NAME, track.getName());
values.put(Constants.KEY_PACKAGE, track.getPackage());
values.put(Constants.KEY_NUMBER, track.getmNumber());
if (isAvailable) {
values.put(KEY_AVAILABLE, Constants.TRUE);
} else {
values.put(KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_TRACK, values, KEY_ID + " = ?",
new String[]{String.valueOf(track.getId())});
return db.update(Constants.TABLE_TRACK, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single character.
*
* @param character The character which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeCharacterAvailability(final Character character, final boolean isAvailable) {
public int changeCharacterAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, character.getGame());
values.put(KEY_NAME, character.getName());
values.put(Constants.KEY_WEIGHT, character.getWeight());
if (isAvailable) {
values.put(KEY_AVAILABLE, Constants.TRUE);
} else {
values.put(KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_CHARACTER, values, KEY_ID + " = ?",
new String[]{String.valueOf(character.getId())});
return db.update(Constants.TABLE_CHARACTER, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single kart.
*
* @param kart The kart which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeKartAvailability(final Kart kart, final boolean isAvailable) {
public int changeKartAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, kart.getGame());
values.put(KEY_NAME, kart.getName());
values.put(Constants.KEY_WEIGHT, kart.getWeight());
values.put(Constants.KEY_WHEELS, kart.getWheels());
values.put(Constants.KEY_ACCESSORY, kart.getAccessory());
values.put(Constants.KEY_DEDICATED_DRIVER, kart.getDedicatedDriver());
values.put(Constants.KEY_FREE_FOR_ALL, kart.getFreeForAll());
if (isAvailable) {
values.put(KEY_AVAILABLE, Constants.TRUE);
} else {
values.put(KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_KART, values, KEY_ID + " = ?",
new String[]{String.valueOf(kart.getId())});
return db.update(Constants.TABLE_KART, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single accessory.
*
* @param accessory The accessory which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeAccessoryAvailability(final Accessory accessory, final boolean isAvailable) {
public int changeAccessoryAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, accessory.getGame());
values.put(KEY_NAME, accessory.getName());
if (isAvailable) {
values.put(KEY_AVAILABLE, Constants.TRUE);
} else {
values.put(KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_ACCESSORY, values, KEY_ID + " = ?",
new String[]{String.valueOf(accessory.getId())});
return db.update(Constants.TABLE_ACCESSORY, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single wheels.
*
* @param wheels The wheels which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeWheelsAvailability(final Wheels wheels, final boolean isAvailable) {
public int changeWheelsAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, wheels.getGame());
values.put(KEY_NAME, wheels.getGame());
if (isAvailable) {
values.put(KEY_AVAILABLE, Constants.TRUE);
} else {
values.put(KEY_AVAILABLE, Constants.FALSE);
}
return db.update(TABLE_WHEELS, values, KEY_ID + " = ?",
new String[]{String.valueOf(wheels.getId())});
return db.update(Constants.TABLE_WHEELS, values, selection, selectionArgs);
}
public Track testDBConnection(final int id) {
Log.d(TAG, "testDBConnection: Opening Readable Database.");
final SQLiteDatabase database= this.getReadableDatabase();
// -------------------------------------------------------------------------------------------
// -------------------------- "G E T A L L" F U N C T I O N S ----------------------------
// -------------------------------------------------------------------------------------------
Log.d(TAG, "testDBConnection: Query a single track for id = [" + id + "]");
final Cursor cursor = database.query(TABLE_TRACK, new String[]{KEY_ID,
KEY_NAME, KEY_GAME, KEY_AVAILABLE}, KEY_ID + "=?",
new String[]{String.valueOf(id)}, null, null, null, null);
if (cursor != null) {
Log.d(TAG, "testDBConnection: Moving cursor to first.");
cursor.moveToFirst();
} else {
Log.d(TAG, "testDBConnection: cursor is null");
return null;
}
/**
* Retrieves all Tracks from Database. If a Game is provided, all tracks of this specific
* game will be retrieved.
*
* @return List containing all Track Objects retrieved from Database.
*/
public Cursor getAllTracks(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
DatabaseUtils.dumpCursor(cursor);
Log.d(TAG, "getAllTracks: Creating Cursor for Tracks.");
final Cursor cursor = database.query(Constants.TABLE_TRACK, projection,
selection, selectionArgs, null, null, null, null);
return cursor;
}
final int nameIdx = cursor.getColumnIndex(KEY_NAME);
final int gameIdx = cursor.getColumnIndex(KEY_GAME);
final int idIdx = cursor.getColumnIndex(KEY_ID);
final int availableIdx = cursor.getColumnIndex(KEY_AVAILABLE);
/**
* Retrieves all Karts from Database. If a Game is provided, all karts of this specific
* game will be retrieved.
*
* @return List containing all Kart Objects retrieved from Database.
*/
public Cursor getAllKarts(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
if (nameIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + KEY_NAME + "]");
}
if (gameIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + KEY_GAME + "]");
}
if (idIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + KEY_ID + "]");
}
if (availableIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + KEY_AVAILABLE + "]");
}
Log.d(TAG, "getAllKarts: Creating Cursor for Karts.");
final Cursor cursor = database.query(Constants.TABLE_KART, projection, selection,
selectionArgs, null, null, null, null);
return cursor;
}
if (availableIdx >= 0 && idIdx >= 0 && gameIdx >= 0 && nameIdx >= 0) {
final Track track = new Track();
track.setName(cursor.getString(cursor.getColumnIndex(KEY_NAME)));
track.setGame(cursor.getString(cursor.getColumnIndex(KEY_GAME)));
track.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_ID))));
track.setAvailable(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_AVAILABLE))));
database.close();
/**
* Retrieves all Characters from Database. If a Game is provided, all characters of this
* specific game will be retrieved.
*
* @param projection The character projection.
* @param selection The selection clause.
* @param selectionArgs The selection arguments.
* @return Cursor containing all Character Objects retrieved from Database.
*/
public Cursor getAllCharacters(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
// return contact
return track;
Log.d(TAG, "getAllCharacters: Creating Cursor for Characters.");
final Cursor cursor = database.query(Constants.TABLE_CHARACTER,
projection, selection, selectionArgs, null, null, null,
null);
}
database.close();
return cursor;
}
/**
* Retrieves all Rulesets from Database. If a Game is provided, the ruleset of this specific
* game will be retrieved.
*
* @return List containing all Ruleset Objects retrieved from Database.
*/
public Cursor getAllRulesets(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
Log.d(TAG, "getAllRulesets: Creating Cursor for Rulesets.");
final Cursor cursor = database.query(Constants.TABLE_RULESET, projection, selection,
selectionArgs, null, null, null, null);
return cursor;
}
/**
* Retrieves all Accessories from Database. If a Game is provided, all accessories of this
* specific game will be retrieved.
*
* @return List containing all Accessory Objects retrieved from Database.
*/
public Cursor getAllAccessories(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
Log.d(TAG, "getAllAccessories: Creating Cursor for Accessories.");
final Cursor cursor = database.query(Constants.TABLE_ACCESSORY,
projection, selection, selectionArgs, null, null, null,
null);
return cursor;
}
/**
* Retrieves all Wheels from Database. If a Game is provided, all wheels of this specific
* game will be retrieved.
*
* @return List containing all Wheels Objects retrieved from Database.
*/
public Cursor getAllWheels(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
Log.d(TAG, "getAllWheels: Creating Cursor for Wheels.");
final Cursor cursor = database.query(Constants.TABLE_WHEELS, projection, selection,
selectionArgs, null, null, null, null);
// return contact
return null;
return cursor;
}
/**
* Retrieves all Games from Database.
*
* @return List containing all Game Objects retrieved from Database.
*/
public Cursor getAllGames(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
Log.d(TAG, "getAllGames: Greating Cursor for Games.");
final Cursor cursor = database.query(Constants.TABLE_GAME, projection, selection,
selectionArgs, null, null, null, null);
return cursor;
}
// -------------------------------------------------------------------------------------------
// ------------------------------ T E S T F U N C T I O N S -------------------------------
// -------------------------------------------------------------------------------------------
}

View File

@@ -0,0 +1,151 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* Created by aldo7224 on 18.08.17.
*/
public class GameContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "GameProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/games");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -1,42 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
public class GameSelection extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_selection);
final DatabaseHandler handler = new DatabaseHandler(this);
final EditText editText = (EditText) findViewById(R.id.id_input);
final Button button = (Button) findViewById(R.id.ok_button);
final TextView result = (TextView) findViewById(R.id.result_field);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final int id = Integer.parseInt(editText.getText().toString());
final Track track = handler.testDBConnection(id);
if (track != null) {
final String resultStr = track.getGame() + " - " + track.getName()
+ " - Available = " + track.getAvailable();
result.setText(resultStr);
}
}
});
}
}

View File

@@ -0,0 +1,154 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* The ContentProvider which retrieves the Kart Data.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class KartContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "KartProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/karts");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -0,0 +1,35 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
/**
* Enum holding the different PagerTypes which are displayed in the NavigationTabBar.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public enum PagerType {
/**
* Character tab.
*/
CHARACTER,
/**
* Kart tab.
*/
KART,
/**
* Track tab.
*/
TRACK,
/**
* Accessory tab.
*/
ACCESSORY,
/**
* Wheels tab.
*/
WHEEL
}

View File

@@ -0,0 +1,151 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* Created by aldo7224 on 18.08.17.
*/
public class RulesetContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "RulesetProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/ruleset");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -0,0 +1,154 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* The ContentProvider which retrieves the Track Data.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class TrackContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "TrackProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on cust_master table. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/tracks");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -0,0 +1,154 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.util.Log;
/**
* The ContentProvider which retrieves the Wheels Data.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class WheelsContentProvider extends ContentProvider {
/**
* Tag for debugging output.
*/
private static final String TAG = "WheelsProvider";
/**
* The Provider Name to find the correct Provider and register it in the Android Lifecycle.
*/
public static final String PROVIDER_NAME
= "com.de.aldo_apps.aldo.mariokartcircuitselector";
/**
* A uri to do operations on cust_master table. A content provider is identified by its uri
*/
public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/wheels");
/**
* UriMatcher to check which callback needs to be handled.
* TODO: Check whether this is really needed.
*/
private static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "games", Constants.GAME_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "ruleset", Constants.RULESET_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID);
uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID);
}
/**
* This content provider does the database operations by this object
*/
DatabaseHandler mHandler;
/**
* A callback method which is invoked when the content provider is starting up
*/
@Override
public boolean onCreate() {
mHandler = new DatabaseHandler(getContext());
return true;
}
@Override
public String getType(@NonNull final Uri uri) {
return null;
}
/**
* A callback method which is by the default content uri
*/
@Override
public Cursor query(@NonNull final Uri uri,
final String[] projection,
final String selection,
final String[] selectionArgs,
final String sortOrder) {
Log.d(TAG, "query: Perform Query for [" + uri + "]");
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Getting all Characters.");
return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER,
selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Getting all Karts.");
return mHandler.getAllKarts(Constants.PROJECTION_KART,
selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Getting all Acessories.");
return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY,
selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Getting all Tracks.");
return mHandler.getAllTracks(Constants.PROJECTION_TRACK,
selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Getting all Wheels.");
return mHandler.getAllWheels(Constants.PROJECTION_WHEELS,
selection, selectionArgs);
case Constants.GAME_LOADER_ID:
Log.d(TAG, "query: Getting all Games.");
return mHandler.getAllGames(Constants.PROJECTION_GAME, null, null);
case Constants.RULESET_LOADER_ID:
Log.d(TAG, "query: Getting all Rulesets.");
return mHandler.getAllRulesets(Constants.PROJECTION_RULESET, null, null);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return null;
}
}
@Override
public int delete(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
return 0;
}
@Override
public Uri insert(@NonNull final Uri uri, final ContentValues values) {
return null;
}
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -0,0 +1,64 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.activities;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ListView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.GameContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.GameCursorAdapter;
public class GameSelectionActivity extends AppCompatActivity
implements LoaderManager.LoaderCallbacks<Cursor> {
private static final String TAG = "GameSelectionActivity";
private ListView mListView;
private SimpleCursorAdapter mCursorAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_selection);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mListView = (ListView) findViewById(R.id.all_games_list);
mCursorAdapter = new GameCursorAdapter(this, R.layout.game_list_item,
null, Constants.PROJECTION_GAME, new int[] {}, 0);
mListView.setAdapter(mCursorAdapter);
getSupportLoaderManager().initLoader(Constants.GAME_LOADER_ID, null, this);
}
@Override
public CursorLoader onCreateLoader(int id, Bundle args) {
return new CursorLoader(GameSelectionActivity.this,
GameContentProvider.CONTENT_URI,
Constants.PROJECTION_GAME, null, null, null);
}
@Override
public void onLoadFinished(Loader loader, Cursor cursor) {
Log.d(TAG, "onLoadFinished: Finished Loading for " + loader.getId());
// Swapping the cursor makes the Data visible in the corresponding ListView.
mCursorAdapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(final Loader loader) {
mCursorAdapter.swapCursor(null);
}
}

View File

@@ -0,0 +1,166 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.activities;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.CursorPagerAdapter;
import java.util.ArrayList;
import devlight.io.library.ntb.NavigationTabBar;
/**
* The Activity which handles the Main-Game Selection.
* TODO: Currently the DB-Logic is here, which needs to be handled in an additional screen.
*
* @author aldo7224
* @version 0.2
* @since 17.08.2017
*/
public class GameSettingsActivity extends AppCompatActivity {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "GameSettingsActivity";
/**
* The Custom CursorPagerAdapter which fills the ViewPager with data.
*/
private CursorPagerAdapter mAdapter;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_settings);
final String gameSelected = getIntent().getStringExtra(Constants.KEY_GAME);
// Initialize the Adapter.
mAdapter = new CursorPagerAdapter(getSupportFragmentManager(), gameSelected);
// Fill the UI.
updateUI();
}
/**
* Helper method which handles UI updates.
*/
public void updateUI() {
// Get the colors for the ViewPager Items.
final String[] colors = getResources().getStringArray(R.array.vertical_ntb);
// get the ViewPager and assign adapter to it.
final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
viewPager.setAdapter(mAdapter);
// Get the NavigationBar and assign the models to it.
initNavBar(colors, viewPager);
}
/**
* Helper method which initializes the NavigationTabBar and adds functionality.
*
* @param colors The Array of colors to apply to the different Tabs.
* @param viewPager The ViewPager which should be assigned to the tabBar.
* @return The fully inflated and initialized NavigationTabbar.
*/
private NavigationTabBar initNavBar(final String[] colors, final ViewPager viewPager) {
final NavigationTabBar navigationTabBar
= (NavigationTabBar) findViewById(R.id.ntb_vertical);
final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
models.add(
new NavigationTabBar.Model.Builder(
ResourcesCompat.getDrawable(getResources(),
R.drawable.character_50_dark_grey, null),
Color.parseColor(colors[0])
).title(getString(R.string.title_character))
.badgeTitle("NTB")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
ResourcesCompat.getDrawable(getResources(),
R.drawable.kart_50_dark_grey, null),
Color.parseColor(colors[1])
).title(getString(R.string.title_kart))
.badgeTitle("with")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
ResourcesCompat.getDrawable(getResources(),
R.drawable.track_50_dark_grey, null),
Color.parseColor(colors[2])
).title(getString(R.string.title_track))
.badgeTitle("state")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
ResourcesCompat.getDrawable(getResources(),
R.drawable.accessory_50_dark_grey, null),
Color.parseColor(colors[3])
).title(getString(R.string.title_accessory))
.badgeTitle("icon")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
ResourcesCompat.getDrawable(getResources(),
R.drawable.wheels_50_dark_grey, null),
Color.parseColor(colors[4])
).title(getString(R.string.title_wheels))
.badgeTitle("777")
.build()
);
navigationTabBar.setModels(models);
navigationTabBar.setViewPager(viewPager);
// Assign a OnPageChangedListener to assure correct functionality while swiping.
navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(final int position,
final float positionOffset,
final int positionOffsetPixels) {
}
@Override
public void onPageSelected(final int position) {
Log.d(TAG, "onPageSelected: Selected Tab on Position [" + position
+ "] with Title [" + navigationTabBar.getModels().get(position).getTitle()
+ "]");
navigationTabBar.getModels().get(position).hideBadge();
}
@Override
public void onPageScrollStateChanged(final int state) {
}
});
navigationTabBar.postDelayed(new Runnable() {
@Override
public void run() {
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
navigationTabBar.postDelayed(new Runnable() {
@Override
public void run() {
model.showBadge();
}
}, i * 100);
}
}
}, 500);
return navigationTabBar;
}
}

View File

@@ -0,0 +1,166 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.AccessoryContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Custom CursorAdapter which populates the ListView with accessory data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class AccessoryCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "AccessoryAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public AccessoryCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, coverUri, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the accessory to be displayed.
* @param available Current AvailabilityState of the accessory.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String imageUri,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final View multipleContainer = view.findViewById(R.id.multiple_information_container);
multipleContainer.setVisibility(View.GONE);
final TextView nameTextView = (TextView) view.findViewById(R.id.single_info_name);
nameTextView.setText(name);
nameTextView.setVisibility(View.VISIBLE);
// // Uncomment this if CoverUris are present for accessories and are allowed to be shown.
// final CircleImageView imageView = (CircleImageView) view.findViewById(R.id.image_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(AccessoryContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
}
}

View File

@@ -0,0 +1,177 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.CharacterContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Custom CursorAdapter which populates the ListView with character data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class CharacterCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "CharacterAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public CharacterCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxWeight = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxWeight > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String weight = cursor.getString(idxWeight);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, weight, coverUri, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the character to be displayed.
* @param weight Weight of the character to be displayed.
* @param available Current AvailabilityState of the character.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String weight,
final String imageUri,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView weightTextView = (TextView) view.findViewById(R.id.additional_info_first);
weightTextView.setText(weight);
final TextView separator
= (TextView) view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.GONE);
// // Uncomment this if CoverUris are present for characters and are allowed to be shown.
// final CircleImageView imageView = (CircleImageView) view.findViewById(R.id.image_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(CharacterContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
}
}

View File

@@ -0,0 +1,90 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.PagerType;
import com.de.aldo_apps.aldo.mariokartcircuitselector.fragments.GenericListFragment;
import java.util.Arrays;
/**
* The custom FragmentPagerAdapter which handles data provided via a cursor so the data retrieved
* from DB can be directly accessed and displayed.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class CursorPagerAdapter extends FragmentPagerAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "CursorPagerAdapter";
private String mGame;
/**
* Default constructor.
*/
public CursorPagerAdapter(final FragmentManager fm, final String game) {
super(fm);
mGame = game;
}
@Override
public Fragment getItem(final int position) {
final Bundle bundle = new Bundle();
final String[] projection;
final int loaderId;
// Get the PagerType of the position, so that the correct Loader is initialized.
switch (PagerType.values()[position]) {
case CHARACTER:
projection = Constants.PROJECTION_CHARACTER;
loaderId = Constants.CHARACTER_LOADER_ID;
break;
case KART:
projection = Constants.PROJECTION_KART;
loaderId = Constants.KART_LOADER_ID;
break;
case WHEEL:
projection = Constants.PROJECTION_WHEELS;
loaderId = Constants.WHEELS_LOADER_ID;
break;
case ACCESSORY:
projection = Constants.PROJECTION_ACCESSORY;
loaderId = Constants.ACCESSORY_LOADER_ID;
break;
case TRACK:
projection = Constants.PROJECTION_TRACK;
loaderId = Constants.TRACK_LOADER_ID;
break;
default:
projection = null;
loaderId = Constants.BASE_LOADER_ID;
}
// Provide Projection and LoaderId via a Bundle.
bundle.putStringArray(Constants.PROJECTION_KEY, projection);
bundle.putInt(Constants.LOADER_ID_KEY, loaderId);
bundle.putString(Constants.KEY_GAME, mGame);
Log.d(TAG, "getItem: New GenericListFragment with loaderId = [" + loaderId
+ "] and projection = [" + Arrays.toString(projection) + "] on position ["
+ position + "]");
final GenericListFragment genericListFragment = new GenericListFragment();
genericListFragment.setArguments(bundle);
return genericListFragment;
}
@Override
public int getCount() {
return PagerType.values().length;
}
}

View File

@@ -0,0 +1,133 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.activities.GameSettingsActivity;
/**
* Created by aldo7224 on 18.08.17.
*/
public class GameCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "GameAdapter";
/**
* The Context where this adapter was assigned.
*/
private final Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public GameCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
if (idxId > -1 && idxName > -1 ) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
fillViewWithData(view, id, name, coverUri);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the accessory to be displayed.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String imageUri) {
final TextView idView = (TextView) view.findViewById(R.id.id_view);
idView.setText(String.valueOf(id));
final TextView nameView = (TextView) view.findViewById(R.id.game_name_view);
nameView.setText(name);
// // Uncomment this if CoverUris are present for games and are allowed to be shown.
// final ImageView imageView = (ImageView) view.findViewById(R.id.cover_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
final Intent intent = new Intent(mContext, GameSettingsActivity.class);
intent.putExtra(Constants.KEY_GAME, name);
mContext.startActivity(intent);
}
});
}
}

View File

@@ -0,0 +1,179 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.KartContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Custom CursorAdapter which populates the ListView with kart data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class KartCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "KartAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public KartCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxWeight = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int idxDedicatedDriver = cursor.getColumnIndex(Constants.KEY_DEDICATED_DRIVER);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxDedicatedDriver > -1 && idxWeight > -1
&& idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String weight = cursor.getString(idxDedicatedDriver);
final String dedicatedDriver = cursor.getString(idxWeight);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, weight, dedicatedDriver, coverUri, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the kart to be displayed.
* @param weight Weight of the kart to be displayed.
* @param dedicatedDriver The dedicated Driver of this Kart..
* @param available Current AvailabilityState of the kart.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String weight,
final String dedicatedDriver,
final String imageUri,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView weightTextView = (TextView) view.findViewById(R.id.additional_info_first);
weightTextView.setText(weight);
final TextView dedicatedDriverTextView
= (TextView) view.findViewById(R.id.additional_info_second);
dedicatedDriverTextView.setText(dedicatedDriver);
// // Uncomment this if CoverUris are present for karts and are allowed to be shown.
// final CircleImageView imageView = (CircleImageView) view.findViewById(R.id.image_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(KartContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
}
}

View File

@@ -0,0 +1,178 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.TrackContentProvider;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Custom CursorAdapter which populates the ListView with track data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class TrackCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "TrackAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public TrackCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxPackage = cursor.getColumnIndex(Constants.KEY_PACKAGE);
final int idxNumber = cursor.getColumnIndex(Constants.KEY_NUMBER);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxNumber > -1 && idxPackage > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String number = cursor.getString(idxNumber);
final String packageName = cursor.getString(idxPackage);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, packageName, number, coverUri, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the track to be displayed.
* @param packageName Name of the package where this track is available to be displayed.
* @param number Number of the track to be displayed.
* @param imageUri The String (uri) pointing to the image location.
* @param available Current AvailabilityState of the track.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String packageName,
final String number,
final String imageUri,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView packageTextView = (TextView) view.findViewById(R.id.additional_info_first);
packageTextView.setText(packageName);
final TextView numberTextView = (TextView) view.findViewById(R.id.additional_info_second);
numberTextView.setText(number);
// // Uncomment this if CoverUris are present for tracks and are allowed to be shown.
// final CircleImageView imageView = (CircleImageView) view.findViewById(R.id.image_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(TrackContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
}
}

View File

@@ -0,0 +1,167 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.WheelsContentProvider;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Custom CursorAdapter which populates the ListView with wheels data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class WheelsCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "WheelsAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public WheelsCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxCoverUri = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
String coverUri = null;
if (idxCoverUri > -1) {
coverUri = cursor.getString(idxCoverUri);
}
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, coverUri, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the wheels to be displayed.
* @param available Current AvailabilityState of the wheels.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String imageUri,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final View multipleContainer = view.findViewById(R.id.multiple_information_container);
multipleContainer.setVisibility(View.GONE);
final TextView nameTextView = (TextView) view.findViewById(R.id.single_info_name);
nameTextView.setText(name);
nameTextView.setVisibility(View.VISIBLE);
// // Uncomment this if CoverUris are present for wheels and are allowed to be shown.
// final CircleImageView imageView = (CircleImageView) view.findViewById(R.id.image_view);
// if (imageUri != null && !imageUri.isEmpty()) {
// Log.d(TAG, "fillViewWithData: Loading Image for [" + imageUri + "]");
// Picasso.with(mContext).load(imageUri).error(R.drawable.unknown_character)
// .placeholder(R.drawable.animation_progress).into(imageView);
// imageView.setVisibility(View.VISIBLE);
// } else {
// Log.d(TAG, "fillViewWithData: No image uri provided. ImageView will not be visible.");
// imageView.setVisibility(View.GONE);
// }
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(WheelsContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
}
}

View File

@@ -46,7 +46,8 @@ public class Character {
/**
* Empty default constructor.
*/
public Character() {}
public Character() {
}
/**
* The constructor of this character object.

View File

@@ -67,7 +67,8 @@ public class Kart {
/**
* Empty default constructor.
*/
public Kart() {}
public Kart() {
}
/**
* The constructor of this kart object.
@@ -187,7 +188,7 @@ public class Kart {
*
* @param wheels the availability state of wheels for this kart object.
*/
public void setWheels(int wheels) {
public void setWheels(final int wheels) {
mWheels = wheels;
}
@@ -205,7 +206,7 @@ public class Kart {
*
* @param accessory the availability state of accessory for this kart object.
*/
public void setAccessory(int accessory) {
public void setAccessory(final int accessory) {
mAccessory = accessory;
}
@@ -223,7 +224,7 @@ public class Kart {
*
* @param dedicatedDriver the dedicated driver for this kart.
*/
public void setDedicatedDriver(String dedicatedDriver) {
public void setDedicatedDriver(final String dedicatedDriver) {
mDedicatedDriver = dedicatedDriver;
}
@@ -242,7 +243,7 @@ public class Kart {
* @param freeForAll the availability state of this kart for other characters than the
* dedicated driver.
*/
public void setFreeForAll(int freeForAll) {
public void setFreeForAll(final int freeForAll) {
mFreeForAll = freeForAll;
}

View File

@@ -64,20 +64,21 @@ public class Ruleset {
/**
* Empty default constructor.
*/
public Ruleset() {}
public Ruleset() {
}
/**
* The constructor of this ruleset object.
*
* @param id The database ID of this ruleset object.
* @param game The name of the game where this ruleset object is available.
* @param id The database ID of this ruleset object.
* @param game The name of the game where this ruleset object is available.
* @param mirrorClassAvailable The availability state of a mirror class.
* @param ccm50Available The availability state of a 50 ccm class.
* @param ccm100Available The availability state of a 100 ccm class.
* @param ccm150Available The availability state of a 150 ccm class.
* @param ccm200Available The availability state of a 200 ccm class.
* @param kartsFreeForAll The availability state of a karts for all characters by default.
* @param bikesAvailable The availability state of a bikes.
* @param ccm50Available The availability state of a 50 ccm class.
* @param ccm100Available The availability state of a 100 ccm class.
* @param ccm150Available The availability state of a 150 ccm class.
* @param ccm200Available The availability state of a 200 ccm class.
* @param kartsFreeForAll The availability state of a karts for all characters by default.
* @param bikesAvailable The availability state of a bikes.
*/
public Ruleset(final int id, final String game, final int mirrorClassAvailable,
final int ccm50Available, final int ccm100Available, final int ccm150Available,
@@ -149,7 +150,7 @@ public class Ruleset {
*
* @param ccm50Available the availability of a 50 ccm class.
*/
public void set50CcmAvailable(int ccm50Available) {
public void set50CcmAvailable(final int ccm50Available) {
m50CcmAvailable = ccm50Available;
}
@@ -167,7 +168,7 @@ public class Ruleset {
*
* @param ccm100Available the availability of a 100 ccm class.
*/
public void set100CcmAvailable(int ccm100Available) {
public void set100CcmAvailable(final int ccm100Available) {
m100CcmAvailable = ccm100Available;
}
@@ -185,7 +186,7 @@ public class Ruleset {
*
* @param ccm150Available the availability of a 150 ccm class.
*/
public void set150CcmAvailable(int ccm150Available) {
public void set150CcmAvailable(final int ccm150Available) {
m150CcmAvailable = ccm150Available;
}
@@ -203,7 +204,7 @@ public class Ruleset {
*
* @param ccm200Available the availability of a 200 ccm class.
*/
public void set200CcmAvailable(int ccm200Available) {
public void set200CcmAvailable(final int ccm200Available) {
m200CcmAvailable = ccm200Available;
}
@@ -221,7 +222,7 @@ public class Ruleset {
*
* @param mirrorClassAvailable the availability of a mirror class.
*/
public void setMirrorClassAvailable(int mirrorClassAvailable) {
public void setMirrorClassAvailable(final int mirrorClassAvailable) {
mMirrorClassAvailable = mirrorClassAvailable;
}
@@ -239,7 +240,7 @@ public class Ruleset {
*
* @param kartsFreeForAll the availability of all karts for all characters.
*/
public void setKartsFreeForAll(int kartsFreeForAll) {
public void setKartsFreeForAll(final int kartsFreeForAll) {
mKartsFreeForAll = kartsFreeForAll;
}
@@ -257,7 +258,7 @@ public class Ruleset {
*
* @param bikesAvailable the availability of bikes.
*/
public void setBikesAvailable(int bikesAvailable) {
public void setBikesAvailable(final int bikesAvailable) {
mBikesAvailable = bikesAvailable;
}
}

View File

@@ -51,7 +51,8 @@ public class Track {
/**
* Empty default constructor.
*/
public Track() {}
public Track() {
}
/**
* The constructor of this track object.
@@ -141,9 +142,10 @@ public class Track {
/**
* Sets the package name where this track is part of.
*
* @param packageName the package name where this track is part of.
*/
public void setPackage(String packageName) {
public void setPackage(final String packageName) {
mPackage = packageName;
}
@@ -152,7 +154,7 @@ public class Track {
*
* @return the number of the track within the package.
*/
public int getmNumber() {
public int getNumber() {
return mNumber;
}
@@ -161,7 +163,7 @@ public class Track {
*
* @param number the number of the track within the package.
*/
public void setmNumber(int number) {
public void setNumber(final int number) {
mNumber = number;
}

View File

@@ -0,0 +1,164 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import com.de.aldo_apps.aldo.mariokartcircuitselector.AccessoryContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.CharacterContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.KartContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.TrackContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.WheelsContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.AccessoryCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.CharacterCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.KartCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.TrackCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.WheelsCursorAdapter;
import java.util.Arrays;
/**
* The ListFragment which is initialized in each PagerView and gets populated with data retrieved
* from database via cursor loader.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class GenericListFragment extends ListFragment
implements LoaderManager.LoaderCallbacks<Cursor> {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "GenericListFragment";
/**
* The SimpleCursorAdapter which populates the ListView.
*/
private SimpleCursorAdapter mCursorAdapter;
private String mGame;
private String[] mSelectionArgs;
@Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
// Get Arguments from previous Class.
final Bundle arguments = getArguments();
if (arguments != null) {
// Get Projection and LoaderId from arguments.
final String[] projection = arguments.getStringArray(Constants.PROJECTION_KEY);
final int loaderId = arguments.getInt(Constants.LOADER_ID_KEY);
mGame = arguments.getString(Constants.KEY_GAME);
if (mGame != null) {
mSelectionArgs = new String[]{mGame};
}
final int[] to = new int[]{};
Log.d(TAG, "onCreate: New GenericListFragment with loaderId = [" + loaderId
+ "] and projection = [" + Arrays.toString(projection) + "]");
switch (loaderId) {
case Constants.CHARACTER_LOADER_ID:
mCursorAdapter = new CharacterCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.KART_LOADER_ID:
mCursorAdapter = new KartCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.TRACK_LOADER_ID:
mCursorAdapter = new TrackCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.ACCESSORY_LOADER_ID:
mCursorAdapter = new AccessoryCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.WHEELS_LOADER_ID:
mCursorAdapter = new WheelsCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
default:
mCursorAdapter = new SimpleCursorAdapter(getContext(),
android.R.layout.simple_list_item_1,
null, projection, to, 0);
break;
}
// Set the ListAdapter to the ListView.
setListAdapter(mCursorAdapter);
// initialize Loader for specified LoaderId.
getLoaderManager().initLoader(loaderId, null, this);
} else {
Log.d(TAG, "onCreate: No Arguments where provided. Skip Loader Creation.");
}
}
@Override
public CursorLoader onCreateLoader(final int id, final Bundle args) {
Log.d(TAG, "onCreateLoader: Creating Loader for ID [" + id + "]");
// Create CursorLoader for provided LoaderId.
switch (id) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "onCreateLoader: Creating character loader");
return new CursorLoader(getContext(),
CharacterContentProvider.CONTENT_URI,
Constants.PROJECTION_CHARACTER,
Constants.SELECT_WHERE_GAME, mSelectionArgs, null);
case Constants.KART_LOADER_ID:
Log.d(TAG, "onCreateLoader: Creating kart loader");
return new CursorLoader(getContext(),
KartContentProvider.CONTENT_URI,
Constants.PROJECTION_KART,
Constants.SELECT_WHERE_GAME, mSelectionArgs, null);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "onCreateLoader: Creating kart loader");
return new CursorLoader(getContext(),
WheelsContentProvider.CONTENT_URI,
Constants.PROJECTION_WHEELS,
Constants.SELECT_WHERE_GAME, mSelectionArgs, null);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "onCreateLoader: Creating kart loader");
return new CursorLoader(getContext(),
AccessoryContentProvider.CONTENT_URI,
Constants.PROJECTION_ACCESSORY,
Constants.SELECT_WHERE_GAME, mSelectionArgs, null);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "onCreateLoader: Creating kart loader");
return new CursorLoader(getContext(),
TrackContentProvider.CONTENT_URI,
Constants.PROJECTION_TRACK,
Constants.SELECT_WHERE_GAME, mSelectionArgs, null);
}
return null;
}
@Override
public void onLoadFinished(final Loader loader, final Cursor cursor) {
Log.d(TAG, "onLoadFinished: Finished Loading for " + loader.getId());
// Swapping the cursor makes the Data visible in the corresponding ListView.
mCursorAdapter.swapCursor(cursor);
}
@Override
public void onLoaderReset(final Loader loader) {
mCursorAdapter.swapCursor(null);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_image"
android:pivotX="50%"
android:pivotY="50%"/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 565 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -1,30 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.de.aldo_apps.aldo.mariokartcircuitselector.GameSelection">
tools:context="com.de.aldo_apps.aldo.mariokartcircuitselector.activities.GameSelectionActivity">
<EditText
android:id="@+id/id_input"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
android:theme="@style/AppTheme.AppBarOverlay">
<Button
android:id="@+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Track"
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
/>
</android.support.design.widget.AppBarLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result_field"
android:text="TestContent Goes here" />
<include layout="@layout/content_game_selection" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.de.aldo_apps.aldo.mariokartcircuitselector.activities.GameSettingsActivity"
>
<android.support.v4.view.ViewPager
android:id="@+id/vp_horizontal_ntb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ntb_vertical"/>
<devlight.io.library.ntb.NavigationTabBar
app:ntb_title_mode="all"
app:ntb_titled="true"
app:ntb_title_size="14sp"
android:id="@+id/ntb_vertical"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
app:ntb_preview_colors="@array/vertical_ntb"/>
</RelativeLayout>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.de.aldo_apps.aldo.mariokartcircuitselector.activities.GameSelectionActivity"
tools:showIn="@layout/activity_game_selection">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/all_games_list" />
</android.support.constraint.ConstraintLayout>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="14dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/cover_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/id_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/game_name_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Large" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>

View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="14dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="@+id/database_id_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<!-- CheckBox indicating the current availability status -->
<CheckBox
android:id="@+id/availability_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- LinearLayout container which holds multiple TextViews for multiple information
(e.g. name and weight) -->
<LinearLayout
android:id="@+id/multiple_information_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- The TextView containing the objects name -->
<TextView
android:id="@+id/multi_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Large" />
<!-- LinearLayout which aligns the additional information properly -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- TextView holding the first value (e.g. weight) -->
<TextView
android:id="@+id/additional_info_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- TextView which has a function as a separator between the first and the second
value -->
<TextView
android:id="@+id/additional_information_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/separator_margin"
android:layout_marginRight="@dimen/separator_margin"
android:text="@string/separator" />
<!-- TextView holding the second value (e.g. dedicated driver) -->
<TextView
android:id="@+id/additional_info_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<!-- TextView which simply holds a name without additional information -->
<TextView
android:id="@+id/single_info_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.Large"
android:visibility="gone" />
</LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/image_view"
android:visibility="gone"
android:layout_gravity="end"
/>
</android.support.v7.widget.CardView>
</RelativeLayout>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/all_items_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="vertical_ntb">
<item>#df5a55</item>
<item>#f9bb72</item>
<item>#76afcf</item>
<item>#dd6495</item>
<item>#72d3b4</item>
<item>#563d91</item>
<item>#56342e</item>
<item>#8c9f58</item>
</string-array>
</resources>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="separator_margin">10dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>

View File

@@ -1,3 +1,13 @@
<resources>
<string name="app_name">MarioKartCircuitSelector</string>
<string name="separator">-</string>
<string name="title_track">Strecken</string>
<string name="title_character">Fahrer</string>
<string name="title_kart">Karts</string>
<string name="title_accessory">Sonstiges</string>
<string name="title_wheels">Reifen</string>
<string name="title_activity_game_selection">GameSelectionActivity</string>
</resources>

View File

@@ -8,4 +8,13 @@
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>