Android Open Source - trivial-password Account






From Project

Back to project page trivial-password.

License

The source code is released under:

MIT License

If you think the Android project trivial-password listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.hbabcock.trivialpassword;
//from   w w  w  .  j av a 2  s.c om
import java.util.ArrayList;
import java.util.UUID;

import org.json.JSONException;
import org.json.JSONObject;

/*
 * All the account data is stored in mData. The first element
 * is the account name, the second is the username, the third
 * is the password and the rest is extr account data.
 */
public class Account {
    private static final String DELIMITER = "\u001F";
    private static final String JSON_DATA = "data";
    private static final Integer nFields = 6;
    
  private UUID mId;
  private ArrayList<String> mData;

  public Account(){
    mId = UUID.randomUUID();
    mData = new ArrayList<String>();
    for (int j = 0;j < nFields; j++){
      mData.add("");
    }
  }

  public Account(ArrayList<String> data){
    mId = UUID.randomUUID();
    mData = data;
  }
  
  public Account (JSONObject json) throws JSONException {
    setFromString(json.getString(JSON_DATA));    
  }
  
  public Account (String s){
       String[] sData = s.split(DELIMITER, -1);
       mId = UUID.fromString(sData[0]);
       mData = new ArrayList<String>();
       for(int i=1;i<sData.length;i++){
         mData.add(sData[i]);
       }
  }

  public Account(UUID id, ArrayList<String> data){
    mId = id;
    mData = data;
  }
  
  public String getAccount(){
    return mData.get(0);
  }
  
  public ArrayList<String> getData(){
    return mData;
  }
  
  public UUID getId(){
    return mId;
  }
  
  public String getUsername(){
    return mData.get(1);
  }
    
  public void setFromString(String s){
       String[] sData = s.split(DELIMITER, -1);
       mId = UUID.fromString(sData[0]);
       ArrayList<String> data = new ArrayList<String>();
       for(int i=1;i<sData.length;i++){
         data.add(sData[i]);
       }
       mData = data;
  }
  
  public JSONObject toJSON() throws JSONException {
    JSONObject json = new JSONObject();
    json.put(JSON_DATA, toString());
    return json;
  }
  
  @Override
  public String toString(){
      StringBuilder accountData = new StringBuilder();
      accountData.append(mId.toString());
      accountData.append(DELIMITER);      
      for(String datum : mData){
          accountData.append(datum);
          accountData.append(DELIMITER);
        }
      accountData.setLength(accountData.length() - DELIMITER.length());
      return accountData.toString();
  }

}




Java Source Code List

org.hbabcock.trivialpassword.AccountEditorFragment.java
org.hbabcock.trivialpassword.AccountFragment.java
org.hbabcock.trivialpassword.AccountListActivity.java
org.hbabcock.trivialpassword.AccountListFragment.java
org.hbabcock.trivialpassword.AccountManager.java
org.hbabcock.trivialpassword.AccountPagerActivity.java
org.hbabcock.trivialpassword.Account.java
org.hbabcock.trivialpassword.PasswordActivity.java
org.hbabcock.trivialpassword.PasswordChangeFragment.java
org.hbabcock.trivialpassword.PasswordFragment.java
org.hbabcock.trivialpassword.PasswordManager.java
org.hbabcock.trivialpassword.SingleFragmentActivity.java
org.hbabcock.trivialpassword.TrivialPasswordJSONSerializer.java