Project

General

Profile

« Previous | Next » 

Revision 176308f8

Added by Leszek Koltunski about 4 years ago

Progress with Pretty Patterns.

View differences:

src/main/java/org/distorted/dialog/RubikDialogPatternPagerAdapter.java
70 70
  @NonNull
71 71
  public Object instantiateItem(@NonNull ViewGroup collection, final int position)
72 72
    {
73
    mViews[position] = new RubikDialogPatternView(mAct);
74
    collection.addView(mViews[position]);
75

  
76 73
    String[] categories = createCategories(position);
77
    final LinearLayout section = mViews[position].createSection(mAct, categories);
78

  
79
    mAct.runOnUiThread(new Runnable()
80
        {
81
        @Override
82
        public void run()
83
          {
84
          mViews[position].addSection(section);
85
          }
86
        });
74
    mViews[position] = new RubikDialogPatternView(mAct, categories);
75
    collection.addView(mViews[position]);
87 76

  
88 77
    return mViews[position];
89 78
    }
src/main/java/org/distorted/dialog/RubikDialogPatternView.java
21 21

  
22 22
import android.content.Context;
23 23
import android.support.v4.app.FragmentActivity;
24
import android.util.AttributeSet;
24 25
import android.util.DisplayMetrics;
25 26
import android.view.View;
26 27
import android.widget.Button;
......
37 38

  
38 39
///////////////////////////////////////////////////////////////////////////////////////////////////
39 40

  
40
  public RubikDialogPatternView(Context context)
41
  public RubikDialogPatternView(Context context, AttributeSet attrs, int defStyle)
41 42
    {
42
    super(context);
43
    super(context, attrs, defStyle);
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  public RubikDialogPatternView(Context context, AttributeSet attrs)
49
    {
50
    super(context, attrs);
51
    }
43 52

  
44
    View tab = inflate( context, R.layout.dialog_tab, null);
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  public RubikDialogPatternView(FragmentActivity act, String[] categories)
56
    {
57
    super(act);
58

  
59
    View tab = inflate( act, R.layout.dialog_tab, null);
45 60
    mLayout = tab.findViewById(R.id.tabLayout);
61
    createSection(act,categories);
62

  
46 63
    addView(tab);
47 64
    }
48 65

  
49 66
///////////////////////////////////////////////////////////////////////////////////////////////////
50 67

  
51
  LinearLayout createSection(FragmentActivity act, final String[] categories)
68
  private void createSection(FragmentActivity act, final String[] categories)
52 69
    {
53
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
54
    LinearLayout layout = new LinearLayout(act);
55
    layout.setLayoutParams(params);
56
    layout.setOrientation(LinearLayout.VERTICAL);
57

  
58 70
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
59 71
    final float scale = metrics.density;
60 72
    int len = categories.length;
......
64 76

  
65 77
    for(int i=0; i<len; i++)
66 78
      {
67
      android.util.Log.e("view", "adding button "+i +" to layout!");
68

  
69

  
70 79
      final int fi = i;
71 80
      Button button = new Button(act);
72 81
      button.setLayoutParams(bParams);
......
80 89
          android.util.Log.e("view", "category "+categories[fi]+" clicked");
81 90
          }
82 91
        });
83
      }
84

  
85
    return layout;
86
    }
87 92

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
// needs to run on UI thread
90

  
91
  void addSection(LinearLayout section)
92
    {
93
    android.util.Log.e("view", "adding section to tab!");
94

  
95
    mLayout.addView(section);
93
      mLayout.addView(button);
94
      }
96 95
    }
97 96
  }

Also available in: Unified diff