Esempio n. 1
0
  private void showSetup(String serial) {

    int position = -1;

    for (int i = 0; i < adapter.getCount(); i++) {
      if (adapter.getItem(i).getSerial().equals(serial)) {
        position = i;
        break;
      }
    }

    if (position != -1) {
      final MmcModell card = adapter.getItem(position);

      SDdialog dialog = new SDdialog(this, 1, card, uiHandler, position);
      dialog.useIcon();
      dialog.show();
    }
  }
Esempio n. 2
0
  @SuppressLint("HandlerLeak")
  private void init() {

    context = this;
    mmcDetection = false;
    mmcLock = false;

    Database db = getDbInstance();

    uiButtonApply = (ImageView) findViewById(R.id.btn_green);
    uiButtonExit = (ImageView) findViewById(R.id.btn_red);
    uiButtonHelp = (ImageView) findViewById(R.id.btn_blue);
    uiButtonSetting = (ImageView) findViewById(R.id.btn_orange);
    uiButtonReport = (ImageView) findViewById(R.id.btn_report);

    uiBoxCache = (CheckBox) findViewById(R.id.cbx_cache_all);
    uiBoxBoot = (CheckBox) findViewById(R.id.cbx_boot_all);
    uiBoxMonitor = (CheckBox) findViewById(R.id.cbx_monitor_all);

    uiCacheSize = (EditText) findViewById(R.id.cache_edit);

    uiNoCardList = (LinearLayout) findViewById(R.id.card_list_error);
    uiCardList = (LinearLayout) findViewById(R.id.card_list);

    uiBoxListener =
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton view, boolean isChecked) {

            int value = isChecked == true ? 1 : 0;
            setPref((String) view.getTag(), value);

            if (value == 1) {
              showMessage(4, null);
            } else {
              showMessage(8, null);
            }

            String tag = (String) view.getTag();

            // logical verification

            if (tag.equals("cbx_monitor_all")) {
              if (isChecked) {
                Database db = getDbInstance();
                if (db.getPref(1, 1) == 0) {
                  showMessage(10, null);
                }
              }
            }

            // EditText

            if (tag.equals("cbx_cache_all")) {
              if (isChecked) {
                Database db = getDbInstance();
                int allSize = db.getPref(5, 0);
                if (allSize >= 128 && allSize <= 8192 && allSize != 128) {
                  uiCacheSize.setText(String.valueOf(allSize));
                }
              } else {
                uiCacheSize.setText(null);
              }
            }
          }
        };

    uiHandler =
        new Handler() {

          /*
           * arg1 0 = Kernel messages
           * arg1 1 = MMC detection
           * arg1 2 = App exit
           * arg1 3 = License
           * arg1 4 = Preferences
           * arg1 5 = card setup
           *
           * @see android.os.Handler#handleMessage(android.os.Message)
           */

          @Override
          public void handleMessage(Message msg) {

            if (msg.arg1 == 0) {

              // kernel

              if (msg.arg2 == 0) {
                showMessage(1, null);
              } else if (msg.arg2 == 1) {
                showMessage(3, null);

              } else if (msg.arg2 == 2) {

                // all ok

                if (!mmcLock) {
                  mmcLock = true;
                  Thread thread = new Thread(cards);
                  thread.start();

                  if (msg.what == 0) {
                    showMessage(2, null);
                  }
                } else {
                  showMessage(11, null);
                  Log.e(Utils.TAG, "MMC lock found");
                }

              } else if (msg.arg2 == 3) {

                // device ok

                MmcModell card = (MmcModell) msg.obj;
                String text =
                    getString(R.string.msg_kernel_cache_p1)
                        + " "
                        + card.getName()
                        + " "
                        + getString(R.string.msg_kernel_cache_p2)
                        + " "
                        + card.getAheadUser()
                        + " "
                        + getString(R.string.msg_kernel_cache_p3);

                showMessage(7, text);

              } else if (msg.arg2 == 4) {

                // device failed

                MmcModell card = (MmcModell) msg.obj;
                String text =
                    getString(R.string.msg_kernel_cache_p1)
                        + " "
                        + card.getName()
                        + " "
                        + getString(R.string.msg_kernel_cache_p4);

                showMessage(7, text);

              } else if (msg.arg2 == 5) {

                // device skipped

                MmcModell card = (MmcModell) msg.obj;
                String text =
                    getString(R.string.msg_kernel_device_skip_p1)
                        + " "
                        + card.getName()
                        + " "
                        + getString(R.string.msg_kernel_device_skip_p1);

                Log.i(Utils.TAG, text + "." + " (reason = " + msg.what + ")");
              }

              if (kernelLock) {
                kernelLock = false;
              } else {
                Log.e(Utils.TAG, "Kernel without lock");
              }

            } else if (msg.arg1 == 1) {

              // MMC detection

              if (msg.arg2 == 0) {
                mmcDetection = true;

                // sd-booster.prop

                FileSetting prop = new FileSetting(context, getDbInstance());
                prop.setCardProperties(cards.getList());

                listToAdapter();
                adapterToView();

                if (uiNoCardList.getVisibility() == View.VISIBLE) {
                  uiNoCardList.setVisibility(View.GONE);
                  uiCardList.setVisibility(View.VISIBLE);
                }

                // EditText

                if (uiBoxCache.isChecked()) {

                  Database db = getDbInstance();
                  int allSize = db.getPref(5, 0); // User size

                  if (allSize >= 128 && allSize <= 8192 && allSize != 128) {
                    uiCacheSize.setText(String.valueOf(allSize));
                  }
                } else {
                  uiCacheSize.setText(null);
                }

                ServiceSetup setup = new ServiceSetup(context);
                setup.configuration(true);

                // notification

                Bundle bundle = getIntent().getExtras();
                String serial = null;

                if (bundle != null) {
                  serial = bundle.getString(Utils.SERIAL);
                }

                if (serial != null) {
                  showSetup(serial);
                }

              } else {
                mmcDetection = false;
                showMessage(1, null);

                if (uiNoCardList.getVisibility() == View.GONE) {
                  uiNoCardList.setVisibility(View.VISIBLE);
                  uiCardList.setVisibility(View.GONE);
                }
              }

              if (mmcLock) {
                mmcLock = false;
              } else {
                Log.e(Utils.TAG, "MMC detecion without lock");
              }

            } else if (msg.arg1 == 2) {

              // App exit

              finish();
            } else if (msg.arg1 == 3) {

              if (msg.arg2 == 0) {

                // License accepted

                if (!mmcLock) {
                  mmcLock = true;

                  Thread thread = new Thread(cards);
                  thread.start();
                }
              } else {

                // help screen

                SDdialog dialog = new SDdialog(context, uiHandler, 4);
                dialog.useIcon();
                dialog.show();
              }
            } else if (msg.arg1 == 4) {

              // Preferences

              if (msg.arg2 == 0) {

                if (ringtone != null) {
                  Database db = getDbInstance();
                  db.setRingTone(ringtone);
                }
                showMessage(9, null);

                // logical check

                boolean monitor = uiBoxMonitor.isChecked();

                if (!monitor) {
                  for (int i = 0; i < adapter.getCount(); i++) {
                    MmcModell card = adapter.getItem(i);

                    if (card.isOnMonitor()) {
                      monitor = true;
                      break;
                    }
                  }
                }

                if (monitor) {
                  Database db = getDbInstance();
                  if (db.getPref(1, 1) == 0) {
                    showMessage(10, null);
                  }
                }

                // background updates

                ServiceSetup setup = new ServiceSetup(context);
                setup.configuration(true);

              } else if (msg.arg2 == 1) {
                ringtoneChooser();
              }
            } else if (msg.arg1 == 5) {

              // card setup finished

              showMessage(9, null);

              MmcModell card = (MmcModell) msg.obj;

              if (card.isOnMonitor()) {
                Database db = getDbInstance();
                if (db.getPref(1, 1) == 0) {
                  showMessage(10, null);
                }
              }
            }
          }
        };

    uiButtonApply.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {

            if (!mmcDetection) {
              showMessage(1, null);
              return;
            }

            if (mmcLock) {
              showMessage(11, null);
              return;
            }

            if (uiBoxCache.isChecked()) {
              String size = uiCacheSize.getText().toString();

              if (size.length() < 3
                  || !Utils.containOnlyNumbers(size)
                  || !Utils.cacheSizeIsOk(size)) {

                showMessage(5, null);
                return;
              }

              int value = Integer.valueOf(size);

              setPref("size", value);

              if (!kernelLock) {
                kernelLock = true;
                cards.setToKernel(value);
              } else {
                Log.e(Utils.TAG, "Kernel lock found");
                showMessage(11, null);
              }

            } else {

              boolean setup = false;

              for (int i = 0; i < adapter.getCount(); i++) {
                if (adapter.getItem(i).isSetup()) {
                  setup = true;
                  break;
                }
              }

              if (setup) {
                if (!kernelLock) {
                  kernelLock = true;
                  cards.setToKernel(0);
                } else {
                  Log.e(Utils.TAG, "Kernel lock found");
                  showMessage(11, null);
                }
              } else {
                showMessage(6, null);
              }
            }
          }
        });

    uiButtonExit.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {
            finish();
          }
        });

    uiButtonHelp.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {

            Uri uri;
            String locale = getResources().getConfiguration().locale.getDisplayName();

            if (locale.contains("Deutsch") == true) {
              uri = Uri.parse(Utils.HELP_DE);
            } else {
              uri = Uri.parse(Utils.HELP_EN);
            }

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(uri);

            try {
              startActivity(intent);
            } catch (ActivityNotFoundException e) {
              Log.e(Utils.TAG, "No browser installed");
            }
          }
        });

    uiButtonSetting.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {

            SDpreference dialog = new SDpreference(context, uiHandler);
            dialog.useIcon();
            dialog.show();
          }
        });

    uiButtonReport.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            sendReport();
          }
        });

    uiBoxCache.setChecked(db.getPref(4, 0) == 1 ? true : false);
    uiBoxCache.setOnCheckedChangeListener(uiBoxListener);
    uiBoxBoot.setChecked(db.getPref(1, 0) == 1 ? true : false);
    uiBoxBoot.setOnCheckedChangeListener(uiBoxListener);
    uiBoxMonitor.setChecked(db.getPref(2, 0) == 1 ? true : false);
    uiBoxMonitor.setOnCheckedChangeListener(uiBoxListener);

    uiCacheSize.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {

          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            if (actionId == EditorInfo.IME_ACTION_DONE) {
              String input = v.getText().toString();

              if (input.length() < 3
                  || !Utils.containOnlyNumbers(input)
                  || !Utils.cacheSizeIsOk(input)) {

                showMessage(5, null);
                v.setText(null);
              }
            }
            return false;
          }
        });

    adapter = new ListAdapter(this, uiHandler);
    cards = new Mmc(uiHandler, 0);

    // License

    if (db.getPref(3, 0) == 0) {
      SDdialog dialog = new SDdialog(context, uiHandler, 2);
      dialog.useIcon();
      dialog.show();
    } else {
      mmcLock = true;
      Thread thread = new Thread(cards);
      thread.start();
    }
  }