Advertisement
andyshon

кривая анимация

Jan 8th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 33.43 KB | None | 0 0
  1. package com.teachme.activities.Managers.StudentViews.StudentsTasks.Fragments;
  2.  
  3. import android.animation.Animator;
  4. import android.animation.AnimatorListenerAdapter;
  5. import android.animation.ArgbEvaluator;
  6. import android.animation.ObjectAnimator;
  7. import android.animation.ValueAnimator;
  8. import android.annotation.SuppressLint;
  9. import android.graphics.drawable.AnimationDrawable;
  10. import android.graphics.drawable.ColorDrawable;
  11. import android.graphics.drawable.Drawable;
  12. import android.graphics.drawable.TransitionDrawable;
  13. import android.os.Handler;
  14. import android.support.constraint.ConstraintLayout;
  15. import android.support.v4.app.Fragment;
  16. import android.app.ProgressDialog;
  17. import android.graphics.Bitmap;
  18. import android.graphics.BitmapFactory;
  19. import android.graphics.Color;
  20. import android.os.AsyncTask;
  21. import android.os.Build;
  22. import android.os.Bundle;
  23. import android.support.annotation.NonNull;
  24. import android.support.annotation.RequiresApi;
  25. import android.util.Base64;
  26. import android.view.LayoutInflater;
  27. import android.view.View;
  28. import android.view.ViewAnimationUtils;
  29. import android.view.ViewGroup;
  30. import android.view.animation.Animation;
  31. import android.view.animation.LinearInterpolator;
  32. import android.view.animation.RotateAnimation;
  33. import android.widget.Button;
  34. import android.widget.ImageView;
  35. import android.widget.LinearLayout;
  36. import android.widget.RelativeLayout;
  37. import android.widget.TextView;
  38. import android.widget.Toast;
  39.  
  40. import com.teachme.DB.Pattern;
  41. import com.teachme.DB.PatternStudent;
  42. import com.teachme.DB.RestClient;
  43. import com.teachme.R;
  44. import com.teachme.activities.Managers.ForCheckAnswer;
  45. import com.teachme.activities.Managers.ImageManager;
  46. import com.teachme.activities.Managers.StudentViews.ShowCourseLessonStudent;
  47. import com.teachme.global.Global_config;
  48.  
  49. import org.json.JSONArray;
  50. import org.json.JSONException;
  51. import org.json.JSONObject;
  52.  
  53. import java.io.ByteArrayOutputStream;
  54. import java.util.ArrayList;
  55. import java.util.Collections;
  56. import java.util.List;
  57.  
  58. import retrofit2.Call;
  59. import retrofit2.Callback;
  60. import retrofit2.Response;
  61.  
  62. /**
  63.  * Created by andyshon on 02.01.18.
  64.  */
  65.  
  66. public class TaskStudentFindPictureFragment extends Fragment implements View.OnClickListener {
  67.  
  68.     static final String ARGUMENT_PAGE_NUMBER = "arg_page_number";
  69.  
  70.     //ConstraintLayout mainLayout;
  71.  
  72.     RestClient restClient;
  73.     public String _Pattern_Id, _Lesson_Id, lesson_title, pattern_title;
  74.     boolean swap = false;
  75.     boolean userClickedButton = false;
  76.  
  77.     Button button1, button2;
  78.     String rightAnswer, wrongAnswer1, wrongAnswer2, wrongAnswer3;
  79.     //ImageView imageView;
  80.     TextView tv_title;
  81.  
  82.     int pageNumber;
  83.     public static int backColor;
  84.  
  85.     AnimationDrawable animationDrawable;
  86.  
  87.     ProgressDialog progressDialog;
  88.  
  89.     //ImageView imageView1, imageView2, imageView3, imageView4;
  90.     Bitmap bitmap;
  91.     ImageView image, image2;
  92.  
  93.  
  94.     public TaskStudentFindPictureFragment newInstance(int page) {
  95.         System.out.println("this._Pattern_Id = " +this._Pattern_Id);
  96.  
  97.         TaskStudentFindPictureFragment taskStudentFindPictureFragment = new TaskStudentFindPictureFragment();
  98.  
  99.         Bundle arguments = new Bundle();
  100.         arguments.putInt(ARGUMENT_PAGE_NUMBER, page);
  101.         taskStudentFindPictureFragment.setArguments(arguments);
  102.  
  103.  
  104.         return taskStudentFindPictureFragment;
  105.     }
  106.  
  107.     @Override
  108.     public void onCreate(Bundle savedInstanceState) {
  109.         super.onCreate(savedInstanceState);
  110.         System.out.println("restClient is Ready!");
  111.  
  112.         pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER);
  113.     }
  114.  
  115.  
  116.  
  117.     @RequiresApi(api = Build.VERSION_CODES.M)
  118.     @Override
  119.     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  120.         System.out.println("[STUDENT MODE] : =pagenumber = " + pageNumber);
  121.         System.out.println("TASKSTUDENT choose word image!!!");
  122.  
  123.  
  124.         /* Вкладка НАЙТИ СЛОВО */
  125.         final View view = inflater.inflate(R.layout.task_student_find_picture, null);
  126.  
  127.         //mainLayout = view.findViewById(R.id.mainLayout_find_picture);
  128.         //mainLayout.setVisibility(View.INVISIBLE);
  129.  
  130.         /*btn1 = view.findViewById(R.id.btn1);
  131.         btn1.setOnClickListener(this);
  132.         btn2 = view.findViewById(R.id.btn2);
  133.         btn2.setOnClickListener(this);
  134.         btn3 = view.findViewById(R.id.btn3);
  135.         btn3.setOnClickListener(this);
  136.         btn4 = view.findViewById(R.id.btn4);
  137.         btn4.setOnClickListener(this);*/
  138.         //btnCheckTaskFindPicture = view.findViewById(R.id.btnCheckTaskFindPicture);
  139.         //btnCheckTaskFindPicture.setOnClickListener(this);
  140.  
  141.         button1 = view.findViewById(R.id.button1);
  142.         button1.setOnClickListener(this);
  143.  
  144.         button2 = view.findViewById(R.id.button2);
  145.         button2.setOnClickListener(this);
  146.  
  147.         image = view.findViewById(R.id.image);
  148.         //image.setBackgroundResource(R.drawable.ic_launcher_background);
  149.         image2 = view.findViewById(R.id.image2);
  150.  
  151.         /*imageView1 = view.findViewById(R.id.imageView1);
  152.         imageView1.setVisibility(View.VISIBLE);
  153.         imageView2 = view.findViewById(R.id.imageView2);
  154.         imageView2.setVisibility(View.VISIBLE);
  155.         imageView3 = view.findViewById(R.id.imageView3);
  156.         imageView3.setVisibility(View.VISIBLE);
  157.         imageView4 = view.findViewById(R.id.imageView4);
  158.         imageView4.setVisibility(View.VISIBLE);*/
  159.  
  160.         tv_title = view.findViewById(R.id.title);
  161.         tv_title.setTextSize(22);
  162.         tv_title.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
  163.         //imageView = view.findViewById(R.id.imageView);
  164.  
  165.         /*if (swap){
  166.             btnCheckTaskFindPicture.setBackgroundColor(Color.rgb(153, 204, 0));
  167.             btnCheckTaskFindPicture.setTextColor(Color.WHITE);
  168.             btnCheckTaskFindPicture.setText("Продолжить");
  169.         }*/
  170.  
  171.  
  172.         @SuppressLint("StaticFieldLeak")
  173.         class AsyncTaskUploadClass extends AsyncTask<Void, Void, String> {
  174.  
  175.             @Override
  176.             protected void onPreExecute() {
  177.  
  178.                 super.onPreExecute();
  179.  
  180.                 //progressDialog = ProgressDialog.show(getContext(),
  181.                 //        "Картинка загружается", "Пожалуйста подождите", false, true);
  182.             }
  183.  
  184.             @Override
  185.             protected void onPostExecute(String string1) {
  186.                 super.onPostExecute(string1);
  187.  
  188.                 //progressDialog.dismiss();
  189.  
  190.                 //Toast.makeText(getContext(), "onPostExecute", Toast.LENGTH_SHORT).show();
  191.             }
  192.  
  193.             @Override
  194.             protected String doInBackground(Void... params) {
  195.  
  196.                 // TODO: Узнать прошел ли студент это задание (isDone)
  197.                 restClient = new RestClient();
  198.                 Call<List<PatternStudent>> call0 = restClient.getService().getPatternStudentsByPatternId(_Pattern_Id);
  199.                 call0.enqueue(new Callback<List<PatternStudent>>() {
  200.                                   @Override
  201.                                   public void onResponse(@NonNull Call<List<PatternStudent>> call, @NonNull Response<List<PatternStudent>> response) {
  202.  
  203.  
  204.                                       for (int i = 0; i < response.body().size(); i++) {
  205.                                           if (response.body().get(i).getPatternId().equals(_Pattern_Id))
  206.                                               swap = response.body().get(i).getIsDone();
  207.                                       }
  208.                                       System.out.println("SWAP onStart = " + swap);
  209.                                   }
  210.  
  211.                                   @Override
  212.                                   public void onFailure(@NonNull Call<List<PatternStudent>> call, @NonNull Throwable t) {
  213.                                       Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show();
  214.  
  215.                                   }
  216.                               }
  217.                 );
  218.  
  219.                 //TODO: Получить данные задания
  220.                 restClient = new RestClient();
  221.                 Call<Pattern> call = restClient.getService().getPatternById(_Pattern_Id);
  222.                 call.enqueue(new Callback<Pattern>() {
  223.                     @Override
  224.                     public void onResponse(@NonNull Call<Pattern> call, @NonNull Response<Pattern> response) {
  225.                         Pattern pattern = response.body();
  226.  
  227.                         _Lesson_Id = pattern.getLessonId();
  228.                         pattern_title = pattern.getName();
  229.                         tv_title.setText(pattern_title);
  230.  
  231.                         System.out.println("pattern.getJsonText::" + pattern.getJsonText());
  232.  
  233.  
  234.                         String text=null;
  235.                         try {
  236.                             JSONObject jsonObject2 = new JSONObject(pattern.getJsonText());
  237.                             JSONArray jsonArray = jsonObject2.getJSONArray("FindPicture");
  238.                             JSONObject exploredObj = jsonArray.getJSONObject(0);
  239.                             text = exploredObj.getString("textMessage");
  240.                             System.out.println("String text:" + text);
  241.  
  242.                             exploredObj = jsonArray.getJSONObject(1);
  243.                             rightAnswer = exploredObj.getString("rightAnswer");
  244.                             System.out.println("rightAnswer json:" + rightAnswer);
  245.  
  246.                             exploredObj = jsonArray.getJSONObject(2);
  247.                             wrongAnswer1 = exploredObj.getString("wrongAnswer1");
  248.                             System.out.println("wrongAnswer1 json:" + wrongAnswer1);
  249.  
  250.                             exploredObj = jsonArray.getJSONObject(3);
  251.                             wrongAnswer2 = exploredObj.getString("wrongAnswer2");
  252.                             System.out.println("wrongAnswer2 json:" + wrongAnswer2);
  253.  
  254.                             exploredObj = jsonArray.getJSONObject(4);
  255.                             wrongAnswer3 = exploredObj.getString("wrongAnswer3");
  256.                             System.out.println("wrongAnswer3 json:" + wrongAnswer3);
  257.                         } catch (JSONException e) {
  258.                             e.printStackTrace();
  259.                         }
  260.  
  261.                         ArrayList<Button> buttons = new ArrayList<>();
  262.                         /*buttons.add(btn1);
  263.                         buttons.add(btn2);
  264.                         buttons.add(btn3);
  265.                         buttons.add(btn4);*/
  266.  
  267.                         /*Collections.shuffle(buttons);
  268.  
  269.                         ArrayList<String> answers = new ArrayList<>();
  270.                         answers.add(rightAnswer);
  271.                         answers.add(wrongAnswer1);
  272.                         answers.add(wrongAnswer2);
  273.                         answers.add(wrongAnswer3);
  274.  
  275.                         Collections.shuffle(answers);
  276.  
  277.                         for (int i=0; i<buttons.size(); i++){
  278.                             buttons.get(i).setText(answers.get(i));
  279.                         }*/
  280.  
  281.                         /*if (Math.random() > 0.5) {
  282.                             btn1.setText(rightAnswer);
  283.                             btn2.setText(wrongAnswer1);
  284.                             btn3.setText(wrongAnswer2);
  285.                             btn4.setText(wrongAnswer3);
  286.                         } else {
  287.                             btn1.setText(wrongAnswer1);
  288.                             btn2.setText(rightAnswer);
  289.                         }*/
  290.  
  291.                         //byte[] decodedString = Base64.decode(text, Base64.DEFAULT);
  292.                         //Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
  293.                         //System.out.println("DecodedByte onStart() = " + decodedByte);
  294.                         //imageView.setImageBitmap(decodedByte);
  295.  
  296.  
  297.                         System.out.println("BLOB GOING....");
  298.                         final ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
  299.  
  300.                         final Handler handler = new Handler();
  301.  
  302.                         System.out.println("BLOB THREAD....");
  303.                         final String finalText = text;
  304.                         Thread th = new Thread(new Runnable() {
  305.                             public void run() {
  306.  
  307.                                 try {
  308.  
  309.                                     long imageLength = 0;
  310.  
  311.                                     ImageManager.GetImage(/*image*/finalText, imageStream, imageLength);
  312.                                     System.out.println("BLOB GetImage....");
  313.  
  314.                                     handler.post(new Runnable() {
  315.  
  316.                                         public void run() {
  317.                                             byte[] buffer = imageStream.toByteArray();
  318.  
  319.                                             bitmap = BitmapFactory.decodeByteArray(buffer, 0, buffer.length);
  320.                                             System.out.println("BLOB bitmap...." + bitmap);
  321.                                             //Toast.makeText(getContext(), "Got it bitmap!", Toast.LENGTH_SHORT).show();
  322.  
  323.                                             //image.setImageBitmap(bitmap);
  324.                                             image.setImageResource(R.drawable.ic_close_white_240dp);
  325.                                             show(image);
  326.                                             //image.setImageBitmap(bitmap);
  327.                                             image2.setImageResource(R.drawable.attention512);
  328.                                             show(image2);
  329.  
  330.                                             //imageView.setImageBitmap(bitmap);
  331.  
  332.                                             //imageView1.setImageBitmap(bitmap);
  333.                                             //imageView2.setImageBitmap(bitmap);
  334.                                             //imageView3.setImageBitmap(bitmap);
  335.                                             //imageView4.setImageBitmap(bitmap);
  336.  
  337.                                             //mainLayout.setVisibility(View.VISIBLE);
  338.                                         }
  339.                                     });
  340.                                 } catch (Exception ex) {
  341.                                     final String exceptionMessage = ex.getMessage();
  342.                                     handler.post(new Runnable() {
  343.                                         public void run() {
  344.                                             Toast.makeText(getContext(), exceptionMessage, Toast.LENGTH_SHORT).show();
  345.                                         }
  346.                                     });
  347.                                 }
  348.                             }
  349.                         });
  350.                         th.start();
  351.  
  352.  
  353.                         //mainLayout.setVisibility(View.VISIBLE);
  354.                     }
  355.  
  356.                     @Override
  357.                     public void onFailure(@NonNull Call<Pattern> call, @NonNull Throwable t) {
  358.                         Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show();
  359.  
  360.                     }
  361.                 });
  362.  
  363.                 return null;
  364.             }
  365.         }
  366.         AsyncTaskUploadClass AsyncTaskUploadClassOBJ = new AsyncTaskUploadClass();
  367.         AsyncTaskUploadClassOBJ.execute();
  368.  
  369.  
  370.         //  здесь код выполняется асинхронно
  371.  
  372.         return view;
  373.     }
  374.  
  375.  
  376.     @RequiresApi(api = Build.VERSION_CODES.M)
  377.     @Override
  378.     public void onClick(View v) {
  379.         switch (v.getId()){
  380.  
  381.             case R.id.button1:
  382.                 //btnSingleEvent(button1);
  383.                 //image.setImageBitmap(bitmap);
  384.                 show(image);
  385.                 break;
  386.  
  387.             case R.id.button2:
  388.                 //btnSingleEvent(button2);
  389.                 //image.setImageBitmap(bitmap);
  390.                 show(image2);
  391.                 break;
  392.  
  393.             /*case R.id.btn1:
  394.  
  395.                 userClickedButton = true;
  396.                 btnSingleEvent(btn1);
  397.                 break;
  398.  
  399.             case R.id.btn2:
  400.  
  401.                 userClickedButton = true;
  402.                 btnSingleEvent(btn2);
  403.                 break;
  404.  
  405.             case R.id.btn3:
  406.  
  407.                 userClickedButton = true;
  408.                 btnSingleEvent(btn3);
  409.                 break;
  410.  
  411.             case R.id.btn4:
  412.  
  413.                 userClickedButton = true;
  414.                 btnSingleEvent(btn4);
  415.                 break;*/
  416.  
  417.  
  418.             /*case R.id.btnCheckTaskChooseWordImage:
  419.  
  420.                 new ForCheckAnswer().checkWholeTask(ShowCourseLessonStudent.patternsTypes.size(),
  421.                         ShowCourseLessonStudent.pager.getCurrentItem(),
  422.                         mainLayout, getContext());
  423.  
  424.                 if (!swap) {
  425.                     if (userClickedButton) {
  426.                         *//*if (btn2.getText().equals(wrongAnswer))
  427.                             btn2.setBackgroundColor(Color.RED);
  428.                         else if (btn1.getText().equals(wrongAnswer))
  429.                             btn1.setBackgroundColor(Color.RED);*//*
  430.                     }
  431.                     else {
  432.                         Toast.makeText(getContext(), "Вы не выбрали ответ!", Toast.LENGTH_SHORT).show();
  433.                     }
  434.                 }
  435.                 else {
  436.                     int itemPosition = ShowCourseLessonStudent.pager.getCurrentItem();
  437.                     ShowCourseLessonStudent.pager.setCurrentItem(itemPosition+1);
  438.                 }
  439.  
  440.                 break;*/
  441.         }
  442.     }
  443.  
  444.     // To reveal a previously invisible view using this effect:
  445.     @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  446.     private void show(final View view) {
  447.  
  448.         //final ImageView imageView = (ImageView) view;
  449.         //imageView.setImageBitmap(bitmap);
  450.  
  451.         //imageView.invalidate();
  452.  
  453.         // get the center for the clipping circle
  454.  
  455.  
  456.         int cx = (view.getLeft() + view.getRight()) / 2;
  457.         int cy = (view.getTop() + view.getBottom()) / 2;
  458.  
  459.         // get the final radius for the clipping circle
  460.         int finalRadius = Math.max(view.getWidth(), view.getHeight());
  461.  
  462.         // create the animator for this view (the start radius is zero)
  463.         Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
  464.         anim.setDuration(1000);
  465.  
  466.         // make the view visible and start the animation
  467.         //imageView.setVisibility(View.VISIBLE);
  468.  
  469.         // make the view invisible when the animation is done
  470.         /*anim.addListener(new AnimatorListenerAdapter() {
  471.             @Override
  472.             public void onAnimationEnd(Animator animation) {
  473.                 super.onAnimationEnd(animation);
  474.                 //view.setVisibility(View.INVISIBLE);
  475.                 Toast.makeText(getContext(), "TOAST", Toast.LENGTH_SHORT).show();
  476.             }
  477.         });*/
  478.  
  479.         anim.start();
  480.  
  481.  
  482.  
  483.         /*final Handler handler = new Handler();
  484.         Thread th = new Thread(new Runnable() {
  485.             public void run() {
  486.                 try {
  487.                     // get the center for the clipping circle
  488.                     int cx = (imageView.getLeft() + imageView.getRight()) / 2;
  489.                     int cy = (imageView.getTop() + imageView.getBottom()) / 2;
  490.  
  491.                     // get the final radius for the clipping circle
  492.                     int finalRadius = Math.max(imageView.getWidth(), imageView.getHeight());
  493.  
  494.                     // create the animator for this view (the start radius is zero)
  495.                     Animator anim = ViewAnimationUtils.createCircularReveal(imageView, cx, cy, 0, finalRadius);
  496.                     anim.setDuration(1500);
  497.  
  498.                     // make the view visible and start the animation
  499.                     imageView.setVisibility(View.VISIBLE);
  500.                     anim.start();
  501.  
  502.  
  503.                     handler.post(new Runnable() {
  504.                         public void run() {
  505.                             try {
  506.                                 Thread.sleep(1500);
  507.                             } catch (InterruptedException e) {
  508.                                 e.printStackTrace();
  509.                             }
  510.                             //int itemPosition = ShowCourseLessonStudent.customViewPager.getCurrentItem();
  511.                             //ShowCourseLessonStudent.customViewPager.setCurrentItem(itemPosition+1);
  512.                         }
  513.                     });
  514.                 } catch (Exception ex) {
  515.                     final String exceptionMessage = ex.getMessage();
  516.                     handler.post(new Runnable() {
  517.                         public void run() {
  518.                             Toast.makeText(getContext(), exceptionMessage, Toast.LENGTH_SHORT).show();
  519.                         }
  520.                     });
  521.                 }
  522.             }
  523.         });
  524.         th.start();*/
  525.     }
  526.  
  527.     @RequiresApi(api = Build.VERSION_CODES.M)
  528.     private void btnSingleEvent(Button button){
  529.  
  530.         Button btn = button;
  531.  
  532.         //if (btn.getId() == R.id.button1){
  533.             //image = getView().findViewById(R.id.image);
  534.             //image.setBackgroundResource(R.drawable.ic_launcher_background);
  535.             image.setImageBitmap(bitmap);
  536.  
  537.             int cx = (image.getLeft() + image.getRight()) / 2;
  538.             int cy = (image.getTop() + image.getBottom()) / 2;
  539.  
  540.             // get the final radius for the clipping circle
  541.             int finalRadius = Math.max(image.getWidth(), image.getHeight());
  542.  
  543.             // create the animator for this view (the start radius is zero)
  544.             Animator anim = ViewAnimationUtils.createCircularReveal(image, cx, cy, 0, finalRadius);
  545.             anim.setDuration(1000);
  546.  
  547.             anim.start();
  548.         //}
  549.         /*else if (btn.getId() == R.id.button2){
  550.             image = getView().findViewById(R.id.image2);
  551.             image.setBackgroundResource(R.drawable.ic_close_white_240dp);
  552.  
  553.             int cx = (image.getLeft() + image.getRight()) / 2;
  554.             int cy = (image.getTop() + image.getBottom()) / 2;
  555.  
  556.             // get the final radius for the clipping circle
  557.             int finalRadius = Math.max(image.getWidth(), image.getHeight());
  558.  
  559.             // create the animator for this view (the start radius is zero)
  560.             Animator anim = ViewAnimationUtils.createCircularReveal(image, cx, cy, 0, finalRadius);
  561.             anim.setDuration(1000);
  562.  
  563.             anim.start();
  564.         }*/
  565.  
  566.         /*ImageView image1 = new ImageView(getContext());
  567.  
  568.         image1.setLeft(btn.getLeft());
  569.         image1.setRight(btn.getRight());
  570.         image1.setTop(btn.getTop());
  571.         image1.setBottom(btn.getBottom());
  572.  
  573.         image1.setMaxWidth(500);
  574.         image1.setMaxHeight(500);*/
  575.  
  576.  
  577.         //image.setImageBitmap(bitmap);
  578.  
  579.  
  580.         //image1.setLayoutParams(new android.view.ViewGroup.LayoutParams(500,500));
  581.         //mainLayout.addView(image1);
  582.  
  583.         //show(image1);
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.         //LinearLayout layout = new LinearLayout(getContext());
  591.         //layout.setOrientation(LinearLayout.VERTICAL);
  592.  
  593. // TODO: Set attributes for layout
  594. // i.e. RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
  595. // layout.setLayoutParams(params);
  596.  
  597.         //ImageView imageView1 = new ImageView(getContext());
  598.         //imageView1.setLeft(100);
  599.         //image1.setLeft(btn3.getLeft());
  600.         //image1.setRight(btn3.getRight());
  601.         //image1.setTop(btn3.getTop());
  602.         //image1.setBottom(btn3.getBottom());
  603.  
  604.         //image1.setMaxWidth(500);
  605.         //image1.setMaxHeight(500);
  606.         //imageView1.setBackgroundResource(R.drawable.ic_launcher_background);
  607.  
  608.         //ImageView imageView2 = new ImageView(getContext());
  609.         //imageView2.setLeft(500);
  610.         //imageView2.setBackgroundResource(R.drawable.ic_close_white_240dp);
  611.  
  612. // TODO: Set LayoutParams for each imageView
  613. // i.e. RelativeLayout.LayoutParams imageParams1 = new RelativeLayout.LayoutParams(imageWidth, imageHeight);
  614. // imageParams1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
  615. // imageParams1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
  616.  
  617.         //ViewGroup.LayoutParams layoutParams2 = new ViewGroup.LayoutParams(500,500);
  618.  
  619.  
  620.         //layout.addView(imageView1, layoutParams2);
  621.         //layout.addView(imageView2, layoutParams2);
  622.  
  623.  
  624.         //mainLayout.addView(layout);
  625.  
  626.  
  627.         /*show(imageView1);
  628.         int cx2 = (imageView1.getLeft() + imageView1.getRight()) / 2;
  629.         int cy2 = (imageView1.getTop() + imageView1.getBottom()) / 2;
  630.  
  631.         // get the final radius for the clipping circle
  632.         int finalRadius2 = Math.max(imageView1.getWidth(), imageView1.getHeight());
  633.  
  634.         // create the animator for this view (the start radius is zero)
  635.         Animator anim2 = ViewAnimationUtils.createCircularReveal(imageView1, cx, cy, 0, finalRadius);
  636.         anim2.setDuration(1000);
  637.  
  638.         anim2.start();
  639.  
  640.         show(imageView2);
  641.         int cx3 = (imageView2.getLeft() + imageView2.getRight()) / 2;
  642.         int cy3 = (imageView2.getTop() + imageView2.getBottom()) / 2;
  643.  
  644.         // get the final radius for the clipping circle
  645.         int finalRadius3 = Math.max(imageView2.getWidth(), imageView2.getHeight());
  646.  
  647.         // create the animator for this view (the start radius is zero)
  648.         Animator anim3 = ViewAnimationUtils.createCircularReveal(imageView2, cx, cy, 0, finalRadius);
  649.         anim3.setDuration(1000);
  650.  
  651.         anim3.start();*/
  652.  
  653.  
  654. //        RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
  655. //        anim.setInterpolator(new LinearInterpolator());
  656. //        anim.setRepeatCount(Animation.INFINITE);
  657. //        anim.setDuration(700);
  658. //
  659. //        image1.startAnimation(anim);
  660.  
  661.  
  662.         button.setVisibility(View.INVISIBLE);
  663.  
  664.  
  665.  
  666.  
  667.  
  668.         int id = button.getId();
  669.  
  670.         /*if (id == R.id.btn1){
  671.  
  672.             System.out.println("BTN 1");
  673.  
  674.             int shelfHeight = btn1.getHeight();
  675.             int shelfWidth = btn1.getWidth();
  676.             int shelfTop = btn1.getTop();
  677.             int shelfLeft = btn1.getLeft();
  678.             int shelfBottom = btn1.getBottom();
  679.             int shelfRight = btn1.getRight();
  680.  
  681.             ImageView image = new ImageView(getActivity());
  682.  
  683.             image.setLeft(shelfLeft);
  684.             image.setRight(shelfRight);
  685.             image.setTop(shelfTop);
  686.             image.setBottom(shelfBottom);
  687.  
  688.             image.setMaxWidth(shelfWidth+100);
  689.             image.setMaxWidth(shelfHeight+100);
  690.             image.setVisibility(View.VISIBLE);
  691.  
  692.             image.setImageBitmap(bitmap);
  693.  
  694.  
  695.             System.out.println("IMAGE! = " + image.getDrawable() + " " + image.getRight());
  696.  
  697.             mainLayout.addView(image);
  698.  
  699.             //image.invalidate();
  700.             show(image);
  701.  
  702.  
  703.             button.setVisibility(View.INVISIBLE);
  704.             //imageView1.setImageBitmap(bitmap);
  705.             //show(imageView1);
  706.         }
  707.         if (id == R.id.btn2){
  708.  
  709.             System.out.println("BTN 2");
  710.  
  711.             int shelfHeight = btn2.getHeight()+250;
  712.             int shelfWidth = btn2.getWidth()+250;
  713.             int shelfTop = btn2.getTop();
  714.             int shelfLeft = btn2.getLeft()+250;
  715.             int shelfBottom = btn2.getBottom();
  716.             int shelfRight = btn2.getRight()+250;
  717.  
  718.             ImageView image = new ImageView(getActivity());
  719.  
  720.             image.setLeft(shelfLeft);
  721.             image.setRight(shelfRight);
  722.             image.setTop(shelfTop);
  723.             image.setBottom(shelfBottom);
  724.  
  725.             image.setMaxWidth(shelfWidth);
  726.             image.setMaxWidth(shelfHeight);
  727.             image.setVisibility(View.VISIBLE);
  728.  
  729.             image.setImageBitmap(bitmap);
  730.  
  731.  
  732.             System.out.println("IMAGE! = " + image.getDrawable() + " " + image.getRight());
  733.  
  734.             ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(1000,1000);
  735.  
  736.  
  737.             mainLayout.addView(image, layoutParams);
  738.  
  739.             //image.invalidate();
  740.             show(image);
  741.  
  742.             btn1.setVisibility(View.INVISIBLE);
  743.             button.setVisibility(View.INVISIBLE);
  744.             //imageView2.setImageBitmap(bitmap);
  745.             //show(imageView2);
  746.         }
  747.         if (id == R.id.btn3){
  748.             button.setVisibility(View.INVISIBLE);
  749.             //imageView3.setImageBitmap(bitmap);
  750.             //show(imageView3);
  751.         }
  752.         if (id == R.id.btn4){
  753.             button.setVisibility(View.INVISIBLE);
  754.             //imageView4.setImageBitmap(bitmap);
  755.             //show(imageView4);
  756.         }*/
  757.  
  758.         if (button.getText().equals(/*rightAnswer*/"Dd")){
  759.  
  760.             int id2 = button.getId();
  761.  
  762.             /*if (id2 == R.id.btn1){
  763.                 button.setVisibility(View.INVISIBLE);
  764.                 //imageView1.setImageBitmap(bitmap);
  765.                 //show(imageView1);
  766.             }
  767.             if (id2 == R.id.btn2){
  768.                 button.setVisibility(View.INVISIBLE);
  769.                 //imageView2.setImageBitmap(bitmap);
  770.                 //show(imageView2);
  771.             }
  772.             if (id2 == R.id.btn3){
  773.                 button.setVisibility(View.INVISIBLE);
  774.                 //imageView3.setImageBitmap(bitmap);
  775.                 //show(imageView3);
  776.             }
  777.             if (id2 == R.id.btn4){
  778.                 button.setVisibility(View.INVISIBLE);
  779.                 //imageView4.setImageBitmap(bitmap);
  780.                 //show(imageView4);
  781.             }*/
  782.  
  783.             //button.setVisibility(View.INVISIBLE);
  784.  
  785.  
  786.             /*btnCheckTaskFindPicture.setBackgroundColor(Color.rgb(153, 204, 0));
  787.             btnCheckTaskFindPicture.setTextColor(Color.WHITE);
  788.             btnCheckTaskFindPicture.setText("Продолжить");*/
  789.  
  790.             //Toast.makeText(getContext(), "Правильно!", Toast.LENGTH_SHORT).show();
  791.  
  792.             //TODO: сохранить в бд в таблицу PatternStudent ид задания, ид студента и isDone = true
  793.  
  794.             /*PatternStudent patternstudent = new PatternStudent();
  795.             patternstudent.setUserId(Global_config._USER_ID_CUR);
  796.             patternstudent.setStudentAnswer("no answer");
  797.             patternstudent.setIsDone(true);
  798.             patternstudent.setPatternId(_Pattern_Id);
  799.             System.out.println("_Pattern_Id ====" + _Pattern_Id);
  800.  
  801.             restClient.getService().addPatternStudent(patternstudent).enqueue(new Callback<PatternStudent>() {
  802.                 @Override
  803.                 public void onResponse(@NonNull Call<PatternStudent> call, @NonNull Response<PatternStudent> response) {
  804.                     if (response.code() == 201) {
  805.                         //Toast.makeText(getContext(), "New PatternStudent Registered.", Toast.LENGTH_LONG).show();
  806.                     } else {
  807.                         Toast.makeText(getContext(), "Not Created:" + response.errorBody(), Toast.LENGTH_LONG).show();
  808.                     }
  809.                 }
  810.  
  811.                 @Override
  812.                 public void onFailure(@NonNull Call<PatternStudent> call, @NonNull Throwable t) {
  813.                     Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_LONG).show();
  814.                 }
  815.             });*/
  816.  
  817.             swap = true;
  818.         }
  819.         else {
  820.             swap = false;
  821.  
  822.             //AnimationDrawable animationDrawable = (AnimationDrawable) button.getBackground();
  823.             //animationDrawable.start();
  824.  
  825.             //Drawable drawable = button.getBackground();
  826.             //int c = button.getDrawingCacheBackgroundColor();
  827.             //System.out.println("color = " + c);
  828.             //ColorDrawable initialColor = new ColorDrawable(Color.parseColor(String.valueOf(button.getDrawingCacheBackgroundColor())));
  829.             //Drawable initialColor = (Drawable) button.getBackground();
  830.  
  831.             //Button button1 = new Button(getContext());
  832.             //System.out.println("button1.getSolidColor(); = " + button1.getSolidColor());
  833.  
  834.             //int colorId = initialColor.getColor();
  835.             ColorDrawable lightRed = new ColorDrawable(Color.parseColor("#FFF97981"));
  836.             ColorDrawable initialColor = new ColorDrawable(Color.LTGRAY);
  837.             ColorDrawable[] color = {initialColor, lightRed};
  838.             /*ColorDrawable[] color = {
  839.                     new ColorDrawable(Color.parseColor("#fa0707")),
  840.                     new ColorDrawable(Color.parseColor("#3507fa")),
  841.                     new ColorDrawable(Color.parseColor("#07faec")),
  842.                     new ColorDrawable(Color.parseColor("#faec07"))
  843.             };*/
  844.             TransitionDrawable trans = new TransitionDrawable(color);
  845.             button.setBackground(trans);
  846.             trans.startTransition(300); // duration 3 seconds
  847.  
  848.             //overridePendingTransition(R.anim.animation_enter, R.anim.animation_leave);
  849.  
  850.  
  851.  
  852.             /*int colorStart = button.getSolidColor();
  853.             int colorEnd = 0xFFFF0000;
  854.  
  855.             ValueAnimator colorAnim = ObjectAnimator.ofInt(button,
  856.                     "backgroundColor", colorStart, colorEnd);
  857.  
  858.             colorAnim.setDuration(1000);
  859.             colorAnim.setEvaluator(new ArgbEvaluator());
  860.             colorAnim.setRepeatCount(1);
  861.             colorAnim.setRepeatMode(ValueAnimator.REVERSE);
  862.             colorAnim.start();*/
  863.  
  864.             //button.setBackgroundColor(Color.RED);
  865.  
  866.             /*if (btn1.getText().equals(wrongAnswer))
  867.                 btn1.setBackgroundColor(Color.RED);
  868.             else
  869.                 btn2.setBackgroundColor(Color.RED);*/
  870.         }
  871.     }
  872. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement