Пример #1
0
 private AccountManager.Account getAccount() {
   AccountManager.Account account = AccountManager.getInstance().newAccount(mPosition);
   account.mId = mAccountId;
   for (EntryHolder eh : mEntries) {
     account.addEntry(eh.mEntryItem);
   }
   return account;
 }
Пример #2
0
 @Override
 public View onCreateView(
     LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   if (savedInstanceState != null && AccountManager.getInstance() == null) {
     return null;
   }
   View rootView = inflater.inflate(R.layout.fragment_edit, container, false);
   mContainer = (LinearLayout) rootView.findViewById(android.R.id.list);
   View footer = inflater.inflate(R.layout.add_field, container, false);
   footer.setOnClickListener(this);
   mNameEditText = (EditText) rootView.findViewById(android.R.id.title);
   mScroll = (PbScrollView) rootView.findViewById(R.id.scroll);
   mNameEditText.addTextChangedListener(this);
   mToolbarContainer = rootView.findViewById(R.id.toolbar_container);
   if (mToolbarContainer != null) {
     mHeader = rootView.findViewById(R.id.header);
     mScroll.setPbScrollListener(this);
   }
   setupToolbar(rootView);
   mCategorySpinner = (Spinner) rootView.findViewById(R.id.category);
   if (mAccountId >= 0) {
     mDummyAccount = AccountManager.getInstance().getAccountById(mAccountId).clone();
     mName = mDummyAccount.getAccountName();
   } else {
     mDummyAccount = getEntryList();
     mName = "";
   }
   int spinnerLayout =
       android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
           ? android.R.layout.simple_spinner_dropdown_item
           : R.layout.spinner_dropdown;
   mTypeAdapter =
       ArrayAdapter.createFromResource(
           getActivity(), R.array.field_types, android.R.layout.simple_spinner_dropdown_item);
   mTypeAdapter.setDropDownViewResource(spinnerLayout);
   mEntries = new ArrayList<>();
   mDeleteView = (ImageView) inflater.inflate(R.layout.delete_field, container, false);
   int pos = 0;
   for (Entry e : mDummyAccount.getEntryList()) {
     onAddField(e, pos++);
   }
   mContainer.addView(footer);
   mContainer.addView(mDeleteView);
   mDeleteView.setOnDragListener(mDragListener);
   ArrayAdapter<String> spinnerAdapter =
       new ArrayAdapter<>(
           getActivity(),
           android.R.layout.simple_spinner_dropdown_item,
           Application.getSortedCategoryNames());
   spinnerAdapter.setDropDownViewResource(spinnerLayout);
   mCategorySpinner.setAdapter(spinnerAdapter);
   mCategorySpinner.setOnItemSelectedListener(this);
   View top = rootView.findViewById(R.id.top_frame);
   if (top != null) {
     top.setOnClickListener(this);
   }
   return rootView;
 }
Пример #3
0
 private void save() {
   String name = mNameEditText.getText().toString();
   AccountManager.Account account = getAccount();
   account.setName(name);
   int categoryId = Application.getSortedCategoryIds()[mPosition];
   account.setCategory(categoryId);
   if (mAccountId < 0) {
     AccountManager.getInstance().addAccount(categoryId, account);
     if (mListener != null) {
       mListener.onSave(categoryId);
     }
   } else {
     AccountManager.getInstance().setAccount(mAccountId, account);
     if (mListener != null) {
       mListener.onSaveChanged(
           mAccountId, categoryId, mOldCategoryId, name.equals(account.getAccountName()));
     }
   }
   getActivity().onBackPressed();
 }
Пример #4
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.auto_gen:
       EntryHolder eh = (EntryHolder) v.getTag();
       requestPassword(eh.mValueField, eh.mEntryItem.mType);
       break;
     case R.id.close:
     case R.id.top_frame:
       getActivity().onBackPressed();
       break;
     default:
       onAddField(mDummyAccount.newEntry("", "", 1), mEntries.size());
       break;
   }
 }
Пример #5
-1
  private AccountManager.Account getDefaultTemplate(int id) {
    int intArrayIds[] = {
      R.array.index_5,
      R.array.index_0,
      R.array.index_1,
      R.array.index_2,
      R.array.index_3,
      R.array.index_4
    };
    Resources r = getResources();
    String[] defNames = r.getStringArray(R.array.def_field_names);
    int[] defTypes = r.getIntArray(R.array.def_field_types);
    int[] indexArray;
    AccountManager.Account account = AccountManager.getInstance().newAccount(id);
    if (id < intArrayIds.length) {
      indexArray = r.getIntArray(intArrayIds[id]);
    } else {
      indexArray = r.getIntArray(intArrayIds[0]);
    }
    for (int i : indexArray) {
      account.addEntry(defTypes[i], defNames[i], "");
    }

    return account;
  }