Skip to content

Commit

Permalink
Counter_v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
LaIixia committed May 19, 2024
1 parent ea4b419 commit 56b5a13
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdk 21
targetSdk 34
versionCode 1
versionName "1.1"
versionName "1.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
10 changes: 3 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?xml version="1.0" encoding="utf-8"?><!--Androidアプリを作る際に必須のアプリに関する情報-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.textcounter">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myapp.textcounter">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity
android:name=".MainActivity"
android:exported="true">
android:theme="@style/Theme.TextCounter">
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/com/myapp/textcounter/Buttons.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -26,6 +23,4 @@ public String formatter(int lines){
return Integer.toString (lines);
}



}
48 changes: 35 additions & 13 deletions app/src/main/java/com/myapp/textcounter/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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;
}
}
}

}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

Expand Down Expand Up @@ -116,5 +117,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_lines2" />

<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.956"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.015" />

</androidx.constraintlayout.widget.ConstraintLayout>

6 changes: 3 additions & 3 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- ダークテーマ用 テーマで使用するカラーの指定 -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色-->
<style name="Theme.TextCounter" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<item name="colorPrimary">@color/purple</item>
<!-- TextViewとeditTextのテキストの色 -->
<item name="android:textColor">@color/white</item>
<!-- 背景(background)の色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<!-- 背景(background)の色-->
<item name="android:colorPrimary">@color/teal</item>
<!-- テキスト選択時のカラー-->
<item name="colorSecondary">@color/blue</item>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
<string name="button_cpy">コピー</string>
<string name="button_pst">貼り付け</string>

<string name="button_dark">ダークモード</string>

<string name="hint">テキストを入力</string>
<string name="noText">テキストが入力されていません</string>
<string name="copy">コピーしました</string>
<string name="letters">文字数:</string>
<string name="lines">行数:</string>
<string name="letters_zero">0</string>
<string name="lines_zero">1</string>
<string name="True">有効</string>
<string name="False">無効</string>

</resources>
6 changes: 3 additions & 3 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- ホワイトテーマ用 テーマで使用するカラーの指定 -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色-->
<style name="Theme.TextCounter" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<item name="colorPrimary">@color/purple</item>
<!-- TextViewとeditTextのテキストの色 -->
<item name="android:textColor">@color/great</item>
<!-- 背景(background)の色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<!-- 背景(background)の色-->
<item name="android:colorPrimary">@color/white</item>
<!-- テキスト選択時のカラー-->
<item name="colorSecondary">#5A9ACC</item>
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ dependencyResolutionManagement {
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "My Application"
rootProject.name = "TextCounter"
include ':app'

0 comments on commit 56b5a13

Please sign in to comment.