Advertisement
aunkang

FifthFragment.java

May 18th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.00 KB | None | 0 0
  1. package com.example.analogy.fragment.Fragment;
  2.  
  3. import android.os.Bundle;
  4. import android.support.annotation.Nullable;
  5. import android.support.v4.app.Fragment;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.Button;
  10. import android.widget.ImageView;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14. import com.bumptech.glide.Glide;
  15. import com.example.analogy.fragment.R;
  16.  
  17. import java.util.HashMap;
  18. import java.util.List;
  19.  
  20. /**
  21.  * Created by Analogy on 4/28/2017.
  22.  */
  23.  
  24. public class fifthFragment extends Fragment {
  25.     private String url = "http://192.168.1.6/dashboard/senior-project/uploads/thumbs/";
  26.     private int countSound=0;
  27.     private Button btnSound;
  28.     private Sound sound = new Sound();
  29.     static private int size=0;
  30.     static private int index=0;
  31.     static private List<PhotoItemDao> dao;
  32.     static private HashMap<Integer,String> imgStep = new HashMap<>();
  33.     static private HashMap<Integer,String> soundStep =new HashMap<>();
  34.     static private HashMap<Integer,String> description =new HashMap<>();
  35.     static  private String albumnName = "";
  36.     private TextView  tvDescription, tvTitle;
  37.     private ImageView ivImage, ivNext, ivBack, ivClose;
  38.     private int sequnce=0;
  39.     private int temp=0;
  40.     private String temp00="";
  41.  
  42.     public HashMap<Integer, String> getImgStep() {
  43.         return imgStep;
  44.     }
  45.  
  46.     public void setImgStep(HashMap<Integer, String> imgStep) {
  47.         if(fifthFragment.imgStep.size()!=0){
  48.  
  49.         }else{
  50.             fifthFragment.imgStep = imgStep;
  51.         }
  52.  
  53.  
  54.     }
  55.  
  56.     public HashMap<Integer, String> getSoundStep() {
  57.         return soundStep;
  58.     }
  59.  
  60.     public List<PhotoItemDao> getDao() {
  61.         return dao;
  62.     }
  63.  
  64.     public void setDao(List<PhotoItemDao> dao) {
  65.         fifthFragment.dao = dao;
  66.     }
  67.  
  68.     public void setSoundStep(HashMap<Integer, String> soundStep) {
  69.         fifthFragment.soundStep = soundStep;
  70.     }
  71.  
  72.     public HashMap<Integer, String> getDescription() {
  73.         return description;
  74.     }
  75.  
  76.     public void setDescription(HashMap<Integer, String> description) {
  77.         fifthFragment.description = description;
  78.     }
  79.  
  80.  
  81.  
  82.     public String getAlbumnName() {
  83.         return albumnName;
  84.     }
  85.  
  86.     public void setAlbumnName(String albumnName) {
  87.         fifthFragment.albumnName = albumnName;
  88.     }
  89.  
  90.     public static fifthFragment newInstance(int someVar){
  91.         fifthFragment fragment = new fifthFragment();
  92.         index = someVar;
  93.         Bundle args = new Bundle(); //argument
  94.         args.putInt("someVar", someVar);
  95.         fragment.setArguments(args);
  96.         return fragment;
  97.     }
  98.  
  99.     @Override
  100.     public void onCreate(@Nullable Bundle savedInstanceState) {
  101.         super.onCreate(savedInstanceState);
  102.  
  103.         Toast.makeText(getContext(), "This is image albumn", Toast.LENGTH_SHORT).show();
  104.  
  105.     }
  106.  
  107.     @Nullable
  108.     @Override
  109.     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  110.  
  111.         View rootView = inflater.inflate(R.layout.fragment_fifth, container, false);
  112.  
  113.         initInstances(rootView);
  114.  
  115.         return rootView;
  116.  
  117.  
  118.     }
  119.  
  120.     View.OnClickListener clickListener = new View.OnClickListener() {
  121.         @Override
  122.         public void onClick(View v) {
  123.  
  124.             if(v==ivClose){
  125.                 sound.stop();
  126.                 sequnce = 0;
  127.                 ThirdFragment thirdFragment = new ThirdFragment();
  128.                 thirdFragment.setImgStep(getImgStep());
  129.                 getFragmentManager().popBackStack();
  130.             }
  131.             else if(v==ivBack){
  132.                 sound.stop();
  133.                 countSound = 0;
  134.                 sequnce -= 1;
  135.                 for(PhotoItemDao p: getDao()){
  136.                     if(p.getAlbumnName().equals(getAlbumnName())){
  137.                         if(sequnce == 0) ivBack.setVisibility(View.INVISIBLE);
  138.                         ivNext.setVisibility(View.VISIBLE);
  139.                         tvTitle.setText("ขึ่นตอนที่"+(sequnce+1));
  140.                         Glide.with(getContext()).load(url+p.getStep().getAllStep().get(sequnce)).into(ivImage);
  141.                         tvDescription.setText(p.getDescription().getAllStep().get(sequnce));
  142.                         break;
  143.                     }
  144.                 }
  145.             }
  146.             else if(v==ivNext){
  147.                 sound.stop();
  148.                 countSound = 0;
  149.                 sequnce += 1;
  150.                 for(PhotoItemDao p: getDao()){
  151.                     if(p.getAlbumnName().equals(getAlbumnName())){
  152.                         Toast.makeText(getContext(),sequnce+"", Toast.LENGTH_SHORT).show();
  153.                         if(sequnce == p.getStep().getRealSize()-1){ ivNext.setVisibility(View.INVISIBLE);}
  154.                         ivBack.setVisibility(View.VISIBLE);
  155.                         tvTitle.setText("ขึ่นตอนที่"+(sequnce+1));
  156.                         Glide.with(getContext()).load(url+p.getStep().getAllStep().get(sequnce)).into(ivImage);
  157.                         tvDescription.setText(p.getDescription().getAllStep().get(sequnce));
  158.                         break;
  159.                     }
  160.                 }
  161.             }
  162.             else{
  163.                 if(soundStep.containsKey(sequnce+1)){
  164.                     if(countSound == 0){
  165.                         sound.prepareToPlay(soundStep.get(sequnce+1));
  166.                     }
  167.                     sound.playForFifth();
  168.                     countSound++;
  169.                 }
  170.             }
  171.         }
  172.     };
  173.     public void initInstances(View rootView){
  174.         btnSound = (Button) rootView.findViewById(R.id.btnSound);
  175.         ivClose = (ImageView) rootView.findViewById(R.id.ivClose);
  176.         tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
  177.         ivBack = (ImageView) rootView.findViewById(R.id.ivBack);
  178.         ivImage = (ImageView) rootView.findViewById(R.id.ivImage);
  179.         ivNext = (ImageView) rootView.findViewById(R.id.ivNext);
  180.         tvDescription = (TextView) rootView.findViewById(R.id.tvDescription);
  181.         tvTitle.setText("ขั้นตอนที่1");
  182.         btnSound.setTag("sound");
  183.         Glide.with(getContext()).load(url+imgStep.get(1)).into(ivImage);
  184.         ivBack.setVisibility(View.INVISIBLE);
  185.         //imgURL = imgStep.get(1);
  186.         if(description.containsKey(1)){
  187.             tvDescription.setText(description.get(1));
  188.         }
  189.         btnSound.setOnClickListener(clickListener);
  190.         ivNext.setOnClickListener(clickListener);
  191.         ivBack.setOnClickListener(clickListener);
  192.         ivClose.setOnClickListener(clickListener);
  193.  
  194.     }
  195.  
  196.     @Override
  197.     public void onSaveInstanceState(Bundle outState) {
  198.         super.onSaveInstanceState(outState);
  199.     }
  200.  
  201.     @Override
  202.     public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  203.         super.onActivityCreated(savedInstanceState);
  204.         if(null != savedInstanceState){
  205.             //
  206.         }
  207.     }
  208.  
  209.  
  210.  
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement