diff --git a/android/build.gradle b/android/build.gradle index 6bf3d03..991c029 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -49,6 +49,7 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23+' + compile 'com.android.support:appcompat-v7:' + androidSupportLibVersion + compile 'com.android.support:design:' + androidSupportLibVersion compile project(':core') } diff --git a/android/src/main/java/org/robovm/store/StoreAppActivity.java b/android/src/main/java/org/robovm/store/StoreAppActivity.java index 533bb06..85a6ecc 100644 --- a/android/src/main/java/org/robovm/store/StoreAppActivity.java +++ b/android/src/main/java/org/robovm/store/StoreAppActivity.java @@ -16,23 +16,31 @@ package org.robovm.store; -import android.app.Activity; -import android.app.Fragment; -import android.app.FragmentManager; -import android.app.FragmentTransaction; import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; import android.util.DisplayMetrics; import android.view.MenuItem; + import org.robovm.store.api.RoboVMWebService; import org.robovm.store.api.RoboVMWebService.ActionWrapper; -import org.robovm.store.fragments.*; +import org.robovm.store.fragments.BasketFragment; +import org.robovm.store.fragments.BragFragment; +import org.robovm.store.fragments.LoginFragment; +import org.robovm.store.fragments.ProductDetailsFragment; +import org.robovm.store.fragments.ProductListFragment; +import org.robovm.store.fragments.ShippingDetailsFragment; import org.robovm.store.model.Product; import org.robovm.store.util.Action; import org.robovm.store.util.ImageCache; import org.robovm.store.util.Images; -public class StoreAppActivity extends Activity { +public class StoreAppActivity extends AppCompatActivity { private int baseFragment; + private Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { @@ -52,6 +60,8 @@ public void invoke(Action action, T result) { }; setContentView(R.layout.main); + toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); // Retain fragments so don't set home if state is stored. if (getFragmentManager().getBackStackEntryCount() == 0) { @@ -76,25 +86,25 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) { } @Override - public boolean onMenuItemSelected(int featureId, MenuItem item) { + public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.cart_menu_item: - showBasket(); - return true; - case android.R.id.home: - // pop full backstack when going home. - getFragmentManager().popBackStack(baseFragment, FragmentManager.POP_BACK_STACK_INCLUSIVE); - setupActionBar(); - return true; + case R.id.cart_menu_item: + showBasket(); + return true; + case android.R.id.home: + // pop full backstack when going home. + getFragmentManager().popBackStack(baseFragment, FragmentManager.POP_BACK_STACK_INCLUSIVE); + setupActionBar(); + return true; } - return super.onMenuItemSelected(featureId, item); + return super.onOptionsItemSelected(item); } @Override public void onBackPressed() { super.onBackPressed(); - setupActionBar(getFragmentManager().getBackStackEntryCount() != 0); + setupActionBar(getSupportFragmentManager().getBackStackEntryCount() != 0); } public int switchScreens(Fragment fragment) { @@ -102,7 +112,7 @@ public int switchScreens(Fragment fragment) { } public int switchScreens(Fragment fragment, boolean animated, boolean isRoot) { - FragmentTransaction transaction = getFragmentManager().beginTransaction(); + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); if (animated) { transaction.setCustomAnimations(getInAnimationForFragment(fragment), getOutAnimationForFragment(fragment)); @@ -121,12 +131,12 @@ private int getInAnimationForFragment(Fragment fragment) { int animIn = R.anim.enter; switch (fragment.getClass().getSimpleName()) { - case "ProductDetailsFragment": - animIn = R.anim.product_detail_in; - break; - case "BasketFragment": - animIn = R.anim.basket_in; - break; + case "ProductDetailsFragment": + animIn = R.anim.product_detail_in; + break; + case "BasketFragment": + animIn = R.anim.basket_in; + break; } return animIn; } @@ -135,11 +145,11 @@ private int getOutAnimationForFragment(Fragment fragment) { int animOut = R.anim.exit; switch (fragment.getClass().getSimpleName()) { - case "ProductDetailsFragment": - animOut = R.anim.product_detail_out; - break; - case "BasketFragment": - break; + case "ProductDetailsFragment": + animOut = R.anim.product_detail_out; + break; + case "BasketFragment": + break; } return animOut; } @@ -148,6 +158,7 @@ public void showProductDetail(Product product, int itemVerticalOffset) { ProductDetailsFragment productDetails = new ProductDetailsFragment(product, itemVerticalOffset); productDetails.setAddToBasketListener((order) -> { RoboVMWebService.getInstance().getBasket().add(order); + onBackPressed(); setupActionBar(); }); switchScreens(productDetails); @@ -158,7 +169,8 @@ public void setupActionBar() { } public void setupActionBar(boolean showUp) { - getActionBar().setDisplayHomeAsUpEnabled(showUp); + getSupportActionBar().setDisplayHomeAsUpEnabled(showUp); + toolbar.setNavigationOnClickListener(v -> onBackPressed()); } public void showBasket() { diff --git a/android/src/main/java/org/robovm/store/fragments/BasketFragment.java b/android/src/main/java/org/robovm/store/fragments/BasketFragment.java index 6998724..6708f88 100644 --- a/android/src/main/java/org/robovm/store/fragments/BasketFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/BasketFragment.java @@ -16,13 +16,6 @@ package org.robovm.store.fragments; -import android.app.ListFragment; -import android.content.Context; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.*; import org.robovm.store.R; import org.robovm.store.api.RoboVMWebService; import org.robovm.store.model.Basket; @@ -31,13 +24,26 @@ import org.robovm.store.views.SwipableListItem; import org.robovm.store.views.ViewSwipeTouchListener; +import android.content.Context; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + public class BasketFragment extends ListFragment { private Basket basket; private Button checkoutButton; private Runnable checkoutListener; - public BasketFragment() {} + public BasketFragment() { + } public BasketFragment(Basket basket) { this.basket = basket; @@ -50,10 +56,11 @@ public void onCreate(Bundle savedInstanceState) { } @Override - public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { View shoppingCartView = inflater.inflate(R.layout.basket, container, false); - checkoutButton = (Button) shoppingCartView.findViewById(R.id.checkoutBtn); + checkoutButton = (Button)shoppingCartView.findViewById(R.id.checkoutBtn); checkoutButton.setOnClickListener((b) -> { if (checkoutListener != null) { checkoutListener.run(); @@ -75,8 +82,8 @@ public void onViewCreated(View view, Bundle savedInstanceState) { checkoutButton.setVisibility(View.INVISIBLE); } - basket.addOnBasketChangeListener( - () -> checkoutButton.setVisibility(basket.size() > 0 ? View.VISIBLE : View.INVISIBLE)); + basket.addOnBasketChangeListener(() -> checkoutButton + .setVisibility(basket.size() > 0 ? View.VISIBLE : View.INVISIBLE)); } public static class GroceryListAdapter extends BaseAdapter { @@ -110,7 +117,7 @@ public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; // re-use an existing view, if one is available if (view == null) { view = LayoutInflater.from(context).inflate(R.layout.basket_item, parent, false); - ViewSwipeTouchListener swipper = ((SwipableListItem) view).getSwipeListener(); + ViewSwipeTouchListener swipper = ((SwipableListItem)view).getSwipeListener(); final View finalView = view; swipper.addEventListener(new ViewSwipeTouchListener.EventListener() { @Override @@ -129,7 +136,7 @@ public void onItemSwipped() { if (finalView.getParent() == null) { return; } - int p = ((ListView) parent).getPositionForView(finalView); + int p = ((ListView)parent).getPositionForView(finalView); Basket basket = RoboVMWebService.getInstance().getBasket(); basket.remove(p); notifyDataSetChanged(); @@ -137,12 +144,14 @@ public void onItemSwipped() { }); } - ((TextView) view.findViewById(R.id.productTitle)).setText(order.getProduct().getName()); - ((TextView) view.findViewById(R.id.productPrice)).setText(order.getProduct().getPriceDescription()); - ((TextView) view.findViewById(R.id.productColor)).setText(order.getColor().getName()); - ((TextView) view.findViewById(R.id.productSize)).setText(order.getSize().getName()); + ((TextView)view.findViewById(R.id.productTitle)).setText(order.getProduct().getName()); + ((TextView)view.findViewById(R.id.productPrice)) + .setText(order.getProduct().getPriceDescription()); + ((TextView)view.findViewById(R.id.productColor)).setText(order.getColor().getName()); + ((TextView)view.findViewById(R.id.productSize)).setText(order.getSize().getName()); + ((TextView)view.findViewById(R.id.productQuantity)).setText("x" + order.getQuantity()); - ImageView orderImage = (ImageView) view.findViewById(R.id.productImage); + ImageView orderImage = (ImageView)view.findViewById(R.id.productImage); orderImage.setImageResource(R.drawable.product_image); Images.setImageFromUrlAsync(orderImage, order.getColor().getImageUrls().get(0)); diff --git a/android/src/main/java/org/robovm/store/fragments/BragFragment.java b/android/src/main/java/org/robovm/store/fragments/BragFragment.java index fdb2c26..f33f4d1 100644 --- a/android/src/main/java/org/robovm/store/fragments/BragFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/BragFragment.java @@ -16,13 +16,14 @@ package org.robovm.store.fragments; -import android.app.Fragment; import android.content.Intent; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; + import org.robovm.store.R; public class BragFragment extends Fragment { diff --git a/android/src/main/java/org/robovm/store/fragments/LoginFragment.java b/android/src/main/java/org/robovm/store/fragments/LoginFragment.java index b6c50d8..ca6e68a 100644 --- a/android/src/main/java/org/robovm/store/fragments/LoginFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/LoginFragment.java @@ -16,18 +16,23 @@ package org.robovm.store.fragments; -import android.app.Fragment; import android.app.ProgressDialog; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.text.Html; import android.text.Spanned; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + import org.robovm.store.R; import org.robovm.store.api.RoboVMWebService; import org.robovm.store.util.Gravatar; @@ -45,7 +50,8 @@ public class LoginFragment extends Fragment { private Button login; private ImageView imageView; - public LoginFragment() {} + public LoginFragment() { + } @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/src/main/java/org/robovm/store/fragments/ProductDetailsFragment.java b/android/src/main/java/org/robovm/store/fragments/ProductDetailsFragment.java index 4f38df1..88061a7 100644 --- a/android/src/main/java/org/robovm/store/fragments/ProductDetailsFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/ProductDetailsFragment.java @@ -16,31 +16,53 @@ package org.robovm.store.fragments; +import org.robovm.store.R; +import org.robovm.store.api.RoboVMWebService; +import org.robovm.store.model.Basket; +import org.robovm.store.model.Order; +import org.robovm.store.model.Product; +import org.robovm.store.model.ProductColor; +import org.robovm.store.model.ProductSize; +import org.robovm.store.util.Action; +import org.robovm.store.util.Colors; +import org.robovm.store.util.ImageCache; +import org.robovm.store.util.Images; +import org.robovm.store.util.MatrixEvaluator; +import org.robovm.store.views.BadgeDrawable; +import org.robovm.store.views.KenBurnsDrawable; +import org.robovm.store.views.SlidingLayout; + import android.animation.Animator; -import android.animation.AnimatorInflater; import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.Activity; -import android.app.Fragment; import android.graphics.Bitmap; import android.graphics.Matrix; import android.os.Bundle; -import android.view.*; -import android.widget.*; -import org.robovm.store.R; -import org.robovm.store.api.RoboVMWebService; -import org.robovm.store.model.*; -import org.robovm.store.util.*; -import org.robovm.store.views.BadgeDrawable; -import org.robovm.store.views.KenBurnsDrawable; -import org.robovm.store.views.SlidingLayout; +import android.support.design.widget.Snackbar; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; -public class ProductDetailsFragment extends Fragment implements ViewTreeObserver.OnGlobalLayoutListener { +public class ProductDetailsFragment extends Fragment implements ViewTreeObserver + .OnGlobalLayoutListener { private static final float ENLARGE_RATIO = 1.1f; private Action addToBasketListener; @@ -59,12 +81,14 @@ public class ProductDetailsFragment extends Fragment implements ViewTreeObserver private int slidingDelta; private Spinner sizeSpinner; private Spinner colorSpinner; + private Spinner quantitySpinner; private KenBurnsDrawable productDrawable; private ValueAnimator kenBurnsMovement; private ValueAnimator kenBurnsAlpha; - public ProductDetailsFragment() {} + public ProductDetailsFragment() { + } public ProductDetailsFragment(Product product, int slidingDelta) { this.currentProduct = product; @@ -83,7 +107,8 @@ public void onCreate(Bundle savedInstanceState) { } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { return inflater.inflate(R.layout.product_detail, null, true); } @@ -91,26 +116,32 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - productImage = (ImageView) view.findViewById(R.id.productImage); - sizeSpinner = (Spinner) view.findViewById(R.id.productSize); - colorSpinner = (Spinner) view.findViewById(R.id.productColor); + productImage = (ImageView)view.findViewById(R.id.productImage); + sizeSpinner = (Spinner)view.findViewById(R.id.productSize); + colorSpinner = (Spinner)view.findViewById(R.id.productColor); + quantitySpinner = (Spinner)view.findViewById(R.id.productQuantity); - Button addToBasket = (Button) view.findViewById(R.id.addToBasket); + Button addToBasket = (Button)view.findViewById(R.id.addToBasket); addToBasket.setOnClickListener((button) -> { order.setSize(currentProduct.getSizes().get(sizeSpinner.getSelectedItemPosition())); order.setColor(currentProduct.getColors().get(colorSpinner.getSelectedItemPosition())); + order.setQuantity((Integer)quantitySpinner.getSelectedItem()); shouldAnimatePop = true; + Snackbar.make(getView(), order.getProduct() + " added to basket", Snackbar.LENGTH_LONG) + .show(); getActivity().getFragmentManager().popBackStack(); if (addToBasketListener != null) { addToBasketListener.invoke(new Order(order)); } }); - ((TextView) view.findViewById(R.id.productTitle)).setText(currentProduct.getName()); - ((TextView) view.findViewById(R.id.productPrice)).setText(currentProduct.getPriceDescription()); - ((TextView) view.findViewById(R.id.productDescription)).setText(currentProduct.getDescription()); + ((TextView)view.findViewById(R.id.productTitle)).setText(currentProduct.getName()); + ((TextView)view.findViewById(R.id.productPrice)) + .setText(currentProduct.getPriceDescription()); + ((TextView)view.findViewById(R.id.productDescription)) + .setText(currentProduct.getDescription()); - ((SlidingLayout) view).setInitialMainViewDelta(slidingDelta); + ((SlidingLayout)view).setInitialMainViewDelta(slidingDelta); loadOptions(); } @@ -127,6 +158,13 @@ private void loadOptions() { colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); colorSpinner.setAdapter(colorAdapter); + + Integer[] quantities = new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + ArrayAdapter quantityAdapter = new ArrayAdapter(getContext(), + android.R.layout.simple_spinner_dropdown_item, quantities); + quantityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + quantitySpinner.setAdapter(quantityAdapter); } @Override @@ -159,11 +197,11 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { } @Override - public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { + public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { if (!enter && shouldAnimatePop) { - return AnimatorInflater.loadAnimator(getView().getContext(), R.anim.add_to_basket_in); + return AnimationUtils.loadAnimation(getView().getContext(), R.anim.add_to_basket_in); } - return super.onCreateAnimator(transit, enter, nextAnim); + return super.onCreateAnimation(transit, enter, nextAnim); } private void animateImages() { @@ -218,19 +256,21 @@ public void onGlobalLayout() { if (imageHeight > frameHeight) { heightDiff = imageHeight - frameHeight; - if (widthDiff > heightDiff) + if (widthDiff > heightDiff) { resizeRatio = frameHeight / imageHeight; - else + } else { resizeRatio = frameWidth / imageWidth; + } // No higher than screen [OK] } else { heightDiff = frameHeight - imageHeight; - if (widthDiff > heightDiff) + if (widthDiff > heightDiff) { resizeRatio = frameWidth / imageWidth; - else + } else { resizeRatio = frameHeight / imageHeight; + } } // No wider than screen } else { @@ -240,19 +280,21 @@ public void onGlobalLayout() { if (imageHeight > frameHeight) { heightDiff = imageHeight - frameHeight; - if (widthDiff > heightDiff) + if (widthDiff > heightDiff) { resizeRatio = imageHeight / frameHeight; - else + } else { resizeRatio = frameWidth / imageWidth; + } // No higher than screen [OK] } else { heightDiff = frameHeight - imageHeight; - if (widthDiff > heightDiff) + if (widthDiff > heightDiff) { resizeRatio = frameWidth / imageWidth; - else + } else { resizeRatio = frameHeight / imageHeight; + } } } @@ -269,68 +311,72 @@ public void onGlobalLayout() { float rotation = random.nextInt(9) / 100f; switch (random.nextInt(3)) { - case 0: - zoomInX = 1.25f; - zoomInY = 1.25f; - moveX = -maxMoveX; - moveY = -maxMoveY; - break; - case 1: - zoomInX = 1.1f; - zoomInY = 1.1f; - moveX = -maxMoveX; - moveY = maxMoveY; - originY = -moveY * zoomInY * 1.1f; - break; - case 2: - zoomInX = 1.2f; - zoomInY = 1.2f; - moveX = 0; - moveY = -maxMoveY; - break; - default: - zoomInX = 1.2f; - zoomInY = 1.2f; - moveX = 0; - moveY = maxMoveY; - originY = -moveY * zoomInY * 1.1f; - break; + case 0: + zoomInX = 1.25f; + zoomInY = 1.25f; + moveX = -maxMoveX; + moveY = -maxMoveY; + break; + case 1: + zoomInX = 1.1f; + zoomInY = 1.1f; + moveX = -maxMoveX; + moveY = maxMoveY; + originY = -moveY * zoomInY * 1.1f; + break; + case 2: + zoomInX = 1.2f; + zoomInY = 1.2f; + moveX = 0; + moveY = -maxMoveY; + break; + default: + zoomInX = 1.2f; + zoomInY = 1.2f; + moveX = 0; + moveY = maxMoveY; + originY = -moveY * zoomInY * 1.1f; + break; } MatrixEvaluator evaluator = new MatrixEvaluator(); Matrix startMatrix = new Matrix(); startMatrix.setTranslate(originX, originY); - startMatrix - .postScale(resizeRatio * ENLARGE_RATIO, resizeRatio * ENLARGE_RATIO, originX, originY); + startMatrix.postScale(resizeRatio * ENLARGE_RATIO, + resizeRatio * ENLARGE_RATIO, originX, originY); Matrix finalMatrix = new Matrix(); finalMatrix.setTranslate(originX + moveX, originY + moveY); - finalMatrix - .postScale(resizeRatio * ENLARGE_RATIO * zoomInX, resizeRatio * ENLARGE_RATIO * zoomInY, - originX, originY); + finalMatrix.postScale(resizeRatio * ENLARGE_RATIO * zoomInX, + resizeRatio * ENLARGE_RATIO * zoomInY, originX, originY); finalMatrix.postRotate(rotation); - kenBurnsMovement = ValueAnimator.ofObject(evaluator, startMatrix, finalMatrix); - kenBurnsMovement.addUpdateListener( - (animator) -> productDrawable.setMatrix((Matrix) animator.getAnimatedValue())); + kenBurnsMovement = ValueAnimator + .ofObject(evaluator, startMatrix, finalMatrix); + kenBurnsMovement.addUpdateListener((animator) -> productDrawable + .setMatrix((Matrix)animator.getAnimatedValue())); kenBurnsMovement.setDuration(14000); kenBurnsMovement.setRepeatMode(ValueAnimator.REVERSE); kenBurnsMovement.setRepeatCount(ValueAnimator.INFINITE); kenBurnsMovement.start(); - kenBurnsAlpha = ObjectAnimator.ofInt(productDrawable, "alpha", 0, 0, 0, 255, 255, 255); + kenBurnsAlpha = ObjectAnimator + .ofInt(productDrawable, "alpha", 0, 0, 0, 255, 255, 255); kenBurnsAlpha.setDuration(kenBurnsMovement.getDuration()); kenBurnsAlpha.setRepeatMode(ValueAnimator.REVERSE); kenBurnsAlpha.setRepeatCount(ValueAnimator.INFINITE); kenBurnsAlpha.addListener(new Animator.AnimatorListener() { @Override - public void onAnimationStart(Animator animation) {} + public void onAnimationStart(Animator animation) { + } @Override - public void onAnimationEnd(Animator animation) {} + public void onAnimationEnd(Animator animation) { + } @Override - public void onAnimationCancel(Animator animation) {} + public void onAnimationCancel(Animator animation) { + } @Override public void onAnimationRepeat(Animator animation) { @@ -360,7 +406,8 @@ private void precacheNextImage() { } int next = currentIndex + 1; String image = images.get(next); - ImageCache.getInstance().downloadImage(image, (f) -> {}); + ImageCache.getInstance().downloadImage(image, (f) -> { + }); } public void setAddToBasketListener(Action listener) { diff --git a/android/src/main/java/org/robovm/store/fragments/ProductListFragment.java b/android/src/main/java/org/robovm/store/fragments/ProductListFragment.java index 8aa6fc8..996675a 100644 --- a/android/src/main/java/org/robovm/store/fragments/ProductListFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/ProductListFragment.java @@ -16,14 +16,24 @@ package org.robovm.store.fragments; -import android.app.ListFragment; import android.content.Context; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import android.view.*; +import android.support.v4.app.ListFragment; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; import android.view.animation.DecelerateInterpolator; -import android.widget.*; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.ProgressBar; +import android.widget.TextView; + import org.robovm.store.R; import org.robovm.store.api.RoboVMWebService; import org.robovm.store.model.Basket; diff --git a/android/src/main/java/org/robovm/store/fragments/ShippingDetailsFragment.java b/android/src/main/java/org/robovm/store/fragments/ShippingDetailsFragment.java index 436f42d..443d41a 100644 --- a/android/src/main/java/org/robovm/store/fragments/ShippingDetailsFragment.java +++ b/android/src/main/java/org/robovm/store/fragments/ShippingDetailsFragment.java @@ -16,13 +16,19 @@ package org.robovm.store.fragments; -import android.app.Fragment; import android.app.ProgressDialog; import android.os.Bundle; +import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.*; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + import org.robovm.store.R; import org.robovm.store.api.RoboVMWebService; import org.robovm.store.api.ValidationError; @@ -102,7 +108,8 @@ public void onItemSelected(AdapterView parent, View view, int position, long } @Override - public void onNothingSelected(AdapterView parent) {} + public void onNothingSelected(AdapterView parent) { + } }); placeOrder.setOnClickListener((b) -> placeOrder()); @@ -131,8 +138,8 @@ private void loadStates() { } private void placeOrder() { - EditText[] entries = new EditText[] { phoneNumberField, address1Field, address2Field, cityField, stateField, - zipCodeField, countryField }; + EditText[] entries = new EditText[]{phoneNumberField, address1Field, address2Field, cityField, stateField, + zipCodeField, countryField}; for (EditText entry : entries) { entry.setEnabled(false); } @@ -180,30 +187,30 @@ private void placeOrder() { alertMessage = message; } else { switch (field) { - case "firstName": - alertMessage = "First name is required"; - break; - case "lastName": - alertMessage = "Last name is required"; - break; - case "address1": - alertMessage = "Address is required"; - break; - case "city": - alertMessage = "City is required"; - break; - case "zipCode": - alertMessage = "ZIP code is required"; - break; - case "phone": - alertMessage = "Phone number is required"; - break; - case "country": - alertMessage = "Country is required"; - break; - default: - alertMessage = message; - break; + case "firstName": + alertMessage = "First name is required"; + break; + case "lastName": + alertMessage = "Last name is required"; + break; + case "address1": + alertMessage = "Address is required"; + break; + case "city": + alertMessage = "City is required"; + break; + case "zipCode": + alertMessage = "ZIP code is required"; + break; + case "phone": + alertMessage = "Phone number is required"; + break; + case "country": + alertMessage = "Country is required"; + break; + default: + alertMessage = message; + break; } } } diff --git a/android/src/main/java/org/robovm/store/util/Images.java b/android/src/main/java/org/robovm/store/util/Images.java index 5178889..889bf28 100644 --- a/android/src/main/java/org/robovm/store/util/Images.java +++ b/android/src/main/java/org/robovm/store/util/Images.java @@ -77,13 +77,43 @@ public static void fromUrl(String url, Action completion) { } private static Bitmap saveBitmap(String url, File imagePath) { - Bitmap bmp = BitmapFactory.decodeFile(imagePath.getAbsolutePath()); + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeFile(imagePath.getAbsolutePath(), options); + + options.inSampleSize = calculateInSampleSize(options, (int) SCREEN_WIDTH, (int) SCREEN_WIDTH); + options.inJustDecodeBounds = false; + Bitmap bmp = BitmapFactory.decodeFile(imagePath.getAbsolutePath(), options); + if (bmp != null) { bmpCache.put(url, bmp); } return bmp; } + public static int calculateInSampleSize( + BitmapFactory.Options options, int reqWidth, int reqHeight) { + // Raw height and width of image + final int height = options.outHeight; + final int width = options.outWidth; + int inSampleSize = 1; + + if (height > reqHeight || width > reqWidth) { + + final int halfHeight = height / 2; + final int halfWidth = width / 2; + + // Calculate the largest inSampleSize value that is a power of 2 and keeps both + // height and width larger than the requested height and width. + while ((halfHeight / inSampleSize) > reqHeight + && (halfWidth / inSampleSize) > reqWidth) { + inSampleSize *= 2; + } + } + + return inSampleSize; + } + public static void setScreenWidth(float screenWidth) { SCREEN_WIDTH = screenWidth; } diff --git a/android/src/main/res/anim/add_to_basket_in.xml b/android/src/main/res/anim/add_to_basket_in.xml index 7f48fc2..b59c2be 100755 --- a/android/src/main/res/anim/add_to_basket_in.xml +++ b/android/src/main/res/anim/add_to_basket_in.xml @@ -1,9 +1,7 @@ - + \ No newline at end of file diff --git a/android/src/main/res/anim/basket_in.xml b/android/src/main/res/anim/basket_in.xml index 05577b4..19434bb 100755 --- a/android/src/main/res/anim/basket_in.xml +++ b/android/src/main/res/anim/basket_in.xml @@ -1,21 +1,15 @@ - - - + + + \ No newline at end of file diff --git a/android/src/main/res/anim/enter.xml b/android/src/main/res/anim/enter.xml index ac10566..427bd8c 100755 --- a/android/src/main/res/anim/enter.xml +++ b/android/src/main/res/anim/enter.xml @@ -1,9 +1,6 @@ - - + + \ No newline at end of file diff --git a/android/src/main/res/anim/exit.xml b/android/src/main/res/anim/exit.xml index 3de5f69..8c35bfa 100755 --- a/android/src/main/res/anim/exit.xml +++ b/android/src/main/res/anim/exit.xml @@ -1,9 +1,6 @@ - - + + \ No newline at end of file diff --git a/android/src/main/res/anim/product_detail_in.xml b/android/src/main/res/anim/product_detail_in.xml index 4f5835b..16de2aa 100755 --- a/android/src/main/res/anim/product_detail_in.xml +++ b/android/src/main/res/anim/product_detail_in.xml @@ -1,15 +1,11 @@ - - + + \ No newline at end of file diff --git a/android/src/main/res/anim/product_detail_out.xml b/android/src/main/res/anim/product_detail_out.xml index e82ac85..c1fa3dc 100755 --- a/android/src/main/res/anim/product_detail_out.xml +++ b/android/src/main/res/anim/product_detail_out.xml @@ -1,9 +1,8 @@ - + + \ No newline at end of file diff --git a/android/src/main/res/drawable/ab_background.xml b/android/src/main/res/drawable/ab_background.xml deleted file mode 100755 index 20c919f..0000000 --- a/android/src/main/res/drawable/ab_background.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/android/src/main/res/layout/basket_item.xml b/android/src/main/res/layout/basket_item.xml index 3a2dd53..fefd075 100755 --- a/android/src/main/res/layout/basket_item.xml +++ b/android/src/main/res/layout/basket_item.xml @@ -1,111 +1,141 @@ - + android:layout_height="wrap_content"> + + android:id="@+id/swipeContent" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="?android:attr/colorBackground" + android:minHeight="25px" + android:minWidth="25px" + android:orientation="horizontal"> + + android:id="@+id/productImage" + android:layout_width="72dp" + android:layout_height="72dp" + android:layout_marginBottom="4dp" + android:layout_marginTop="4dp" + android:scaleType="centerCrop" + android:src="@android:drawable/ic_menu_gallery"/> + + android:id="@+id/linearLayout2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_marginBottom="4dp" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="4dp" + android:layout_weight="1" + android:minHeight="25px" + android:minWidth="25px" + android:orientation="vertical"> + + android:id="@+id/linearLayout3" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:minHeight="25px" + android:minWidth="25px" + android:orientation="horizontal"> + + android:id="@+id/productTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:layout_weight="1" + android:text="Men's Java t-shirt" + android:textColor="#272727" + android:textSize="18sp"/> + + android:id="@+id/productPrice" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:text="Free" + android:textAllCaps="true" + android:textColor="#09a8d6" + android:textSize="12sp"/> + + + + + - + + + android:layout_gravity="bottom" + android:text="x1" + android:textColor="@color/robo_dark_blue" + android:textSize="12sp"/> + + + android:id="@+id/swipeAfter" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:minHeight="25px" + android:minWidth="25px" + android:orientation="horizontal" + android:visibility="invisible"> + + android:id="@+id/textView1" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_weight="1" + android:gravity="center" + android:text="Item removed" + android:textSize="20sp"/> + + android:id="@+id/view1" + android:layout_width="1dp" + android:layout_height="match_parent" + android:layout_marginBottom="8dp" + android:layout_marginTop="8dp" + android:background="#aaaaaa"/> +