OpenGL ugh

I toyed around with some extremely basic openGL code today. My first impression of openGL is ~ugh~ I don’t like anything about it. It feels very archaic, overly difficult. I wanted to use touch to rotate a 3D cube, but something as seemingly simplistic as that requires 500 lines of code in just 1 class. I didn’t feel like diving into that especially when I just wanted to toy around.

I did learn one neat trick, something I want to remember. Using system time to rotate a 3D cube.

(also learned to use system time to conserve cpu power)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


long time = SystemClock.uptimeMillis() % 4000L;
 float angle = .090f * ((int)time);
 gl.glRotatef(angle, 1, 0, 1);

cube.draw(gl);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Advertisements

Liyr Web Brower

Just created a custom web browser. After tweaking it a bit I really like it. However I love that I learned how to not reset states when I change the orientation.

To do that I first created a FrameLayout to act as a holder for my WebView.


</LinearLayout>

<FrameLayout
 android:id="@+id/wvBrowser"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />

</LinearLayout>

Then I placed the WebView inside the layout.


protected void UI() {
 LinearLayout bgColor = (LinearLayout) findViewById(R.id.LOLiyr);
 bgColor.setBackgroundColor(Color.WHITE);
 wvHolder = ((FrameLayout) findViewById(R.id.wvBrowser));

if(wv == null) {

wv = new WebView(this);
 wv.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
 wv.getSettings().setJavaScriptEnabled(true);
 wv.getSettings().setLoadWithOverviewMode(true);
 wv.getSettings().setUseWideViewPort(true);
 wv.getSettings().setLoadsImagesAutomatically(true);
 wv.getSettings().setSupportZoom(true);
 wv.setWebViewClient(new wvClient());
 wv.requestFocus(View.FOCUS_DOWN);
 wv.setOnTouchListener(new View.OnTouchListener() {

@Override
 public boolean onTouch(View v, MotionEvent event) {
 // TODO Auto-generated method stub
 switch(event.getAction())
 {
 case MotionEvent.ACTION_DOWN:
 case MotionEvent.ACTION_UP:
 if(!v.hasFocus())
 {
 v.requestFocus();
 }
 break;
 }
 return false;
 }
 });
 wv.loadUrl("http://google.com");
 }
 wvHolder.addView(wv);
 }

public void onCofigurationChanged(Configuration config) {

if (wv != null)
 wvHolder.removeView(wv);

super.onConfigurationChanged(config);
 setContentView(R.layout.liyr);
 UI();
 }

The last step is to add


android:configChanges="orientation"

to the manifest. I’m not 100% sure why but I know it makes sure that a new activity isn’t started and that the config is kept. I love it! I could use this technique for everything.

http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/

http://www.androidhive.info/2011/11/android-xml-parsing-tutorial/

I built an xml parser to my NB app today. It was harder than I thought but I understand it at least 70%ish. I’m hoping that understanding parsing xml from online will help me understand how to call in data for the surv app. I’ll start it tonight but by tomorrow I should have a custom List View with images and a nice look to it. Then I’ll finish the action bar and start trying to make the List View look the way I want.

Solved OnClickListener Bug!

Took me a lot of stacked overflowing but I finally solved the bug. It turns out that the Pager Adapter I was using wasn’t creating the layouts until I swiped to view them. Thus I was getting a null pointer exception because I was trying to call a button that didn’t exist. So now I inflate the views before I call the onClickListener and voilà! Now on to the hard part.

BEFORE:

<pre><code>@Override
public Object instantiateItem(View collection, int position) {
    LayoutInflater inflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int resId = 0;
    switch (position) {

    case 0:
        resId = R.layout.splash2;
        b = (Button) collection.findViewById(R.id.splashB);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                                    //setContentView(r.layout.someLayout);
            }
        });
        break;</code>

AFTER:

</pre>
public Object instantiateItem(View collection, int position) {
 LayoutInflater inflater = (LayoutInflater) collection.getContext()
 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view = null;
 switch (position) {

case 0:
 view = inflater.inflate(R.layout.splash2, null);
 b1 = (Button) view.findViewById(R.id.splashB1);
 b1.setOnClickListener(new OnClickListener() {

@Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 v.getContext().startActivity(i);

}
 });
 break;

onClickListener Crash

I’m getting a crash with this code. I think it’s because i’m trying to load two views at once. I’ve been trying to figure this out for a while but I’m sure I’ll have a solution soon.  It must be trying to load two things at once or something. I’ve tried loading a new view and then tried to load a new activity but neither work. I believe that the View Pager is fucking it up somehow but I don’t know how to fix it. I really want to use the View Pager, it works perfectly.

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);

SplashPager adapter = new SplashPager();
ViewPager myPager = (ViewPager) findViewById(R.id.splashPager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);

listButtonListener();

}

public void listButtonListener() {

listButton = (Button) findViewById(R.id.splashB);
listButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

startActivity(new Intent("com.example.survtest1.Main"));

}

});

}

}