├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── scopes
│ └── scope_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── fastfood1.jpg
│ │ │ │ ├── fastfood3.jpg
│ │ │ │ ├── fastfood2.jpeg
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_add_item.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_settings.xml
│ │ │ │ ├── fragment_add_item.xml
│ │ │ │ ├── fragment_shopping_list.xml
│ │ │ │ └── shopping_list_item.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ └── layout-sw600dp
│ │ │ │ └── fragment_add_item.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jonmal
│ │ │ │ └── shoppit
│ │ │ │ ├── Interfaces
│ │ │ │ └── FragmentCommunication.java
│ │ │ │ ├── objects
│ │ │ │ └── ShoppingItem.java
│ │ │ │ ├── activities
│ │ │ │ ├── AddItemActivity.java
│ │ │ │ ├── SettingsActivity.java
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── receivers
│ │ │ │ └── onBootCompletedReceiver.java
│ │ │ │ ├── MainApplication.java
│ │ │ │ ├── data
│ │ │ │ ├── ShoppingListDbHelper.java
│ │ │ │ ├── ShopContract.java
│ │ │ │ └── ItemProvider.java
│ │ │ │ ├── adapters
│ │ │ │ └── ShoppingListAdapter.java
│ │ │ │ └── views
│ │ │ │ ├── AddItemFragment.java
│ │ │ │ └── ShoppingListFragment.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jonmal
│ │ └── shoppit
│ │ └── ApplicationTest.java
├── build.gradle
├── proguard-rules.pro
└── app.iml
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── APK+selfEvaluation+Mockups
├── udacity mockups.pdf
├── Udacityfinalproject.pdf
├── shopppit-app-release.apk
└── Android+Fundamentals+Project+Self-Evaluation.docx
├── gradle.properties
├── shoppIt.iml
├── gradlew.bat
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | shoppIt
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | /.idea/libraries
5 | .DS_Store
6 | /build
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/APK+selfEvaluation+Mockups/udacity mockups.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/APK+selfEvaluation+Mockups/udacity mockups.pdf
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/fastfood1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-xxhdpi/fastfood1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/fastfood3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-xxhdpi/fastfood3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/fastfood2.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-xxhdpi/fastfood2.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/APK+selfEvaluation+Mockups/Udacityfinalproject.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/APK+selfEvaluation+Mockups/Udacityfinalproject.pdf
--------------------------------------------------------------------------------
/APK+selfEvaluation+Mockups/shopppit-app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/APK+selfEvaluation+Mockups/shopppit-app-release.apk
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/APK+selfEvaluation+Mockups/Android+Fundamentals+Project+Self-Evaluation.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jy2k/shoppIt/master/APK+selfEvaluation+Mockups/Android+Fundamentals+Project+Self-Evaluation.docx
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_add_item.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/Interfaces/FragmentCommunication.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.Interfaces;
2 |
3 | import com.jonmal.shoppit.objects.ShoppingItem;
4 |
5 | public interface FragmentCommunication {
6 |
7 | public void addShoppingItem(ShoppingItem shoppingItem);
8 | public void startAddItemActivity();
9 | }
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jonmal/shoppit/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 21
5 | buildToolsVersion "21.1.2"
6 |
7 | defaultConfig {
8 | applicationId "com.jonmal.shoppit"
9 | minSdkVersion 16
10 | targetSdkVersion 21
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:21.0.3'
25 | }
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Jon/Downloads/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/shoppIt.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | shoppIt
5 | Hello world!
6 | Settings
7 | Share App
8 | Shopping List:
9 | Add Item
10 | Title
11 | Description
12 | Submit
13 | Please fill in a title
14 | Please fill in a description
15 | Lock shopping list (when locked, Items can not be added)
16 | List has been locked using settings menu... \\r\\n To unlock use settings
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/objects/ShoppingItem.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.objects;
2 |
3 | public class ShoppingItem {
4 |
5 | //==========================================================
6 | // Fields
7 | //==========================================================
8 |
9 | private String mTitle;
10 | private String mDescritption;
11 |
12 | //==========================================================
13 | // Constructors
14 | //==========================================================
15 |
16 | public ShoppingItem() {
17 | }
18 |
19 | public ShoppingItem(String title, String description) {
20 |
21 | mTitle = title;
22 | mDescritption = description;
23 | }
24 |
25 | //==========================================================
26 | // Setters / Getters
27 | //==========================================================
28 |
29 |
30 | public String getTitle() {
31 | return mTitle;
32 | }
33 |
34 | public void setTitle(String title) {
35 | this.mTitle = title;
36 | }
37 |
38 | public String getDescritption() {
39 | return mDescritption;
40 | }
41 |
42 | public void semDescritption(String descritption) {
43 | this.mDescritption = descritption;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_add_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
18 |
22 |
23 |
28 |
29 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_shopping_list.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
17 |
18 |
23 |
24 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/shopping_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
19 |
20 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/activities/AddItemActivity.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.os.Vibrator;
8 |
9 | import com.jonmal.shoppit.MainApplication;
10 | import com.jonmal.shoppit.R;
11 | import com.jonmal.shoppit.views.AddItemFragment;
12 |
13 | public class AddItemActivity extends Activity {
14 |
15 | //==========================================================
16 | // Constants
17 | //==========================================================
18 |
19 | public static final int ACTIVITY_ADD_ITEM = 1;
20 |
21 | //==========================================================
22 | // Activity Lifecycle
23 | //==========================================================
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_add_item);
29 |
30 | if (savedInstanceState == null) {
31 | getFragmentManager().beginTransaction()
32 | .add(R.id.container, AddItemFragment.newInstance())
33 | .commit();
34 | }
35 | }
36 |
37 | public void onItemSubmitted(Intent data) {
38 |
39 | setResult(Activity.RESULT_OK, data);
40 |
41 | Vibrator vibrator = (Vibrator) MainApplication.getAppContext().getSystemService(Context.VIBRATOR_SERVICE);
42 | vibrator.vibrate(500);
43 |
44 | finish();
45 | }
46 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
32 |
33 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/receivers/onBootCompletedReceiver.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.receivers;
2 |
3 | import android.app.NotificationManager;
4 | import android.app.PendingIntent;
5 | import android.content.BroadcastReceiver;
6 | import android.content.Context;
7 | import android.content.Intent;
8 | import android.support.v4.app.NotificationCompat;
9 |
10 | import com.jonmal.shoppit.R;
11 | import com.jonmal.shoppit.activities.MainActivity;
12 |
13 | public class onBootCompletedReceiver extends BroadcastReceiver {
14 |
15 | @Override
16 | public void onReceive(Context context, Intent intent) {
17 |
18 | Intent resultIntent = new Intent(context, MainActivity.class);
19 |
20 | PendingIntent resultPendingIntent =
21 | PendingIntent.getActivity(
22 | context,
23 | 0,
24 | resultIntent,
25 | PendingIntent.FLAG_UPDATE_CURRENT
26 | );
27 |
28 | NotificationCompat.Builder mBuilder =
29 | new NotificationCompat.Builder(context)
30 | .setSmallIcon(R.drawable.fastfood1)
31 | .setContentTitle("Shoppit")
32 | .setContentText("Because forgetting is for lamers!")
33 | .setContentIntent(resultPendingIntent);
34 |
35 | // Sets an ID for the notification
36 | int mNotificationId = 333;
37 |
38 | // Gets an instance of the NotificationManager service
39 | NotificationManager mNotifyMgr =
40 | (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
41 |
42 | // Builds the notification and issues it.
43 | mNotifyMgr.notify(mNotificationId, mBuilder.build());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/MainApplication.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.os.Handler;
7 |
8 | public class MainApplication extends Application {
9 |
10 | //==========================================================
11 | // Constants
12 | //==========================================================
13 |
14 | private static final String SHARED_PREFS_NAME = "com.jonmal.SHARED_PREFS_NAME";
15 |
16 | //==========================================================
17 | // Fields
18 | //==========================================================
19 |
20 | private static Context mAppContext;
21 | private static Handler mMainThreadHandler;
22 | private static SharedPreferences prefs;
23 |
24 | //==========================================================
25 | // Constructor
26 | //==========================================================
27 |
28 |
29 | @Override
30 | public void onCreate() {
31 | super.onCreate();
32 |
33 | mAppContext = this;
34 | mMainThreadHandler = new Handler();
35 | prefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE);
36 | }
37 |
38 | //===========================================================
39 | // Public Methods
40 | //===========================================================
41 |
42 | public static Context getAppContext() {
43 | return mAppContext;
44 | }
45 |
46 | public static Handler getUIHandler() {
47 | return mMainThreadHandler;
48 | }
49 |
50 | public static SharedPreferences getSharedPreferences() {
51 | return prefs;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/data/ShoppingListDbHelper.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.data;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | public class ShoppingListDbHelper extends SQLiteOpenHelper {
8 |
9 | // If you change the database schema, you must increment the database version.
10 | private static final int DATABASE_VERSION = 1;
11 |
12 | public static final String DATABASE_NAME = "shop.db";
13 |
14 | public ShoppingListDbHelper(Context context) {
15 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
16 | }
17 |
18 | @Override
19 | public void onCreate(SQLiteDatabase sqLiteDatabase) {
20 | // Create a table to hold locations. A location consists of the string supplied in the
21 | // location setting, the city name, and the latitude and longitude
22 | final String SQL_CREATE_SHOP_TABLE = "CREATE TABLE " + ShopContract.ItemEntry.TABLE_NAME + " (" +
23 | ShopContract.ItemEntry._ID + " INTEGER PRIMARY KEY," +
24 | ShopContract.ItemEntry.COLUMN_TITLE + " TEXT NOT NULL, " +
25 | ShopContract.ItemEntry.COLUMN_DESCRIPTION + " TEXT NOT NULL" +
26 | " );";
27 |
28 | sqLiteDatabase.execSQL(SQL_CREATE_SHOP_TABLE);
29 | }
30 |
31 | @Override
32 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
33 | // This database is only a cache for online data, so its upgrade policy is
34 | // to simply to discard the data and start over
35 | // Note that this only fires if you change the version number for your database.
36 | // It does NOT depend on the version number for your application.
37 | // If you want to update the schema without wiping data, commenting out the next 2 lines
38 | // should be your top priority before modifying this method.
39 | sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + ShopContract.ItemEntry.TABLE_NAME);
40 | onCreate(sqLiteDatabase);
41 | }
42 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/activities/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.SharedPreferences;
5 | import android.os.Bundle;
6 | import android.widget.CheckBox;
7 | import android.widget.CompoundButton;
8 |
9 | import com.jonmal.shoppit.MainApplication;
10 | import com.jonmal.shoppit.R;
11 |
12 | public class SettingsActivity extends Activity {
13 |
14 | //==========================================================
15 | // Constants
16 | //==========================================================
17 |
18 | public static final String PREF_LOCK_SHOPPING_LIST = "com.jonmal.PREF_LOCK_SHOPPING_LIST";
19 |
20 | //==========================================================
21 | // Fields
22 | //==========================================================
23 |
24 | //ui references
25 | private CheckBox mLockShoppingListCB;
26 |
27 | //==========================================================
28 | // Activity Lifecycle
29 | //==========================================================
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_settings);
35 |
36 | mLockShoppingListCB = (CheckBox) findViewById(R.id.activitySettings_lockListCB);
37 |
38 | final SharedPreferences sharedPreferences = MainApplication.getSharedPreferences();
39 | boolean shouldLockCheckList = sharedPreferences.getBoolean(PREF_LOCK_SHOPPING_LIST, false);
40 |
41 | mLockShoppingListCB.setChecked(shouldLockCheckList);
42 | mLockShoppingListCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
43 |
44 | @Override
45 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
46 |
47 | mLockShoppingListCB.setChecked(isChecked);
48 | sharedPreferences.edit().putBoolean(PREF_LOCK_SHOPPING_LIST, isChecked).apply();
49 | }
50 | });
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/data/ShopContract.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.data;
2 |
3 | import android.content.ContentUris;
4 | import android.net.Uri;
5 | import android.provider.BaseColumns;
6 |
7 | public class ShopContract {
8 |
9 | // The "Content authority" is a name for the entire content provider, similar to the
10 | // relationship between a domain name and its website. A convenient string to use for the
11 | // content authority is the package name for the app, which is guaranteed to be unique on the
12 | // device.
13 | public static final String CONTENT_AUTHORITY = "com.example.android.shoppit.app";
14 |
15 | // Use CONTENT_AUTHORITY to create the base of all URI's which apps will use to contact
16 | // the content provider.
17 | public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
18 |
19 | // Possible paths (appended to base content URI for possible URI's)
20 | // For instance, content://com.example.android.sunshine.app/weather/ is a valid path for
21 | // looking at weather data. content://com.example.android.sunshine.app/givemeroot/ will fail,
22 | // as the ContentProvider hasn't been given any information on what to do with "givemeroot".
23 | // At least, let's hope not. Don't be that dev, reader. Don't be that dev.
24 | public static final String PATH_ITEM = "item";
25 |
26 |
27 | /* Inner class that defines the table contents of the location table */
28 | public static final class ItemEntry implements BaseColumns {
29 |
30 | public static final Uri CONTENT_URI =
31 | BASE_CONTENT_URI.buildUpon().appendPath(PATH_ITEM).build();
32 |
33 | public static final String CONTENT_TYPE =
34 | "vnd.android.cursor.dir/" + CONTENT_AUTHORITY + "/" + PATH_ITEM;
35 | public static final String CONTENT_ITEM_TYPE =
36 | "vnd.android.cursor.item/" + CONTENT_AUTHORITY + "/" + PATH_ITEM;
37 |
38 | // Table name
39 | public static final String TABLE_NAME = "item";
40 |
41 | public static final String COLUMN_TITLE = "title";
42 | public static final String COLUMN_DESCRIPTION = "description";
43 |
44 | public static Uri buildItemUri(long id) {
45 | return ContentUris.withAppendedId(CONTENT_URI, id);
46 | }
47 |
48 | public static Uri getItemsUri() {
49 | return CONTENT_URI;
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Abstraction issues
15 |
16 |
17 | Android Lint
18 |
19 |
20 | Code style issues
21 |
22 |
23 | Concurrency annotation issues
24 |
25 |
26 | Declaration redundancy
27 |
28 |
29 | Initialization issues
30 |
31 |
32 | Internationalization issues
33 |
34 |
35 | J2ME issues
36 |
37 |
38 | Language Injection
39 |
40 |
41 | Logging issues
42 |
43 |
44 | Naming conventions
45 |
46 |
47 | Pattern Validation
48 |
49 |
50 | Performance issues
51 |
52 |
53 | Portability issues
54 |
55 |
56 | Probable bugs
57 |
58 |
59 | Security issues
60 |
61 |
62 | Threading issues
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | Android API 16 Platform
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/adapters/ShoppingListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.adapters;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.TextView;
8 |
9 | import com.jonmal.shoppit.MainApplication;
10 | import com.jonmal.shoppit.R;
11 | import com.jonmal.shoppit.objects.ShoppingItem;
12 |
13 | import java.util.ArrayList;
14 |
15 | public class ShoppingListAdapter extends BaseAdapter {
16 |
17 | //==========================================================
18 | // Fields
19 | //==========================================================
20 |
21 | private ArrayList mShoppingItemsList;
22 |
23 | //==========================================================
24 | // Constructor
25 | //==========================================================
26 |
27 | public ShoppingListAdapter() {
28 |
29 | super();
30 |
31 | mShoppingItemsList = new ArrayList();
32 | }
33 |
34 | //==========================================================
35 | // BaseAdatper Implmentation
36 | //==========================================================
37 |
38 | @Override
39 | public int getCount() {
40 | return mShoppingItemsList.size();
41 | }
42 |
43 | @Override
44 | public ShoppingItem getItem(int position) {
45 | return mShoppingItemsList.get(position);
46 | }
47 |
48 | @Override
49 | public long getItemId(int position) {
50 | return 0;
51 | }
52 |
53 | @Override
54 | public View getView(int position, View convertView, ViewGroup parent) {
55 |
56 | LayoutInflater layoutInflater = LayoutInflater.from(MainApplication.getAppContext());
57 |
58 | View rootView = layoutInflater.inflate(R.layout.shopping_list_item, null);
59 |
60 | // ui references
61 | TextView title = (TextView) rootView.findViewById(R.id.shoppingListItem_title);
62 | TextView description = (TextView) rootView.findViewById(R.id.shoppingListItem_description);
63 |
64 | ShoppingItem shoppingItem = mShoppingItemsList.get(position);
65 |
66 | title.setText(shoppingItem.getTitle());
67 | description.setText(shoppingItem.getDescritption());
68 |
69 | return rootView;
70 | }
71 |
72 | //==========================================================
73 | // Public Methods
74 | //==========================================================
75 |
76 | public void addItem(ShoppingItem shoppingItem) {
77 |
78 | mShoppingItemsList.add(shoppingItem);
79 | }
80 |
81 | public void clearItemList() {
82 |
83 | mShoppingItemsList.clear();
84 | notifyDataSetChanged();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/res/layout-sw600dp/fragment_add_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
17 |
18 |
23 |
24 |
28 |
29 |
34 |
35 |
44 |
45 |
46 |
52 |
53 |
59 |
65 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/views/AddItemFragment.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.views;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.EditText;
11 |
12 | import com.jonmal.shoppit.R;
13 | import com.jonmal.shoppit.activities.AddItemActivity;
14 |
15 | public class AddItemFragment extends Fragment {
16 |
17 | //==========================================================
18 | // Constants
19 | //==========================================================
20 |
21 | public static final String SHOPPING_ITEM_DESCRIPTION = "com.jonmal.shopit.SHOPPING_ITEM_DESCRIPTION";
22 | public static final String SHOPPING_ITEM_TITLE = "com.jonmal.shopit.SHOPPING_ITEM_TITLE";
23 |
24 | //==========================================================
25 | // Fields
26 | //==========================================================
27 |
28 | //ui references
29 | private EditText mTitleET;
30 | private EditText mDescriptionET;
31 | private View mSubmitButton;
32 |
33 | private AddItemActivity mActivity;
34 |
35 | //==========================================================
36 | // Constructor + Factory
37 | //==========================================================
38 |
39 | public AddItemFragment() {
40 | }
41 |
42 | public static AddItemFragment newInstance() {
43 |
44 | AddItemFragment fragment = new AddItemFragment();
45 |
46 | Bundle args = new Bundle();
47 |
48 | fragment.setArguments(args);
49 |
50 | return fragment;
51 | }
52 |
53 | @Override
54 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55 |
56 | View rootView = inflater.inflate(R.layout.fragment_add_item, null);
57 |
58 | mTitleET = (EditText) rootView.findViewById(R.id.addItemFragment_titleET);
59 |
60 | mDescriptionET = (EditText) rootView.findViewById(R.id.addItemFragment_decriptionET);
61 |
62 | mSubmitButton = rootView.findViewById(R.id.addItemFragment_submitButton);
63 |
64 | mSubmitButton.setOnClickListener(new View.OnClickListener() {
65 |
66 | @Override
67 | public void onClick(View v) {
68 |
69 | String title = mTitleET.getEditableText().toString();
70 | String description = mDescriptionET.getEditableText().toString();
71 |
72 | if(title.isEmpty()){
73 |
74 | mTitleET.setError(getResources().getString(R.string.addItemFragment_titleMissing));
75 |
76 | } else if (description.isEmpty()) {
77 |
78 | mDescriptionET.setError(getResources().getString(R.string.addItemFragment_descriptionMissing));
79 |
80 | } else {
81 | // both editTexts have been filled properly
82 |
83 | Intent data = new Intent();
84 | data.putExtra(SHOPPING_ITEM_TITLE, title);
85 | data.putExtra(SHOPPING_ITEM_DESCRIPTION, description);
86 |
87 | mActivity.onItemSubmitted(data);
88 |
89 | }
90 |
91 | }
92 | });
93 |
94 | return rootView;
95 | }
96 |
97 | @Override
98 | public void onAttach(Activity activity) {
99 | super.onAttach(activity);
100 |
101 | // This makes sure that the container activity has implemented
102 | // the callback interface. If not, it throws an exception
103 | try {
104 | mActivity = (AddItemActivity) activity;
105 | } catch (ClassCastException e) {
106 | throw new ClassCastException(activity.toString()
107 | + " must implement OnHeadlineSelectedListener");
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.activities;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.ActionBarActivity;
7 | import android.view.Menu;
8 | import android.view.MenuItem;
9 |
10 | import com.jonmal.shoppit.Interfaces.FragmentCommunication;
11 | import com.jonmal.shoppit.R;
12 | import com.jonmal.shoppit.objects.ShoppingItem;
13 | import com.jonmal.shoppit.views.AddItemFragment;
14 | import com.jonmal.shoppit.views.ShoppingListFragment;
15 |
16 |
17 | public class MainActivity extends ActionBarActivity implements FragmentCommunication{
18 |
19 |
20 | //==========================================================
21 | // Activity Lifecycle
22 | //==========================================================
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 | if (savedInstanceState == null) {
30 | getFragmentManager().beginTransaction()
31 | .add(R.id.container, ShoppingListFragment.newInstance(), ShoppingListFragment.FRAGMENT_TAG)
32 | .commit();
33 | }
34 |
35 | }
36 |
37 | @Override
38 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
39 |
40 | switch (requestCode) {
41 |
42 | case AddItemActivity.ACTIVITY_ADD_ITEM:
43 |
44 | if (resultCode == Activity.RESULT_OK && data != null) {
45 |
46 | String shoppingItemTitle = data.getStringExtra(AddItemFragment.SHOPPING_ITEM_TITLE);
47 | String shoppingItemDescription = data.getStringExtra(AddItemFragment.SHOPPING_ITEM_DESCRIPTION);
48 |
49 | ShoppingItem shoppingItem = new ShoppingItem(shoppingItemTitle, shoppingItemDescription);
50 |
51 | addShoppingItem(shoppingItem);
52 |
53 | }
54 |
55 | break;
56 | }
57 | }
58 |
59 | //==========================================================
60 | // FragmentCommunication Implementation
61 | //==========================================================
62 |
63 | @Override
64 | public void addShoppingItem(ShoppingItem shoppingItem) {
65 |
66 | ShoppingListFragment shoppingListFragment = (ShoppingListFragment) getFragmentManager().findFragmentByTag(ShoppingListFragment.FRAGMENT_TAG);
67 | shoppingListFragment.addItem(shoppingItem);
68 | }
69 |
70 | @Override
71 | public void startAddItemActivity() {
72 |
73 | //launch second activity
74 | Intent intent = new Intent(this, AddItemActivity.class);
75 | startActivityForResult(intent, AddItemActivity.ACTIVITY_ADD_ITEM);
76 | }
77 |
78 | //==========================================================
79 | // Menu implementation
80 | //==========================================================
81 |
82 | @Override
83 | public boolean onCreateOptionsMenu(Menu menu) {
84 | // Inflate the menu; this adds items to the action bar if it is present.
85 | getMenuInflater().inflate(R.menu.menu_main, menu);
86 | return true;
87 | }
88 |
89 | @Override
90 | public boolean onOptionsItemSelected(MenuItem item) {
91 | // Handle action bar item clicks here. The action bar will
92 | // automatically handle clicks on the Home/Up button, so long
93 | // as you specify a parent activity in AndroidManifest.xml.
94 | int id = item.getItemId();
95 |
96 | switch (id) {
97 | case R.id.action_settings:
98 |
99 | Intent launchSettingsActivity = new Intent(this, SettingsActivity.class);
100 | startActivity(launchSettingsActivity);
101 |
102 | break;
103 | case R.id.action_share:
104 |
105 | Intent shareIntent = new Intent(Intent.ACTION_SEND);
106 | shareIntent.setType("text/plain");
107 | shareIntent.putExtra(Intent.EXTRA_TEXT, "Try this awesome app!");
108 | startActivity(Intent.createChooser(shareIntent, "Share the love"));
109 |
110 | break;
111 | }
112 |
113 | return super.onOptionsItemSelected(item);
114 | }
115 |
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/views/ShoppingListFragment.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.views;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.app.LoaderManager;
6 | import android.content.ContentValues;
7 | import android.content.CursorLoader;
8 | import android.content.Loader;
9 | import android.database.Cursor;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ListView;
16 | import android.widget.Toast;
17 |
18 | import com.jonmal.shoppit.Interfaces.FragmentCommunication;
19 | import com.jonmal.shoppit.MainApplication;
20 | import com.jonmal.shoppit.R;
21 | import com.jonmal.shoppit.activities.SettingsActivity;
22 | import com.jonmal.shoppit.adapters.ShoppingListAdapter;
23 | import com.jonmal.shoppit.data.ShopContract;
24 | import com.jonmal.shoppit.objects.ShoppingItem;
25 |
26 | public class ShoppingListFragment extends Fragment implements LoaderManager.LoaderCallbacks {
27 |
28 |
29 | //==========================================================
30 | // Constants
31 | //==========================================================
32 |
33 | public static final String FRAGMENT_TAG = "com.jonmal.shoppit.FRAGMENT_TAG";
34 |
35 | private static final int SHOPPING_LIST_LOADER = 0;
36 |
37 | private static final String[] ITEM_COLUMNS = {
38 | ShopContract.ItemEntry.TABLE_NAME + "." + ShopContract.ItemEntry._ID,
39 | ShopContract.ItemEntry.COLUMN_TITLE,
40 | ShopContract.ItemEntry.COLUMN_DESCRIPTION,
41 | };
42 | //==========================================================
43 | // Fields
44 | //==========================================================
45 |
46 | private FragmentCommunication mActivity;
47 |
48 | // ui references
49 | private ListView mListView;
50 | private View mAddButton;
51 | private ShoppingListAdapter mShoppingListAdapter;
52 |
53 |
54 | //==========================================================
55 | // Constructor + Factory
56 | //==========================================================
57 |
58 | public ShoppingListFragment() {
59 | }
60 |
61 | public static ShoppingListFragment newInstance() {
62 |
63 | ShoppingListFragment fragment = new ShoppingListFragment();
64 |
65 | Bundle args = new Bundle();
66 |
67 | fragment.setArguments(args);
68 |
69 | return fragment;
70 | }
71 |
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
74 |
75 | View rootView = inflater.inflate(R.layout.fragment_shopping_list, null);
76 |
77 | mListView = (ListView) rootView.findViewById(R.id.shoppingListFragment_listView);
78 |
79 | mShoppingListAdapter = new ShoppingListAdapter();
80 |
81 | mListView.setAdapter(mShoppingListAdapter);
82 |
83 | mAddButton = rootView.findViewById(R.id.shoppingListFragment_addButton);
84 |
85 | mAddButton.setOnClickListener(new View.OnClickListener() {
86 |
87 | @Override
88 | public void onClick(View v) {
89 |
90 | boolean isListLocked = MainApplication.getSharedPreferences().getBoolean(SettingsActivity.PREF_LOCK_SHOPPING_LIST, false);
91 |
92 | if (mActivity != null && !isListLocked) {
93 |
94 | mActivity.startAddItemActivity();
95 | } else {
96 |
97 | Toast.makeText(MainApplication.getAppContext(), getResources().getString(R.string.activitySettings_lockListToastMessage), Toast.LENGTH_SHORT).show();
98 | }
99 | }
100 | });
101 |
102 | getLoaderManager().initLoader(SHOPPING_LIST_LOADER, null, this);
103 |
104 | return rootView;
105 | }
106 |
107 | @Override
108 | public void onResume() {
109 | super.onResume();
110 | getLoaderManager().restartLoader(SHOPPING_LIST_LOADER, null, this);
111 | }
112 |
113 |
114 |
115 | @Override
116 | public void onAttach(Activity activity) {
117 | super.onAttach(activity);
118 |
119 | // This makes sure that the container activity has implemented
120 | // the callback interface. If not, it throws an exception
121 | try {
122 | mActivity = (FragmentCommunication) activity;
123 | } catch (ClassCastException e) {
124 | throw new ClassCastException(activity.toString()
125 | + " must implement FragmentCommunication");
126 | }
127 |
128 |
129 | }
130 |
131 |
132 | public void addItem(ShoppingItem shoppingItem) {
133 | //add item
134 |
135 | ContentValues values = new ContentValues();
136 | values.put(ShopContract.ItemEntry.COLUMN_TITLE, shoppingItem.getTitle());
137 | values.put(ShopContract.ItemEntry.COLUMN_DESCRIPTION, shoppingItem.getDescritption());
138 |
139 | getActivity().getContentResolver().insert(ShopContract.ItemEntry.getItemsUri(), values);
140 |
141 | }
142 |
143 | //==========================================================
144 | // LoaderManager
145 | //==========================================================
146 |
147 |
148 | @Override
149 | public Loader onCreateLoader(int id, Bundle args) {
150 |
151 | Uri itemsURI = ShopContract.ItemEntry.getItemsUri();
152 |
153 | // Now create and return a CursorLoader that will take care of
154 | // creating a Cursor for the data being displayed.
155 | return new CursorLoader(
156 | getActivity(),
157 | itemsURI,
158 | ITEM_COLUMNS,
159 | null,
160 | null,
161 | null
162 | );
163 | }
164 |
165 | @Override
166 | public void onLoadFinished(Loader loader, Cursor data) {
167 |
168 | mShoppingListAdapter.clearItemList();
169 | if (data != null) {
170 |
171 | while (data.moveToNext()) {
172 |
173 | // Read description from cursor and update view
174 | String title = data.getString(data.getColumnIndex(ShopContract.ItemEntry.COLUMN_TITLE));
175 | String description = data.getString(data.getColumnIndex(ShopContract.ItemEntry.COLUMN_DESCRIPTION));
176 |
177 | ShoppingItem shoppingItem = new ShoppingItem(title, description);
178 |
179 | mShoppingListAdapter.addItem(shoppingItem);
180 | }
181 | }
182 | }
183 |
184 | @Override
185 | public void onLoaderReset(Loader loader) {
186 | }
187 | }
188 |
189 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jonmal/shoppit/data/ItemProvider.java:
--------------------------------------------------------------------------------
1 | package com.jonmal.shoppit.data;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentValues;
5 | import android.content.UriMatcher;
6 | import android.database.Cursor;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.net.Uri;
9 |
10 | public class ItemProvider extends ContentProvider {
11 |
12 | // The URI Matcher used by this content provider.
13 | private static final UriMatcher sUriMatcher = buildUriMatcher();
14 | private ShoppingListDbHelper mOpenHelper;
15 |
16 | private static final int ITEM = 300;
17 | private static final int ITEM_ID = 301;
18 |
19 |
20 | private static UriMatcher buildUriMatcher() {
21 | // I know what you're thinking. Why create a UriMatcher when you can use regular
22 | // expressions instead? Because you're not crazy, that's why.
23 |
24 | // All paths added to the UriMatcher have a corresponding code to return when a match is
25 | // found. The code passed into the constructor represents the code to return for the root
26 | // URI. It's common to use NO_MATCH as the code for this case.
27 | final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
28 | final String authority = ShopContract.CONTENT_AUTHORITY;
29 |
30 | // For each type of URI you want to add, create a corresponding code.
31 |
32 | matcher.addURI(authority, ShopContract.PATH_ITEM, ITEM);
33 | matcher.addURI(authority, ShopContract.PATH_ITEM + "/#", ITEM_ID);
34 |
35 | return matcher;
36 | }
37 |
38 | @Override
39 | public boolean onCreate() {
40 | mOpenHelper = new ShoppingListDbHelper(getContext());
41 | return true;
42 | }
43 |
44 | @Override
45 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
46 | String sortOrder) {
47 | // Here's the switch statement that, given a URI, will determine what kind of request it is,
48 | // and query the database accordingly.
49 | Cursor retCursor;
50 | switch (sUriMatcher.match(uri)) {
51 | // "item"
52 | case ITEM: {
53 | retCursor = mOpenHelper.getReadableDatabase().query(
54 | ShopContract.ItemEntry.TABLE_NAME,
55 | projection,
56 | selection,
57 | null,
58 | null,
59 | null,
60 | sortOrder
61 | );
62 | break;
63 | }
64 |
65 | default:
66 | throw new UnsupportedOperationException("Unknown uri: " + uri);
67 | }
68 | retCursor.setNotificationUri(getContext().getContentResolver(), uri);
69 | return retCursor;
70 | }
71 |
72 | @Override
73 | public String getType(Uri uri) {
74 |
75 | // Use the Uri Matcher to determine what kind of URI this is.
76 | final int match = sUriMatcher.match(uri);
77 |
78 | switch (match) {
79 | case ITEM:
80 | return ShopContract.ItemEntry.CONTENT_TYPE;
81 | case ITEM_ID:
82 | return ShopContract.ItemEntry.CONTENT_ITEM_TYPE;
83 | default:
84 | throw new UnsupportedOperationException("Unknown uri: " + uri);
85 | }
86 | }
87 |
88 | @Override
89 | public Uri insert(Uri uri, ContentValues values) {
90 | final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
91 | final int match = sUriMatcher.match(uri);
92 | Uri returnUri;
93 |
94 | switch (match) {
95 |
96 | case ITEM: {
97 | long _id = db.insert(ShopContract.ItemEntry.TABLE_NAME, null, values);
98 | if ( _id > 0 )
99 | returnUri = ShopContract.ItemEntry.buildItemUri(_id);
100 | else
101 | throw new android.database.SQLException("Failed to insert row into " + uri);
102 | break;
103 | }
104 | default:
105 | throw new UnsupportedOperationException("Unknown uri: " + uri);
106 | }
107 |
108 | getContext().getContentResolver().notifyChange(uri, null);
109 | return returnUri;
110 | }
111 |
112 | @Override
113 | public int delete(Uri uri, String selection, String[] selectionArgs) {
114 | final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
115 | final int match = sUriMatcher.match(uri);
116 | int rowsDeleted;
117 | switch (match) {
118 | case ITEM:
119 | rowsDeleted = db.delete(
120 | ShopContract.ItemEntry.TABLE_NAME, selection, selectionArgs);
121 | break;
122 | default:
123 | throw new UnsupportedOperationException("Unknown uri: " + uri);
124 | }
125 | // Because a null deletes all rows
126 | if (selection == null || rowsDeleted != 0) {
127 | getContext().getContentResolver().notifyChange(uri, null);
128 | }
129 | return rowsDeleted;
130 | }
131 |
132 | @Override
133 | public int update(
134 | Uri uri, ContentValues values, String selection, String[] selectionArgs) {
135 | final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
136 | final int match = sUriMatcher.match(uri);
137 | int rowsUpdated;
138 |
139 | switch (match) {
140 | case ITEM:
141 | rowsUpdated = db.update(ShopContract.ItemEntry.TABLE_NAME, values, selection,
142 | selectionArgs);
143 | break;
144 | default:
145 | throw new UnsupportedOperationException("Unknown uri: " + uri);
146 | }
147 | if (rowsUpdated != 0) {
148 | getContext().getContentResolver().notifyChange(uri, null);
149 | }
150 | return rowsUpdated;
151 | }
152 |
153 | @Override
154 | public int bulkInsert(Uri uri, ContentValues[] values) {
155 | final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
156 | final int match = sUriMatcher.match(uri);
157 | switch (match) {
158 | // case WEATHER:
159 | // db.beginTransaction();
160 | // int returnCount = 0;
161 | // try {
162 | // for (ContentValues value : values) {
163 | // long _id = db.insert(WeatherContract.WeatherEntry.TABLE_NAME, null, value);
164 | // if (_id != -1) {
165 | // returnCount++;
166 | // }
167 | // }
168 | // db.setTransactionSuccessful();
169 | // } finally {
170 | // db.endTransaction();
171 | // }
172 | // getContext().getContentResolver().notifyChange(uri, null);
173 | // return returnCount;
174 | default:
175 | return super.bulkInsert(uri, values);
176 | }
177 | }
178 | }
--------------------------------------------------------------------------------