public class Define {
    public static boolean DEBUG = false;
    
	public static String APP_ID = "125";
	public static String APP_SECRET = "1c5224ad2961704a6076c0bda127003933828a16";
	public static String PIN = null;
	public static String REAL_TOKEN = null;
	public static int USER_ID = -1;
	public static String TOKEN_SECRET = null;
	public static String APP_SECTION = null;
	
	public static String CURRENCY_CODE = null;
	public static String COUNTRY_CODE = null;;
	public static String TIMEZONE = null;
	public static String LOCALE_LANGUAGE = null;
	
	// General Key and Shared Preference Key
	public static String SHARED_PREFERENCE = "SHARED_AUTH";
	public static String KEY_SHARED_PIN = "SHARED_PIN";
	public static String KEY_SHARED_TOKEN = "SHARED_TOKEN";
	public static String KEY_SHARED_TOKEN_SECRET = "SHARED_TOKEN_SECRET";
	public static String KEY_SHARED_USER_ID = "SHARED_USER_ID";
	public static String KEY_SHARED_SECTION_ID = "SHARED_SECTION_ID";
	public static String KEY_SHARED_USER_INFO = "SHARED_USER_INFO";
	
	public static String KEY_SHARED_CURRENCY_CODE = "SHARED_CURRENCY_CODE";
	public static String KEY_SHARED_COUNTRY_CODE = "SHARED_COUNTRY_CODE";
	public static String KEY_SHARED_TIMEZONE = "SHARED_TIMEZONE";
	public static String KEY_SHARED_LOCALE_LANGUAGE = "SHARED_LOCALE_LANG";
	
	// Response/Request Key
	public static final int RESPONSE_EXIT = 10;
	public static final int REQUEST_AUTH = 50;
	public static final int REQUEST_NORMAL = 51;
	
	//Message
	public static final int MSG_REQ_AUTH = 100;
	public static final int MSG_FAIL = 101;
	public static final int MSG_AUTH_DONE = 102;
	public static final int MSG_AUTH_TOTAL_DONE = 103;
	public static final int MSG_USER_SETTING_DONE = 104;
	public static final int MSG_SETTING_DONE = 105;
	
	public static final int RESULT_OK = 200;
	public static final int RESULT_NONE_RECORD = 204;
	public static final int RESULT_ERROR = 400;
	public static final int RESULT_INSUFFIENT_API = 402;
	
	public static final int MSG_API_OK = 1000;
	public static final int MSG_API_FAIL = 1003;
	public static final int MSG_API_FAIL_WITH_404 = 404;
		
	public static final int API_GET_SECTIONS = 2010;
	public static final int API_GET_MAIN = 2020;
	public static final int API_GET_BUDGET = 2030;
	public static final int API_GET_BALANCE = 2040;

    public static final int API_GET_ENTRIES_LATEST = 2060;
    public static final int API_GET_ENTRIES_INSERT = 2061;
    public static final int API_GET_ENTRIES_LATEST_ITEMS = 2062;
    public static final int API_GET_PL = 2070;
    public static final int API_GET_MOUNTAIN = 2080;
    public static final int API_GET_ENTRIES = 2090;
    public static final int API_GET_BILL = 2100;
    
    // Post It
    public static final int API_GET_POST_IT = 2110;
    public static final int API_POST_POSTIT = 2111;
    public static final int API_PUT_POSTIT = 2112;
    public static final int API_DELETE_POSTIT = 2113;
    
    // Board
    public static final int API_GET_BOARD = 2190;
    public static final int API_GET_BOARD_BASE = 2200;
    public static final int API_GET_BOARD_FREE = 2200;
    public static final int API_GET_BOARD_MONEY_TALK = 2201;
    public static final int API_GET_BOARD_COUNSELING = 2202;
    public static final int API_GET_BOARD_WHOOING = 2203;
    
    //Board Article
    public static final int API_GET_BOARD_ARTICLE = 2210;
    public static final int API_POST_BOARD_ARTICLE = 2211;
    public static final int API_PUT_BOARD_ARTICLE = 2212;
    public static final int API_DELETE_BOARD_ARTICLE = 2213;
    
    
    public static final int API_POST_BOARD_REPLY = 2220;
    public static final int API_PUT_BOARD_REPLY = 2221;
    public static final int API_DELETE_BOARD_REPLY = 2222;
    
    //Board Comment
    public static final int API_GET_BOARD_COMMENT = 2230;
    public static final int API_POST_BOARD_COMMENT = 2231;
    public static final int API_PUT_BOARD_COMMENT = 2232;
    public static final int API_DELETE_BOARD_COMMENT = 2233;

    // Account
    public static final int API_GET_ACCOUNTS = 2300;
    public static final int API_POST_ACCOUNTS = 2301;
    public static final int API_PUT_ACCOUNTS = 2302;
    public static final int API_DELETE_ACCOUNTS = 2303;
    public static final int API_GET_ACCOUNT_EXISTS_ENTRIES = 2304;    
    
    // user
    public static final int API_GET_USER_INFO = 3000;
    public static final int API_PUT_USER_INFO = 3001;
    
    // etc
    public static final int API_GET_FREQUENT_ITEM = 3010;
    
    
	public static Typeface ROBOFONT = null;
    
    
    //flags
    //If there is need to be refreshed by insert some transaction or something like that
    //set this flag true
    public static boolean NEED_TO_REFRESH = false;
    
    public static boolean SHOW_NO_API_INFORM = false;
    
    public static void gettingLoginInfo(Context context){
    	if(context == null){
    		return;
    	}
    	/*
        if(Define.DEBUG){
            Define.REAL_TOKEN = "9772ff8e2f751ddf1c5cf74b0d9b328f392a4b71";
            Define.PIN = "339599";
            Define.TOKEN_SECRET = "7776e79057bc222254da0b108555afd86e3b7d3c";
            Define.APP_SECTION = "s10550";
            Define.USER_ID = 8955;
            Define.CURRENCY_CODE = "KRW";
            Define.COUNTRY_CODE="KR";
            Define.LOCALE_LANGUAGE = "ko";
        }*/
    	SharedPreferences prefs = context.getSharedPreferences(Define.SHARED_PREFERENCE, Context.MODE_PRIVATE);
        Define.REAL_TOKEN = prefs.getString(Define.KEY_SHARED_TOKEN, null);
        Define.PIN = prefs.getString(Define.KEY_SHARED_PIN, null);
        Define.TOKEN_SECRET = prefs.getString(Define.KEY_SHARED_TOKEN_SECRET, null);
        Define.APP_SECTION = prefs.getString(Define.KEY_SHARED_SECTION_ID, null);
        Define.USER_ID = prefs.getInt(Define.KEY_SHARED_USER_ID, 0);
        Define.CURRENCY_CODE = prefs.getString(Define.KEY_SHARED_CURRENCY_CODE, "USD");
        Define.COUNTRY_CODE = prefs.getString(Define.KEY_SHARED_COUNTRY_CODE, "US");
        Define.LOCALE_LANGUAGE = prefs.getString(Define.KEY_SHARED_LOCALE_LANGUAGE, "en");
        Define.TIMEZONE = prefs.getString(Define.KEY_SHARED_TIMEZONE, null);
    }

} public class WhooingApplication extends Application {
    
    private static WhooingApplication sInstance;
    //using singleton
    private static DataRepository dataRepository = null;
    
    public static WhooingApplication getInstance(){
        return sInstance;
    }
    
    public synchronized DataRepository getRepo(){
        if(dataRepository == null){
            Log.d("wisedog", "DataRepository is just created");
            dataRepository = new DataRepository();
        }
        return dataRepository;
    }
    
    @Override
    public void onCreate() {
      super.onCreate();  
      sInstance = this;
      sInstance.initializeInstance();
    }

    private void initializeInstance() {
        dataRepository = new DataRepository();        
    }

} public class GeneralApi extends AbstractAPI {
    /**
     * Call RPC from given API
     * @param   url         Url address to call
     * @param   appID       Application ID
     * @param   token       Token
     * @param   appKey      Application Key
     * @param   tokenSecret Secret key for token
     * @return  Returns JSONObject for result, or null if it fails      
     * */
    public JSONObject getInfo(String url, String appID, 
    		String token, String appKey, String tokenSecret){
        return callApi(url, appID, token, appKey, tokenSecret);
    }
} public class AccountsEntity implements Parcelable{
    /** String for Asset, liabilities and so on*/
    public String accountType = null;
    /** account id like X1, X2*/
    public String account_id = null;
    /** account type - 'account' or 'group*/
    public String type = null;
    /** The name of the accounts */
    public String title = null;
    /** Additional information for account*/
    public String memo = null;
    public int open_date = 0;
    public int close_date = 0;
    /** Account category. normal, steady, client .... */
    public String category = null;
    
    //only for liabilities
    public String opt_use_date = null;
    public int opt_pay_date = 0;
    public String opt_pay_account_id = null;
    
    public AccountsEntity(String account_type, JSONObject jsonObj) throws org.json.JSONException{
        if(jsonObj == null || account_type == null){
            return;
        }
        accountType = account_type;
        account_id = jsonObj.getString("account_id");
        type = jsonObj.getString("type");
        title = jsonObj.getString("title");
        memo = jsonObj.getString("memo");
        open_date = jsonObj.getInt("open_date");
        close_date = jsonObj.getInt("close_date");
        category = jsonObj.getString("category");


        if(account_type.equals("liabilities")){
            opt_use_date = jsonObj.getString("opt_use_date");
            opt_pay_account_id = jsonObj.getString("opt_pay_account_id");
            opt_pay_date = jsonObj.optInt("opt_pay_date", 0);
        }
    }
    
    public AccountsEntity(Parcel in){
        readFromParcel(in);
    }
    
    /**
     * 
     */
    public AccountsEntity() {
        ;//Do nothing
    }

    /* (non-Javadoc)
     * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
     */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(accountType);
        dest.writeString(account_id);
        dest.writeString(type);
        dest.writeString(title);
        dest.writeString(memo);
        dest.writeInt(open_date);
        dest.writeInt(close_date);
        dest.writeString(category);
        if(accountType.equals("liabilities")){
            dest.writeString(opt_use_date);
            dest.writeString(opt_pay_account_id);
            dest.writeInt(opt_pay_date);
        }
    }
    
    public void readFromParcel(Parcel in){
        accountType = in.readString();
        account_id = in.readString();
        type = in.readString();
        title = in.readString();
        memo = in.readString();
        open_date = in.readInt();
        close_date = in.readInt();
        category = in.readString();
        if(accountType.equals("liabilities")){
            opt_use_date = in.readString();
            opt_pay_account_id = in.readString();
            opt_pay_date = in.readInt();
        }else{
            opt_use_date = null;
            opt_pay_date = 0;
            opt_pay_account_id = null;
        }
        
    }
    
    public boolean compareEntity(AccountsEntity entity){
        if(entity == null){
            return false;
        }
        if(accountType.compareTo(entity.accountType) != 0){
            return false;
        }
        if(type.compareTo(entity.type) != 0){
            return false;
        }
        if(title.compareTo(entity.title) != 0){
            return false;
        }
        if(open_date != entity.open_date){
            return false;
        }
        if(close_date != entity.close_date){
            return false;
        }
        if(category.compareTo(entity.category) != 0){
            return false;
        }
        if(opt_pay_date != entity.opt_pay_date){
            return false;
        }
        
        //Belows are optional, so the values may be null
        if(memo != null){
            if(entity.memo != null){
                if(memo.compareTo(entity.memo) != 0){
                    return false;
                }                
            }else{
                ; // those are null also.
            }
        }
        if(opt_pay_account_id != null){
            if(entity.opt_pay_account_id != null){
                if(opt_pay_account_id.compareTo(entity.opt_pay_account_id) != 0){
                    return false;
                }                
            }
            else{
                ;   //those are null also.
            }
        }
        if(opt_use_date != null){
            if(entity.opt_use_date != null){
                if(opt_use_date.compareTo(entity.opt_use_date) != 0){
                    return false;
                }
                else{
                    ;//those are null also
                }
            }
        }       
        return false;
    }

    /* (non-Javadoc)
     * @see android.os.Parcelable#describeContents()
     */
    public int describeContents() {
        // do nothing
        return 0;
    }
    
    /**
     * @return  Integer value of opt_use_date. If opt_use_date is "pp~", return minus value. Otherwise return plus value.
     * */
    public int getUseDateInt(){
        int result = 0;
        try{
            result = Integer.parseInt(opt_use_date.replaceAll("[\\D]", ""));
        }
        catch(NumberFormatException e){
            result = 0;
            e.printStackTrace();
        }
        if(opt_use_date.contains("pp")){
            result = -(result);
        }
        return result;
    }
    
    /**
     * set use date by integer date 
     * @param   date    if integer value is less than 0, it pre-pre month. or it is pre-month.
     * */
    public void setUseDate(int date){
        if(date == 0)
            return;
        String pDate;
        if(date> 0){
            pDate = "p";
        }else{
            pDate = "pp";
        }
        this.opt_use_date = pDate + date;        
    }
    

    @SuppressWarnings("rawtypes")
    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
            public AccountsEntity createFromParcel(Parcel in) {
                 return new AccountsEntity(in);
           }

           public AccountsEntity[] newArray(int size) {
                return new AccountsEntity[size];
           }
       };   
} public class DataRepository{
    static public final int BS_MODE = 0;
    static public final int PL_MODE = 1;
    static public final int MOUNTAIN_MODE = 2;
    static public final int EXP_BUDGET_MODE = 3;
    static public final int USER_MODE = 4;
    static public final int LATEST_TRANSACTION = 5;
    public static final int ACCOUNT_MODE = 6;
    public static final int DASHBOARD_MODE = 7;
    
    /**자산부채 - bs*/
    private JSONObject mBsValue = null;
    /**비용수익 - pl*/
    private JSONObject mPlValue = null;
    /**Mountain Value*/
    private JSONObject mMtValue = null;
    /** Expenses Budget Value */
    private JSONObject mExpBudgetValue = null;
    
    /** User Information value*/
    private JSONObject mUserValue = null;
    /** Frequent item info*/
    private static JSONObject mLastestItem = null;    
    
    private onLoadingMessage mLoadingMsgListener = null;
	private Context mContext;
	
	private int mRestApiNum = -1;
    
    // 대쉬보드 - Asset/Doubt: bs,pl / Monthly Budget : pl/ Credit Card : bs 
    public static interface onLoadingMessage{
        public void onMessage(int message);
    }
        
    /**
     * Refresh account infomation from server
     * @param		context		Context that is needed for accessing database
     * */
    public void refreshAccount(Context context) {
    	mContext = context;
    	ThreadRestAPI thread = new ThreadRestAPI(mHandler,
                Define.API_GET_ACCOUNTS);
        thread.start();
	}
        
	public void refreshUserInfo(Context context) {
		mContext = context;
		ThreadRestAPI thread = new ThreadRestAPI(mHandler, Define.API_GET_USER_INFO);
		thread.start();
	}
	
	public void refreshLastestItems(Context context){
        ThreadRestAPI thread = new ThreadRestAPI(mHandler, Define.API_GET_ENTRIES_LATEST_ITEMS);
        thread.start();
	}
    
    Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == Define.MSG_API_OK) {
                JSONObject obj = (JSONObject)msg.obj;
                if(obj != null){
                    int returnCode = 200;
                    try{
                        mRestApiNum = obj.getInt("rest_of_api");
                        setRestApi(mContext, mRestApiNum);
                        returnCode = obj.getInt("code");
                    }catch(JSONException e){
                        setRestApi(mContext, 0);
                    }
                    
                    if(setCodeHandling(returnCode) == false){
                        return;
                    }
                }
                
                if (msg.arg1 == Define.API_GET_ACCOUNTS) {
                    if (mContext != null) {
                        GeneralProcessor general = new GeneralProcessor(mContext);
                        try {
                            JSONObject objResult = obj.getJSONObject("results");
                            general.fillAccountsTable(objResult);
                        } catch (JSONException e) {
                            e.printStackTrace();
                            return;
                        }
                    }
                    if (mLoadingMsgListener != null) {
                        mLoadingMsgListener.onMessage(ACCOUNT_MODE);
                    }
                }
                else if(msg.arg1 == Define.API_GET_USER_INFO){
                	if(mContext != null){
                		mUserValue = obj;
                		try {
							JSONObject objResults = obj.getJSONObject("results");
							Define.CURRENCY_CODE = objResults.getString("currency");
							//TODO preference update
						} catch (JSONException e) {
							e.printStackTrace();
							return;
						}
                		
                        if(mLoadingMsgListener != null){
                            mLoadingMsgListener.onMessage(USER_MODE);
                        }
                	}
                }
                else if(msg.arg1 == Define.API_GET_ENTRIES_LATEST_ITEMS){
                    mLastestItem = obj;
                    if(mLoadingMsgListener != null){
                        mLoadingMsgListener.onMessage(LATEST_TRANSACTION);
                    }
                }
            }
        }
    };
    
    protected void setRestApi(Context context, final int apiNum){
        if(context != null){
            /*TextView textView = (TextView) ((Activity)context).findViewById(MainFragmentActivity.API_MENUITEM_ID);
            if(textView != null){
                if(apiNum == 0){
                    textView.setText("Api\r\n -");
                }else{
                    textView.setText("Api\r\n "+String.valueOf(apiNum));
                }
            }*/
        }
    }
    
    public void refreshRestApi(Context context){
        setRestApi(context, mRestApiNum);
    }
    
    /** @return	return Rest of API num*/
    public int getRestApi(){
    	return mRestApiNum;
    }
    
    public void setRestApi(int apiNum){
        mRestApiNum = apiNum;
    }
    
    /**
     * @param returnCode
     * @return
     */
    protected boolean setCodeHandling(int returnCode) {
        // TODO Auto-generated method stub
        return true;
    }
 
    /**
     * @return  Return saved mountain value
     * */
    public synchronized JSONObject getMtValue(){
        return mMtValue;
    }
    
    /**
     * @return  Return saved budget value
     * */
    public synchronized JSONObject getExpBudgetValue(){
        return mExpBudgetValue;
    }
    
    /**
     * @return	return Balance info
     * */
    public synchronized JSONObject getBsValue(){
        return mBsValue;
    }
    
    /**
     * @return	return Profit/Loss info
     * */
    public synchronized JSONObject getPlValue(){
        return mPlValue;
    }
    
    /**
     * @return	return user info
     * */
    public synchronized JSONObject getUserValue(){
    	return mUserValue;
    }
    
    /**
     * @return	return lastest items for suggestion account selection in adding transaction
     * */
    public JSONObject getLastestItems(){
        return mLastestItem;
    }
    
    /**
     * Set loading message listener for splash activity
     * @param	listener	Listener to register
     * */
    public void setLoadingMsgListener(onLoadingMessage listener){
        mLoadingMsgListener = listener;
    }

    /**
     * Clear cached data for changing data
     * */
	public void clearCachedData() {
		mPlValue = null;
		mMtValue = null;
		mBsValue = null;
		mExpBudgetValue = null;
	}
    
    /**
     * Store User information
     * @param	obj		JSONObject to store
     * */
	public synchronized void setUserInfo(JSONObject obj) {
		this.mUserValue = obj;
	}

	/**
	 * Store Profit/Loss value
	 * @param	obj		JSONObject to store
	 * */
	public synchronized void setPLValue(JSONObject obj) {
		this.mPlValue = obj;
	}

	/**
	 * Store Mountain value
	 * @param	obj		JSONObject to store
	 * */
	public synchronized void setMtValue(JSONObject obj) {
		this.mMtValue = obj;
	}

	/**
	 * Store Balance value
	 * @param	obj		JSONObject to store
	 * */
	public synchronized void setBsValue(JSONObject obj) {
		this.mBsValue = obj;
	}

	/**
	 * Store Expenses Budget value
	 * @param	obj		JSONObject to store
	 * */
	public synchronized void setExpBudgetValue(JSONObject obj) {
		this.mExpBudgetValue = obj;
	}
} public class GeneralProcessor {
    public static final String PLUS    =   "+";
    public static final String MINUS    =   "-";
    public static final String NOTHING    =   "";
    
	protected Context mContext = null;
	
	public GeneralProcessor(Context context) {
		mContext = context;
	}

	/**
	 * Check if exists accounts table
	 * @return		return true if it exists and it has 1 record at least, else return false
	 * */
	public boolean checkingAccountsInfo() {
		AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
		if(dbHelper.getAccountsInfoCount() > 0){
			return true;
		}
		return false;
	}

    /**
     * Insert items with given parameter value
     * @param objResult     JSON format value
     */
    public boolean fillAccountsTable(final JSONObject objResult) throws JSONException {
        if(objResult == null){
            return false;
        }
        
        //There are five sections. - assets, liabilites, capital, income, expenses
        final AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        dbHelper.clearTable();
        final String accountsType[] = new String[]{"assets", "liabilities", "capital", "income", "expenses"};
        for(int j = 0; j < accountsType.length; j++){
            JSONArray assetsArray = null;
            AccountsEntity info = null;
            try {
                assetsArray = objResult.getJSONArray(accountsType[j]);
                for(int i = 0; i < assetsArray.length(); i++){
                    info = new AccountsEntity(accountsType[j], (JSONObject) assetsArray.get(i));
                    dbHelper.addAccountEntity(info);
                }
            } catch (JSONException e) {
                Toast.makeText(mContext, "Error - General-01", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }                    
        }
/*        new Thread(new Runnable(){

            @Override
            public void run() {
                for(int j = 0; j < accountsType.length; j++){
                    JSONArray assetsArray = null;
                    AccountsEntity info = null;
                    try {
                        assetsArray = objResult.getJSONArray(accountsType[j]);
                        for(int i = 0; i < assetsArray.length(); i++){
                            info = new AccountsEntity(accountsType[j], (JSONObject) assetsArray.get(i));
                            dbHelper.addAccountEntity(info);
                        }
                    } catch (JSONException e) {
                        Toast.makeText(mContext, "Error - General-01", Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                    }                    
                }                
            }            
        }).start();*/
        return true;
    }
    
    /**
     * @param	exceptGroup		If you need all account include group, set false. Otherwise set true
     * @return  Return all account information in database
     * */
    public ArrayList<AccountsEntity> getAllAccount(boolean exceptGroup){
        AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        return dbHelper.getAllAccountsInfo(exceptGroup);
    }

    /**
     * @param accountName   String 
     * @return  An AccountsEntity if it successed, else return null
     */
    public AccountsEntity findAccountById(String accountId) {
        AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        AccountsEntity entity = null;
        if(accountId.compareTo("x0") == 0){ //Deleted item
            entity = new AccountsEntity();
            entity.title = mContext.getString(R.string.text_deleted);
            entity.account_id = "x0";
            entity.accountType = "N/A";
        }
        else{
            entity = dbHelper.getAccountById(accountId);
        }
        
        return entity;
    }
    
    /**
     * 좌/우변에 따라서 +, - 기호를 붙여줌 
     * @param   isLeft      flag weather left or right
     * @param   entity      Account Entity       
     * @return      if +, return 1, - , return -1, nothing return 0
     * */
    static public String getPlusMinus(AccountsEntity entity, boolean isLeft){
        if(entity == null){
            return NOTHING;
        }
        if(isLeft){
            if(entity.accountType.compareTo("assets") == 0){
                return PLUS;
            }else if(entity.accountType.compareTo("liabilities") == 0){
                return MINUS;
            }else if(entity.accountType.compareTo("capital") == 0){
                return MINUS;
            }else if(entity.accountType.compareTo("income") == 0){
                return NOTHING;
            }else if(entity.accountType.compareTo("expenses") == 0){
                return NOTHING;
            }
        }else{
            if(entity.accountType.compareTo("assets") == 0){
                return MINUS;
            }else if(entity.accountType.compareTo("liabilities") == 0){
                return PLUS;
            }else if(entity.accountType.compareTo("capital") == 0){
                return PLUS;
            }else if(entity.accountType.compareTo("income") == 0){
                return NOTHING;
            }else if(entity.accountType.compareTo("expenses") == 0){
                return NOTHING;
            }
        } 
        return NOTHING;
    }

    /**
     * Add an account entity to database 
     * @param   entity      entity to add
     * */
    public boolean addAccount(AccountsEntity entity) {
        AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        return dbHelper.addAccountEntity(entity);
    }

    /**
     * Modify given account entity 
     * @param   entity      entity to update
     * */
    public boolean modifyAccount(AccountsEntity entity) {
        AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        return dbHelper.updateAccount(entity);
    }
    
    /**
     * Delete give account entity
     * @param   entity      entity to delete
     * */
    public boolean deleteAccount(AccountsEntity entity){
        AccountsDbOpenHelper dbHelper = new AccountsDbOpenHelper(mContext);
        return dbHelper.deleteAccount(entity); 
    }
} public class FragmentUtil {
    static public int getBarWidth(double value, double maxValue, int limitWidth, int labelWidth){
        double ratio = value / (double)maxValue;
        double width = (float)limitWidth * ratio;
        if(width <= 5){
            return 5;
        }
        if((int)width >= limitWidth - labelWidth){
            return (int)width - labelWidth;
        }
        return (int)width;
    }
} public class WhooingAlert {
	/**
	 * Show alert that inform user not enough message
	 * */
	static public void showNotEnoughApi(Context context){
		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle(context.getString(R.string.global_no_api_inform_title));
        alertDialogBuilder.setMessage(context.getString(R.string.global_no_api_inform))
        .setCancelable(true)
        .setPositiveButton(context.getString(R.string.text_okay), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            	dialog.dismiss();

            }
        });
        
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
	}

	/**
	 * Show alert that leads user to go whooing webpage
	 * @param	context		context
	 * @param	msg			Alert dialog message
	 * */
	public static void showGoWhooing(final Context context, String msg) {
		AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
        alertDialogBuilder.setTitle(context.getString(R.string.text_inform));
        alertDialogBuilder.setMessage(msg)
        .setCancelable(true)
        .setPositiveButton(context.getString(R.string.alert_go_setting_whooing_btn), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            	Intent intent = new Intent(Intent.ACTION_VIEW);
            	intent.setData(Uri.parse("http://www.whooing.com"));
            	context.startActivity(intent);
            	dialog.dismiss();

            }
        })
        .setNegativeButton(context.getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            	dialog.dismiss();
            }
        });
        
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
		
	}
} public class WhooingCalendar {

	static public String getTodayYYYYMMDD(){
		Calendar rightNow = Calendar.getInstance(); 
		
		int year = rightNow.get(Calendar.YEAR);
		int month = rightNow.get(Calendar.MONTH);
		int day = rightNow.get(Calendar.DAY_OF_MONTH);
		month = month + 1;    //달은 0~11이다.
		String monthString = "";
		String dayString = "";
		if(day < 10)
			dayString += "0";
		if(month < 10)
			monthString += "0";
		monthString +=month;
		dayString += day;
		
		return ""+year+monthString+dayString;
	}

    static public int getTodayYYYYMMDDint(){
        String str = getTodayYYYYMMDD();
        
        int date = 0;
        try{
            date = Integer.parseInt(str);
        }catch(NumberFormatException e){
            return 0;
        }
        return date;
    }
    
    static public String getTodayYYYYMM(){
        Calendar rightNow = Calendar.getInstance(); 
        
        int year = rightNow.get(Calendar.YEAR);
        int month = rightNow.get(Calendar.MONTH);
        month = month + 1;
        String monthString = "";
        if(month < 10){
            monthString += "0";
        }
        monthString += month;
        return "" + year + monthString;
    }
    
    static public String getTodayLocale(Context context){
    	Define.gettingLoginInfo(context);
        Locale locale = new Locale(Define.LOCALE_LANGUAGE, Define.COUNTRY_CODE);
        Calendar calendar = Calendar.getInstance(); 
        java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM, locale);
        String date = df.format(calendar.getTime()).toString();
        return date;
    }
    
    static public String getPreMonthYYYYMM(int premonth){
        Calendar rightNow = Calendar.getInstance(); 
        rightNow.add(Calendar.MONTH, -(premonth));
        int year = rightNow.get(Calendar.YEAR);
        int month = rightNow.get(Calendar.MONTH);
        month = month + 1;
        String monthString = "";
        if(month < 10)
            monthString += "0";
        monthString += month;
        return "" + year + monthString;
    }
    
    static public String getPreMonthYYYYMMDD(int premonth){
        Calendar rightNow = Calendar.getInstance(); 
        rightNow.add(Calendar.MONTH, -(premonth));
        int year = rightNow.get(Calendar.YEAR);
        int month = rightNow.get(Calendar.MONTH);
        int days = rightNow.get(Calendar.DATE);
        month = month + 1;
        String monthString = "";
        if(month < 10)
            monthString += "0";
        monthString += month;
        
        String dayString = "";
        if(days < 10){
            dayString += "0";
        }
        dayString += days;
        
        return "" + year + monthString + dayString;
    }
    
    static public String getPreMonthLocale(Context context, int premonth){
    	Define.gettingLoginInfo(context);
        Locale locale = new Locale(Define.LOCALE_LANGUAGE, Define.COUNTRY_CODE);
        Calendar calendar = Calendar.getInstance(); 
        calendar.add(Calendar.MONTH, -(premonth));
        java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM, locale);
        String date = df.format(calendar.getTime()).toString();
        return date;
    }
    
    static public String getNextMonthYYYYMM(int nextMonth){
        Calendar rightNow = Calendar.getInstance(); 
        rightNow.add(Calendar.MONTH, nextMonth);
        int year = rightNow.get(Calendar.YEAR);
        int month = rightNow.get(Calendar.MONTH);
        month = month + 1;
        String monthString = "";
        if(month < 10)
            monthString += "0";
        monthString += month;
        
        
        return "" + year + monthString;
    }
    
    static public String getLocaleDateInt(int date){
        int year = date / 10000;
        int month = (date % 10000) / 100;
        int day = month % 100;
        return getLocaleDateString(year,month,day,java.text.DateFormat.MEDIUM);        
    }
    
    static public String getLocaleDateString(int year, int month, int day){
        return getLocaleDateString(year,month,day,java.text.DateFormat.MEDIUM);
    }
    
    static public String getLocaleDateString(int year, int month, int day, int style){
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month, day);
        Locale locale = new Locale(Define.LOCALE_LANGUAGE, Define.COUNTRY_CODE);
        java.text.DateFormat df = java.text.DateFormat.getDateInstance(style, locale);
        String date = df.format(calendar.getTime()).toString();
        return date;
    }
    
    static public int getWhooingStyleDateInt(int year, int month, int day){
        return ((year * 10000) + (month * 100) + day);
    }
    
} public class WhooingCurrency {
    public static final String TIMEZONE[] = {"", "America/Anchorage", "America/Phoenix",
            "America/Los_Angeles", "America/Denver", "Pacific/Honolulu", "America/Indianapolis",
            "America/Chicago", "America/New_York", "America/Edmonton", "America/Vancouver",
            "America/Winnipeg", "America/St_Johns", "America/Yellowknife", "America/Halifax",
            "America/Rankin_Inlet", "America/Rainy_River", "America/Montreal", "America/Regina",
            "America/Whitehorse", "Australia/Canberra", "Australia/NSW", "Australia/North",
            "Australia/Queensland", "Australia/South", "Australia/Tasmania", "Australia/Victoria",
            "Australia/West", "US/Samoa", "Africa/Abidjan", "Africa/Accra", "Africa/Algiers",
            "Africa/Asmera", "Africa/Bamako", "Africa/Bangui", "Africa/Banjul", "Africa/Bissau",
            "Africa/Brazzaville", "Africa/Bujumbura", "Africa/Cairo", "Africa/Casablanca",
            "Africa/Conakry", "Africa/Dakar", "Africa/Djibouti", "Africa/Freetown",
            "Africa/Gaborone", "Africa/Harare", "Africa/Johannesburg", "Africa/Kampala",
            "Africa/Khartoum", "Africa/Kigali", "Africa/Lagos", "Africa/Libreville", "Africa/Lome",
            "Africa/Luanda", "Africa/Lusaka", "Africa/Malabo", "Africa/Maputo", "Africa/Maseru",
            "Africa/Mbabane", "Africa/Mogadishu", "Africa/Monrovia", "Africa/Nairobi",
            "Africa/Ndjamena", "Africa/Niamey", "Africa/Nouakchott", "Africa/Ouagadougou",
            "Africa/Sao_Tome", "Africa/Tripoli", "Africa/Tunis", "America/Anguilla",
            "America/Antigua", "America/Aruba", "America/Barbados", "America/Belize",
            "America/Bogota", "America/Caracas", "America/Cayman", "America/Costa_Rica",
            "America/Dominica", "America/El_Salvador", "America/Grenada", "Europe/Paris",
            "America/Guadeloupe", "America/Guatemala", "America/Guyana", "America/Havana",
            "America/Jamaica", "America/La_Paz", "America/Lima", "America/Managua",
            "America/Martinique", "America/Montevideo", "America/Montserrat", "America/Nassau",
            "America/Panama", "America/Paramaribo", "America/Puerto_Rico", "America/St_Kitts",
            "America/St_Lucia", "America/St_Vincent", "America/Tegucigalpa", "Asia/Aden",
            "Asia/Amman", "Asia/Ashgabat", "Asia/Baghdad", "Asia/Bahrain", "Asia/Baku",
            "Asia/Bangkok", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Calcutta",
            "Asia/Choibalsan", "Asia/Colombo", "Asia/Dhaka", "Asia/Dubai", "Asia/Dushanbe",
            "Asia/Hong_Kong", "Asia/Istanbul", "Asia/Jerusalem", "Asia/Kabul", "Asia/Karachi",
            "Asia/Katmandu", "Asia/Kuwait", "Asia/Macao", "Asia/Manila", "Asia/Muscat",
            "Asia/Nicosia", "Asia/Pyongyang", "Asia/Qatar", "Asia/Rangoon", "Asia/Riyadh",
            "Asia/Seoul", "Asia/Singapore", "Asia/Taipei", "Asia/Tbilisi", "Asia/Thimphu",
            "Asia/Tokyo", "Asia/Vientiane", "Asia/Yerevan", "Atlantic/Bermuda",
            "Atlantic/Cape_Verde", "Atlantic/Faeroe", "Atlantic/Reykjavik", "Atlantic/South_Georg",
            "Atlantic/St_Helena", "Chile/Continental", "Europe/Amsterdam", "Europe/Andorra",
            "Europe/Athens", "Europe/Belgrade", "Europe/Berlin", "Europe/Bratislava",
            "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Copenhagen",
            "Europe/Dublin", "Europe/Gibraltar", "Europe/Helsinki", "Europe/Ljubljana",
            "Europe/London", "Europe/Luxembourg", "Europe/Malta", "Europe/Minsk", "Europe/Monaco",
            "Europe/Oslo", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/San_Marino",
            "Europe/Sarajevo", "Europe/Skopje", "Europe/Sofia", "Europe/Stockholm",
            "Europe/Tallinn", "Europe/Tirane", "Europe/Vaduz", "Europe/Vatican", "Europe/Vienna",
            "Europe/Vilnius", "Europe/Warsaw", "Europe/Zagreb", "Asia/Tehran",
            "Indian/Antananarivo", "Indian/Christmas", "Indian/Cocos", "Indian/Comoro",
            "Indian/Maldives", "Indian/Mauritius", "Indian/Mayotte", "Indian/Reunion",
            "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Guam", "Pacific/Nauru", "Pacific/Niue",
            "Pacific/Norfolk", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Rarotonga",
            "Pacific/Samoa", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Wallis",
            "Africa/Dar_es_Salaam", "Asia/Phnom_Penh", "Africa/Lagos", "America/Santo_Doming",
            "Africa/Addis_Ababa", "Europe/Paris", "America/Port-au-Prin", "Europe/Zurich",
            "Africa/Porto-Novo", "Africa/El_Aaiun", "Atlantic/Stanley", "America/Cayenne",
            "Indian/Chagos", "Europe/Chisinau", "Pacific/Saipan", "Africa/Blantyre",
            "Africa/Windhoek", "Pacific/Noumea", "Pacific/Port_Moresby", "America/Miquelon",
            "Asia/Gaza", "America/Asuncion", "Pacific/Guadalcanal", "Indian/Mahe",
            "Arctic/Longyearbyen", "Asia/Damascus", "America/Grand_Turk", "Indian/Kerguelen",
            "Pacific/Fakaofo", "America/Port_of_Spai", "America/Tortola", "America/St_Thomas",
            "Pacific/Efate", "Europe/Belgrade", "Europe/Podgorica", "Europe/Mariehamn",
            "Europe/Guernsey", "Europe/Isle_of_Man", "Europe/Jersey", "America/St_Barthelem",
            "America/Marigot", "America/Argentina/Ca", "America/Argentina/Ri",
            "America/Argentina/Co", "America/Argentina/Tu", "America/Argentina/Ju",
            "America/Argentina/La", "America/Argentina/Me", "America/Argentina/Sa",
            "America/Argentina/Ri", "America/Argentina/Bu", "America/Argentina/Ca",
            "America/Argentina/Us", "America/Rio_Branco", "America/Sao_Paulo", "America/Manaus",
            "America/Bahia", "America/Fortaleza", "America/Campo_Grande", "America/Belem",
            "America/Cuiaba", "America/Recife", "America/Porto_Velho", "America/Boa_Vista",
            "America/Maceio", "America/Araguaina", "Africa/Kinshasa", "Africa/Lubumbashi",
            "Africa/Kinshasa", "Africa/Kinshasa", "Asia/Harbin", "Asia/Shanghai", "Asia/Chongqing",
            "Asia/Urumqi", "Pacific/Galapagos", "America/Guayaquil", "Africa/Ceuta",
            "Atlantic/Canary", "Europe/Madrid", "America/Thule", "America/Godthab",
            "Asia/Jayapura", "Asia/Jakarta", "Asia/Makassar", "Asia/Pontianak", "Asia/Aqtobe",
            "Asia/Qyzylorda", "Asia/Aqtau", "Asia/Oral", "Asia/Almaty", "America/Tijuana",
            "America/Merida", "America/Chihuahua", "America/Mazatlan", "America/Chihuahua",
            "America/Cancun", "America/Hermosillo", "America/Monterrey", "America/Mexico_City",
            "Asia/Kuala_Lumpur", "Asia/Kuching", "Pacific/Auckland", "Pacific/Chatham",
            "Europe/Lisbon", "Atlantic/Madeira", "Asia/Yekaterinburg", "Europe/Kaliningrad",
            "Asia/Kamchatka", "Asia/Novokuznetsk", "Asia/Anadyr", "Asia/Krasnoyarsk",
            "Asia/Magadan", "Asia/Omsk", "Europe/Samara", "Asia/Vladivostok", "Asia/Yakutsk",
            "Asia/Sakhalin", "Europe/Volgograd", "Asia/Novosibirsk", "Asia/Irkutsk",
            "Europe/Moscow", "Europe/Simferopol", "Europe/Kiev", "Europe/Uzhgorod",
            "Europe/Zaporozhye", "Asia/Samarkand", "Asia/Tashkent", "Asia/Dili",
            "Pacific/Marquesas", "America/Curacao" };
    
    public static final String COUNTRY[] = {"", "Andorra", "United Arab Emirates", "Afghanistan",
            "Antigua & Barbuda", "Anguilla", "Albania", "Armenia", "Netherlands Antilles",
            "Angola", "Antarctica", "Argentina", "American Samoa", "Austria", "Australia", "Aruba",
            "Azerbaijan", "Bosnia and Herzegovina", "Barbados", "Bangladesh", "Belgium",
            "Burkina Faso", "Bulgaria", "Bahrain", "Burundi", "Benin", "Bermuda",
            "Brunei Darussalam", "Bolivia", "Brazil", "Bahama", "Bhutan", "Bouvet Island",
            "Botswana", "Belarus", "Belize", "Canada", "Cocos (Keeling) Islands",
            "Central African Republic", "Congo", "Switzerland", "Côte D'ivoire (Ivory Coast)",
            "Cook Iislands", "Chile", "Cameroon", "China", "Colombia", "Costa Rica", "Cuba",
            "Cape Verde", "Christmas Island", "Cyprus", "Czech Republic", "Germany", "Djibouti",
            "Denmark", "Dominica", "Dominican Republic", "Algeria", "Ecuador", "Estonia", "Egypt",
            "Western Sahara", "Eritrea", "Spain", "Ethiopia", "Finland", "Fiji",
            "Falkland Islands (Malvinas)", "Micronesia", "Faroe Islands", "France", "France",
            "Gabon", "United Kingdom (Great Britain)", "Grenada", "Georgia", "French Guiana",
            "Ghana", "Gibraltar", "Greenland", "Gambia", "Guinea", "Guadeloupe",
            "Equatorial Guinea", "Greece", "South Georgia and the South Sandwich Islands",
            "Guatemala", "Guam", "Guinea-Bissau", "Guyana", "Hong Kong",
            "Heard & McDonald Islands", "Honduras", "Croatia", "Haiti", "Hungary", "Indonesia",
            "Ireland", "Israel", "India", "British Indian Ocean Territory", "Iraq",
            "Islamic Republic of Iran", "Iceland", "Italy", "Jamaica", "Jordan", "Japan", "Kenya",
            "Kyrgyzstan", "Cambodia", "Kiribati", "Comoros", "St. Kitts and Nevis",
            "Democratic People's Republic of Korea(북한)", "Republic of Korea(대한민국)", "Kuwait",
            "Cayman Islands", "Kazakhstan", "Lao People's Democratic Republic", "Lebanon",
            "Saint Lucia", "Liechtenstein", "Sri Lanka", "Liberia", "Lesotho", "Lithuania",
            "Luxembourg", "Latvia", "Libyan Arab Jamahiriya", "Morocco", "Monaco", "Moldova",
            "Madagascar", "Marshall Islands", "Mali", "Mongolia", "Myanmar", "Macau",
            "Northern Mariana Islands", "Martinique", "Mauritania", "Monserrat", "Malta",
            "Mauritius", "Maldives", "Malawi", "Mexico", "Malaysia", "Mozambique", "Namibia",
            "New Caledonia", "Niger", "Norfolk Island", "Nigeria", "Nicaragua", "Netherlands",
            "Norway", "Nepal", "Nauru", "Niue", "New Zealand", "Oman", "Panama", "Peru",
            "French Polynesia", "Papua New Guinea", "Philippines", "Pakistan", "Poland",
            "St. Pierre & Miquelon", "Pitcairn", "Puerto Rico", "Portugal", "Palau", "Paraguay",
            "Qatar", "Réunion", "Romania", "Russian Federation", "Rwanda", "Saudi Arabia",
            "Solomon Islands", "Seychelles", "Sudan", "Sweden", "Singapore", "St. Helena",
            "Slovenia", "Svalbard & Jan Mayen Islands", "Slovakia", "Sierra Leone", "San Marino",
            "Senegal", "Somalia", "Suriname", "Sao Tome & Principe", "El Salvador",
            "Syrian Arab Republic", "Swaziland", "Turks & Caicos Islands", "Chad",
            "French Southern Territories", "Togo", "Thailand", "Tajikistan", "Tokelau",
            "Turkmenistan", "Tunisia", "Tonga", "East Timor", "Turkey", "Trinidad & Tobago",
            "Tuvalu", "Taiwan", "Tanzania", "Ukraine", "Uganda",
            "United States Minor Outlying Islands", "United States of America", "Uruguay",
            "Uzbekistan", "Vatican City State (Holy See)", "St. Vincent & the Grenadines",
            "Venezuela", "British Virgin Islands", "United States Virgin Islands", "Viet Nam",
            "Vanuatu", "Wallis & Futuna Islands", "Samoa", "Yemen", "Mayotte", "Yugoslavia",
            "South Africa", "Zambia", "Zaire", "Zimbabwe", "Unknown or unspecified country" };
    public static final String COUNTRY_CODE[] = {"", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN",
            "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AZ", "BA", "BB", "BD", "BE", "BF", "BG",
            "BH", "BI", "BJ", "BM", "BN", "BO", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA",
            "CC", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CX",
            "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES",
            "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "FX", "GA", "GB", "GD", "GE", "GF", "GH",
            "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM",
            "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IN", "IO", "IQ", "IR", "IS", "IT", "JM",
            "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA",
            "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "MG",
            "MH", "ML", "MN", "MM", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX",
            "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ",
            "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PT", "PW", "PY",
            "QA", "RE", "RO", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ",
            "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SY", "SZ", "TC", "TD", "TF", "TG",
            "TH", "TJ", "TK", "TM", "TN", "TO", "TP", "TR", "TT", "TV", "TW", "TZ", "UA", "UG",
            "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE",
            "YT", "YU", "ZA", "ZM", "ZR", "ZW", "ZZ" };
    public static final String CURRENCY[] = {"", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS",
            "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB",
            "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP",
            "CRC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR",
            "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL",
            "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY",
            "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR",
            "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MKD", "MMK", "MNT", "MOP", "MUR",
            "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD",
            "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB",
            "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP",
            "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS",
            "UAH", "UGX", "USD", "UYI", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD",
            "XOF", "XPF", "YER", "ZAR", "ZMW" };
	public static final String LOCALE_LANGUAGE_CODE[] = { "", "ab", "aa", "af",
			"ak", "sq", "am", "ar", "an", "hy", "as", "av", "ay", "az", "bm",
			"ba", "eu", "be", "bn", "bh", "bi", "bs", "br", "bg", "my", "ca",
			"ch", "ce", "ny", "zh", "cv", "kw", "co", "cr", "hr", "cs", "da",
			"dv", "nl", "dz", "en", "eo", "et", "ee", "fo", "fj", "fi", "fr",
			"ff", "gl", "ka", "de", "el", "gn", "gu", "ht", "ha", "he", "hz",
			"hi", "ho", "hu", "id", "ga", "ig", "ik", "io", "is", "it", "iu",
			"ja", "jv", "kl", "kn", "kr", "ks", "kk", "km", "ki", "rw", "ky",
			"kv", "kg", "ko", "ku", "kj", "lb", "lg", "li", "ln", "lo", "lt",
			"lu", "lv", "gv", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mh",
			"mn", "na", "nv", "nb", "nd", "ne", "ng", "nn", "no", "ii", "nr",
			"oc", "oj", "om", "or", "os", "pa", "fa", "pl", "ps", "pt", "qu",
			"rm", "rn", "ro", "ru", "sa", "sc", "sd", "se", "sm", "sg", "sr",
			"gd", "sn", "si", "sk", "sl", "so", "st", "es", "su", "sw", "ss",
			"sv", "ta", "te", "tg", "th", "ti", "bo", "tk", "tl", "tn", "to",
			"tr", "ts", "tt", "tw", "ty", "ug", "uk", "ur", "uz", "ve", "vi",
			"wa", "cy", "wo", "fy", "xh", "yi", "yo", "za", "zu" };
	public static final String LOCALE_LANGUAGE_NAME[] = {"", "Abkhaz", "Afar",
			"Afrikaans", "Akan", "Albanian", "Amharic", "Arabic", "Aragonese",
			"Armenian", "Assamese", "Avaric", "Aymara", "Azerbaijani",
			"Bambara", "Bashkir", "Basque", "Belarusian", "Bengali; Bangla",
			"Bihari", "Bislama", "Bosnian", "Breton", "Bulgarian", "Burmese",
			"Catalan; Valencian", "Chamorro", "Chechen",
			"Chichewa; Chewa; Nyanja", "Chinese", "Chuvash", "Cornish",
			"Corsican", "Cree", "Croatian", "Czech", "Danish",
			"Divehi; Dhivehi; Maldivian;", "Dutch", "Dzongkha", "English",
			"Esperanto", "Estonian", "Ewe", "Faroese", "Fijian", "Finnish",
			"French", "Fula; Fulah; Pulaar; Pular", "Galician", "Georgian",
			"German", "Greek, Modern", "Guaraní", "Gujarati",
			"Haitian; Haitian Creole", "Hausa", "Hebrew (modern)", "Herero",
			"Hindi", "Hiri Motu", "Hungarian", "Indonesian", "Irish", "Igbo",
			"Inupiaq", "Ido", "Icelandic", "Italian", "Inuktitut", "Japanese",
			"Javanese", "Kalaallisut, Greenlandic", "Kannada", "Kanuri",
			"Kashmiri", "Kazakh", "Khmer", "Kikuyu, Gikuyu", "Kinyarwanda",
			"Kyrgyz", "Komi", "Kongo", "Korean", "Kurdish",
			"Kwanyama, Kuanyama", "Luxembourgish, Letzeburgesch", "Ganda",
			"Limburgish, Limburgan, Limburger", "Lingala", "Lao", "Lithuanian",
			"Luba-Katanga", "Latvian", "Manx", "Macedonian", "Malagasy",
			"Malay", "Malayalam", "Maltese", "Māori", "Marathi (Marāṭhī)",
			"Marshallese", "Mongolian", "Nauru", "Navajo, Navaho",
			"Norwegian Bokmål", "North Ndebele", "Nepali", "Ndonga",
			"Norwegian Nynorsk", "Norwegian", "Nuosu", "South Ndebele",
			"Occitan", "Ojibwe, Ojibwa", "Oromo", "Oriya", "Ossetian, Ossetic",
			"Panjabi, Punjabi", "Persian", "Polish", "Pashto, Pushto",
			"Portuguese", "Quechua", "Romansh", "Kirundi",
			"Romanian, Moldavian(Romanian from Republic of Moldova)",
			"Russian", "Sanskrit (Saṁskṛta)", "Sardinian", "Sindhi",
			"Northern Sami", "Samoan", "Sango", "Serbian",
			"Scottish Gaelic; Gaelic", "Shona", "Sinhala, Sinhalese", "Slovak",
			"Slovene", "Somali", "Southern Sotho", "Spanish; Castilian",
			"Sundanese", "Swahili", "Swati", "Swedish", "Tamil", "Telugu",
			"Tajik", "Thai", "Tigrinya", "Tibetan Standard, Tibetan, Central",
			"Turkmen", "Tagalog", "Tswana", "Tonga (Tonga Islands)", "Turkish",
			"Tsonga", "Tatar", "Twi", "Tahitian", "Uighur, Uyghur",
			"Ukrainian", "Urdu", "Uzbek", "Venda", "Vietnamese", "Walloon",
			"Welsh", "Wolof", "Western Frisian", "Xhosa", "Yiddish", "Yoruba",
			"Zhuang, Chuang", "Zulu" };
    //public static final String WHOOING_LANGUAGE[] = {"English","Korean", "Dutch"};
    
    private static WhooingCurrency mInstance = new WhooingCurrency();
    
    public static WhooingCurrency getInstance(){
    	if(mInstance == null){
    		mInstance = new WhooingCurrency();
    	}
    	return mInstance;
    }
    
    
    /**
     * Return string formatted locale currency
     * @param	d	value
     * */
    public static String getFormattedValue(double d, Context context){
        NumberFormat format = NumberFormat.getInstance();
        if(Define.CURRENCY_CODE == null){
        	SharedPreferences prefs = context.getSharedPreferences(Define.SHARED_PREFERENCE, 0);
        	Define.CURRENCY_CODE = prefs.getString(Define.KEY_SHARED_CURRENCY_CODE, "USD");
        }
        Currency currency = Currency.getInstance(Define.CURRENCY_CODE);
        format.setMaximumFractionDigits(currency.getDefaultFractionDigits());
        try{
        	format.setCurrency(currency);
        }
        catch(UnsupportedOperationException e){
        	e.printStackTrace();
        	return String.valueOf(d);
        }
        
        return format.format(d);
    }
} public class WiTextView extends TextView {

    public WiTextView(Context context) {
        super(context);
        setTypeface(Define.ROBOFONT);
    }

    public WiTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setTypeface(Define.ROBOFONT);
    }

    public WiTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setTypeface(Define.ROBOFONT);
    }

}
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import net.wisedog.android.whooing.Define;
import net.wisedog.android.whooing.R;
import net.wisedog.android.whooing.WhooingApplication;
import net.wisedog.android.whooing.api.GeneralApi;
import net.wisedog.android.whooing.db.AccountsEntity;
import net.wisedog.android.whooing.engine.DataRepository;
import net.wisedog.android.whooing.engine.GeneralProcessor;
import net.wisedog.android.whooing.utils.FragmentUtil;
import net.wisedog.android.whooing.utils.WhooingAlert;
import net.wisedog.android.whooing.utils.WhooingCalendar;
import net.wisedog.android.whooing.utils.WhooingCurrency;
import net.wisedog.android.whooing.widget.WiTextView;
import android.app.Fragment;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
/*
 * Copyright (C) 2013 Jongha Kim
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.wisedog.android.whooing.activity;




/**
 * @author Wisedog(me@wisedog.net)
 *
 */
public class BalanceFragment extends Fragment{

    public static BalanceFragment newInstance(Bundle b) {
        BalanceFragment fragment = new BalanceFragment();
        fragment.setArguments(b);
        return fragment;
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.balance_fragment, container, false);
		return view;
    }
    
    

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        TableLayout tl = (TableLayout) getActivity()
                .findViewById(R.id.balance_asset_table);
        if(tl.getChildCount() <= 2){
        	DataRepository repository = WhooingApplication.getInstance().getRepo();