longquan
Posted Sunnor
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了longquan相关的知识,希望对你有一定的参考价值。
1 /** 2 * 登录后将数据填写到主数据 3 */ 4 public void login(String login_nr) 5 { 6 //File f = new File(android.os.Environment.getExternalStorageDirectory()+"/info.txt"); //后面是跟你在sd卡上存放的xml路径 7 String path = this.ReadFilePatch("/info.txt"); 8 9 File myfile=new File(path); 10 String login_file; 11 String login_nr_new; 12 if(myfile.exists()) 13 { 14 login_file = ReadTxtFile(path); 15 // = "login,"+login_file; 16 login_nr_new = "login,"+login_file; 17 }else 18 { 19 login_nr_new = login_nr; 20 } 21 22 login_nr_new.replaceAll("\n", ""); 23 24 String[] array_nr = login_nr_new.split(","); 25 /** 26 * UserName + ‘,‘ 27 + CardNum + ‘,‘ + Star + ‘,‘ 28 + JobNum + ‘,‘ + UserJobDesc + ‘,‘ 29 + UserDept + ‘,‘ + UserWin 30 */ 31 //tv_name = (TextView)findViewById(R.id.ew_name); 32 //weiyongle if判断里的代码有问题,经过调试,发现array_nr的长度是1,这里直接访问array_nr[1]的数值,所以程序异常退出 33 if(array_nr.length>8){ 34 tv_name.setText(array_nr[1]); 35 36 //tv_code = (TextView)findViewById(R.id.ew_code); 37 tv_code.setText(array_nr[4]); 38 39 tv_ckh = (TextView)findViewById(R.id.ew_ckh); 40 tv_ckh.setText(array_nr[7].replaceAll("\n", "")); 41 } 42 43 44 if (array_nr.length>7) 45 { 46 TextView txt_bsjs = (TextView)findViewById(R.id.txt_bsjs); 47 txt_bsjs.setText(array_nr[8].replaceAll("\n", "")); 48 } 49 50 TextView tv_userjob = (TextView)findViewById(R.id.txt_userjob); 51 52 //ratingbar_Small = (RatingBar)findViewById(R.id.ratingbar_Small); 53 if (!array_nr[3].equals("")) 54 ratingbar_Small.setRating(Integer.parseInt(array_nr[3])); 55 else 56 ratingbar_Small.setRating(0); 57 58 //tv_part = (TextView)findViewById(R.id.ew_part); 59 tv_part.setText(array_nr[6]); 60 61 tv_bsjs = (TextView)findViewById(R.id.txt_bsjs); 62 //tv_bsjs.setText(array_nr[4]); 63 64 img_user = (ImageView)findViewById(R.id.img_user); 65 66 path = this.ReadFilePatch("/2.JPG"); 67 68 Bitmap bmp = getlocalBitmap(path);//"/mnt/external_sd/2.jpg"); 69 70 71 72 img_user.setImageBitmap(bmp); 73 74 75 }
完整版:
1 package cn.com.yutian.zwxt; 2 3 4 import java.io.BufferedInputStream; 5 import java.io.BufferedReader; 6 import java.io.File; 7 import java.io.FileInputStream; 8 import java.io.FileNotFoundException; 9 import java.io.IOException; 10 import java.io.InputStream; 11 import java.io.InputStreamReader; 12 import java.io.RandomAccessFile; 13 import java.text.SimpleDateFormat; 14 import java.util.ArrayList; 15 import java.util.Calendar; 16 import java.util.Date; 17 import java.util.HashMap; 18 import java.util.List; 19 import java.util.Locale; 20 import java.util.Map; 21 import java.util.Timer; 22 import java.util.TimerTask; 23 24 import org.json.JSONArray; 25 import org.json.JSONObject; 26 27 import com.androidquery.AQuery; 28 import com.androidquery.callback.AjaxCallback; 29 import com.androidquery.callback.AjaxStatus; 30 31 import cn.com.css.tax.product.android.common.utils.DataHelper; 32 import cn.com.css.tax.product.android.common.utils.ServiceHelper; 33 import cn.com.css.tax.product.android.common.utils.SettingsHelper; 34 import cn.com.css.tax.product.android.widget.fragment.AbstractAsyncActivity; 35 import cn.com.css.tax.product.android.widget.pulllist.RequestMessage; 36 import cn.com.yutian.zwxt.R; 37 38 import android.app.Activity; 39 import android.app.AlertDialog; 40 import android.content.ContentValues; 41 import android.content.Context; 42 import android.content.Intent; 43 import android.content.res.Resources; 44 import android.database.sqlite.SQLiteDatabase; 45 import android.graphics.Bitmap; 46 import android.graphics.BitmapFactory; 47 import android.graphics.drawable.AnimationDrawable; 48 import android.media.MediaPlayer; 49 import android.os.Bundle; 50 import android.os.Environment; 51 import android.os.Handler; 52 import android.os.Message; 53 import android.util.DisplayMetrics; 54 import android.util.Log; 55 import android.view.LayoutInflater; 56 import android.view.Menu; 57 import android.view.View; 58 import android.view.ViewGroup; 59 import android.widget.AbsListView; 60 import android.widget.AdapterView; 61 import android.widget.AdapterView.OnItemClickListener; 62 import android.widget.ArrayAdapter; 63 import android.widget.ImageView; 64 import android.widget.LinearLayout; 65 import android.widget.ListView; 66 import android.widget.RatingBar; 67 import android.widget.SimpleAdapter; 68 import android.widget.TextView ; 69 import android.widget.Toast; 70 71 public class MianActivy extends Activity { 72 public TextView tv_name,tv_code,tv_ckh,tv_part,tv_bsjs,txt_time,txt_date,txt_mdate; 73 public RatingBar ratingbar_Small; 74 public TimeTextView tv_djs; 75 public AQuery aq; 76 private RequestMessage requestMessage; 77 78 private ImageView imageView,img_user; 79 80 private LinearLayout linearLayout; 81 82 private AnimationDrawable animationDrawable; 83 84 // wangling 85 private static final String PACKAGE_NAME = "com.wangling.anypcadmin"; 86 87 // intent action to trigger wangling 88 public static final String PRINT_ACTION = "com.wangling.anypcadmin.AuthActivity"; 89 90 private List list_bslc = new ArrayList();; 91 private Bitmap bmp; 92 93 private ListView mListView; 94 private String[] mStrings = {"“三高”地点接纳设置无线寻呼发射基站的“三高”产权单位备案(... ","《承装(修、试)电力设施许可证》核发", 95 "《电工进网作业许可证》核发","《医疗器械出口销售证明书》", 96 "《医疗器械生产企业许可证》换证","《自费出国留学中介服务协议书》样本备案", 97 "安全技术防范产品生产审批","安全生产许可_1","安全生产许可_2"}; 98 99 private View view_pjend; 100 private MediaPlayer mp1; 101 private Timer timer; 102 private int recLen; 103 104 public void onCreate(Bundle savedInstanceState) { 105 106 super.onCreate(savedInstanceState); 107 setContentView(R.layout.main_1920); 108 /* 109 * 隐藏运行Android 4.0以上系统的平板的屏幕下方的状态栏 110 */ 111 /*try 112 { 113 String ProcID = "79"; 114 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) ProcID = "42"; // ICS 115 // 需要root 权限 116 Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "service call activity " + ProcID + " s16 com.android.systemui" }); // WAS 117 proc.waitFor(); 118 } 119 catch (Exception ex) 120 { 121 Toast.makeText(getApplicationContext(), ex.getMessage(), Toast.LENGTH_LONG).show(); 122 } */ 123 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 124 // getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE); 125 // getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 126 127 //aq = new AQuery(this); 128 129 tv_name = (TextView)findViewById(R.id.ew_name); 130 //tv_name.setText(R.string.ew_name); 131 132 tv_code = (TextView)findViewById(R.id.ew_code); 133 //tv_code.setText(R.string.ew_code); 134 135 tv_ckh = (TextView)findViewById(R.id.ew_ckh); 136 //tv_ckh.setText(R.string.ew_ckh); 137 138 tv_part = (TextView)findViewById(R.id.ew_part); 139 //tv_part.setText(R.string.ew_part); 140 141 tv_bsjs = (TextView)findViewById(R.id.txt_bsjs); 142 //tv_bsjs.setText(""); 143 144 ratingbar_Small = (RatingBar)findViewById(R.id.ratingbar_Small); 145 //ratingbar_Small.setMax(5); 146 147 148 //handlertime.post(updateThread); 149 150 linearLayout = (LinearLayout)findViewById(R.id.layout_main); 151 152 153 //weiyongle 注释 154 initImgAnim(); 155 156 //initwelcome(); 157 Intent intent = getIntent(); 158 // 获得Intent中的Extra 159 String value = intent.getDataString(); 160 //weiyongle 注释 161 mp1 = MediaPlayer.create(MianActivy.this, R.raw.welcome); 162 163 if (value==null) 164 { 165 166 value = ""; 167 168 //weiyongle login方法有问题,所以这里先注释掉 169 // this.login(value); 170 171 this.initImgAnim(); 172 173 } 174 /*animationDrawable = new AnimationDrawable(); 175 176 177 178 animationDrawable.addFrame(getResources().getDrawable(R.drawable.news_1), 1500); 179 animationDrawable.addFrame(getResources().getDrawable(R.drawable.news_2), 1500); 180 animationDrawable.addFrame(getResources().getDrawable(R.drawable.bszn), 1500); 181 182 //设置手否重复播放,false为重复 183 184 animationDrawable.setOneShot(false); 185 186 imageView.setImageDrawable(animationDrawable); 187 188 animationDrawable.start();*/ 189 190 //initImgAnim(); 191 192 /*DisplayMetrics mDisplayMetrics = new DisplayMetrics(); 193 getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics); 194 int W = mDisplayMetrics.widthPixels; 195 int H = mDisplayMetrics.heightPixels; 196 197 TextView txt_bsjs = (TextView)findViewById(R.id.txt_bsjs);*/ 198 199 //txt_bsjs.setText("Width = " + String.valueOf(W) + "Height = " + H) 200 201 // 得到传过来的Intent对象 202 /*Intent intent = getIntent(); 203 // 获得Intent中的Extra 204 String value = intent.getDataString(); //输出 -pj 205 if (value==null) 206 { 207 208 value = ""; 209 new AlertDialog.Builder(this).setTitle("Android 提示").setMessage(value).show(); 210 this.login(value); 211 new AlertDialog.Builder(this).setTitle("Android 提示").setMessage("3").show(); 212 this.initImgAnim(); 213 new AlertDialog.Builder(this).setTitle("Android 提示").setMessage("4").show(); 214 } 215 216 if (value.equals("pj")) 217 { 218 this.login(value); 219 this.pj(); 220 }else 221 if (value.indexOf("tp")!=-1) 222 { 223 this.login(value); 224 this.tp(); 225 }else 226 if (value.indexOf("zt")!=-1) 227 { 228 this.login(value); 229 this.djs(); 230 }else 231 if (value.indexOf("tz")!=-1) 232 { 233 this.login(value); 234 this.tz(value); 235 }else 236 if (value.indexOf("login")!=-1) 237 { 238 this.login(value); 239 this.initImgAnim(); 240 }else 241 if (value.indexOf("bj")!=-1) 242 { 243 this.login(value); 244 this.bj(); 245 } 246 else if (value.indexOf("hy")!=-1) 247 { 248 this.login(value); 249 mp1.start(); 250 new Thread(){ 251 @Override 252 public void run() { 253 //需要花时间的函数 254 try { 255 Thread.sleep(8000); 256 } catch (InterruptedException e) { 257 // TODO Auto-generated catch block 258 e.printStackTrace(); 259 } 260 //向handler发消息 261 handler.sendEmptyMessage(0); 262 }}.start(); 263 }else 264 { 265 initImgAnim(); 266 }*/ 267 } 268 269 /** 270 * 得到数据 271 */ 272 public void getData(View view) { 273 274 asyncTrans("10008001","{GBNF:test}","jsonCallBack"); 275 276 } 277 278 /** 279 * 普通报文通讯 280 * 281 * @param businessid 282 * 业务ID 283 * @param requestmessage 284 * 请求报文(JSONObject JSONArray结构) 285 * @param callback 286 * 需要实现的返回回调方法 public void jsonCallback(String url,JSONObject 287 * json, AjaxStatus status){} 288 * 289 */ 290 public void asyncTrans(String businessid, String requestmessage, 291 AjaxCallback<JSONObject> callback) { 292 final String url = DataHelper 293 .getServiceType(this) == DataHelper.SERVICE_TYPE_TEST ? getString(R.string.base_uri) 294 : SettingsHelper.getInstance(this) 295 .getStringSetting(SettingsHelper.SETTING_STR_IP) 296 + "servlet/AndroidServlet"; 297 Map<String, Object> params = new HashMap<String, Object>(); 298 requestMessage = new RequestMessage(this); 299 requestMessage.setBusinessid(businessid); 300 requestMessage.setRequestmessage(requestmessage); 301 params.put(ServiceHelper.SERVICE_REQUEST_PARM_STR, requestMessage); 302 aq.progress(android.R.id.progress).ajax(url, params, JSONObject.class, 303 callback); 304 } 305 306 /** 307 * 普通报文通讯 308 * 309 * @param businessid 310 * 业务ID 311 * @param requestmessage 312 * 请求报文(JSONObject JSONArray结构) 313 * @param callback 314 * 需要实现的返回回调方法 public void jsonCallback(String url,JSONObject 315 * json, AjaxStatus status){} 316 * 317 */ 318 public void asyncTrans(String businessid, String requestmessage, 319 String callback) { 320 final String url = getString(R.string.base_uri) 321 + "servlet/AndroidServlet"; 322 Map<String, Object> params = new HashMap<String, Object>(); 323 requestMessage = new RequestMessage(this); 324 requestMessage.setBusinessid(businessid); 325 requestMessage.setRequestmessage(requestmessage); 326 params.put(ServiceHelper.SERVICE_REQUEST_PARM_STR, requestMessage); 327 aq.progress(android.R.id.progress).ajax(url, params, JSONObject.class, 328 this, callback); 329 330 } 331 332 333 /** 334 * 切换布局,将布局 内容嵌套到当前页面 335 */ 336 public void pj() 337 { 338 mp1 = MediaPlayer.create(MianActivy.this, R.raw.fwpj); 339 340 mp1.start(); 341 342 removeView(); 343 344 View view =LayoutInflater.from(this).inflate(R.layout.main_pj_1280, null); 345 linearLayout.addView(view); 346 } 347 348 public void jsonCallback(String url,JSONObject 349 json, AjaxStatus status){ 350 System.out.println(json.toString()); 351 } 352 353 //第三种方式(Android1.6版本及以后的版本中提供了) 354 public void Imv2OnClick(View view){ 355 /*Intent intent = new Intent(this, SearchViewActivity.class); 356 startActivity(intent);*/ 357 removeView(); 358 View v =LayoutInflater.from(this).inflate(R.layout.searchview_layout_1280, null); 359 linearLayout.addView(v); 360 mListView = (ListView) findViewById(R.id.list_view); //拿到ListView对象 361 362 final Resources res = getResources(); 363 //final String[] bslc_title = res.getStringArray(R.array.string_array_bslc_title); 364 final String[] bslc_title2 =readbslc(""); 365 final String[] bslc_nr =readbslc_nr(""); 366 /*mListView.setAdapter(new ArrayAdapter<String>( 367 this,R.layout.list_bslc,R.id.tv_bslc_title1,bslc_title)); //添加适配器*/ 368 List<Map<String, Object>> list_bslc = new ArrayList<Map<String, Object>>(); 369 Map<String, Object> item; 370 371 boolean dup = true; 372 int i = 0; 373 /*while (dup) { 374 item = new HashMap<String, Object>(); 375 if (i<bslc_title2.length){ 376 //判断刚好为单数的情况 377 if (i+1==bslc_title2.length) 378 { 379 item.put("title1",bslc_title2[i]); 380 list_bslc.add(item); 381 dup = false; 382 }else 383 { 384 item.put("title1",bslc_title2[i]); 385 item.put("title1",bslc_title2[i+1]); 386 list_bslc.add(item); 387 i=i+2; 388 if (i==bslc_title2.length) 389 { 390 391 dup = false; 392 } 393 } 394 } 395 396 397 }*/ 398 for (int i1=0;i1<bslc_title2.length;i1++) 399 { 400 item = new HashMap<String, Object>(); 401 item.put("title1",bslc_title2[i1]); 402 list_bslc.add(item); 403 } 404 405 SimpleAdapter adapter = new SimpleAdapter(this,list_bslc,R.layout.list_bslc, 406 //new String[]{"title1", "title2"}, 407 new String[]{"title1"}, 408 new int[]{R.id.tv_bslc_title1}); 409 410 final View v_nr =LayoutInflater.from(this).inflate(R.layout.main_bslc_1280, null); 411 412 mListView.setAdapter(adapter); 413 414 mListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); 415 mListView.setOnItemClickListener(new OnItemClickListener() { 416 417 418 419 @Override 420 public void onItemClick(AdapterView<?> arg0, View arg1, 421 int arg2, long arg3) { 422 // TODO Auto-generated method stub 423 removeView(); 424 425 linearLayout.addView(v_nr); 426 427 //final String[] bslc_nr = res.getStringArray(R.array.string_array_bslc_mx); 428 //final String[] bslc_title = res.getStringArray(R.array.string_array_bslc_title); 429 430 TextView tv_title = (TextView)findViewById(R.id.txt_blsc_title); 431 tv_title.setText(bslc_title2[arg2]); 432 433 TextView tv_nr = (TextView)findViewById(R.id.txt_nr); 434 tv_nr.setText(bslc_nr[arg2]); 435 436 } 437 //@Override 438 /*public View getView(int position, View convert, ViewGroup parent) { 439 // TODO Auto-generated method stub 440 ViewHolder holder; 441 442 // 设置选中效果 443 if(selectedPosition == position) 444 { 445 holder.text.setTextColor(Color.BLUE); 446 holder.layout.setBackgroundColor(Color.YELLOW); 447 } else { 448 holder.text.setTextColor(Color.WHITE); 449 holder.layout.setBackgroundColor(Color.TRANSPARENT); 450 } 451 return convert; 452 } */ 453 }); 454 } 455 //第三种方式(Android1.6版本及以后的版本中提供了) 456 public void Imv3OnClick(View view){ 457 /*Intent intent = new Intent(this, PjActivy.class); 458 startActivity(intent);*/ 459 this.pj(); 460 } 461 462 private void removeView() { 463 //获取linearlayout子view的个数 464 int count = linearLayout.getChildCount(); 465 if (count>0) 466 linearLayout.removeViewAt(count - 1); 467 //研究整个LAYOUT布局, 468 //因此,在remove的时候,只能操作的是0<location<count-1这个范围的 469 //在执行每次remove时,我们从count-2的位置即textview上面的那个控件开始删除~ 470 if (count - 2 > 0) { 471 //count-2>0用来判断当前linearlayout子view数多于2个,即还有我们点add增加的button 472 linearLayout.removeViewAt(count - 2); 473 } 474 } 475 private void openBmp(String path) 476 { 477 if (bmp != null)// 如果不释放的话,不断取图片,将会内存不够 478 { 479 bmp.recycle(); 480 481 bmp = BitmapFactory.decodeFile(path); 482 483 imageView.setImageBitmap(bmp); 484 485 } else { 486 bmp = BitmapFactory.decodeFile(path); 487 imageView.setImageBitmap(bmp); 488 } 489 } 490 public void ImvPjOnClick(View view){ 491 492 493 String pjjg="0"; 494 int vid = view.getId(); 495 switch (vid) 496 { 497 case R.id.my_912: 498 pjjg="0"; 499 break; 500 case R.id.jbmy_912: 501 pjjg="1"; 502 break; 503 case R.id.tdbh_912: 504 pjjg="2"; 505 break; 506 case R.id.xlbg_912: 507 pjjg="3"; 508 break; 509 case R.id.ywbs_912: 510 pjjg="4"; 511 break; 512 case R.id.ydgj_912: 513 pjjg="5"; 514 break; 515 default: 516 pjjg=""; 517 break; 518 } 519 String scode= String.valueOf(tv_code.getText()); 520 521 ////员工号+//评价信息+//录像文件目录+//业务办理计时,写死5分钟 522 this.WriteData(scode.replaceAll(" ", "") + "," + pjjg + ",,5"); 523 this.insertpjxx(scode,pjjg); 524 removeView(); 525 /*view_pjend =LayoutInflater.from(this).inflate(R.layout.pj_end, null); 526 linearLayout.addView(view_pjend);*/ 527 528 View v =LayoutInflater.from(this).inflate(R.layout.anima_1920, null); 529 linearLayout.addView(v); 530 531 532 imageView = (ImageView)findViewById(R.id.animationviewbg3); 533 534 imageView.setImageResource(R.drawable.thanks); 535 536 mp1 = MediaPlayer.create(MianActivy.this, R.raw.thanks); 537 538 mp1.start(); 539 540 new Thread(){ 541 @Override 542 public void run() { 543 //需要花时间的函数 544 try { 545 Thread.sleep(5000); 546 } catch (InterruptedException e) { 547 // TODO Auto-generated catch block 548 e.printStackTrace(); 549 } 550 //向handler发消息 551 handler.sendEmptyMessage(0); 552 }}.start(); 553 /*try { 554 Thread.currentThread(); 555 Thread.sleep(5000); 556 } catch (InterruptedException e) { 557 // TODO Auto-generated catch block 558 e.printStackTrace(); 559 }*/ 560 561 562 //initImgAnim(); 563 } 564 private void initImgAnim() 565 { 566 567 removeView(); 568 View v =LayoutInflater.from(this).inflate(R.layout.anima_1920, null); 569 linearLayout.addView(v); 570 571 animationDrawable = new AnimationDrawable(); 572 animationDrawable.addFrame(getResources().getDrawable(R.drawable.zgm912), 3000); 573 animationDrawable.addFrame(getResources().getDrawable(R.drawable.ad912), 3000); 574 //animationDrawable.addFrame(getResources().getDrawable(R.drawable.ad2), 3000); 575 //animationDrawable.addFrame(getResources().getDrawable(R.drawable.bszn), 1500); 576 577 //设置手否重复播放,false为重复 578 579 animationDrawable.setOneShot(false); 580 581 imageView = (ImageView)findViewById(R.id.animationviewbg3); 582 583 imageView.setImageDrawable(animationDrawable); 584 585 animationDrawable.start(); 586 } 587 private Handler handler = new Handler(){ 588 589 @Override 590 public void handleMessage(Message msg) { 591 592 593 initImgAnim(); 594 }}; 595 596 private void initwelcome() 597 { 598 599 removeView(); 600 View v =LayoutInflater.from(this).inflate(R.layout.anima_1920, null); 601 linearLayout.addView(v); 602 603 604 imageView = (ImageView)findViewById(R.id.animationviewbg3); 605 606 imageView.setImageResource(R.drawable.welcome); 607 608 609 } 610 611 public void djs() 612 { 613 614 mp1 = MediaPlayer.create(MianActivy.this, R.raw.stop); 615 mp1.start(); 616 removeView(); 617 View v =LayoutInflater.from(this).inflate(R.layout.mian_stop_1280, null); 618 linearLayout.addView(v); 619 620 621 tv_djs= (TimeTextView)findViewById(R.id.txt_djs); 622 //开始计时,性能测试用nanoTime会更精确,因为它是纳秒级的 623 long startTime = System.nanoTime(); 624 long[] times = {0,0,15,0}; 625 tv_djs.setTimes(times); 626 //特卖倒计时控件 627 //已经在倒计时的时候不再开启计时 628 if(!tv_djs.isRun()) 629 { 630 tv_djs.run(); 631 } 632 //停止计时 633 long endTime = System.nanoTime(); 634 //耗时 635 long spendTime = (endTime - startTime); 636 637 Log.d("GoogleIO", "--sumTime:"+String.valueOf(spendTime)); 638 //timer = new Timer(); 639 //recLen = 10; 640 641 //timer.schedule(task, 1000, 1000); // timeTask 642 643 } 644 645 public void djs(View view) 646 { 647 648 removeView(); 649 View v =LayoutInflater.from(this).inflate(R.layout.mian_stop_1280, null); 650 linearLayout.addView(v); 651 652 653 tv_djs= (TimeTextView)findViewById(R.id.txt_djs); 654 //开始计时,性能测试用nanoTime会更精确,因为它是纳秒级的 655 long startTime = System.nanoTime(); 656 long[] times = {0,0,15,0}; 657 tv_djs.setTimes(times); 658 //特卖倒计时控件 659 //已经在倒计时的时候不再开启计时 660 if(!tv_djs.isRun()) 661 { 662 tv_djs.run(); 663 } 664 //停止计时 665 long endTime = System.nanoTime(); 666 //耗时 667 long spendTime = (endTime - startTime); 668 669 Log.d("GoogleIO", "--sumTime:"+String.valueOf(spendTime)); 670 //timer = new Timer(); 671 //recLen = 10; 672 673 //timer.schedule(task, 1000, 1000); // timeTask 674 675 } 676 TimerTask task = new TimerTask() { 677 @Override 678 public void run() { 679 680 runOnUiThread(new Runnable() { // UI thread 681 @Override 682 public void run() { 683 recLen--; 684 tv_djs.setText("倒计时时间("+recLen+")"); 685 if(recLen < 0){ 686 timer.cancel(); 687 tv_djs.setVisibility(View.GONE); 688 } 689 } 690 }); 691 } 692 }; 693 694 695 public static Bitmap getlocalBitmap(String url) 696 { 697 698 File f = new File(url); //后面是跟你在sd卡上存放的xml路径 699 String path=f.getAbsolutePath(); 700 File myfile=new File(path); 701 if(myfile.exists()) 702 { 703 //hasFile=1; 704 } 705 try { 706 FileInputStream fileIS = new FileInputStream(path); 707 return BitmapFactory.decodeStream(fileIS); 708 } catch (FileNotFoundException e) { 709 // TODO Auto-generated catch block 710 e.printStackTrace(); 711 return null; 712 } 713 714 715 } 716 717 718 /** 719 * 切换布局,将布局 内容嵌套到当前页面 720 */ 721 public void tp() 722 { 723 removeView(); 724 View v =LayoutInflater.from(this).inflate(R.layout.anima_1280, null); 725 linearLayout.addView(v); 726 727 728 imageView = (ImageView)findViewById(R.id.animationviewbg3); 729 730 Bitmap bmp = getlocalBitmap("/mnt/external_sd/1.jpg"); 731 732 imageView.setImageBitmap(bmp); 733 } 734 735 /** 736 * 切换布局,将布局 内容嵌套到当前页面 737 */ 738 public void tz(String tznr) 739 { 740 741 removeView(); 742 743 final View v_nr =LayoutInflater.from(this).inflate(R.layout.main_bslc_1280, null); 744 String[] array = tznr.split(","); 745 linearLayout.addView(v_nr); 746 747 TextView tv_title = (TextView)findViewById(R.id.txt_blsc_title); 748 tv_title.setText("临时通知"); 749 String path = this.ReadFilePatch("/tzxx.txt"); 750 751 File myfile=new File(path); 752 String login_file=""; 753 String login_nr_new; 754 if(myfile.exists()) 755 { 756 login_file = ReadTxtFile(path); 757 // = "login,"+login_file; 758 759 } 760 761 TextView tv_nr = (TextView)findViewById(R.id.txt_nr); 762 tv_nr.setText(login_file); 763 764 } 765 /** 766 * 切换布局,将布局 内容嵌套到当前页面 767 */ 768 public void bj() 769 { 770 771 removeView(); 772 773 final View v_nr =LayoutInflater.from(this).inflate(R.layout.bslc_bj_1280, null); 774 775 linearLayout.addView(v_nr); 776 777 778 779 } 780 /** 781 * 登录后将数据填写到主数据 782 */ 783 public void login(String login_nr) 784 { 785 //File f = new File(android.os.Environment.getExternalStorageDirectory()+"/info.txt"); //后面是跟你在sd卡上存放的xml路径 786 String path = this.ReadFilePatch("/info.txt"); 787 788 File myfile=new File(path); 789 String login_file; 790 String login_nr_new; 791 if(myfile.exists()) 792 { 793 login_file = ReadTxtFile(path); 794 // = "login,"+login_file; 795 login_nr_new = "login,"+login_file; 796 }else 797 { 798 login_nr_new = login_nr; 799 } 800 801 login_nr_new.replaceAll("\n", ""); 802 803 String[] array_nr = login_nr_new.split(","); 804 /** 805 * UserName + ‘,‘ 806 + CardNum + ‘,‘ + Star + ‘,‘ 807 + JobNum + ‘,‘ + UserJobDesc + ‘,‘ 808 + UserDept + ‘,‘ + UserWin 809 */ 810 //tv_name = (TextView)findViewById(R.id.ew_name); 811 //weiyongle if判断里的代码有问题,经过调试,发现array_nr的长度是1,这里直接访问array_nr[1]的数值,所以程序异常退出 812 if(array_nr.length>8){ 813 tv_name.setText(array_nr[1]); 814 815 //tv_code = (TextView)findViewById(R.id.ew_code); 816 tv_code.setText(array_nr[4]); 817 818 tv_ckh = (TextView)findViewById(R.id.ew_ckh); 819 tv_ckh.setText(array_nr[7].replaceAll("\n", "")); 820 } 821 822 823 if (array_nr.length>7) 824 { 825 TextView txt_bsjs = (TextView)findViewById(R.id.txt_bsjs); 826 txt_bsjs.setText(array_nr[8].replaceAll("\n", "")); 827 } 828 829 TextView tv_userjob = (TextView)findViewById(R.id.txt_userjob); 830 831 //ratingbar_Small = (RatingBar)findViewById(R.id.ratingbar_Small); 832 if (!array_nr[3].equals("")) 833 ratingbar_Small.setRating(Integer.parseInt(array_nr[3])); 834 else 835 ratingbar_Small.setRating(0); 836 837 //tv_part = (TextView)findViewById(R.id.ew_part); 838 tv_part.setText(array_nr[6]); 839 840 tv_bsjs = (TextView)findViewById(R.id.txt_bsjs); 841 //tv_bsjs.setText(array_nr[4]); 842 843 img_user = (ImageView)findViewById(R.id.img_user); 844 845 path = this.ReadFilePatch("/2.JPG"); 846 847 Bitmap bmp = getlocalBitmap(path);//"/mnt/external_sd/2.jpg"); 848 849 850 851 img_user.setImageBitmap(bmp); 852 853 854 } 855 856 //读取文本文件中的内容 857 public static String ReadTxtFile(String strFilePath) 858 { 859 String path = strFilePath; 860 String content = ""; //文件内容字符串 861 //打开文件 862 File file = new File(path); 863 //如果path是传递过来的参数,可以做一个非目录的判断 864 if (file.isDirectory()) 865 { 866 Log.d("TestFile", "The File doesn‘t not exist."); 867 } 868 else 869 { 870 try { 871 InputStream instream = new FileInputStream(file); 872 if (instream != null) 873 { 874 875 InputStreamReader inputreader = new InputStreamReader(instream); 876 BufferedReader buffreader ; 877 BufferedInputStream in = new BufferedInputStream(instream); 878 in.mark(4); 879 byte[]first3bytes = new byte[3]; 880 in.read(first3bytes); 881 in.reset(); 882 if(first3bytes[0] == (byte) 0xEF && first3bytes[1] == (byte) 0xBB 883 &&first3bytes[2] == (byte) 0xBF) {// utf-8 884 885 buffreader = new BufferedReader(new InputStreamReader(in, "utf-8")); 886 887 }else if (first3bytes[0] == (byte) 0xFF 888 &&first3bytes[1] == (byte) 0xFE) { 889 890 buffreader = new BufferedReader( 891 new InputStreamReader(in,"unicode")); 892 }else if (first3bytes[0] == (byte) 0xFE 893 &&first3bytes[1] == (byte) 0xFF) { 894 895 buffreader = new BufferedReader(new InputStreamReader(in, 896 "utf-16be")); 897 }else if (first3bytes[0] == (byte) 0xFF 898 &&first3bytes[1] == (byte) 0xFF) { 899 900 buffreader = new BufferedReader(new InputStreamReader(in, 901 "utf-16le")); 902 }else { 903 904 buffreader = new BufferedReader(new InputStreamReader(in, "GBK")); 905 } 906 //BufferedReader buffreader = new BufferedReader(inputreader); 907 String line; 908 //分行读取 909 while (( line = buffreader.readLine()) != null) { 910 content += line + "\n"; 911 } 912 instream.close(); 913 } 914 } 915 catch (java.io.FileNotFoundException e) 916 { 917 Log.d("TestFile", "The File doesn‘t not exist."); 918 } 919 catch (IOException e) 920 { 921 Log.d("TestFile", e.getMessage()); 922 } 923 } 924 return content; 925 } 926 //读取文本文件中的内容 927 public String ReadFilePatch(String strFileName) 928 { 929 File f = new File(android.os.Environment.getExternalStorageDirectory() + strFileName); //后面是跟你在sd卡上存放的xml路径 930 String path=f.getAbsolutePath(); 931 932 File myfile=new File(path); 933 934 if(myfile.exists()) 935 { 936 return path; 937 } 938 939 if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ 940 941 942 f = new File(android.os.Environment.getExternalStorageDirectory() + strFileName); //后面是跟你在sd卡上存放的xml路径 943 path=f.getAbsolutePath(); 944 945 myfile=new File(path); 946 if(myfile.exists()) 947 { 948 return path; 949 } 950 } 951 952 953 954 f = new File(android.os.Environment.getDownloadCacheDirectory() + strFileName); //后面是跟你在sd卡上存放的xml路径 955 path=f.getAbsolutePath(); 956 957 myfile=new File(path); 958 if(myfile.exists()) 959 { 960 return path; 961 } 962 963 f = new File("/storage/sdcard0/"+ strFileName); //后面是跟你在sd卡上存放的xml路径 964 path=f.getAbsolutePath(); 965 966 myfile=new File(path); 967 if(myfile.exists()) 968 { 969 return path; 970 } 971 return ""; 972 } 973 974 private void WriteData(String pjdata) { 975 String filePath = this.ReadFilePatch("/info.txt"); 976 977 filePath = filePath.replaceAll("info.txt", ""); 978 //new AlertDialog.Builder(this).setTitle("Android 提示").setMessage(filePath).show(); 979 980 String fileName = "pj.txt"; 981 982 writeTxtToFile(pjdata, filePath, fileName); 983 } 984 985 986 // 将字符串写入到文本文件中 987 public void writeTxtToFile(String strcontent, String filePath, String fileName) { 988 //生成文件夹之后,再生成文件,不然会出错 989 makeFilePath(filePath, fileName); 990 991 String strFilePath = filePath+fileName; 992 // 每次写入时,都换行写 993 String strContent = strcontent + "\r\n"; 994 try { 995 File file = new File(strFilePath); 996 if (!file.exists()) { 997 Log.d("TestFile", "Create the file:" + strFilePath); 998 file.getParentFile().mkdirs(); 999 file.createNewFile(); 1000 } 1001 RandomAccessFile raf = new RandomAccessFile(file, "rwd"); 1002 raf.seek(file.length()); 1003 raf.write(strContent.getBytes()); 1004 raf.close(); 1005 } catch (Exception e) { 1006 Log.e("TestFile", "Error on write File:" + e); 1007 } 1008 } 1009 1010 // 生成文件 1011 public File makeFilePath(String filePath, String fileName) { 1012 File file = null; 1013 makeRootDirectory(filePath); 1014 try { 1015 file = new File(filePath + fileName); 1016 if (!file.exists()) { 1017 file.createNewFile(); 1018 } 1019 } catch (Exception e) { 1020 e.printStackTrace(); 1021 } 1022 return file; 1023 } 1024 1025 // 生成文件夹 1026 public static void makeRootDirectory(String filePath) { 1027 File file = null; 1028 try { 1029 file = new File(filePath); 1030 if (!file.exists()) { 1031 file.mkdir(); 1032 } 1033 } catch (Exception e) { 1034 Log.i("error:", e+""); 1035 } 1036 } 1037 1038 public void insertpjxx(String user_code,String pjjg) 1039 { 1040 //初始化数据库 1041 DatabaseHelper helper = new DatabaseHelper(this); 1042 SQLiteDatabase database = helper.getReadableDatabase(); 1043 1044 ContentValues value = new ContentValues(); 1045 //Iterator<Map<String, Object>> sListIterator = myapp.getList_dcjsxx().iterator(); 1046 //while(sListIterator.hasNext()){ 1047 1048 value.put("user_code", user_code); 1049 value.put("pjsj", pjjg); 1050 1051 value.put("jk_time", System.currentTimeMillis()); 1052 1053 database.insert("tb_dcxx_mx", null, value); 1054 //} 1055 } 1056 1057 /** 1058 * 登录后将数据填写到主数据 1059 * @throws Exception 1060 */ 1061 public String[] readbslc(String login_nr) 1062 { 1063 //File f = new File(android.os.Environment.getExternalStorageDirectory()+"/info.txt"); //后面是跟你在sd卡上存放的xml路径 1064 String path = this.ReadFilePatch("/bslc.txt"); 1065 1066 File myfile=new File(path); 1067 String login_file; 1068 String login_nr_new; 1069 1070 if(myfile.exists()) 1071 { 1072 login_file = ReadTxtFile(path); 1073 // = "login,"+login_file; 1074 //bslcjs = JSONObject.fromString(login_file); 1075 try { 1076 String s = "["+login_file.replaceAll("\\}\n\\{", "\\},\\{")+"]"; 1077 list_bslc =DataHelper.getList(s); 1078 String[] title1 = new String[list_bslc.size()]; 1079 for (int i =0 ;i<list_bslc.size();i++) 1080 { 1081 Map jsonObject = (Map) list_bslc.get(i); 1082 title1[i] = (String) jsonObject.get("bslc_title"); 1083 } 1084 return title1; 1085 1086 } catch (Exception e) { 1087 // TODO Auto-generated catch block 1088 e.printStackTrace(); 1089 } 1090 1091 1092 1093 }else 1094 { 1095 return mStrings; 1096 } 1097 1098 return mStrings; 1099 1100 } 1101 /** 1102 * 登录后将数据填写到主数据 1103 * @throws Exception 1104 */ 1105 public String[] readbslc_nr(String login_nr) 1106 { 1107 1108 if (list_bslc!=null&&list_bslc.size()>0) 1109 { 1110 String[] nr1 = new String[list_bslc.size()]; 1111 for (int i =0 ;i<list_bslc.size();i++) 1112 { 1113 Map jsonObject = (Map) list_bslc.get(i); 1114 nr1[i] = (String) jsonObject.get("bslc_nr"); 1115 } 1116 return nr1; 1117 } 1118 return this.getResources().getStringArray(R.array.string_array_bslc_mx); 1119 1120 1121 1122 //return mStrings; 1123 1124 } 1125 1126 @Override 1127 protected void onDestroy() 1128 { 1129 // TODO Auto-generated method stub 1130 /* 1131 * 恢复运行Android 4.0以上系统的平板的屏幕下方的状态栏 1132 */ 1133 try 1134 { 1135 Process proc = Runtime.getRuntime().exec(new String[] { "am", "startservice", "-n", "com.android.systemui/.SystemUIService" }); 1136 proc.waitFor(); 1137 } 1138 catch (Exception e) 1139 { 1140 e.printStackTrace(); 1141 } 1142 super.onDestroy(); 1143 } 1144 1145 /*@Override 1146 public boolean onCreateOptionsMenu(Menu menu) 1147 { 1148 // Inflate the menu; this adds items to the action bar if it is present. 1149 getMenuInflater().inflate(R.menu.startup, menu); 1150 return true; 1151 } 1152 1153 @Override 1154 public boolean onOptionsItemSelected(MenuItem item) 1155 { 1156 // TODO Auto-generated method stub 1157 switch (item.getItemId()) 1158 { 1159 case R.id.action_exit: 1160 finish(); 1161 break; 1162 } 1163 return true; 1164 }*/ 1165 private String DEFAULT_TIME_FORMAT = "HH:mm"; 1166 1167 private String DEFAULT_DATE_FORMAT = "yyyy/MM/dd"; 1168 1169 private String time=""; 1170 1171 //创建Handler对象 1172 1173 Handler handlertime = new Handler(); 1174 1175 //新建一个线程对象 1176 1177 Runnable updateThread = new Runnable(){ 1178 1179 //将要执行的操作写在线程对象的run方法当中 1180 1181 public void run(){ 1182 1183 handlertime.postDelayed(updateThread, 60*1000); 1184 1185 //调用Handler的postDelayed()方法 1186 1187 //这个方法的作用是:将要执行的线程对象放入到队列当中,待时间结束后,运行制定的线程对象 1188 1189 //第一个参数是Runnable类型:将要执行的线程对象 1190 1191 //第二个参数是long类型:延迟的时间,以毫秒为单位 1192 1193 SimpleDateFormat dateFormatter = new SimpleDateFormat(DEFAULT_TIME_FORMAT); 1194 1195 time = dateFormatter.format(Calendar.getInstance().getTime()); 1196 /*txt_time = (TextView)findViewById(R.id.txt_time); 1197 if (txt_time.getText().toString().indexOf(":")>-1) 1198 { 1199 txt_time.setText(time.replaceAll(":", " ")); 1200 }else 1201 { 1202 txt_time.setText(time); 1203 } 1204 1205 1206 1207 dateFormatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT); 1208 1209 String date = dateFormatter.format(Calendar.getInstance().getTime()); 1210 1211 1212 1213 txt_date = (TextView)findViewById(R.id.txt_date); 1214 txt_date.setText(date); 1215 1216 txt_mdate = (TextView)findViewById(R.id.txt_mdate); 1217 txt_mdate.setText(DataString.StringData());*/ 1218 //txt_mdate.setText(); 1219 1220 1221 } 1222 1223 }; 1224 1225 }
以上是关于longquan的主要内容,如果未能解决你的问题,请参考以下文章