Java Code Examples for android.support.v7.widget.RecyclerView#setBackgroundResource()

The following examples show how to use android.support.v7.widget.RecyclerView#setBackgroundResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorActivity.java    From GreatFit with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView root = new RecyclerView(this);
    //Add header to a list of settings
    List<BaseSetting> settings = new ArrayList<>();
    settings.add(new HeaderSetting(getString(R.string.set_color)));
    //Setup items for each day
    String[] colors = getResources().getStringArray(R.array.colors);
    String[] colorCodes = getResources().getStringArray(R.array.color_codes);
    final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE);
    int x = 0;
    int current = sharedPreferences.getInt("color", -1);
    for(String color : colors){
        //Each item needs a Setting
        final int finalX = x;
        settings.add(new IconSetting( (current==x)?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), color, null, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sharedPreferences.edit().putInt("color", finalX).apply();
                ColorActivity.this.finish();
            }
        }, Color.parseColor(colorCodes[x])));
        x++;
    }
    //Setup layout
    root.setBackgroundResource(R.drawable.settings_background);
    root.setLayoutManager(new LinearLayoutManager(this));
    root.setAdapter(new Adapter(this, settings));
    root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large));
    root.setClipToPadding(false);
    setContentView(root);
}
 
Example 2
Source File: FontActivity.java    From GreatFit with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView root = new RecyclerView(this);
    //Add header to a list of settings
    List<BaseSetting> settings = new ArrayList<>();
    settings.add(new HeaderSetting(getString(R.string.set_font)));
    //Setup items for each day
    String[] fonts = ResourceManager.getNames(ResourceManager.Font.class);//getResources().getStringArray(R.array.colors);
    final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE);
    int x = 0;
    int current = sharedPreferences.getInt("font", 0);
    for(String font : fonts){
        //Each item needs a Setting
        final int finalX = x;
        settings.add(new IconSetting( (current==x)?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), font, null, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sharedPreferences.edit().putInt("font", finalX).apply();
                FontActivity.this.finish();
            }
        }, x));
        x++;
    }
    //Setup layout
    root.setBackgroundResource(R.drawable.settings_background);
    root.setLayoutManager(new LinearLayoutManager(this));
    root.setAdapter(new Adapter(this, settings));
    root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large));
    root.setClipToPadding(false);
    setContentView(root);
}
 
Example 3
Source File: LinkTypeFragment.java    From Shield with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    recyclerView = new RecyclerView(getContext());
    recyclerView.setBackgroundResource(R.color.gray_light_background);
    LinearLayout rootView = new LinearLayout(getContext());
    rootView.addView(recyclerView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    return rootView;
}
 
Example 4
Source File: MixFragment.java    From Shield with MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    recyclerView = new RecyclerView(getContext());
    recyclerView.setBackgroundResource(R.color.gray_light_background);
    LinearLayout rootView = new LinearLayout(getContext());
    rootView.addView(recyclerView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    return rootView;
}
 
Example 5
Source File: WidgetsActivity.java    From GreatFit with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView root = new RecyclerView(this);
    //Add header to a list of settings
    List<BaseSetting> settings = new ArrayList<>();
    settings.add(new HeaderSetting(getString(R.string.set_elements)));
    //Setup items for each day
    String[] elements = getResources().getStringArray(R.array.supported_widgets);
    final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE);

    // Get Widgets
    String widgetsAsText = sharedPreferences.getString("widgets", null);
    String text = widgetsAsText.replaceAll("(\\[|\\]| )",""); // Replace "[", "]" and "spaces"
    List <String> widgets_list = Arrays.asList(text.split(","));

    int current = sharedPreferences.getInt("temp_widget", 0);
    String currentAsText = widgets_list.get(current);
    for(String element : elements){
        // Go to next if already a widget
        if(widgets_list.indexOf(element)>=0 && !element.equals(currentAsText) && !element.equals("none")){
            continue;
        }
        // Create the setting
        widgets_list.set(current,element);
        final String finalWidgets = widgets_list.toString();
        settings.add(new IconSetting( (element.equals(currentAsText))?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), prepareTitle(element), prepareSubtitle(element), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sharedPreferences.edit().putString("widgets", finalWidgets).apply();
                WidgetsActivity.this.finish();
            }
        }, null));
    }
    //Setup layout
    root.setBackgroundResource(R.drawable.settings_background);
    root.setLayoutManager(new LinearLayoutManager(this));
    root.setAdapter(new Adapter(this, settings));
    root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large));
    root.setClipToPadding(false);
    setContentView(root);
}
 
Example 6
Source File: ProgressWidgetsActivity.java    From GreatFit with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RecyclerView root = new RecyclerView(this);
    //Add header to a list of settings
    List<BaseSetting> settings = new ArrayList<>();
    settings.add(new HeaderSetting(getString(R.string.set_progress_bar)));

    //Setup items for each day
    String[] elements = getResources().getStringArray(R.array.supported_progress_elements);
    final SharedPreferences sharedPreferences = getSharedPreferences(getPackageName()+"_settings", Context.MODE_PRIVATE);

    // Get Widgets
    String widgetsAsText = sharedPreferences.getString("progress_bars", null);
    String text = widgetsAsText.replaceAll("(\\[|\\]| )",""); // Replace "[", "]" and "spaces"
    List <String> widgets_list = Arrays.asList(text.split(","));

    int current = sharedPreferences.getInt("temp_progress_bars", 0);
    String currentAsText = widgets_list.get(current);
    for(String element : elements){
        // Go to next if already a widget
        if(widgets_list.indexOf(element)>=0 && !element.equals(currentAsText) && !element.equals("none")){
            continue;
        }
        // Create the setting
        widgets_list.set(current,element);
        final String finalWidgets = widgets_list.toString();
        settings.add(new IconSetting( (element.equals(currentAsText))?getDrawable(R.drawable.check):getDrawable(R.drawable.circle_icon), prepareTitle(element), prepareSubtitle(element), new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sharedPreferences.edit().putString("progress_bars", finalWidgets).apply();
                ProgressWidgetsActivity.this.finish();
            }
        }, null));
    }
    //Setup layout
    root.setBackgroundResource(R.drawable.settings_background);
    root.setLayoutManager(new LinearLayoutManager(this));
    root.setAdapter(new Adapter(this, settings));
    root.setPadding((int) getResources().getDimension(R.dimen.padding_round_small), 0, (int) getResources().getDimension(R.dimen.padding_round_small), (int) getResources().getDimension(R.dimen.padding_round_large));
    root.setClipToPadding(false);
    setContentView(root);
}