Procedure
HUAWEI Scene Kit uses SceneView to provide you with rendering capabilities that automatically adapt to 3D scenes. To complete the rendering of a complex 3D scene, you only need to call several APIs.
SceneView inherits from surfaceView and overrides methods including surfaceCreated, surfaceChanged, surfaceDestroyed, onTouchEvent, and onDraw. You create a SampleView inheriting from SceneView to quickly access HUAWEI Scene Kit.
1. Create a SampleView that inherits from SceneView.
Code:
public class SampleView extends SceneView {
public SampleView(Context context) {
super(context);
}
public SampleView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
}
2. Override the surfaceCreated method of SceneView in SampleView, and call this method to create and initialize SceneView.
Code:
public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
}
3. In the surfaceCreated method, call loadScene to load materials to be rendered.
Code:
loadScene("scene.gltf");
4. In the surfaceCreated method, call loadSkyBox to load skybox materials.
Code:
loadSkyBox("skyboxTexture.dds");
5. In the surfaceCreated method, call loadSpecularEnvTexture to load specular maps.
Code:
loadSpecularEnvTexture("specularEnvTexture.dds");
6. In the surfaceCreated method, call loadDiffuseEnvTexture to load diffuse maps.
Code:
loadDiffuseEnvTexture("diffuseEnvTexture.dds");
7. (Optional) To clear the materials from a scene, call the clearScene method.
Code:
clearScene();
NOTE:
When the loadScene method is called to load new materials for a scene, its original materials are automatically cleared, with no need to call the clearScene method.
8. (Optional) Determine whether to override the surface-related lifecycle methods as needed.
Code:
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int foramt, int width, int height) {
super.surfaceChanged(surfaceHolder, foramt, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
super.surfaceDestroyed(surfaceHolder);
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return super.onTouchEvent(motionEvent);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
NOTE:
If you do not need custom functions, the methods of SceneView are used by default. No overriding is required.
If custom functions are needed, override the SceneView methods.
For example, if you want to display the frame rate for your rendering, override the onDraw method and add the function of displaying the frame rate.
Code:
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
// showCurrentFPS();
}
9. Create an activity and call setContentView in the onCreate method. Pass the SampleView that you have created to the setContentView method.
Code:
public class SampleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
}
Full SampleView Code
Code:
public class SampleView extends SceneView {
// Create a SampleView in new mode.
public SampleView(Context context) {
super(context);
}
// Create a SampleView by registering it in the Layout xml file.
public SampleView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
super.surfaceCreated(holder);
// Load the model of a scene by reading files from assets.
loadScene("scene.gltf");
// Load skybox materials by reading files from assets.
loadSkyBox("skyboxTexture.dds");
// Load specular maps by reading files from assets.
loadSpecularEnvTexture("specularEnvTexture.dds");
// Load diffuse maps by reading files from assets.
loadDiffuseEnvTexture("diffuseEnvTexture.dds");
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {
super.surfaceChanged(surfaceHolder, format, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
super.surfaceDestroyed(surfaceHolder);
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
return super.onTouchEvent(motionEvent);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
}
Related
problem is in CFGameView???
hi, i will make this short but to the point...
making a 2D app with a space theme and involves making a Game View which needs to use two images to make the background which is scrolling in portrait.
im stuck on the CFGameView part at the bottom.
i think i need to link them some how??
its blatantly simple and im just being thick..
cheers
-----------------CFGameRenderer-----------
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class CFGameRenderer implements Renderer {
private CFBackground background = new CFBackground();
private CFBackground background2 = new CFBackground();
private float bgScroll1;
private float bgScroll2;
@Override
public void onDrawFrame(GL10 gl) { try { Thread.sleep(CFEngine.GAME_THREAD_FPS_SLEEP);
} catch (InterruptedException e) {
e.printStackTrace();
}
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
scrollBackground1(gl);
scrollBackground2(gl);
//ALL OTHER GAME DRAWING WILL BE CALLED HERE
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
}
private void scrollBackground1(GL10 gl){
if (bgScroll1 == Float.MAX_VALUE){
bgScroll1 = 0f;
}
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(1f, 1f, 1f);
gl.glTranslatef(0f, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, bgScroll1, 0.0f);
background.draw(gl);
gl.glPopMatrix();
bgScroll1 += CFEngine.SCROLL_BACKGROUND1;
gl.glLoadIdentity();
}
private void scrollBackground2(GL10 gl){
if (bgScroll2 == Float.MAX_VALUE){
bgScroll2 = 0f;
}
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glPushMatrix();
gl.glScalef(.5f, 1f, 1f);
gl.glTranslatef(1.5f, 0f, 0f);
gl.glMatrixMode(GL10.GL_TEXTURE);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, bgScroll2, 0.0f);
background2.draw(gl);
gl.glPopMatrix();
bgScroll2 += CFEngine.SCROLL_BACKGROUND2;
gl.glLoadIdentity();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0f, 1f, 0f, 1f, -1f, 1f);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
background.loadTexture(gl, CFEngine.BACKGROUND_LAYER_ONE, CFEngine.context);
background2.loadTexture(gl, CFEngine.BACKGROUND_LAYER_TWO, CFEngine.context);
}
}
---------------- CFGame-------------
import android.app.Activity;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
public class CFGame extends Activity {
private CFGameView gameView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
gameView = new CFGameView(this);
setContentView(gameView);
}
@Override
protected void onResume() {
super.onResume();
gameView.onResume();
}
@Override
protected void onPause() {
super.onPause();
gameView.onPause();
}
}
--------------- CFGamView ---------------
import android.content.Context;
import android.opengl.GLSurfaceView;
public class CFGameView extends GLSurfaceView{
public CFGameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}
basically how do i properly create and extend the GLSurfaceView so it starts my game.
i keep getting this logcat error no matter what i try.
03-09 17:42:16.649: E/AndroidRuntime(17570): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blah blah/com.blah blah.CFGame}: java.lang.NullPointerException
Hello guys,
I need your help to find how to code a Scrollable tabs (ics), I find no help and I'm looking but I can not find!
Had you any idea? Thank you in advance
http://developer.android.com/design/media/tabs_scrolly.mp4
Source: http://developer.android.com/design/patterns/actionbar.html#contextual
youpi01 said:
Hello guys,
I need your help to find how to code a Scrollable tabs (ics), I find no help and I'm looking but I can not find!
Had you any idea? Thank you in advance
http://developer.android.com/design/media/tabs_scrolly.mp4
Source: http://developer.android.com/design/patterns/actionbar.html#contextual
Click to expand...
Click to collapse
Create an actionbar and edit the layout to fit your needs.
Code:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle startInfo) {
super.onCreate(startInfo);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tabCPU = actionBar.newTab()
.setText(R.string.cpu_tab_title)
.setTabListener(new TabListener<CpuInfoActivity>(
this, "artist", CpuInfoActivity.class));
actionBar.addTab(tabCPU);
Tab tabMEM = actionBar.newTab()
.setText(R.string.mem_tab_title)
.setTabListener(new TabListener<MemInfoActivity>(
this, "artist", MemInfoActivity.class));
actionBar.addTab(tabMEM);
}
thank you very much I will test it now!
Well I just tried but I can not, it shows me many errors!
Is there source code available for me to view?
Hello, I have made some progress ...
I would just like to add tabs and be able to edit in xml!
How do I add Java code to the link to my different layout (tabs)
Attached is the file in question!
Code:
package com.youpi.app;
import com.actionbarsherlock.app.SherlockActivity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class AppActivity extends SherlockActivity implements OnPageChangeListener {
private ViewPager viewPager;
private static int NUM_VIEWS = 2;
private MyPagerAdapter pagerAdapter;
private TextView pageIndicator;
private int currentPage = 0;
private View[] tabViews = new View[NUM_VIEWS];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
pagerAdapter = new MyPagerAdapter();
viewPager = (ViewPager) findViewById(R.id.viewpager1);
TextView textView1 = new TextView(this);
textView1.setText("Tunandroid View Pager Example");
textView1.setTextSize(20);
ImageView imageView1 = new ImageView(this);
imageView1.setImageResource(R.drawable.ic_launcher);
[COLOR="Red"]tabViews[0] = textView1;
tabViews[1] = imageView1;
tabViews[2]= here add a new tab but in xml![/COLOR]
viewPager.setAdapter(pagerAdapter);
viewPager.setOnPageChangeListener(this);
viewPager.setCurrentItem(currentPage);
pageIndicator = (TextView)findViewById(R.id.pageIndicator);
pageIndicator.setText(String.valueOf(currentPage+1));
}
private class MyPagerAdapter extends PagerAdapter
{
@Override
public int getCount() {
return NUM_VIEWS;
}
@Override
public Object instantiateItem(View collection, int position) {
((ViewPager) collection).addView(tabViews[position],0);
return tabViews[position];
}
@Override
public void destroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((View)view);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==(object);
}
@Override
public void finishUpdate(View arg0) {}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {}
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int position) {
currentPage = position;
pageIndicator.setText(String.valueOf(currentPage+1));
}
}
I couldn't think of a better way to word the title, but the issue I'm having is this: I'm using HoloColorPicker by Lars Werkman. Now I have correctly imported the library, I can see the ColorPicker and other views from the library in my app, the only symbol that is failing to be found is OnColorChangedListener. I looked through the code of the library and it is an interface that is defined in ColorPicker.java, which I am importing, and the ColorPicker view itself, as I already stated, is appearing in my GUI fine.
Here is my associated code:
Code:
import com.larswerkman.holocolorpicker.SaturationBar;
import com.larswerkman.holocolorpicker.ColorPicker;
import com.larswerkman.holocolorpicker.ValueBar;
public class ColorChooserDialog extends DialogFragment {
private String title;
private CustomColor cur_color;
private boolean edit = false;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.choose_color_dialog_title);
// Inflate layout color chooser view and set to builder
LayoutInflater layout_inflater = getActivity().getLayoutInflater();
View view = layout_inflater.inflate(R.layout.color_chooser_view, null);
builder.setView(view);
// Get views by IDs
EditText hex_input = (EditText)view.findViewById(R.id.hexInput);
EditText red_input = (EditText)view.findViewById(R.id.redInput);
EditText green_input = (EditText)view.findViewById(R.id.greenInput);
EditText blue_input = (EditText)view.findViewById(R.id.blueInput);
ColorPicker color_picker = (ColorPicker)view.findViewById(R.id.colorPicker);
SaturationBar sat_bar = (SaturationBar)view.findViewById(R.id.saturationBar);
ValueBar val_bar = (ValueBar)view.findViewById(R.id.valueBar);
// Connect bars to color picker
color_picker.addSaturationBar(sat_bar);
color_picker.addValueBar(val_bar);
// When color is changed via picker, set text fields
color_picker.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});
// Add listener for when HEX value is changed
hex_input.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable editable) {}
@Override
public void beforeTextChanged(CharSequence chars, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence chars, int start, int before, int count) {
//TODO
}
});
builder.setPositiveButton(
R.string.ok_button,
new DialogInterface.OnClickListener() {
// User clicked OK, add color to palette
public void onClick(DialogInterface dialog, int id) {
//TODO
}
}
);
builder.setNegativeButton(
R.string.cancel_button,
new DialogInterface.OnClickListener() {
// User cancelled the dialog, don't create palette
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}
);
// Create the AlertDialog object and return it
return builder.create();
}
}
OK, so I figured it out, I didn't notice this at first because Java is not my first language, but the OnColorChangedListener is within the ColorPicker class, so I instead of using this:
Code:
color_picker.setOnColorChangedListener(new OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});
I needed to use this:
Code:
color_picker.setOnColorChangedListener(new [B]ColorPicker.[/B]OnColorChangedListener() {
@Override
public void onColorChanged(int color) {
//TODO
}
});
Hi
Frag1 which is a side navigation drawer, is instantiated in MainActivity.java onCreate by manager.findFragmentById since there is a fragment tag in a xml file.
Frag2 and Frag3 are dynamically committed at some point by a manager, non of their layouts contain a <fragment> tag, they are not committed in the MainActivity onCreate method and thus don't have ids or tags either.
When a button on frag2 is pressed, frag3 "a dialogFragment" needs to be displayed on the screen for user login inputs.
How can I get this to work? I am getting null pointer when referencing frag2 in MainActivity.
here is a illustrative stripped down version of the code. sorry for any unintended typos
Thank you for helping
Frag2.java
Code:
public class Frag2 extends Fragment {
Frag2Communicator = mFrag2communicator;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.frag2_layout, container, false);
class ClickHandler implements View.OnClickListener {
@Override
public void onClick(View v) {
mFrag2communicator.show_frag3();
}
}
}
public interface Frag2Communicator {
public void show_frag3();
}
public void setFrag2Communicator(Frag2Communicator frag2communicator) {
mFrag2communicator = frag2communicator;
}
}
MainActivity.java
Code:
public class MainActivity extends ActionBarActivity implements frag2.frag2Communicator {
protected void onCreate(Bundle savedInstanceState) {
Frag2 frag2 = getSupportFragmentManager().findFragmentById(R.id.frag_2);
//frag_2 is the id of a RelativeLayout inside a ScrollView inside frag2_layout.xml
//I tried to move this ide to the root tag "ScrollView" but still get a null pointer.
frag2.setFrag2Communicator(this);
public void show_frag3(){
FragmentManager manager = getSupportFragmentManager();
Frag3 frag_3 = new Frag3();
frag_3.show(manager, "loging");
}
}
}
Hey Im very new to Android studio, and Im trying to understand the procces of building a app
So here is what I learned so far.
1. I start with the MainActivty
2. Add Activity Cycle: onCreate, onStart, onResume etc.
3. Import android.util.Log; so I can see the log information for my code
4. Create a Second Activity
5. Create a btn on the MainActivity and onClick move to Second Activity.
Check the code below to say how I set up my MainActivity
Now here is the problem, when i run the Emulator:
- there are no errors
Press button to go to the other Activity, my log shows:
MainActivity_message: onClick
MainActivity_message: onPause
SecondActivity_message: onCreate
SecondActivity_message: onStart
SecondActivity_message: onResume
BUT, in my Emulator viewer the MainActivity stays visible and Im not seeing the SecondAcivity.
How do i solve this or what im I missing here?
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button BtnMove; //
public static final String TAG = "MainActivity_message";
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate"); //
BtnMove = findViewById(R.id.BTNActivityOne); //
BtnMove.setOnClickListener(new View.OnClickListener() { //
@override
public void onClick(View v) {
moveToActivityTwo(); //
Log.i(TAG, "onClick"); //
}
});
}
private void moveToActivityTwo() { //
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
@override
protected void onStart() {
super.onStart();
Log.i(TAG, "onStart"); //
}
@override
protected void onResume() {
super.onResume();
Log.i(TAG, "onResume"); //
}
@override
protected void onPause() {
super.onPause();
Log.i(TAG, "onPause"); //
}
@override
protected void onStop() {
super.onStop();
Log.i(TAG, "onStop"); //
}
@override
protected void onRestart() {
super.onRestart();
Log.i(TAG, "onRestart"); //
}
@override
protected void onDestroy() {
super.onDestroy();
Log.i(TAG, "onDestroy"); //
}
}