forked from codinguser/gnucash-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Enable creation of accounts and recording of transactions th…
…rough intents Apps which do so will need to declare the necessary permissions
- Loading branch information
1 parent
e73c3b0
commit 7838865
Showing
11 changed files
with
258 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
GnucashMobile/src/org/gnucash/android/receivers/AccountCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Written By: Ngewi Fet <ngewif@gmail.com> | ||
* Copyright (c) 2012 Ngewi Fet | ||
* | ||
* This file is part of Gnucash for Android | ||
* | ||
* Gnucash for Android is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, contact: | ||
* | ||
* Free Software Foundation Voice: +1-617-542-5942 | ||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 | ||
* Boston, MA 02110-1301, USA gnu@gnu.org | ||
*/ | ||
|
||
package org.gnucash.android.receivers; | ||
|
||
import java.util.Currency; | ||
|
||
import org.gnucash.android.data.Account; | ||
import org.gnucash.android.db.AccountsDbAdapter; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
public class AccountCreator extends BroadcastReceiver { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Log.i("Gnucash", "Received account creation intent"); | ||
Bundle args = intent.getExtras(); | ||
|
||
String uid = args.getString(Intent.EXTRA_UID); | ||
|
||
Account account = new Account(args.getString(Intent.EXTRA_TITLE)); | ||
String currencyCode = args.getString(Account.EXTRA_CURRENCY_CODE); | ||
|
||
if (currencyCode != null){ | ||
Currency currency = Currency.getInstance(currencyCode); | ||
account.setCurrency(currency); | ||
} | ||
|
||
if (uid != null) | ||
account.setUID(uid); | ||
|
||
AccountsDbAdapter accountsAdapter = new AccountsDbAdapter(context); | ||
accountsAdapter.addAccount(account); | ||
accountsAdapter.close(); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
GnucashMobile/src/org/gnucash/android/receivers/TransactionRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Written By: Ngewi Fet <ngewif@gmail.com> | ||
* Copyright (c) 2012 Ngewi Fet | ||
* | ||
* This file is part of Gnucash for Android | ||
* | ||
* Gnucash for Android is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation; either version 2 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, contact: | ||
* | ||
* Free Software Foundation Voice: +1-617-542-5942 | ||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 | ||
* Boston, MA 02110-1301, USA gnu@gnu.org | ||
*/ | ||
|
||
package org.gnucash.android.receivers; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Currency; | ||
|
||
import org.gnucash.android.data.Account; | ||
import org.gnucash.android.data.Money; | ||
import org.gnucash.android.data.Transaction; | ||
import org.gnucash.android.db.TransactionsDbAdapter; | ||
import org.gnucash.android.ui.MainActivity; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
public class TransactionRecorder extends BroadcastReceiver { | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Log.i("Gnucash", "Received transaction recording intent"); | ||
Bundle args = intent.getExtras(); | ||
String name = args.getString(Intent.EXTRA_TITLE); | ||
String note = args.getString(Intent.EXTRA_TEXT); | ||
double amountDouble = args.getDouble(Transaction.EXTRA_AMOUNT, 0); | ||
String currencyCode = args.getString(Account.EXTRA_CURRENCY_CODE); | ||
if (currencyCode == null) | ||
currencyCode = MainActivity.DEFAULT_CURRENCY_CODE; | ||
|
||
String accountUID = args.getString(Transaction.EXTRA_ACCOUNT_UID); | ||
if (accountUID == null) | ||
accountUID = "uncategorized"; | ||
|
||
Money amount = new Money(new BigDecimal(amountDouble), Currency.getInstance(currencyCode)); | ||
Transaction transaction = new Transaction(amount, name); | ||
transaction.setTime(System.currentTimeMillis()); | ||
transaction.setDescription(note); | ||
transaction.setAccountUID(accountUID); | ||
|
||
TransactionsDbAdapter transacionsDbAdapter = new TransactionsDbAdapter(context); | ||
transacionsDbAdapter.addTransaction(transaction); | ||
transacionsDbAdapter.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters