Skip to content

Commit

Permalink
Counter_v0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
LaIixia committed Apr 17, 2024
1 parent f1788f3 commit 1a47b16
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.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/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.8"
versionName "0.9"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/myapp/textcounter/Buttons.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ public class Buttons {
public void setCount(Editable text){this.textLen = text.length();}
public int getCount(){ return this.textLen; }

public boolean setJudge(int len){
if(len == 0){
return true;
}
else {
return false;
}
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/myapp/textcounter/Delete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.myapp.textcounter;
/*
import android.text.Editable;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Delete extends AppCompatActivity {
private EditText editText;
private TextView textView;
public void creater (){
//テキスト入力
editText = findViewById(R.id.edit_text);
//テキスト表示
textView = findViewById(R.id.text_view);
editText.getText().clear();
textView.setText(editText.getText().length() + "文字");
//textView.setText();
//textView.getText();
}
}*/
97 changes: 57 additions & 40 deletions app/src/main/java/com/myapp/textcounter/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,88 +1,89 @@
package com.myapp.textcounter;

import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;



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.MenuItem;
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 java.util.Objects;

import static androidx.appcompat.app.AppCompatDelegate.*;
//AppcompatActivityクラスに継承
public class MainActivity extends AppCompatActivity {
//フィールド
private EditText editText;
private TextView textView;
private int MODE_NIGHT_YES;
Buttons bt = new Buttons();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); // アプリ全体に適用

//API28以降はシステムの設定に依存させる
if(Build.VERSION.SDK_INT>=28){
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM); // アプリ全体に適用
}else{//API28以下はダークテーマ無効化
AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
}

//テキスト入力
editText = findViewById(R.id.edit_text);
//テキスト表示
textView = findViewById(R.id.text_view);
//テキストカウントボタン
textView = findViewById(R.id.text_view);
//使用するボタンの定義
//テキストカウント
Button button_cnt = findViewById(R.id.button_cnt);
//テキスト削除ボタン
button_cnt.setOnClickListener(new ButtonCount());
//テキスト削除
Button button_del = findViewById(R.id.button_del);
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());
//view初期表示
textView.setText("0文字");
}

//クリップボードにコピー | クリップボード クラス
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
class ButtonCount implements View.OnClickListener {
//トーストメッセージ
Context toastMsg = getApplicationContext();

//テキストペースト
button_pst.setOnClickListener(v -> {
CharSequence pasteData;
try {
//グリップボートのデータの位置 0番目
ClipData.Item item = Objects.requireNonNull (clipboard.getPrimaryClip ( )).getItemAt (0);
pasteData = item.getText ( );
editText.setText (pasteData);
textView.setText (pasteData.length ( ) + "文字");
} catch (Exception e) {
return;
}
});

//テキストのカウント
button_cnt.setOnClickListener(v -> {
Context toastMsg = getApplicationContext();
public void onClick(View view) {
bt.setCount(editText.getText());
if(bt.getCount()==0){
Toast.makeText(toastMsg, "テキストが入力されていません", Toast.LENGTH_SHORT).show();
if(bt.setJudge(bt.getCount ())){
Toast.makeText(toastMsg, R.string.notext, Toast.LENGTH_SHORT).show();
}
textView.setText(bt.getCount() + "文字");
});
}
}

//テキスト削除
button_del.setOnClickListener(v -> {
class ButtonDelete implements View.OnClickListener {
public void onClick(View view){
editText.getText().clear();
textView.setText(editText.getText().length() + "文字");
});
}
}

//テキストコピー
button_cpy.setOnClickListener(v -> {
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.getCount()==0){
Toast.makeText(toastMsg, "テキストが入力されていません", Toast.LENGTH_SHORT).show();
if(bt.setJudge(bt.getCount ())){
Toast.makeText(toastMsg, R.string.notext, Toast.LENGTH_SHORT).show();
}else{
// Editのテキストを取得
ClipData clip = ClipData.newPlainText(null, editText.getText());
Expand All @@ -93,6 +94,22 @@ protected void onCreate(Bundle savedInstanceState) {
if(Build.VERSION.SDK_INT<=32 && bt.getCount() !=0) {
Toast.makeText(toastMsg, "コピーしました", 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 ( );
editText.setText (pasteData);
textView.setText (pasteData.length ( ) + "文字");
} catch (Exception e) {
return;
}
}
}
}
49 changes: 23 additions & 26 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
android:background="@color/teal"
tools:context=".MainActivity">

<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:gravity="center_horizontal"
android:textSize="45sp"
app:drawableTint="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/edit_text"
android:layout_width="265dp"
Expand All @@ -34,19 +21,6 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.433" />

<Button
android:id="@+id/button_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_del"
app:backgroundTint="@color/purple"
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.825" />

<Button
android:id="@+id/button_cnt"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -86,4 +60,27 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.925" />

<Button
android:id="@+id/button_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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" />

<TextView
android:id="@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:textSize="45sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources><!--カラーパレット (ダークテーマで必要な色だけ定義)-->
<!-- ボタンの色-->
<color name="purple">#50A1E1</color>
<!-- 背景(background)の色-->
<color name="teal">#313535</color>
<!-- edittext@backgroundとTextView@backgroundの色 -->
<color name="white">#FFFFFFFF</color>


</resources>
19 changes: 12 additions & 7 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- ダークテーマ用 カラーパレット宣言(Base application theme. ) -->
<!-- ダークテーマ用 テーマで使用するカラーの指定 -->
<style name="Theme.MyApplication" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. --><!-- Secondary brand color. -->
<!-- ボタンの色-->
<item name="colorPrimary">@color/purple</item>
<item name="colorOnPrimary">@color/white</item>
<item name="colorSecondary">@color/teal</item>
<item name="colorOnSecondary">@color/black</item>
<!-- ステータスバーカラー(Status bar color.) -->
<!-- TextViewとeditTextの色 -->
<item name="android:textColor">@color/white</item>

<!-- 背景(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>
<!-- Activityの上のアプリ名タブ -->
<!-- Activityの上のアプリ名タブ -->
<item name="windowNoTitle">true</item>
</style>
</resources>
13 changes: 11 additions & 2 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources><!--カラーパレット -->
<!-- ボタンの色-->
<color name="purple">#FF6200EE</color>
<!-- 背景(background)の色-->
<color name="teal">#99EAF4</color>
<color name="black">#FF000000</color>
<!-- edittext@backgroundの色 -->
<color name="white">#FFFFFFFF</color>
<!-- TextViewとeditText@textcolorの色 -->
<color name="great">#585C5C</color>
<!--テキスト選択時の色 -->
<color name="blue">#0163AF</color>


<color name="black">#000000</color>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<string name="button_pst">貼り付け</string>
<string name="hint">文字を入力</string>
<string name="normal">文字を入力</string>
<string name="notext">テキストが入力されていません</string>
<string name="letters">文字</string>
</resources>
Loading

0 comments on commit 1a47b16

Please sign in to comment.