Last active
February 27, 2016 17:49
-
-
Save kivantium/b0e5b8e67771a85af5b1 to your computer and use it in GitHub Desktop.
OTAKU!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<FrameLayout | |
android:id="@+id/live2DLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_alignParentLeft="true" | |
android:layout_alignParentTop="true" | |
android:background="#ffffff"> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" | |
android:weightSum="3"> | |
<View | |
android:layout_width="fill_parent" | |
android:layout_height="0dp" | |
android:layout_weight="2" /> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:layout_gravity="center_horizontal|bottom" | |
android:layout_weight="1" | |
android:background="#60505050" | |
android:paddingLeft="60dp" | |
android:paddingRight="60dp" | |
android:paddingTop="20dp" | |
android:shadowColor="#000" | |
android:shadowDx="2.0" | |
android:shadowDy="2.0" | |
android:shadowRadius="4.0" | |
android:text="New Text" | |
android:textColor="#EEE" | |
android:textSize="35sp" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" | |
android:weightSum="6"> | |
<View | |
android:layout_width="fill_parent" | |
android:layout_height="0dp" | |
android:layout_weight="5" /> | |
<TextView | |
android:id="@+id/TimerView" | |
android:layout_width="match_parent" | |
android:layout_height="0dp" | |
android:textSize="50sp" | |
android:gravity="right|bottom" | |
android:layout_weight="1" | |
android:paddingRight="40dp" | |
android:paddingBottom="20dp" | |
android:shadowColor="#000" | |
android:shadowDx="2.0" | |
android:shadowDy="2.0" | |
android:shadowRadius="4.0" | |
android:text="00:00" | |
android:textColor="#EEE" | |
android:clickable="true" | |
android:onClick="TimeTouched"/> | |
</LinearLayout> | |
</FrameLayout> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* You can modify and use this source freely | |
* only for the development of application related Live2D. | |
* <p> | |
* (c) Live2D Inc. All rights reserved. | |
*/ | |
package jp.live2d.sample; | |
import jp.live2d.utils.android.FileManager; | |
import jp.live2d.utils.android.SoundManager; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.graphics.Color; | |
import android.media.MediaPlayer; | |
import android.os.Bundle; | |
import android.os.CountDownTimer; | |
import android.os.Handler; | |
import android.speech.RecognitionListener; | |
import android.speech.RecognizerIntent; | |
import android.speech.SpeechRecognizer; | |
import android.util.Log; | |
import android.view.MotionEvent; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.view.ViewGroup.LayoutParams; | |
import android.view.Window; | |
import android.widget.FrameLayout; | |
import android.widget.LinearLayout; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import java.util.ArrayList; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
import android.view.Display; | |
import android.graphics.Point; | |
/* | |
* SampleApplicationはActivityを継承し、サンプル・アプリケーションのエントリポイント(メインのActivityクラス)となります。 | |
*/ | |
public class SampleApplication extends Activity { | |
// Live2Dの管理 | |
private LAppLive2DManager live2DMgr; | |
static private Activity instance; | |
private SpeechRecognizer sr; | |
private Timer mTimer = null; | |
private Handler mHandler = null; | |
private Timer mTimer2 = null; | |
private Handler mHandler2 = null; | |
String[] strs = {"人参を入れます", | |
"玉ねぎを入れます"}; | |
int current_menu = 0; | |
int times = 0; | |
int view_width, view_height; | |
int timer_count = 180; | |
boolean counting = false; | |
private MediaPlayer mp; | |
public SampleApplication() { | |
instance = this; | |
if (LAppDefine.DEBUG_LOG) { | |
Log.d("", "==============================================\n"); | |
Log.d("", " Live2D Sample \n"); | |
Log.d("", "==============================================\n"); | |
} | |
SoundManager.init(this); | |
live2DMgr = new LAppLive2DManager(); | |
} | |
static public void exit() { | |
SoundManager.release(); | |
instance.finish(); | |
} | |
/* | |
* Activityが作成されたときのイベント | |
*/ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
requestWindowFeature(Window.FEATURE_NO_TITLE); | |
// GUIを初期化 | |
setupGUI(); | |
FileManager.init(this.getApplicationContext()); | |
//SpeechRecognizer生成 | |
sr = SpeechRecognizer.createSpeechRecognizer(this); | |
sr.setRecognitionListener(new listener()); | |
change_recipe(); | |
// 画面サイズを取得する | |
Display display = getWindowManager().getDefaultDisplay(); | |
Point p = new Point(); | |
display.getSize(p); | |
view_width = p.x; | |
view_height = p.y; | |
TextView timer_text = (TextView) findViewById(R.id.TimerView); | |
timer_text.setText("00:00"); | |
mHandler = new Handler(); | |
mTimer = new Timer(); | |
mTimer.schedule(new TimerTask() { | |
@Override | |
public void run() { | |
mHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
// 実行したい処理 | |
/*times++; | |
Toast.makeText(getApplicationContext(), "コマンドをどうぞ" + String.valueOf(times), Toast.LENGTH_SHORT).show(); | |
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); | |
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); | |
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "voice.recognition.test"); | |
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1); | |
sr.startListening(intent);*/ | |
} | |
}); | |
} | |
}, 0, 6000); // 実行したい間隔(ミリ秒) | |
mHandler2 = new Handler(); | |
mTimer2 = new Timer(); | |
mTimer2.schedule(new TimerTask() { | |
@Override | |
public void run() { | |
mHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
TimerUpdate(); | |
} | |
}); | |
} | |
}, 0, 1000); // 実行したい間隔(ミリ秒) | |
mp = MediaPlayer.create(this, R.raw.voice1); | |
mp.start(); | |
} | |
private void TimerUpdate() { | |
TextView timer_text = (TextView) findViewById(R.id.TimerView); | |
timer_text.setText(String.format("%02d", (timer_count / 60)) + ":" + String.format("%02d", (timer_count % 60))); | |
if (counting && timer_count > 0) { | |
timer_count--; | |
switch (timer_count) { | |
case 0: | |
mp = MediaPlayer.create(this, R.raw.remain0); | |
mp.start(); | |
counting = false; | |
timer_text.setTextColor(Color.rgb(0xE0, 0xE0, 0xE0)); | |
break; | |
case 10: | |
mp = MediaPlayer.create(this, R.raw.remain10s); | |
mp.start(); | |
break; | |
case 30: | |
mp = MediaPlayer.create(this, R.raw.remain30s); | |
mp.start(); | |
break; | |
case 60: | |
mp = MediaPlayer.create(this, R.raw.remain1m); | |
mp.start(); | |
break; | |
case 120: | |
mp = MediaPlayer.create(this, R.raw.remain2m); | |
mp.start(); | |
break; | |
case 180: | |
mp = MediaPlayer.create(this, R.raw.remain3m); | |
mp.start(); | |
break; | |
case 240: | |
mp = MediaPlayer.create(this, R.raw.remain4m); | |
mp.start(); | |
break; | |
case 300: | |
mp = MediaPlayer.create(this, R.raw.remain5m); | |
mp.start(); | |
break; | |
case 600: | |
mp = MediaPlayer.create(this, R.raw.remain10m); | |
mp.start(); | |
break; | |
} | |
} | |
} | |
public void TimeTouched(View view) { | |
counting = !counting; | |
TextView timer_text = (TextView) findViewById(R.id.TimerView); | |
if (counting) { | |
timer_text.setTextColor(Color.rgb(0xFF, 0xA0, 0xA0)); | |
} else { | |
timer_text.setTextColor(Color.rgb(0xE0, 0xE0, 0xE0)); | |
} | |
TimerUpdate(); | |
} | |
private void change_recipe() { | |
TextView message = (TextView) findViewById(R.id.textView); | |
message.setText(strs[current_menu]); | |
} | |
class listener implements RecognitionListener { | |
public void onReadyForSpeech(Bundle params) { | |
} | |
public void onBeginningOfSpeech() { | |
} | |
public void onRmsChanged(float rmsdB) { | |
} | |
public void onBufferReceived(byte[] buffer) { | |
} | |
public void onEndOfSpeech() { | |
} | |
public void onPartialResults(Bundle partialResults) { | |
} | |
public void onEvent(int eventType, Bundle params) { | |
} | |
public void onError(int error) { | |
//Log.d(TAG, "error " + error); | |
//Toast.makeText(getApplicationContext(), String.valueOf(times)+": error", Toast.LENGTH_SHORT).show(); | |
} | |
public void onResults(Bundle results) { | |
/*String str = new String(); | |
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); | |
if (data.size() > 0) str += data.get(0); | |
//Toast.makeText(getApplicationContext(), String.valueOf(times)+": "+str, Toast.LENGTH_SHORT).show(); | |
if (str.indexOf("もう一度") >= 0) { | |
Toast.makeText(getApplicationContext(), "もう一度読み上げます", Toast.LENGTH_SHORT).show(); | |
change_recipe(); | |
} else if (str.indexOf("進んで") >= 0) { | |
Toast.makeText(getApplicationContext(), "進みます", Toast.LENGTH_SHORT).show(); | |
if (current_menu < strs.length - 1) current_menu++; | |
change_recipe(); | |
} else if (str.indexOf("戻って") >= 0) { | |
Toast.makeText(getApplicationContext(), "戻ります", Toast.LENGTH_SHORT).show(); | |
if (current_menu > 0) current_menu--; | |
change_recipe(); | |
}*/ | |
} | |
} | |
/* | |
* GUIの初期化 | |
* activity_main.xmlからViewを作成し、そこにLive2Dを配置する | |
*/ | |
void setupGUI() { | |
setContentView(R.layout.activity_main); | |
// Viewの初期化 | |
LAppView view = live2DMgr.createView(this); | |
// activity_main.xmlにLive2DのViewをレイアウトする | |
FrameLayout layout = (FrameLayout) findViewById(R.id.live2DLayout); | |
layout.addView(view, 0, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); | |
} | |
public boolean onTouchEvent(MotionEvent event) { | |
Log.d("TouchEvent", "X:" + event.getX() + ",Y:" + event.getY()); | |
if (event.getAction() == MotionEvent.ACTION_UP) { | |
if (event.getX() / view_width < 0.2) { | |
if (current_menu > 0) current_menu--; | |
change_recipe(); | |
} else if (event.getX() / view_width > 0.8) { | |
if (current_menu < strs.length - 1) current_menu++; | |
change_recipe(); | |
} else { | |
if (!counting && event.getY() / view_height < 0.2) { | |
timer_count += 60; | |
TimerUpdate(); | |
} | |
if (!counting && event.getY() / view_height > 0.5 & timer_count >= 60) { | |
timer_count -= 60; | |
TimerUpdate(); | |
} | |
} | |
} | |
return true; | |
} | |
/* | |
* Activityを再開したときのイベント。 | |
*/ | |
@Override | |
protected void onResume() { | |
//live2DMgr.onResume() ; | |
super.onResume(); | |
} | |
/* | |
* Activityを停止したときのイベント。 | |
*/ | |
@Override | |
protected void onPause() { | |
live2DMgr.onPause(); | |
super.onPause(); | |
if (mTimer != null) { | |
mTimer.cancel(); | |
mTimer = null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment