Guest User

Untitled

a guest
May 4th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.74 KB | None | 0 0
  1. Android AsyncTask doInBackground operation stopping suddenly with unhandled exception
  2. 01-26 12:13:48.216: I/System.out(4421): success
  3. 01-26 12:13:48.386: I/System.out(4421): success
  4. 01-26 12:13:48.576: I/System.out(4421): success
  5. 01-26 12:13:48.616: D/dalvikvm(4421): GC_CONCURRENT freed 473K, 48% free 3256K/6215K, external 0K/0K, paused 3ms+4ms
  6. 01-26 12:13:48.806: I/System.out(4421): success
  7. 01-26 12:13:48.806: W/dalvikvm(4421): threadid=9: thread exiting with uncaught exception (group=0x40018560)
  8. 01-26 12:13:48.806: E/AndroidRuntime(4421): FATAL EXCEPTION: AsyncTask #1
  9. 01-26 12:13:48.806: E/AndroidRuntime(4421): java.lang.RuntimeException: An error occured while executing doInBackground()
  10. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.os.AsyncTask$3.done(AsyncTask.java:200)
  11. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
  12. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
  13. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
  14. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  15. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
  16. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
  17. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.lang.Thread.run(Thread.java:1019)
  18. 01-26 12:13:48.806: E/AndroidRuntime(4421): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  19. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
  20. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.ArrayList.get(ArrayList.java:311)
  21. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.gesture.Instance.temporalSampler(Instance.java:91)
  22. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.gesture.Instance.createInstance(Instance.java:76)
  23. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.gesture.GestureStore.addGesture(GestureStore.java:158)
  24. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.gesture.GestureLibrary.addGesture(GestureLibrary.java:68)
  25. 01-26 12:13:48.806: E/AndroidRuntime(4421): at com.android.pack.TestActivity.saveGesture(TestActivity.java:467)
  26. 01-26 12:13:48.806: E/AndroidRuntime(4421): at com.android.pack.TestActivity$A.doInBackground(TestActivity.java:102)
  27. 01-26 12:13:48.806: E/AndroidRuntime(4421): at com.android.pack.TestActivity$A.doInBackground(TestActivity.java:1)
  28. 01-26 12:13:48.806: E/AndroidRuntime(4421): at android.os.AsyncTask$2.call(AsyncTask.java:185)
  29. 01-26 12:13:48.806: E/AndroidRuntime(4421): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  30. 01-26 12:13:48.806: E/AndroidRuntime(4421): ... 4 more
  31. 01-26 12:13:49.356: E/WindowManager(4421): Activity com.android.pack.TestActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4053a358 that was originally added here
  32. 01-26 12:13:49.356: E/WindowManager(4421): android.view.WindowLeaked: Activity com.android.pack.TestActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4053a358 that was originally added here
  33. 01-26 12:13:49.356: E/WindowManager(4421): at android.view.ViewRoot.<init>(ViewRoot.java:259)
  34. 01-26 12:13:49.356: E/WindowManager(4421): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
  35. 01-26 12:13:49.356: E/WindowManager(4421): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
  36. 01-26 12:13:49.356: E/WindowManager(4421): at android.view.Window$LocalWindowManager.addView(Window.java:465)
  37. 01-26 12:13:49.356: E/WindowManager(4421): at android.app.Dialog.show(Dialog.java:241)
  38. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.pack.TestActivity.addgestures(TestActivity.java:159)
  39. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.pack.TestActivity.onOptionsItemSelected(TestActivity.java:404)
  40. 01-26 12:13:49.356: E/WindowManager(4421): at android.app.Activity.onMenuItemSelected(Activity.java:2205)
  41. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:776)
  42. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
  43. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
  44. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
  45. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
  46. 01-26 12:13:49.356: E/WindowManager(4421): at android.view.View$PerformClick.run(View.java:9107)
  47. 01-26 12:13:49.356: E/WindowManager(4421): at android.os.Handler.handleCallback(Handler.java:587)
  48. 01-26 12:13:49.356: E/WindowManager(4421): at android.os.Handler.dispatchMessage(Handler.java:92)
  49. 01-26 12:13:49.356: E/WindowManager(4421): at android.os.Looper.loop(Looper.java:130)
  50. 01-26 12:13:49.356: E/WindowManager(4421): at android.app.ActivityThread.main(ActivityThread.java:3835)
  51. 01-26 12:13:49.356: E/WindowManager(4421): at java.lang.reflect.Method.invokeNative(Native Method)
  52. 01-26 12:13:49.356: E/WindowManager(4421): at java.lang.reflect.Method.invoke(Method.java:507)
  53. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
  54. 01-26 12:13:49.356: E/WindowManager(4421): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
  55. 01-26 12:13:49.356: E/WindowManager(4421): at dalvik.system.NativeStart.main(Native Method)
  56. 01-26 12:14:04.836: I/Process(4421): Sending signal. PID: 4421 SIG: 9
  57.  
  58. class A extends AsyncTask<File[],Integer,Void>
  59. {
  60. private Context cnt;
  61. int count=0;
  62. @Override
  63. protected void onPreExecute() {
  64.  
  65. }
  66. A(Context context)
  67. {
  68. cnt=context;
  69. }
  70.  
  71. protected Void doInBackground(File[]... params) {
  72. // TODO Auto-generated method stub
  73. File[] newfiles=params[0];
  74. File[] temp=null;
  75. int progress=0;
  76. float dircnt=0;
  77. int numberofdir=newfiles.length;
  78. for(File b:newfiles)
  79. {
  80.  
  81.  
  82. count=0;
  83. dirname=b.getName();
  84. if(b.isDirectory())
  85. {
  86.  
  87. temp=b.listFiles();
  88. }
  89. for(File a:temp)
  90. {
  91. gest=dotask.batchprocess(a.getPath());
  92. if(gest!=null)
  93. System.out.println("success");
  94. String name=dirname+"_"+count;
  95. saveGesture(name, gest);
  96. count++;
  97.  
  98. }
  99. dircnt=dircnt+1;
  100. progress=(int)((dircnt/numberofdir)*100);
  101. try {
  102. Thread.sleep(60);
  103. publishProgress(progress);
  104. } catch (InterruptedException e) {
  105. // TODO Auto-generated catch block
  106. e.printStackTrace();
  107. }
  108.  
  109.  
  110.  
  111. }
  112.  
  113.  
  114. return null;
  115. }
  116. @Override
  117. protected void onProgressUpdate(Integer... values) {
  118. // increment progress bar by progress value
  119. pd.setProgress(values[0]);
  120. pd.setMessage("completed "+dirname);
  121.  
  122.  
  123. }
  124. protected void onPostExecute() {
  125. pd.hide();
  126. pd=null;
  127. }
  128.  
  129. public void addgestures()
  130. {
  131. cView.postInvalidate();
  132. dotask.setH(cView.getH());
  133. dotask.setW(cView.getW());
  134.  
  135. count=0;
  136. files=null;
  137. /*if(dir.isDirectory())
  138. {
  139. files=dir.listFiles();
  140. }*/
  141. files=dir.listFiles();
  142. for(int i=0;i<files.length;i++)
  143. {
  144. System.out.println(files[i].getPath());
  145. }
  146. pd = new ProgressDialog(this);
  147. pd.setMessage("Matching progress");
  148. pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  149. pd.setMax(100);
  150. pd.setCancelable(false);
  151. pd.setProgress(0);
  152. pd.show();
  153.  
  154.  
  155.  
  156. A a=new A(this);
  157. a.execute(files);
  158.  
  159.  
  160.  
  161. }
  162.  
  163. **here is the TESTACTIVITY CLASS**
  164.  
  165. package com.android.pack;
  166.  
  167.  
  168. import java.io.File;
  169. import java.net.URISyntaxException;
  170.  
  171.  
  172.  
  173. import android.app.Activity;
  174. import android.app.AlertDialog;
  175. import android.app.ProgressDialog;
  176. import android.content.Context;
  177. import android.content.DialogInterface;
  178. import android.content.Intent;
  179. import android.gesture.Gesture;
  180. import android.gesture.GestureLibraries;
  181. import android.gesture.GestureLibrary;
  182. import android.net.Uri;
  183. import android.os.AsyncTask;
  184. import android.os.Bundle;
  185. import android.os.Environment;
  186. import android.os.Handler;
  187. import android.os.Message;
  188. import android.text.Editable;
  189. import android.util.Log;
  190. import android.view.Menu;
  191. import android.view.MenuItem;
  192. import android.widget.EditText;
  193. import android.widget.LinearLayout;
  194. import android.widget.Toast;
  195.  
  196.  
  197. public class TestActivity extends Activity {
  198. /** Called when the activity is first created. */
  199. int height;
  200. int weight;
  201. private ProgressDialog pd=null;
  202. customview cView;
  203. String path="";
  204. String pathchk="";
  205. String temp="";
  206. String name=null;
  207. float pathSmooth[];
  208. private File mStoreFile;
  209. Gesture gest;
  210. File dir;
  211. String dirname;
  212. File[] files;
  213. int count;
  214. int Height;
  215. int Weight;
  216. task dotask;
  217. Context ct;
  218. private static GestureLibrary sStore=null;
  219.  
  220.  
  221. private static final int FILE_SELECT_CODE = 0;
  222.  
  223.  
  224. public void perform() //
  225. {
  226. cView.set_file(pathchk);
  227. cView.postInvalidate();
  228. }
  229. class A extends AsyncTask<File[],Integer,Void>
  230. {
  231. private Context cnt;
  232. int count=0;
  233. @Override
  234. protected void onPreExecute() {
  235.  
  236. }
  237. A(Context context)
  238. {
  239. cnt=context;
  240. }
  241.  
  242. protected Void doInBackground(File[]... params) {
  243. // TODO Auto-generated method stub
  244. File[] newfiles=params[0];
  245. File[] temp=null;
  246. int progress=0;
  247. float dircnt=0;
  248. int numberofdir=newfiles.length;
  249. for(File b:newfiles)
  250. {
  251.  
  252.  
  253. count=0;
  254. dirname=b.getName();
  255. if(b.isDirectory())
  256. {
  257.  
  258. temp=b.listFiles();
  259. }
  260. for(File a:temp)
  261. {
  262. gest=dotask.batchprocess(a.getPath());
  263. if(gest!=null)
  264. System.out.println("success");
  265. String name=dirname+"_"+count;
  266. saveGesture(name, gest);
  267. count++;
  268.  
  269. }
  270. dircnt=dircnt+1;
  271. progress=(int)((dircnt/numberofdir)*100);
  272. try {
  273. Thread.sleep(60);
  274. publishProgress(progress);
  275. } catch (InterruptedException e) {
  276. // TODO Auto-generated catch block
  277. e.printStackTrace();
  278. }
  279.  
  280.  
  281.  
  282. }
  283.  
  284.  
  285. return null;
  286. }
  287. @Override
  288. protected void onProgressUpdate(Integer... values) {
  289. // increment progress bar by progress value
  290. pd.setProgress(values[0]);
  291. pd.setMessage("completed "+dirname);
  292.  
  293.  
  294. }
  295. protected void onPostExecute() {
  296. pd.hide();
  297. pd=null;
  298. }
  299. }
  300. public void addgestures()
  301. {
  302. cView.postInvalidate();
  303. dotask.setH(cView.getH());
  304. dotask.setW(cView.getW());
  305.  
  306. count=0;
  307. files=null;
  308. /*if(dir.isDirectory())
  309. {
  310. files=dir.listFiles();
  311. }*/
  312. files=dir.listFiles();
  313. for(int i=0;i<files.length;i++)
  314. {
  315. System.out.println(files[i].getPath());
  316. }
  317. pd = new ProgressDialog(this);
  318. pd.setMessage("Matching progress");
  319. pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  320. pd.setMax(100);
  321. pd.setCancelable(false);
  322. pd.setProgress(0);
  323. pd.show();
  324.  
  325.  
  326.  
  327. A a=new A(this);
  328. a.execute(files);
  329.  
  330.  
  331.  
  332. }
  333.  
  334.  
  335.  
  336.  
  337.  
  338. public void showFileChooser() {
  339. Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  340. // File file = new File("/sdcard");
  341. intent.setType("file://*");
  342.  
  343. intent.addCategory(Intent.CATEGORY_OPENABLE);
  344.  
  345. try {
  346. startActivityForResult(
  347. Intent.createChooser(intent, "Select a File to Upload"),
  348. FILE_SELECT_CODE);
  349.  
  350. } catch (android.content.ActivityNotFoundException ex) {
  351. // Potentially direct the user to the Market with a Dialog
  352. Toast.makeText(this, "Please install a File Manager.",
  353. Toast.LENGTH_SHORT).show();
  354. }
  355. }
  356. public void smoothPoint()
  357. {
  358.  
  359. float pathScale[]=cView.getPathSmooth();
  360. int pi; // Index over all the points in the trace
  361.  
  362. int ti; // Index over all the traces of a tracegroup
  363. float Xavg,Yavg;
  364. //int numTraces=getNumTraces();
  365. int numTraces=1;
  366. int stopCount=0;
  367. int numPoints =(pathScale.length)/2;
  368. float xsd,ysd;
  369. int count1=1,count2=1;
  370. float m2=0,m1=0;
  371. float sumX=0, sumY=0; //partial sum
  372. float Xchannel []=new float[numPoints*2];
  373. float Xdist=0,Ydist=0;
  374. float Ychannel []=new float[numPoints*2];
  375. float nXchannel[]= new float[numPoints*2*2];
  376. float nYchannel[]=new float[numPoints*2*2];
  377. int finalCount=1;
  378. float n1Xchannel[]= new float[numPoints*4*2];
  379. float n1Ychannel[]=new float[numPoints*4*2];
  380. float xfinal[] = new float[numPoints*4*2];
  381. float yfinal[]= new float[numPoints*4*2];
  382. int valid[]=new int[numPoints];
  383. Log.v("number of points",numPoints+"");
  384. for(int i=0;i<numPoints;i++)
  385. {
  386. //valid[i]=1;
  387. Xchannel[i]=pathScale[i*2];
  388. Ychannel[i]=pathScale[i*2+1];
  389. }
  390. for(ti=0;ti<numTraces;ti++)
  391. {
  392. sumX=sumY=0;
  393. for(pi=0;pi<numPoints-1;pi++)
  394. {
  395. sumX+=Math.abs((Math.abs(Xchannel[pi+1])-Math.abs(Xchannel[pi])));
  396. sumY+=Math.abs((Math.abs(Ychannel[pi+1])-Math.abs(Ychannel[pi])));
  397. }
  398. }
  399. for(pi=1;pi<numPoints-1;pi++)
  400. {
  401. m1=(Ychannel[pi]-Ychannel[pi-1])/(Xchannel[pi]-Xchannel[pi-1]);
  402. m2=(Ychannel[pi+1]-Ychannel[pi])/(Xchannel[pi+1]-Xchannel[pi]);
  403. if(m1*m2<0)
  404. {
  405. valid[pi]=0;
  406. stopCount++;
  407.  
  408. }
  409.  
  410. }
  411.  
  412.  
  413. nXchannel[0]=Xchannel[0];
  414. nYchannel[0]=Ychannel[0];
  415. for(pi=1;pi<numPoints;pi++)
  416. {
  417. nXchannel[pi*2-1]=(Xchannel[pi]+Xchannel[pi-1])/2;
  418.  
  419. nYchannel[pi*2-1]=(Ychannel[pi]+Ychannel[pi-1])/2;
  420. //System.out.print(" n mid x and y "+nXchannel[pi*2-1]+nYchannel[pi*2-1]);
  421. nXchannel[pi*2]=Xchannel[pi];
  422.  
  423. nYchannel[pi*2]=Ychannel[pi];
  424. count1+=2;
  425. }
  426. //System.out.println("new array... ");
  427. n1Xchannel[0]=nXchannel[0];
  428. n1Ychannel[0]=nYchannel[0];
  429. for(pi=1;pi<count1;pi++)
  430. {
  431. n1Xchannel[pi*2-1]=(nXchannel[pi]+nXchannel[pi-1])/2;
  432.  
  433. n1Ychannel[pi*2-1]=(nYchannel[pi]+nYchannel[pi-1])/2;
  434. //System.out.print(" n mid x and y "+n1Xchannel[pi*2-1]+n1Ychannel[pi*2-1]);
  435. n1Xchannel[pi*2]=nXchannel[pi];
  436. count2+=2;
  437. n1Ychannel[pi*2]=nYchannel[pi];
  438.  
  439. }
  440. Log.v("Count1",count1+"");
  441. Log.v("Count2",count2+"");
  442. xfinal[0]=n1Xchannel[0];
  443. yfinal[0]=n1Ychannel[0];
  444. Xavg=sumX/(numPoints -1);
  445. Log.v("finalCount",finalCount+"");
  446. Log.v("Xavg",sumX+"");
  447. Yavg=sumY/(numPoints-1) ;
  448.  
  449. for(pi=1;pi<count2-1;pi++)
  450. {
  451.  
  452. Xdist=Math.abs((Math.abs(n1Xchannel[pi])-Math.abs(xfinal[finalCount-1])));
  453. Ydist=Math.abs((Math.abs(n1Ychannel[pi])-Math.abs(yfinal[finalCount-1])));
  454. if(Xdist>=Xavg||Ydist>=Yavg)
  455. {
  456. xfinal[finalCount]=n1Xchannel[pi];
  457. yfinal[finalCount++]=n1Ychannel[pi];
  458. }
  459.  
  460.  
  461. }
  462. pathSmooth=new float[finalCount*2];
  463. for(pi=0;pi<finalCount;pi++)
  464. {
  465. pathSmooth[pi*2] = xfinal[pi];
  466. pathSmooth[pi*2+1] = yfinal[pi];
  467. //pnts.get(pi).x=(int) nXchannel[pi];
  468. //pnts.get(pi).y=(int) nYchannel[pi];
  469. ////System.out.println("x "+(int)nXchannel[pi]+ " and y "+(int)nYchannel[pi]);
  470. }
  471.  
  472. cView.setPathSmooth(pathSmooth);
  473.  
  474.  
  475.  
  476.  
  477.  
  478. }
  479. protected void onActivityResult(int requestCode, int resultCode, Intent data)
  480. {
  481. switch (requestCode) {
  482. case FILE_SELECT_CODE:
  483. if (resultCode == RESULT_OK) {
  484. // Get the Uri of the selected file
  485. Uri uri = data.getData();
  486. Log.v("check", "File Uri: " + uri.toString());
  487. // Get the path
  488.  
  489. try {
  490. path = FileUtils.getPath(this, uri);
  491. pathchk=path.substring(12);
  492. perform();
  493.  
  494.  
  495.  
  496. } catch (URISyntaxException e) {
  497. // TODO Auto-generated catch block
  498. Log.v("error", "File Path: "+pathchk);
  499. }
  500. Log.v("check", "File Path: "+path);
  501. // Get the file instance
  502. // File file = new File(path);
  503. // Initiate the upload
  504. }
  505. break;
  506. case 1:
  507. if(resultCode==RESULT_OK)
  508. {
  509. Uri uri=data.getData();
  510. dir=new File(uri.getPath());
  511. dirname=dir.getName();
  512. //addgestures();
  513.  
  514. }
  515. break;
  516. }
  517.  
  518. super.onActivityResult(requestCode, resultCode, data);
  519. }
  520. @Override
  521.  
  522. public void onCreate(Bundle savedInstanceState) {
  523. super.onCreate(savedInstanceState);
  524. setContentView(R.layout.main);
  525. cView = (customview)findViewById(R.id.customview1);
  526. LinearLayout ll = new LinearLayout(this);
  527. ll.setOrientation(LinearLayout.VERTICAL);
  528. mStoreFile= new File(Environment.getExternalStorageDirectory(), "gestures");
  529. if (sStore == null) {
  530. sStore = GestureLibraries.fromFile(mStoreFile);
  531. }
  532. dotask=new task();
  533.  
  534. //select=(Button)findViewById(R.id.button1);
  535. }
  536. public boolean onCreateOptionsMenu(Menu menu)
  537. {
  538. //call the base class to include system menus
  539. super.onCreateOptionsMenu(menu);
  540. menu.add(0,1,0,"Open File"); // title
  541. menu.add(0,2,1,"Smoothen");
  542. menu.add(0,3,2,"add to gesture library");
  543. menu.add(0,4,3,"Assign a name");
  544. menu.add(0,5,4,"select a folder");
  545. menu.add(0,6,5,"Exit");
  546. //It is important to return true to see the menu
  547. return true;
  548. }
  549. public boolean onOptionsItemSelected(MenuItem item) {
  550.  
  551. // Handle item selection
  552. switch (item.getItemId()) {
  553. case 1:
  554. showFileChooser();
  555. return true;
  556. case 2:
  557. smoothPoint();
  558. return true;
  559. case 3:
  560.  
  561. /*if(name.length()<1)
  562. Toast.makeText(getApplicationContext(), "Give a name to the gesture ist", Toast.LENGTH_LONG).show();
  563. else
  564. {
  565. gest=cView.batchprocess(pathchk);
  566. saveGesture(name, gest);
  567. }*/
  568. addgestures();
  569. return true;
  570.  
  571. case 4:
  572. nameDialog();
  573. return true;
  574. case 5:
  575. Intent intent = new Intent("org.openintents.action.PICK_DIRECTORY");
  576. intent.setData(Uri.parse("file:///sdcard"));
  577. intent.putExtra("org.openintents.extra.TITLE", "Please select a folder");
  578. intent.putExtra("org.openintents.extra.BUTTON_TEXT", "Use this folder");
  579. startActivityForResult(intent, 1);
  580. return true;
  581. case 6:
  582. Toast.makeText(getApplicationContext(), "exiting", Toast.LENGTH_LONG).show();
  583. System.exit(1);
  584. return true;
  585. default:
  586. return super.onOptionsItemSelected(item);
  587. }
  588. }
  589. public void nameDialog()
  590. {
  591. AlertDialog.Builder alert = new AlertDialog.Builder(this);
  592.  
  593. alert.setTitle("Title");
  594. alert.setMessage("Message");
  595.  
  596. // Set an EditText view to get user input
  597. final EditText input = new EditText(this);
  598. alert.setView(input);
  599.  
  600. alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  601. public void onClick(DialogInterface dialog, int whichButton) {
  602. name = input.getText().toString();
  603. //Log.d("name",name);
  604. check();
  605. // Do something with value!
  606. }
  607. });
  608.  
  609. alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  610. public void onClick(DialogInterface dialog, int whichButton) {
  611. // Canceled.
  612. }
  613. });
  614.  
  615. alert.show();
  616. }
  617. public static GestureLibrary get()
  618. {
  619. return sStore;
  620. }
  621. public void check()
  622. {
  623. if(name.length()<1)
  624. Toast.makeText(this,"No name is set for this gesture",Toast.LENGTH_SHORT).show();
  625. else
  626. Toast.makeText(this,"GESTURE NAME IS "+name,Toast.LENGTH_SHORT).show();
  627. }
  628. public void saveGesture(String name,Gesture gest)
  629. {
  630. final GestureLibrary store = get();
  631. store.addGesture(name, gest);
  632. store.save();
  633.  
  634. }
  635.  
  636. }
  637.  
  638. float[] pts = GestureUtils.temporalSampling(gesture.getStrokes().get(0), SEQUENCE_SAMPLE_SIZE);
Advertisement
Add Comment
Please, Sign In to add comment