List of usage examples for android.support.v4.widget CursorAdapter CursorAdapter
public CursorAdapter(Context context, Cursor c, int flags)
From source file:individual.aurthconan.automateandroid.SpellBookActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Cursor cursor = getContentResolver().query(SpellLibrary.SPELL_LIST_URI, new String[] { SpellLibrary.ID_COLUMN, SpellLibrary.ENABLE_COLUMN, SpellLibrary.NAME_COLUMN }, null, null, null);/*from w w w.ja v a 2 s . com*/ CursorAdapter adapter = new CursorAdapter(this.getApplicationContext(), cursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public void bindView(View arg0, Context arg1, Cursor cursor) { CheckBox box = (CheckBox) arg0.findViewById(R.id.is_enabled); if (box != null) { box.setChecked(cursor.getInt(1) == 1); } TextView view = (TextView) arg0.findViewById(R.id.script_name); if (view != null) { view.setText(cursor.getString(2)); } } @Override public View newView(Context arg0, Cursor arg1, ViewGroup arg2) { View view = getLayoutInflater().inflate(R.layout.spell_list_item, null); return view; } }; setContentView(R.layout.spell_book_layout); ListView list = (ListView) findViewById(R.id.spell_list); list.setAdapter(adapter); }
From source file:de.fahrgemeinschaft.util.SpinningZebraListFragment.java
@Override public void onViewCreated(View layout, Bundle state) { super.onViewCreated(layout, state); layout.setOnClickListener(null);//from www. j a va2 s .c o m setListAdapter(new CursorAdapter(getActivity(), null, 0) { @Override public int getCount() { if (spinningEnabled) return super.getCount() + 1; else return super.getCount(); } @Override public int getViewTypeCount() { if (spinningEnabled) return 2; else return 1; } @Override public int getItemViewType(int position) { if (!spinningEnabled || position < getCount() - 1) return 0; else return 1; } @Override public View getView(int position, View v, ViewGroup parent) { if (!spinningEnabled || position < getCount() - 1) v = super.getView(position, v, parent); else { if (v == null) { v = getLayoutInflater(null).inflate(R.layout.view_spinning_wheel, parent, false); } ((TextView) v.findViewById(R.id.small)).setText(smallText); ((TextView) v.findViewById(R.id.large)).setText(largeText); if (spinning && onScreen) { v.findViewById(R.id.progress).startAnimation(rotate); } else if (onScreen) { v.findViewById(R.id.progress).clearAnimation(); } } if (position % 2 == 0) { v.setBackgroundColor(getResources().getColor(R.color.medium_green)); } else { v.setBackgroundColor(getResources().getColor(R.color.almost_medium_green)); } return v; } @Override public View newView(Context ctx, Cursor rides, ViewGroup parent) { return getLayoutInflater(null).inflate(R.layout.view_ride_list_entry, parent, false); } @Override public void bindView(View view, Context ctx, Cursor ride) { if (ride.getPosition() == ride.getCount()) return; bindListItemView(view, ride); } }); registerForContextMenu(getListView()); rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(600); rotate.setRepeatMode(Animation.RESTART); rotate.setRepeatCount(Animation.INFINITE); stopSpinning(getString(R.string.search_continue)); if (state != null) { code = state.getInt(ID); setSpinningEnabled(state.getBoolean(SPIN)); uri = (Uri) (state.getParcelable(URI)); getActivity().getSupportLoaderManager().initLoader(code, state, this); } else if (uri != null) { getActivity().getSupportLoaderManager().restartLoader(code, state, this); } getListView().requestFocus(); }
From source file:de.fahrgemeinschaft.PlaceListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); search_field = (EditText) view.findViewById(R.id.autocomplete_text); wheel = (ProgressBar) view.findViewById(R.id.busy_search); toggle = (ImageButton) view.findViewById(R.id.toggle); search_field.addTextChangedListener(this); toggle.setOnClickListener(new OnClickListener() { @Override/* w w w .j a v a 2s . co m*/ public void onClick(View arg0) { toggleSearchField(); } }); adapter = new CursorAdapter(getActivity(), null, false) { @Override public View newView(Context arg0, Cursor arg1, ViewGroup p) { return getActivity().getLayoutInflater().inflate(R.layout.view_place_list_entry, p, false); } @Override public void bindView(View view, Context arg1, Cursor place) { ((TextView) view.findViewById(R.id.place_name)).setText(place.getString(2)); ((TextView) view.findViewById(R.id.place_address)).setText(place.getString(3)); } }; setListAdapter(adapter); uri = getActivity().getIntent().getData(); getActivity().getSupportLoaderManager().initLoader(LOCAL, null, this); }
From source file:com.readystatesoftware.chuck.internal.ui.TransactionAdapter.java
TransactionAdapter(Context context, OnListFragmentInteractionListener listener) { this.listener = listener; this.context = context; colorDefault = ContextCompat.getColor(context, R.color.chuck_status_default); colorRequested = ContextCompat.getColor(context, R.color.chuck_status_requested); colorError = ContextCompat.getColor(context, R.color.chuck_status_error); color500 = ContextCompat.getColor(context, R.color.chuck_status_500); color400 = ContextCompat.getColor(context, R.color.chuck_status_400); color300 = ContextCompat.getColor(context, R.color.chuck_status_300); cursorAdapter = new CursorAdapter(TransactionAdapter.this.context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override/*from ww w .j av a 2 s. c o m*/ public View newView(Context context, Cursor cursor, ViewGroup parent) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.chuck_list_item_transaction, parent, false); ViewHolder holder = new ViewHolder(itemView); itemView.setTag(holder); return itemView; } @Override public void bindView(View view, final Context context, Cursor cursor) { final HttpTransaction transaction = LocalCupboard.getInstance().withCursor(cursor) .get(HttpTransaction.class); final ViewHolder holder = (ViewHolder) view.getTag(); holder.path.setText(transaction.getMethod() + " " + transaction.getPath()); holder.host.setText(transaction.getHost()); holder.start.setText(transaction.getRequestStartTimeString()); holder.ssl.setVisibility(transaction.isSsl() ? View.VISIBLE : View.GONE); if (transaction.getStatus() == HttpTransaction.Status.Complete) { holder.code.setText(String.valueOf(transaction.getResponseCode())); holder.duration.setText(transaction.getDurationString()); holder.size.setText(transaction.getTotalSizeString()); } else { holder.code.setText(null); holder.duration.setText(null); holder.size.setText(null); } if (transaction.getStatus() == HttpTransaction.Status.Failed) { holder.code.setText("!!!"); } setStatusColor(holder, transaction); holder.transaction = transaction; holder.view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (null != TransactionAdapter.this.listener) { TransactionAdapter.this.listener.onListFragmentInteraction(holder.transaction); } } }); } private void setStatusColor(ViewHolder holder, HttpTransaction transaction) { int color; if (transaction.getStatus() == HttpTransaction.Status.Failed) { color = colorError; } else if (transaction.getStatus() == HttpTransaction.Status.Requested) { color = colorRequested; } else if (transaction.getResponseCode() >= 500) { color = color500; } else if (transaction.getResponseCode() >= 400) { color = color400; } else if (transaction.getResponseCode() >= 300) { color = color300; } else { color = colorDefault; } holder.code.setTextColor(color); holder.path.setTextColor(color); } }; }
From source file:eu.chainfire.geolog.ui.ProfilesFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { setEmptyText(getResources().getString(R.string.profiles_empty)); setListShown(false);//from w w w . j ava2s. c o m getLoaderManager().initLoader(LIST_LOADER, null, this); adapter = new CursorAdapter(getActivity(), null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { private LayoutInflater inflater = null; private String formatName = null; private ViewHolder holderFromView(View v) { if ((v.getTag() != null) && (v.getTag() instanceof ViewHolder)) { return (ViewHolder) v.getTag(); } else if ((v.getParent() != null) && (v.getParent() instanceof View)) { return holderFromView((View) v.getParent()); } return null; } private OnClickListener onTimerClick = new OnClickListener() { @Override public void onClick(View v) { //ViewHolder holder = holderFromView(v); //TODO: handle } }; private OnClickListener onEditClick = new OnClickListener() { @Override public void onClick(View v) { ViewHolder holder = holderFromView(v); ProfileActivity.launchActivity(getActivity(), holder.profile.getId()); } }; private OnClickListener onDeleteClick = new OnClickListener() { @Override public void onClick(View v) { ViewHolder holder = holderFromView(v); final long id = holder.profile.getId(); (new AlertDialog.Builder(getActivity())).setTitle(R.string.generic_delete) .setMessage(Html.fromHtml(String.format(Locale.ENGLISH, getString(R.string.profile_delete_confirm), holder.profile.getName()))) .setPositiveButton(getString(R.string.generic_delete), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Database.Profile.delete(Database.Helper.getInstance(getActivity()), id); } }) .setNegativeButton(getString(R.string.generic_cancel), null).show(); } }; @Override public View newView(Context context, Cursor cursor, ViewGroup root) { if (inflater == null) inflater = LayoutInflater.from(context); formatName = context.getString(R.string.row_profiles_name); return inflater.inflate(R.layout.row_profiles, null); } @Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); if (holder == null) { holder = new ViewHolder(); holder.container = view.findViewById(R.id.container); holder.name = (TextView) view.findViewById(R.id.name); holder.timer = (ImageView) view.findViewById(R.id.timer); holder.timer.setOnClickListener(onTimerClick); holder.edit = (ImageView) view.findViewById(R.id.edit); holder.edit.setOnClickListener(onEditClick); holder.delete = (ImageView) view.findViewById(R.id.delete); holder.delete.setOnClickListener(onDeleteClick); holder.profile = new Database.Profile(); view.setTag(holder); } holder.profile.loadFromCursor(cursor); boolean selected = (holder.profile.getId() == currentProfileId); boolean readonly = (holder.profile.getType() == Database.Profile.Type.OFF); //holder.timer.setVisibility((selected || readonly) ? View.GONE : View.VISIBLE); holder.timer.setVisibility(View.GONE); //TODO disabled for now holder.edit.setVisibility(readonly ? View.GONE : View.VISIBLE); holder.delete.setVisibility(readonly ? View.GONE : View.VISIBLE); if (selected) { holder.container.setBackgroundColor(0xFFa8dff4); } else { holder.container.setBackgroundDrawable(null); } holder.name.setText( Html.fromHtml(String.format(Locale.ENGLISH, formatName, holder.profile.getName()))); } }; setListAdapter(adapter); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { currentProfileId = id; PreferenceManager.getDefaultSharedPreferences(getActivity()).edit() .putLong(SettingsFragment.PREF_CURRENT_PROFILE, id).commit(); Database.Profile profile = Database.Profile.getById(Database.Helper.getInstance(getActivity()), id, null); if (profile.getType() != Database.Profile.Type.OFF) BackgroundService.startService(getActivity()); getListView().invalidateViews(); } }); }
From source file:cm.aptoide.ptdev.ScheduledDownloadsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Aptoide.getThemePicker().setAptoideTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.page_sch_downloads); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle(getString(R.string.setting_schdwntitle)); lv = (ListView) findViewById(android.R.id.list); lv.setDivider(null);//from ww w .ja va2s .c o m db = new Database(Aptoide.getDb()); bindService(new Intent(this, DownloadService.class), conn, Context.BIND_AUTO_CREATE); adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap .get(c.getLong(c.getColumnIndex("_id"))); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); if (getIntent().hasExtra("downloadAll")) { ScheduledDownloadsDialog pd = new ScheduledDownloadsDialog(); pd.show(getSupportFragmentManager(), "installAllScheduled"); } lv.setAdapter(adapter); }
From source file:cm.aptoide.pt.ScheduledDownloads.java
private void continueLoading() { lv = (ListView) findViewById(android.R.id.list); db = Database.getInstance();/*w ww.j ava2 s . com*/ adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap.get(c.getString(0)); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText("" + scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; lv.setAdapter(adapter); getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); IntentFilter filter = new IntentFilter("pt.caixamagica.aptoide.REDRAW"); registerReceiver(receiver, filter); Button installButton = (Button) findViewById(R.id.sch_down); // installButton.setText(getText(R.string.schDown_installselected)); installButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (isAllChecked()) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { if (scheduledDownloadsHashMap.get(scheduledDownload).checked) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } } } else { Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.schDown_nodownloadselect, Toast.LENGTH_SHORT); toast.show(); } } }); if (getIntent().hasExtra("downloadAll")) { Builder dialogBuilder = new AlertDialog.Builder(this); final AlertDialog scheduleDownloadDialog = dialogBuilder.create(); scheduleDownloadDialog.setTitle(getText(R.string.schDwnBtn)); scheduleDownloadDialog.setIcon(android.R.drawable.ic_dialog_alert); scheduleDownloadDialog.setCancelable(false); scheduleDownloadDialog.setMessage(getText(R.string.schDown_install)); scheduleDownloadDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { for (String scheduledDownload : scheduledDownloadsHashMap.keySet()) { ScheduledDownload schDown = scheduledDownloadsHashMap.get(scheduledDownload); ViewApk apk = new ViewApk(); apk.setApkid(schDown.getApkid()); apk.setName(schDown.getName()); apk.setVercode(schDown.getVercode()); apk.setIconPath(schDown.getIconPath()); apk.setVername(schDown.getVername()); apk.setRepoName(schDown.getRepoName()); serviceDownloadManager .startDownloadWithWebservice(serviceDownloadManager.getDownload(apk), apk); Toast toast = Toast.makeText(ScheduledDownloads.this, R.string.starting_download, Toast.LENGTH_SHORT); toast.show(); } finish(); } }); scheduleDownloadDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); scheduleDownloadDialog.show(); } }
From source file:eu.chainfire.geolog.ui.LogsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { LocalBroadcastManager.getInstance(getActivity()).registerReceiver(preferenceReceiver, new IntentFilter(SettingsFragment.NOTIFY_BROADCAST)); getListView().setSelector(android.R.color.transparent); setEmptyText(getResources().getString(R.string.logs_empty)); setListShown(false);//from www . j ava 2 s . c o m getLoaderManager().initLoader(LIST_LOADER, null, this); adapter = new CursorAdapter(getActivity(), null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { private LayoutInflater inflater = null; private Database.Location location = null; private String formatTime = null; private String formatActivity = null; private String formatLocation = null; private String formatBattery = null; private boolean lastMetric = true; private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", Locale.ENGLISH); @Override public View newView(Context context, Cursor cursor, ViewGroup root) { if (inflater == null) inflater = LayoutInflater.from(context); return inflater.inflate(R.layout.row_logs, null); } @SuppressWarnings("deprecation") @Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder holder = (ViewHolder) view.getTag(); if (holder == null) { holder = new ViewHolder(); holder.container = view.findViewById(R.id.container); holder.time = (TextView) view.findViewById(R.id.time); holder.activity = (TextView) view.findViewById(R.id.activity); holder.location = (TextView) view.findViewById(R.id.location); view.setTag(holder); } if (location == null) location = new Database.Location(); location.loadFromCursor(cursor); if (formatTime == null) formatTime = context.getString(R.string.row_logs_time); if (formatActivity == null) formatActivity = context.getString(R.string.row_logs_activity); if (formatBattery == null) formatBattery = context.getString(R.string.row_logs_battery); if ((formatLocation == null) || (metric != lastMetric)) { if (metric) { formatLocation = context.getString(R.string.row_logs_location_metric); } else { formatLocation = context.getString(R.string.row_logs_location_imperial); } lastMetric = metric; } float accuracy = location.getAccuracyDistance(); if (!metric) accuracy *= SettingsFragment.METER_FEET_RATIO; if (location.isSegmentStart()) { holder.container.setBackgroundColor(0xFFa8dff4); } else { holder.container.setBackgroundDrawable(null); } holder.time.setText(Html.fromHtml(String.format(Locale.ENGLISH, formatTime, simpleDateFormat.format(new Date(location.getTime()))))); holder.activity.setText(Html.fromHtml(String.format(Locale.ENGLISH, formatActivity, Database.activityToString(location.getActivity()), location.getConfidence()) + " " + String.format(Locale.ENGLISH, formatBattery, (location.getBattery() > 100) ? location.getBattery() - 100 : location.getBattery(), (location.getBattery() > 100) ? "+" : ""))); holder.location.setText(Html.fromHtml(String.format(Locale.ENGLISH, formatLocation, location.getLatitude(), location.getLongitude(), accuracy))); } }; setListAdapter(adapter); }
From source file:com.aptoide.amethyst.ui.ScheduledDownloadsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { //Aptoide.getThemePicker().setAptoideTheme(this); super.onCreate(savedInstanceState); setContentView(getContentView());// w w w . j a va 2 s . c o m bindViews(); mToolbar.setCollapsible(false); setSupportActionBar(mToolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle(getString(R.string.setting_schdwntitle)); lv = (ListView) findViewById(android.R.id.list); lv.setDivider(null); db = new AptoideDatabase(Aptoide.getDb()); bindService(new Intent(this, DownloadService.class), conn, Context.BIND_AUTO_CREATE); adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { ScheduledDownload scheduledDownload = scheduledDownloadsMap.get(c.getLong(c.getColumnIndex("_id"))); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; if (convertView.getTag() == null) { textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVersion_name()); Glide.with(ScheduledDownloadsActivity.this).load(scheduledDownload.getIcon()).into(imageViewIcon); } }; getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); if (getIntent().hasExtra(ARG_DOWNLOAD_ALL)) { ScheduledDownloadsDialog pd = new ScheduledDownloadsDialog(); pd.show(getSupportFragmentManager(), "installAllScheduled"); } lv.setAdapter(adapter); }
From source file:osu.appclub.corvallisbus.MainActivity.java
@Override public void searchComplete(Cursor cursor) { Log.d("osu.appclub", "Found " + cursor.getCount() + " results"); if (cursor.getCount() == 0) { MatrixCursor placeholder = new MatrixCursor(new String[] { "_id" }); placeholder.addRow(new Object[] { 0 }); searchView.setSuggestionsAdapter(new CursorAdapter(this, placeholder, false) { @Override/* w w w . j a va 2 s .c o m*/ public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { TextView text = (TextView) view.findViewById(android.R.id.text1); text.setText(R.string.search_no_results); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // no-op } }); } }); } else { searchView.setSuggestionsAdapter(new CursorAdapter(this, cursor, false) { @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(android.R.layout.simple_list_item_2, parent, false); return view; } @SuppressLint("DefaultLocale") @Override public void bindView(View view, Context context, Cursor cursor) { final int stopID = cursor.getInt(0); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchView.clearFocus(); enqueueBusStop(stopID); } }); TextView textStopName = (TextView) view.findViewById(android.R.id.text1); textStopName.setText(cursor.getString(1)); TextView textDistance = (TextView) view.findViewById(android.R.id.text2); if (cursor.getType(2) == Cursor.FIELD_TYPE_NULL) { textDistance.setText(""); } else { textDistance.setText(String.format("%.1f miles", cursor.getDouble(2))); } } }); } }