示例#1
0
  /** Handles key events in a AppsCustomize tab between the last tab view and the shop button. */
  static boolean handleAppsCustomizeTabKeyEvent(View v, int keyCode, KeyEvent e) {
    final TabHost tabHost = findTabHostParent(v);
    final ViewGroup contents = tabHost.getTabContentView();
    final View shop = null;

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (handleKeyEvent) {
          // Select the shop button if we aren't on it
          if (v != shop) {
            shop.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_DOWN:
        if (handleKeyEvent) {
          // Select the content view (down is handled by the tab key handler otherwise)
          if (v == shop) {
            contents.requestFocus();
            wasHandled = true;
          }
        }
        break;
      default:
        break;
    }
    return wasHandled;
  }
示例#2
0
  public void updateOnBroadcast() {
    LinkedList<Tag> tagList = tags.getTags();

    if (getActivity() == null) return;

    if (tagList.size() > 0) {
      noTagsMsg.setVisibility(View.GONE);
    } else {
      noTagsMsg.setVisibility(View.VISIBLE);
    }

    if (tagListView.getAdapter() == null) {
      adapter = new TagListAdapter(getActivity(), tagList);

      // get and set an ad for the tag list
      LayoutInflater inflater = getActivity().getLayoutInflater();
      header = (ViewGroup) inflater.inflate(R.layout.ad_layout, tagListView, false);
      tagListView.addHeaderView(header, null, false);
      header.requestFocus();
      WebserviceClient.getAnAd(getActivity(), new AdRespHandler());

      tagListView.setAdapter(adapter);
    } else {
      adapter.updateAdapterContents(tagList);
    }
    // hide progress bar
    ((MainActivity) getActivity()).showProgBar(false);
  }
示例#3
0
  /** Handles key events in the tab widget. */
  static boolean handleTabKeyEvent(AccessibleTabView v, int keyCode, KeyEvent e) {
    if (true) return false;

    final FocusOnlyTabWidget parent = (FocusOnlyTabWidget) v.getParent();
    final TabHost tabHost = findTabHostParent(parent);
    final ViewGroup contents = tabHost.getTabContentView();
    final int tabCount = parent.getTabCount();
    final int tabIndex = parent.getChildTabIndex(v);

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_LEFT:
        if (handleKeyEvent) {
          // Select the previous tab
          if (tabIndex > 0) {
            parent.getChildTabViewAt(tabIndex - 1).requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (handleKeyEvent) {
          // Select the next tab, or if the last tab has a focus right id, select that
          if (tabIndex < (tabCount - 1)) {
            parent.getChildTabViewAt(tabIndex + 1).requestFocus();
          } else {
            if (v.getNextFocusRightId() != View.NO_ID) {
              tabHost.findViewById(v.getNextFocusRightId()).requestFocus();
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_UP:
        // Do nothing
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_DOWN:
        if (handleKeyEvent) {
          // Select the content view
          contents.requestFocus();
        }
        wasHandled = true;
        break;
      default:
        break;
    }
    return wasHandled;
  }
  @Test
  public void clearFocus_shouldRecursivelyClearTheFocusOfAllChildren() throws Exception {
    child3a.requestFocus();

    root.clearFocus();

    assertFalse(child3a.hasFocus());
    assertFalse(child3.hasFocus());
    assertFalse(root.hasFocus());

    root.requestFocus();
    root.clearFocus();
    assertFalse(root.hasFocus());
  }
  @Test
  public void hasFocus_shouldReturnTrueIfAnyChildHasFocus() throws Exception {
    assertFalse(root.hasFocus());

    child1.requestFocus();
    assertTrue(root.hasFocus());

    child1.clearFocus();
    assertFalse(root.hasFocus());

    child3b.requestFocus();
    assertTrue(root.hasFocus());

    child3b.clearFocus();
    assertFalse(root.hasFocus());

    root.requestFocus();
    assertTrue(root.hasFocus());
  }
示例#6
0
  // Put up our own UI for how to handle the decoded contents.
  private void handleDecodeInternally(
      Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(
          BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    CharSequence displayContents = resultHandler.getDisplayContents();
    final String sptm = displayContents.toString().trim();
    // 2013-12-09,cj,显示药品详情
    SpkfkService spService = new SpkfkService(CaptureActivity.this);
    final AdvSpkfk sp = spService.getByBarcode(displayContents.toString());
    if (sp != null) {
      displayContents = displayContents + "\n" + spService.toString(sp);
    } else {
      displayContents = displayContents + "\n未找到相关商品";
    }

    contentsTextView.setText(displayContents);
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    /*2013-12-10,cj,简化,此处查询尝试去亚马逊查询商品信息
       TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
       supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
       if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
           PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
         SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
                                                        resultHandler.getResult(),
                                                        historyManager,
                                                        this);
       }
    	*/

    // 2013-12-09,cj,添加,设置回退按钮,功能同按返回键
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x == 0) {
        button.setVisibility(View.VISIBLE);
        button.setText("继续扫码");
        button.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
              }
            });
      } else if (x == 1) {
        String btnText = "";
        if (sp == null) {
          btnText = "寻找商品";
        } else {
          btnText = "商品资料";
        }
        button.setVisibility(View.VISIBLE);
        button.setText(btnText);
        button.setOnClickListener(
            new OnClickListener() {
              @Override
              public void onClick(View v) {
                if (sp == null) {
                  Intent intent = new Intent(CaptureActivity.this, SpkfkSelectActivity.class);
                  intent.setFlags(SpkfkSelectActivity.FLAG_FIND_SP);
                  intent.putExtra(EXTRA_NAME_SPTM, sptm);
                  startActivity(intent);
                } else {
                  // TODO
                  Toast.makeText(CaptureActivity.this, "暂未实现功能", Toast.LENGTH_LONG).show();
                  // 启动商品详情activity
                  Intent intent = new Intent(CaptureActivity.this, SpkfkDetailActivity.class);
                  intent.putExtra(SpkfkDetailActivity.EXTRA_NAME_SPKFK, sp);
                  startActivity(intent);
                }
                // restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
              }
            });
      } else {
        button.setVisibility(View.GONE);
      }
    }

    /*2013-12-10,cj,简化,此处根据条码类型来显示不同的按钮
    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }
    */

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardInterface.setText(displayContents, this);
    }
  }
  // Put up our own UI for how to handle the decoded contents.
  private void handleDecodeInternally(
      Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(fakeR.getId("id", "barcode_image_view"));
    if (barcode == null) {
      barcodeImageView.setImageBitmap(
          BitmapFactory.decodeResource(getResources(), fakeR.getId("drawable", "launcher_icon")));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(fakeR.getId("id", "format_text_view"));
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(fakeR.getId("id", "type_text_view"));
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
    TextView timeTextView = (TextView) findViewById(fakeR.getId("id", "time_text_view"));
    timeTextView.setText(formattedTime);

    TextView metaTextView = (TextView) findViewById(fakeR.getId("id", "meta_text_view"));
    View metaTextViewLabel = findViewById(fakeR.getId("id", "meta_text_view_label"));
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(fakeR.getId("id", "contents_text_view"));
    CharSequence displayContents = resultHandler.getDisplayContents();
    contentsTextView.setText(displayContents);
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView =
        (TextView) findViewById(fakeR.getId("id", "contents_supplement_text_view"));
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    if (PreferenceManager.getDefaultSharedPreferences(this)
        .getBoolean(PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
      SupplementalInfoRetriever.maybeInvokeRetrieval(
          supplementTextView, resultHandler.getResult(), historyManager, this);
    }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(fakeR.getId("id", "result_button_view"));
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
      if (displayContents != null) {
        clipboard.setText(displayContents);
      }
    }
  }
  // Put up our own UI for how to handle the decoded contents.
  private void handleDecodeInternally(
      Result rawResult, ResultHandler resultHandler, Bitmap barcode) {

    CharSequence displayContents = resultHandler.getDisplayContents();

    if (copyToClipboard && !resultHandler.areContentsSecure()) {
      ClipboardInterface.setText(displayContents, this);
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    if (resultHandler.getDefaultButtonID() != null
        && prefs.getBoolean(PreferencesActivity.KEY_AUTO_OPEN_WEB, false)) {
      resultHandler.handleButtonPress(resultHandler.getDefaultButtonID());
      return;
    }

    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(
          BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formatter.format(new Date(rawResult.getTimestamp())));

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    contentsTextView.setText(displayContents);
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    TextView supplementTextView = (TextView) findViewById(R.id.contents_supplement_text_view);
    supplementTextView.setText("");
    supplementTextView.setOnClickListener(null);
    // if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
    // PreferencesActivity.KEY_SUPPLEMENTAL, true)) {
    // SupplementalInfoRetriever.maybeInvokeRetrieval(supplementTextView,
    // resultHandler.getResult(),
    // historyManager,
    // this);
    // }

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }
  }
  // Put up our own UI for how to handle the decoded contents.
  private void handleDecodeInternally(Result rawResult, Bitmap barcode) {
    statusView.setVisibility(View.GONE);
    viewfinderView.setVisibility(View.GONE);
    resultView.setVisibility(View.VISIBLE);

    ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    if (barcode == null) {
      barcodeImageView.setImageBitmap(
          BitmapFactory.decodeResource(getResources(), R.drawable.launcher_icon));
    } else {
      barcodeImageView.setImageBitmap(barcode);
    }

    TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    formatTextView.setText(rawResult.getBarcodeFormat().toString());

    ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
    TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    typeTextView.setText(resultHandler.getType().toString());

    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
    TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    timeTextView.setText(formattedTime);

    TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    metaTextView.setVisibility(View.GONE);
    metaTextViewLabel.setVisibility(View.GONE);
    Map<ResultMetadataType, Object> metadata =
        (Map<ResultMetadataType, Object>) rawResult.getResultMetadata();
    if (metadata != null) {
      StringBuilder metadataText = new StringBuilder(20);
      for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
        if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
          metadataText.append(entry.getValue()).append('\n');
        }
      }
      if (metadataText.length() > 0) {
        metadataText.setLength(metadataText.length() - 1);
        metaTextView.setText(metadataText);
        metaTextView.setVisibility(View.VISIBLE);
        metaTextViewLabel.setVisibility(View.VISIBLE);
      }
    }

    TextView contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    CharSequence displayContents = resultHandler.getDisplayContents();
    contentsTextView.setText(displayContents);
    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);

    int buttonCount = resultHandler.getButtonCount();
    ViewGroup buttonView = (ViewGroup) findViewById(R.id.result_button_view);
    buttonView.requestFocus();
    for (int x = 0; x < ResultHandler.MAX_BUTTON_COUNT; x++) {
      TextView button = (TextView) buttonView.getChildAt(x);
      if (x < buttonCount) {
        button.setVisibility(View.VISIBLE);
        button.setText(resultHandler.getButtonText(x));
        button.setOnClickListener(new ResultButtonListener(resultHandler, x));
      } else {
        button.setVisibility(View.GONE);
      }
    }

    if (copyToClipboard) {
      ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
      clipboard.setText(displayContents);
    }
  }
示例#10
0
  /** Handles key events in a Workspace containing. */
  static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
    ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
    final CellLayout layout = (CellLayout) parent.getParent();
    if (!(layout.getParent() instanceof Workspace)) return false;
    final Workspace workspace = (Workspace) layout.getParent();
    final ViewGroup launcher = (ViewGroup) workspace.getParent();
    final ViewGroup tabs = null;
    final ViewGroup hotseat = null;
    int pageIndex = workspace.indexOfChild(layout);
    int pageCount = workspace.getChildCount();

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_LEFT:
        if (handleKeyEvent) {
          // Select the previous icon or the last icon on the previous page if possible
          View newIcon = getIconInDirection(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            if (pageIndex > 0) {
              parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
              newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
              if (newIcon != null) {
                newIcon.requestFocus();
              } else {
                // Snap to the previous page
                workspace.snapToPage(pageIndex - 1);
              }
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (handleKeyEvent) {
          // Select the next icon or the first icon on the next page if possible
          View newIcon = getIconInDirection(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            if (pageIndex < (pageCount - 1)) {
              parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
              newIcon = getIconInDirection(layout, parent, -1, 1);
              if (newIcon != null) {
                newIcon.requestFocus();
              } else {
                // Snap to the next page
                workspace.snapToPage(pageIndex + 1);
              }
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_UP:
        if (handleKeyEvent) {
          // Select the closest icon in the previous line, otherwise select the tab bar
          View newIcon = getClosestIconOnLine(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
            wasHandled = true;
          } else {
            if (tabs != null) tabs.requestFocus();
          }
        }
        break;
      case KeyEvent.KEYCODE_DPAD_DOWN:
        if (handleKeyEvent) {
          // Select the closest icon in the next line, otherwise select the button bar
          View newIcon = getClosestIconOnLine(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
            wasHandled = true;
          } else if (hotseat != null) {
            hotseat.requestFocus();
          }
        }
        break;
      case KeyEvent.KEYCODE_PAGE_UP:
        if (handleKeyEvent) {
          // Select the first icon on the previous page or the first icon on this page
          // if there is no previous page
          if (pageIndex > 0) {
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            } else {
              // Snap to the previous page
              workspace.snapToPage(pageIndex - 1);
            }
          } else {
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_PAGE_DOWN:
        if (handleKeyEvent) {
          // Select the first icon on the next page or the last icon on this page
          // if there is no previous page
          if (pageIndex < (pageCount - 1)) {
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            } else {
              // Snap to the next page
              workspace.snapToPage(pageIndex + 1);
            }
          } else {
            View newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
            if (newIcon != null) {
              newIcon.requestFocus();
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_HOME:
        if (handleKeyEvent) {
          // Select the first icon on this page
          View newIcon = getIconInDirection(layout, parent, -1, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_END:
        if (handleKeyEvent) {
          // Select the last icon on this page
          View newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      default:
        break;
    }
    return wasHandled;
  }
示例#11
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;
  }