Skip to content

Commit

Permalink
Counter_v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
LaIixia committed Apr 22, 2024
1 parent a494604 commit 63fab87
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 74 deletions.
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.0"
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
28 changes: 20 additions & 8 deletions app/src/main/java/com/myapp/textcounter/Buttons.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package com.myapp.textcounter;

import android.text.Editable;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;

public class Buttons {
public class Buttons extends AppCompatActivity {
//テキストのカウント
private int textLen;

//edittextの文字列の長さを取得するメソッド
public void setCount(Editable text){this.textLen = text.length();}
//edittextの文字列の長さを返すメソッド
public int getCount(){ return this.textLen; }

public boolean setJudge(int len){
if(len == 0){
return true;
}
else {
return false;
}
//edittextの文字列の長さが0であるか判断するメソッド
public boolean setJudge(){
if(textLen == 0){return true;}
else {return false;}
}
//Int型からstring型に変換するメソッド
//textLenの値から変換
public String format(){return Integer.toString (textLen);}
//引数から変換
public String formatter(int lines){
return Integer.toString (lines);
}



}
33 changes: 15 additions & 18 deletions app/src/main/java/com/myapp/textcounter/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import android.view.View;
import java.util.Objects;
import static androidx.appcompat.app.AppCompatDelegate.*;
//AppcompatActivityクラスに継承
public class MainActivity extends AppCompatActivity {

public class MainActivity extends AppCompatActivity {//継承
//フィールド
private EditText editText;
private TextView textLetter,textLines;
Expand Down Expand Up @@ -48,37 +48,34 @@ protected void onCreate(Bundle savedInstanceState) {
//テキストペースト
Button button_pst = findViewById(R.id.button_pst);
button_pst.setOnClickListener(new ButtonPaste());

}

class ButtonCount implements View.OnClickListener {
//トーストメッセージ
Context toastMsg = getApplicationContext();
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();
if(bt.setJudge()){
Toast.makeText(getApplicationContext(), R.string.noText, Toast.LENGTH_SHORT).show();//トーストメッセージ
}
textLetter.setText(Integer.toString(bt.getCount()));
textLines.setText(Integer.toString(editText.getLineCount()));
textLetter.setText(bt.format());
textLines.setText(bt.formatter(editText.getLineCount()));
}
}

class ButtonDelete implements View.OnClickListener {
public void onClick(View view){
editText.getText().clear();
textLetter.setText(Integer.toString(editText.getText().length()));
textLines.setText(Integer.toString(editText.getLineCount()));
textLetter.setText(bt.formatter(editText.getText().length()));
textLines.setText(bt.formatter(editText.getLineCount()));
}
}

class ButtonCopy implements View.OnClickListener {
//クリップボードにコピー | クリップボードマネージャー
//クリップボードマネージャー
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
Context toastMsg = getApplicationContext();
public void onClick(View view) {
bt.setCount(editText.getText());
if(bt.setJudge(bt.getCount ())){
Toast.makeText(toastMsg, R.string.noText, Toast.LENGTH_SHORT).show();
if(bt.setJudge()){
Toast.makeText(getApplicationContext(), R.string.noText, Toast.LENGTH_SHORT).show();
}else{
// Editのテキストを取得
ClipData clip = ClipData.newPlainText(null, editText.getText());
Expand All @@ -87,7 +84,7 @@ public void onClick(View view) {
}
//OS 12L以下かつ、edittext内の文字の長さが0でない時だけバブルを出す
if(Build.VERSION.SDK_INT<=32 && bt.getCount() !=0) {
Toast.makeText(toastMsg, R.string.copy, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), R.string.copy, Toast.LENGTH_SHORT).show();
}
}
}
Expand All @@ -101,7 +98,7 @@ public void onClick(View view) {
CharSequence pasteData = item.getText ( );
editText.setText (pasteData);
textLetter.setText (pasteData.length ( ));
textLines.setText(Integer.toString(editText.getLineCount()));
textLines.setText(bt.formatter(editText.getLineCount()));
} catch (Exception e) {
return;
}
Expand Down
87 changes: 42 additions & 45 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,72 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/teal"
tools:context=".MainActivity">

<EditText
android:id="@+id/edit_text"
android:layout_width="265dp"
android:layout_height="320dp"
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"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.433" />
android:textAlignment="center"
tools:context=".MyActivity">

<Button
android:id="@+id/button_cnt"
android:layout_width="wrap_content"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginBottom="95dp"
android:text="@string/button_cnt"
app:backgroundTint="@color/purple"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.280"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.825" />
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button_cpy"
android:layout_width="wrap_content"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginStart="80dp"
android:layout_marginBottom="45dp"
android:text="@string/button_cpy"
app:backgroundTint="@color/purple"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.280"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.925" />
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button_pst"
android:layout_width="wrap_content"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginEnd="80dp"
android:layout_marginBottom="45dp"
android:backgroundTint="@color/purple"
android:text="@string/button_pst"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.695"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.925" />
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/button_del"
android:layout_width="wrap_content"
android:layout_width="95dp"
android:layout_height="wrap_content"
android:layout_marginEnd="80dp"
android:layout_marginBottom="95dp"
android:backgroundTint="@color/purple"
android:text="@string/button_del"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.697"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.825" />
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/text_letters1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="90dp"
android:layout_height="35dp"
android:layout_marginStart="100dp"
android:layout_marginTop="45dp"
android:gravity="right"
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_width="90dp"
android:layout_height="35dp"
android:layout_marginStart="100dp"
android:layout_marginTop="80dp"
android:gravity="right"
android:text="@string/lines"
android:textSize="24sp"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -120,4 +100,21 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
<EditText
android:id="@+id/edit_text"
android:layout_width="300dp"
android:layout_height="320dp"
android:layout_marginBottom="5dp"
android:autofillHints="@string/hint"
android:background="@color/white"
android:gravity="top"
android:hint="@string/hint"
android:inputType="textMultiLine"
app:layout_constraintBottom_toTopOf="@+id/button_cnt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_lines2" />

</androidx.constraintlayout.widget.ConstraintLayout>

4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<string name="hint">テキストを入力</string>
<string name="noText">テキストが入力されていません</string>
<string name="copy">コピーしました</string>
<string name="letters">文字数</string>
<string name="lines">行数</string>
<string name="letters">文字数:</string>
<string name="lines">行数:</string>
<string name="letters_zero">0</string>
<string name="lines_zero">1</string>

Expand Down

0 comments on commit 63fab87

Please sign in to comment.