mirror of
https://github.com/hmalik144/Udacity_Project_10---Inventory_App.git
synced 2025-12-10 03:05:30 +00:00
Initial commit
This commit is contained in:
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/workspace.xml
|
||||
/.idea/libraries
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
22
.idea/compiler.xml
generated
Normal file
22
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
3
.idea/copyright/profiles_settings.xml
generated
Normal file
3
.idea/copyright/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
18
.idea/gradle.xml
generated
Normal file
18
.idea/gradle.xml
generated
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
46
.idea/misc.xml
generated
Normal file
46
.idea/misc.xml
generated
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
||||
9
.idea/modules.xml
generated
Normal file
9
.idea/modules.xml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Inventoryapp.iml" filepath="$PROJECT_DIR$/Inventoryapp.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
12
.idea/runConfigurations.xml
generated
Normal file
12
.idea/runConfigurations.xml
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
30
app/build.gradle
Normal file
30
app/build.gradle
Normal file
@@ -0,0 +1,30 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
defaultConfig {
|
||||
applicationId "com.example.h_mal.inventoryapp"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
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.3.0'
|
||||
compile 'com.android.support:design:25.3.0'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
17
app/proguard-rules.pro
vendored
Normal file
17
app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in C:\Users\h_mal\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.example.h_mal.inventoryapp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumentation test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.example.h_mal.inventoryapp", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
38
app/src/main/AndroidManifest.xml
Normal file
38
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.h_mal.inventoryapp">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".AddProduct"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name=".data.ProductProvider"
|
||||
android:authorities="com.example.h_mal.inventoryapp"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
380
app/src/main/java/com/example/h_mal/inventoryapp/AddProduct.java
Normal file
380
app/src/main/java/com/example/h_mal/inventoryapp/AddProduct.java
Normal file
@@ -0,0 +1,380 @@
|
||||
package com.example.h_mal.inventoryapp;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.LoaderManager;
|
||||
import android.content.ContentValues;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.h_mal.inventoryapp.data.ProductContract.ProductEntry;
|
||||
|
||||
public class AddProduct extends AppCompatActivity implements
|
||||
LoaderManager.LoaderCallbacks<Cursor>{
|
||||
|
||||
private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1;
|
||||
|
||||
private static final int EXISTING_PRODUCT_LOADER = 0;
|
||||
|
||||
private Uri mCurrentProductUri;
|
||||
|
||||
private EditText mNameEditText;
|
||||
|
||||
private EditText mQuantityEditText;
|
||||
|
||||
private EditText mPriceEditText;
|
||||
|
||||
private ImageView mImageView;
|
||||
|
||||
private Uri mImageURI;
|
||||
|
||||
private static final int RESULT_LOAD_IMAGE = 1;
|
||||
|
||||
private boolean mProductHasChanged = false;
|
||||
|
||||
private static final int PICK_IMAGE_REQUEST = 0;
|
||||
|
||||
private View.OnTouchListener mTouchListener = new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
mProductHasChanged = true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_add_product);
|
||||
|
||||
mNameEditText = (EditText) findViewById(R.id.productName);
|
||||
mQuantityEditText = (EditText) findViewById(R.id.productQuantity);
|
||||
mPriceEditText = (EditText) findViewById(R.id.productPrice);
|
||||
mImageView = (ImageView) findViewById(R.id.imageView2);
|
||||
|
||||
Intent intent = getIntent();
|
||||
mCurrentProductUri = intent.getData();
|
||||
|
||||
if (mCurrentProductUri == null) {
|
||||
setTitle(getString(R.string.add_product_title));
|
||||
|
||||
invalidateOptionsMenu();
|
||||
} else {
|
||||
|
||||
setTitle(getString(R.string.edit_product_title));
|
||||
|
||||
|
||||
getLoaderManager().initLoader(EXISTING_PRODUCT_LOADER, null, this);
|
||||
}
|
||||
|
||||
Button Browse = (Button) findViewById(R.id.BrowseImage);
|
||||
Browse.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
tryToOpenImageSelector();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Button SubmitProduct = (Button) findViewById(R.id.submit);
|
||||
SubmitProduct.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
saveProduct();
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton ContactSupplier = (ImageButton) findViewById(R.id.ContactSupplier);
|
||||
ContactSupplier.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_SENDTO);
|
||||
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, "Order Stock " + mNameEditText.getText().toString().trim());
|
||||
intent.putExtra(Intent.EXTRA_TEXT, "I would like to order more " + mNameEditText.getText().toString().trim());
|
||||
if (intent.resolveActivity(getPackageManager()) != null) {
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button Incrament = (Button) findViewById(R.id.buttonAdd);
|
||||
Incrament.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
IncramentQuantity();
|
||||
}
|
||||
});
|
||||
|
||||
Button decrament = (Button) findViewById(R.id.buttonMinus);
|
||||
decrament.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
DecramentQuantity();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
mNameEditText.setOnTouchListener(mTouchListener);
|
||||
mQuantityEditText.setOnTouchListener(mTouchListener);
|
||||
mPriceEditText.setOnTouchListener(mTouchListener);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle("Discard changes?")
|
||||
.setMessage("Are you sure you want to discard changes?")
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
AddProduct.super.onBackPressed();
|
||||
}
|
||||
}).create().show();
|
||||
}
|
||||
|
||||
private void saveProduct() {
|
||||
|
||||
String nameString = mNameEditText.getText().toString().trim();
|
||||
String quantityString = mQuantityEditText.getText().toString().trim();
|
||||
String priceString = mPriceEditText.getText().toString().trim();
|
||||
|
||||
if (
|
||||
TextUtils.isEmpty(nameString) || TextUtils.isEmpty(quantityString) ||
|
||||
TextUtils.isEmpty(priceString) || mImageURI == null) {
|
||||
Toast.makeText(AddProduct.this, "please insert all product data", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
int quantity = Integer.parseInt(quantityString);
|
||||
int price = Integer.parseInt(priceString);
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_NAME, nameString);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_PRICE, price);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_QUANTITY, quantity);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_IMAGE, String.valueOf(mImageURI));
|
||||
|
||||
if (mCurrentProductUri == null) {
|
||||
|
||||
Uri newUri = getContentResolver().insert(ProductEntry.CONTENT_URI, values);
|
||||
|
||||
if (newUri == null) {
|
||||
Toast.makeText(this, getString(R.string.insert_product_failed),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
|
||||
Toast.makeText(this, getString(R.string.insert_product_successful),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
int rowsAffected = getContentResolver().update(mCurrentProductUri, values, null, null);
|
||||
|
||||
if (rowsAffected == 0) {
|
||||
Toast.makeText(this, getString(R.string.update_product_failed),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, getString(R.string.update_product_successful),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
NavUtils.navigateUpFromSameTask(AddProduct.this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_editor, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void tryToOpenImageSelector() {
|
||||
if (ContextCompat.checkSelfPermission(this,
|
||||
Manifest.permission.READ_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this,
|
||||
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
||||
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
|
||||
return;
|
||||
}
|
||||
openImageSelector();
|
||||
}
|
||||
|
||||
private void openImageSelector() {
|
||||
|
||||
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
openImageSelector();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case R.id.action_delete:
|
||||
DeleteDialog();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void DeleteDialog() {
|
||||
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this);
|
||||
builder.setMessage("Are you sure you want to delete");
|
||||
builder.setPositiveButton("delete", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
deleteProduct();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
android.app.AlertDialog alertDialog = builder.create();
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void deleteProduct() {
|
||||
|
||||
if (mCurrentProductUri != null) {
|
||||
|
||||
int rowsDeleted = getContentResolver().delete(mCurrentProductUri, null, null);
|
||||
|
||||
if (rowsDeleted == 0) {
|
||||
Toast.makeText(this, "error deleting product", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Product deleted", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
|
||||
Uri selectedImage = data.getData();
|
||||
mImageView.setImageURI(selectedImage);
|
||||
mImageURI = Uri.parse(selectedImage.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||
String[] projection = {
|
||||
ProductEntry._ID,
|
||||
ProductEntry.COLUMN_PRODUCT_IMAGE,
|
||||
ProductEntry.COLUMN_PRODUCT_NAME,
|
||||
ProductEntry.COLUMN_PRODUCT_QUANTITY,
|
||||
ProductEntry.COLUMN_PRODUCT_PRICE };
|
||||
|
||||
return new CursorLoader(this,
|
||||
mCurrentProductUri,
|
||||
projection,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
if (cursor == null || cursor.getCount() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursor.moveToFirst()) {
|
||||
int nameColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_PRODUCT_NAME);
|
||||
int quantityColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_PRODUCT_QUANTITY);
|
||||
int priceColumnIndex = cursor.getColumnIndex(ProductEntry.COLUMN_PRODUCT_PRICE);
|
||||
int selectedImage = cursor.getColumnIndex(ProductEntry.COLUMN_PRODUCT_IMAGE);
|
||||
|
||||
String name = cursor.getString(nameColumnIndex);
|
||||
int quantity = cursor.getInt(quantityColumnIndex);
|
||||
int price = cursor.getInt(priceColumnIndex);
|
||||
String image = cursor.getString(selectedImage);
|
||||
|
||||
mNameEditText.setText(name);
|
||||
mQuantityEditText.setText(Integer.toString(quantity));
|
||||
mPriceEditText.setText(Integer.toString(price));
|
||||
mImageView.setImageURI(Uri.parse(image));
|
||||
mImageURI = Uri.parse(image);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void IncramentQuantity() {
|
||||
String quantityString = mQuantityEditText.getText().toString();
|
||||
int initialQuantity;
|
||||
if (quantityString.isEmpty()) {
|
||||
initialQuantity = 0;
|
||||
} else {
|
||||
initialQuantity = Integer.parseInt(quantityString);
|
||||
}
|
||||
mQuantityEditText.setText(String.valueOf(initialQuantity + 1));
|
||||
}
|
||||
|
||||
private void DecramentQuantity() {
|
||||
String quantityString = mQuantityEditText.getText().toString();
|
||||
int initialQuantity;
|
||||
if (quantityString.isEmpty()) {
|
||||
return;
|
||||
} else if (quantityString.equals("0")) {
|
||||
return;
|
||||
} else {
|
||||
initialQuantity = Integer.parseInt(quantityString);
|
||||
mQuantityEditText.setText(String.valueOf(initialQuantity - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.example.h_mal.inventoryapp;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.example.h_mal.inventoryapp.data.ProductContract.ProductEntry;
|
||||
import com.example.h_mal.inventoryapp.data.ProductDbHelper;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements
|
||||
LoaderManager.LoaderCallbacks<Cursor>{
|
||||
|
||||
private static final int PRODUCT_LOADER = 0;
|
||||
|
||||
ProductCursorAdapter mCursorAdapter;
|
||||
ProductDbHelper productDbhelper;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(MainActivity.this, AddProduct.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
ListView productListView = (ListView) findViewById(R.id.list_item_view);
|
||||
|
||||
View emptyView = findViewById(R.id.empty_view);
|
||||
productListView.setEmptyView(emptyView);
|
||||
|
||||
mCursorAdapter = new ProductCursorAdapter(this, null);
|
||||
productListView.setAdapter(mCursorAdapter);
|
||||
|
||||
getLoaderManager().initLoader(PRODUCT_LOADER, null, this);
|
||||
|
||||
}
|
||||
|
||||
private void insertProduct() {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_NAME, "demoItem");
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_PRICE, 8);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_QUANTITY, 4);
|
||||
Uri SadImageuri = Uri.parse("android.resource://com.example.h_mal.inventoryapp/drawable/sad");
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_IMAGE, String.valueOf(SadImageuri));
|
||||
|
||||
Uri newUri = getContentResolver().insert(ProductEntry.CONTENT_URI, values);
|
||||
}
|
||||
|
||||
|
||||
private void deleteAllProducts() {
|
||||
int rowsDeleted = getContentResolver().delete(ProductEntry.CONTENT_URI, null, null);
|
||||
Log.v("MainActivity", rowsDeleted + " rows deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clickOnViewItem(long id) {
|
||||
Intent intent = new Intent(MainActivity.this, AddProduct.class);
|
||||
Uri currentProductUri = ContentUris.withAppendedId(ProductEntry.CONTENT_URI, id);
|
||||
intent.setData(currentProductUri);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
||||
case R.id.action_settings:
|
||||
deleteAllProducts();
|
||||
return true;
|
||||
|
||||
case R.id.insert_placeholder_data:
|
||||
insertProduct();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||
// Define a projection that specifies the columns from the table we care about.
|
||||
String[] projection = {
|
||||
ProductEntry._ID,
|
||||
ProductEntry.COLUMN_PRODUCT_IMAGE,
|
||||
ProductEntry.COLUMN_PRODUCT_NAME,
|
||||
ProductEntry.COLUMN_PRODUCT_QUANTITY,
|
||||
ProductEntry.COLUMN_PRODUCT_PRICE};
|
||||
|
||||
// This loader will execute the ContentProvider's query method on a background thread
|
||||
return new CursorLoader(this, // Parent activity context
|
||||
ProductEntry.CONTENT_URI, // Provider content URI to query
|
||||
projection, // Columns to include in the resulting Cursor
|
||||
null, // No selection clause
|
||||
null, // No selection arguments
|
||||
null); // Default sort order
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
|
||||
mCursorAdapter.swapCursor(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
mCursorAdapter.swapCursor(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.example.h_mal.inventoryapp;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.CursorAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.example.h_mal.inventoryapp.data.ProductContract.ProductEntry;
|
||||
|
||||
/**
|
||||
* Created by h_mal on 04/04/2017.
|
||||
*/
|
||||
|
||||
public class ProductCursorAdapter extends CursorAdapter {
|
||||
|
||||
private final MainActivity activity;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public ProductCursorAdapter(MainActivity context, Cursor c) {
|
||||
super(context, c, 0);
|
||||
this.activity = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
mContext = context;
|
||||
|
||||
ImageView picImageView = (ImageView) view.findViewById(R.id.imageView);
|
||||
TextView nameTextView = (TextView) view.findViewById(R.id.Product);
|
||||
TextView priceTextView = (TextView) view.findViewById(R.id.price);
|
||||
TextView quantityTextView = (TextView) view.findViewById(R.id.Qn);
|
||||
Button sellButton = (Button) view.findViewById(R.id.button);
|
||||
|
||||
final String nameColumnIndex = cursor.getString(cursor.getColumnIndexOrThrow(ProductEntry.COLUMN_PRODUCT_NAME));
|
||||
final Integer priceColumnIndex = cursor.getInt(cursor.getColumnIndexOrThrow(ProductEntry.COLUMN_PRODUCT_PRICE));
|
||||
final Integer quantityColumnIndex = cursor.getInt(cursor.getColumnIndexOrThrow(ProductEntry.COLUMN_PRODUCT_QUANTITY));
|
||||
final String imageColumnIndex = cursor.getString(cursor.getColumnIndexOrThrow(ProductEntry.COLUMN_PRODUCT_IMAGE));
|
||||
|
||||
nameTextView.setText(nameColumnIndex);
|
||||
priceTextView.setText(Integer.toString(priceColumnIndex));
|
||||
quantityTextView.setText(String.valueOf(quantityColumnIndex));
|
||||
|
||||
// picImageView.setImageURI(Uri.parse(cursor.getString(cursor.getColumnIndex(ProductEntry.COLUMN_PRODUCT_IMAGE))));
|
||||
|
||||
if (imageColumnIndex == null) {
|
||||
picImageView.setVisibility(View.GONE);
|
||||
}else {
|
||||
picImageView.setVisibility(View.VISIBLE);
|
||||
picImageView.setImageURI(Uri.parse(imageColumnIndex));
|
||||
}
|
||||
|
||||
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(ProductEntry._ID));
|
||||
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
activity.clickOnViewItem(id);
|
||||
}
|
||||
});
|
||||
|
||||
sellButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view != null) {
|
||||
Object obj = view.getTag();
|
||||
String st = obj.toString();
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_NAME, nameColumnIndex);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_IMAGE, imageColumnIndex);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_QUANTITY, quantityColumnIndex >= 1? quantityColumnIndex-1: 0);
|
||||
values.put(ProductEntry.COLUMN_PRODUCT_PRICE, priceColumnIndex);
|
||||
|
||||
Uri currentPetUri = ContentUris.withAppendedId(ProductEntry.CONTENT_URI, Integer.parseInt(st));
|
||||
|
||||
int rowsAffected = mContext.getContentResolver().update(currentPetUri, values, null, null);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
Object obj = cursor.getInt(cursor.getColumnIndex(ProductEntry._ID));
|
||||
sellButton.setTag(obj);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.example.h_mal.inventoryapp.data;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
/**
|
||||
* Created by h_mal on 04/04/2017.
|
||||
*/
|
||||
|
||||
public class ProductContract {
|
||||
|
||||
private ProductContract() {}
|
||||
|
||||
public static final String CONTENT_AUTHORITY = "com.example.h_mal.inventoryapp";
|
||||
|
||||
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
|
||||
|
||||
public static final String PATH_PRODUCTS = "products";
|
||||
|
||||
public static final class ProductEntry implements BaseColumns {
|
||||
|
||||
public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, PATH_PRODUCTS);
|
||||
|
||||
public static final String CONTENT_LIST_TYPE =
|
||||
ContentResolver.CURSOR_DIR_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_PRODUCTS;
|
||||
|
||||
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
ContentResolver.CURSOR_ITEM_BASE_TYPE + "/" + CONTENT_AUTHORITY + "/" + PATH_PRODUCTS;
|
||||
|
||||
|
||||
public final static String TABLE_NAME = "products";
|
||||
|
||||
public final static String _ID = BaseColumns._ID;
|
||||
|
||||
public final static String COLUMN_PRODUCT_IMAGE = "image";
|
||||
|
||||
public final static String COLUMN_PRODUCT_NAME ="name";
|
||||
|
||||
public final static String COLUMN_PRODUCT_QUANTITY = "quantity";
|
||||
|
||||
public final static String COLUMN_PRODUCT_PRICE = "price";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.example.h_mal.inventoryapp.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import com.example.h_mal.inventoryapp.data.ProductContract.ProductEntry;
|
||||
|
||||
/**
|
||||
* Created by h_mal on 04/04/2017.
|
||||
*/
|
||||
|
||||
public class ProductDbHelper extends SQLiteOpenHelper{
|
||||
|
||||
public static final String LOG_TAG = ProductDbHelper.class.getSimpleName();
|
||||
|
||||
private static final String DATABASE_NAME = "inventory.db";
|
||||
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
|
||||
public ProductDbHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
String SQL_CREATE_PRODUCTS_TABLE = "CREATE TABLE " + ProductEntry.TABLE_NAME + " ("
|
||||
+ ProductEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ ProductEntry.COLUMN_PRODUCT_IMAGE + " TEXT, "
|
||||
+ ProductEntry.COLUMN_PRODUCT_NAME + " TEXT NOT NULL, "
|
||||
+ ProductEntry.COLUMN_PRODUCT_QUANTITY + " INTEGER NOT NULL DEFAULT 0, "
|
||||
+ ProductEntry.COLUMN_PRODUCT_PRICE + " INTEGER NOT NULL DEFAULT 0)";
|
||||
|
||||
db.execSQL(SQL_CREATE_PRODUCTS_TABLE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
package com.example.h_mal.inventoryapp.data;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.example.h_mal.inventoryapp.data.ProductContract.ProductEntry;
|
||||
|
||||
public class ProductProvider extends ContentProvider {
|
||||
|
||||
|
||||
public static final String LOG_TAG = ProductProvider.class.getSimpleName();
|
||||
|
||||
private static final int PRODUCTS = 100;
|
||||
private static final int PRODUCT_ID = 101;
|
||||
|
||||
private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
|
||||
|
||||
static {
|
||||
|
||||
sUriMatcher.addURI(ProductContract.CONTENT_AUTHORITY, ProductContract.PATH_PRODUCTS, PRODUCTS);
|
||||
|
||||
sUriMatcher.addURI(ProductContract.CONTENT_AUTHORITY, ProductContract.PATH_PRODUCTS + "/#", PRODUCT_ID);
|
||||
}
|
||||
|
||||
ProductDbHelper mDbHelper;
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
mDbHelper = new ProductDbHelper(getContext());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
|
||||
SQLiteDatabase database = mDbHelper.getReadableDatabase();
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
int match = sUriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PRODUCTS:
|
||||
|
||||
cursor = database.query(ProductEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||
null, null, sortOrder);
|
||||
break;
|
||||
case PRODUCT_ID:
|
||||
|
||||
selection = ProductEntry._ID + "=?";
|
||||
selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) };
|
||||
cursor = database.query(ProductEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||
null, null, sortOrder);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Cannot query " + uri);
|
||||
}
|
||||
|
||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues contentValues) {
|
||||
final int match = sUriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PRODUCTS:
|
||||
return insertProduct(uri, contentValues);
|
||||
default:
|
||||
throw new IllegalArgumentException("Insertion is not supported for " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
private Uri insertProduct(Uri uri, ContentValues values) {
|
||||
|
||||
String name = values.getAsString(ProductEntry.COLUMN_PRODUCT_NAME);
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("name required");
|
||||
}
|
||||
|
||||
Integer quantity = values.getAsInteger(ProductEntry.COLUMN_PRODUCT_QUANTITY);
|
||||
if (quantity != null && quantity < 0) {
|
||||
throw new IllegalArgumentException("quantity required");
|
||||
}
|
||||
|
||||
|
||||
Integer price = values.getAsInteger(ProductEntry.COLUMN_PRODUCT_PRICE);
|
||||
if (price != null && price < 0) {
|
||||
throw new IllegalArgumentException("Price required");
|
||||
}
|
||||
|
||||
String image = values.getAsString(ProductEntry.COLUMN_PRODUCT_IMAGE);
|
||||
if (image == null) {
|
||||
throw new IllegalArgumentException("image required");
|
||||
}
|
||||
|
||||
SQLiteDatabase database = mDbHelper.getWritableDatabase();
|
||||
|
||||
long id = database.insert(ProductEntry.TABLE_NAME, null, values);
|
||||
if (id == -1) {
|
||||
Log.e(LOG_TAG, "row failed " + uri);
|
||||
return null;
|
||||
}
|
||||
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
|
||||
return ContentUris.withAppendedId(uri, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues contentValues, String selection,
|
||||
String[] selectionArgs) {
|
||||
final int match = sUriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PRODUCTS:
|
||||
return updateProduct(uri, contentValues, selection, selectionArgs);
|
||||
case PRODUCT_ID:
|
||||
|
||||
selection = ProductEntry._ID + "=?";
|
||||
selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) };
|
||||
return updateProduct(uri, contentValues, selection, selectionArgs);
|
||||
default:
|
||||
throw new IllegalArgumentException("Update is not supported for " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int updateProduct(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
|
||||
if (values.containsKey(ProductEntry.COLUMN_PRODUCT_NAME)) {
|
||||
String name = values.getAsString(ProductEntry.COLUMN_PRODUCT_NAME);
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("Name required");
|
||||
}
|
||||
}
|
||||
|
||||
if (values.containsKey(ProductEntry.COLUMN_PRODUCT_QUANTITY)) {
|
||||
Integer quantity = values.getAsInteger(ProductEntry.COLUMN_PRODUCT_QUANTITY);
|
||||
if (quantity != null && quantity < 0) {
|
||||
throw new IllegalArgumentException("quantity required");
|
||||
}
|
||||
}
|
||||
|
||||
if (values.containsKey(ProductEntry.COLUMN_PRODUCT_PRICE)) {
|
||||
Integer price = values.getAsInteger(ProductEntry.COLUMN_PRODUCT_PRICE);
|
||||
if (price != null && price < 0) {
|
||||
throw new IllegalArgumentException("Price required");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (values.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SQLiteDatabase database = mDbHelper.getWritableDatabase();
|
||||
int rowsUpdated = database.update(ProductEntry.TABLE_NAME, values, selection, selectionArgs);
|
||||
if (rowsUpdated != 0) {
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
}
|
||||
|
||||
return rowsUpdated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
SQLiteDatabase database = mDbHelper.getWritableDatabase();
|
||||
|
||||
int rowsDeleted;
|
||||
|
||||
final int match = sUriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PRODUCTS:
|
||||
rowsDeleted = database.delete(ProductEntry.TABLE_NAME, selection, selectionArgs);
|
||||
break;
|
||||
case PRODUCT_ID:
|
||||
selection = ProductEntry._ID + "=?";
|
||||
selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) };
|
||||
rowsDeleted = database.delete(ProductEntry.TABLE_NAME, selection, selectionArgs);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Deletion is not supported for " + uri);
|
||||
}
|
||||
|
||||
if (rowsDeleted != 0) {
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
}
|
||||
|
||||
return rowsDeleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
final int match = sUriMatcher.match(uri);
|
||||
switch (match) {
|
||||
case PRODUCTS:
|
||||
return ProductEntry.CONTENT_LIST_TYPE;
|
||||
case PRODUCT_ID:
|
||||
return ProductEntry.CONTENT_ITEM_TYPE;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown URI " + uri + " with match " + match);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
BIN
app/src/main/res/drawable/sad.jpg
Normal file
BIN
app/src/main/res/drawable/sad.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
168
app/src/main/res/layout/activity_add_product.xml
Normal file
168
app/src/main/res/layout/activity_add_product.xml
Normal file
@@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/activity_add_product"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context="com.example.h_mal.inventoryapp.AddProduct"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="center"
|
||||
app:srcCompat="@mipmap/ic_launcher" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:text="Image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat" />
|
||||
|
||||
<Button
|
||||
android:text="Browse"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/BrowseImage"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:text="Name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPersonName"
|
||||
android:hint="Product name"
|
||||
android:ems="10"
|
||||
android:id="@+id/productName"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="quantity"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonMinus"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="-" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/productQuantity"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="4"
|
||||
android:ems="10"
|
||||
android:hint="Quantity"
|
||||
android:inputType="number" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonAdd"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="+" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/activity_horizontal_margin">
|
||||
|
||||
<TextView
|
||||
android:text="Price"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat" />
|
||||
|
||||
<TextView
|
||||
android:text="£"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/textView8"
|
||||
android:layout_weight="1"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:hint="Price"
|
||||
android:ems="10"
|
||||
android:layout_weight="4"
|
||||
android:id="@+id/productPrice" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageButton
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email"
|
||||
android:id="@+id/ContactSupplier"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:text="submit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/submit"
|
||||
android:layout_weight="2" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
53
app/src/main/res/layout/activity_main.xml
Normal file
53
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list_item_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</ListView>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/empty_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_title_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:fontFamily="sans-serif-medium"
|
||||
android:paddingTop="16dp"
|
||||
android:text="Inventory list empty"
|
||||
android:textAppearance="?android:textAppearanceMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/empty_subtitle_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/empty_title_text"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:fontFamily="sans-serif"
|
||||
android:paddingTop="8dp"
|
||||
android:text="add products to begin"
|
||||
android:textAppearance="?android:textAppearanceSmall"
|
||||
android:textColor="#A2AAB0"/>
|
||||
</RelativeLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:src="@android:drawable/ic_menu_add" />
|
||||
|
||||
</RelativeLayout>
|
||||
99
app/src/main/res/layout/list_item.xml
Normal file
99
app/src/main/res/layout/list_item.xml
Normal file
@@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="112sp"
|
||||
android:padding="@dimen/activity_horizontal_margin">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:scaleType="fitCenter"
|
||||
app:srcCompat="@mipmap/ic_launcher"
|
||||
android:id="@+id/imageView" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Product"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:text="Product Name" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Price: £ " />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="00.00" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:text="Sell" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Quantity: " />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Qn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Qn" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
23
app/src/main/res/menu/menu_editor.xml
Normal file
23
app/src/main/res/menu/menu_editor.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2016 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- Options menu for the EditorActivity -->
|
||||
<menu 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"
|
||||
tools:context=".EditorActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:title="@string/delete_item"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
15
app/src/main/res/menu/menu_main.xml
Normal file
15
app/src/main/res/menu/menu_main.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<menu 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"
|
||||
tools:context="com.example.h_mal.inventoryapp.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="delete all data"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/insert_placeholder_data"
|
||||
android:orderInCategory="100"
|
||||
android:title="insert test data"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
9
app/src/main/res/values-v21/styles.xml
Normal file
9
app/src/main/res/values-v21/styles.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
</resources>
|
||||
6
app/src/main/res/values-w820dp/dimens.xml
Normal file
6
app/src/main/res/values-w820dp/dimens.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
||||
6
app/src/main/res/values/colors.xml
Normal file
6
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#3F51B5</color>
|
||||
<color name="colorPrimaryDark">#303F9F</color>
|
||||
<color name="colorAccent">#FF4081</color>
|
||||
</resources>
|
||||
6
app/src/main/res/values/dimens.xml
Normal file
6
app/src/main/res/values/dimens.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
</resources>
|
||||
12
app/src/main/res/values/strings.xml
Normal file
12
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<resources>
|
||||
<string name="app_name">Inventory app</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="add_product_title">Add Product</string>
|
||||
<string name="edit_product_title">Edit product</string>
|
||||
<string name="insert_product_failed">Inserting product failed</string>
|
||||
<string name="insert_product_successful">Product added</string>
|
||||
<string name="update_product_failed">Product update failed</string>
|
||||
<string name="update_product_successful">Product updated successful</string>
|
||||
<string name="save_item">Save product</string>
|
||||
<string name="delete_item">Delete product</string>
|
||||
</resources>
|
||||
20
app/src/main/res/values/styles.xml
Normal file
20
app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<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>
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.h_mal.inventoryapp;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||
23
build.gradle
Normal file
23
build.gradle
Normal file
@@ -0,0 +1,23 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
17
gradle.properties
Normal file
17
gradle.properties
Normal file
@@ -0,0 +1,17 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#Fri Apr 07 21:02:58 BST 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||
160
gradlew
vendored
Normal file
160
gradlew
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
90
gradlew.bat
vendored
Normal file
90
gradlew.bat
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@@ -0,0 +1 @@
|
||||
include ':app'
|
||||
Reference in New Issue
Block a user