Guest User

fd

a guest
Feb 23rd, 2016
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1.  
  2. import android.app.Fragment;
  3. import android.content.res.Resources;
  4. import android.graphics.Color;
  5. import android.os.Bundle;
  6. import android.support.v4.app.FragmentTransaction;
  7. import android.util.Log;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.RadioButton;
  12. import android.widget.TextView;
  13. import java.util.Random;
  14.  
  15. public class TemperFragment extends android.support.v4.app.Fragment {
  16.  
  17.     private TextView question;
  18.     private RadioButton first, second, third;
  19.     private TextView textdata;
  20.     private int page;
  21.     private TextView textindicator;
  22.     private String answers1[],answers2[],answers3[],answers4[],answers5[],answers6[];
  23.     private String questions[];
  24.  
  25.     @Override
  26.     public void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         Resources  res = getResources();
  29.         questions = res.getStringArray(R.array.test_questions);
  30.        
  31.         answers1 = res.getStringArray(R.array.answers_one);
  32.         answers2 = res.getStringArray(R.array.answers_two);
  33.         answers3 = res.getStringArray(R.array.answers_three);
  34.         answers4 = res.getStringArray(R.array.answers_four);
  35.         answers5 = res.getStringArray(R.array.answers_five);
  36.         answers6 = res.getStringArray(R.array.answers_six);
  37.     }
  38.  
  39.     public static TemperFragment newInstance(int page)
  40.     {
  41.         TemperFragment temperFragment = new TemperFragment();
  42.         Bundle args = new Bundle();
  43.         args.putInt("someInt",page);
  44.         temperFragment.setArguments(args);
  45.         return temperFragment;
  46.     }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.     @Override
  53.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  54.                              Bundle savedInstanceState) {
  55.         ViewGroup rootView = (ViewGroup) inflater.inflate(
  56.                 R.layout.test_temper, container, false);
  57.  
  58.         page = getArguments().getInt("someInt");
  59.        
  60.  
  61.  
  62.         textdata = (TextView) rootView.findViewById(R.id.present_text);
  63.         question = (TextView) rootView.findViewById(R.id.question_text);
  64.         textdata = (TextView) rootView.findViewById(R.id.present_text);
  65.         first = (RadioButton) rootView.findViewById(R.id.first_answer);
  66.         second = (RadioButton) rootView.findViewById(R.id.second_answer);
  67.         third = (RadioButton) rootView.findViewById(R.id.third_answer);
  68.         textindicator = (TextView) rootView.findViewById(R.id.textIndicator);
  69.         TypefaceInit typefaceInit = new TypefaceInit(getContext());
  70.         first.setTypeface(typefaceInit.getRobotoThin());
  71.         second.setTypeface(typefaceInit.getRobotoThin());
  72.         third.setTypeface(typefaceInit.getRobotoThin());
  73.         textdata.setTypeface(typefaceInit.getRobotoMedium());
  74.  
  75.         switch (page)
  76.         {
  77.             case 1:
  78.             {
  79.                 textdata.setText(getText(R.string.firstText).toString());
  80.                 textindicator.setText(page+"");
  81.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  82.  
  83.             }
  84.             case 2:
  85.             {
  86.                 question.setText(questions[0].toString());
  87.                 first.setText(answers1[0]);
  88.                 second.setText(answers1[1]);
  89.                 third.setText(answers1[2]);
  90.                 textindicator.setText(page+"");
  91.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  92.  
  93.  
  94.  
  95.             }
  96.             case 3:
  97.             {
  98.                 question.setText(questions[1].toString());
  99.                 first.setText(answers2[0]);
  100.                 second.setText(answers2[1]);
  101.                 third.setText(answers3[2]);
  102.                 textindicator.setText(page+"");
  103.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  104.  
  105.  
  106.  
  107.             }
  108.             case 4:
  109.             {
  110.                 question.setText(questions[2]);
  111.                 first.setText(answers3[0]);
  112.                 second.setText(answers3[1]);
  113.                 third.setText(answers3[2]);
  114.                 textindicator.setText(page+"");
  115.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  116.  
  117.             }
  118.             case 5:
  119.             {
  120.                 question.setText(questions[3].toString());
  121.                 first.setText(answers4[0]);
  122.                 second.setText(answers4[1]);
  123.                 third.setText(answers4[2]);
  124.                 textindicator.setText(page+"");
  125.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  126.  
  127.             }
  128.             case 6:
  129.             {
  130.                 question.setText(questions[4].toString());
  131.                 first.setText(answers5[0]);
  132.                 second.setText(answers5[1]);
  133.                 third.setText(answers5[2]);
  134.                 textindicator.setText(page+"");
  135.                 rootView.getRootView().setBackgroundColor(Color.parseColor(randColor()));
  136.  
  137.             }
  138.             case 7:
  139.             {
  140.                 question.setText(questions[5].toString());
  141.                 first.setText(answers6[0]);
  142.                 second.setText(answers6[1]);
  143.                 third.setText(answers6[2]);
  144.                 textindicator.setText(page+"");
  145.                 rootView.setBackgroundColor(Color.parseColor(randColor()));
  146.  
  147.             }
  148.             case 8:
  149.             {
  150.  
  151.             }
  152.         }
  153.         return rootView;
  154.     }
  155.  
  156.     public String randColor()
  157.     {
  158.         String []cont = {"#189fff","#ff440d","#14c239","#9121e8"};
  159.         return  cont[ new Random().nextInt(cont.length)];
  160.     }
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment