Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.analogy.fragment.Fragment;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.bumptech.glide.Glide;
- import com.example.analogy.fragment.R;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.List;
- /**
- * Created by Analogy on 4/26/2017.
- */
- public class ThirdFragment extends Fragment{
- private String url = "http://192.168.1.6/dashboard/senior-project/uploads/thumbs/";
- private String urlSound = "http://192.168.1.6/dashboard/senior-project/uploads/audios/";
- String tempUrl="";
- private ImageView back, backHome;
- private ImageView showAll;
- private Sound sound = new Sound();
- private int countClick=0;
- private HashMap<Integer,String> imgStep = new HashMap<>();
- private HashMap<Integer,String> soundStep =new HashMap<>();
- private HashMap<Integer,String> description =new HashMap<>();
- static private String albumnName = "";
- static private List<PhotoItemDao> dao;
- private TextView tvTitle;
- private ImageView ivImg1,ivImg2,ivImg3,ivImg4,ivImg5,ivImg6,ivImg7,ivImg8,ivImg9,ivImg10;
- private int index=0;
- public static List<PhotoItemDao> getDao() {
- return dao;
- }
- public static void setDao(List<PhotoItemDao> dao) {
- ThirdFragment.dao = dao;
- }
- public static ThirdFragment newInstance(String someVar){
- ThirdFragment fragment = new ThirdFragment();
- albumnName = someVar;
- Bundle args = new Bundle(); //argument
- args.putString("someVar", someVar);
- fragment.setArguments(args);
- return fragment;
- }
- public HashMap<Integer, String> getImgStep() {
- return imgStep;
- }
- public void setImgStep(HashMap<Integer, String> imgStep) {
- this.imgStep = imgStep;
- }
- @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_third, container, false);
- initInstances(rootView);
- return rootView;
- }
- View.OnClickListener clickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(v == back){
- getFragmentManager().popBackStack();
- try {
- sound.pause();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else if(v == backHome){
- getFragmentManager().popBackStack(null, getFragmentManager().POP_BACK_STACK_INCLUSIVE);
- try {
- sound.pause();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- else if(v == showAll){
- fifthFragment fifthFragment = new fifthFragment();
- fifthFragment.setDao(getDao());
- fifthFragment.setAlbumnName(albumnName);
- fifthFragment.setImgStep(getImgStep());
- fifthFragment.setSoundStep(soundStep);
- fifthFragment.setDescription(description);
- getActivity().getSupportFragmentManager().beginTransaction()
- .add(R.id.contentContainer, fifthFragment.newInstance(index))
- .addToBackStack(null)
- .commit();
- }
- else{
- Button button = (Button) v;
- if(countClick>0){
- try {
- sound.pause();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(tempUrl.equals((button.getText().toString()))){
- sound.restart();
- countClick++;
- }
- else if(tempUrl.equals("")){
- tempUrl = button.getText().toString();
- sound.prepareToPlay(button.getText().toString());
- sound.play();
- countClick++;
- }
- else if(!tempUrl.equals((button.getText().toString()))){
- tempUrl = button.getText().toString();
- sound.prepareToPlay(button.getText().toString());
- sound.play();
- countClick++;
- }
- }
- /*if(v.getTag().toString().equals("sound")){
- Button b = (Button) v;
- if(countClick>0){
- try {
- sound.pause();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- sound.prepareToPlay(b.getText().toString());
- sound.play();
- countClick++;
- }*/
- }
- };
- public void initInstances(final View rootView){
- back = (ImageView) rootView.findViewById(R.id.back);
- backHome = (ImageView) rootView.findViewById(R.id.back_home);
- showAll = (ImageView) rootView.findViewById(R.id.showAll);
- showAll.setOnClickListener(clickListener);
- tvTitle = (TextView) rootView.findViewById(R.id.tvTitle);
- tvTitle.setText(albumnName);
- for(int i=0;i<getDao().size();i++){
- if(albumnName.equals(getDao().get(i).getAlbumnName())){
- index = i;
- break;
- }
- }
- back.setOnClickListener(clickListener);
- backHome.setOnClickListener(clickListener);
- List<String> temp;
- temp = getDao().get(index).getStep().getAllStep();
- int count=0;
- for(String img : temp){
- count++;
- if(!img.equals("") || !img.isEmpty()){
- imgStep.put(count, img);
- }
- }
- temp = getDao().get(index).getSoundStep().getAllStep();
- count=0;
- for(String img : temp){
- count++;
- if(!img.equals("")){
- soundStep.put(count, img);
- }
- }
- temp = getDao().get(index).getDescription().getAllStep();
- count=0;
- for(String img : temp){
- count++;
- if(!img.equals("")){
- description.put(count, img);
- }
- }
- count=0;
- int x=0;
- for(int i=0;i<=imgStep.size();i++){
- while(true){
- x++;
- if(imgStep.containsKey(x)){
- LinearLayout container = (LinearLayout)rootView.findViewById(R.id.contentContainer);
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
- );
- String temp2 = "ivImg" + x;
- TextView tv = new TextView(getContext());
- tv.setText("ขั้นตอนที่"+x);
- tv.setTextSize(25);
- tv.setTextColor(Color.BLACK);
- tv.setBackgroundColor(Color.parseColor("#FFEBBE"));
- lp.gravity = Gravity.CENTER;
- container.addView(tv, lp);
- lp = new LinearLayout.LayoutParams(300,300);
- //get url image here
- ImageView img = new ImageView(getContext());
- Image imgLaod = new Image();
- lp.gravity = Gravity.CENTER;
- container.addView(img, lp);
- Glide.with(getContext()).load(url+imgStep.get(x)).into(img);
- Toast.makeText(getContext(),url+imgStep.get(x),Toast.LENGTH_SHORT ).show();
- if(description.containsKey(x)){
- Toast.makeText(getContext(),description.get(x), Toast.LENGTH_LONG).show();
- lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
- );
- tv = new TextView(getContext());
- tv.setText(description.get(x));
- lp.gravity = Gravity.CENTER;
- lp.setMargins(0,0,0,50);
- container.addView(tv, lp);
- }
- if(soundStep.containsKey(x)){
- lp = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT,
- LinearLayout.LayoutParams.WRAP_CONTENT
- );
- lp.gravity = Gravity.CENTER;
- lp.setMargins(0,0,0,200);
- Button btn = new Button(getContext());
- //get url sound here
- btn.setText(soundStep.get(x));
- btn.setTextSize(0);
- btn.setTag("sound");
- btn.setOnClickListener(clickListener);
- container.addView(btn, lp);
- }
- }
- break;
- }
- }
- }
- @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