Skip to content

Commit

Permalink
Add link to shopping cart
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyvu2014 committed May 29, 2016
1 parent b5fb609 commit 2d51979
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
15 changes: 15 additions & 0 deletions demo/src/main/java/com/android/tonyvu/sc/demo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.android.tonyvu.sc.demo.adapter.ProductAdapter;
import com.android.tonyvu.sc.demo.constant.Constant;
Expand All @@ -21,6 +24,18 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView tvViewShoppingCart = (TextView)findViewById(R.id.tvViewShoppingCart);
SpannableString content = new SpannableString(getText(R.string.shopping_cart));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tvViewShoppingCart.setText(content);
tvViewShoppingCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ShoppingCartActivity.class);
startActivity(intent);
}
});

ListView lvProducts = (ListView) findViewById(R.id.lvProducts);
lvProducts.addHeaderView(getLayoutInflater().inflate(R.layout.product_list_header, lvProducts, false));

Expand Down
19 changes: 19 additions & 0 deletions demo/src/main/java/com/android/tonyvu/sc/demo/ProductActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
Expand Down Expand Up @@ -37,6 +39,9 @@ protected void onCreate(Bundle savedInstanceState) {

Log.d(TAG, "Product hashCode: " + product.hashCode());

//Set Shopping Cart link
setShoppingCartLink();

//Retrieve views
retrieveViews();

Expand All @@ -50,6 +55,20 @@ protected void onCreate(Bundle savedInstanceState) {
onOrderProduct();
}

private void setShoppingCartLink() {
TextView tvViewShoppingCart = (TextView)findViewById(R.id.tvViewShoppingCart);
SpannableString content = new SpannableString(getText(R.string.shopping_cart));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tvViewShoppingCart.setText(content);
tvViewShoppingCart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ProductActivity.this, ShoppingCartActivity.class);
startActivity(intent);
}
});
}

private void retrieveViews() {
tvProductName = (TextView) findViewById(R.id.tvProductName);
tvProductDesc = (TextView) findViewById(R.id.tvProductDesc);
Expand Down
11 changes: 11 additions & 0 deletions demo/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.android.tonyvu.sc.demo.MainActivity">

<TextView android:id="@+id/tvViewShoppingCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/blue"
android:gravity="center"
android:paddingBottom="@dimen/common_padding"
android:paddingTop="@dimen/common_padding"
android:text="@string/shopping_cart"
android:textSize="@dimen/small_header_text_size"/>

<TextView
android:id="@+id/tvProductListHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tvViewShoppingCart"
android:background="@color/green"
android:gravity="center"
android:paddingBottom="@dimen/common_padding"
Expand Down
13 changes: 12 additions & 1 deletion demo/src/main/res/layout/activity_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">

<TextView android:id="@+id/tvViewShoppingCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textColor="@color/blue"
android:gravity="center"
android:paddingBottom="@dimen/common_padding"
android:paddingTop="@dimen/common_padding"
android:text="@string/shopping_cart"
android:textSize="@dimen/small_header_text_size"/>

<TextView
android:id="@+id/tvProductName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="@id/tvViewShoppingCart"
android:background="@color/green"
android:gravity="center"
android:padding="@dimen/common_padding"
Expand Down
1 change: 1 addition & 0 deletions demo/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<resources>
<color name="green">#008000</color>
<color name="orange">#ff5500</color>
<color name="blue">#0000FF</color>
</resources>
1 change: 1 addition & 0 deletions demo/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<dimen name="header_text_size">16sp</dimen>
<dimen name="product_list_header_text_size">14sp</dimen>
<dimen name="common_padding">5dp</dimen>
<dimen name="small_header_text_size">14sp</dimen>

</resources>

0 comments on commit 2d51979

Please sign in to comment.