private void populateItem() { SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() { public boolean setViewValue(View view, Object data, String textRepresentation) { // We configured the SimpleAdapter to create TextViews (see // the 'to' array, above), so this cast should be safe: TextView textView = (TextView) view; textView.setText(textRepresentation); return true; } }; SimpleAdapter seasonAdapter = new SimpleAdapter( this, seasonList, android.R.layout.simple_spinner_item, new String[] {"seasonName"}, new int[] {android.R.id.text1}); seasonAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); seasonAdapter.setViewBinder(viewBinder); spnSeason.setAdapter(seasonAdapter); spnSeason.setPrompt(getString(R.string.select_season)); SimpleAdapter typeAdapter = new SimpleAdapter( this, typeList, android.R.layout.simple_spinner_item, new String[] {"typeName"}, new int[] {android.R.id.text1}); typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeAdapter.setViewBinder(viewBinder); spnType.setAdapter(typeAdapter); spnType.setPrompt(getString(R.string.select_type)); SimpleAdapter statusAdapter = new SimpleAdapter( this, statusList, android.R.layout.simple_spinner_item, new String[] {"statusName"}, new int[] {android.R.id.text1}); statusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); statusAdapter.setViewBinder(viewBinder); spnStatus.setAdapter(statusAdapter); spnStatus.setPrompt(getString(R.string.select_status)); }
// 刷新图片 @Override public void onResume() { super.onResume(); if (!TextUtils.isEmpty(pathImage)) { Bitmap addbmp = BitmapFactory.decodeFile(pathImage); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("itemImage", addbmp); imageItem.add(map); simpleAdapter = new SimpleAdapter( getActivity(), imageItem, R.layout.item_upload_image_grid, new String[] {"itemImage"}, new int[] {R.id.imageView1}); simpleAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { // TODO Auto-generated method stub if (view instanceof ImageView && data instanceof Bitmap) { ImageView i = (ImageView) view; i.setImageBitmap((Bitmap) data); return true; } return false; } }); mGridView.setAdapter(simpleAdapter); simpleAdapter.notifyDataSetChanged(); // 刷新后释放防止手机休眠后自动添加 pathImage = null; } }
/** 初始化资源 */ void initreso() { al_demandobject = new ArrayList<>(); arrayList_map = new ArrayList<>(); simpleAdapter = new SimpleAdapter( view.getContext(), arrayList_map, R.layout.demanditem, new String[] {"goodname", "picture", "descreption", "time"}, new int[] { R.id.goods_name, R.id.demand_touxiang, R.id.goods_description, R.id.release_time }); listView.setAdapter(simpleAdapter); simpleAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView && data instanceof Bitmap) { ImageView iv = (ImageView) view; // iv.setImageBitmap((Bitmap) data); iv.setImageDrawable(new CircleImageDrawable((Bitmap) data)); return true; } else { return false; } } }); }
/** 处理资讯 */ private void dealNews() { SimpleAdapter listItemAdapter = new SimpleAdapter( this.getActivity(), newsList, R.layout.listitem_news, new String[] {"photo", "title", "publisher", "date"}, new int[] { R.id.news_image_photo, R.id.news_label_title, R.id.news_label_publisher, R.id.news_label_date }); listItemAdapter.setViewBinder( new ViewBinder() { public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView && data instanceof Bitmap) { ImageView imageView = (ImageView) view; Bitmap bitmap = (Bitmap) data; imageView.setImageDrawable(new BitmapDrawable(bitmap)); return true; } return false; } }); listNews.setAdapter(listItemAdapter); listNews.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int index, long arg3) { index = index - 1; HashMap<String, Object> newsMap = newsList.get(index); Intent intent = new Intent(HomeActivity.this.getActivity(), BrowserActivity.class); intent.putExtra("url", newsMap.get("url").toString()); HomeActivity.this.startActivity(intent); } }); listNews.setOnScrollListener( new OnScrollListener() { boolean isLastRow = false; @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (isLastRow && scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { loadNews(); isLastRow = false; } } @Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem + visibleItemCount == totalItemCount && totalItemCount > 2) { isLastRow = true; } } }); }
private void bindFileToFileListView(String selectDir) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException { if (selectDir.equals("")) selectDir = "/"; this.currDir = selectDir; this.fileNav.setText(this.currDir); File dir = new File(this.currDir); File[] files = dir.listFiles(); List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); if (files != null) for (File f : files) { String name = f.getName(); Map<String, Object> map = new HashMap<String, Object>(); if (f.isDirectory()) { map.put(FILE_PIC, this.getImageResourceByFileExt("")); map.put(FILE_FULL_PATH, f.getAbsolutePath()); } else { int p = name.lastIndexOf("."); if (p > 0) { map.put(FILE_PIC, this.getImageResourceByFileExt(name.substring(p + 1).toLowerCase())); } else map.put(FILE_PIC, this.unknowFile); StringBuilder sb = new StringBuilder(String.valueOf(f.length() / 1024)); sb.append("KB "); sb.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(f.lastModified()))); map.put(FILE_FULL_PATH, sb.toString()); } map.put(FILE_NAME, name); data.add(map); } else data.add(new HashMap<String, Object>()); SimpleAdapter adp = new SimpleAdapter( this.getContext(), data, R.layout.file_list_view, new String[] {FILE_PIC, FILE_NAME, FILE_FULL_PATH}, new int[] {R.id.file_pic, R.id.file_name, R.id.file_full_path}); adp.setViewBinder( new ViewBinder() { public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView && data instanceof Integer) { ImageView img = (ImageView) view; img.setImageResource(Integer.parseInt(data.toString())); return true; } return false; } }); this.fileList.setAdapter(adp); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); prefsWrapper = new PreferencesWrapper(getActivity()); useCodecsPerSpeed = SipConfigManager.getPreferenceBooleanValue( getActivity(), SipConfigManager.CODECS_PER_BANDWIDTH); initDatas(); setHasOptionsMenu(true); // Adapter mAdapter = new SimpleAdapter( getActivity(), codecsList, R.layout.codecs_list_item, new String[] {CODEC_NAME, CODEC_NAME, CODEC_PRIORITY}, new int[] {R.id.line1, R.id.AccCheckBoxActive, R.id.entiere_line}); mAdapter.setViewBinder( new ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (view.getId() == R.id.entiere_line) { Log.d(THIS_FILE, "Entiere line is binded "); TextView tv = (TextView) view.findViewById(R.id.line1); ImageView grabber = (ImageView) view.findViewById(R.id.icon); CompoundButton checker = (CompoundButton) view.findViewById(R.id.AccCheckBoxActive); checker.setOnCheckedChangeListener(CodecsFragment.this); if ((Short) data == 0) { tv.setTextColor(Color.GRAY); grabber.setVisibility(View.GONE); checker.setChecked(false); } else { tv.setTextColor(Color.WHITE); grabber.setVisibility(View.VISIBLE); checker.setChecked(true); } return true; } else if (view.getId() == R.id.AccCheckBoxActive) { view.setTag(data); return true; } return false; } }); setListAdapter(mAdapter); registerForContextMenu(getListView()); }
@SuppressWarnings("unchecked") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rc_devices_list); dataList = (List<PingResult>) getIntent().getSerializableExtra(MainFragmentRemote.DEVICE_LIST); adapter = new SimpleAdapter( this, dataList, R.layout.rc_devices_list_item, new String[] {"IP", "HostName"}, new int[] {R.id.rc_device_list_item_tv_ip, R.id.rc_device_list_item_tv_hostname}); adapter.setViewBinder(IPViewBinder); setListAdapter(adapter); regNetStatusListener(); }
/** * Creates ListAdapter populated with recommendation information. * * @param recommendations the list of recommendations used to populate the adapter. * @return an adapter populated with recommendation information. */ private ListAdapter createRecommendationsListAdapter(List<Recommendation> recommendations) { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); for (Recommendation recommendation : recommendations) { Map<String, Object> map = new HashMap<String, Object>(); map.put("productImage", recommendation.getImageUrl()); map.put("recommendationTitle", recommendation.getTitle()); map.put("recommendationDetails", recommendation.getDescription()); data.add(map); } SimpleAdapter adapter = new SimpleAdapter( PlaceDetailsActivity.this, data, R.layout.offer_item, new String[] {"productImage", "recommendationTitle", "recommendationDetails"}, new int[] {R.id.offer_Image, R.id.offer_name, R.id.offer_description}); adapter.setViewBinder(new ImageUrlViewBinder(R.id.offer_Image)); return adapter; }
/** * Creates ListAdapter populated with offer information. * * @param offers the list of offers used to populate the adapter. * @return an adapter populated with offer information. */ private ListAdapter createOfferListAdapter(List<Offer> offers) { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); for (Offer offer : offers) { Map<String, Object> map = new HashMap<String, Object>(); map.put("offerIcon", offer.getImageUrl()); map.put("offerTitle", offer.getTitle()); map.put("offerDetails", offer.getDescription()); data.add(map); } SimpleAdapter adapter = new SimpleAdapter( PlaceDetailsActivity.this, data, R.layout.offer_item, new String[] {"offerIcon", "offerTitle", "offerDetails"}, new int[] {R.id.offer_Image, R.id.offer_name, R.id.offer_description}); adapter.setViewBinder(new ImageUrlViewBinder(R.id.offer_Image)); return adapter; }
@Override protected void buildListAdapter(Object[] result) { // TODO Auto-generated method stub if (result.length == 0) Toast.makeText(this, R.string.error_device_code_is_not_existed, Toast.LENGTH_LONG).show(); ArrayList<HashMap<String, Device>> items = new ArrayList<HashMap<String, Device>>(); for (int i = 0; i < result.length; i++) { HashMap<String, Device> item = new HashMap<String, Device>(); item.put("device", (Device) result[i]); items.add(item); } SimpleAdapter adapter = new SimpleAdapter( this, items, android.R.layout.simple_list_item_checked, new String[] {"device"}, new int[] {android.R.id.text1}); adapter.setViewBinder(this); setListAdapter(adapter); }
private void initAdapert() { // TODO Auto-generated method stub // 实例化数据库服务 timingService = new TimingService(memoDb); realTimeService = new RealTimeService(memoDb); periodicService = new PeriodicService(memoDb); // 获取userId String userId = sp.getString("user", null); // 数据库中获取的List<Timing> List<Timing> timingList = timingService.getTimingByUserID(userId); List<RealTime> realList = realTimeService.getRealTimeByUserID(userId); List<Periodic> perioList = periodicService.getPeriodicByUserID(userId); mList = new ArrayList<Map<String, Object>>(); if (timingList != null) { Collections.sort( timingList, new Comparator<Timing>() { @Override public int compare(Timing lhs, Timing rhs) { String timingStartTime1 = lhs.getStart_time(); String timingStartTime2 = rhs.getStart_time(); if (lhs.getPriority() < rhs.getPriority()) { return 1; } else if (lhs.getPriority() == rhs.getPriority()) { if (timingStartTime1.compareTo(timingStartTime2) > 0) { return 1; } else { return -1; } } else { return -1; } } }); } if (perioList != null) { Collections.sort( perioList, new Comparator<Periodic>() { @Override public int compare(Periodic lhs, Periodic rhs) { String periodicStartTime1 = lhs.getStart_time(); String periodicStartTime2 = rhs.getStart_time(); if (lhs.getPriority() < rhs.getPriority()) { return 1; } else if (lhs.getPriority() == rhs.getPriority()) { if (periodicStartTime1.compareTo(periodicStartTime2) > 0) { return 1; } else { return -1; } } else { return -1; } } }); } if (realList != null) { Collections.sort( realList, new Comparator<RealTime>() { @Override public int compare(RealTime lhs, RealTime rhs) { String realStartTime1 = lhs.getStart_time(); String realStartTime2 = rhs.getStart_time(); if (lhs.getPriority() < rhs.getPriority()) { return 1; } else if (lhs.getPriority() == rhs.getPriority()) { if (realStartTime1.compareTo(realStartTime2) > 0) { return 1; } else { return -1; } } else { return -1; } } }); } if (realList != null) { // 实时提醒迭代器 RealTime tempRealTime; Iterator itRealTime = realList.iterator(); while (itRealTime.hasNext()) { tempRealTime = (RealTime) itRealTime.next(); if (tempRealTime.getIsfinish() == 0) { Map<String, Object> mListItem = new HashMap<String, Object>(); String temp; mListItem.put("textListCategory", "实时提醒"); mListItem.put("ratingBarListItem", (float) tempRealTime.getPriority()); if (tempRealTime.getContent().length() <= 10) { temp = tempRealTime.getContent(); } else { temp = tempRealTime.getContent().substring(0, 10) + "……"; } mListItem.put("textListContent", temp); mListItem.put("textIndex", tempRealTime.getReal_id()); mList.add(mListItem); } } } if (timingList != null) { Timing tempTiming; // 定时提醒迭代器 Iterator itTiming = timingList.iterator(); while (itTiming.hasNext()) { tempTiming = (Timing) itTiming.next(); if (tempTiming.getIsfinish() == 0) { Map<String, Object> mListItem = new HashMap<String, Object>(); String temp; mListItem.put("textListCategory", "定时提醒"); mListItem.put("ratingBarListItem", (float) tempTiming.getPriority()); if (tempTiming.getContent().length() <= 10) { temp = tempTiming.getContent(); } else { temp = tempTiming.getContent().substring(0, 10) + "……"; } mListItem.put("textListContent", temp); mListItem.put("textIndex", tempTiming.getTiming_id()); mList.add(mListItem); } } } if (perioList != null) { Periodic tempPreiodic; // 周期性提醒迭代器 Iterator itPeriodic = perioList.iterator(); while (itPeriodic.hasNext()) { tempPreiodic = (Periodic) itPeriodic.next(); Map<String, Object> mListItem = new HashMap<String, Object>(); String temp; mListItem.put("textListCategory", "周期性提醒"); mListItem.put("ratingBarListItem", (float) tempPreiodic.getPriority()); if (tempPreiodic.getContent().length() <= 10) { temp = tempPreiodic.getContent(); } else { temp = tempPreiodic.getContent().substring(0, 10) + "……"; } mListItem.put("textListContent", temp); mListItem.put("textIndex", tempPreiodic.getPeriodic_id()); mList.add(mListItem); } } mAdapter = new SimpleAdapter(getActivity(), mList, R.layout.listview_layout, from, to); // 重写Adapter支持RatingBar mAdapter.setViewBinder( new ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { // TODO Auto-generated method stub if (view.getId() == R.id.textListCategory) { category = (String) data; if (category.equals("定时提醒")) { color = getResources().getColor(R.color.red); drawable = getResources().getDrawable(R.drawable.alarm_icon_getup); } else if (category.equals("实时提醒")) { color = getResources().getColor(R.color.red); drawable = getResources().getDrawable(R.drawable.alarm_icon_normal); } else if (category.equals("周期性提醒")) { color = getResources().getColor(R.color.red); drawable = getResources().getDrawable(R.drawable.alarm_icon_monthly); } TextView textListCategory = (TextView) view; textListCategory.setTextColor(color); textListCategory.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } if (view.getId() == R.id.ratingBarListItem) { Float value = (Float) data; float ratingValue = value.floatValue(); RatingBar ratingBar = (RatingBar) view; ratingBar.setRating(ratingValue); return true; } else return false; } }); memosRemind(); }
private void initUI() { /** * This adapter takes the data in transferRecordMaps and displays it, with the keys of the map * being related to the columns in the adapter */ simpleAdapter = new SimpleAdapter( this, transferRecordMaps, R.layout.record_item, new String[] {"checked", "fileName", "progress", "bytes", "state", "percentage"}, new int[] { R.id.radioButton1, R.id.textFileName, R.id.progressBar1, R.id.textBytes, R.id.textState, R.id.textPercentage }); simpleAdapter.setViewBinder( new ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { switch (view.getId()) { case R.id.radioButton1: RadioButton radio = (RadioButton) view; radio.setChecked((Boolean) data); return true; case R.id.textFileName: TextView fileName = (TextView) view; String getData = (String) data; String fileNameStr = getData.split("/")[5]; fileName.setText(fileNameStr); return true; case R.id.progressBar1: ProgressBar progress = (ProgressBar) view; progress.setProgress((Integer) data); return true; case R.id.textBytes: TextView bytes = (TextView) view; bytes.setText((String) data); return true; case R.id.textState: TextView state = (TextView) view; state.setText(((TransferState) data).toString()); return true; case R.id.textPercentage: TextView percentage = (TextView) view; percentage.setText((String) data); return true; } return false; } }); setListAdapter(simpleAdapter); // Updates checked index when an item is clicked getListView() .setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int pos, long id) { if (checkedIndex != pos) { transferRecordMaps.get(pos).put("checked", true); if (checkedIndex >= 0) { transferRecordMaps.get(checkedIndex).put("checked", false); } checkedIndex = pos; updateButtonAvailability(); simpleAdapter.notifyDataSetChanged(); } } }); // btnUploadFile = (Button) findViewById(R.id.buttonUploadFile); // btnUploadImage = (Button) findViewById(R.id.buttonUploadImage); // btnPause = (Button) findViewById(R.id.buttonPause); // btnResume = (Button) findViewById(R.id.buttonResume); // btnCancel = (Button) findViewById(R.id.buttonCancel); btnDelete = (Button) findViewById(R.id.buttonDelete); // btnPauseAll = (Button) findViewById(R.id.buttonPauseAll); // btnCancelAll = (Button) findViewById(R.id.buttonCancelAll); btnPlay = (Button) findViewById(R.id.button_upload_play); btnPlay.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (checkedIndex >= 0 && checkedIndex < observers.size()) { Object nowData = simpleAdapter.getItem(checkedIndex); String myData = nowData.toString(); String myDataSet[] = myData.split(","); String fileNameSet[] = myDataSet[2].split("="); String fileName = fileNameSet[1]; // 현재 선택한 object 에서 file name 가져오기 Intent intent = new Intent(UploadActivity.this, MusicPlayerActivity.class); intent.putExtra("pos", fileName); Toast.makeText(UploadActivity.this, "pos : " + fileName, Toast.LENGTH_SHORT).show(); startActivityForResult(intent, 1); } } }); // // btnUploadFile.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // Intent intent = new Intent(); // if (Build.VERSION.SDK_INT >= 19) { // // For Android KitKat, we use a different intent to ensure // // we can // // get the file path from the returned intent URI // intent.setAction(Intent.ACTION_OPEN_DOCUMENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); // intent.setType("*/*"); // } else { // intent.setAction(Intent.ACTION_GET_CONTENT); // intent.setType("file/*"); // } // // startActivityForResult(intent, 0); // } // }); // // btnUploadImage.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // Intent intent = new Intent(); // if (Build.VERSION.SDK_INT >= 19) { // // For Android versions of KitKat or later, we use a // // different intent to ensure // // we can get the file path from the returned intent URI // intent.setAction(Intent.ACTION_OPEN_DOCUMENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); // } else { // intent.setAction(Intent.ACTION_GET_CONTENT); // } // // intent.setType("image/*"); // startActivityForResult(intent, 0); // } // }); // // btnPause.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // Make sure the user has selected a transfer // if (checkedIndex >= 0 && checkedIndex < observers.size()) { // Boolean paused = // transferUtility.pause(observers.get(checkedIndex).getId()); // /** // * If paused does not return true, it is likely because the // * user is trying to pause an upload that is not in a // * pausable state (For instance it is already paused, or // * canceled). // */ // if (!paused) { // Toast.makeText( // UploadActivity.this, // "Cannot pause transfer. You can only pause transfers in a // IN_PROGRESS or WAITING state.", // Toast.LENGTH_SHORT).show(); // } // } // } // }); // // btnResume.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // Make sure the user has selected a transfer // if (checkedIndex >= 0 && checkedIndex < observers.size()) { // TransferObserver resumed = // transferUtility.resume(observers.get(checkedIndex) // .getId()); // // Sets a new transfer listener to the original observer. // // This will overwrite existing listener. // observers.get(checkedIndex).setTransferListener(new UploadListener()); // /** // * If resume returns null, it is likely because the transfer // * is not in a resumable state (For instance it is already // * running). // */ // if (resumed == null) { // Toast.makeText( // UploadActivity.this, // "Cannot resume transfer. You can only resume transfers in a // PAUSED state.", // Toast.LENGTH_SHORT).show(); // } // } // } // }); // // btnCancel.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // Make sure a transfer is selected // if (checkedIndex >= 0 && checkedIndex < observers.size()) { // Boolean canceled = // transferUtility.cancel(observers.get(checkedIndex).getId()); // /** // * If cancel returns false, it is likely because the // * transfer is already canceled // */ // if (!canceled) { // Toast.makeText( // UploadActivity.this, // "Cannot cancel transfer. You can only resume transfers in a // PAUSED, WAITING, or IN_PROGRESS state.", // Toast.LENGTH_SHORT).show(); // } // } // } // }); btnDelete.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // Make sure a transfer is selected if (checkedIndex >= 0 && checkedIndex < observers.size()) { transferUtility.deleteTransferRecord(observers.get(checkedIndex).getId()); observers.remove(checkedIndex); transferRecordMaps.remove(checkedIndex); checkedIndex = INDEX_NOT_CHECKED; updateButtonAvailability(); updateList(); } } }); // // btnPauseAll.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // transferUtility.pauseAllWithType(TransferType.UPLOAD); // } // }); // // btnCancelAll.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // transferUtility.cancelAllWithType(TransferType.UPLOAD); // } // }); updateButtonAvailability(); }
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); Resources res = getResources(); Context context = getBaseContext(); SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context); mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK); mNonce = UUID.randomUUID().getMostSignificantBits(); mFeedbackUrl = res.getString(R.string.feedback_post_url); mErrorUrl = res.getString(R.string.error_post_url); mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); mPostingFeedback = false; initAllAlertDialogs(); getErrorFiles(); Intent i = getIntent(); mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR)) || mReportErrorMode.equals(REPORT_ASK); if (!mAllowFeedback) { if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report try { String feedback = "Automatically sent"; Connection.sendFeedback( mSendListener, new Payload( new Object[] { mFeedbackUrl, mErrorUrl, feedback, mErrorReports, mNonce, getApplication(), true })); if (mErrorReports.size() > 0) { mPostingFeedback = true; } if (feedback.length() > 0) { mPostingFeedback = true; } } catch (Exception e) { Log.e(AnkiDroidApp.TAG, e.toString()); } finish(); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE); } return; } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report deleteFiles(false, false); finish(); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE); } return; } } View mainView = getLayoutInflater().inflate(R.layout.feedback, null); setContentView(mainView); Themes.setWallpaper(mainView); Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer)); Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList)); Button btnSend = (Button) findViewById(R.id.btnFeedbackSend); Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest); Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll); mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText); mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList); mErrorAdapter = new SimpleAdapter( this, mErrorReports, R.layout.error_item, new String[] {"name", "state", "result"}, new int[] {R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status}); mErrorAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { switch (view.getId()) { case R.id.error_item_progress: if (text.equals(STATE_UPLOADING)) { view.setVisibility(View.VISIBLE); } else { view.setVisibility(View.GONE); } return true; case R.id.error_item_status: if (text.length() == 0) { view.setVisibility(View.GONE); return true; } else { view.setVisibility(View.VISIBLE); return false; } } return false; } }); btnClearAll.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { deleteFiles(false, false); refreshErrorListView(); refreshInterface(); } }); mLvErrorList.setAdapter(mErrorAdapter); btnSend.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (!mPostingFeedback) { String feedback = mEtFeedbackText.getText().toString(); Connection.sendFeedback( mSendListener, new Payload( new Object[] { mFeedbackUrl, mErrorUrl, feedback, mErrorReports, mNonce, getApplication(), false })); if (mErrorReports.size() > 0) { mPostingFeedback = true; } if (feedback.length() > 0) { mPostingFeedback = true; } refreshInterface(); } } }); btnKeepLatest.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { deleteFiles(false, true); refreshErrorListView(); refreshInterface(); } }); refreshInterface(); getWindow() .setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); }
private void populateMyMovies(ListView tLV) throws ParseException { List<Movie> movies = db.getAllMovies(sortStr, sortDir); List<Map<String, String>> list = new ArrayList<Map<String, String>>(); if (movies.size() < 1) { toastMessage(MainActivity.this, getString(R.string.no_movie_notice)); } else { for (Movie i : movies) { Map map = new HashMap(); map.put("id", i.getId()); map.put("title", i.getTitle()); String target = i.getDateStr(); DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH); DateFormat newf = new SimpleDateFormat("EEE, MMM d, yyyy", Locale.ENGLISH); Date mDate = df.parse(target); String newDate = newf.format(mDate); map.put("date", newDate); map.put("rating", i.getRating()); map.put("lat", String.valueOf(i.getVenue().getLat())); map.put("lng", String.valueOf(i.getVenue().getLng())); map.put("type", i.getVenue().getVenue_type()); map.put("venue_name", i.getVenue().getVenue_name()); list.add(map); } movieAdapter = new SimpleAdapter( this, list, R.layout.my_movies_layout, new String[] {"title", "date", "rating", "type"}, new int[] { R.id.my_movie_title, R.id.my_movie_date, R.id.my_movie_rating, R.id.my_movie_icon }); movieAdapter.setViewBinder(new MyMovieBinder()); tLV.setAdapter(movieAdapter); tLV.setLongClickable(true); tLV.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Map item = (Map) parent.getAdapter().getItem(position); LatLng latlong = new LatLng( Double.valueOf(item.get("lat").toString()), Double.valueOf(item.get("lng").toString())); mMap.clear(); Marker marker = mMap.addMarker( new MarkerOptions() .position(latlong) .title(item.get("title").toString()) .snippet(item.get("venue_name").toString())); // Zoom in, animating the camera. mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latlong, 13), 800, null); marker.showInfoWindow(); } }); } }
private void initView(View rootView) { mGridView = (GridView) rootView.findViewById(R.id.grid_view); /* * 载入默认图片添加图片加号 * 通过适配器实现 * SimpleAdapter参数imageItem为数据源 R.layout.griditem_addpic为布局 */ // 获取资源图片加号 bmp = BitmapFactory.decodeResource(getResources(), android.R.drawable.ic_input_add); imageItem = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("itemImage", bmp); imageItem.add(map); simpleAdapter = new SimpleAdapter( getActivity(), imageItem, R.layout.item_upload_image_grid, new String[] {"itemImage"}, new int[] {R.id.imageView1}); /* * HashMap载入bmp图片在GridView中不显示,但是如果载入资源ID能显示 如 * map.put("itemImage", R.drawable.img); * 解决方法: * 1.自定义继承BaseAdapter实现 * 2.ViewBinder()接口实现 * 参考 http://blog.csdn.net/admin_/article/details/7257901 */ simpleAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object data, String textRepresentation) { if (view instanceof ImageView && data instanceof Bitmap) { ImageView i = (ImageView) view; i.setImageBitmap((Bitmap) data); return true; } return false; } }); mGridView.setAdapter(simpleAdapter); /* * 监听GridView点击事件 * 报错:该函数必须抽象方法 故需要手动导入import android.view.View; */ mGridView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { if (imageItem.size() == 4) { // 第一张为默认图片 Toaster.showDefToast(getActivity(), "图片数3张已满"); } else if (position == 0) { // 点击图片位置为+ 0对应0张图片 Toaster.showDefToast(getActivity(), "添加图片"); // 选择图片 Intent intent = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, IMAGE_OPEN); // 通过onResume()刷新数据 } else { dialog(position); // Toast.makeText(MainActivity.this, "点击第"+(position + 1)+" 号图片", // Toast.LENGTH_SHORT).show(); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView); Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = Collection.currentCollection(); if (mCol == null) { reloadCollection(savedInstanceState); return; } Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); mrelativeBrowserFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); mPrefCacheCardBrowser = preferences.getBoolean("cardBrowserCache", false); mOrder = preferences.getInt("cardBrowserOrder", CARD_ORDER_NONE); mCards = new ArrayList<HashMap<String, String>>(); mAllCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter( this, mCards, R.layout.card_item, new String[] {"sfld", "tmpl", "deck", "flags"}, new int[] {R.id.card_sfld, R.id.card_tmpl, R.id.card_deck, R.id.card_item}, mrelativeBrowserFontSize); mCardsAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editCard = new Intent(CardBrowser.this, CardEditor.class); editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); // if (mSelectedCard == null) { // deleteCard(mCards.get(mPositionInCardsList).get("id"), mPositionInCardsList); // return; // } startActivityForResult(editCard, EDIT_CARD); if (Integer.valueOf(android.os.Build.VERSION.SDK) > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { mTimerHandler.removeCallbacks(updateList); mTimerHandler.postDelayed(updateList, WAIT_TIME_UNTIL_UPDATE); } public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) {} }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); if (mWholeCollection) { setTitle(getResources().getString(R.string.card_browser_all_decks)); } else { try { setTitle(mCol.getDecks().current().getString("name")); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); getCards(); }
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.card_browser); mDeck = AnkiDroidApp.deck(); mDeck.resetUndo(); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext()); mrelativeBrowserFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); mCards = new ArrayList<HashMap<String, String>>(); mAllCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter( this, mCards, R.layout.card_item, new String[] {"question", "answer", "marSus"}, new int[] {R.id.card_question, R.id.card_answer, R.id.card_item}, mrelativeBrowserFontSize); mCardsAdapter.setViewBinder( new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("11")) { which = BACKGROUND_MARKED_SUSPENDED; } else if (text.substring(1, 2).equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.substring(0, 1).equals("1")) { which = BACKGROUND_MARKED; } view.setBackgroundResource(mBackground[which]); return true; } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editCard = new Intent(CardBrowser.this, CardEditor.class); mPositionInCardsList = position; mSelectedCard = mDeck.cardFromId(Long.parseLong(mCards.get(mPositionInCardsList).get("id"))); sEditorCard = mSelectedCard; editCard.putExtra("callfromcardbrowser", true); startActivityForResult(editCard, EDIT_CARD); if (Integer.valueOf(android.os.Build.VERSION.SDK) > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.addTextChangedListener( new TextWatcher() { public void afterTextChanged(Editable s) { mTimerHandler.removeCallbacks(updateList); mTimerHandler.postDelayed(updateList, WAIT_TIME_UNTIL_UPDATE); } public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int before, int count) {} }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); setTitle(mDeck.getDeckName()); allTags = null; mSelectedTags = new HashSet<String>(); getCards(); }
/** * 兴趣点列表展示 * * @param * @return */ public void setTripPoiList() { // 兴趣点列表上的基本信息 Bundle bundle = getIntent().getExtras(); // 获取Bundle tripId = bundle.getString("tripId"); // 获取路书id参数 final String TripName = bundle.getString("tripName"); // 获取路书名字参数 tripName = (TextView) this.findViewById(R.id.tripName); // 获取路书名字TextView组件 tripName.setText(TripName); // 显示路书名字 poiListLayout = (LinearLayout) this.findViewById(R.id.poiListLayout); // 获取兴趣点列表的LinearLayout myListView = new ListView(this); // 创建ListView对象 // 创建布局参数对象 LinearLayout.LayoutParams param3 = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); // 设置myListView高亮显示的颜色,默认是黑色,这里设置为白色 myListView.setCacheColorHint(Color.WHITE); poiListLayout.addView(myListView, param3); // 将myListView添加到poiListLayout布局上,用param3布局参数 // 创建适配器 SimpleAdapter adapter = new SimpleAdapter( this, getData(), R.layout.trippoilistrow, new String[] { "title", "tel", "img", }, new int[] {R.id.poiTitle, R.id.poiTel, R.id.poiImg}); myListView.setAdapter(adapter); // 为myListView添加适配器 // setViewBinder()方法设置binder用于绑定数据到视图 参数:用于绑定数据到视图的binder adapter.setViewBinder( new ViewBinder() { @Override public boolean setViewValue(View arg0, Object arg1, String textRepresentation) { // TODO Auto-generated method stub if ((arg0 instanceof ImageView) & (arg1 instanceof Bitmap)) { ImageView imageView = (ImageView) arg0; Bitmap bitmap = (Bitmap) arg1; imageView.setImageBitmap(bitmap); return true; } else { return false; } } }); // myListView列表项点击事件 myListView.setOnItemClickListener( new OnItemClickListener() { // position 指在ListView里的位置 ,id是view的资源id。 @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { // TODO Auto-generated method stub Intent it = new Intent(); // 实例化Intent Bundle poiMsg = new Bundle(); // 实例化Bundle it.setClass(TripPoiList.this, PoiDetail.class); // 设置Class // 将当前ListView被点击的项目的对象放到Bundle中 poiMsg.putSerializable("poiObj", (Serializable) poiLists.get(position)); poiMsg.putString("tripId", tripId); // 将路书id放到Bundle中 poiMsg.putString("tripName", TripName); // 将路数名称放到Bundle中 it.putExtras(poiMsg); // 将该对象作为参数传递给下一个窗体 startActivity(it); // 启动Activity } }); }