use of androidx.annotation.NonNull in project Douya by DreaminginCodeZH.
the class ArrayAdapterCompat method createViewFromResource.
/*
* @see ArrayAdapter#createViewFromResource(LayoutInflater, int, View, ViewGroup, int)
*/
@NonNull
private View createViewFromResource(@NonNull LayoutInflater inflater, int position, @Nullable View convertView, @NonNull ViewGroup parent, int resource) {
final View view;
final TextView text;
if (convertView == null) {
view = inflater.inflate(resource, parent, false);
} else {
view = convertView;
}
try {
if (mFieldId == 0) {
// If no custom field is assigned, assume the whole resource is a TextView
text = (TextView) view;
} else {
// Otherwise, find the TextView field within the layout
text = view.findViewById(mFieldId);
if (text == null) {
throw new RuntimeException("Failed to find view with ID " + getContext().getResources().getResourceName(mFieldId) + " in item layout");
}
}
} catch (ClassCastException e) {
Log.e("ArrayAdapter", "You must supply a resource ID for a TextView");
throw new IllegalStateException("ArrayAdapter requires the resource ID to be a TextView", e);
}
final T item = getItem(position);
if (item instanceof CharSequence) {
text.setText((CharSequence) item);
} else {
text.setText(item.toString());
}
return view;
}
use of androidx.annotation.NonNull in project RSAndroidApp by RailwayStations.
the class InboxAdapter method getView.
@Override
@NonNull
public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
var rowView = convertView;
// reuse views
final ItemInboxBinding binding;
if (rowView == null) {
binding = ItemInboxBinding.inflate(context.getLayoutInflater(), parent, false);
rowView = binding.getRoot();
rowView.setTag(binding);
} else {
binding = (ItemInboxBinding) rowView.getTag();
}
// fill data
final var item = publicInboxes.get(position);
binding.txtStationName.setText(item.getTitle());
if (item.getStationId() != null) {
binding.txtStationId.setText(item.getCountryCode().concat(":").concat(item.getStationId()));
} else {
binding.txtStationId.setText(R.string.missing_station);
}
binding.txtCoordinates.setText(String.valueOf(item.getLat()).concat(",").concat(String.valueOf(item.getLon())));
return rowView;
}
use of androidx.annotation.NonNull in project RSAndroidApp by RailwayStations.
the class HighScoreAdapter method getView.
@Override
@NonNull
public View getView(final int position, final View convertView, @NonNull final ViewGroup parent) {
var rowView = convertView;
// reuse views
final ItemHighscoreBinding binding;
if (rowView == null) {
binding = ItemHighscoreBinding.inflate(context.getLayoutInflater(), parent, false);
rowView = binding.getRoot();
rowView.setTag(binding);
} else {
binding = (ItemHighscoreBinding) rowView.getTag();
}
final var item = highScore.get(position);
binding.highscoreName.setText(item.getName());
binding.highscorePhotos.setText(String.valueOf(item.getPhotos()));
binding.highscorePosition.setText(String.valueOf(item.getPosition()).concat("."));
switch(item.getPosition()) {
case 1:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_gold);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
case 2:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_silver);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
case 3:
binding.highscoreAward.setImageResource(R.drawable.ic_crown_bronze);
binding.highscoreAward.setVisibility(View.VISIBLE);
binding.highscorePosition.setVisibility(View.GONE);
break;
default:
binding.highscoreAward.setVisibility(View.GONE);
binding.highscorePosition.setVisibility(View.VISIBLE);
break;
}
if (position % 2 == 1) {
rowView.setBackgroundResource(R.drawable.item_list_backgroundcolor);
} else {
rowView.setBackgroundResource(R.drawable.item_list_backgroundcolor2);
}
return rowView;
}
use of androidx.annotation.NonNull in project RSAndroidApp by RailwayStations.
the class NearbyBahnhofNotificationManager method getStationPendingIntent.
/**
* Build an intent for an action to view a map.
*
* @return the PendingIntent built.
*/
@NonNull
protected PendingIntent getStationPendingIntent() {
// Build an intent for an action to see station details
final var stationIntent = new Intent().setClassName(DB_BAHNHOF_LIVE_PKG, DB_BAHNHOF_LIVE_CLASS);
stationIntent.putExtra(DetailsActivity.EXTRA_STATION, notificationStation);
return pendifyMe(stationIntent, REQUEST_STATION);
}
use of androidx.annotation.NonNull in project Paper by pilgr.
the class MultiThreadTest method startWritingLargeDataSetInSeparateThread.
@NonNull
private CountDownLatch startWritingLargeDataSetInSeparateThread(@SuppressWarnings("SameParameterValue") final String key) throws InterruptedException {
final CountDownLatch writeStartLatch = new CountDownLatch(1);
final CountDownLatch writeFinishLatch = new CountDownLatch(1);
new Thread() {
final List<Person> dataset = TestDataGenerator.genPersonList(10000);
@Override
public void run() {
Log.d(TAG, "write '" + key + "': start");
writeStartLatch.countDown();
Paper.book().write(key, dataset);
Log.d(TAG, "write '" + key + "': finish");
writeFinishLatch.countDown();
}
}.start();
writeStartLatch.await(5, TimeUnit.SECONDS);
// A small delay is required to let writer thread start writing data and acquire a lock
Thread.sleep(100);
return writeFinishLatch;
}
Aggregations