Android Open Source - android-play-api-client Add New Fragment






From Project

Back to project page android-play-api-client.

License

The source code is released under:

Apache License

If you think the Android project android-play-api-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ar.com.gmvsoft.play.ui.fragment;
// w  ww. j  a v  a2  s  . com
import org.androidannotations.annotations.AfterInject;
import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.rest.RestService;

import android.app.ProgressDialog;
import android.support.v4.app.Fragment;
import android.widget.EditText;
import android.widget.Toast;
import ar.com.gmvsoft.play.Global;
import ar.com.gmvsoft.play.R;
import ar.com.gmvsoft.play.api.ProductsResource;
import ar.com.gmvsoft.play.api.dto.BaseProductDTO;
import ar.com.gmvsoft.play.api.error.APIErrorHandler;
import ar.com.gmvsoft.play.ui.dialog.DialogHelper;

@EFragment(R.layout.fragment_add_new)
public class AddNewFragment extends Fragment {

  private ProgressDialog progress;
  
  @RestService
  ProductsResource productsResource;
  
  @Bean
  APIErrorHandler restErrorHandler;
  
  @ViewById
  EditText txtName;
  
  @ViewById
  EditText txtPrice;
  
  @AfterInject
  void setUp() {
    productsResource.setRootUrl(Global.instance().getApiUrl());
    productsResource.setRestErrorHandler(restErrorHandler);
    progress = DialogHelper.createProgressBar(getActivity());
  }
  
  @Click
  void btnAddNewClicked() {
    progress.show();
    saveProductInBackground();
  }
  
  @Background
  void saveProductInBackground() {
    String name = txtName.getText().toString();
    Double price = Double.parseDouble(txtPrice.getText().toString());
    BaseProductDTO product = new BaseProductDTO(name, price);
    productsResource.addProduct(product);
    progress.dismiss();
    showInfo();
  }
  
  @UiThread
  void showInfo() {
    Toast.makeText(getActivity(), "Product saved successfully!", Toast.LENGTH_SHORT).show();
  }
  
}




Java Source Code List

ar.com.gmvsoft.play.Global.java
ar.com.gmvsoft.play.api.ProductsResource.java
ar.com.gmvsoft.play.api.dto.BaseProductDTO.java
ar.com.gmvsoft.play.api.dto.ProductDTO.java
ar.com.gmvsoft.play.api.error.APIErrorHandler.java
ar.com.gmvsoft.play.hardware.ShakeSensorListener.java
ar.com.gmvsoft.play.ui.DebugOptionsActivity.java
ar.com.gmvsoft.play.ui.MainActivity.java
ar.com.gmvsoft.play.ui.adapter.ProductsListAdapter.java
ar.com.gmvsoft.play.ui.adapter.ProductsTabsPagerAdapter.java
ar.com.gmvsoft.play.ui.dialog.DialogHelper.java
ar.com.gmvsoft.play.ui.fragment.AddNewFragment.java
ar.com.gmvsoft.play.ui.fragment.FindAllFragment.java
ar.com.gmvsoft.play.ui.fragment.FindByIdFragment.java