Search in sources :

Example 1 with Example

use of org.rajawali3d.examples.data.Example in project Rajawali by Rajawali.

the class ExamplesActivity method processExtras.

private void processExtras(Bundle extras) {
    Example example = extras.getParcelable(EXTRA_EXAMPLE);
    if (example == null) {
        throw new NullPointerException();
    }
    Class aClass = example.getType();
    try {
        Bundle bundle = new Bundle();
        bundle.putString(AExampleFragment.BUNDLE_EXAMPLE_URL, example.getPath());
        Fragment fragment = (Fragment) aClass.newInstance();
        fragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, fragment, aClass.getName()).commit();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : Bundle(android.os.Bundle) Example(org.rajawali3d.examples.data.Example) AExampleFragment(org.rajawali3d.examples.examples.AExampleFragment) Fragment(androidx.fragment.app.Fragment)

Example 2 with Example

use of org.rajawali3d.examples.data.Example in project Rajawali by Rajawali.

the class CategoryAdapter method filter.

public void filter(@NonNull Context context, @NonNull String query) {
    String queryLC = query.trim().toLowerCase(Locale.ENGLISH);
    List<Category> categories = new LinkedList<>();
    if (queryLC.length() == 0) {
        categories.addAll(categoriesOriginal);
    } else {
        for (Category category : categoriesOriginal) {
            List<Example> filtered = new LinkedList<>();
            Example[] examples = category.getExamples();
            // If the category matches the query, add all examples then move to the next item
            String categoryName = context.getString(category.getName()).toLowerCase(Locale.ENGLISH);
            if (categoryName.contains(queryLC)) {
                categories.add(category);
                continue;
            }
            // Iterate the examples adding matches to the filtered list
            for (Example example : examples) {
                String exampleName = context.getString(example.getName()).toLowerCase(Locale.ENGLISH);
                if (exampleName.contains(queryLC)) {
                    filtered.add(example);
                }
            }
            // If the category has any matching examples, keep it and add the matches
            final int size = filtered.size();
            if (size > 0) {
                Example[] filteredExamples = filtered.toArray(new Example[size]);
                Category filteredCategory = new Category(category.getName(), filteredExamples);
                categories.add(filteredCategory);
            }
        }
    }
    setReferencesFromList(categories);
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example) LinkedList(java.util.LinkedList)

Example 3 with Example

use of org.rajawali3d.examples.data.Example in project Rajawali by Rajawali.

the class CategoryAdapter method filterDone.

public boolean filterDone(@NonNull Context context) {
    if (categoriesDisplayed.size() == 1) {
        Category category = categoriesDisplayed.get(0);
        Example[] examples = category.getExamples();
        if (examples.length == 1) {
            Example example = examples[0];
            onExampleSelected(context, example);
            return true;
        }
    }
    return false;
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example)

Example 4 with Example

use of org.rajawali3d.examples.data.Example in project Rajawali by Rajawali.

the class CategoryAdapter method onReferenceClicked.

@Override
public void onReferenceClicked(View view, IndexReference reference) {
    Class type = reference.getType();
    if (Example.class.equals(type)) {
        Example example = (Example) reference.get();
        Context context = view.getContext();
        onExampleSelected(context, example);
    } else {
        throw new IllegalStateException("Unhandled reference for " + type);
    }
}
Also used : Context(android.content.Context) Example(org.rajawali3d.examples.data.Example)

Example 5 with Example

use of org.rajawali3d.examples.data.Example in project Rajawali by Rajawali.

the class CategoryAdapter method setReferencesFromList.

void setReferencesFromList(List<Category> categories) {
    final List<NamedIndexReference<INamed>> indexReferences;
    indexReferences = new LinkedList<>();
    for (Category category : categories) {
        indexReferences.add(new CategoryReference(category));
        Example[] examples = category.getExamples();
        for (Example example : examples) {
            indexReferences.add(new ExampleReference(example));
        }
    }
    categoriesDisplayed = categories;
    setReferences(indexReferences);
}
Also used : Category(org.rajawali3d.examples.data.Category) Example(org.rajawali3d.examples.data.Example)

Aggregations

Example (org.rajawali3d.examples.data.Example)5 Category (org.rajawali3d.examples.data.Category)3 Context (android.content.Context)1 Bundle (android.os.Bundle)1 Fragment (androidx.fragment.app.Fragment)1 LinkedList (java.util.LinkedList)1 AExampleFragment (org.rajawali3d.examples.examples.AExampleFragment)1