Exemplo n.º 1
0
  private void seekBar(int maxGpu, int currentGpu) {

    seekGpu.setMax(maxGpu);
    seekGpu.setProgress(currentGpu);
    seekGpu.setOnSeekBarChangeListener(
        new SeekBar.OnSeekBarChangeListener() {
          int selectedGpu;

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            curGpuTxt.setText(current + ": " + (gpu.get(progress)) + mhz);
            selectedGpu = progress;
          }

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub

          }

          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {
            Command command =
                new Command(
                    0,
                    "chmod 777 " + Constants.GPU_SGX540,
                    "echo " + selectedGpu + " > " + Constants.GPU_SGX540);
            try {
              RootShell.getShell(true).add(command);
            } catch (Exception e) {

            }
            gpuCurrent = readFile(Constants.GPU_SGX540);
            curGpuTxt.setText(current + ": " + gpuCurrent + mhz);
            seekBar.setProgress(gpu.indexOf(gpuCurrent));
            PrefsManager.setGpu2d(gpuCurrent);
          }
        });
  }
        // @Override
        public void handleMessage(Message msg) {
          if (msg.what == 1) {
            _progressDlg.hide();

            getNumPuzzles();
            if (_seekBar != null) {
              _seekBar.setMax(_num);
            }

            play();
          } else if (msg.what == 2) {
            _progressDlg.setMessage(
                _parent.getString(R.string.msg_progress)
                    + String.format(" %d", (_cnt * 100) / _num)
                    + " %");
          } else if (msg.what == 3) {
            _progressDlg.hide();
            _tvPuzzleText.setText("An error occured during install");
          }
        }
  public ChessViewPuzzle(final Activity activity) {
    super();
    _parent = (puzzle) activity;
    _view = new ChessViewBase(activity);

    _cr = activity.getContentResolver();

    _tvPuzzleText = (TextView) _parent.findViewById(R.id.TextViewPuzzleText);
    _imgTurn = (ImageView) _parent.findViewById(R.id.ImageTurn);

    _imgStatus = (ImageView) _parent.findViewById(R.id.ImageStatus);

    _cnt = 0;
    // _num = 500;
    getNumPuzzles();

    _seekBar = (SeekBar) _parent.findViewById(R.id.SeekBarPuzzle);
    if (_seekBar != null) {
      _seekBar.setOnSeekBarChangeListener(
          new OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
              if (fromUser) {
                _iPos = progress - 1;
                play();
              }
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
              // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
              // TODO Auto-generated method stub

            }
          });

      _seekBar.setMax(_num);
    }

    _iPos = 0;

    OnClickListener ocl =
        new OnClickListener() {
          public void onClick(View arg0) {
            handleClick(_view.getIndexOfButton(arg0));
          }
        };
    _view.init(ocl);

    _butPuzzle = (Button) _parent.findViewById(R.id.ButtonPuzzle);

    _butPuzzle.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            jumptoMove(_jni.getNumBoard());
            updateState();

            // if(_arrPGN.size() == m_game.getBoard().getNumBoard()-1)
            //   _butPuzzle.setText("Next");

          }
        });

    _butJump = (Button) _parent.findViewById(R.id.ButtonPuzzleJump);
    _butJump.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            AlertDialog.Builder builder = new AlertDialog.Builder(_parent);
            builder.setTitle(_parent.getString(R.string.title_puzzle_jump));
            final EditText input = new EditText(_parent);
            input.setInputType(InputType.TYPE_CLASS_PHONE);
            builder.setView(input);
            builder.setPositiveButton(
                _parent.getString(R.string.button_ok),
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int whichButton) {
                    try {
                      int num = Integer.parseInt(input.getText().toString());

                      if (num > 0 && num <= _num) {
                        _iPos = num - 1;
                        play();
                        return;
                      }
                    } catch (Exception ex) {

                    }
                    _parent.doToast(_parent.getString(R.string.err_puzzle_jump));
                  }
                });

            AlertDialog alert = builder.create();
            alert.show();
          }
        });

    _butPrev = (ImageButton) _parent.findViewById(R.id.ButtonPuzzlePrevious);
    _butPrev.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            if (_iPos > 1) _iPos -= 2;
            play();
          }
        });

    _butNext = (ImageButton) _parent.findViewById(R.id.ButtonPuzzleNext);
    _butNext.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            play();
          }
        });

    _butHelp = (ImageButton) _parent.findViewById(R.id.ButtonPuzzleHelp);
    _butHelp.setOnClickListener(
        new OnClickListener() {
          public void onClick(View arg0) {
            Intent i = new Intent();
            i.setClass(_parent, HtmlActivity.class);
            i.putExtra(HtmlActivity.HELP_MODE, "help_puzzle");
            _parent.startActivity(i);
          }
        });
  }
  public void OnResume(final SharedPreferences prefs) {
    super.OnResume();

    if (_seekBar != null) {
      if (prefs.getBoolean("PuzzleShowSeekBar", true)) {
        _seekBar.setVisibility(View.VISIBLE);

      } else {
        _seekBar.setVisibility(View.GONE);
      }
    }

    ChessImageView._colorScheme = prefs.getInt("ColorScheme", 0);

    _view.setFlippedBoard(prefs.getBoolean("flippedBoard", false));

    _iPos = prefs.getInt("puzzlePos", 0);

    getNumPuzzles();

    if (_num == 0) {

      _num = 500; // first puzzle set has fixed amount
      _progressDlg =
          ProgressDialog.show(
              _parent,
              _parent.getString(R.string.title_installing),
              _parent.getString(R.string.msg_wait),
              false,
              false);

      // if(iTmp > 0)
      //	_cr.delete(MyPuzzleProvider.CONTENT_URI_PUZZLES, "1=1", null);

      _thread =
          new Thread(
              new Runnable() {
                public void run() {

                  try {
                    InputStream is = _parent.getAssets().open("puzzles.pgn");

                    StringBuffer sb = new StringBuffer();
                    String s = "", data;
                    int pos1 = 0, pos2 = 0, len;
                    byte[] buffer = new byte[2048];

                    while ((len = is.read(buffer, 0, buffer.length)) != -1) {
                      data = new String(buffer, 0, len);
                      sb.append(data);
                      pos1 = sb.indexOf("[Event \"");
                      while (pos1 >= 0) {
                        pos2 = sb.indexOf("[Event \"", pos1 + 10);
                        if (pos2 == -1) break;
                        s = sb.substring(pos1, pos2);

                        processPGN(s);

                        sb.delete(0, pos2);

                        pos1 = sb.indexOf("[Event \"");
                      }
                      // break;

                      // Log.i("run", "left: " + sb);
                      // break;
                    }
                    processPGN(sb.toString());

                    Log.i("run", "Count " + _cnt);

                    Message msg = new Message();
                    msg.what = 1;
                    m_threadHandler.sendMessage(msg);

                    is.close();

                  } catch (Exception ex) {
                    Log.e("Install", ex.toString());
                  }
                }
              });
      _thread.start();

      return;
    }

    play();
  }
  @Override
  public void play() {
    m_iFrom = -1;
    Log.i("ChessViewPuzzle", "Numboard = " + _jni.getNumBoard());

    _imgStatus.setImageResource(R.drawable.indicator_none);

    String sPGN;

    _iPos++;
    if (_iPos < 1) _iPos = 1;
    if (_iPos > _num) {
      setMessage("You completed all puzzles!!!");
      return;
    }

    if (_seekBar != null) {
      _seekBar.setProgress(_iPos);
    }
    if (_cursor != null) {
      _cursor.moveToPosition(_iPos - 1);
      sPGN = _cursor.getString(_cursor.getColumnIndex(MyPuzzleProvider.COL_PGN));
      Log.i("ChessViewPuzzle", "init: " + sPGN);
      loadPGN(sPGN);

      jumptoMove(0);

      int turn = _jni.getTurn();
      if (turn == BoardConstants.BLACK && false == _view.getFlippedBoard()
          || turn == BoardConstants.WHITE && _view.getFlippedBoard()) _view.flipBoard();

      String sWhite = _mapPGNHead.get("White");
      if (sWhite == null) {
        sWhite = "";
      } else {
        sWhite = sWhite.replace("?", "");
      }
      String sDate = _mapPGNHead.get("Date");
      if (sDate == null) {
        sDate = "";
      } else {
        sDate = sDate.replace("????", "");
        sDate = sDate.replace(".??.??", "");
      }

      if (sWhite.length() > 0 && sDate.length() > 0) {
        sWhite += ", ";
      }

      _tvPuzzleText.setText(
          "# " + _iPos + " - " + sWhite
              + sDate); // + "\n\n" + _mapPGNHead.get("Event") + ", " +
                        // _mapPGNHead.get("Date").replace(".??.??", ""));
      // _tvPuzzle.setText(");

      _imgTurn.setImageResource(
          (turn == BoardConstants.WHITE ? R.drawable.turnwhite : R.drawable.turnblack));

      updateState();
    }
  }
Exemplo n.º 6
0
 @SuppressWarnings("ConstantConditions")
 public static void setEventListener(
     Object handler,
     ViewFinder finder,
     DoubleKeyValueMap<Object, Annotation, Method> value_annotation_method_map) {
   for (Object value : value_annotation_method_map.getFirstKeys()) {
     ConcurrentHashMap<Annotation, Method> annotation_method_map =
         value_annotation_method_map.get(value);
     for (Annotation annotation : annotation_method_map.keySet()) {
       try {
         Method method = annotation_method_map.get(annotation);
         if (annotation.annotationType().equals(OnClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnLongClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnLongClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnFocusChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnFocusChangeListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnKey.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnKeyListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnTouch.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.setOnTouchListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnItemClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((AdapterView<?>) view)
               .setOnItemClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnItemLongClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((AdapterView<?>) view)
               .setOnItemLongClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnChildClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnChildClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupClick.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupCollapse.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupCollapseListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnGroupExpand.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((ExpandableListView) view)
               .setOnGroupExpandListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnCheckedChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           if (view instanceof RadioGroup) {
             ((RadioGroup) view)
                 .setOnCheckedChangeListener(new ViewCommonEventListener(handler, method));
           } else if (view instanceof CompoundButton) {
             ((CompoundButton) view)
                 .setOnCheckedChangeListener(new ViewCommonEventListener(handler, method));
           }
         } else if (annotation.annotationType().equals(OnPreferenceClick.class)) {
           Preference preference = finder.findPreference(value.toString());
           if (preference == null) break;
           preference.setOnPreferenceClickListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnPreferenceChange.class)) {
           Preference preference = finder.findPreference(value.toString());
           if (preference == null) break;
           preference.setOnPreferenceChangeListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnTabChange.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           ((TabHost) view).setOnTabChangedListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnScrollChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           view.getViewTreeObserver()
               .addOnScrollChangedListener(new ViewCommonEventListener(handler, method));
         } else if (annotation.annotationType().equals(OnScrollStateChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnScrollStateChanged.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnScroll.class)) {
               method1 = a_m_map.get(a);
             }
           }
           ((AbsListView) view)
               .setOnScrollListener(new ViewCommonEventListener(handler, method0, method1));
         } else if (annotation.annotationType().equals(OnItemSelected.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnItemSelected.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnNothingSelected.class)) {
               method1 = a_m_map.get(a);
             }
           }
           ((AdapterView<?>) view)
               .setOnItemSelectedListener(new ViewCommonEventListener(handler, method0, method1));
         } else if (annotation.annotationType().equals(OnProgressChanged.class)) {
           View view = finder.findViewById((Integer) value);
           if (view == null) break;
           Method method0 = null, method1 = null, method2 = null;
           ConcurrentHashMap<Annotation, Method> a_m_map = value_annotation_method_map.get(value);
           for (Annotation a : a_m_map.keySet()) {
             if (a.annotationType().equals(OnProgressChanged.class)) {
               method0 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnStartTrackingTouch.class)) {
               method1 = a_m_map.get(a);
             } else if (a.annotationType().equals(OnStopTrackingTouch.class)) {
               method2 = a_m_map.get(a);
             }
           }
           ((SeekBar) view)
               .setOnSeekBarChangeListener(
                   new ViewCommonEventListener(handler, method0, method1, method2));
         }
       } catch (Throwable e) {
         LogUtils.e(e.getMessage(), e);
       }
     }
   }
 }