10 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
59 changed files with 3140 additions and 1623 deletions

View File

@@ -7,8 +7,8 @@ android {
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
minSdkVersion 16
targetSdkVersion 25
versionCode 7
versionName "0.1.7"
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

@@ -5,27 +5,77 @@ package com.de.aldo_apps.aldo.mariokartcircuitselector;
* centralized class.
*
* @author aldo7224
* @version 0.1
* @since 07.08.2017
* @version 0.2
* @since 17.08.2017
*/
public class Constants {
public final class Constants {
/**
* The Version Code of the Database.
*/
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.
* This is the value for a false statement.
*/
final static Integer FALSE = 0;
public final static Integer FALSE = 0;
/**
* The Base LoaderID.
*/
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.
@@ -70,102 +120,107 @@ public class Constants {
/**
* The global KEY for the _id field in the database.
*/
static final String KEY_ID = "_id";
public static final String KEY_ID = "_id";
/**
* The global KEY for the name field in the database.
*/
static final String KEY_NAME = "name";
public static final String KEY_NAME = "name";
/**
* The global KEY for the game field in the database.
*/
static final String KEY_GAME = "game";
public static final String KEY_GAME = "game";
/**
* The global KEY for the available field in the database.
*/
static final String KEY_AVAILABLE = "available";
public static final String KEY_AVAILABLE = "available";
/**
* The global KEY for the weight field in the database.
*/
static final String KEY_WEIGHT = "weight";
public static final String KEY_WEIGHT = "weight";
/**
* The global KEY for the cover uri field in the database.
*/
static final String KEY_COVER_URI = "cover_uri";
public static final String KEY_COVER_URI = "cover_uri";
/**
* The global KEY for the wheels field in the database.
*/
static final String KEY_WHEELS = "wheels";
public static final String KEY_WHEELS = "wheels";
/**
* The global KEY for the accessory field in the database.
*/
static final String KEY_ACCESSORY = "accessory";
public static final String KEY_ACCESSORY = "accessory";
/**
* The global KEY for the dedicated driver field in the database.
*/
static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
public static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
/**
* The global KEY for the free for all field in the database.
*/
static final String KEY_FREE_FOR_ALL = "free_for_all";
public static final String KEY_FREE_FOR_ALL = "free_for_all";
/**
* The global KEY for the mirror class field in the database.
*/
static final String KEY_MIRROR_CLASS = "mirror_class";
public static final String KEY_MIRROR_CLASS = "mirror_class";
/**
* The global KEY for the 50 ccm field in the database.
*/
static final String KEY_50_CCM = "50_ccm";
public static final String KEY_50_CCM = "50_ccm";
/**
* The global KEY for the 100 ccm field in the database.
*/
static final String KEY_100_CCM = "100_ccm";
public static final String KEY_100_CCM = "100_ccm";
/**
* The global KEY for the 150 ccm field in the database.
*/
static final String KEY_150_CCM = "150_ccm";
public static final String KEY_150_CCM = "150_ccm";
/**
* The global KEY for the 200 ccm field in the database.
*/
static final String KEY_200_CCM = "200_ccm";
public static final String KEY_200_CCM = "200_ccm";
/**
* The global KEY for the kart free for all field in the database.
*/
static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
public static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
/**
* The global KEY for the bikes field in the database.
*/
static final String KEY_BIKES = "bikes";
public static final String KEY_BIKES = "bikes";
/**
* The global KEY for the package field in the database.
*/
static final String KEY_PACKAGE = "package";
public static final String KEY_PACKAGE = "package";
/**
* The global KEY for the number field in the database.
*/
static final String KEY_NUMBER = "number";
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.
*/
static final String[] PROJECTION_GAME = {
public static final String[] PROJECTION_GAME = {
KEY_ID,
KEY_NAME,
KEY_COVER_URI
@@ -174,30 +229,32 @@ public class Constants {
/**
* The Projection to retrieve all Information of a track object from database.
*/
static final String[] PROJECTION_TRACK = {
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.
*/
static final String[] PROJECTION_CHARACTER = {
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.
*/
static final String[] PROJECTION_KART = {
public static final String[] PROJECTION_KART = {
KEY_ID,
KEY_NAME,
KEY_GAME,
@@ -206,13 +263,14 @@ public class Constants {
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.
*/
static final String[] PROJECTION_RULESET = {
public static final String[] PROJECTION_RULESET = {
KEY_ID,
KEY_GAME,
KEY_MIRROR_CLASS,
@@ -227,20 +285,22 @@ public class Constants {
/**
* The Projection to retrieve all Information of a accessory object from database.
*/
static final String[] PROJECTION_ACCESSORY = {
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.
*/
static final String[] PROJECTION_WHEELS = {
public static final String[] PROJECTION_WHEELS = {
KEY_ID,
KEY_NAME,
KEY_GAME,
KEY_COVER_URI,
KEY_AVAILABLE
};
}

View File

@@ -3,16 +3,13 @@ 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.support.annotation.Nullable;
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.Ruleset;
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;
@@ -57,134 +54,76 @@ 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(Constants.KEY_NAME, track.getName());
values.put(Constants.KEY_PACKAGE, track.getPackage());
values.put(Constants.KEY_NUMBER, track.getNumber());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_TRACK, values, Constants.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(Constants.KEY_NAME, character.getName());
values.put(Constants.KEY_WEIGHT, character.getWeight());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_CHARACTER, values, Constants.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(Constants.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(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_KART, values, Constants.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(Constants.KEY_NAME, accessory.getName());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_ACCESSORY, values, Constants.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(Constants.KEY_NAME, wheels.getGame());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_WHEELS, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(wheels.getId())});
return db.update(Constants.TABLE_WHEELS, values, selection, selectionArgs);
}
// -------------------------------------------------------------------------------------------
@@ -195,634 +134,110 @@ public class DatabaseHandler extends SQLiteAssetHelper {
* Retrieves all Tracks from Database. If a Game is provided, all tracks of this specific
* game will be retrieved.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Track Objects retrieved from Database.
*/
public ArrayList<Track> getAllTracks(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllTracks(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
final Cursor cursor = database.query(Constants.TABLE_TRACK, Constants.PROJECTION_TRACK,
selectionClause, selectionArgs, null, null, null, null);
if (cursor != null) {
Log.d(TAG, "getAllTracks: Moving cursor to first.");
cursor.moveToFirst();
} else {
Log.d(TAG, "getAllTracks: cursor is null");
return null;
}
final ArrayList<Track> allAvailableTrack = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int packageIdx = cursor.getColumnIndex(Constants.KEY_PACKAGE);
final int numberIdx = cursor.getColumnIndex(Constants.KEY_NUMBER);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
final Track track = new Track();
boolean isValid = true;
if (idIdx >= 0) {
track.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
track.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (gameIdx >= 0) {
track.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (packageIdx >= 0) {
track.setPackage(cursor.getString(packageIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_PACKAGE + "]");
isValid = false;
}
if (numberIdx >= 0) {
track.setPackage(cursor.getString(numberIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_NUMBER + "]");
isValid = false;
}
if (availableIdx < 0) {
track.setAvailable(cursor.getInt(availableIdx));
} else {
Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_AVAILABLE + "]");
isValid = false;
}
if (isValid) {
allAvailableTrack.add(track);
} else {
Log.d(TAG, "getAllTracks: Do not add Track as one or more arguments are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableTrack;
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;
}
/**
* Retrieves all Karts from Database. If a Game is provided, all karts of this specific
* game will be retrieved.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Kart Objects retrieved from Database.
*/
public ArrayList<Kart> getAllKarts(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllKarts(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
final Cursor cursor = database.query(Constants.TABLE_KART, Constants.PROJECTION_KART,
selectionClause, selectionArgs, null, null, null, null);
if (cursor != null) {
Log.d(TAG, "getAllKarts: Moving cursor to first.");
cursor.moveToFirst();
} else {
Log.d(TAG, "getAllKarts: cursor is null");
return null;
}
final ArrayList<Kart> allAvailableKarts = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int weightIdx = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int accessoryIdx = cursor.getColumnIndex(Constants.KEY_ACCESSORY);
final int wheelsIdx = cursor.getColumnIndex(Constants.KEY_WHEELS);
final int freeForAllIdx = cursor.getColumnIndex(Constants.KEY_FREE_FOR_ALL);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
final Kart kart = new Kart();
boolean isValid = true;
if (idIdx >= 0) {
kart.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
kart.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (gameIdx >= 0) {
kart.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (weightIdx >= 0) {
kart.setWeight(cursor.getString(weightIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_WEIGHT + "]");
isValid = false;
}
if (accessoryIdx >= 0) {
kart.setAccessory(cursor.getInt(accessoryIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_ACCESSORY + "]");
isValid = false;
}
if (wheelsIdx >= 0) {
kart.setWheels(cursor.getInt(wheelsIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_WHEELS + "]");
isValid = false;
}
if (freeForAllIdx >= 0) {
kart.setFreeForAll(cursor.getInt(freeForAllIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_FREE_FOR_ALL + "]");
isValid = false;
}
if (availableIdx < 0) {
kart.setAvailable(cursor.getInt(availableIdx));
} else {
Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_AVAILABLE + "]");
isValid = false;
}
if (isValid) {
allAvailableKarts.add(kart);
} else {
Log.d(TAG, "getAllKarts: Do not add Kart as one or more arguments are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableKarts;
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;
}
/**
* Retrieves all Characters from Database. If a Game is provided, all characters of this
* specific game will be retrieved.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Character Objects retrieved from Database.
* @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 ArrayList<Character> getAllCharacters(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllCharacters(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
Log.d(TAG, "getAllCharacters: Creating Cursor for Characters.");
final Cursor cursor = database.query(Constants.TABLE_CHARACTER,
Constants.PROJECTION_CHARACTER, selectionClause, selectionArgs, null, null, null,
projection, selection, selectionArgs, null, null, null,
null);
final ArrayList<Character> allAvailableCharacters = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int weightIdx = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
final Character character = new Character();
boolean isValid = true;
if (idIdx >= 0) {
character.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
character.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (gameIdx >= 0) {
character.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (weightIdx >= 0) {
character.setWeight(cursor.getString(weightIdx));
} else {
Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_WEIGHT + "]");
isValid = false;
}
if (availableIdx < 0) {
character.setAvailable(cursor.getInt(availableIdx));
} else {
Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_AVAILABLE + "]");
isValid = false;
}
if (isValid) {
allAvailableCharacters.add(character);
} else {
Log.d(TAG, "getAllCharacters: Do not add Character as one or more arguments " +
"are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableCharacters;
return cursor;
}
/**
* Retrieves all Rulesets from Database. If a Game is provided, the ruleset of this specific
* game will be retrieved.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Ruleset Objects retrieved from Database.
*/
public ArrayList<Ruleset> getAllRulesets(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllRulesets(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
final Cursor cursor = database.query(Constants.TABLE_RULESET, Constants.PROJECTION_RULESET,
selectionClause, selectionArgs, null, null, null, null);
final ArrayList<Ruleset> allAvailableRulesets = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int mirrorIdx = cursor.getColumnIndex(Constants.KEY_MIRROR_CLASS);
final int ccm50Idx = cursor.getColumnIndex(Constants.KEY_50_CCM);
final int ccm100Idx = cursor.getColumnIndex(Constants.KEY_100_CCM);
final int ccm150Idx = cursor.getColumnIndex(Constants.KEY_150_CCM);
final int ccm200Idx = cursor.getColumnIndex(Constants.KEY_200_CCM);
final int freeForAllIdx = cursor.getColumnIndex(Constants.KEY_KART_FREE_FOR_ALL);
final int bikesIdx = cursor.getColumnIndex(Constants.KEY_BIKES);
final Ruleset ruleset = new Ruleset();
boolean isValid = true;
if (idIdx >= 0) {
ruleset.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (gameIdx >= 0) {
ruleset.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (mirrorIdx >= 0) {
ruleset.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (ccm50Idx >= 0) {
ruleset.set50CcmAvailable(cursor.getInt(ccm50Idx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_50_CCM + "]");
isValid = false;
}
if (ccm100Idx >= 0) {
ruleset.set100CcmAvailable(cursor.getInt(ccm100Idx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_100_CCM + "]");
isValid = false;
}
if (ccm150Idx >= 0) {
ruleset.set150CcmAvailable(cursor.getInt(ccm150Idx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_150_CCM + "]");
isValid = false;
}
if (ccm200Idx >= 0) {
ruleset.set200CcmAvailable(cursor.getInt(ccm200Idx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_200_CCM + "]");
isValid = false;
}
if (freeForAllIdx >= 0) {
ruleset.setKartsFreeForAll(cursor.getInt(freeForAllIdx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_KART_FREE_FOR_ALL
+ "]");
isValid = false;
}
if (bikesIdx >= 0) {
ruleset.setBikesAvailable(cursor.getInt(bikesIdx));
} else {
Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_BIKES + "]");
isValid = false;
}
if (isValid) {
allAvailableRulesets.add(ruleset);
} else {
Log.d(TAG, "getAllRulesets: Do not add Ruleset as one or more arguments " +
"are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableRulesets;
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.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Accessory Objects retrieved from Database.
*/
public ArrayList<Accessory> getAllAccessories(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllAccessories(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
Log.d(TAG, "getAllAccessories: Creating Cursor for Accessories.");
final Cursor cursor = database.query(Constants.TABLE_ACCESSORY,
Constants.PROJECTION_ACCESSORY, selectionClause, selectionArgs, null, null, null,
projection, selection, selectionArgs, null, null, null,
null);
final ArrayList<Accessory> allAvailableAccessories = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
final Accessory accessory = new Accessory();
boolean isValid = true;
if (idIdx >= 0) {
accessory.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
accessory.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (gameIdx >= 0) {
accessory.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (availableIdx < 0) {
accessory.setAvailable(cursor.getInt(availableIdx));
} else {
Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_AVAILABLE + "]");
isValid = false;
}
if (isValid) {
allAvailableAccessories.add(accessory);
} else {
Log.d(TAG, "getAllAccessories: Do not add Accessory as one or more arguments " +
"are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableAccessories;
return cursor;
}
/**
* Retrieves all Wheels from Database. If a Game is provided, all wheels of this specific
* game will be retrieved.
*
* @param game The game of which all tracks should be retrieved.
* @param onlyAvailable If true, only available objects will be returned, otherwise all
*
* @return List containing all Wheels Objects retrieved from Database.
*/
public ArrayList<Wheels> getAllWheels(@Nullable final Game game,
final boolean onlyAvailable) {
public Cursor getAllWheels(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final String selectionClause;
final String[] selectionArgs;
if (game != null && onlyAvailable) {
selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)};
} else if (game != null) {
selectionClause = Constants.KEY_GAME + "=?";
selectionArgs = new String[]{game.getName()};
} else if (onlyAvailable) {
selectionClause = Constants.KEY_AVAILABLE + "=?";
selectionArgs = new String[]{String.valueOf(Constants.TRUE)};
} else {
selectionClause = null;
selectionArgs = null;
}
final Cursor cursor = database.query(Constants.TABLE_WHEELS, Constants.PROJECTION_WHEELS,
selectionClause, selectionArgs, null, null, null, null);
if (cursor != null) {
Log.d(TAG, "getAllWheels: Moving cursor to first.");
cursor.moveToFirst();
} else {
Log.d(TAG, "getAllWheels: cursor is null");
return null;
}
final ArrayList<Wheels> allAvailableWheels = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
final Wheels wheels = new Wheels();
boolean isValid = true;
if (idIdx >= 0) {
wheels.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
wheels.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (gameIdx >= 0) {
wheels.setGame(cursor.getString(gameIdx));
} else {
Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_GAME + "]");
isValid = false;
}
if (availableIdx < 0) {
wheels.setAvailable(cursor.getInt(availableIdx));
} else {
Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_AVAILABLE + "]");
isValid = false;
}
if (isValid) {
allAvailableWheels.add(wheels);
} else {
Log.d(TAG, "getAllWheels: Do not add Wheels as one or more arguments are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
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 allAvailableWheels;
return cursor;
}
/**
@@ -830,121 +245,20 @@ public class DatabaseHandler extends SQLiteAssetHelper {
*
* @return List containing all Game Objects retrieved from Database.
*/
public ArrayList<Game> getAllGames() {
public Cursor getAllGames(final String[] projection,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase database = this.getReadableDatabase();
final Cursor cursor = database.query(Constants.TABLE_GAME, Constants.PROJECTION_GAME, null,
null, null, null, null, null);
if (cursor != null) {
Log.d(TAG, "getAllGames: Moving cursor to first.");
cursor.moveToFirst();
} else {
Log.d(TAG, "getAllGames: cursor is null");
return null;
}
Log.d(TAG, "getAllGames: Greating Cursor for Games.");
final Cursor cursor = database.query(Constants.TABLE_GAME, projection, selection,
selectionArgs, null, null, null, null);
final ArrayList<Game> allAvailableGames = new ArrayList<>();
do {
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int coverUriIdx = cursor.getColumnIndex(Constants.KEY_COVER_URI);
final Game game = new Game();
boolean isValid = true;
if (idIdx >= 0) {
game.setId(cursor.getInt(idIdx));
} else {
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_ID + "]");
isValid = false;
}
if (nameIdx >= 0) {
game.setName(cursor.getString(nameIdx));
} else {
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_NAME + "]");
isValid = false;
}
if (coverUriIdx >= 0) {
game.setCoverUri(cursor.getString(coverUriIdx));
} else {
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_COVER_URI + "]");
isValid = false;
}
if (isValid) {
allAvailableGames.add(game);
} else {
Log.d(TAG, "getAllGames: Do not add Game as one or more arguments are invalid.");
}
} while (cursor.moveToNext());
cursor.close();
database.close();
// return contact
return allAvailableGames;
return cursor;
}
// -------------------------------------------------------------------------------------------
// ------------------------------ T E S T F U N C T I O N S -------------------------------
// -------------------------------------------------------------------------------------------
// TODO: This is only an intermediate state and can be removed later on
public Track testDBConnection(final int id) {
Log.d(TAG, "testDBConnection: Opening Readable Database.");
final SQLiteDatabase database = this.getReadableDatabase();
Log.d(TAG, "testDBConnection: Query a single track for id = [" + id + "]");
final Cursor cursor = database.query(Constants.TABLE_TRACK, new String[]{Constants.KEY_ID,
Constants.KEY_NAME, Constants.KEY_GAME, Constants.KEY_AVAILABLE},
Constants.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;
}
DatabaseUtils.dumpCursor(cursor);
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (nameIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_NAME + "]");
}
if (gameIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_GAME + "]");
}
if (idIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_ID + "]");
}
if (availableIdx < 0) {
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_AVAILABLE + "]");
}
if (availableIdx >= 0 && idIdx >= 0 && gameIdx >= 0 && nameIdx >= 0) {
final Track track = new Track();
track.setName(cursor.getString(nameIdx));
track.setGame(cursor.getString(gameIdx));
track.setId(Integer.parseInt(cursor.getString(idIdx)));
track.setAvailable(Integer.parseInt(cursor.getString(availableIdx)));
database.close();
// return contact
return track;
}
cursor.close();
database.close();
// return contact
return null;
}
}

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,41 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector;
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(final 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(final 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;
}
@@ -161,7 +163,7 @@ public class Track {
*
* @param number the number of the track within the package.
*/
public void setNumber(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);
}
}

View File

@@ -1,124 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory;
/**
* The SingleAccessoryFragment which displays all information of a single accessory object. Also
* this fragment handles the onClick. Based on the Click we will toggle the availability of this
* object in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleAccessoryFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleAccessoryFragment";
/**
* Checkbox indicating the current availability status of the single accessory object.
*/
private CheckBox mAccessoryAvailable;
/**
* TextView displaying the name of the single accessory object.
*/
private TextView mAccessoryName;
/**
* The accessory object assigned to this fragment.
*/
private Accessory mAccessory;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mAccessoryAvailable != null) {
mAccessoryAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mAccessoryAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mAccessoryAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mAccessory != null) {
mHandler.changeAccessoryAvailability(mAccessory, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Accessory are null!");
}
}
});
// Mark the Container as GONE.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.GONE);
// Initialize all single views and make them visible.
mAccessoryName = (TextView) view.findViewById(R.id.single_info_name);
mAccessoryName.setVisibility(View.VISIBLE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param accessory The Accessory object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Accessory accessory, final DatabaseHandler handler) {
mAccessory = accessory;
mHandler = handler;
mAccessoryAvailable.setChecked(accessory.getAvailable());
mAccessoryName.setText(accessory.getName());
}
}

View File

@@ -1,140 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character;
/**
* The SingleCharacterFragment which displays all information of a single character object. Also
* this fragment handles the onClick. Based on the Click we will toggle the availability of this
* object in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleCharacterFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleCharacterFragment";
/**
* Checkbox indicating the current availability status of the single character object.
*/
private CheckBox mCharacterAvailable;
/**
* TextView displaying the name of the single character object.
*/
private TextView mCharacterName;
/**
* TextView displaying the package (Cup) of the single character object.
*/
private TextView mCharacterWeight;
/**
* The character object assigned to this fragment.
*/
private Character mCharacter;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mCharacterAvailable != null) {
mCharacterAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mCharacterAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mCharacterAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mCharacter != null) {
mHandler.changeCharacterAvailability(mCharacter, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Character are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mCharacterName = (TextView) view.findViewById(R.id.multi_view_name);
mCharacterWeight = (TextView) view.findViewById(R.id.additional_info_first);
mCharacterWeight.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.GONE);
final View secondInfo = view.findViewById(R.id.additional_info_second);
secondInfo.setVisibility(View.GONE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param character The Character object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Character character, final DatabaseHandler handler) {
mCharacter = character;
mHandler = handler;
mCharacterAvailable.setChecked(character.getAvailable());
mCharacterName.setText(character.getName());
mCharacterWeight.setText(character.getWeight());
}
}

View File

@@ -1,146 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart;
/**
* The SingleKartFragment which displays all information of a single kart object. Also this fragment
* handles the onClick. Based on the Click we will toggle the availability of this object in the
* database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleKartFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleKartFragment";
/**
* Checkbox indicating the current availability status of the single kart object.
*/
private CheckBox mKartAvailable;
/**
* TextView displaying the name of the single kart object.
*/
private TextView mKartName;
/**
* TextView displaying the weight of the single kart object.
*/
private TextView mKartWeight;
/**
* TextView displaying the dedicated Driver of the single kart object.
*/
private TextView mKartDedicatedDriver;
/**
* The kart object assigned to this fragment.
*/
private Kart mKart;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mKartAvailable != null) {
mKartAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mKartAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mKartAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mKart != null) {
mHandler.changeKartAvailability(mKart, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Kart are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mKartName = (TextView) view.findViewById(R.id.multi_view_name);
mKartWeight = (TextView) view.findViewById(R.id.additional_info_first);
mKartWeight.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.VISIBLE);
mKartDedicatedDriver = (TextView) view.findViewById(R.id.additional_info_second);
mKartDedicatedDriver.setVisibility(View.VISIBLE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param kart The Kart object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Kart kart, final DatabaseHandler handler) {
mKart = kart;
mHandler = handler;
mKartAvailable.setChecked(kart.getAvailable());
mKartName.setText(kart.getName());
mKartWeight.setText(kart.getWeight());
mKartDedicatedDriver.setText(kart.getDedicatedDriver());
}
}

View File

@@ -1,145 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
/**
* The SingleTrackFragment which displays all information of a single track object. Also this
* fragment handles the onClick. Based on the Click we will toggle the availability of this object
* in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleTrackFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleTrackFragment";
/**
* Checkbox indicating the current availability status of the single track object.
*/
private CheckBox mTrackAvailable;
/**
* TextView displaying the name of the single track object.
*/
private TextView mTrackName;
/**
* TextView displaying the package (Cup) of the single track object.
*/
private TextView mTrackPackage;
/**
* TextView displaying the number of the single track object.
*/
private TextView mTrackNumber;
/**
* The track object assigned to this fragment.
*/
private Track mTrack;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mTrackAvailable != null) {
mTrackAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mTrackAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mTrackAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mTrack != null) {
mHandler.changeTrackAvailability(mTrack, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Track are null!");
}
}
});
// Make the Container Visible.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.VISIBLE);
// Initialize all single views and make them visible.
mTrackName = (TextView) view.findViewById(R.id.multi_view_name);
mTrackPackage = (TextView) view.findViewById(R.id.additional_info_first);
mTrackPackage.setVisibility(View.VISIBLE);
final View separator = view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.VISIBLE);
mTrackNumber = (TextView) view.findViewById(R.id.additional_info_second);
mTrackNumber.setVisibility(View.VISIBLE);
// Mark the single name view (without additional information) as GONE
final View singleName = view.findViewById(R.id.single_info_name);
singleName.setVisibility(View.GONE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param track The Track object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Track track, final DatabaseHandler handler) {
mTrack = track;
mHandler = handler;
mTrackAvailable.setChecked(track.getAvailable());
mTrackName.setText(track.getName());
mTrackPackage.setText(track.getPackage());
mTrackNumber.setText(track.getNumber());
}
}

View File

@@ -1,125 +0,0 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments;
import android.os.Bundle;
import android.support.v4.app.Fragment;
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.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels;
/**
* The SingleWheelsFragment which displays all information of a single wheels object. Also this
* fragment handles the onClick. Based on the Click we will toggle the availability of this object
* in the database.
*
* @author aldo7224
* @version 0.1
* @since 10.08.2017
*/
public class SingleWheelsFragment extends Fragment {
/**
* The Tag for Debugging Output.
*/
private static final String TAG = "SingleWheelsFragment";
/**
* Checkbox indicating the current availability status of the single wheels object.
*/
private CheckBox mWheelsAvailable;
/**
* TextView displaying the name of the single wheels object.
*/
private TextView mWheelsName;
/**
* The wheels object assigned to this fragment.
*/
private Wheels mWheels;
/**
* The Database handler passed from the activity to handle database operations.
*/
private DatabaseHandler mHandler;
@Override
public View onCreateView(final LayoutInflater inflater,
final ViewGroup container,
final Bundle savedInstanceState) {
// Inflate the GenericListItem and return it. All Operations on the View will be handled
// in own functions.
return inflater.inflate(R.layout.generic_list_item, container, false);
}
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Initialize the Views and member variables.
// Make all the Visible/Invisible/Gone Actions here as we know which information will be
// shown here.
initViews(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
if (mWheelsAvailable != null) {
mWheelsAvailable.toggle();
}
}
});
}
/**
* Helper method to initialize all View objects and toggle the visibility as we now know which
* object should be passed into the fragment.
*
* @param view The Parent View.
*/
private void initViews(final View view) {
mWheelsAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox);
// Assign a CheckedChange Listener to the Checkbox, so we can update the status in the
// database as well.
mWheelsAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton,
final boolean availability) {
if (mHandler != null && mWheels != null) {
mHandler.changeWheelsAvailability(mWheels, availability);
} else {
Log.d(TAG, "onCheckedChanged: Either Handler or Wheels are null!");
}
}
});
// Mark the Container as GONE.
final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container);
additionalInfoContainer.setVisibility(View.GONE);
// Initialize all single views and make them visible.
mWheelsName = (TextView) view.findViewById(R.id.single_info_name);
mWheelsName.setVisibility(View.VISIBLE);
}
/**
* Helper method which sets the real texts/arguments to the view objects.
*
* @param wheels The Wheels object of which we will retrieve our texts/arguments.
* @param handler The Database handler which handles the database operations.
*/
public void setArguments(final Wheels wheels, final DatabaseHandler handler) {
mWheels = wheels;
mHandler = handler;
mWheelsAvailable.setChecked(wheels.getAvailable());
mWheelsName.setText(wheels.getName());
}
}

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

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

@@ -1,6 +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

@@ -2,4 +2,12 @@
<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>