Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.analogy.fragment.Fragment;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.bumptech.glide.Glide;
- import com.example.analogy.fragment.R;
- import java.util.HashMap;
- import java.util.List;
- /**
- * Created by Analogy on 4/28/2017.
- */
- public class fifthFragment extends Fragment {
- private String url = "http://192.168.1.6/dashboard/senior-project/uploads/thumbs/";
- private int countSound=0;
- private Button btnSound;
- private Sound sound = new Sound();
- static private int size=0;
- static private int index=0;
- static private List<PhotoItemDao> dao;
- static private HashMap<Integer,String> imgStep = new HashMap<>();
- static private HashMap<Integer,String> soundStep =new HashMap<>();
- static private HashMap<Integer,String> description =new HashMap<>();
- static private String albumnName = "";
- private TextView tvDescription, tvTitle;
- private ImageView ivImage, ivNext, ivBack, ivClose;
- private int sequnce=0;
- private int temp=0;
- private String temp00="";
- public HashMap<Integer, String> getImgStep() {
- return imgStep;
- }
- public void setImgStep(HashMap<Integer, String> imgStep) {
- if(fifthFragment.imgStep.size()!=0){
- }else{
- fifthFragment.imgStep = imgStep;
- }
- }
- public HashMap<Integer, String> getSoundStep() {
- return soundStep;
- }
- public List<PhotoItemDao> getDao() {
- return dao;
- }
- public void setDao(List<PhotoItemDao> dao) {
- fifthFragment.dao = dao;
- }
- public void setSoundStep(HashMap<Integer, String> soundStep) {
- fifthFragment.soundStep = soundStep;
- }
- public HashMap<Integer, String> getDescription() {
- return description;
- }
- public void setDescription(HashMap<Integer, String> description) {
- fifthFragment.description = description;
- }
- public String getAlbumnName() {
- return albumnName;
- }
- public void setAlbumnName(String albumnName) {
- fifthFragment.albumnName = albumnName;
- }
- public static fifthFragment newInstance(int someVar){
- fifthFragment fragment = new fifthFragment();
- index = someVar;
- Bundle args = new Bundle(); //argument
- args.putInt("someVar", someVar);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Toast.makeText(getContext(), "This is image albumn", Toast.LENGTH_SHORT).show();
- }
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.fragment_fifth, container, false);
- initInstances(rootView);
- return rootView;
- }
- View.OnClickListener clickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(v==ivClose){
- sound.stop();
- sequnce = 0;
- ThirdFragment thirdFragment = new ThirdFragment();
- thirdFragment.setImgStep(getImgStep());
- getFragmentManager().popBackStack();
- }
- else if(v==ivBack){
- sound.stop();
- countSound = 0;
- sequnce -= 1;
- for(PhotoItemDao p: getDao()){
- if(p.getAlbumnName().equals(getAlbumnName())){
- if(sequnce == 0) ivBack.setVisibility(View.INVISIBLE);
- ivNext.setVisibility(View.VISIBLE);
- tvTitle.setText("ขึ่นตอนที่"+(sequnce+1));
- Glide.with(getContext()).load(url+p.getStep().getAllStep().get(sequnce)).into(ivImage);
- tvDescription.setText(p.getDescription().getAllStep().get(sequnce));
- break;
- }
- }
- }
- else if(v==ivNext){
- sound.stop();
- countSound = 0;
- sequnce += 1;
- for(PhotoItemDao p: getDao()){
- if(p.getAlbumnName().equals(getAlbumnName())){
- Toast.makeText(getContext(),sequnce+"", Toast.LENGTH_SHORT).show();
- if(sequnce == p.getStep().getRealSize()-1){ ivNext.setVisibility(View.INVISIBLE);}
- ivBack.setVisibility(View.VISIBLE);
- tvTitle.setText("ขึ่นตอนที่"+(sequnce+1));
- Glide.with(getContext()).load(url+p.getStep().getAllStep().get(sequnce)).into(ivImage);
- tvDescription.setText(p.getDescription().getAllStep().get(sequnce));
- break;
- }
- }
- }
- else{
- if(soundStep.containsKey(sequnce+1)){
- if(countSound == 0){
- sound.prepareToPlay(soundStep.get(sequnce+1));
- }
- sound.playForFifth();
- countSound++;
- }
- }
- }
- };
- public void initInstances(View rootView){
- btnSound = (Button) rootView.findViewById(R.id.btnSound);
- ivClose = (ImageView) rootView.findViewById(R.id.ivClose);
- tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
- ivBack = (ImageView) rootView.findViewById(R.id.ivBack);
- ivImage = (ImageView) rootView.findViewById(R.id.ivImage);
- ivNext = (ImageView) rootView.findViewById(R.id.ivNext);
- tvDescription = (TextView) rootView.findViewById(R.id.tvDescription);
- tvTitle.setText("ขั้นตอนที่1");
- btnSound.setTag("sound");
- Glide.with(getContext()).load(url+imgStep.get(1)).into(ivImage);
- ivBack.setVisibility(View.INVISIBLE);
- //imgURL = imgStep.get(1);
- if(description.containsKey(1)){
- tvDescription.setText(description.get(1));
- }
- btnSound.setOnClickListener(clickListener);
- ivNext.setOnClickListener(clickListener);
- ivBack.setOnClickListener(clickListener);
- ivClose.setOnClickListener(clickListener);
- }
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- }
- @Override
- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- if(null != savedInstanceState){
- //
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement