diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..28c10bd --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "com.example.chishingwan.myapplication" + minSdkVersion 19 + 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.1' + compile 'com.android.support:recyclerview-v7:25.3.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..5d95558 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\SDKfiles/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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/example/chishingwan/myapplication/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/chishingwan/myapplication/ExampleInstrumentedTest.java new file mode 100644 index 0000000..8aa82af --- /dev/null +++ b/app/src/androidTest/java/com/example/chishingwan/myapplication/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.chishingwan.myapplication; + +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 Testing documentation + */ +@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.chishingwan.myapplication", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..eb9236a --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/chishingwan/myapplication/FirstFragment.java b/app/src/main/java/com/example/chishingwan/myapplication/FirstFragment.java new file mode 100644 index 0000000..3faf8e9 --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/FirstFragment.java @@ -0,0 +1,45 @@ +package com.example.chishingwan.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +/** + * Created by Chi Shing Wan on 5/13/2017. + */ + +public class FirstFragment extends Fragment { + + Button btLogin; + EditText etName; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_first, container, false); + bindViews(view); + return view; + } + + private void bindViews(View view) { + btLogin = (Button) view.findViewById(R.id.bt_login); + btLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getContext(), WelcomeActivity.class); + String name = etName.getText().toString(); + intent.putExtra("Name", name); + startActivity(intent); + } + }); + + etName = (EditText) view.findViewById(R.id.et_name); + } +} diff --git a/app/src/main/java/com/example/chishingwan/myapplication/MainActivity.java b/app/src/main/java/com/example/chishingwan/myapplication/MainActivity.java new file mode 100644 index 0000000..99dc202 --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/MainActivity.java @@ -0,0 +1,57 @@ +package com.example.chishingwan.myapplication; + +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.FrameLayout; + +public class MainActivity extends AppCompatActivity { + + Button btLogin; + Button btRegister; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + loadViews(); + loadFragment(); + } + + private void loadViews() { + btLogin = (Button) findViewById(R.id.bt_login); + btRegister = (Button) findViewById(R.id.bt_register); + btLogin.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadFragment(); + } + }); + btRegister.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + loadRegister(); + } + }); + } + + private void loadFragment() { + FirstFragment firstFragment = new FirstFragment(); + + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction transaction = fm.beginTransaction(); + transaction.replace(R.id.container, firstFragment); + transaction.commit(); + } + + private void loadRegister() { + SecondFragment secondFragment = new SecondFragment(); + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction transaction = fm.beginTransaction(); + transaction.replace(R.id.container, secondFragment); + transaction.commit(); + } +} diff --git a/app/src/main/java/com/example/chishingwan/myapplication/SecondFragment.java b/app/src/main/java/com/example/chishingwan/myapplication/SecondFragment.java new file mode 100644 index 0000000..4de5b04 --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/SecondFragment.java @@ -0,0 +1,22 @@ +package com.example.chishingwan.myapplication; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * Created by Chi Shing Wan on 5/13/2017. + */ + +public class SecondFragment extends Fragment { + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_second, container, false); + //TODO: Proceed to WelcomeActivity upon registering. Display + return view; + } +} diff --git a/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListAdapter.java b/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListAdapter.java new file mode 100644 index 0000000..c154ea1 --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListAdapter.java @@ -0,0 +1,74 @@ +package com.example.chishingwan.myapplication; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.ArrayList; + +/** + * Created by Chi Shing Wan on 5/13/2017. + */ + +public class ShoppingListAdapter extends RecyclerView.Adapter { + + ArrayList list; + + public ShoppingListAdapter() { + list = new ArrayList<>(); + populateList(); + } + + private void populateList() { + ShoppingListItem item1 = new ShoppingListItem(); + item1.setName("Raisins"); + item1.setQty(1); + item1.setPrice(45.00); + list.add(item1); + + ShoppingListItem item2 = new ShoppingListItem(); + item2.setName("Flour"); + item2.setQty(2); + item2.setPrice(37.00); + list.add(item2); + + ShoppingListItem item3 = new ShoppingListItem(); + item3.setName("The Elder Scrolls V Skyrim"); + item3.setQty(1); + item3.setPrice(999.00); + list.add(item3); + } + + @Override + public ShoppingListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_shopping, parent, false); + return new ShoppingListViewHolder(view); + } + + @Override + public void onBindViewHolder(ShoppingListViewHolder holder, int position) { + holder.itemName.setText(list.get(position).getName()); + holder.itemPrice.setText("Php " + list.get(position).getPrice()); + holder.itemQty.setText("" + list.get(position).getQty()); + } + + @Override + public int getItemCount() { + return list.size(); + } + + protected class ShoppingListViewHolder extends RecyclerView.ViewHolder { + TextView itemName; + TextView itemQty; + TextView itemPrice; + public ShoppingListViewHolder(View itemView) { + super(itemView); + itemName = (TextView) itemView.findViewById(R.id.item_name); + itemQty = (TextView) itemView.findViewById(R.id.item_qty); + itemPrice = (TextView) itemView.findViewById(R.id.item_price); + } + } + +} diff --git a/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListItem.java b/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListItem.java new file mode 100644 index 0000000..3a8fe7d --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/ShoppingListItem.java @@ -0,0 +1,34 @@ +package com.example.chishingwan.myapplication; + +/** + * Created by Chi Shing Wan on 5/13/2017. + */ +public class ShoppingListItem { + private String name; + private double price; + private int qty; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public int getQty() { + return qty; + } + + public void setQty(int qty) { + this.qty = qty; + } +} diff --git a/app/src/main/java/com/example/chishingwan/myapplication/WelcomeActivity.java b/app/src/main/java/com/example/chishingwan/myapplication/WelcomeActivity.java new file mode 100644 index 0000000..8cfbc7a --- /dev/null +++ b/app/src/main/java/com/example/chishingwan/myapplication/WelcomeActivity.java @@ -0,0 +1,52 @@ +package com.example.chishingwan.myapplication; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; + +/** + * Created by Chi Shing Wan on 5/13/2017. + */ + +public class WelcomeActivity extends AppCompatActivity { + + RecyclerView rvShoppingList; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_welcome); +// getSupportActionBar().setDisplayHomeAsUpEnabled(true); + henlo(); + bindViews(); + } + + private void bindViews() { + rvShoppingList = (RecyclerView) findViewById(R.id.rv_shoppinglist); + rvShoppingList.setLayoutManager(new LinearLayoutManager(this)); + rvShoppingList.setAdapter(new ShoppingListAdapter()); + } + + private void henlo() { + Intent intent = getIntent(); + String name = intent.getStringExtra("Name"); + getSupportActionBar().setTitle("Hello " + name); + } + +/* @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + } + return super.onOptionsItemSelected(item); + }*/ + +/* @Override + public void onBackPressed() { + super.onBackPressed(); + }*/ +} diff --git a/app/src/main/res/drawable/user_pic.png b/app/src/main/res/drawable/user_pic.png new file mode 100644 index 0000000..75ac2b5 Binary files /dev/null and b/app/src/main/res/drawable/user_pic.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..f869c56 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + + +