<commit_before>package com.arquitetaweb.comanda.fragment;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.arquitetaweb.comanda.R;
import com.arquitetaweb.comanda.activity.DetailMesaActivity;
import com.arquitetaweb.comanda.adapter.ProdutoGrupoAdapter;
import com.arquitetaweb.comanda.controller.ProdutoController;
import com.arquitetaweb.comanda.model.MesaModel;
import com.arquitetaweb.comum.component.ListViewCustom;

public class ProdutoFragment extends ListFragment {

	private ProdutoController controller;

	private ListViewCustom mListView;
	private LinearLayout mQuickReturnViewTop;
	private int mQuickReturnHeightTop;

	private View mPlaceHolder;
	private View mHeader;

	private int mCachedVerticalScrollRange;

	private static final int STATE_ONSCREEN = 0;
	private static final int STATE_OFFSCREEN = 1;
	private static final int STATE_RETURNING = 2;
	private static final int STATE_EXPANDED = 3;

	private int mState = STATE_ONSCREEN;
	private int mScrollYtop;
	private int mMinRawYtop = 0;
	private int rawY;
	private boolean noAnimation = false;

	private TranslateAnimation animTop;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_produto, null);
		mHeader = inflater.inflate(R.layout.produto_header, null);

		mQuickReturnViewTop = (LinearLayout) view
				.findViewById(R.id.comanda_layout);

		mPlaceHolder = mHeader.findViewById(R.id.placeholder);

		Button btn1 = (Button) view.findViewById(R.id.produtos_recentes);
		btn1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Toast toast = Toast.makeText(getActivity(), "teste 1 btn",
						Toast.LENGTH_SHORT);
				toast.show();
			}
		});

		View mInfoHeader = mHeader.findViewById(R.id.infoheader);
		MesaModel mesa = ((DetailMesaActivity) this.getActivity())
				.getMesaModel();
		TextView id = (TextView) mInfoHeader.findViewById(R.id.txtidmesaheader);
		id.setText("Id: " + mesa.id.toString());
		TextView numero = (TextView) mInfoHeader
				.findViewById(R.id.txtmesaheader);
		numero.setText("Nmero: " + mesa.numero_mesa.toString());
		TextView situacao = (TextView) mInfoHeader
				.findViewById(R.id.txtdetailmesaheader);
		situacao.setText("Situao: " + mesa.situacao.toString());

		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		controller = new ProdutoController(this.getActivity());
		ProdutoGrupoAdapter adapter = new ProdutoGrupoAdapter(
				this.getActivity(), controller.sincronizar());
		
		mListView = (ListViewCustom) getListView();
		mListView.addHeaderView(mHeader);
		
		setListAdapter(adapter);	
		//mListView.setAdapter(adapter);

		mListView.setOnItemClickListener(new OnItemClickListener() {
			
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				Toast toast = Toast.makeText(getActivity(),
						position + " - " + id, Toast.LENGTH_SHORT);
				toast.show();

				// Intent intent = new Intent(view.getContext(),
				// TestePutActivity.class);
				//
				// MesaModel mesaObj = adapter.getItem(idMesa);
				// String mesaGson = new Gson().toJson(mesaObj);
				// intent.putExtra("mesa", mesaGson);
				// fragment.startActivityForResult(intent, 100);

			}

		});

		mListView.getViewTreeObserver().addOnGlobalLayoutListener(
				new ViewTreeObserver.OnGlobalLayoutListener() {
					@Override
					public void onGlobalLayout() {
						mQuickReturnHeightTop = mQuickReturnViewTop.getHeight();
						mListView.computeScrollY();
						mCachedVerticalScrollRange = mListView.getListHeight();
					}
				});

		mListView.setOnScrollListener(new OnScrollListener() {
			@SuppressLint("NewApi")
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {

				int translationY = 0;
				translationY = noAnimation(); // used
				// translationY = animation();

				/** this can be used if the build is below honeycomb **/
				if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
					animTop = new TranslateAnimation(0, 0, translationY,
							translationY);
					animTop.setFillAfter(true);
					animTop.setDuration(0);<commit_msg>#170320142217<commit_after>package com.arquitetaweb.comanda.fragment;

import java.util.List;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.arquitetaweb.comanda.R;
import com.arquitetaweb.comanda.activity.DetailMesaActivity;
import com.arquitetaweb.comanda.adapter.ProdutoAdapter;
import com.arquitetaweb.comanda.adapter.ProdutoGrupoAdapter;
import com.arquitetaweb.comanda.controller.ProdutoController;
import com.arquitetaweb.comanda.model.MesaModel;
import com.arquitetaweb.comanda.model.ProdutoGrupoModel;
import com.arquitetaweb.comanda.model.ProdutoModel;
import com.arquitetaweb.comum.component.ListViewCustom;
import com.arquitetaweb.helper.sqllite.ProdutoGenericHelper;

public class ProdutoFragment extends ListFragment {

	private ProdutoController controller;

	private ListViewCustom mListView;
	private LinearLayout mQuickReturnViewTop;
	private int mQuickReturnHeightTop;

	private View mPlaceHolder;
	private View mHeader;

	private int mCachedVerticalScrollRange;

	private static final int STATE_ONSCREEN = 0;
	private static final int STATE_OFFSCREEN = 1;
	private static final int STATE_RETURNING = 2;
	private static final int STATE_EXPANDED = 3;

	private int mState = STATE_ONSCREEN;
	private int mScrollYtop;
	private int mMinRawYtop = 0;
	private int rawY;
	private boolean noAnimation = false;

	private TranslateAnimation animTop;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_produto, null);
		mHeader = inflater.inflate(R.layout.produto_header, null);

		mQuickReturnViewTop = (LinearLayout) view
				.findViewById(R.id.comanda_layout);

		mPlaceHolder = mHeader.findViewById(R.id.placeholder);

		Button btn1 = (Button) view.findViewById(R.id.produtos_recentes);
		btn1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Toast toast = Toast.makeText(getActivity(), "teste 1 btn",
						Toast.LENGTH_SHORT);
				toast.show();
			}
		});

		View mInfoHeader = mHeader.findViewById(R.id.infoheader);
		MesaModel mesa = ((DetailMesaActivity) this.getActivity())
				.getMesaModel();
		TextView id = (TextView) mInfoHeader.findViewById(R.id.txtidmesaheader);
		id.setText("Id: " + mesa.id.toString());
		TextView numero = (TextView) mInfoHeader
				.findViewById(R.id.txtmesaheader);
		numero.setText("Nmero: " + mesa.numero_mesa.toString());
		TextView situacao = (TextView) mInfoHeader
				.findViewById(R.id.txtdetailmesaheader);
		situacao.setText("Situao: " + mesa.situacao.toString());

		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		controller = new ProdutoController(this.getActivity());
		ProdutoGrupoAdapter adapter = new ProdutoGrupoAdapter(
				this.getActivity(), controller.sincronizar());

		mListView = (ListViewCustom) getListView();
		mListView.addHeaderView(mHeader);
		// setListAdapter(adapter);
		mListView.setAdapter(adapter);
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				abrirDetalhes(view, id);
				// Intent intent = new Intent(view.getContext(),
				// TestePutActivity.class);
				//
				// MesaModel mesaObj = adapter.getItem(idMesa);
				// String mesaGson = new Gson().toJson(mesaObj);
				// intent.putExtra("mesa", mesaGson);
				// fragment.startActivityForResult(intent, 100);

			}

			private void abrirDetalhes(View view, long id) {
				// Get List Produto from DB SQLLite
				ProdutoGenericHelper dbProduto = new ProdutoGenericHelper(
						getActivity());
				List<ProdutoModel> produtoGrupoList = dbProduto
						.selectWhere("produtoGrupoId = " + id);
				dbProduto.closeDB();

				ProdutoAdapter adapterProduto = new ProdutoAdapter(
						getActivity(), produtoGrupoList);

				mListView.setAdapter(adapterProduto);
			}
		});

		mListView.getViewTreeObserver().addOnGlobalLayoutListener(
				new ViewTreeObserver.OnGlobalLayoutListener() {
					@Override
					public void onGlobalLayout() {
						mQuickReturnHeightTop = mQuickReturnViewTop.getHeight();
						mListView.computeScrollY();
						mCachedVerticalScrollRange = mListView.getListHeight();
					}
				});

		mListView.setOnScrollListener(new OnScrollListener() {
			@SuppressLint("NewApi")
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {

				int translationY = 0;
				translationY = noAnimation(); // used
				// translationY = animation();

				/** this can be used if the build is below honeycomb **/
				if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
					animTop = new TranslateAnimation(0, 0, translationY,
							translationY);
					animTop.setFillAfter(true);
					animTop.setDuration(0);
{'fraction_non_alphanumeric': 0.10059450787958857, 'fraction_numerical': 0.0043408511842974425, 'mean_word_length': 4.855248618784531, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7318495', 'n_tokens_mistral': 3768, 'n_tokens_neox': 3184, 'n_words': 646}