Created
March 6, 2022 08:53
-
-
Save lawgimenez/f88f7dfa16abb5858780e0f8023e70c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.iRender.s5.studies.expresioncheck; | |
| import java.io.File; | |
| import java.io.FileDescriptor; | |
| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import java.io.InputStream; | |
| import java.io.OutputStream; | |
| import java.util.ArrayList; | |
| import android.app.Activity; | |
| import android.content.BroadcastReceiver; | |
| import android.content.Context; | |
| import android.content.Intent; | |
| import android.content.IntentFilter; | |
| import android.content.pm.PackageInfo; | |
| import android.content.res.Configuration; | |
| import android.graphics.Color; | |
| import android.media.MediaPlayer; | |
| import android.os.Bundle; | |
| import android.os.Environment; | |
| import android.text.Html; | |
| import android.util.Log; | |
| import android.util.TypedValue; | |
| import android.view.Gravity; | |
| import android.view.LayoutInflater; | |
| import android.view.MotionEvent; | |
| import android.view.View; | |
| import android.view.View.OnClickListener; | |
| import android.view.View.OnTouchListener; | |
| import android.widget.Button; | |
| import android.widget.CheckBox; | |
| import android.widget.CompoundButton; | |
| import android.widget.CompoundButton.OnCheckedChangeListener; | |
| import android.widget.ImageButton; | |
| import android.widget.ImageView; | |
| import android.widget.LinearLayout; | |
| import android.widget.RelativeLayout; | |
| import android.widget.ScrollView; | |
| import android.widget.TableLayout; | |
| import android.widget.TableRow; | |
| import android.widget.TableRow.LayoutParams; | |
| import android.widget.TextView; | |
| import com.iRender.s5.commons.CommonValues; | |
| import com.iRender.s5.commons.Constants; | |
| import com.iRender.s5.commons.Dialog; | |
| import com.iRender.s5.db.dao.HistoryDaoManager; | |
| import com.iRender.s5.db.dao.impl.GrammarExpressionCheckDB; | |
| import com.iRender.s5.holders.Content; | |
| import com.iRender.s5.holders.Sentence; | |
| import com.iRender.s5.otherfeatures.BugActivity; | |
| import com.iRender.s5.otherfeatures.LanguageActivity; | |
| import com.iRender.s5.s5.R; | |
| import com.iRender.s5.s5.S5Application; | |
| import com.iRender.s5.studies.expresioncheck.views.AnswerItem; | |
| import com.iRender.s5.studies.expresioncheck.views.DraggableItem; | |
| import com.javamex.arcmexer.ArchiveEntry; | |
| import com.javamex.arcmexer.ArchiveReader; | |
| public class ExpressionCheck extends Activity implements | |
| OnCheckedChangeListener, OnTouchListener { | |
| private LinearLayout fllHeaderLayout; | |
| private ImageButton fbtnBug; | |
| private ImageButton fbtnQNA; | |
| private ImageButton fbtnClose; | |
| private ImageButton fbtnBack; | |
| private ImageButton fbtnHome; | |
| private TextView ftvStudyName; | |
| private TextView ftvView; | |
| private TextView ftvTrans; | |
| // views | |
| private Button fbtnTrainingLeft; | |
| private CheckBox fcbKoreanLeft; | |
| private Button fbtnTrainingRight; | |
| private CheckBox fcbKoreanRight; | |
| private TableLayout ftlOptions; | |
| private TableLayout ftlAnswers; | |
| private ScrollView fsvParent; | |
| private DraggableItem fdiSelected; | |
| //test | |
| private DraggableItem ftvAnswered; | |
| private TextView ftvPreviousHighlighted; | |
| private ArrayList<TextView> falOptions; | |
| private ArrayList<ImageButton> falPlayButtons; | |
| private ArrayList<TextView> falTranslations; | |
| private ArrayList<AnswerItem> falAnswers; | |
| private ArrayList<DraggableItem> falSelectedOptions; | |
| private ArrayList<AnswerItem> falAnsweredItem; | |
| private ArrayList<String> falStrAnswers; | |
| private ImageView fivDraggedImage; | |
| //test | |
| private ImageView fivDraggedAnswerImg; | |
| private int fiContentId = 0; | |
| private ArrayList<Sentence> falExpressions; | |
| private int fiStartTouch = 0, fiCurrentTouch = 0; | |
| private int fiCounter; | |
| private int fiActionMove = 0, fiActionDown = 0; | |
| private int fiTextSize = 14, fiPadding = 4; | |
| private MediaPlayer fmpMediaPlayer = null; | |
| private FileDescriptor ffdAudioFile = null; | |
| private int fiStart = 0; | |
| private int fiEnd = 0; | |
| private boolean fbKillAI = false; | |
| private boolean fbAudioDone = false; | |
| private String fsTextCleared = ""; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.expressioncheck_layout); | |
| fsvParent = (ScrollView) findViewById(R.id.expressionCheck_svContentParent); | |
| fbtnTrainingLeft = (Button) findViewById(R.id.expressionCheck_btnNextLeft); | |
| fbtnTrainingLeft.setOnClickListener(foclButtonClick); | |
| fcbKoreanLeft = (CheckBox) findViewById(R.id.expressionCheck_cbKoreanLeft); | |
| fbtnTrainingRight = (Button) findViewById(R.id.expressionCheck_btnNextRight); | |
| fbtnTrainingRight.setOnClickListener(foclButtonClick); | |
| fcbKoreanRight = (CheckBox) findViewById(R.id.expressionCheck_cbKoreanRight); | |
| ftlOptions = (TableLayout) findViewById(R.id.expressionCheck_tlOptions); | |
| ftlAnswers = (TableLayout) findViewById(R.id.expressionCheck_tlAnswers); | |
| fivDraggedImage = (ImageView) findViewById(R.id.expressionCheck_ivDragImage); | |
| fivDraggedAnswerImg = (ImageView) findViewById(R.id.expressionCheck_ivDragImage); | |
| ftvView = (TextView) findViewById(R.id.textView2); | |
| ftvTrans = (TextView) findViewById(R.id.expressionCheck_txtTrans); | |
| LayoutInflater liLayouter = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
| fllHeaderLayout = (LinearLayout) findViewById(R.id.expressionCheck_llTop); | |
| LinearLayout ll = (LinearLayout) liLayouter.inflate(R.layout.headerlayout, null); | |
| fllHeaderLayout.addView(ll); | |
| TextView tvVersion = (TextView) fllHeaderLayout.findViewById(R.id.head_tvVersion); | |
| try{ | |
| PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); | |
| String versionName = pinfo.versionName; | |
| tvVersion.setText("v " + versionName); | |
| }catch(Exception e){ | |
| // | |
| } | |
| fbtnBug = (ImageButton) fllHeaderLayout.findViewById(R.id.head_btnBug); | |
| fbtnBug.setOnClickListener(foclHeadBtnClick); | |
| fbtnQNA = (ImageButton) fllHeaderLayout.findViewById(R.id.head_btnQNA); | |
| fbtnQNA.setOnClickListener(foclHeadBtnClick); | |
| fbtnClose = (ImageButton) fllHeaderLayout.findViewById(R.id.head_btnClose); | |
| fbtnClose.setOnClickListener(foclHeadBtnClick); | |
| fbtnHome = (ImageButton) fllHeaderLayout.findViewById(R.id.head_btnHome); | |
| fbtnHome.setOnClickListener(foclHeadBtnClick); | |
| fbtnBack = (ImageButton) fllHeaderLayout.findViewById(R.id.head_btnBack); | |
| fbtnBack.setOnClickListener(foclHeadBtnClick); | |
| ftvStudyName = (TextView) fllHeaderLayout.findViewById(R.id.head_tvStudy); | |
| LinearLayout llWelcomeLayout = (LinearLayout) fllHeaderLayout.findViewById(R.id.head_WelcomeLayout); | |
| llWelcomeLayout.setVisibility(View.GONE); | |
| ftvStudyName.setText(Html.fromHtml(String.format(Constants.STUDYNAME2, CommonValues.fsSetName, CommonValues.fiDayStudied, "Expression Check"))); | |
| fsvParent.setOnTouchListener(this); | |
| fcbKoreanLeft.setOnCheckedChangeListener(this); | |
| fcbKoreanRight.setOnCheckedChangeListener(this); | |
| Content c = getIntent().getParcelableExtra("CONTENT"); | |
| fiContentId = c.getID(); | |
| falExpressions = c.getExpressions(); | |
| Log.e("SIZE", "" + falExpressions.size()); | |
| if (falExpressions.size() > 0) { | |
| fillOptionsTable(ftlOptions); | |
| fillAnswersTable(ftlAnswers); | |
| } | |
| if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) { | |
| this.fiTextSize = 21; | |
| this.fiPadding = 6; | |
| } else{ | |
| this.fiTextSize = 14; | |
| this.fiPadding = 4; | |
| } | |
| View viewTemp = ftlOptions.getChildAt(0); | |
| TableRow tableRowTemp = (TableRow) viewTemp; | |
| Log.i("OnCreate" , "Child Count: " + tableRowTemp.getChildAt(0)); | |
| } | |
| protected void onActivityResult(int requestCode, int resultCode, Intent data){ | |
| if(resultCode == Constants.HEXITTAG || resultCode == Constants.HRESTARTTAG){ | |
| setResult(resultCode); | |
| finish(); | |
| } | |
| } | |
| private BroadcastReceiver fbrReceiver = new BroadcastReceiver() { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| // | |
| } | |
| }; | |
| private BroadcastReceiver fbrExitReceiver = new BroadcastReceiver() { | |
| @Override | |
| public void onReceive(Context context, Intent intent) { | |
| (ExpressionCheck.this).setResult(Constants.HRESTARTTAG); | |
| finish(); | |
| } | |
| }; | |
| protected void onResume() { | |
| IntentFilter filter = new IntentFilter(); | |
| filter.addAction("CLOSE_DB"); | |
| registerReceiver(fbrReceiver, filter); | |
| IntentFilter filterExit = new IntentFilter(); | |
| filterExit.addAction("CLOSE_APP"); | |
| registerReceiver(fbrExitReceiver, filterExit); | |
| setLocale(); | |
| super.onResume(); | |
| } | |
| protected void onPause() { | |
| unregisterReceiver(fbrReceiver); | |
| unregisterReceiver(fbrExitReceiver); | |
| super.onPause(); | |
| } | |
| private OnClickListener foclHeadBtnClick = new OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| ImageButton caller = (ImageButton) v; | |
| if (caller == fbtnBug) { | |
| Intent intent = new Intent(ExpressionCheck.this, BugActivity.class); | |
| intent.putExtra("TYPE", "B"); | |
| startActivity(intent); | |
| } else if (caller == fbtnQNA) { | |
| Intent intent = new Intent(ExpressionCheck.this, LanguageActivity.class); | |
| startActivityForResult(intent, 101010); | |
| /* | |
| Intent intent = new Intent(ExpressionCheck.this, BugActivity.class); | |
| intent.putExtra("TYPE", "Q"); | |
| startActivity(intent); | |
| */ | |
| }else if (caller == fbtnClose) { | |
| setResult(Constants.HEXITTAG); | |
| finish(); | |
| } else if (caller == fbtnHome) { | |
| setResult(Constants.HHOMETAG); | |
| finish(); | |
| } else if (caller == fbtnBack) { | |
| setResult(Constants.HBACKTAG); | |
| finish(); | |
| } | |
| } | |
| }; | |
| private void fillOptionsTable(TableLayout atlLayout) { | |
| falOptions = new ArrayList<TextView>(falExpressions.size()); | |
| falSelectedOptions = new ArrayList<DraggableItem>(); | |
| TableRow trRow = null; | |
| fiCounter = 0; | |
| int iLimit = falExpressions.size() % 2 == 0 ? falExpressions.size() / 2 | |
| : (falExpressions.size() / 2) + 1; | |
| for (int i = 0; i < iLimit; i++) { | |
| trRow = new TableRow(this); | |
| if(i % 2 == 0){ | |
| trRow.setBackgroundColor(Color.WHITE); | |
| } | |
| else{ | |
| trRow.setBackgroundColor(Color.rgb(0xfa, 0xf4, 0xe0)); | |
| } | |
| trRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, | |
| LayoutParams.FILL_PARENT)); | |
| trRow.setWeightSum(1); | |
| for (int a = 1; a <= 2; a++) { | |
| if (fiCounter < falExpressions.size()) { | |
| final String strData = falExpressions.get(fiCounter).getEnglish(); | |
| DraggableItem diOption = new DraggableItem(this, strData); | |
| diOption.setPadding(fiPadding, fiPadding, fiPadding, fiPadding); | |
| diOption.setTextSize(fiTextSize); | |
| diOption.setGravity(Gravity.CENTER); | |
| diOption.setLayoutParams(new LayoutParams( | |
| LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); | |
| diOption.setTextColor(Color.BLACK); | |
| diOption.setDrawingCacheEnabled(true); | |
| trRow.addView(diOption); | |
| falOptions.add(diOption); | |
| } else { | |
| TextView tvBlankOption = new TextView(this); | |
| tvBlankOption.setText(""); | |
| tvBlankOption.setPadding(fiPadding, fiPadding, fiPadding, fiPadding); | |
| tvBlankOption.setTextSize(fiTextSize); | |
| tvBlankOption.setGravity(Gravity.CENTER); | |
| tvBlankOption.setLayoutParams(new LayoutParams( | |
| LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); | |
| trRow.addView(tvBlankOption); | |
| } | |
| fiCounter++; | |
| } | |
| atlLayout.addView(trRow); | |
| } | |
| atlLayout.setStretchAllColumns(true); | |
| } | |
| private void fillAnswersTable(TableLayout atlLayout) { | |
| TableRow trRow = null; | |
| fiCounter = 0; | |
| falAnsweredItem = new ArrayList<AnswerItem>(); | |
| falAnswers = new ArrayList<AnswerItem>(falExpressions.size()); | |
| falStrAnswers = new ArrayList<String>(falExpressions.size()); | |
| falPlayButtons = new ArrayList<ImageButton>(falExpressions.size()); | |
| falTranslations = new ArrayList<TextView>(falExpressions.size()); | |
| for (int i = 0; i < falExpressions.size(); i++) { | |
| fiCounter = i; | |
| trRow = new TableRow(this); | |
| if(i % 2 == 0){ | |
| trRow.setBackgroundColor(Color.WHITE); | |
| } | |
| else{ | |
| trRow.setBackgroundColor(Color.rgb(0xfa, 0xf4, 0xe0)); | |
| } | |
| trRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, | |
| LayoutParams.FILL_PARENT)); | |
| trRow.setWeightSum(1); | |
| ImageButton imgbtnPlayAudio = new ImageButton(this); | |
| // imgbtnPlayAudio.setImageDrawable(getResources().getDrawable( | |
| // R.drawable.btn_playaudio)); | |
| // imgbtnPlayAudio.setBackgroundDrawable(getResources().getDrawable( | |
| // R.drawable.draggable_style)); | |
| imgbtnPlayAudio.setBackgroundResource(R.drawable.btn_audio_style); | |
| imgbtnPlayAudio.setLayoutParams(new LayoutParams( | |
| LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); | |
| String audio = "" + falExpressions.get(fiCounter).getAudioMarking(); | |
| imgbtnPlayAudio.setTag(audio); | |
| imgbtnPlayAudio.setOnClickListener(fAudioClick); | |
| trRow.addView(imgbtnPlayAudio); | |
| falPlayButtons.add(imgbtnPlayAudio); | |
| final String strData = falExpressions.get(i).getTranslation(); | |
| AnswerItem aiAnswer = new AnswerItem(this, "" + (i + 1)); | |
| aiAnswer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, | |
| LayoutParams.FILL_PARENT)); | |
| aiAnswer.setGravity(Gravity.CENTER); | |
| aiAnswer.setWidth(200); | |
| aiAnswer.setTextSize(fiTextSize); | |
| aiAnswer.setTag("" + (i + 1)); | |
| aiAnswer.setOnTouchListener(this); | |
| trRow.addView(aiAnswer); | |
| falAnswers.add(aiAnswer); | |
| falStrAnswers.add(aiAnswer.getText().toString()); | |
| TextView tvTranslation = new TextView(this); | |
| tvTranslation.setText(strData); | |
| tvTranslation.setLayoutParams(new LayoutParams( | |
| LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); | |
| // tvTranslation.setBackgroundDrawable(getResources().getDrawable( | |
| // R.drawable.tablecell_light_style)); | |
| tvTranslation.setBackgroundResource(R.drawable.btn_texts); | |
| tvTranslation.setGravity(Gravity.CENTER); | |
| tvTranslation.setWidth(200); | |
| tvTranslation.setTextSize(fiTextSize); | |
| // tvTranslation.setVisibility(View.GONE); | |
| trRow.addView(tvTranslation); | |
| falTranslations.add(tvTranslation); | |
| atlLayout.addView(trRow); | |
| } | |
| atlLayout.setColumnStretchable(1, true); | |
| showTranslations(fcbKoreanLeft.isChecked()); | |
| } | |
| private OnClickListener fAudioClick = new OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| try{ | |
| String sAudio = v.getTag().toString(); | |
| fiStart = Integer.parseInt(sAudio.split("\\-")[0]); | |
| fiEnd = Integer.parseInt(sAudio.split("\\-")[1]); | |
| if(fmpMediaPlayer != null){ | |
| try{ | |
| fbKillAI = true; | |
| try { | |
| //if(fmpMediaPlayer.isPlaying() == false) { | |
| fmpMediaPlayer.stop(); | |
| //} | |
| fmpMediaPlayer.release(); | |
| } catch(IllegalStateException e) { | |
| } | |
| }catch(Exception e){ | |
| // | |
| } | |
| } | |
| if(ffdAudioFile == null){ | |
| prepareAudio(); | |
| } | |
| fmpMediaPlayer = new MediaPlayer(); | |
| fmpMediaPlayer.setDataSource(ffdAudioFile); | |
| fmpMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { | |
| @Override | |
| public void onPrepared(MediaPlayer mp) { | |
| fmpMediaPlayer.seekTo(fiStart); | |
| fmpMediaPlayer.start(); | |
| fbAudioDone = false; | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| fbKillAI = false; | |
| new Thread(new AIPositionTracker()).start(); | |
| } | |
| }).start(); | |
| } | |
| }); | |
| fmpMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { | |
| @Override | |
| public void onCompletion(MediaPlayer mp) { | |
| fbAudioDone = true; | |
| } | |
| }); | |
| fmpMediaPlayer.prepare(); | |
| } | |
| catch(Exception e){ | |
| //String m = e.getMessage(); | |
| } | |
| } | |
| }; | |
| private void showTranslations(Boolean aboolExp) { | |
| if (falTranslations != null && falTranslations.size() > 0) { | |
| if (aboolExp) { | |
| for (int i = 0; i < falTranslations.size(); i++) { | |
| falTranslations.get(i).setVisibility(View.VISIBLE); | |
| } | |
| } else { | |
| for (int i = 0; i < falTranslations.size(); i++) { | |
| falTranslations.get(i).setVisibility(View.GONE); | |
| } | |
| } | |
| } | |
| } | |
| private OnClickListener foclButtonClick = new OnClickListener() { | |
| @Override | |
| public void onClick(View v) { | |
| Button caller = (Button) v; | |
| if((caller == fbtnTrainingLeft) || (caller == fbtnTrainingRight)){ | |
| if(CommonValues.fbSaveAnswer){ | |
| Dialog.ShowProgressSpinner(ExpressionCheck.this, "Saving data..."); | |
| Thread th = new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| String sData = ""; | |
| for(int i = 0; i < falExpressions.size(); i++){ | |
| sData += Integer.toString(falExpressions.get(i).getID()) + "||" + | |
| falStrAnswers.get(i) +"|~|"; | |
| } | |
| sData = sData.substring(0, sData.length() - 3); | |
| //DaoManager dmManager = ((S5Application) ExpressionCheck.this.getApplicationContext()).getDaoManager(); | |
| HistoryDaoManager dmManager = ((S5Application) ExpressionCheck.this.getApplicationContext()).getHistoryDaoManager(); | |
| GrammarExpressionCheckDB.updateuserexpressions(dmManager, CommonValues.fiUserId, CommonValues.fiSetId, fiContentId, | |
| 4, CommonValues.fiDayStudied, 1, 1, 1, sData); | |
| runOnUiThread(new Runnable() { | |
| @Override | |
| public void run() { | |
| finish(); | |
| } | |
| }); | |
| // HTTPLib_Static httplib = new HTTPLib_Static(); | |
| // List<BasicNameValuePair> bnvp = new ArrayList<BasicNameValuePair>(); | |
| // bnvp.add(new BasicNameValuePair("UID", Integer.toString(CommonValues.fiUserId))); | |
| // bnvp.add(new BasicNameValuePair("SID", Integer.toString(CommonValues.fiSetId))); | |
| // bnvp.add(new BasicNameValuePair("CID", Integer.toString(fiContentId))); | |
| // bnvp.add(new BasicNameValuePair("TYP", "4")); | |
| // bnvp.add(new BasicNameValuePair("Day", Integer.toString(CommonValues.fiDayStudied))); | |
| // bnvp.add(new BasicNameValuePair("DoneCnt", "1")); | |
| // bnvp.add(new BasicNameValuePair("QCnt", "1")); | |
| // bnvp.add(new BasicNameValuePair("Point", "1")); | |
| // | |
| // String sData = ""; | |
| // for(int i = 0; i < falExpressions.size(); i++){ | |
| // sData += Integer.toString(falExpressions.get(i).getID()) + "||" + | |
| // falStrAnswers.get(i) +"|~|"; | |
| // } | |
| // sData = sData.substring(0, sData.length() - 3); | |
| // bnvp.add(new BasicNameValuePair("Data", sData)); | |
| // | |
| // InputStream is = httplib.HTTPRequest(Constants.PHPLINK + "updateuserexpressions.php", bnvp); | |
| // try{ | |
| // String sReturn = httplib.convertStreamToString(is).trim(); | |
| // if(sReturn.equals("1")){ | |
| // PointUpdater.updatePoints("EXP", 1); | |
| // runOnUiThread(new Runnable() { | |
| // @Override | |
| // public void run() { | |
| // finish(); | |
| // } | |
| // }); | |
| // } | |
| // else{ | |
| // runOnUiThread(new Runnable() { | |
| // @Override | |
| // public void run() { | |
| // Dialog.AlertMe(ExpressionCheck.this, Constants.MSGERROR, Constants.MSGDATANOTSAVED, null); | |
| // } | |
| // }); | |
| // } | |
| // } | |
| // catch(Exception e){ | |
| // final Exception ex = e; | |
| // runOnUiThread(new Runnable() { | |
| // @Override | |
| // public void run() { | |
| // Dialog.AlertMe(ExpressionCheck.this, Constants.MSGERROR, ex.getMessage(), null); | |
| // } | |
| // }); | |
| // } | |
| Dialog.DismissProgressSpinner(); | |
| } | |
| }); | |
| th.start(); | |
| } | |
| else{ | |
| finish(); | |
| } | |
| } | |
| } | |
| }; | |
| @Override | |
| public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | |
| if (buttonView == this.fcbKoreanLeft | |
| || buttonView == this.fcbKoreanRight) { | |
| showTranslations(isChecked); | |
| this.fcbKoreanLeft.setChecked(isChecked); | |
| this.fcbKoreanRight.setChecked(isChecked); | |
| } | |
| } | |
| @Override | |
| public boolean onTouch(View v, MotionEvent event) { | |
| RelativeLayout.LayoutParams layout = (RelativeLayout.LayoutParams) fivDraggedImage.getLayoutParams(); | |
| RelativeLayout.LayoutParams layoutAns = (RelativeLayout.LayoutParams) fivDraggedAnswerImg.getLayoutParams(); | |
| switch (event.getAction()) { | |
| case MotionEvent.ACTION_DOWN: | |
| fiActionDown = (int) event.getRawY(); | |
| fiStartTouch = (int) event.getRawY(); | |
| if (fsvParent.getScrollY() > 0) { | |
| fiActionDown += (fsvParent.getScrollY()); | |
| } | |
| fdiSelected = (DraggableItem) isInsideOptions((int) event.getRawX(), fiActionDown); | |
| if (fdiSelected != null) { | |
| // fdiSelected.setVisibility(View.INVISIBLE); | |
| fivDraggedImage.setImageBitmap(fdiSelected.getDrawingCache()); | |
| // fdiSelected.setBackgroundDrawable(getResources().getDrawable( | |
| // R.drawable.tablecell_light_style)); | |
| //fdiSelected.setBackgroundDrawable(null); | |
| fdiSelected.setVisibility(View.INVISIBLE); | |
| //fdiSelected.setTextColor(Color.TRANSPARENT); | |
| //if(!fbSelected) { | |
| layout.leftMargin = getRelativeLeft(fsvParent) | |
| + (int) event.getX() - fdiSelected.getWidth() / 2; //use fdiSelected instead of fivDraggedImage | |
| layout.topMargin = getRelativeTop(fsvParent) //ky dili pa makuha ang width and height sa fivDraggedImage | |
| + (int) event.getY() - fdiSelected.getHeight() / 2;//ky wala pa ma draw.. :) | |
| fivDraggedImage.setLayoutParams(layout); | |
| fivDraggedImage.setLayoutParams(layout); | |
| // fbSelected = true; | |
| //} | |
| fivDraggedImage.setVisibility(ImageView.VISIBLE); | |
| fivDraggedImage.bringToFront(); | |
| } else { | |
| View vClicked = isInsideAnswer((int) event.getRawX(), fiStartTouch); | |
| if (vClicked != null && vClicked instanceof AnswerItem) { | |
| AnswerItem aiClicked = ((AnswerItem) vClicked); | |
| Log.i("Expression Check", "Answered Item to clear: " + aiClicked.getText()); | |
| fsTextCleared = String.valueOf(aiClicked.getText()); | |
| removeAnsweredItem(aiClicked);//remove item in answers table | |
| try { | |
| addOptions(fsTextCleared);//add item to option table | |
| } catch(ClassCastException e) { | |
| if(e != null) { | |
| Log.e("CLASS CAST", "addOptions: " + e.getMessage()); | |
| } | |
| } | |
| /* | |
| aiClicked.incrementClick(); | |
| if (aiClicked.getFiClick() == 2) { | |
| aiClicked.resetClick(); | |
| removeAnsweredItem(aiClicked); | |
| } | |
| */ | |
| } | |
| } | |
| break; | |
| case MotionEvent.ACTION_MOVE: | |
| fiCurrentTouch = (int) event.getRawY(); | |
| fiActionMove = (int) event.getRawY(); | |
| if (fsvParent.getScrollY() > 0) { | |
| fiActionMove += fsvParent.getScrollY(); | |
| } | |
| if (fdiSelected != null) { | |
| if (fsvParent.getHeight() - fiCurrentTouch <= -65) { | |
| fsvParent.scrollBy(0, 20); | |
| } else if (fiCurrentTouch - fsvParent.getScrollY() < 10) { | |
| fsvParent.scrollBy(0, -20); | |
| } | |
| layout.leftMargin = getRelativeLeft(fsvParent) | |
| + (int) event.getX() - fivDraggedImage.getWidth() / 2; | |
| layout.topMargin = getRelativeTop(fsvParent) | |
| + (int) event.getY() - fdiSelected.getHeight() / 2; | |
| fivDraggedImage.setLayoutParams(layout); | |
| TextView tv = (TextView) isInside(fdiSelected, (int) event.getRawX(), fiActionMove); | |
| if (ftvPreviousHighlighted != null) { | |
| if (!falAnsweredItem.contains(ftvPreviousHighlighted)) { | |
| // ftvPreviousHighlighted.setBackgroundDrawable(getResources() | |
| // .getDrawable(R.drawable.tablecell_light_style)); | |
| ftvPreviousHighlighted.setBackgroundDrawable(null); | |
| } | |
| } | |
| if (tv != null) { | |
| ftvPreviousHighlighted = tv; | |
| // tv.setBackgroundDrawable(getResources().getDrawable( | |
| // R.drawable.tablecell_light_style_selected)); | |
| tv.setBackgroundResource(R.drawable.list_bg); | |
| } | |
| } else { | |
| if (fiCurrentTouch > fiStartTouch) { | |
| fsvParent.scrollBy(0, fiStartTouch - fiCurrentTouch); | |
| } else if (fiCurrentTouch < fiStartTouch) { | |
| fsvParent.scrollBy(0, fiStartTouch - fiCurrentTouch); | |
| } | |
| } | |
| //if inside answer | |
| if(ftvAnswered != null) { | |
| //fivDraggedAnswerImg | |
| layoutAns.leftMargin = getRelativeLeft(fsvParent) + (int) event.getX() - fivDraggedAnswerImg.getWidth() / 2; | |
| layoutAns.topMargin = getRelativeTop(fsvParent) + (int) event.getY() - ftvAnswered.getHeight() / 2; | |
| fivDraggedAnswerImg.setLayoutParams(layoutAns); | |
| TextView tv = (TextView) isInsideOptions((int) event.getRawX(), fiActionMove); | |
| if(ftvPreviousHighlighted != null) { | |
| if(!falSelectedOptions.contains(ftvPreviousHighlighted)) { | |
| ftvPreviousHighlighted.setBackgroundResource(R.drawable.list_bg); | |
| } | |
| } | |
| if(tv != null) {//tv is in the options | |
| ftvPreviousHighlighted = tv; | |
| tv.setBackgroundDrawable(null); | |
| } | |
| } | |
| break; | |
| case MotionEvent.ACTION_UP: | |
| if (fdiSelected != null) { | |
| fivDraggedImage.setVisibility(View.GONE); | |
| TextView tv = (TextView) isInside(fdiSelected, | |
| (int) event.getRawX(), fiActionMove); | |
| if (tv != null) { | |
| AnswerItem answer = ((AnswerItem) tv); | |
| falSelectedOptions.add(fdiSelected); | |
| answer.setText(fdiSelected.getText()); | |
| answer.setTextColor(Color.BLACK); | |
| // answer.setBackgroundDrawable(getResources().getDrawable( | |
| // R.drawable.draggable_style)); | |
| answer.setBackgroundResource(R.drawable.btn_texts); | |
| int index = getAnswerIndex(answer); | |
| if (index != -1) { | |
| falStrAnswers.set(index, answer.getText().toString()); | |
| } | |
| falAnsweredItem.add(answer); | |
| } else { | |
| // fdiSelected.setVisibility(View.VISIBLE); | |
| // fdiSelected.setBackgroundDrawable(getResources() | |
| // .getDrawable(R.drawable.draggable_style)); | |
| // fdiSelected.setTextColor(Color.WHITE); | |
| //fdiSelected.setBackgroundResource(R.drawable.btn_texts); | |
| //fdiSelected.setTextColor(Color.BLACK); | |
| fdiSelected.setVisibility(View.VISIBLE); | |
| } | |
| fdiSelected = null; | |
| } | |
| break; | |
| default: | |
| super.onTouchEvent(event); | |
| } | |
| return true; | |
| } | |
| public int getAnswerIndex(View v) { | |
| for (int i = 0; i < falAnswers.size(); i++) { | |
| if (falAnswers.get(i).equals(v)) { | |
| return i; | |
| } | |
| } | |
| return -1; | |
| } | |
| public View isInside(View v, int x, int y) { | |
| for (int i = 0; i < falAnswers.size(); i++) { | |
| AnswerItem aiAnswer = falAnswers.get(i); | |
| int coords[] = getCoord(aiAnswer); | |
| if ((x > coords[0] && x < coords[0] + aiAnswer.getWidth()) | |
| && (y > coords[1] && y < coords[1] + aiAnswer.getHeight())) { | |
| if (falAnsweredItem.contains(aiAnswer)) { | |
| return null; | |
| } else { | |
| return aiAnswer; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| public View isInsideAnswer(int x, int y) { | |
| for (AnswerItem aiItem : falAnsweredItem) { | |
| int coords[] = getCoord(aiItem); | |
| if ((x > coords[0] && x < coords[0] + aiItem.getWidth()) | |
| && (y > coords[1] && y < coords[1] + aiItem.getHeight())) { | |
| return aiItem; | |
| } | |
| } | |
| return null; | |
| } | |
| public View isInsideOptions(int x, int y) { | |
| for (TextView tv : falOptions) { | |
| int coords[] = getCoord(tv); | |
| if ((x > coords[0] && x < coords[0] + tv.getWidth()) | |
| && (y > coords[1] && y < coords[1] + tv.getHeight())) { | |
| if (falSelectedOptions.contains(tv)) { | |
| return null; | |
| } else { | |
| return tv; | |
| } | |
| } | |
| } | |
| return null; | |
| } | |
| public int[] getCoord(View v) { | |
| int[] coord = { 0, 0 }; | |
| coord[0] = getRelativeLeft(v); | |
| coord[1] = getRelativeTop(v); | |
| return coord; | |
| } | |
| private int getRelativeLeft(View myView) { | |
| if (myView.getParent() == myView.getRootView()) | |
| return myView.getLeft(); | |
| else | |
| return myView.getLeft() | |
| + getRelativeLeft((View) myView.getParent()); | |
| } | |
| private int getRelativeTop(View myView) { | |
| if (myView.getParent() == myView.getRootView()) | |
| return myView.getTop(); | |
| else | |
| return myView.getTop() + getRelativeTop((View) myView.getParent()); | |
| } | |
| public boolean removeAnsweredItem(View v) { | |
| if (falAnsweredItem.contains(v)) { | |
| v.setBackgroundDrawable(getResources().getDrawable( | |
| R.drawable.tablecell_light_style)); | |
| int index = getAnswerIndex(v); | |
| if (index != -1) { | |
| falStrAnswers.set(index, ""); | |
| } | |
| falAnsweredItem.remove(v); | |
| for (DraggableItem di : falSelectedOptions) { | |
| if (di.getText().equals(((TextView) v).getText())) { | |
| // di.setVisibility(View.VISIBLE); | |
| di.setBackgroundDrawable(getResources().getDrawable( | |
| R.drawable.draggable_style)); | |
| di.setTextColor(Color.WHITE); | |
| falSelectedOptions.remove(di); | |
| break; | |
| } | |
| } | |
| ((TextView) v).setTextColor(Color.BLACK); | |
| ((TextView) v).setText((CharSequence) ((TextView) v).getTag()); | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| private void addOptions(String aStrOption) { | |
| TableRow tableRow = null; | |
| DraggableItem item = null; | |
| for(int i=0; i<ftlOptions.getChildCount(); i++) { | |
| tableRow = (TableRow) ftlOptions.getChildAt(i); | |
| for(int j=0; j<tableRow.getChildCount(); j++) { | |
| item = (DraggableItem) tableRow.getChildAt(j); | |
| if(item.getVisibility() == View.INVISIBLE) {//item is in answers table | |
| if(aStrOption.equalsIgnoreCase(item.getText().toString())) {//same texts | |
| item.setVisibility(View.VISIBLE); | |
| float density = getResources().getDisplayMetrics().density; | |
| if(density <= 1.5){ | |
| item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); | |
| } | |
| else{ | |
| item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21); | |
| } | |
| item.setTextColor(Color.BLACK); | |
| item.setBackgroundResource(R.drawable.btn_texts); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| private class AIPositionTracker implements Runnable{ | |
| @Override | |
| public void run() { | |
| int iHolder = 0, iEnd = 0; | |
| while(!fbKillAI){ | |
| iHolder = fmpMediaPlayer.getCurrentPosition(); | |
| iEnd = fiEnd; | |
| if((iHolder >= iEnd) || (fbAudioDone)){ | |
| fbKillAI = true; | |
| try { | |
| //if(fmpMediaPlayer.isPlaying() == false) { | |
| fmpMediaPlayer.stop(); | |
| //} | |
| fmpMediaPlayer.release(); | |
| } catch(IllegalStateException e) { | |
| } | |
| } | |
| } | |
| } | |
| } | |
| private boolean prepareAudio(){ | |
| try{ | |
| String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DME Talking/data/books"; | |
| File f = new File(path+"/"+String.format("%06d.zip", CommonValues.fiSetId)); | |
| String sVideoFile = String.format("exp_%d.mp3", fiContentId); | |
| InputStream ais = getImage(f, sVideoFile); | |
| if(ais != null){ | |
| StreamToTemp(ais); | |
| FileInputStream fis = new FileInputStream(new File(getFilesDir() + "/gccollect911.mp3")); | |
| ffdAudioFile = fis.getFD(); | |
| } | |
| return true; | |
| }catch(Exception e){ | |
| return false; | |
| } | |
| } | |
| private InputStream getImage(File Zipfile, String FileName){ | |
| if(Zipfile.exists()){ | |
| if(Zipfile.canRead()){ | |
| try{ | |
| ArchiveReader r = ArchiveReader.getReader(Zipfile); | |
| try { | |
| ArchiveEntry entry; | |
| String sImageName = FileName; | |
| while ((entry = r.nextEntry()) != null) { | |
| if(entry.getFilename().equals(sImageName)){ | |
| entry.setPassword("irender~!@#$%"); | |
| return entry.getInputStream(); | |
| } | |
| } | |
| return null; | |
| } finally { | |
| r.close(); | |
| } | |
| }catch(Exception e){ | |
| return null; | |
| } | |
| } | |
| else | |
| return null; | |
| } | |
| else | |
| return null; | |
| } | |
| private void StreamToTemp(InputStream is){ | |
| try | |
| { | |
| File temp = new File(getFilesDir(), "gccollect911.mp3"); | |
| if(temp.exists()) | |
| temp.delete(); | |
| temp.createNewFile(); | |
| OutputStream out = new FileOutputStream(temp); | |
| byte buf[] = new byte[1024]; | |
| do{ | |
| int numread = is.read(buf); | |
| if(numread <= 0) break; | |
| out.write(buf,0,numread); | |
| } while(true); | |
| out.close(); | |
| } | |
| catch (IOException e){} | |
| } | |
| private void setLocale() { | |
| fbtnTrainingLeft.setText(getResources().getString(R.string.next)); | |
| fbtnTrainingRight.setText(getResources().getString(R.string.next)); | |
| ftvView.setText(getResources().getString(R.string.exp_view)); | |
| fcbKoreanLeft.setText(getResources().getString(R.string.exp_trans)); | |
| ftvTrans.setText(getResources().getString(R.string.exp_trans)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment