コード例 #1
0
ファイル: MainListFragment.java プロジェクト: liangxm/PwdBook
 public void selectCategory(int category_id, boolean forceUpdate) {
   if (mCategoryId != category_id || forceUpdate) {
     mCategoryId = category_id;
     if ((mAdapter = getAdapter(mCategoryId)) == null) {
       mAdapter =
           new MainListAdapter(
               getActivity(),
               AccountManager.getInstance().getAccountsByCategory(mCategoryId),
               Application.getThemedIcons(),
               R.drawable.pb_unknown);
       mListView.postDelayed(
           new Runnable() {
             @Override
             public void run() {
               mAdapter.enableAnimation(false);
             }
           },
           100);
       cacheAdapter(mCategoryId, mAdapter);
     }
     mAdapter.setListener(this);
     mListView.setAdapter(mAdapter);
     mAdapter.notifyDataSetChanged();
     mToBeRemoved = new int[mAdapter.getCount()];
     ((TextView) mListView.getEmptyView()).setText(R.string.no_accounts);
     mCategoryIcon = -1;
     mCategoryName = null;
   }
 }
コード例 #2
0
ファイル: MainListFragment.java プロジェクト: liangxm/PwdBook
 public void setSearch(ArrayList<AccountManager.Account> result) {
   mAdapter =
       new MainListAdapter(
           getActivity(), result, Application.getThemedIcons(), R.drawable.pb_unknown);
   mAdapter.enableAnimation(false);
   mAdapter.setListener(this);
   mListView.setAdapter(mAdapter);
   mAdapter.notifyDataSetChanged();
   mToBeRemoved = new int[mAdapter.getCount()];
   ((TextView) mListView.getEmptyView()).setText(R.string.empty_search);
 }
コード例 #3
0
ファイル: MainListFragment.java プロジェクト: liangxm/PwdBook
 public void editCategory() {
   if (mIsEditing) {
     return;
   }
   mIsEditing = true;
   mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mEditCategoryCallback);
   EditText editCategoryName = (EditText) mCategoryEditView.findViewById(R.id.category_name);
   mCategoryIconView = (ImageView) mCategoryEditView.findViewById(R.id.category_icon);
   mCategoryEditView.setVisibility(View.VISIBLE);
   int[] icons = Application.getThemedIcons();
   AccountManager.Category category = AccountManager.getInstance().getCategory(mCategoryId);
   if (mCategoryName == null) {
     mCategoryName = mCategoryId > AccountManager.DEFAULT_CATEGORY_ID ? category.mName : "";
   }
   if (mCategoryIcon < 0) {
     mCategoryIcon =
         mCategoryId > AccountManager.DEFAULT_CATEGORY_ID ? category.mImgCode : icons.length - 1;
   }
   editCategoryName.setText(mCategoryName);
   mCategoryIconView.setImageResource(icons[mCategoryIcon]);
   mCategoryIconView.setOnClickListener(this);
   mCategoryIconView.setColorFilter(C.ThemedColors[C.colorTextNormal]);
   updateListForEditing();
 }
コード例 #4
0
ファイル: MainListFragment.java プロジェクト: liangxm/PwdBook
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    mListView = (ListView) rootView.findViewById(android.R.id.list);
    if ((mAdapter = getAdapter(mCategoryId)) == null) {
      mAdapter =
          new MainListAdapter(
              getActivity(),
              AccountManager.getInstance().getAccountsByCategory(mCategoryId),
              Application.getThemedIcons(),
              R.drawable.pb_unknown);
      mListView.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              mAdapter.enableAnimation(false);
            }
          },
          100);
      cacheAdapter(mCategoryId, mAdapter);
    }
    mAdapter.setListener(this);
    mListView.setAdapter(mAdapter);
    mListView.setEmptyView(rootView.findViewById(android.R.id.empty));
    mListView.setOnItemClickListener(this);
    mListView.setOnItemLongClickListener(this);
    mToBeRemoved = new int[mAdapter.getCount()];
    mFab = (ImageButton) rootView.findViewById(R.id.fab);
    mFab.setOnClickListener(this);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
      LayerDrawable background = (LayerDrawable) mFab.getBackground();
      background
          .getDrawable(1)
          .setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
    }
    if (!getResources().getBoolean(R.bool.snackbar_left_align)) {
      mFabToPush = (int) (getResources().getDimension(R.dimen.snackbar_height_single) + 0.5f);
    } else {
      mFabToPush = 0;
    }
    mCategoryEditView = rootView.findViewById(R.id.category_editor);
    EditText editCategoryName = (EditText) rootView.findViewById(R.id.category_name);
    editCategoryName.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

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

          @Override
          public void afterTextChanged(Editable s) {
            if (mActionMode != null) {
              mCategoryName = s.toString();
              mCategorySavable = mCategoryName.length() > 0;
              mActionMode.invalidate();
            }
          }
        });
    if (mIsEditing) {
      mIsEditing = false;
      editCategory();
    } else if (mSelectionMode) {
      mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback);
    }
    return rootView;
  }