private void initActionView(MenuItem searchItem) { if (searchView != null) return; searchView = (SearchView) MenuItemCompat.getActionView(searchItem); try { // 更改搜索按钮的icon int searchImgId = getResources().getIdentifier("android:id/search_button", null, null); ImageView v = (ImageView) searchView.findViewById(searchImgId); v.setImageResource(R.drawable.ic_menu_search); } catch (Exception e) { Global.errorLog(e); } searchView.setOnQueryTextListener( new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { return true; } @Override public boolean onQueryTextChange(String s) { ++sSearchPos; searchAdapter.reload(searchView.getQuery().toString()); return true; } }); }
public static void writeFile(File srcFile, String content) { try { FileOutputStream fos = new FileOutputStream(srcFile); fos.write(content.getBytes()); fos.close(); } catch (Exception e) { Global.errorLog(e); } }
private String readTextFile(InputStream inputStream) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int len; try { while ((len = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, len); } outputStream.close(); inputStream.close(); } catch (IOException e) { Global.errorLog(e); } return outputStream.toString(); }
@AfterViews protected final void initMaopaoDetailActivity() { getSupportActionBar().setDisplayHomeAsUpEnabled(true); mEnterLayout = new EnterEmojiLayout( this, onClickSend, EnterLayout.Type.TextOnly, EnterEmojiLayout.EmojiType.SmallOnly); mEnterLayout.content.addTextChangedListener(new TextWatcherAt(this, this, RESULT_REQUEST_AT)); try { bubble = readTextFile(getAssets().open("bubble")); } catch (Exception e) { Global.errorLog(e); } swipeRefreshLayout.setOnRefreshListener(this); swipeRefreshLayout.setColorSchemeResources(R.color.green); loadData(); }