@Override
 public void onDestroyView() {
   if (mList != null) {
     mList.setOnKeyListener(null);
   }
   mList = null;
   mHandler.removeCallbacks(mRequestFocus);
   mHandler.removeMessages(MSG_BIND_PREFERENCES);
   super.onDestroyView();
 }
 private void ensureList() {
   if (mList != null) {
     return;
   }
   View root = getView();
   if (root == null) {
     throw new IllegalStateException("Content view not yet created");
   }
   View rawListView = root.findViewById(android.R.id.list);
   if (!(rawListView instanceof ListView)) {
     throw new RuntimeException(
         "Content has view with id attribute 'android.R.id.list' "
             + "that is not a ListView class");
   }
   mList = (ListView) rawListView;
   mList.setOnKeyListener(mListOnKeyListener);
   mHandler.post(mRequestFocus);
 }
Пример #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View view = inflater.inflate(R.layout.tab_tags_layout, container, false);

    // instantiate views
    noTagsMsg = (TextView) view.findViewById(R.id.vt_no_tags_msg);
    tagListView = (ListView) view.findViewById(R.id.vt_tag_list);
    //		tagListView.setOnTouchListener(new touchClickListener());
    createTagEdit = (EditText) view.findViewById(R.id.vt_create_tag_edit);
    editCasttoTextView = (TextView) view.findViewById(R.id.vt_create_tag_edit);
    charCount = (TextView) view.findViewById(R.id.vt_char_count);
    arrowIcon = (ImageView) view.findViewById(R.id.vt_send_arrow);
    arrowIcon.setOnClickListener(new createTagOnClick());

    createTagEdit.addTextChangedListener(
        new TextWatcher() {
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void onTextChanged(CharSequence s, int start, int before, int count) {}

          public void afterTextChanged(Editable s) {
            int remainingCount = charMax - s.length();
            charCount.setText(remainingCount + "");
            if (remainingCount < 0) {
              charCount.setTextColor(0xffed1c24);
              arrowIcon.setColorFilter(0x77ff0000);
            } else {
              charCount.setTextColor(0xff3c3c3c);
              arrowIcon.setColorFilter(0x00000000);
            }
          }
        });

    // set up adapter and ad
    LocStack stack = ((MainActivity) getActivity()).locStack;

    tags = ((TagLocWrapper) ((MainActivity) getActivity()).locStack.getCurrent()).getTagList();
    adapter = new TagListAdapter(getActivity(), tags.getTags());
    // get and set an ad for the tag list
    LayoutInflater adInflater = getActivity().getLayoutInflater();
    header = (ViewGroup) adInflater.inflate(R.layout.ad_layout, tagListView, false);
    tagListView.addHeaderView(header, null, false);
    header.requestFocus();
    WebserviceClient.getAnAd(getActivity(), new AdRespHandler());
    tagListView.setAdapter(adapter);

    // set onKeyListener for tagListView to navigate
    tagListView.setOnKeyListener(
        new OnKeyListener() {

          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && v.hasFocus()) {
              ((MainActivity) getActivity()).focusTagTab();
              return true;
            } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && v.hasFocus()) {
              ((MainActivity) getActivity()).focusEditbox();
              return true;
            }
            return false;
          }
        });

    // get shared preferences
    tagInfo = Ttagit.getAppContext().getSharedPreferences("tag", 0);
    return view;
  }