コード例 #1
0
  private void createActionBarMenu() {
    ActionBarMenu menu = actionBarLayer.createMenu();
    menu.clearItems();

    if (ContactsController.getInstance().contactsDict.get(user_id) == null) {
      TLRPC.User user = MessagesController.getInstance().users.get(user_id);
      if (user == null) {
        return;
      }
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      if (user.phone != null && user.phone.length() != 0) {
        item.addSubItem(
            add_contact, LocaleController.getString("AddContact", R.string.AddContact), 0);
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      } else {
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      }
    } else {
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      item.addSubItem(
          share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0);
      item.addSubItem(
          block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      item.addSubItem(
          edit_contact, LocaleController.getString("EditContact", R.string.EditContact), 0);
      item.addSubItem(
          delete_contact, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0);
    }
  }
コード例 #2
0
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
      actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
      if (isBroadcast) {
        actionBarLayer.setTitle(
            LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
      } else {
        actionBarLayer.setTitle(LocaleController.getString("NewGroup", R.string.NewGroup));
      }
      actionBarLayer.setSubtitle(
          LocaleController.formatString(
              "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));

      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == -1) {
                finishFragment();
              } else if (id == done_button) {
                if (!selectedContacts.isEmpty()) {
                  ArrayList<Integer> result = new ArrayList<Integer>();
                  result.addAll(selectedContacts.keySet());
                  Bundle args = new Bundle();
                  args.putIntegerArrayList("result", result);
                  args.putBoolean("broadcast", isBroadcast);
                  presentFragment(new GroupCreateFinalActivity(args));
                }
              }
            }
          });

      ActionBarMenu menu = actionBarLayer.createMenu();
      View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout);
      TextView doneTextView = (TextView) doneItem.findViewById(R.id.done_button);
      doneTextView.setText(LocaleController.getString("Next", R.string.Next));

      searching = false;
      searchWas = false;

      fragmentView = inflater.inflate(R.layout.group_create_layout, container, false);

      emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
      emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
      emptyTextView.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return true;
            }
          });
      userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text);
      userSelectEditText.setHint(
          LocaleController.getString("SendMessageTo", R.string.SendMessageTo));
      if (Build.VERSION.SDK_INT >= 11) {
        userSelectEditText.setTextIsSelectable(false);
      }
      userSelectEditText.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(
                CharSequence charSequence, int start, int count, int after) {
              if (!ignoreChange) {
                beforeChangeIndex = userSelectEditText.getSelectionStart();
                changeString = new SpannableString(charSequence);
              }
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (!ignoreChange) {
                boolean search = false;
                int afterChangeIndex = userSelectEditText.getSelectionEnd();
                if (editable.toString().length() < changeString.toString().length()) {
                  String deletedString = "";
                  try {
                    deletedString =
                        changeString.toString().substring(afterChangeIndex, beforeChangeIndex);
                  } catch (Exception e) {
                    FileLog.e("tmessages", e);
                  }
                  if (deletedString.length() > 0) {
                    if (searching && searchWas) {
                      search = true;
                    }
                    Spannable span = userSelectEditText.getText();
                    for (int a = 0; a < allSpans.size(); a++) {
                      XImageSpan sp = allSpans.get(a);
                      if (span.getSpanStart(sp) == -1) {
                        allSpans.remove(sp);
                        selectedContacts.remove(sp.uid);
                      }
                    }
                    actionBarLayer.setSubtitle(
                        LocaleController.formatString(
                            "MembersCount",
                            R.string.MembersCount,
                            selectedContacts.size(),
                            maxCount));
                    listView.invalidateViews();
                  } else {
                    search = true;
                  }
                } else {
                  search = true;
                }
                if (search) {
                  String text = userSelectEditText.getText().toString().replace("<", "");
                  if (text.length() != 0) {
                    searchDialogs(text);
                    searching = true;
                    searchWas = true;
                    emptyTextView.setText(
                        LocaleController.getString("NoResult", R.string.NoResult));
                    listViewAdapter.notifyDataSetChanged();
                  } else {
                    searchResult = null;
                    searchResultNames = null;
                    searching = false;
                    searchWas = false;
                    emptyTextView.setText(
                        LocaleController.getString("NoContacts", R.string.NoContacts));
                    listViewAdapter.notifyDataSetChanged();
                  }
                }
              }
            }
          });

      listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView);
      listView.setEmptyView(emptyTextView);
      listView.setVerticalScrollBarEnabled(false);

      listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
      listView.setOnItemClickListener(
          new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
              TLRPC.User user;
              int section = listViewAdapter.getSectionForPosition(i);
              int row = listViewAdapter.getPositionInSectionForPosition(i);
              if (searching && searchWas) {
                user = searchResult.get(row);
              } else {
                ArrayList<TLRPC.TL_contact> arr =
                    ContactsController.getInstance()
                        .usersSectionsDict
                        .get(
                            ContactsController.getInstance().sortedUsersSectionsArray.get(section));
                user = MessagesController.getInstance().getUser(arr.get(row).user_id);
                listView.invalidateViews();
              }
              if (selectedContacts.containsKey(user.id)) {
                XImageSpan span = selectedContacts.get(user.id);
                selectedContacts.remove(user.id);
                SpannableStringBuilder text =
                    new SpannableStringBuilder(userSelectEditText.getText());
                text.delete(text.getSpanStart(span), text.getSpanEnd(span));
                allSpans.remove(span);
                ignoreChange = true;
                userSelectEditText.setText(text);
                userSelectEditText.setSelection(text.length());
                ignoreChange = false;
              } else {
                if (selectedContacts.size() == maxCount) {
                  return;
                }
                ignoreChange = true;
                XImageSpan span = createAndPutChipForUser(user);
                span.uid = user.id;
                ignoreChange = false;
              }
              actionBarLayer.setSubtitle(
                  LocaleController.formatString(
                      "MembersCount", R.string.MembersCount, selectedContacts.size(), maxCount));
              if (searching || searchWas) {
                searching = false;
                searchWas = false;
                emptyTextView.setText(
                    LocaleController.getString("NoContacts", R.string.NoContacts));

                ignoreChange = true;
                SpannableStringBuilder ssb = new SpannableStringBuilder("");
                for (ImageSpan sp : allSpans) {
                  ssb.append("<<");
                  ssb.setSpan(
                      sp,
                      ssb.length() - 2,
                      ssb.length(),
                      SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                userSelectEditText.setText(ssb);
                userSelectEditText.setSelection(ssb.length());
                ignoreChange = false;

                listViewAdapter.notifyDataSetChanged();
              } else {
                listView.invalidateViews();
              }
            }
          });

      listView.setOnScrollListener(
          new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {
              if (i == SCROLL_STATE_TOUCH_SCROLL) {
                AndroidUtilities.hideKeyboard(userSelectEditText);
              }
            }

            @Override
            public void onScroll(
                AbsListView absListView,
                int firstVisibleItem,
                int visibleItemCount,
                int totalItemCount) {}
          });
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }
コード例 #3
0
ファイル: LoginActivity.java プロジェクト: JMQCode/Telegram
  @Override
  public View createView(LayoutInflater inflater, ViewGroup container) {
    if (fragmentView == null) {
      actionBarLayer.setDisplayUseLogoEnabled(true, R.drawable.ic_ab_logo);
      actionBarLayer.setTitle(LocaleController.getString("AppName", R.string.AppName));

      actionBarLayer.setActionBarMenuOnItemClick(
          new ActionBarLayer.ActionBarMenuOnItemClick() {
            @Override
            public void onItemClick(int id) {
              if (id == done_button) {
                onNextAction();
              }
            }
          });

      ActionBarMenu menu = actionBarLayer.createMenu();
      View doneItem = menu.addItemResource(done_button, R.layout.group_create_done_layout);
      TextView doneTextView = (TextView) doneItem.findViewById(R.id.done_button);
      doneTextView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());

      fragmentView = inflater.inflate(R.layout.login_layout, container, false);

      views[0] = (SlideView) fragmentView.findViewById(R.id.login_page1);
      views[1] = (SlideView) fragmentView.findViewById(R.id.login_page2);
      views[2] = (SlideView) fragmentView.findViewById(R.id.login_page3);

      try {
        if (views[0] == null || views[1] == null || views[2] == null) {
          FrameLayout parent = (FrameLayout) ((ScrollView) fragmentView).getChildAt(0);
          for (int a = 0; a < views.length; a++) {
            if (views[a] == null) {
              views[a] = (SlideView) parent.getChildAt(a);
            }
          }
        }
      } catch (Exception e) {
        FileLog.e("tmessages", e);
      }

      actionBarLayer.setTitle(views[0].getHeaderName());

      Bundle savedInstanceState = loadCurrentState();
      if (savedInstanceState != null) {
        currentViewNum = savedInstanceState.getInt("currentViewNum", 0);
      }
      for (int a = 0; a < views.length; a++) {
        SlideView v = views[a];
        if (v != null) {
          if (savedInstanceState != null) {
            v.restoreStateParams(savedInstanceState);
          }
          v.delegate = this;
          v.setVisibility(currentViewNum == a ? View.VISIBLE : View.GONE);
        }
      }
    } else {
      ViewGroup parent = (ViewGroup) fragmentView.getParent();
      if (parent != null) {
        parent.removeView(fragmentView);
      }
    }
    return fragmentView;
  }