Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- toolbar.setNavigationOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- getFragmentManager().popBackStack();
- }
- });
- litersWatterTv = (TextView) view.findViewById(R.id.water_liters_value_tv);
- litersWatterTv.setText("0");
- gridLayout = (GridLayout) view.findViewById(R.id.grid_layout_level_fragment);
- GridLayout.LayoutParams gridParams = new GridLayout.LayoutParams();
- //gridParams.columnSpec = GridLayout.spec(0, 2);
- Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- @Override
- public void run() {
- mWidthGrid = gridLayout.getWidth();
- mHeightGrid = gridLayout.getHeight();
- mValueBottle = 7; // количество бутолк
- mSizeOneBottle = 18.9; //Размер одной бутылки
- mValueMaxSeekBar = (int) (mValueBottle * mSizeOneBottle * 10); // количество позиций seek bar
- mSizeAll = (mValueBottle * mSizeOneBottle);
- if (mValueBottle <= 6) {
- mValueBottlesInRow = mValueBottle;
- mRows = 2;
- } else if (mValueBottle <= 8 & mValueBottle > 6) {
- mValueBottlesInRow = 5;
- mRows = 2;
- } else if (mValueBottle > 8 & mValueBottle <= 15) {
- mValueBottlesInRow = 5;
- mRows = 3;
- } else if (mValueBottle > 15 & mValueBottle <= 25) {
- mValueBottlesInRow = 6;
- mRows = 4;
- } else if (mValueBottle > 25 & mValueBottle > 8) {
- mValueBottlesInRow = mValueBottle / mRows;
- }
- gridLayout.setColumnCount(mValueBottlesInRow*2); //6
- gridLayout.setRowCount(mRows); //5
- mWidthBottle = mWidthGrid / mValueBottlesInRow;
- mHeightBottle = mHeightGrid / mRows;
- }
- }, 100);
- Handler handlerTwo = new Handler();
- handlerTwo.postDelayed(new Runnable() {
- @Override
- public void run() {
- for (int i = 0; i < mValueBottle; i++) {
- RelativeLayout relativeLayout = new RelativeLayout(getActivity());
- //for relativelayout
- RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
- RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
- relativeLayout.setLayoutParams(relativeParams);
- if(i ==0) {
- gridParams.columnSpec = GridLayout.spec(0, 2);
- }else if (i < mValueBottlesInRow) {
- gridParams.columnSpec = GridLayout.spec((i + 2) - 1, 2);
- }else if(i > mValueBottlesInRow) {gridParams.columnSpec = GridLayout.spec((i-mValueBottlesInRow)*2, 2);
- gridParams.rowSpec = GridLayout.spec(1,1);
- }
- gridLayout.addView(relativeLayout, gridParams);
- ImageView imageViewFirst = new ImageView(getActivity());
- //for image
- RelativeLayout.LayoutParams lpView = new RelativeLayout.LayoutParams(mWidthBottle, mHeightBottle);
- imageViewFirst.setImageResource(R.drawable.clip_b1);
- mB1 = (ClipDrawable) imageViewFirst.getDrawable();
- mB1.setLevel(0);
- imageViewFirst.setLayoutParams(lpView);
- relativeLayout.addView(imageViewFirst);
- imageViewArrayListFirst.add(i, mB1);
- ImageView imageViewSecond = new ImageView(getActivity());
- imageViewSecond.setImageResource(R.drawable.clip_b2);
- mB2 = (ClipDrawable) imageViewSecond.getDrawable();
- mB2.setLevel(10000);
- imageViewSecond.setLayoutParams(lpView);
- imageViewSecond.setId(i);
- relativeLayout.addView(imageViewSecond);
- imageViewArrayListSecond.add(i, mB2);
- }
- mFlag = true;
- litersWatterTv.setText(String.valueOf((double) Math.round(mSizeAll * 100d) / 100d));
- final SeekBar seekBar = (SeekBar) view.findViewById(R.id.seekBar);
- seekBar.setMax(mValueMaxSeekBar);
- seekBar.setProgress(mValueMaxSeekBar);
- //seekBar.setPadding(25,0,25,0);
- seekBar.setPadding(0,0,0,0);
- seekBar.setOnSeekBarChangeListener(EditLevelWatterFragment.this);
- }
- }, 100);
- return view;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement