Skip to content

Commit 12d866f

Browse files
committed
StsExtension を追加
1 parent 161122c commit 12d866f

File tree

11 files changed

+191
-2
lines changed

11 files changed

+191
-2
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ android {
4646

4747
dependencies {
4848
compileOnly files('libs/BenesseExtension.jar')
49+
implementation files('libs/StsExtension.jar')
4950
}

app/libs/StsExtension.jar

1.49 KB
Binary file not shown.

app/src/main/AndroidManifest.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
66

77
<application
8-
android:icon="@mipmap/ic_launcher"
8+
android:icon="@drawable/ic_launcher"
99
android:label="@string/app_name">
1010
<activity
1111
android:name=".Tester"
@@ -31,6 +31,19 @@
3131
</intent-filter>
3232
</activity>
3333

34+
<activity
35+
android:name=".StsTester"
36+
android:enabled="false"
37+
android:exported="true"
38+
android:icon="@drawable/ic_launcher_sts"
39+
android:label="@string/sts_name"
40+
android:launchMode="singleInstance">
41+
<intent-filter>
42+
<action android:name="android.intent.action.MAIN" />
43+
<category android:name="android.intent.category.LAUNCHER" />
44+
</intent-filter>
45+
</activity>
46+
3447
</application>
3548

3649
</manifest>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package me.s1204.benesse.touch.test;
2+
3+
import android.app.Activity;
4+
import android.content.ComponentName;
5+
import android.content.Intent;
6+
import android.content.pm.PackageManager;
7+
import android.os.Bundle;
8+
import android.view.Menu;
9+
import android.view.MenuItem;
10+
import android.widget.EditText;
11+
import android.widget.Toast;
12+
13+
import androidx.annotation.NonNull;
14+
15+
import com.sts.tottori.extension.BenesseExtension;
16+
17+
public class StsTester extends Activity {
18+
19+
20+
private void makeText(String msg) {
21+
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
22+
}
23+
24+
private void noClassFound(@NonNull NoClassDefFoundError ignored) {
25+
makeText("StsExtensionService が存在しません");
26+
finishAndRemoveTask();
27+
}
28+
29+
private void reflective(@NonNull ReflectiveOperationException ignored) {
30+
makeText("ReflectiveOperationException");
31+
}
32+
33+
private void backHome() {
34+
finish();
35+
startActivity(new Intent(Intent.ACTION_MAIN)
36+
.addCategory(Intent.CATEGORY_DEFAULT)
37+
.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
38+
.setClassName(getPackageName(), getClass().getName()));
39+
}
40+
41+
@Override
42+
public void onCreate(Bundle savedInstanceState) {
43+
super.onCreate(savedInstanceState);
44+
setContentView(R.layout.sts);
45+
46+
// getLcdSize
47+
findViewById(R.id.btn_getLcdSize).setOnClickListener(view -> {
48+
try {
49+
makeText("getLcdSize:" + BenesseExtension.getLcdSize());
50+
} catch (NoClassDefFoundError e) {
51+
noClassFound(e);
52+
} catch (ReflectiveOperationException e) {
53+
reflective(e);
54+
}
55+
});
56+
57+
// setForcedDisplaySize(int, int)
58+
findViewById(R.id.btn_setForcedDisplaySize).setOnClickListener(view -> {
59+
setContentView(R.layout.layout_setforceddisplaysize);
60+
findViewById(R.id.exec).setOnClickListener(view15 -> {
61+
EditText widthBox = findViewById(R.id.setForcedDisplaySize_width);
62+
EditText heightBox = findViewById(R.id.setForcedDisplaySize_height);
63+
String width = widthBox.getText().toString();
64+
String height = heightBox.getText().toString();
65+
if (width.isEmpty() || height.isEmpty()) {
66+
makeText("値を入力してください");
67+
return;
68+
}
69+
try {
70+
makeText("実行結果:" + BenesseExtension.setForcedDisplaySize(Integer.parseInt(width), Integer.parseInt(height)));
71+
} catch (NoClassDefFoundError e) {
72+
noClassFound(e);
73+
} catch (ReflectiveOperationException e) {
74+
reflective(e);
75+
}
76+
});
77+
// メニューに戻る
78+
findViewById(R.id.backHome).setOnClickListener(view16 -> backHome());
79+
});
80+
}
81+
82+
@Override
83+
@Deprecated
84+
public void onBackPressed() {
85+
super.onBackPressed();
86+
backHome();
87+
}
88+
89+
@Override
90+
public boolean onCreateOptionsMenu(Menu menu) {
91+
super.onCreateOptionsMenu(menu);
92+
getMenuInflater().inflate(R.menu.menu_sts, menu);
93+
return true;
94+
}
95+
96+
@Override
97+
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
98+
super.onOptionsItemSelected(item);
99+
int itemId = item.getItemId();
100+
if (itemId == R.id.menu_disable) {
101+
getPackageManager().setComponentEnabledSetting(new ComponentName(this, getClass().getName()), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
102+
finishAndRemoveTask();
103+
return true;
104+
}
105+
return super.onOptionsItemSelected(item);
106+
}
107+
}

app/src/main/java/me/s1204/benesse/touch/test/Tester.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.Manifest;
44
import android.app.Activity;
5+
import android.content.ComponentName;
56
import android.content.Intent;
67
import android.content.pm.PackageManager;
78
import android.os.BenesseExtension;
@@ -32,7 +33,7 @@ private void backHome() {
3233
}
3334

3435
private void makeText(String msg) {
35-
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
36+
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
3637
}
3738

3839
private void noClassFound(@NonNull NoClassDefFoundError ignored) {
@@ -333,17 +334,20 @@ public void onCreate(Bundle savedInstanceState) {
333334
@Override
334335
@Deprecated
335336
public void onBackPressed() {
337+
super.onBackPressed();
336338
backHome();
337339
}
338340

339341
@Override
340342
public boolean onCreateOptionsMenu(Menu menu) {
343+
super.onCreateOptionsMenu(menu);
341344
getMenuInflater().inflate(R.menu.menu, menu);
342345
return true;
343346
}
344347

345348
@Override
346349
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
350+
super.onOptionsItemSelected(item);
347351
int itemId = item.getItemId();
348352
if (itemId == R.id.menu_about) {
349353
setContentView(R.layout.about);
@@ -354,6 +358,10 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
354358
} else if (itemId == R.id.menu_devopts) {
355359
startActivity(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
356360
return true;
361+
} else if (itemId == R.id.menu_enable) {
362+
getPackageManager().setComponentEnabledSetting(new ComponentName(this, StsTester.class.getName()), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
363+
startActivity(new Intent(Intent.ACTION_MAIN).setClassName(this, StsTester.class.getName()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
364+
return true;
357365
}
358366
return super.onOptionsItemSelected(item);
359367
}
File renamed without changes.
5.08 KB
Loading

app/src/main/res/layout/sts.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
tools:ignore="HardcodedText">
7+
8+
<LinearLayout
9+
android:layout_width="match_parent"
10+
android:layout_height="wrap_content"
11+
android:orientation="vertical"
12+
android:padding="30dp">
13+
14+
<LinearLayout
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent"
17+
android:padding="1dp">
18+
19+
<Button
20+
android:id="@+id/btn_getLcdSize"
21+
android:layout_width="0dp"
22+
android:layout_height="wrap_content"
23+
android:layout_gravity="center"
24+
android:layout_weight="1"
25+
android:text="getLcdSize"
26+
android:textAllCaps="false"
27+
android:textSize="16sp" />
28+
</LinearLayout>
29+
30+
<LinearLayout
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:padding="1dp">
34+
35+
<Button
36+
android:id="@+id/btn_setForcedDisplaySize"
37+
android:layout_width="0dp"
38+
android:layout_height="wrap_content"
39+
android:layout_gravity="center"
40+
android:layout_weight="1"
41+
android:text="setForcedDisplaySize"
42+
android:textAllCaps="false"
43+
android:textSize="16sp" />
44+
</LinearLayout>
45+
46+
</LinearLayout>
47+
</ScrollView>

app/src/main/res/menu/menu.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
android:id="@+id/menu_devopts"
1313
android:showAsAction="never"
1414
android:title="開発者向けオプション" />
15+
<item
16+
android:id="@+id/menu_enable"
17+
android:showAsAction="never"
18+
android:title="StsExtension" />
19+
1520
</menu>

app/src/main/res/menu/menu_sts.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:id="@+id/menu_disable"
5+
android:showAsAction="never"
6+
android:title="アクティビティの無効化" />
7+
</menu>

0 commit comments

Comments
 (0)