-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc69bb3
commit 83e7fc6
Showing
4 changed files
with
117 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/natalieperna/cupful/adapters/UnitAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.natalieperna.cupful.adapters; | ||
|
||
import android.content.Context; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.BaseAdapter; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.LayoutRes; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import com.natalieperna.cupful.data.Units; | ||
|
||
import java.util.List; | ||
|
||
import javax.measure.quantity.Quantity; | ||
import javax.measure.unit.Unit; | ||
|
||
public class UnitAdapter extends BaseAdapter { | ||
private final LayoutInflater inflater; | ||
private final List<Unit<? extends Quantity>> units; | ||
|
||
public UnitAdapter(@NonNull Context context, List<Unit<? extends Quantity>> units) { | ||
super(); | ||
this.inflater = LayoutInflater.from(context); | ||
this.units = units; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return units.size(); | ||
} | ||
|
||
@Override | ||
public Object getItem(int position) { | ||
return units.get(position); | ||
} | ||
|
||
@Override | ||
public long getItemId(int position) { | ||
return position; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
return constructView(position, convertView, parent, android.R.layout.simple_spinner_item); | ||
} | ||
|
||
@Override | ||
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||
return constructView(position, convertView, parent, android.R.layout.simple_spinner_dropdown_item); | ||
} | ||
|
||
private View constructView(int position, @Nullable View convertView, @NonNull ViewGroup parent, @LayoutRes int resource) { | ||
TextView view; | ||
if (convertView == null) { | ||
view = (TextView) inflater.inflate(resource, parent, false); | ||
} else { | ||
view = (TextView) convertView; | ||
} | ||
|
||
Unit<? extends Quantity> unit = (Unit<? extends Quantity>) getItem(position); | ||
view.setText(Units.unitToString(unit)); | ||
|
||
return view; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
app/src/main/java/com/natalieperna/cupful/models/DisplayUnit.java
This file was deleted.
Oops, something went wrong.