├── README.org
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── ic_launcher_background.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── activity_main_toolbar.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_info_black_24dp.xml
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── xml
│ │ │ │ ├── pref_headers.xml
│ │ │ │ └── pref_general.xml
│ │ │ ├── values-ja
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── jp
│ │ │ └── misohena
│ │ │ └── paymentrecord
│ │ │ ├── AppCompatPreferenceActivity.java
│ │ │ ├── SettingsActivity.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── jp
│ │ │ └── misohena
│ │ │ └── paymentrecord
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── jp
│ │ └── misohena
│ │ └── paymentrecord
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── appicon.psd
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── LICENSE.txt
├── appicon.svg
├── gradlew.bat
└── gradlew
/README.org:
--------------------------------------------------------------------------------
1 | * 出金記録入力アプリ
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/appicon.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/appicon.psd
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/misohena/PaymentRecord/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 01 05:06:37 JST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFFFFF
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_info_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_headers.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/test/java/jp/misohena/paymentrecord/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package jp.misohena.paymentrecord;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/jp/misohena/paymentrecord/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package jp.misohena.paymentrecord;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("jp.misohena.paymentrecord", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\app\dev\android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Misohena Software
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values-ja/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 支払記録
4 | 支払額
5 | 記録
6 | 目的
7 | 支払方法
8 | 支払目的
9 | 支払記録の送り先を選択してください。
10 | 記録日時
11 | 記録場所
12 | 設定
13 | 現金,Suica,クレジットカード,その他
14 | 出金
15 | 一般
16 | 支払方法一覧(カンマ(,)区切り)
17 | 送信方法
18 | 送信タグ名(Evernote時のみ)
19 | 設定
20 |
21 | - Intent
22 | - Intent(Evernote)
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "jp.misohena.paymentrecord"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 2
10 | versionName "1.1"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:27.0.2'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | compile 'com.android.support:design:27.0.2'
30 | compile 'com.google.android.gms:play-services-maps:11.8.0'
31 | compile 'com.google.android.gms:play-services-location:11.8.0'
32 | compile 'com.android.support:support-v4:27.0.2'
33 | compile 'com.android.support:support-vector-drawable:27.0.2'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
8 |
11 |
14 |
17 |
20 |
23 |
26 |
29 |
32 |
35 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
21 |
22 | 8dp
23 | 4dp
24 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Payment Record
3 |
4 | Payment Amount
5 | Post
6 | Purpose
7 | Payment Purpose
8 | Payment Method
9 | Record Datetime
10 | Record Location
11 | Choose a destination of the payment record.
12 | Settings
13 |
14 |
15 |
16 | Settings
17 |
18 | General
19 |
20 |
21 |
22 | Posting Method
23 |
24 | - Intent
25 | - Intent(Evernote)
26 |
27 |
28 | - 0
29 | - 1
30 |
31 |
32 | Payment methods(Comma separated)
33 | Cash,Suica,Credit Card,Other
34 |
35 | Posting tagname(Sending to Evernote only)
36 | Payment
37 |
38 |
39 |
--------------------------------------------------------------------------------
/appicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
63 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/pref_general.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
14 |
15 |
16 |
17 |
25 |
26 |
34 |
35 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/jp/misohena/paymentrecord/AppCompatPreferenceActivity.java:
--------------------------------------------------------------------------------
1 | package jp.misohena.paymentrecord;
2 |
3 | import android.content.res.Configuration;
4 | import android.os.Bundle;
5 | import android.preference.PreferenceActivity;
6 | import android.support.annotation.LayoutRes;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.ActionBar;
9 | import android.support.v7.app.AppCompatDelegate;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.MenuInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 |
15 | /**
16 | * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
17 | * to be used with AppCompat.
18 | */
19 | public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
20 |
21 | private AppCompatDelegate mDelegate;
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | getDelegate().installViewFactory();
26 | getDelegate().onCreate(savedInstanceState);
27 | super.onCreate(savedInstanceState);
28 | }
29 |
30 | @Override
31 | protected void onPostCreate(Bundle savedInstanceState) {
32 | super.onPostCreate(savedInstanceState);
33 | getDelegate().onPostCreate(savedInstanceState);
34 | }
35 |
36 | public ActionBar getSupportActionBar() {
37 | return getDelegate().getSupportActionBar();
38 | }
39 |
40 | public void setSupportActionBar(@Nullable Toolbar toolbar) {
41 | getDelegate().setSupportActionBar(toolbar);
42 | }
43 |
44 | @Override
45 | public MenuInflater getMenuInflater() {
46 | return getDelegate().getMenuInflater();
47 | }
48 |
49 | @Override
50 | public void setContentView(@LayoutRes int layoutResID) {
51 | getDelegate().setContentView(layoutResID);
52 | }
53 |
54 | @Override
55 | public void setContentView(View view) {
56 | getDelegate().setContentView(view);
57 | }
58 |
59 | @Override
60 | public void setContentView(View view, ViewGroup.LayoutParams params) {
61 | getDelegate().setContentView(view, params);
62 | }
63 |
64 | @Override
65 | public void addContentView(View view, ViewGroup.LayoutParams params) {
66 | getDelegate().addContentView(view, params);
67 | }
68 |
69 | @Override
70 | protected void onPostResume() {
71 | super.onPostResume();
72 | getDelegate().onPostResume();
73 | }
74 |
75 | @Override
76 | protected void onTitleChanged(CharSequence title, int color) {
77 | super.onTitleChanged(title, color);
78 | getDelegate().setTitle(title);
79 | }
80 |
81 | @Override
82 | public void onConfigurationChanged(Configuration newConfig) {
83 | super.onConfigurationChanged(newConfig);
84 | getDelegate().onConfigurationChanged(newConfig);
85 | }
86 |
87 | @Override
88 | protected void onStop() {
89 | super.onStop();
90 | getDelegate().onStop();
91 | }
92 |
93 | @Override
94 | protected void onDestroy() {
95 | super.onDestroy();
96 | getDelegate().onDestroy();
97 | }
98 |
99 | public void invalidateOptionsMenu() {
100 | getDelegate().invalidateOptionsMenu();
101 | }
102 |
103 | private AppCompatDelegate getDelegate() {
104 | if (mDelegate == null) {
105 | mDelegate = AppCompatDelegate.create(this, null);
106 | }
107 | return mDelegate;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
18 |
19 |
22 |
23 |
30 |
31 |
32 |
33 |
37 |
38 |
45 |
46 |
47 |
48 |
52 |
53 |
60 |
61 |
67 |
68 |
69 |
70 |
76 |
77 |
81 |
82 |
88 |
89 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/jp/misohena/paymentrecord/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package jp.misohena.paymentrecord;
2 |
3 |
4 | import android.annotation.TargetApi;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.res.Configuration;
8 | import android.media.Ringtone;
9 | import android.media.RingtoneManager;
10 | import android.net.Uri;
11 | import android.os.Build;
12 | import android.os.Bundle;
13 | import android.preference.ListPreference;
14 | import android.preference.Preference;
15 | import android.preference.PreferenceActivity;
16 | import android.support.v7.app.ActionBar;
17 | import android.preference.PreferenceFragment;
18 | import android.preference.PreferenceManager;
19 | import android.preference.RingtonePreference;
20 | import android.text.TextUtils;
21 | import android.view.MenuItem;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * A {@link PreferenceActivity} that presents a set of application settings. On
27 | * handset devices, settings are presented as a single list. On tablets,
28 | * settings are split by category, with category headers shown to the left of
29 | * the list of settings.
30 | *
31 | * See
32 | * Android Design: Settings for design guidelines and the Settings
34 | * API Guide for more information on developing a Settings UI.
35 | */
36 | public class SettingsActivity extends AppCompatPreferenceActivity {
37 | /**
38 | * A preference value change listener that updates the preference's summary
39 | * to reflect its new value.
40 | */
41 | private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
42 | @Override
43 | public boolean onPreferenceChange(Preference preference, Object value) {
44 | String stringValue = value.toString();
45 |
46 | if (preference instanceof ListPreference) {
47 | // For list preferences, look up the correct display value in
48 | // the preference's 'entries' list.
49 | ListPreference listPreference = (ListPreference) preference;
50 | int index = listPreference.findIndexOfValue(stringValue);
51 |
52 | // Set the summary to reflect the new value.
53 | preference.setSummary(
54 | index >= 0
55 | ? listPreference.getEntries()[index]
56 | : null);
57 |
58 | } else if (preference instanceof RingtonePreference) {
59 | // For ringtone preferences, look up the correct display value
60 | // using RingtoneManager.
61 | if (TextUtils.isEmpty(stringValue)) {
62 | // Empty values correspond to 'silent' (no ringtone).
63 | //preference.setSummary(R.string.pref_ringtone_silent);
64 | preference.setSummary("slient");
65 |
66 | } else {
67 | Ringtone ringtone = RingtoneManager.getRingtone(
68 | preference.getContext(), Uri.parse(stringValue));
69 |
70 | if (ringtone == null) {
71 | // Clear the summary if there was a lookup error.
72 | preference.setSummary(null);
73 | } else {
74 | // Set the summary to reflect the new ringtone display
75 | // name.
76 | String name = ringtone.getTitle(preference.getContext());
77 | preference.setSummary(name);
78 | }
79 | }
80 |
81 | } else {
82 | // For all other preferences, set the summary to the value's
83 | // simple string representation.
84 | preference.setSummary(stringValue);
85 | }
86 | return true;
87 | }
88 | };
89 |
90 | /**
91 | * Helper method to determine if the device has an extra-large screen. For
92 | * example, 10" tablets are extra-large.
93 | */
94 | private static boolean isXLargeTablet(Context context) {
95 | return (context.getResources().getConfiguration().screenLayout
96 | & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
97 | }
98 |
99 | /**
100 | * Binds a preference's summary to its value. More specifically, when the
101 | * preference's value is changed, its summary (line of text below the
102 | * preference title) is updated to reflect the value. The summary is also
103 | * immediately updated upon calling this method. The exact display format is
104 | * dependent on the type of preference.
105 | *
106 | * @see #sBindPreferenceSummaryToValueListener
107 | */
108 | private static void bindPreferenceSummaryToValue(Preference preference) {
109 | // Set the listener to watch for value changes.
110 | preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
111 |
112 | // Trigger the listener immediately with the preference's
113 | // current value.
114 | sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
115 | PreferenceManager
116 | .getDefaultSharedPreferences(preference.getContext())
117 | .getString(preference.getKey(), ""));
118 | }
119 |
120 | @Override
121 | protected void onCreate(Bundle savedInstanceState) {
122 | super.onCreate(savedInstanceState);
123 | setupActionBar();
124 | }
125 |
126 | /**
127 | * Set up the {@link android.app.ActionBar}, if the API is available.
128 | */
129 | private void setupActionBar() {
130 | ActionBar actionBar = getSupportActionBar();
131 | if (actionBar != null) {
132 | // Show the Up button in the action bar.
133 | actionBar.setDisplayHomeAsUpEnabled(true);
134 | }
135 | }
136 |
137 | /**
138 | * {@inheritDoc}
139 | */
140 | @Override
141 | public boolean onIsMultiPane() {
142 | return isXLargeTablet(this);
143 | }
144 |
145 | /**
146 | * {@inheritDoc}
147 | */
148 | @Override
149 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
150 | public void onBuildHeaders(List target) {
151 | loadHeadersFromResource(R.xml.pref_headers, target);
152 | }
153 |
154 | /**
155 | * This method stops fragment injection in malicious applications.
156 | * Make sure to deny any unknown fragments here.
157 | */
158 | protected boolean isValidFragment(String fragmentName) {
159 | return PreferenceFragment.class.getName().equals(fragmentName)
160 | || GeneralPreferenceFragment.class.getName().equals(fragmentName);
161 | }
162 |
163 | /**
164 | * This fragment shows general preferences only. It is used when the
165 | * activity is showing a two-pane settings UI.
166 | */
167 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
168 | public static class GeneralPreferenceFragment extends PreferenceFragment {
169 | @Override
170 | public void onCreate(Bundle savedInstanceState) {
171 | super.onCreate(savedInstanceState);
172 | addPreferencesFromResource(R.xml.pref_general);
173 | setHasOptionsMenu(true);
174 |
175 | // Bind the summaries of EditText/List/Dialog/Ringtone preferences
176 | // to their values. When their values change, their summaries are
177 | // updated to reflect the new value, per the Android Design
178 | // guidelines.
179 | bindPreferenceSummaryToValue(findPreference("posting_method"));
180 | bindPreferenceSummaryToValue(findPreference("posting_tagname"));
181 | bindPreferenceSummaryToValue(findPreference("payment_methods"));
182 | }
183 |
184 | @Override
185 | public boolean onOptionsItemSelected(MenuItem item) {
186 | int id = item.getItemId();
187 | if (id == android.R.id.home) {
188 | startActivity(new Intent(getActivity(), SettingsActivity.class));
189 | return true;
190 | }
191 | return super.onOptionsItemSelected(item);
192 | }
193 | }
194 |
195 |
196 | @Override
197 | public boolean onOptionsItemSelected(MenuItem item) {
198 | switch(item.getItemId()){
199 | case android.R.id.home:
200 | finish();
201 | return true;
202 | default:
203 | return super.onOptionsItemSelected(item);
204 | }
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/app/src/main/java/jp/misohena/paymentrecord/MainActivity.java:
--------------------------------------------------------------------------------
1 | package jp.misohena.paymentrecord;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.content.pm.PackageManager;
8 | import android.location.Location;
9 | import android.os.PersistableBundle;
10 | import android.preference.Preference;
11 | import android.preference.PreferenceManager;
12 | import android.support.annotation.NonNull;
13 | import android.support.annotation.Nullable;
14 | import android.support.v4.app.ActivityCompat;
15 | import android.support.v4.content.PermissionChecker;
16 | import android.support.v7.app.AlertDialog;
17 | import android.support.v7.app.AppCompatActivity;
18 | import android.os.Bundle;
19 | import android.util.Log;
20 | import android.view.Menu;
21 | import android.view.MenuItem;
22 | import android.view.View;
23 | import android.widget.ArrayAdapter;
24 | import android.widget.Button;
25 | import android.widget.EditText;
26 | import android.widget.Spinner;
27 | import android.widget.Toast;
28 |
29 | import com.google.android.gms.common.ConnectionResult;
30 | import com.google.android.gms.common.api.GoogleApiClient;
31 | import com.google.android.gms.common.api.PendingResult;
32 | import com.google.android.gms.common.api.ResultCallback;
33 | import com.google.android.gms.common.api.Status;
34 | import com.google.android.gms.location.LocationListener;
35 | import com.google.android.gms.location.LocationRequest;
36 | import com.google.android.gms.location.LocationSettingsRequest;
37 | import com.google.android.gms.location.LocationSettingsResult;
38 | import com.google.android.gms.location.LocationSettingsStatusCodes;
39 | import com.google.android.gms.maps.CameraUpdateFactory;
40 | import com.google.android.gms.maps.GoogleMap;
41 | import com.google.android.gms.maps.MapView;
42 | import com.google.android.gms.maps.OnMapReadyCallback;
43 | import com.google.android.gms.maps.model.LatLng;
44 | import com.google.android.gms.maps.model.PointOfInterest;
45 | import com.google.android.gms.location.LocationServices;
46 |
47 | import java.security.Permission;
48 | import java.text.SimpleDateFormat;
49 | import java.util.ArrayList;
50 | import java.util.Arrays;
51 | import java.util.Date;
52 | import java.util.HashMap;
53 |
54 | public class MainActivity extends AppCompatActivity {
55 | private MapView mapView_;
56 | private GoogleMap googleMap_;
57 |
58 | private LocationTracker locationTracker_;
59 |
60 | @Override
61 | protected void onCreate(Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 | setContentView(R.layout.activity_main);
64 |
65 | updateSpinnerPaymentMethods();
66 |
67 | locationTracker_ = new LocationTracker(this);
68 | locationTracker_.connectGoogleApi();
69 |
70 | mapView_ = (MapView)findViewById(R.id.mapView);
71 | if(mapView_ != null){
72 | mapView_.onCreate(savedInstanceState);
73 | mapView_.getMapAsync(new OnMapReadyCallback() {
74 | @Override
75 | public void onMapReady(GoogleMap googleMap) {
76 | googleMap_ = googleMap;
77 | //googleMap.setMyLocationEnabled(true);
78 | enableMyLocation();
79 |
80 | googleMap.setOnPoiClickListener(new GoogleMap.OnPoiClickListener() {
81 | @Override
82 | public void onPoiClick(PointOfInterest poi) {
83 | Toast.makeText(getApplicationContext(), "Clicked: " +
84 | poi.name + "\nPlace ID:" + poi.placeId +
85 | "\nLatitude:" + poi.latLng.latitude +
86 | " Longitude:" + poi.latLng.longitude,
87 | Toast.LENGTH_SHORT).show();
88 |
89 | }
90 | });
91 | }
92 | });
93 | }
94 |
95 | final Button buttonPost = (Button)findViewById(R.id.button_post);
96 | buttonPost.setOnClickListener(new View.OnClickListener() {
97 | @Override
98 | public void onClick(View v) {
99 | postRecord();
100 | }
101 | });
102 | }
103 |
104 | @Override
105 | protected void onDestroy() {
106 | super.onDestroy();
107 | if(mapView_ != null){mapView_.onDestroy();}
108 | }
109 |
110 | @Override
111 | public void onLowMemory() {
112 | super.onLowMemory();
113 | if(mapView_ != null){mapView_.onLowMemory();}
114 | }
115 |
116 | @Override
117 | protected void onPause() {
118 | super.onPause();
119 | if(mapView_ != null){mapView_.onPause();}
120 | locationTracker_.onPause();
121 | }
122 |
123 | @Override
124 | protected void onResume() {
125 | super.onResume();
126 | if(mapView_ != null){mapView_.onResume();}
127 | locationTracker_.onResume();
128 | updateSpinnerPaymentMethods();
129 | }
130 |
131 | @Override
132 | protected void onSaveInstanceState(Bundle outState) {
133 | super.onSaveInstanceState(outState);
134 | if(mapView_ != null){mapView_.onSaveInstanceState(outState);}
135 | }
136 |
137 | @Override
138 | protected void onStart() {
139 | locationTracker_.onStart();
140 | super.onStart();
141 | }
142 |
143 | @Override
144 | protected void onStop() {
145 | locationTracker_.onStop();
146 | super.onStop();
147 | }
148 |
149 |
150 | //
151 | // UI
152 | //
153 |
154 | void updateSpinnerPaymentMethods()
155 | {
156 | final Spinner sp = (Spinner)findViewById(R.id.spinner_payment_method);
157 |
158 | // backup selection value
159 | final Object selectedItem = sp.getSelectedItem();
160 | final String selectedValue = selectedItem != null ? (String)selectedItem : null;
161 |
162 | // get methods and set list
163 | final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
164 | final String methodsString = prefs.getString("payment_methods", getString(R.string.pref_default_payment_methods));
165 | final String[] methods = methodsString.split(",");
166 |
167 | final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, methods);
168 |
169 | sp.setAdapter(adapter);
170 |
171 | // restore selection
172 | int pos = 0;
173 | if(selectedValue != null) {
174 | for (int i = 0; i < methods.length; ++i) {
175 | if (methods[i].equals(selectedValue)) {
176 | pos = i;
177 | break;
178 | }
179 | }
180 | }
181 |
182 | sp.setSelection(pos);
183 | }
184 |
185 | //
186 | // Menu
187 | //
188 |
189 | @Override
190 | public boolean onCreateOptionsMenu(Menu menu) {
191 | getMenuInflater().inflate(R.menu.activity_main_toolbar, menu);
192 | return true;
193 | }
194 |
195 | @Override
196 | public boolean onOptionsItemSelected(MenuItem item) {
197 | switch(item.getItemId()) {
198 | case R.id.action_settings:
199 | startActivity(new Intent(this, SettingsActivity.class));
200 | return true;
201 | default:
202 | return super.onOptionsItemSelected(item);
203 | }
204 | }
205 |
206 | //
207 | // Post
208 | //
209 |
210 | static final int POSTING_METHOD_INTENT_SEND = 0;
211 | static final int POSTING_METHOD_INTENT_SEND_EVERNOTE = 1;
212 | private void postRecord()
213 | {
214 | // Get settings
215 | final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
216 | final String tagname = prefs.getString("posting_tagname", getString(R.string.pref_default_posting_tagname));
217 | final int postingMethod = Integer.parseInt(prefs.getString("posting_method", Integer.toString(POSTING_METHOD_INTENT_SEND)));
218 |
219 | // Get view
220 | final EditText editPaymentAmount = (EditText)findViewById(R.id.edit_payment_amount);
221 | final EditText editPaymentPurpose = (EditText)findViewById(R.id.edit_payment_purpose);
222 | final Spinner spinnerPaymentMethod = (Spinner)findViewById(R.id.spinner_payment_method);
223 |
224 | // Make content
225 | int paymentAmount;
226 | try {
227 | paymentAmount = Integer.parseInt(editPaymentAmount.getText().toString());
228 | }
229 | catch(NumberFormatException e){
230 | return;
231 | }
232 |
233 | final String purpose = editPaymentPurpose.getText().toString();
234 | final String method = (String)spinnerPaymentMethod.getSelectedItem();
235 |
236 | final String title = Integer.toString(paymentAmount) + purpose;
237 | final String br = "\n";
238 | String body =
239 | getString(R.string.payment_amount) + ": " + paymentAmount + br +
240 | getString(R.string.payment_purpose) + ": " + purpose + br +
241 | getString(R.string.payment_method) + ": " + method + br +
242 | getString(R.string.record_datetime) + ": " + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()) + br;
243 | final Location loc = locationTracker_.getLastLocation();
244 | if(loc != null) {
245 | body += (getString(R.string.record_location) + ": " + Double.toString(loc.getLatitude()) + " , " + Double.toString(loc.getLongitude())) + br;
246 | }
247 |
248 | final ArrayList tags = new ArrayList<>();
249 | tags.add(tagname);
250 |
251 | // Send
252 | Intent intent = new Intent();
253 | switch(postingMethod){
254 | case POSTING_METHOD_INTENT_SEND:
255 | intent.setAction(Intent.ACTION_SEND);
256 | intent.setType("text/plain");
257 | intent.putExtra(Intent.EXTRA_SUBJECT, title);
258 | intent.putExtra(Intent.EXTRA_TEXT, body);
259 | break;
260 | case POSTING_METHOD_INTENT_SEND_EVERNOTE:
261 | intent.setAction("com.evernote.action.CREATE_NEW_NOTE");
262 | intent.setType("text/plain");
263 | intent.putExtra(Intent.EXTRA_SUBJECT, title);
264 | intent.putExtra(Intent.EXTRA_TEXT, body);
265 | intent.putExtra("TAG_NAME_LIST", tags);
266 | if(loc != null) {
267 | intent.putExtra("LATITUDE", loc.getLatitude());
268 | intent.putExtra("LONGITUDE", loc.getLongitude());
269 | }
270 | //intent.putExtra("QUICK_SEND", true);
271 | intent.putExtra("FORCE_NO_UI", true);
272 | break;
273 | default:
274 | return;
275 | }
276 | startActivity(Intent.createChooser(intent, getString(R.string.post_record_to_intent)));
277 | }
278 |
279 |
280 |
281 | //
282 | // Google Map
283 | //
284 |
285 | private void enableMyLocation()
286 | {
287 | requirePermissions(
288 | new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION},
289 | new Runnable(){@Override public void run(){
290 | if(googleMap_ == null) {
291 | return;
292 | }
293 |
294 | try {
295 | googleMap_.setMyLocationEnabled(true);
296 | googleMap_.getUiSettings().setMyLocationButtonEnabled(true);
297 | }
298 | catch(SecurityException e){}
299 |
300 | locationTracker_.setLocationListener(new LocationListener() {
301 | private boolean first = true;
302 | @Override
303 | public void onLocationChanged(Location location) {
304 | Log.d("PaymentRecord", "onLocationChanged");
305 | if(location != null){
306 | if(first) {
307 | first = false;
308 | googleMap_.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 17));
309 | }
310 | else {
311 | googleMap_.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
312 | }
313 | }
314 | }
315 | });
316 | locationTracker_.startTracking();
317 | } } );
318 | }
319 |
320 |
321 |
322 | //
323 | // Runtime Permission
324 | //
325 |
326 | private HashMap perms_handlers_ = new HashMap<>();
327 | private int perms_code_ = 1;
328 |
329 | private void requirePermissions(String[] permissions, Runnable callback)
330 | {
331 | final String[] nonGrantedPerms = perms_getNonGrantedPermissions(permissions);
332 |
333 | if(nonGrantedPerms.length == 0){
334 | callback.run();
335 | }
336 | else {
337 | perms_request(nonGrantedPerms, callback);
338 | }
339 | }
340 | private String[] perms_getNonGrantedPermissions(String[] permissions)
341 | {
342 | final ArrayList nonGrantedPerms = new ArrayList<>();
343 | for(String permission : permissions) {
344 | if (PermissionChecker.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
345 | // not granted
346 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
347 | //@todo show rationale dialog
348 | }
349 | nonGrantedPerms.add(permission);
350 | }
351 | }
352 | return (String[])nonGrantedPerms.toArray(new String[nonGrantedPerms.size()]);
353 | }
354 | private void perms_request(String[] nonGrantedPerms, Runnable callback)
355 | {
356 | // allocate a code
357 | final int code = perms_code_++;
358 | perms_handlers_.put(code, callback);
359 | // request
360 | ActivityCompat.requestPermissions(
361 | this,
362 | nonGrantedPerms,
363 | code);
364 | }
365 | private void perms_handleResult(int requestCode, int[] grantResults)
366 | {
367 | // deallocate the code
368 | final Runnable callback = perms_handlers_.get(requestCode);
369 | perms_handlers_.remove(requestCode);
370 |
371 | // find not granted
372 | boolean grantedAll = true;
373 | for(int result : grantResults) {
374 | if (result != PackageManager.PERMISSION_GRANTED) {
375 | grantedAll = false;
376 | break;
377 | }
378 | }
379 |
380 | // callback
381 | if(grantedAll){
382 | if(callback != null) {
383 | callback.run();
384 | }
385 | }
386 | }
387 |
388 | @Override
389 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
390 | {
391 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
392 | perms_handleResult(requestCode, grantResults);
393 | }
394 | }
395 |
396 |
397 |
398 | class LocationTracker
399 | {
400 | private Context context_;
401 | private GoogleApiClient googleApiClient_;
402 | private LocationRequest locationRequest_;
403 | private Location lastLocation_;
404 | private long lastTime_;
405 | private LocationListener locationListener_;
406 | private boolean tracking_ = false;
407 |
408 | public LocationTracker(Context context)
409 | {
410 | context_ = context;
411 | }
412 |
413 | public void setLocationListener(LocationListener locationListener)
414 | {
415 | locationListener_ = locationListener;
416 | }
417 |
418 |
419 | // call from Activity
420 |
421 | public void onStart()
422 | {
423 | if(googleApiClient_ != null){
424 | Log.d("PaymentRecord", "onStart connect");
425 | googleApiClient_.connect();
426 | }
427 | }
428 | public void onStop()
429 | {
430 | if(googleApiClient_ != null){
431 | Log.d("PaymentRecord", "onStop disconnect");
432 | googleApiClient_.disconnect();
433 | }
434 | }
435 | public void onPause()
436 | {
437 | if(tracking_) {
438 | stopTrackingInner();
439 | }
440 | }
441 | public void onResume()
442 | {
443 | if(tracking_) {
444 | startTrackingInner();
445 | }
446 | }
447 |
448 | public void connectGoogleApi()
449 | {
450 | if (googleApiClient_ == null) {
451 | Log.d("PaymentRecord", "connectGoogleApi start");
452 | googleApiClient_ = new GoogleApiClient.Builder(context_)
453 | .addConnectionCallbacks(callbackConn_)
454 | .addOnConnectionFailedListener(callbackConnFailed_)
455 | .addApi(LocationServices.API)
456 | .build();
457 | }
458 | }
459 |
460 | private GoogleApiClient.ConnectionCallbacks callbackConn_ = new GoogleApiClient.ConnectionCallbacks() {
461 | @Override
462 | public void onConnected(@Nullable Bundle bundle) {
463 | Log.d("PaymentRecord", "onConnected");
464 | if(tracking_){
465 | startTrackingInner();
466 | }
467 | }
468 |
469 | @Override
470 | public void onConnectionSuspended(int i) {
471 | Log.d("PaymentRecord", "onConnectionSuspended");
472 | }
473 | };
474 |
475 | private GoogleApiClient.OnConnectionFailedListener callbackConnFailed_ = new GoogleApiClient.OnConnectionFailedListener() {
476 | @Override
477 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
478 | Log.d("PaymentRecord", "onConnectionFailed");
479 | }
480 | };
481 |
482 |
483 | private void setLastLocation(Location loc)
484 | {
485 | lastLocation_ = loc;
486 | lastTime_ = System.currentTimeMillis();
487 | if(locationListener_ != null){
488 | locationListener_.onLocationChanged(loc);
489 | }
490 | }
491 |
492 | /**
493 | * @see https://developer.android.com/training/location/retrieve-current.html#last-known
494 | */
495 | public Location getLastLocation()
496 | {
497 | if(googleApiClient_ != null) {
498 | try {
499 | // if googleApiClient_ is not connected, return null
500 | final Location loc = LocationServices.FusedLocationApi.getLastLocation(googleApiClient_);
501 | if(loc != null){
502 | setLastLocation(loc);
503 | return loc;
504 | }
505 | } catch (SecurityException e) {}
506 | }
507 | return null;
508 | }
509 |
510 |
511 | /**
512 | * @see https://developer.android.com/training/location/change-location-settings.html#location-request
513 | */
514 | private static LocationRequest createLocationRequest()
515 | {
516 | final LocationRequest req = new LocationRequest();
517 | req.setInterval(10000);
518 | req.setFastestInterval(5000);
519 | req.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
520 | return req;
521 | }
522 | private LocationRequest getLocationRequest()
523 | {
524 | if(locationRequest_ == null){
525 | locationRequest_ = createLocationRequest();
526 | }
527 | return locationRequest_;
528 | }
529 |
530 |
531 | /**
532 | * @see https://developer.android.com/training/location/change-location-settings.html#get-settings
533 | */
534 | public void requestCurrentLocation()
535 | {
536 | if(googleApiClient_ == null){
537 | connectGoogleApi();
538 | if(googleApiClient_ == null) {
539 | return;
540 | }
541 | }
542 | // googleApiClient_ does not need to be connected.
543 |
544 | final LocationRequest locationRequest = getLocationRequest();
545 | final ResultCallback callback = new ResultCallback() {
546 | @Override
547 | public void onResult(@NonNull LocationSettingsResult result) {
548 | final Status status = result.getStatus();
549 | switch(status.getStatusCode()) {
550 | case LocationSettingsStatusCodes.SUCCESS:
551 | getLastLocation();
552 | break;
553 | case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
554 | //status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
555 | break;
556 | }
557 | }
558 | };
559 | final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
560 | final PendingResult result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient_, builder.build());
561 | result.setResultCallback(callback);
562 | }
563 |
564 | public void startTracking()
565 | {
566 | if(!tracking_){
567 | tracking_ = true;
568 | if(googleApiClient_ == null){
569 | connectGoogleApi();
570 | }
571 | else if(!googleApiClient_.isConnected()){
572 | return;
573 | }
574 | else{
575 | startTrackingInner();
576 | }
577 | }
578 | }
579 | public void stopTracking()
580 | {
581 | if(tracking_){
582 | tracking_ = false;
583 | stopTrackingInner();
584 | }
585 | }
586 |
587 |
588 | /**
589 | * @see https://developer.android.com/training/location/receive-location-updates.html#updates
590 | */
591 | private void startTrackingInner()
592 | {
593 | if(googleApiClient_ == null || !googleApiClient_.isConnected()){
594 | return;
595 | }
596 | Log.d("PaymentRecord", "startTrackingInner");
597 |
598 | try {
599 | final LocationRequest request = getLocationRequest();
600 | final LocationListener listener = locationListener_;
601 | LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient_, request, listener);
602 | }
603 | catch(SecurityException e){
604 | Log.d("PaymentRecord", "startTrackingInner exception occured.");
605 | }
606 | }
607 |
608 | /**
609 | * @see https://developer.android.com/training/location/receive-location-updates.html#stop-updates
610 | */
611 | private void stopTrackingInner()
612 | {
613 | if(googleApiClient_ == null || !googleApiClient_.isConnected()){
614 | return;
615 | }
616 |
617 | final LocationListener listener = locationListener_;
618 | LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient_, listener);
619 | }
620 |
621 | private LocationListener locationTracker_ = new LocationListener() {
622 | @Override
623 | public void onLocationChanged(Location location) {
624 | setLastLocation(location);
625 | }
626 | };
627 | }
628 |
--------------------------------------------------------------------------------