I have a list of fonts in my dropdown box and installation process would be by selecting one. I need some guidance in code how would I install this ? I have placed the ' ttf ' font files in assets/font directory. This is what I have so far.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAssetFiles("font");
}
private boolean listAssetFiles(String path)
{
String [] list;
final List<String> fontList = new ArrayList<String>();
try {
list = getAssets().list(path);
if (list.length > 0) {
for (String file : list) {
if (!listAssetFiles(path + "/" + file))
return false;
else {
fontList.add(file);
dropdown = findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, fontList);
dropdown.setAdapter(adapter);
}
dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// Get select item
int sid = dropdown.getSelectedItemPosition();
switch (position) {
case 0:
Toast.makeText(getBaseContext(), "You have selected Xacto Blade" , Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getBaseContext(), "You have selected Xanadu ", Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getBaseContext(), "You have selected Xcelsion ", Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(getBaseContext(), "You have selected Xcelsion Italic ", Toast.LENGTH_SHORT).show();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
}
} catch (IOException e) {
return false;
}
return true;
}