public void commandAction(Command c, Displayable d) {
    if (c == cmdOk) {
      String jid = getString(tJid);
      if (jid != null) {
        String name = getString(tNick);
        String group = group(tGrpList.getSelectedIndex());
        if (group == null) group = getString(tGroup);

        try {
          int gSel = tGrpList.getSelectedIndex();
          if (gSel != tGrpList.size() - 1) {
            group = (gSel > 0) ? tGrpList.getString(gSel) : null; // nokia fix
          }
        } catch (Exception e) {
        } // nokia fix

        // сохранение контакта
        boolean ask[] = new boolean[1];
        tAskSubscrCheckBox.getSelectedFlags(ask);
        roster.storeContact(jid, name, group, ask[0]);
        destroyView();
        return;
      }
    }

    if (c == cmdCancel) destroyView();
  }
  /** Creates a new instance of PrivacyForm */
  public PrivacyForm(Display display, PrivacyItem item, PrivacyList plist) {
    this.display = display;
    parentView = display.getCurrent();
    this.item = item;
    targetList = plist;

    textValue = new TextField(null, item.value, 64, ConstMIDP.TEXTFIELD_URL);
    TextFieldCombo.setLowerCaseLatin(textValue);

    form.append(choiceAction);
    choiceAction.setSelectedIndex(item.action, true);

    form.append(choiseType);

    form.append(textValue);
    choiseType.setSelectedIndex(item.type, true);
    switchType();

    form.append(choiseStanzas);
    choiseStanzas.setSelectedFlags(item.stanzasSet);

    // form.append("Order: "+item.order);

    form.setItemStateListener(this);
    form.setCommandListener(this);
    form.addCommand(cmdOk);
    form.addCommand(cmdCancel);
    display.setCurrent(form);
  }
  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
      return;
    }
    if (c == cmdOk) {
      try {
        int type = choiseType.getSelectedIndex();
        String value = textValue.getString();
        if (type == 2) value = PrivacyItem.subscrs[choiceSubscr.getSelectedIndex()];
        if (type != PrivacyItem.ITEM_ANY) if (value.length() == 0) return;
        // int order=Integer.parseInt(textOrder.getString());

        item.action = choiceAction.getSelectedIndex();
        item.type = type;
        item.value = value;
        // item.order=order;
        choiseStanzas.getSelectedFlags(item.stanzasSet);

        if (targetList != null)
          if (!targetList.rules.contains(item)) {
            targetList.addRule(item);
            item.order = targetList.rules.indexOf(item) * 10;
          }
        destroyView();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
 private void updateChoise(String str, ChoiceGroup grp) {
   int sz = grp.size();
   int set = sz - 1;
   for (int i = 0; i < sz; i++) {
     if (str.equals(grp.getString(i))) {
       set = i;
       break;
     }
   }
   if (grp.getSelectedIndex() != set) grp.setSelectedIndex(set, true);
 }
  public void itemStateChanged(Item item) {
    if (item == tGrpList) {
      int index = tGrpList.getSelectedIndex();
      if (index == tGrpList.size() - 1) {
        f.set(grpFIndex, tGroup);
      }
      // tGroup.setString(group(index));
    }

    // if (item==tGroup) {
    //    updateChoise(tGroup.getString(), tGrpList);
    // }

    if (item == tTranspList) {
      int index = tTranspList.getSelectedIndex();
      if (index == tTranspList.size() - 1) return;

      String transport = tTranspList.getString(index);

      String jid = tJid.getString();
      StringBuffer jidBuf = new StringBuffer(jid);

      int at = jid.indexOf('@');
      if (at < 0) at = tJid.size();

      jidBuf.setLength(at);
      jidBuf.append('@');
      jidBuf.append(transport);
      tJid.setString(jidBuf.toString());
    }
    if (item == tJid) {
      String s1 = tJid.getString();
      int at = tJid.getString().indexOf('@');
      try {
        updateChoise(s1.substring(at + 1), tTranspList);
      } catch (Exception e) {
      }
    }
  }
  private void switchType() {
    int index = choiseType.getSelectedIndex();
    try {
      Object rfocus = StaticData.getInstance().roster.getFocusedObject();
      switch (index) {
        case 0: // jid
          if (targetList != null)
            if (rfocus instanceof Contact) {
              textValue.setString(((Contact) rfocus).getBareJid());
            }
          form.set(2, textValue);
          break;
        case 1: // group
          if (targetList != null)
            textValue.setString(
                ((rfocus instanceof Group) ? (Group) rfocus : ((Contact) rfocus).getGroup())
                    .getName());

          form.set(2, textValue);
          break;
        case 2: // subscription
          form.set(2, choiceSubscr);
          break;

        case 3:
          form.set(2, new StringItem(null, "(ANY)"));
      }
      /*if (index==2) {
          form.set(2, choiceSubscr);
      } else {
          textValue.setLabel(PrivacyItem.types[index]);
          form.set(2, textValue);
      }
       */
    } catch (Exception e) {
      /* При смене на самого себя */
    }
  }
  public ContactEdit(Display display, Contact c) {
    this.display = display;
    parentView = display.getCurrent();

    StaticData sd = StaticData.getInstance();
    roster = sd.roster;

    Vector groups = sd.roster.groups.getRosterGroupNames();
    cf = Config.getInstance();

    f = new Form(SR.MS_ADD_CONTACT); // locale

    tJid = new TextField(SR.MS_USER_JID, null, 150, TextField.EMAILADDR);

    tNick = new TextField("Name", null, 32, TextField.ANY); // locale
    tGroup = new TextField(SR.MS_GROUP, null, 32, TextField.ANY); // locale

    tGrpList = new ChoiceGroup(SR.MS_GROUP, ConstMIDP.CHOICE_POPUP);
    tTranspList = new ChoiceGroup(SR.MS_TRANSPORT, ConstMIDP.CHOICE_POPUP);

    tAskSubscrCheckBox = new ChoiceGroup(SR.MS_SUBSCRIPTION, ChoiceGroup.MULTIPLE); // locale
    tAskSubscrCheckBox.append(SR.MS_ASK_SUBSCRIPTION, null); // locale

    tGrpList.addCommand(cmdSet);
    tGrpList.setItemCommandListener(this);

    tTranspList.addCommand(cmdSet);
    tTranspList.setItemCommandListener(this);

    // Transport droplist
    tTranspList.append(sd.account.getServer(), null);
    for (Enumeration e = sd.roster.getHContacts().elements(); e.hasMoreElements(); ) {
      Contact ct = (Contact) e.nextElement();
      Jid transpJid = ct.jid;
      if (transpJid.isTransport()) tTranspList.append(transpJid.getBareJid(), null);
    }
    tTranspList.append(SR.MS_OTHER, null); // locale

    try {
      String jid;
      if (c instanceof MucContact) {
        jid = Jid.toBareJid(((MucContact) c).realJid);
      } else {
        jid = c.getBareJid();
      }
      // edit contact
      tJid.setString(jid);
      tNick.setString(c.nick);

      if (c instanceof MucContact) {
        c = null;
        throw new Exception();
      }

      if (c.getGroupType() != Groups.TYPE_NOT_IN_LIST
          && c.getGroupType() != Groups.TYPE_SEARCH_RESULT) {
        // edit contact
        f.setTitle(jid);
        cmdOk = new Command("Update", Command.OK, 1); // locale
        newContact = false;
      } else c = null; // adding not-in-list
    } catch (Exception e) {
      c = null;
    } // if MucContact does not contains realJid

    int sel = -1;
    ngroups = 0;
    String grpName = "";
    if (c != null) grpName = c.getGroup().name;

    if (groups != null) {
      ngroups = groups.size();
      for (int i = 0; i < ngroups; i++) {
        String gn = (String) groups.elementAt(i);
        tGrpList.append(gn, null);

        if (gn.equals(grpName)) sel = i;
      }
    }

    // if (sel==-1) sel=groups.size()-1;
    if (sel < 0) sel = 0;
    // tGroup.setString(group(sel));

    if (c == null) {
      f.append(tJid);
      f.append(tTranspList);
    }
    updateChoise(tJid.getString(), tTranspList);
    f.append(tNick);

    tGrpList.append(SR.MS_NEWGROUP, null);

    tGrpList.setSelectedIndex(sel, true);

    grpFIndex = f.append(tGrpList);

    if (newContact) {
      f.append(tAskSubscrCheckBox);
      tAskSubscrCheckBox.setSelectedIndex(0, true);
    }

    f.addCommand(cmdOk);
    f.addCommand(cmdCancel);

    f.setCommandListener(this);
    f.setItemStateListener(this);

    display.setCurrent(f);
  }
 private String group(int index) {
   if (index == 0) return null;
   if (index == tGrpList.size() - 1) return null;
   return tGrpList.getString(index);
 }
Example #9
0
  public GuiSetupGui(ShareNavDisplayable parent, boolean initialSetup) {
    super(Locale.get("guisetupgui.GUIOptions") /*GUI Options*/);
    this.parent = parent;
    this.initialSetup = initialSetup;
    try {
      long mem = Configuration.getPhoneAllTimeMaxMemory();
      if (mem == 0) {
        mem = Runtime.getRuntime().totalMemory();
      }
      mem = mem / 1024;
      memField =
          new TextField(
              Locale.get("guisetupgui.DefineMaxMem") /*Define maxMem (kbyte)*/,
              Long.toString(mem),
              8,
              TextField.DECIMAL);
      append(memField);
      String[] imenu = new String[7];
      imenu[0] = Locale.get("guisetupgui.UseIconMenu") /*Use icon menu*/;
      imenu[1] = Locale.get("guisetupgui.UseSetupIconMenu") /*Use icon menu for settings*/;
      imenu[2] = Locale.get("guisetupgui.FullscreenIconMenu") /*Fullscreen icon menu*/;
      imenu[3] = Locale.get("guisetupgui.SplitscreenIconMenu") /*Split screen icon menu*/;
      imenu[4] = Locale.get("guisetupgui.LargeTabButtons") /*Large tab buttons*/;
      imenu[5] = Locale.get("guisetupgui.IconsMappedOnKeys") /*Icons mapped on keys*/;
      // imenu[5] = Locale.get("guisetupgui.OptimiseForRouting")/*Optimise for routing*/;
      imenu[6] =
          Locale.get("guisetupgui.FavoritesInRouteIconMenu") /*Favorites in route icon menu*/;
      imenuOpts =
          new ChoiceGroup(
              Locale.get("guisetupgui.IconMenu") /*Icon Menu:*/, Choice.MULTIPLE, imenu, null);
      imenuOpts.setSelectedIndex(
          0, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS));
      imenuOpts.setSelectedIndex(
          1, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_SETUP));
      imenuOpts.setSelectedIndex(
          2, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_FULLSCREEN));
      imenuOpts.setSelectedIndex(
          3, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_SPLITSCREEN));
      imenuOpts.setSelectedIndex(
          4, Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_BIG_TAB_BUTTONS));
      imenuOpts.setSelectedIndex(
          5, Configuration.getCfgBitState(Configuration.CFGBIT_ICONMENUS_MAPPED_ICONS));
      // imenuOpts.setSelectedIndex(5,
      //		Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_ROUTING_OPTIMIZED));
      imenuOpts.setSelectedIndex(
          6, Configuration.getCfgBitSavedState(Configuration.CFGBIT_FAVORITES_IN_ROUTE_ICON_MENU));
      append(imenuOpts);

      if (Configuration.getHasPointerEvents()) {
        String[] touch = new String[4];
        int i = 0;
        touch[i++] = Locale.get("guisetupgui.longMapTap");
        touch[i++] = Locale.get("guisetupgui.doubleMapTap");
        touch[i++] = Locale.get("guisetupgui.singleMapTap");
        touch[i++] = Locale.get("guisetupgui.clickableMarkers");
        mapTapFeatures =
            new ChoiceGroup(
                Locale.get("guisetupgui.MapTapFeatures") /*Map Touch Features*/,
                Choice.MULTIPLE,
                touch,
                null);
        i = 0;
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_LONG));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_DOUBLE));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_MAPTAP_SINGLE));
        mapTapFeatures.setSelectedIndex(
            i++, Configuration.getCfgBitState(Configuration.CFGBIT_CLICKABLE_MAPOBJECTS));
        append(mapTapFeatures);
      }

      // search options
      int iMax = 3;
      if (Configuration.getHasPointerEvents()) {
        iMax++;
      }
      // #if polish.android
      iMax++;
      // #endif
      String[] search = null;
      search = new String[iMax];
      int searchnum = 0;
      search[searchnum++] = Locale.get("guisetupgui.scroll") /*Scroll result under cursor*/;
      search[searchnum++] = Locale.get("guisetupgui.scrollall") /*Scroll all results*/;
      if (Configuration.getHasPointerEvents()) {
        search[searchnum++] = Locale.get("guisetupgui.numberkeypad") /*Enable virtual keypad*/;
      }
      search[searchnum++] =
          Locale.get(
              "guisetupgui.SuppressSearchWarning") /*Suppress warning about exceeding max results*/;
      // #if polish.android
      search[searchnum++] =
          Locale.get("guisetupgui.ShowNativeKeyboard") /*Show native keyboard in search*/;
      // #endif
      searchSettings =
          new ChoiceGroup(
              Locale.get("guisetupgui.searchopts") /*Search options:*/,
              Choice.MULTIPLE,
              search,
              null);
      /* only display search settings available on the device */
      // maximum search option entries
      searchnum = 0;
      searchSettings.setSelectedIndex(
          searchnum++, Configuration.getCfgBitSavedState(Configuration.CFGBIT_TICKER_ISEARCH));
      searchSettings.setSelectedIndex(
          searchnum++, Configuration.getCfgBitSavedState(Configuration.CFGBIT_TICKER_ISEARCH_ALL));
      if (Configuration.getHasPointerEvents()) {
        searchSettings.setSelectedIndex(
            searchnum++,
            Configuration.getCfgBitSavedState(Configuration.CFGBIT_SEARCH_TOUCH_NUMBERKEYPAD));
      }
      searchSettings.setSelectedIndex(
          searchnum++,
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_SUPPRESS_SEARCH_WARNING));
      // #if polish.android
      searchSettings.setSelectedIndex(
          searchnum++,
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_SEARCH_SHOW_NATIVE_KEYBOARD));
      // #endif
      append(searchSettings);
      String[] searchLayout = new String[2];
      searchLayout[0] = Locale.get("guidiscover.SearchWholeNames") /*Search for whole names*/;
      searchLayout[1] = Locale.get("guidiscover.SearchWords") /*Search for words*/;
      searchLayoutGroup =
          new ChoiceGroup(
              Locale.get("guidiscover.SearchStyle") /*Search style*/,
              Choice.EXCLUSIVE,
              searchLayout,
              null);
      searchLayoutGroup.setSelectedIndex(
          Configuration.getCfgBitSavedState(Configuration.CFGBIT_WORD_ISEARCH) ? 1 : 0, true);
      append(searchLayoutGroup);

      int searchMax = Configuration.getSearchMax();
      searchField =
          new TextField(
              Locale.get("guisetupgui.DefineMaxSearch") /*Max # of search results*/,
              Integer.toString(searchMax),
              8,
              TextField.DECIMAL);
      append(searchField);

      float dist = Configuration.getPoiSearchDistance();
      poiSearchDistance =
          new TextField(
              Locale.get("guisetupgui.PoiDistance") /*POI Distance: */,
              Float.toString(dist),
              8,
              TextField.ANY);
      append(poiSearchDistance);

      String[] otherSettings = new String[1];
      otherSettings[0] =
          Locale.get("guisetupgui.ExitWithBackButton") /* Back button exits application*/;
      otherGroup =
          new ChoiceGroup(
              Locale.get("guisetupgui.otherOptions") /* Other options */,
              Choice.MULTIPLE,
              otherSettings,
              null);
      otherGroup.setSelectedIndex(
          0,
          Configuration.getCfgBitSavedState(
              Configuration.CFGBIT_EXIT_APPLICATION_WITH_BACK_BUTTON));
      append(otherGroup);

      addCommand(CMD_SAVE);
      addCommand(CMD_CANCEL);

      // Set up this Displayable to listen to command events
      setCommandListener(this);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #10
0
  public void commandAction(Command c, Displayable d) {

    if (c == CMD_CANCEL) {
      parent.show();
      return;
    }

    if (c == CMD_SAVE) {
      try {
        long mem = Long.parseLong(memField.getString());
        Configuration.setPhoneAllTimeMaxMemory(mem * 1024);
      } catch (NumberFormatException e) {
        // nothing to do (ignore content)
      }
      try {
        int searchMax = Integer.parseInt(searchField.getString());
        Configuration.setSearchMax(searchMax);
      } catch (NumberFormatException e) {
        // nothing to do (ignore content)
      }
      try {
        float dist = Float.parseFloat(poiSearchDistance.getString());
        Configuration.setPoiSearchDistance(dist);
      } catch (NumberFormatException e) {
        // nothing to do (ignore content)
      }

      Trace trace = Trace.getInstance();
      if (imenuOpts.isSelected(0)
          != Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS)) {
        trace.removeAllCommands();
        Configuration.setCfgBitSavedState(Configuration.CFGBIT_ICONMENUS, imenuOpts.isSelected(0));
        trace.addAllCommands();
      }
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_ICONMENUS_SETUP, imenuOpts.isSelected(1));
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_ICONMENUS_FULLSCREEN, imenuOpts.isSelected(2));
      if (Configuration.getCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_SPLITSCREEN)
          && !imenuOpts.isSelected(3)) {
        trace.stopShowingSplitScreen();
      }
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_ICONMENUS_SPLITSCREEN, imenuOpts.isSelected(3));
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_ICONMENUS_BIG_TAB_BUTTONS, imenuOpts.isSelected(4));
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_ICONMENUS_MAPPED_ICONS, imenuOpts.isSelected(5));
      // Configuration.setCfgBitSavedState(Configuration.CFGBIT_ICONMENUS_ROUTING_OPTIMIZED,
      //		imenuOpts.isSelected(5));
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_FAVORITES_IN_ROUTE_ICON_MENU, imenuOpts.isSelected(6));
      // When the GUI is to be optimized for routing and we have a default
      // backlight method, turn the backlight on.
      // boolean optimizedForRouting = imenuOpts.isSelected(5);
      boolean optimizedForRouting = imenuOpts.isSelected(5);
      if (initialSetup && optimizedForRouting) {
        if (Configuration.getDefaultDeviceBacklightMethodCfgBit() != 0) {
          Configuration.setCfgBitSavedState(Configuration.CFGBIT_BACKLIGHT_ON, true);
          ShareNav.getInstance().restartBackLightTimer();
        }
      }

      Trace.uncacheIconMenu();
      GuiDiscover.uncacheIconMenu();

      boolean searchLayout = (searchLayoutGroup.getSelectedIndex() == 1);

      if (searchLayout != Configuration.getCfgBitState(Configuration.CFGBIT_WORD_ISEARCH)) {
        Configuration.setCfgBitSavedState(Configuration.CFGBIT_WORD_ISEARCH, searchLayout);
      }
      int i = 0;
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_TICKER_ISEARCH, searchSettings.isSelected(i++));
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_TICKER_ISEARCH_ALL, searchSettings.isSelected(i++));
      if (Configuration.getHasPointerEvents()) {
        Configuration.setCfgBitSavedState(
            Configuration.CFGBIT_SEARCH_TOUCH_NUMBERKEYPAD, searchSettings.isSelected(i++));
      }

      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_SUPPRESS_SEARCH_WARNING, searchSettings.isSelected(i++));
      // #if polish.android
      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_SEARCH_SHOW_NATIVE_KEYBOARD, searchSettings.isSelected(i++));
      // #endif

      i = 0;
      if (Configuration.getHasPointerEvents()) {
        Configuration.setCfgBitSavedState(
            Configuration.CFGBIT_MAPTAP_LONG, mapTapFeatures.isSelected(i++));
        Configuration.setCfgBitSavedState(
            Configuration.CFGBIT_MAPTAP_DOUBLE, mapTapFeatures.isSelected(i++));
        Configuration.setCfgBitSavedState(
            Configuration.CFGBIT_MAPTAP_SINGLE, mapTapFeatures.isSelected(i++));
        Configuration.setCfgBitSavedState(
            Configuration.CFGBIT_CLICKABLE_MAPOBJECTS, mapTapFeatures.isSelected(i++));
      }

      Configuration.setCfgBitSavedState(
          Configuration.CFGBIT_EXIT_APPLICATION_WITH_BACK_BUTTON, otherGroup.isSelected(0));

      parent.show();
      return;
    }
  }