Skip to content

Commit

Permalink
Counter_v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LaIixia committed Apr 19, 2024
1 parent dcedd4a commit a494604
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .idea/misc.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 "0.9"
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
25 changes: 0 additions & 25 deletions app/src/main/java/com/myapp/textcounter/Delete.java

This file was deleted.

44 changes: 20 additions & 24 deletions app/src/main/java/com/myapp/textcounter/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
package com.myapp.textcounter;




import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import android.content.ClipboardManager;
import android.content.ClipData;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
import android.os.Build;
import android.view.View;
import java.util.Objects;
import static androidx.appcompat.app.AppCompatDelegate.*;
//AppcompatActivityクラスに継承
public class MainActivity extends AppCompatActivity {
//フィールド
private EditText editText;
private TextView textView;
private TextView textLetter,textLines;
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){
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); // アプリ全体に適用
setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); // アプリ全体に適用
}else{//API28以下はダークテーマ無効化
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
setDefaultNightMode(MODE_NIGHT_NO);
}

//テキスト入力
//使用するアイテム(オブジェクト)の定義
editText = findViewById(R.id.edit_text);
//テキスト表示
textView = findViewById(R.id.text_view);
//使用するボタンの定義
textLetter = findViewById(R.id.text_letters2);
textLines = findViewById(R.id.text_lines2);

//テキストカウント
Button button_cnt = findViewById(R.id.button_cnt);
button_cnt.setOnClickListener(new ButtonCount());
Expand All @@ -53,8 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
//テキストペースト
Button button_pst = findViewById(R.id.button_pst);
button_pst.setOnClickListener(new ButtonPaste());
//view初期表示
textView.setText("0文字");

}

class ButtonCount implements View.OnClickListener {
Expand All @@ -63,16 +57,17 @@ class ButtonCount implements View.OnClickListener {
public void onClick(View view) {
bt.setCount(editText.getText());
if(bt.setJudge(bt.getCount ())){
Toast.makeText(toastMsg, R.string.notext, Toast.LENGTH_SHORT).show();
Toast.makeText(toastMsg, R.string.noText, Toast.LENGTH_SHORT).show();
}
textView.setText(bt.getCount() + "文字");
textLetter.setText(Integer.toString(bt.getCount()));
textLines.setText(Integer.toString(editText.getLineCount()));
}
}

class ButtonDelete implements View.OnClickListener {
public void onClick(View view){
editText.getText().clear();
textView.setText(editText.getText().length() + "文字");
textLetter.setText(Integer.toString(editText.getText().length()));
textLines.setText(Integer.toString(editText.getLineCount()));
}
}

Expand All @@ -83,7 +78,7 @@ class ButtonCopy implements View.OnClickListener {
public void onClick(View view) {
bt.setCount(editText.getText());
if(bt.setJudge(bt.getCount ())){
Toast.makeText(toastMsg, R.string.notext, Toast.LENGTH_SHORT).show();
Toast.makeText(toastMsg, R.string.noText, Toast.LENGTH_SHORT).show();
}else{
// Editのテキストを取得
ClipData clip = ClipData.newPlainText(null, editText.getText());
Expand All @@ -92,24 +87,25 @@ public void onClick(View view) {
}
//OS 12L以下かつ、edittext内の文字の長さが0でない時だけバブルを出す
if(Build.VERSION.SDK_INT<=32 && bt.getCount() !=0) {
Toast.makeText(toastMsg, "コピーしました", Toast.LENGTH_SHORT).show();
Toast.makeText(toastMsg, R.string.copy, Toast.LENGTH_SHORT).show();
}
}
}

class ButtonPaste implements View.OnClickListener {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
public void onClick(View view) {
CharSequence pasteData;
try {
//グリップボートのデータの位置 0番目
ClipData.Item item = Objects.requireNonNull (clipboard.getPrimaryClip ( )).getItemAt (0);
pasteData = item.getText ( );
CharSequence pasteData = item.getText ( );
editText.setText (pasteData);
textView.setText (pasteData.length ( ) + "文字");
textLetter.setText (pasteData.length ( ));
textLines.setText(Integer.toString(editText.getLineCount()));
} catch (Exception e) {
return;
}
}
}

}
45 changes: 41 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:autofillHints="@string/hint"
android:background="@color/white"
android:hint="@string/hint"
android:inputType="textMultiLine"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down Expand Up @@ -74,13 +75,49 @@
app:layout_constraintVertical_bias="0.825" />

<TextView
android:id="@+id/text_view"
android:id="@+id/text_letters1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:textSize="45sp"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="100dp"
android:layout_marginTop="45dp"
android:text="@string/letters"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text_lines1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="100dp"
android:layout_marginTop="80dp"
android:text="@string/lines"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text_letters2"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_marginTop="45dp"
android:layout_marginEnd="100dp"
android:gravity="right"
android:text="@string/letters_zero"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/text_lines2"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_marginTop="80dp"
android:layout_marginEnd="100dp"
android:gravity="right"
android:text="@string/lines_zero"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 4 additions & 5 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色-->
<item name="colorPrimary">@color/purple</item>
<!-- TextViewとeditTextの色 -->
<!-- TextViewとeditTextのテキストの色 -->
<item name="android:textColor">@color/white</item>

<!-- 背景(background)の色-->
<!-- 背景(background)の色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<item name="android:colorPrimary">@color/teal</item>
<!-- テキスト選択時のカラー-->
<item name="colorSecondary">@color/blue</item>
<!-- <item name="android:background">@color/teal</item> -->

<!-- ステータスバーカラー-->
<!-- ステータスバーカラー-->
<item name="android:statusBarColor" tools:targetApi="l">@color/teal</item>
<!-- 履歴タブのアプリ名 -->
<item name="windowActionBar">false</item>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<color name="great">#585C5C</color>
<!--テキスト選択時の色 -->
<color name="blue">#0163AF</color>


<!-- 予備 -->
<color name="black">#000000</color>
</resources>
13 changes: 9 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
<string name="button_del">リセット</string>
<string name="button_cpy">コピー</string>
<string name="button_pst">貼り付け</string>
<string name="hint">文字を入力</string>
<string name="normal">文字を入力</string>
<string name="notext">テキストが入力されていません</string>
<string name="letters">文字</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>

</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- ボタンの色-->
<item name="colorPrimary">@color/purple</item>
<!-- TextViewとeditTextの色 -->
<!-- TextViewとeditTextのテキストの色 -->
<item name="android:textColor">@color/great</item>
<!-- 背景(background)の色-->
<item name="android:colorPrimary">@color/teal</item>
<!-- 背景(background)の色--><!-- アプリの主なブランドカラー,デフォルトではアクションバーの背景。 -->
<item name="android:colorPrimary">@color/white</item>
<!-- テキスト選択時のカラー-->
<item name="colorSecondary">#5A9ACC</item>
<!-- <item name="android:background">@color/teal</item> -->

<!-- ステータスバーカラー -->
<item name="android:statusBarColor" tools:targetApi="l">@color/teal</item>
Expand Down
23 changes: 10 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# This option should only be used with decoupled projects. For more details, visit
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
#Fri Apr 19 20:29:14 JST 2024
android.enableJetifier=true
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
org.gradle.jvmargs=-Xmx1024M -Dkotlin.daemon.jvm.options\="-Xmx1024M" -Dfile.encoding\=UTF-8

0 comments on commit a494604

Please sign in to comment.