Skip to content

Commit

Permalink
android codecamp workshop initial commit:
Browse files Browse the repository at this point in the history
  • Loading branch information
Monica Labbao committed May 13, 2017
0 parents commit b02db5a
Show file tree
Hide file tree
Showing 36 changed files with 783 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
31 changes: 31 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 <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.chishingwan.myapplication", appContext.getPackageName());
}
}
28 changes: 28 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chishingwan.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!--Must declare to Manifest-->

<activity android:name=".WelcomeActivity"
android:theme="@style/AppTheme"
android:label="Henlo Beautiful"/>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<ShoppingListAdapter.ShoppingListViewHolder> {

ArrayList<ShoppingListItem> 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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit b02db5a

Please sign in to comment.