Project

General

Profile

« Previous | Next » 

Revision cf6fb87f

Added by Leszek Koltunski over 6 years ago

Some progress with Effects3D app

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
395 395
    setContentView(view);
396 396

  
397 397
    mViewPager = findViewById(R.id.effects3d_viewpager);
398
    mViewPager.setOffscreenPageLimit(2);
398 399
    mPager = new Effects3DTabViewPager(this, getFragmentManager() );
399 400
    mViewPager.setAdapter(mPager);
400 401
    TabLayout tabLayout = findViewById(R.id.effects3d_sliding_tabs);
src/main/java/org/distorted/examples/effects3d/Effects3DTab.java
35 35
import org.distorted.library.main.DistortedEffects;
36 36

  
37 37
import java.util.ArrayList;
38
import java.lang.ref.WeakReference;
39 38

  
40 39
///////////////////////////////////////////////////////////////////////////////////////////////////
41 40

  
42 41
public class Effects3DTab extends Fragment implements AdapterView.OnItemSelectedListener
43 42
  {
44
  private WeakReference<Effects3DActivity> mAct;
45 43
  private EffectType mType;
46 44
  private ArrayList<Effects3DEffect> mList;
47 45
  private int mEffectAdd;
......
56 54
    {
57 55
    mList = new ArrayList<>();
58 56
    mEffectAdd = 0;
57

  
58
    android.util.Log.e("tab", "TAB CONSTRUCTOR");
59 59
    }
60 60

  
61 61
///////////////////////////////////////////////////////////////////////////////////////////////////
62 62

  
63
  void setParams(EffectType type, WeakReference<Effects3DActivity> act, int tab, int layout, int spinner)
63
  @Override
64
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
64 65
    {
65
    mTab     = tab;
66
    mLayout  = layout;
67
    mSpinner = spinner;
68
    mType    = type;
69
    mAct     = act;
70
    mEffects = act.get().getEffects();
66
    Bundle args = getArguments();
67

  
68
    int position = args.getInt("position");
69

  
70
    switch(position)
71
      {
72
      case 0: mTab     = R.layout.effects3dtab1;
73
              mLayout  = R.id.effects3dlayout1;
74
              mSpinner = R.id.effects3dspinner1;
75
              mType    = EffectType.VERTEX;
76
              break;
77
      case 1: mTab     = R.layout.effects3dtab2;
78
              mLayout  = R.id.effects3dlayout2;
79
              mSpinner = R.id.effects3dspinner2;
80
              mType    = EffectType.FRAGMENT;
81
              break;
82
      case 2: mTab     = R.layout.effects3dtab3;
83
              mLayout  = R.id.effects3dlayout3;
84
              mSpinner = R.id.effects3dspinner3;
85
              mType    = EffectType.POSTPROCESS;
86
              break;
87
      }
71 88

  
72
    android.util.Log.e("tab", "setparams: "+type.name() );
89
    Effects3DActivity act = (Effects3DActivity)getActivity();
90
    mEffects = act.getEffects();
73 91

  
74 92
    createEffectNames(mType);
75 93
    mEffectStrings = new String[mEffectNames.length];
......
77 95
    for (int i = 0; i < mEffectNames.length; i++)
78 96
      {
79 97
      mEffectStrings[i] = mEffectNames[i].name();
80

  
81
      android.util.Log.d("tab", "  effect: "+mEffectStrings[i]);
82 98
      }
83
    }
84 99

  
85
///////////////////////////////////////////////////////////////////////////////////////////////////
100
    android.util.Log.e("tab", "onCreateView, this is fragment position "+position+" type="+mType.name());
86 101

  
87
  @Override
88
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
89
    {
90 102
    View rootView = inflater.inflate( mTab, container, false);
91 103
    return rootView;
92 104
    }
......
99 111
    super.onStart();
100 112

  
101 113
    android.util.Log.e("tab", "onStart, type="+mType.name());
114
    }
115

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
102 117

  
103
    Effects3DActivity act = mAct.get();
118
  @Override
119
  public void onResume()
120
    {
121
    super.onResume();
122

  
123
    android.util.Log.e("tab", "onResume, type="+mType.name());
124

  
125
    Effects3DActivity act = (Effects3DActivity)getActivity();
104 126

  
105 127
    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>( act, android.R.layout.simple_spinner_item, mEffectStrings);
106 128
    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
107 129

  
108 130
    Spinner effectSpinner = act.findViewById(mSpinner);
131

  
132
    if( mSpinner == R.id.effects3dspinner1 ) android.util.Log.e("tab", "onStart, mSpinner correct");
133
    if( effectSpinner==null ) android.util.Log.e("tab", "onStart, effectSpinner null");
134

  
109 135
    effectSpinner.setOnItemSelectedListener(this);
110 136
    effectSpinner.setAdapter(adapterEffect);
111 137

  
......
132 158

  
133 159
  private void resetData()
134 160
    {
135
    Effects3DSurfaceView view = mAct.get().findViewById(R.id.effects3dSurfaceView);
161
    Effects3DActivity act = (Effects3DActivity)getActivity();
162
    Effects3DSurfaceView view = act.findViewById(R.id.effects3dSurfaceView);
136 163
    view.getRenderer().showRegionAndCenter(false,false);
137 164
    }
138 165

  
......
140 167

  
141 168
  void newEffect()
142 169
    {
143
    Effects3DEffect eff = new Effects3DEffect(mEffectNames[mEffectAdd], mAct.get() );
170
    Effects3DActivity act = (Effects3DActivity)getActivity();
171
    Effects3DEffect eff = new Effects3DEffect(mEffectNames[mEffectAdd], act );
144 172
    mList.add(eff);
145 173

  
146
    LinearLayout layout = mAct.get().findViewById(mLayout);
174
    LinearLayout layout = act.findViewById(mLayout);
147 175
    View view = eff.createView();
148 176
    layout.addView(view);
149 177

  
......
161 189

  
162 190
    eff.apply(mEffects);
163 191

  
164
    Effects3DActivity act = mAct.get();
165 192
    boolean region = act.getShowRegion();
166 193
    boolean center = act.getShowCenter();
167 194

  
......
196 223

  
197 224
  void removeAll()
198 225
    {
199
    Effects3DActivity act = mAct.get();
226
    Effects3DActivity act = (Effects3DActivity)getActivity();
200 227

  
201 228
    mList.clear();
202 229
    LinearLayout layout = act.findViewById(mLayout);
......
215 242
      {
216 243
      if( effect.thisView(v) )
217 244
        {
218
        LinearLayout layout = mAct.get().findViewById(mLayout);
245
        Effects3DActivity act = (Effects3DActivity)getActivity();
246
        LinearLayout layout = act.findViewById(mLayout);
219 247
        View view;
220 248

  
221 249
        view = effect.getEffect();
src/main/java/org/distorted/examples/effects3d/Effects3DTabViewPager.java
21 21

  
22 22
import android.app.Fragment;
23 23
import android.app.FragmentManager;
24
import android.os.Bundle;
24 25
import android.support.v13.app.FragmentPagerAdapter;
25 26
import android.view.View;
26 27

  
27 28
import org.distorted.examples.R;
28
import org.distorted.library.effect.EffectType;
29 29

  
30 30
import java.lang.ref.WeakReference;
31 31

  
......
45 45
    super(fm);
46 46
    mAct = new WeakReference<>(act);
47 47
    mTab = new Effects3DTab[NUM_TABS];
48

  
49
    android.util.Log.e("viewPager"," CONSTRUCTOR ");
48 50
    }
49 51

  
50 52
///////////////////////////////////////////////////////////////////////////////////////////////////
......
75 77
    {
76 78
    android.util.Log.e("viewPager","creating tab "+position);
77 79

  
78
    switch(position)
80
    if( position>=0 && position<NUM_TABS )
79 81
      {
80
      case  0: mTab[0] = new Effects3DTab();
81
               mTab[0].setParams(EffectType.VERTEX     , mAct, R.layout.effects3dtab1, R.id.effects3dlayout1, R.id.effects3dspinner1);
82
               return mTab[0];
83
      case  1: mTab[1] = new Effects3DTab();
84
               mTab[1].setParams(EffectType.FRAGMENT   , mAct, R.layout.effects3dtab2, R.id.effects3dlayout2, R.id.effects3dspinner2);
85
               return mTab[1];
86
      case  2: mTab[2] = new Effects3DTab();
87
               mTab[2].setParams(EffectType.POSTPROCESS, mAct, R.layout.effects3dtab3, R.id.effects3dlayout3, R.id.effects3dspinner3);
88
               return mTab[2];
89
      default: return null;
82
      Bundle bundle = new Bundle();
83
      bundle.putInt("position", position);
84

  
85
      mTab[position] = new Effects3DTab();
86
      mTab[position].setArguments(bundle);
87
      return mTab[position];
90 88
      }
89

  
90
    return null;
91 91
    }
92 92

  
93 93
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff