Ejemplo n.º 1
0
 public void handleMessage(Message msg) {
   if (msg.what == 1) {
     if (lv.getCount() == 0) {
       lv.setSelection(0);
     } else {
       lv.setSelection(lv.getCount() - 1); // 发送一条消息时,ListView显示选择最后一项
     }
     setResult(1);
   } else {
     if (!NetUtils.hasNetwork(ChatActivity.this)) { // 检查网络
       Toast mtoast = new Toast(ChatActivity.this);
       String text = "网络错误,请检查网络";
       if (mtoast == null) { // 防止Toast重复弹出
         Toast.makeText(ChatActivity.this, text, Toast.LENGTH_SHORT).show();
       } else {
         mtoast.setText(text);
         mtoast.setDuration(Toast.LENGTH_SHORT);
       }
     } else {
       LogUtil.d("fail", "error");
       Toast mtoast = new Toast(ChatActivity.this);
       String text = "服务器繁忙";
       if (mtoast == null) { // 防止Toast重复弹出
         Toast.makeText(ChatActivity.this, text, Toast.LENGTH_SHORT).show();
       } else {
         mtoast.setText(text);
         mtoast.setDuration(Toast.LENGTH_SHORT);
       }
     }
   }
 }
Ejemplo n.º 2
0
 private void selectListItem(final ListView l, int num, boolean longClick) {
   final int n = Math.min(l.getCount(), Math.max(1, num)) - 1;
   requestFocus(l);
   Log.i("nofatclips", "Swapping to listview item " + num);
   solo.sendKey(Solo.DOWN);
   getActivity()
       .runOnUiThread(
           new Runnable() {
             public void run() {
               l.setSelection(n);
             }
           });
   sync();
   if (n < l.getCount() / 2) {
     solo.sendKey(Solo.DOWN);
     solo.sendKey(Solo.UP);
   } else {
     solo.sendKey(Solo.UP);
     solo.sendKey(Solo.DOWN);
   }
   sync();
   if (longClick) {
     longClick(l.getSelectedView());
   } else {
     click(l.getSelectedView());
   }
 }
Ejemplo n.º 3
0
 private void updateMeText() {
   int RId = R.layout.list_say_me_item;
   ChatMsgEntity newMessage = new ChatMsgEntity(me_text, null, null, RId, ME_ID);
   list.add(newMessage);
   mAdapter.notifyDataSetChanged();
   text_View.setSelection(text_View.getCount());
 }
  @Override
  protected void onBindDialogView(View view) {
    super.onBindDialogView(view);

    ListView list = (ListView) view.findViewById(R.id.dialog_preference_storage_list);

    list.setAdapter(new StoragesAdapter(getContext()));
    list.setOnItemClickListener(
        new OnItemClickAdapter<StorageMount>() {
          @Override
          public void onItemClick(
              AdapterView<?> parent,
              View view,
              AbstractAdapter<StorageMount> adapter,
              int position,
              long id) {
            selectedPath = adapter.getItem(position).path;

            // if you select the one that was there before dismiss the dialog.
            if (ConfigurationManager.instance().getStoragePath().equals(selectedPath)) {
              dismissPreferenceDialog();
            } else {
              // if you select the SD Card option, show the confirmation dialog, with ok button
              // disabled.
              // will be enabled after user clicks on checkbox.
              confirmDlg = createConfirmDialog(getContext());
              confirmDlg.show();
              confirmDlg.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
            }
          }
        });

    TextView warningText = (TextView) view.findViewById(R.id.dialog_preference_storage_warning);
    warningText.setVisibility(list.getCount() == 1 ? View.GONE : View.VISIBLE);
  }
Ejemplo n.º 5
0
  protected void onResume() {

    File file1 =
        new File(
            Environment.getExternalStorageDirectory().getAbsolutePath()
                + Constants.APP_FOLDER_TEMP);
    DeleteRecursive(file1);

    dbHelper = new AnnounceDBAdapter(this);
    dbHelper.open();
    displayListView();
    dbHelper.close();

    int temp = Integer.parseInt((getPreferences(MODE_PRIVATE).getString("listScroll", 0 + "")));
    Log.v("temp on resume", temp + "");
    listView.setSelection(temp);

    if (listView.getCount() < 1) {

      nomobcast.setVisibility(TextView.VISIBLE);

    } else {
      nomobcast.setVisibility(TextView.GONE);
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction("MyGCMMessageReceived");
    registerReceiver(receiver, filter);
    super.onResume();
  }
Ejemplo n.º 6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#006666")));
    setContentView(R.layout.contacts_picker_activity);
    mNames = Helpers.getAllContactNames();
    List<String> numbers = Helpers.getAllContactNumbers();
    ArrayList<String> output = getFormattedListEntries(mNames, numbers);
    listAdapter =
        new ArrayAdapter<>(this, android.R.layout.simple_list_item_multiple_choice, output);
    mListView = (ListView) findViewById(R.id.list);
    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setAdapter(listAdapter);

    String noteTitle;
    if (getIntent().getExtras() != null) {
      String checkedContacts = getIntent().getExtras().getString("pre_checked");
      noteTitle = getIntent().getExtras().getString("note");
      boolean revisitingTemporary = getIntent().getExtras().getBoolean("temporary_select");
      if (checkedContacts != null) {
        String[] pre_checked = checkedContacts.split(",");
        for (int i = 0; i < mListView.getCount(); i++) {
          for (String contact : pre_checked) {
            if (PhoneNumberUtils.compare(numbers.get(i), contact)) {
              mListView.setItemChecked(i, true);
            }
          }
        }
      } else if (revisitingTemporary) {
        // Just don't do anything
      } else {
        // checkContacts here
      }
    }
  }
 @Override
 public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
   final ListView listView = getListView();
   switch (item.getItemId()) {
     case R.id.delete:
       {
         final Expression where =
             Expression.in(
                 new Column(Filters._ID), new RawItemArray(listView.getCheckedItemIds()));
         mResolver.delete(getContentUri(), where.getSQL(), null);
         break;
       }
     case R.id.inverse_selection:
       {
         final SparseBooleanArray positions = listView.getCheckedItemPositions();
         for (int i = 0, j = listView.getCount(); i < j; i++) {
           listView.setItemChecked(i, !positions.get(i));
         }
         return true;
       }
     default:
       {
         return false;
       }
   }
   mode.finish();
   return true;
 }
Ejemplo n.º 8
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    int position = mList.getSelectedItemPosition();
    if ((position >= 0) && (position != (mList.getCount() - 1))) {
      // Selected one slide.
      if (position > 0) {
        menu.add(0, MENU_MOVE_UP, 0, R.string.move_up).setIcon(R.drawable.ic_menu_move_up);
      }

      if (position < (mSlideListAdapter.getCount() - 1)) {
        menu.add(0, MENU_MOVE_DOWN, 0, R.string.move_down).setIcon(R.drawable.ic_menu_move_down);
      }
      if (mSlideshowModel.size() < SlideshowEditor.MAX_SLIDE_NUM) {
        menu.add(0, MENU_ADD_SLIDE, 0, R.string.add_slide).setIcon(R.drawable.ic_menu_add_slide);
      }

      menu.add(0, MENU_REMOVE_SLIDE, 0, R.string.remove_slide)
          .setIcon(android.R.drawable.ic_menu_delete);
    } else {
      if (mSlideshowModel.size() < SlideshowEditor.MAX_SLIDE_NUM) {
        menu.add(0, MENU_ADD_SLIDE, 0, R.string.add_slide).setIcon(R.drawable.ic_menu_add_slide);
      }
    }

    menu.add(0, MENU_DISCARD_SLIDESHOW, 0, R.string.discard_slideshow)
        .setIcon(R.drawable.ic_menu_delete_played);

    return true;
  }
Ejemplo n.º 9
0
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
   if (position == (l.getCount() - 1)) {
     addNewSlide();
   } else {
     openSlide(position);
   }
 }
Ejemplo n.º 10
0
 @Override
 public void updateChatList(ChatMsgEntity entity) {
   mDataArrays.add(entity);
   mAdapter.notifyDataSetChanged();
   singleChatLv.setSelection(singleChatLv.getCount() - 1);
   delMsgAfterRead(mDataArrays.size(), entity); // handler处理阅后即焚消息
   countDowmList.add(COUNT_DOWN);
 }
Ejemplo n.º 11
0
 private boolean isBottom() {
   if (mListView.getCount() > 0) {
     if (mListView.getLastVisiblePosition() == mListView.getAdapter().getCount() - 1
         && mListView.getChildAt(mListView.getChildCount() - 1).getBottom()
             <= mListView.getHeight()) {
       return true;
     }
   }
   return false;
 }
 @Override
 public void onDestroyActionMode(ActionMode actionMode) {
   mActionMode = null;
   for (int i = 0; i < mListView.getCount(); i++) {
     mListView.setItemChecked(i, false);
   }
   mListView.clearChoices();
   mListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
   limparBusca();
 }
 public void testAddCourseScreenOriantationChange() {
   ListView listView;
   solo.clickOnView(getActivity().findViewById(R.id.add));
   solo.enterText(0, "Course");
   solo.clickOnEditText(0);
   solo.sendKey(Solo.ENTER);
   solo.waitForText("THE COURSE #2", 1, 5);
   listView = (ListView) solo.getView(android.R.id.list);
   assertEquals("List view should contain 2 items before doing anything", 2, listView.getCount());
   solo.setActivityOrientation(Solo.LANDSCAPE);
   solo.sleep(500);
   listView = (ListView) solo.getView(android.R.id.list);
   solo.sleep(3000);
   assertEquals("List view should't change size after oriantation change", 2, listView.getCount());
   assertEquals(
       "SearchView should not reset.", "Course", solo.getEditText(0).getText().toString());
   solo.goBack();
   solo.goBack();
 }
 public List<Host> getSelectedHosts() {
   SparseBooleanArray checked = hostList.getCheckedItemPositions();
   List<Host> ret = new LinkedList<Host>();
   for (int i = 0; i < hostList.getCount(); i++) {
     if (checked.get(i)) ret.add((Host) hostList.getItemAtPosition(i));
   }
   System.out.println("Selection:");
   System.out.println(ret);
   return ret;
 }
  public void onClick(View view) {
    ListView lstView = getListView();

    String itemsSelected = "Selected items: \n";
    for (int i = 0; i < lstView.getCount(); i++) {
      if (lstView.isItemChecked(i)) {
        itemsSelected += lstView.getItemAtPosition(i) + "\n";
      }
    }
    Toast.makeText(this, itemsSelected, Toast.LENGTH_LONG).show();
  }
Ejemplo n.º 16
0
 @Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   if (mmPullDownView != null) {
     if (singleChatLv.getCount() < dataCount) {
       mmPullDownView.setIsCloseTopAllowRefersh(false);
     } else {
       mmPullDownView.setIsCloseTopAllowRefersh(true);
     }
   }
 }
Ejemplo n.º 17
0
 private void initChatView() {
   // TODO Auto-generated method stub
   EMConversation conversation = EMChatManager.getInstance().getConversation(hxusernameString);
   Log.d("test1", "对话初始化成功");
   username.setText(nicknamrString); // 修改聊天对象名字
   messages = conversation.getAllMessages(); // 向环信拉取聊天记录,进行初始化
   conversation.resetUnreadMsgCount();
   mAdapter = new ChatAdapter(ChatActivity.this, messages, myPictureString, friendPictureString);
   lv.setAdapter(mAdapter);
   lv.setSelection(lv.getCount() - 1);
 }
Ejemplo n.º 18
0
  @SuppressWarnings("unchecked")
  public List<T> getChoices() {
    List<T> choices = new ArrayList<T>();

    for (int position = 0; position < listView.getCount(); position++) {
      if (isChosen(listView, position)) {
        choices.add((T) listView.getAdapter().getItem(position));
      }
    }

    return choices;
  }
Ejemplo n.º 19
0
 private View getViewById(int id) {
   for (int i = 0; i < mList.getCount(); i++) {
     View v = mList.getChildAt(i);
     if (v != null) {
       ItemHolder h = (ItemHolder) (v.getTag());
       if (h != null && h.alarm.id == id) {
         return v;
       }
     }
   }
   return null;
 }
 public void testEmptyCourseListClick() {
   ListView listView = (ListView) solo.getView(R.id.courses_list);
   View emptyview = listView.getEmptyView();
   assertEquals("EmptyView shoudl not be visible", View.GONE, emptyview.getVisibility());
   deleteAllCourses();
   assertEquals(0, listView.getCount());
   assertEquals("Empty view should be visible", View.VISIBLE, emptyview.getVisibility());
   solo.clickOnView(emptyview);
   solo.assertCurrentActivity(
       "Current activity shoudl Be the AddCourse Activity", AddCourseActivity.class);
   solo.goBack();
 }
Ejemplo n.º 21
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
      case (R.id.selectall):
        for (int i = 0; i < listContacts.getCount(); i++) {
          listContacts.setItemChecked(i, true);
        }
        break;
      case (R.id.deselectall):
        for (int i = 0; i < listContacts.getCount(); i++) {
          listContacts.setItemChecked(i, false);
        }
        break;

      case (R.id.syncme):
        SparseBooleanArray checked = listContacts.getCheckedItemPositions();
        for (int i = 0; i < checked.size(); i++) {
          int key = checked.keyAt(i);
          boolean value = checked.get(key);
          if (value) {
            if (selectedItemList.contains(listContacts.getItemAtPosition(key))) {
              Log.v(TAG, listContacts.getItemAtPosition(key).toString() + " is a duplicate!!!!");
            }
            selectedItemList.add((String) listContacts.getItemAtPosition(key));
          } else {

          }
        }
        // (TAG, "added " + selectedItemList.size() + " contacts to sync queue");
        CCC =
            new CreateContactsContent(
                getActivity().getApplicationContext(),
                getActivity().getContentResolver(),
                selectedItemList);
        if ((CCC != null) && (CCC.getStatus() != AsyncTask.Status.RUNNING)) {
          CCC.execute();
        }
    }
  }
Ejemplo n.º 22
0
  private void showMentions(boolean initEmpty) {
    if (isMentionsVisible) {
      return;
    }
    isMentionsVisible = true;

    GroupVM groupInfo = groups().get(peer.getPeerId());
    mentionsAdapter =
        new MentionsAdapter(
            groupInfo.getId(),
            this,
            new MentionsAdapter.MentionsUpdatedCallback() {

              @Override
              public void onMentionsUpdated(int oldRowsCount, int newRowsCount) {
                onMentionsChanged(oldRowsCount, newRowsCount);
              }
            },
            initEmpty);

    mentionsList.setAdapter(mentionsAdapter);
    mentionsList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Object item = parent.getItemAtPosition(position);
            if (item != null && item instanceof MentionFilterResult) {

              String origMention = ((MentionFilterResult) item).getMentionString();

              if (mentionStart != -1
                  && mentionStart + mentionSearchString.length() + 1
                      <= messageEditText.getText().length()) {

                String mentionString = origMention + ": ";

                Editable text = messageEditText.getText();

                int cursorPosition = mentionStart + mentionString.length();

                text.replace(
                    mentionStart, mentionStart + mentionSearchString.length() + 1, mentionString);

                messageEditText.setSelection(cursorPosition, cursorPosition);
              }
              hideMentions();
            }
          }
        });

    expandMentions(mentionsList, 0, mentionsList.getCount());
  }
 private void selectCurrentOption() {
   final String currentValue = getArguments().getString(FormFieldActivity.EXTRA_VALUE);
   if (null != currentValue) {
     for (int i = 0; i < listView.getCount(); i++) {
       final FormOption option = (FormOption) listView.getItemAtPosition(i);
       if (null != option && TextUtils.equals(option.getValue(), currentValue)) {
         listView.setItemChecked(i, true);
         listView.setSelection(i);
         break;
       }
     }
   }
 }
Ejemplo n.º 24
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.select_all:
       for (int i = 0; i < mListView.getCount(); i++) {
         mListView.setItemChecked(i, true);
       }
       return true;
     case R.id.unselect_all:
       for (int i = 0; i < mListView.getCount(); i++) {
         mListView.setItemChecked(i, false);
       }
       return true;
     case R.id.action_done:
       SparseBooleanArray array = mListView.getCheckedItemPositions();
       StringBuilder stringBuilder = new StringBuilder();
       StringBuilder namesBuilder = new StringBuilder();
       for (int i = 0; i < mListView.getCount(); i++) {
         if (array.get(i)) {
           String out = (String) mListView.getAdapter().getItem(i);
           String lines[] = out.split("\\r?\\n");
           stringBuilder.append(lines[1]).append(",");
           namesBuilder.append(lines[0]).append(",");
         }
       }
       Intent intent = new Intent();
       if (stringBuilder.length() != 0) {
         intent.putExtra("selected_contacts", stringBuilder.toString());
         intent.putExtra(
             "selected_names",
             getFormattedContacts(namesBuilder.toString(), stringBuilder.toString()));
       }
       intent.putExtra("temporary", true);
       setResult(AppGlobals.RESULT_OK, intent);
       finish();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Ejemplo n.º 25
0
  public static List<Computation> getSelectedComps() {

    List<Computation> selectedComps = new ArrayList<>();

    int count = listView.getCount();
    for (int i = 0; i < count; i++) {
      if (checkedState[i]) {
        selectedComps.add(allComps.get(i));
      }
    }

    return selectedComps;
  }
  // This Method returns the recipientIds ArrayList
  protected ArrayList<String> getRecipientIds() {
    // Create a new ArrayList
    ArrayList<String> recipientIds = new ArrayList<String>();

    // Check who is checked in the arraylist who is checked
    for (int i = 0; i < mListView.getCount(); i++) {

      if (mListView.isItemChecked(i)) {
        recipientIds.add(mFriends.get(i).getObjectId());
      }
    }
    return recipientIds;
  }
 public void onDataLoaded(
     final Loader<SynchronizedStateSavedList<ParcelableStatus, Long>> loader,
     final ParcelableStatusesAdapter adapter) {
   if (loader instanceof ParcelableStatusesLoader) {
     final Long last_viewed_id = ((ParcelableStatusesLoader) loader).getLastViewedId();
     if (last_viewed_id != null
         && mPreferences.getBoolean(PREFERENCE_KEY_REMEMBER_POSITION, true)) {
       final int position = adapter.findItemPositionByStatusId(last_viewed_id);
       if (position > -1 && position < mListView.getCount()) {
         mListView.setSelection(position);
       }
     }
   }
 }
 public void testDeleteCourses() {
   solo.clickOnCheckBox(1);
   solo.clickOnCheckBox(3);
   solo.clickOnCheckBox(5);
   solo.clickOnCheckBox(7);
   solo.clickOnView(getActivity().findViewById(R.id.delete));
   ListView listView = (ListView) solo.getView(R.id.courses_list);
   assertEquals("Listview should only contain 6 courses", 5, listView.getCount());
   for (int i = 0; i < 9; i++) {
     if (i % 2 == 0) {
       assertTrue(solo.searchText("Course #" + i));
     }
   }
 }
 private Character getSelectedChannelMaster() {
   try {
     if (channelMasterListView.getCheckedItemPosition() > channelMasterListView.getCount()
         || channelMasterListView.getCheckedItemPosition() == -1) {
       channelMasterListView.setItemChecked(0, true);
     }
     return channelMasterNamesAdapter
         .getItem(channelMasterListView.getCheckedItemPosition())
         .toString()
         .charAt(0);
   } catch (Exception e) {
     return null;
   }
 }
Ejemplo n.º 30
0
 void checkDistanceOrder(ListView tested) {
   Long distance = (long) 0;
   for (int itemIndex = 0; itemIndex < tested.getCount(); ++itemIndex) {
     ItineraryItem result = (ItineraryItem) tested.getItemAtPosition(itemIndex);
     if (distance == null) {
       assertTrue(result.getDistance() == null);
     } else if (result.getDistance() != null) {
       assertTrue(distance <= result.getDistance());
       distance = result.getDistance();
     } else {
       distance = null;
     }
   }
 }