Skip to content
This repository was archived by the owner on Feb 25, 2022. It is now read-only.

Commit 6d8e8ae

Browse files
author
Hisanobu Tomari
committed
Improve Share action by supporting randomized java
1 parent 9f9f248 commit 6d8e8ae

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

app/src/main/java/com/example/javabutton/MainActivity.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public class MainActivity extends Activity implements SensorEventListener, OnSha
4242
private GestureDetector gDetector;
4343
private JavaGestureListener gestureListener;
4444
private boolean enableLucky=false;
45-
private java.util.Random random;
45+
private final java.util.Random random=new java.util.Random();
4646
private boolean enableShakeModulation=true;
4747
private long counterDJ, counterPress, counterShake, counterVoice;
48-
48+
private Intent shareIntent;
49+
private String[] meigen;
4950
@Override
5051
protected void onCreate(Bundle savedInstanceState) {
5152
super.onCreate(savedInstanceState);
5253
setContentView(R.layout.activity_main);
53-
random=new java.util.Random();
5454

5555
javaPool=new SoundPool(maxJavaSounds,AudioManager.STREAM_MUSIC,0);
5656
javaSoundId=javaPool.load(this, R.raw.java22, 1);
@@ -78,7 +78,7 @@ private void loadPreferences(SharedPreferences shrPrefs) {
7878
}
7979
z=Math.max(1.f, Math.min(x, y));
8080
v_min=density*z;
81-
w=Math.max(v_min+1.f, Math.max(x, y));
81+
w=Math.max(v_min + 1.f, Math.max(x, y));
8282
v_max=density*w;
8383
gestureListener.setMinMax(v_min, v_max);
8484

@@ -172,15 +172,18 @@ private boolean setupShareAction(Menu menu) {
172172
MenuItem shareItem=menu.findItem(R.id.menu_item_share);
173173
ShareActionProvider sap=(ShareActionProvider)shareItem.getActionProvider();
174174
if(sap!=null) {
175-
Intent shareIntent=new Intent(Intent.ACTION_SEND);
175+
shareIntent = new Intent(Intent.ACTION_SEND);
176176
shareIntent.setType(ClipDescription.MIMETYPE_TEXT_PLAIN);
177-
shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.java_message));
178-
179177
sap.setShareIntent(shareIntent);
178+
meigen=getResources().getStringArray(R.array.meigen);
179+
refreshMeigen();
180180
}
181-
182181
return true;
183182
}
183+
private void refreshMeigen() {
184+
shareIntent.removeExtra(Intent.EXTRA_TEXT);
185+
shareIntent.putExtra(Intent.EXTRA_TEXT, meigen[random.nextInt(meigen.length)]);
186+
}
184187

185188
@Override
186189
public boolean onMenuItemSelected(int featureId, MenuItem item) {
@@ -199,6 +202,7 @@ public boolean onMenuItemSelected(int featureId, MenuItem item) {
199202
public void JavaButtonClick(View v) {
200203
playJava(1.f);
201204
counterPress++;
205+
refreshMeigen();
202206
}
203207

204208
@Override

app/src/main/res/values/java.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string-array name="meigen">
4+
<item>あなたとJava</item>
5+
<item>あなたとJAVA,\n今すぐダウンロー\nド</item>
6+
<item>無料Javaのダウンロード</item>
7+
<item>今すぐダウンロード</item>
8+
<item>30億のデバイスで動くJava</item>
9+
<item>Javaのバージョンの確認</item>
10+
<item>Javaの有無のチェック</item>
11+
<item>Javaを使用すると、驚くべきJavaコンテンツの世界に安全かつセキュアにアクセスできます。</item>
12+
<item>ジャバ</item>
13+
<item>無料Javaのダ</item>
14+
</string-array>
15+
</resources>

0 commit comments

Comments
 (0)