daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MyFragment extends Fragment {
  2.  
  3.     private Context context;
  4.     private LayoutInflater layoutInflater;
  5.     private ImageView proximo;
  6.     private ImageView anterior;
  7.     private static Promocao[] promocoes;
  8.     private MainActivity mainActivity;
  9.  
  10.     public static Fragment newInstance(MainActivity context, int pos, float scale, Promocao[] promocaoParametro) {
  11.         Bundle b = new Bundle();
  12.         b.putInt("pos", pos);
  13.         b.putFloat("scale", scale);
  14.         promocoes=promocaoParametro;
  15.  
  16.         Log.i(TAG, "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
  17.         Log.i(TAG, "newInstance: pos ---> "+pos);
  18.         Log.i(TAG, "newInstance: scale ---> "+scale);
  19.         Log.i(TAG, "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
  20.  
  21.         return Fragment.instantiate(context, MyFragment.class.getName(), b);
  22.     }
  23.  
  24.     @Override
  25.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  26.                              Bundle savedInstanceState) {
  27.         if (container == null) {
  28.             return null;
  29.         }
  30.  
  31.  
  32.  
  33.         LinearLayout view = (LinearLayout)
  34.                 inflater.inflate(R.layout.mf, container, false);
  35.  
  36.  
  37.         String valordesconto = "";
  38.         SpannableStringBuilder valorDeTextoEditado;
  39.  
  40.  
  41.         TextView titulo             = (TextView)  view.findViewById(R.id.titulo);
  42.         TextView informacao         = (TextView)  view.findViewById(R.id.informacao);
  43.         TextView bairro             = (TextView)  view.findViewById(R.id.bairro);
  44.         TextView valorDe            = (TextView)  view.findViewById(R.id.valorDe);
  45.         TextView valorPara          = (TextView)  view.findViewById(R.id.valorPara);
  46.         TextView resumoOferta       = (TextView)  view.findViewById(R.id.resumoOferta);
  47.         ImageView imageCliente      = (ImageView) view.findViewById(R.id.imageCliente);
  48.         ImageView imagemPromocao    = (ImageView) view.findViewById(R.id.imagemPromocao);
  49.         LinearLayout fundoLayout    = (LinearLayout) view.findViewById(R.id.fundoLayout);
  50.  
  51.         final int position = this.getArguments().getInt("pos");
  52.  
  53.         if(this.promocoes[position].vlreal > 0){
  54.  
  55.             String textoDe ="R$ ";
  56.             String valorDeTexto = String.format("%.2f",this.promocoes[position].vlreal);
  57.             StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
  58.             SpannableStringBuilder ssb = new SpannableStringBuilder(textoDe);
  59.  
  60.             ssb.append(valorDeTexto);
  61.  
  62.             ssb.setSpan(
  63.                     strikethroughSpan,
  64.                     ssb.length() - valorDeTexto.length(),
  65.                     ssb.length(),
  66.                     Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  67.  
  68.             valorDeTextoEditado = ssb;
  69.  
  70.             double valorcalc = this.promocoes[position].vlreal - (this.promocoes[position].vlreal * this.promocoes[position].desconto / 100);
  71.             valordesconto = "R$ "+String.format("%.2f",valorcalc);
  72.  
  73.  
  74.  
  75.         }else{
  76.  
  77.             valorDeTextoEditado = SpannableStringBuilder.valueOf("");
  78.             valordesconto = String.valueOf(this.promocoes[position].desconto) + "%";
  79.  
  80.             valorDe.setVisibility(View.INVISIBLE);
  81.             valorPara.setTextSize(200);
  82.  
  83.             ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) valorPara.getLayoutParams();
  84.             ViewGroup.LayoutParams paramsde = (ViewGroup.LayoutParams) valorDe.getLayoutParams();
  85.  
  86.  
  87.             params.height = 250;
  88.             valorPara.setLayoutParams(params);
  89.  
  90.             paramsde.height = 1;
  91.             valorDe.setLayoutParams(paramsde);
  92.  
  93.         }
  94.  
  95.         BitmapDrawable background = new BitmapDrawable(this.promocoes[position].imagemByte);
  96.         fundoLayout.setBackgroundDrawable(background);
  97.         fundoLayout.getBackground().setAlpha(32);
  98.  
  99.         titulo.setText(this.promocoes[position].titulo);
  100.         informacao.setText(this.promocoes[position].informacao);
  101.         bairro.setText(this.promocoes[position].bairro);
  102.         valorDe.setText(valorDeTextoEditado, TextView.BufferType.EDITABLE);
  103.         valorPara.setText(valordesconto);
  104.         resumoOferta.setText(this.promocoes[position].resumooferta);
  105.         imageCliente.setImageBitmap(this.promocoes[position].logoByte);
  106.         imagemPromocao.setImageBitmap(this.promocoes[position].imagemByte);
  107.  
  108.  
  109.         Button b = (Button) view.findViewById(R.id.btnComprar);
  110.         proximo  = (ImageView) view.findViewById(R.id.btn_proximo);
  111.         anterior = (ImageView) view.findViewById(R.id.btn_voltar);
  112.  
  113.  
  114.         final ViewPager viewPager = (ViewPager)getActivity().findViewById(R.id.myviewpager);
  115.         mainActivity = new MainActivity();
  116.  
  117.         b.setOnClickListener(new View.OnClickListener() {
  118.             @Override
  119.             public void onClick(View v) {
  120.  
  121.                 ArrayList<String> ar = new ArrayList<String>();
  122.  
  123.                 ar.add(String.valueOf(promocoes[position].idpromocao));
  124.  
  125.  
  126.                 Intent telefone = new Intent(v.getContext(),Telefone.class );
  127.                 telefone.putStringArrayListExtra("list",ar);
  128.                 v.getContext().startActivity(telefone);
  129.                 //Log.i(txtTitulo, txtTitulo);
  130.  
  131.             }
  132.         });
  133.  
  134.         proximo.setOnClickListener(new View.OnClickListener(){
  135.             public void onClick(View v ){
  136.                 ----- Aqui da direta para a esquerda
  137.             }
  138.  
  139.         });
  140.  
  141.         anterior.setOnClickListener(new View.OnClickListener(){
  142.             public void onClick(View v ){
  143.                 ----- Aqui da esquerda para a direta
  144.  
  145.             }
  146.  
  147.         });
  148.  
  149.  
  150.  
  151.  
  152.         MyLinearLayout root = (MyLinearLayout) view.findViewById(R.id.root);
  153.         float scale = this.getArguments().getFloat("scale");
  154.         root.setScaleBoth(scale);
  155.  
  156.         return view;
  157.     }
  158.  
  159. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top