示例#1
0
  private void librariesInit(List<RecyclerViewItem> items) {
    CardView cardView = new CardView(getActivity());
    cardView.setTitle(getString(R.string.libraries_used));

    for (final String lib : sLibraries.keySet()) {
      DescriptionView descriptionView = new DescriptionView();
      descriptionView.setTitle(lib.split(",")[1]);
      descriptionView.setSummary(lib.split(",")[0]);
      descriptionView.setOnItemClickListener(
          new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
              Utils.launchUrl(sLibraries.get(lib), getActivity());
            }
          });

      cardView.addItem(descriptionView);
    }
    items.add(cardView);
  }
示例#2
0
  private void load(List<RecyclerViewItem> items) {
    for (final String initd : Initd.list()) {
      CardView cardView = new CardView(getActivity());
      cardView.setOnMenuListener(
          new CardView.OnMenuListener() {
            @Override
            public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
              Menu menu = popupMenu.getMenu();
              menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
              menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.delete));

              popupMenu.setOnMenuItemClickListener(
                  new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                      switch (item.getItemId()) {
                        case 0:
                          mEditInitd = initd;
                          Intent intent = new Intent(getActivity(), EditorActivity.class);
                          intent.putExtra(EditorActivity.TITLE_INTENT, initd);
                          intent.putExtra(EditorActivity.TEXT_INTENT, Initd.read(initd));
                          startActivityForResult(intent, 0);
                          break;
                        case 1:
                          mDeleteDialog =
                              ViewUtils.dialogBuilder(
                                  getString(R.string.sure_question),
                                  new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {}
                                  },
                                  new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                      Initd.delete(initd);
                                      reload();
                                    }
                                  },
                                  new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                      mDeleteDialog = null;
                                    }
                                  },
                                  getActivity());
                          mDeleteDialog.show();
                          break;
                      }
                      return false;
                    }
                  });
            }
          });

      DescriptionView descriptionView = new DescriptionView();
      descriptionView.setSummary(initd);
      descriptionView.setOnItemClickListener(
          new RecyclerViewItem.OnItemClickListener() {
            @Override
            public void onClick(RecyclerViewItem item) {
              mExecuteDialog =
                  ViewUtils.dialogBuilder(
                      getString(R.string.exceute_question, initd),
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {}
                      },
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                          execute(initd);
                        }
                      },
                      new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                          mExecuteDialog = null;
                        }
                      },
                      getActivity());
              mExecuteDialog.show();
            }
          });

      cardView.addItem(descriptionView);
      items.add(cardView);
    }
  }