Skip to content

Commit

Permalink
Counter_v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
LaIixia committed Jul 11, 2024
1 parent ca82c59 commit 68d1653
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 93 deletions.
6 changes: 6 additions & 0 deletions .idea/render.experimental.xml

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

10 changes: 5 additions & 5 deletions 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.4"
versionName "1.5"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -22,8 +22,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

Expand All @@ -33,7 +33,7 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.0'

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SubActivity"></activity>
</application>

</manifest>
45 changes: 24 additions & 21 deletions app/src/main/java/com/myapp/textcounter/Buttons.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@

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

public class Buttons extends AppCompatActivity {
//テキストのカウント
public class Buttons {

//edittextのテキストの行数を取得するメソッド
public String line(EditText text) {return format(text.getLineCount());}
//edittextの文字列の長さを取得するメソッド
public String Count(Editable text) {
return Integer.toString (text.length ( ));
}
public String Count(Editable text) {return format(text.length ( ));}
//SubActivity用
public String Count(String text) {return format(text.length ( ));}
//edittextの改行抜きでテキストの文字数を取得するメソッド
public String BreakCnt(String letters,String lines) {return format((Integer.parseInt(letters) - Integer.parseInt(lines))+1);}
//空白抜きでテキストの文字数をカウント
public String EmptyCnt(String letters) {return format(letters.replaceAll(" ", "").length());}
//Intをstring型に変換するメソッド
public String format(int lines) {return String.valueOf (lines);}

//edittextの文字列の長さが0であるか判断するメソッド
public boolean Judge(Editable s) {
int L = s.toString ( ).length ( );
if (L == 0) {
public boolean Judge(Editable l) {return Integer.parseInt (Count (l)) == 0;}//0の場合だけtrueを返す
//OS Version Check
public boolean ChkOS(int v) {return Build.VERSION.SDK_INT <= v;}//osが引数v以下の場合だけtrueを返す

/*public boolean Judge(Editable l) {
if (Integer.parseInt (Count (l)) == 0) {
return true;
} else {
return false;
}
}

//Int型からstring型に変換するメソッド
public String format(int lines) {
return Integer.toString (lines);
}

//OS Version Check
public boolean ChkOS(int ver) {
if (Build.VERSION.SDK_INT <= ver) {
public boolean ChkOS(int v) {
if (Build.VERSION.SDK_INT <= v) {
return true;
} else {
return false;
}
}
}

}*/
}
52 changes: 37 additions & 15 deletions app/src/main/java/com/myapp/textcounter/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.ClipboardManager;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
Expand All @@ -20,27 +21,37 @@

public class MainActivity extends AppCompatActivity {//継承

//フィールドonCreate内で呼び出すために、privateで宣言
private Buttons bt ;
private EditText e;
private TextView textLetter ,textLines;
private ClipboardManager clipboard;
//フィールド onCreate内で呼び出すために、ここで各クラスを宣言
Buttons bt ;
EditText e;
TextView textLetter ,textLines;
ClipboardManager clipboard;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/* int dpi = getResources().getDisplayMetrics().densityDpi;
if(dpi <=420){
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}*/

//Activity起動時リソースのidに呼び出して、フィールドに代入
bt = new Buttons();
e = findViewById(R.id.edit_text);
textLetter = findViewById (R.id.text_letters2);
textLines = findViewById (R.id.text_lines2);
clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
System.out.println(e.getLineCount());
View (bt.Count (e.getText ( )), bt.format (e.getLineCount ()));

//テキストカウント
Button button_cnt = findViewById(R.id.button_cnt);
button_cnt.setOnClickListener(new ButtonCount());
button_cnt.setOnLongClickListener(new Buttonl());
//テキスト削除
Button button_del = findViewById(R.id.button_del);
button_del.setOnClickListener(new ButtonDelete());
Expand All @@ -61,7 +72,18 @@ protected void onCreate(Bundle savedInstanceState) {
toggleSwitch.setOnCheckedChangeListener(new Theme());
}

static class Theme implements CompoundButton.OnCheckedChangeListener{
class Buttonl implements View.OnLongClickListener {
public boolean onLongClick(View v) {
Intent MS = new Intent(MainActivity.this, SubActivity.class)
.putExtra("text data",String.valueOf (e.getText ()))//テキストの内容
.putExtra("text lines",bt.line (e));//行
startActivity(MS);//subActivityの開始
//finish();ActivityのEdittextを保持させておくため
return false;
}
}

class Theme implements CompoundButton.OnCheckedChangeListener{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
setDefaultNightMode(MODE_NIGHT_YES);
Expand All @@ -77,9 +99,9 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
TWでaddイベントを呼ぶと、removeする際に同じ場所(TW)を参照することでwatcherが切れる
*/
class Check implements CompoundButton.OnCheckedChangeListener{
TextEvent TW = new TextEvent ();
public void onCheckedChanged(CompoundButton buttonView1, boolean isChecked) {
View (bt.Count (e.getText ( )), bt.format (e.getLineCount ( )));
TextEvent TW = new TextEvent ();
View (bt.Count (e.getText ( )), bt.line(e));
if (isChecked) {
e.addTextChangedListener (TW);
}else{
Expand All @@ -91,21 +113,21 @@ class TextEvent implements TextWatcher {
public void beforeTextChanged(CharSequence charSequence, int A, int B, int C) {}
public void onTextChanged(CharSequence charSequence, int A, int B, int C) {}
public void afterTextChanged(Editable editable) {
View (bt.Count (e.getText ( )), bt.format (e.getLineCount ( )));
View (bt.Count (e.getText ( )), bt.line(e));
}
}

class ButtonCount implements View.OnClickListener {
public void onClick(View view) {
if (bt.Judge (e.getText ( ))) {toast ( R.string.noText);}
View (bt.Count (e.getText ( )), bt.format (e.getLineCount ( )));
if (bt.Judge(e.getText ( ))) {toast ( R.string.noText);}
View(bt.Count(e.getText()),bt.line(e));
}
}

class ButtonDelete implements View.OnClickListener {
public void onClick(View view){
e.getText().clear();
View(bt.Count(e.getText()),bt.format(e.getLineCount()));
View(bt.Count(e.getText()),bt.line(e));
}
}

Expand All @@ -117,7 +139,7 @@ public void onClick(View view) {
clipboard.setPrimaryClip(clip);//クリップボードにセット
}
//OS 12L以下かつ、edittext内の文字の長さが0でない時だけバブルを出す
if(bt.ChkOS(32) && e.length() !=0) {toast(R.string.copy);}
if(bt.ChkOS(32) && !bt.Judge (e.getText ())) {toast(R.string.copy);}
}
}

Expand All @@ -127,11 +149,11 @@ public void onClick(View view) {
ClipData.Item item = Objects.requireNonNull (clipboard.getPrimaryClip ( )).getItemAt (0);
String pasteData = item.getText().toString();
e.setText (pasteData);
View(bt.format(pasteData.length()),bt.format(e.getLineCount()));
View(bt.format(pasteData.length()),bt.line(e));
}
catch (Exception e) {System.out.println(e); return;}
}
}
void toast(int id){Toast.makeText(getApplicationContext(), id, Toast.LENGTH_SHORT).show();}
void toast(int resId){Toast.makeText(getApplicationContext(), resId, Toast.LENGTH_SHORT).show();}
void View(String a,String b){textLetter.setText (a);textLines.setText(b);}
}
76 changes: 76 additions & 0 deletions app/src/main/java/com/myapp/textcounter/SubActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.myapp.textcounter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.io.UnsupportedEncodingException;

public class SubActivity extends AppCompatActivity {
private TextView LI,LT,PA,BR,EM,EUC,UTF8,UTF16,JIS,SHIFT;
Buttons bt = new Buttons ();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);

View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);

Button BK = findViewById (R.id.button_back);
BK.setOnClickListener (new Back());

Bundle b = getIntent().getExtras();
String text = b.getString("text data"),
lines = b.getString ("text lines");

/* TextView LT = findViewById (R.id.text_letters2),
LI = findViewById (R.id.text_lines2),
PA = findViewById (R.id.text_paper2),
EM = findViewById (R.id.text_empty2),
BR = findViewById (R.id.text_break2),
UTF8 = findViewById (R.id.text_utf_8_2),
UTF16 = findViewById (R.id.text_utf_16_2),
EUC = findViewById (R.id.text_euc_2),
SHIFT = findViewById (R.id.text_shift_2),
JIS = findViewById (R.id.text_jis_2);*/

LT = findViewById (R.id.text_letters2);
LI = findViewById (R.id.text_lines2);
//PA = findViewById (R.id.text_paper2);
BR = findViewById (R.id.text_break2);
EM = findViewById (R.id.text_empty2);
UTF8 = findViewById (R.id.text_utf_8_2);
UTF16 = findViewById (R.id.text_utf_16_2);
EUC = findViewById (R.id.text_euc_2);
SHIFT = findViewById (R.id.text_shift_2);
//JIS = findViewById (R.id.text_jis_2);

try {
LT.setText (bt.Count (text));
LI.setText (lines);
//PA.setText ();
BR.setText (bt.BreakCnt (bt.Count (text),lines));
EM.setText (bt.EmptyCnt(text));
UTF8.setText(bt.format (text.getBytes("UTF-8").length));
UTF16.setText(bt.format (text.getBytes("UTF-16").length));
EUC.setText(bt.format (text.getBytes("EUC-JP").length));
SHIFT.setText(bt.format (text.getBytes("SHIFT-JIS").length));
//JIS.setText(bt.format (text.getBytes("JIS_X0201").length));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

class Back implements View.OnClickListener{
public void onClick(View v){
new Intent (SubActivity.this,MainActivity.class);
/*startActivity(); 推移先のActivityを新しく開始する
新しくactivityを開始することなく、SubActivityを閉じる*/
finish ();
}
}
}
Loading

0 comments on commit 68d1653

Please sign in to comment.