diff --git a/.idea/.name b/.idea/.name index b3405b3..acd4847 100644 --- a/.idea/.name +++ b/.idea/.name @@ -1 +1 @@ -My Application \ No newline at end of file +TextCounter \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 0c0c338..5144d27 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -2,6 +2,9 @@ + + + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..827fb4d --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 0fbe8d8..b21fb9b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { minSdk 21 targetSdk 34 versionCode 1 - versionName "1.1" + versionName "1.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 190f3bb..d80d4a0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + - + android:theme="@style/Theme.TextCounter"> + - diff --git a/app/src/main/java/com/myapp/textcounter/Buttons.java b/app/src/main/java/com/myapp/textcounter/Buttons.java index 636a914..51ded74 100644 --- a/app/src/main/java/com/myapp/textcounter/Buttons.java +++ b/app/src/main/java/com/myapp/textcounter/Buttons.java @@ -1,10 +1,7 @@ package com.myapp.textcounter; import android.text.Editable; -import android.widget.EditText; -import androidx.appcompat.app.AppCompatActivity; - -public class Buttons extends AppCompatActivity { +public class Buttons { //テキストのカウント private int textLen; @@ -26,6 +23,4 @@ public String formatter(int lines){ return Integer.toString (lines); } - - } diff --git a/app/src/main/java/com/myapp/textcounter/MainActivity.java b/app/src/main/java/com/myapp/textcounter/MainActivity.java index 7ccadfe..25399a1 100644 --- a/app/src/main/java/com/myapp/textcounter/MainActivity.java +++ b/app/src/main/java/com/myapp/textcounter/MainActivity.java @@ -4,10 +4,12 @@ import android.content.ClipboardManager; import android.content.ClipData; import android.content.Context; -import android.widget.Button; +import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; +import android.widget.Button; import android.os.Bundle; import android.os.Build; import android.view.View; @@ -16,22 +18,15 @@ public class MainActivity extends AppCompatActivity {//継承 //フィールド - private EditText editText; private TextView textLetter,textLines; + private EditText editText; Buttons bt = new Buttons(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - //API28以降はシステムの設定に依存させる - if(Build.VERSION.SDK_INT>=28){ - setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); // アプリ全体に適用 - }else{//API28以下はダークテーマ無効化 - setDefaultNightMode(MODE_NIGHT_NO); - } - - //使用するアイテム(オブジェクト)の定義 + //使用アイテムの定義 editText = findViewById(R.id.edit_text); textLetter = findViewById(R.id.text_letters2); textLines = findViewById(R.id.text_lines2); @@ -41,15 +36,43 @@ protected void onCreate(Bundle savedInstanceState) { button_cnt.setOnClickListener(new ButtonCount()); //テキスト削除 Button button_del = findViewById(R.id.button_del); - button_del.setOnClickListener( new ButtonDelete()); + button_del.setOnClickListener(new ButtonDelete()); //テキストコピー Button button_cpy = findViewById(R.id.button_cpy); button_cpy.setOnClickListener(new ButtonCopy()); //テキストペースト Button button_pst = findViewById(R.id.button_pst); button_pst.setOnClickListener(new ButtonPaste()); + + //スイッチの イベントを作成 + Switch toggleSwitch = findViewById(R.id.switch1); + toggleSwitch.setOnCheckedChangeListener(new onCheckedChangeListener()); + + //起動時にシステムのダークモードがYESの場合はtrue(ダークモードオン) + if(getDefaultNightMode() == MODE_NIGHT_YES){ + toggleSwitch.setChecked(true); + } + //そうでない場合はfalse(無効) + else if(getDefaultNightMode()== MODE_NIGHT_NO){ + toggleSwitch.setChecked(false); + } } + // トグルスイッチを押した時に処理するクラス。 + class onCheckedChangeListener implements CompoundButton.OnCheckedChangeListener{ + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + + if (isChecked) { + setDefaultNightMode(MODE_NIGHT_YES); + //Toast.makeText(getApplicationContext(), R.string.True, Toast.LENGTH_SHORT).show(); + } + else { + setDefaultNightMode(MODE_NIGHT_NO); + //Toast.makeText(getApplicationContext(), R.string.False, Toast.LENGTH_SHORT).show(); + } + } + } class ButtonCount implements View.OnClickListener { public void onClick(View view) { bt.setCount(editText.getText()); @@ -100,9 +123,8 @@ public void onClick(View view) { textLetter.setText (pasteData.length ( )); textLines.setText(bt.formatter(editText.getLineCount())); } catch (Exception e) { - return; + System.out.println(e); return; } } } - } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5a87948..3e1d610 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/teal" + android:foregroundTint="@color/white" android:textAlignment="center" tools:context=".MyActivity"> @@ -116,5 +117,17 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/text_lines2" /> + + diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index e6c0442..43b181e 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,11 +1,11 @@ -