I want use the native sdk interface layout, (How a normal app) to design my game menu, and link it to the BaseGameActivity, or GameScene, I know how to design the interface using sdk native, but I dont know how implement it on andengine :S
I cant find any solution, I will hope anybody can help me to find the best method, or the way to use these.
Sorry for my bad english.
More info: I know how to add a little framelayout on my baseactivity, but I can a set of menus (2/3) and that you can move on it, and enter on the game and exit of the game :)
Sorry my english again
Well, I do this works :)
Only create a normal activity, with the layout etc.. and use the intent.putExtra(); to send a particular info to the BaseGameActivy, Then, on onCreateResources() I set a serie of conditions to determine that I press before, and set the wished scene.
Sorry my english :)
EDIT: imported tutorials from original website
How to use UI Android SDK with AndEndine
NOTE : You may have filling errors if you change width and heights in these layouts so be carefull (this solution works with fullscreen usage)
XML layout
In your project's directory res/layout create an empty file named themainactivity.xml and put the following content inside.
Notes : Set the attribute tools:context to your application activity name, beginning with a dot (here: .MyMainActivity)
XML layout file: res/layout/themainactivity.xml
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- code placed here will be above the AndEngine render -->
</RelativeLayout>
Java class
You just have to specify the IDs in your class.
MyMainActivity.java
package com.example;
import org.andengine.ui.activity.SimpleLayoutGameActivity;
public class MyMainActivity extends SimpleLayoutGameActivity
{
#Override
protected int getLayoutID()
{
return R.layout.themainactivity;
}
#Override
protected int getRenderSurfaceViewID()
{
return R.id.gameSurfaceView;
}
}
Create a custom Android SDK layout in AndEngine
XML layout
WARNING: the root node must be a merge node ! Inside this you can do what you want.
XML layout file: res/layout/my_view.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="Dat button" />
</LinearLayout>
</merge>
The controller class
For being able to use your interface you have to link it to the XML view using the inflater service.
NOTE: The UI Java code is compiled when you switch to the WYSIWIG editor so if you don't add the linking code below you won't see the contents of the layout in the activities that use it.
Custom layout: MyView.java
package com.example;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
public class MyView extends LinearLayout
{
public MyView(Context context, AttributeSet attrs)
{
super(context, attrs);
// Link to the XML view
LayoutInflater.from(context).inflate(R.layout.my_view, this, true);
// Link to the XML view (alternative using service, you can delete if you don't need it)
//LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//inflater.inflate(R.layout.my_view, this);
}
}
Reuse in an other activity
Just add this code in the activity layout.
<com.example.MyView
android:id="#+id/myView1"
android:layout_width="100dp"
android:layout_height="wrap_content" />
Related
I've download android process button lib and import it into my eclipse. :
android process button lib :
I created an android project then I added this lib into my project :
now, I want to use this library but I get this error :
ProgressGenerator cannot be resolved to a type
I am using eclipse.
#NIPHIN answer is correct. As you can notice library is using gradle folder structure.
Here are 2 options:
Move com.dd... folders to src folder.
Create new project library, and simply copy all res and classes to your new created folder.
CHeck the project structure, reorganize the folder "java" to reflect folder structure as same folder "src" in eclipse. Eclipse and Studio IDE have different folder structures.
Am not sure of how you integrated it, but the example clearly state to import
import com.dd.processbutton.iml.ActionProcessButton;
import com.dd.processbutton.iml.GenerateProcessButton;
import com.dd.processbutton.iml.SubmitProcessButton;
Even though the project has been added as a dependency library, you would still need to have these import statements. May be eclipse is having trouble automatically adding these imports? Jut add them i manually. If your folder structure and import are correct, it should work.
Thread is a bit old, but perhaps I can help you out.
I´ll show you an Example with the ActionProcessButton
first of all in your layout, u need the specific Button. For example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.dd.processbutton.iml.ActionProcessButton
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginBottom="16dp"
android:textColor="#android:color/white"
android:textSize="18sp"
android:text="#string/login"
android:id="#+id/loginButton"
android:textAllCaps="true"
custom:pb_colorComplete="#color/green_complete"
custom:pb_colorNormal="#color/blue_normal"
custom:pb_colorPressed="#color/blue_pressed"
custom:pb_colorProgress="#color/purple_progress"
custom:pb_textComplete="#string/login_successfull"
custom:pb_textProgress="#string/login_auth" />
</RelativeLayout>
inside your activiy / Fragment / whatever:
public class LoginFragment extends Fragment {
private ActionProcessButton loginButton;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.login_fragment, container, false);
loginButton = (ActionProcessButton) view.findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loginButton.setProgress(50); // starts the Animation and sets the text defined in your .xml file for Progress
loginDone();
}
});
}
private void loginDone(){
//...
// do something time-consuming
loginButton.setProgress(100); // tolds the button, that your operation is done.
}
// ...
}
Of course, you can update the Progress state dynamically, but as I know, the critical values for setProgress are -1(for login failed), 0, 50 and 100.
I'm trying to create a square layout for a widget.
I have the following layout class:
package com.trollhammaren;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;
public class SquareLayout extends LinearLayout {
// constructors
public SquareLayout(Context context) {
super(context);
}
public SquareLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
// methods
#Override
protected void onMeasure(int width, int height) {
Log.v("widget", "resized");
super.onMeasure(width, height);
}
}
And the following xml:
<?xml version="1.0" encoding="utf-8"?>
<com.trollhammaren.SquareLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dip"
android:background="#drawable/myshape" >
</com.trollhammaren.SquareLayout>
Instead of a square I see a rectangle widget with the text "Problem loading widget". When I place the widget I see the following message in logcat:
Error inflating AppWidget AppWidgetProviderInfo(provider=ComponentInfo{com.trollhammaren.wakeonlandroid/com.trollhammaren.wakeonlandroid.WidgetProvider}): android.view.InflateException: Binary XML file line #2: Error inflating class com.trollhammaren.SquareLayout
If I change the layout to LinearLayout, I do see a normal LinearLayout, but it's not square.
What am I doing wrong?
Inside of the Widget you can only have Views and Layouts that are tagged as RemoteViews. So I don't think you can send your own custom class over to the AppWidget context. It has to be done with only the views within the OS version that are tagged this way.
To be clear the way these work, the context which hosts the Widget is not your process. So the AppWidget's context basically sends everything via an RPC like mechanism from your app to another context's view. If it supported custom widgets, that would allow you basically to send arbitrary code to the other apps process and assume a lot more permissions than I bet they would really like you to have. Plus it would be nasty for the IPC, since you would need to parcel the entire class hierarchy and load it in a separate classloader and all that stuff just to guarantee dependancies are upheld.
I am developing an Android Application. In this application, Logo bar is shown on all pages(Activities) or we can say it has header on all pages.
This Logo Bar have few icons like Home, Login, Notification, etc. and on Clicking on these icons corresponding navigation will perform.
for example if user is any where in application and click on home icon, he will navigate to the home page of application.
I am able to inflate logobar.XML into my All Activity by coding. but problem is i have to call onClickListener on all pages for all icons in Logo Bar.
This is not a good programming way.
How can i implement Logo Bar Activity in all other activity without repeating of code?
Is android have any Master Page concept as in .Net or tiles concept as in Struts?
Please guide me.
Edit: ok i got it. may be this answer will help you.
Try using Tab widget with tabactivity check this link for using fragment and tab http://developer.android.com/reference/android/app/TabActivity.html for android. i think for lower versions also we can use this. this si what the link says - "you can use the v4 support library which provides a version of the Fragment API that is compatible down to DONUT."
you have to create your masterLayout in xml and that you have to include it in your other
layouts in which you have to have it.
The solution was pretty easy.
You need to extends "Activity" Class,in onCreate function SetContentView to your base xml layout and also need to override setContentView in base Activity Class
For Example:
1.Create "base_layout.xml" with the below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000"
android:padding="15dp" >
<LinearLayout android:orientation="horizontal" android:background="#000000"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:minHeight="50dp" android:paddingLeft="10dp">
<ImageView android:layout_width="wrap_content" android:id="#+id/ImageView01"
android:adjustViewBounds="true" android:layout_height="wrap_content"
android:scaleType="fitCenter" android:maxHeight="50dp" />
</LinearLayout>
<LinearLayout android:id="#+id/linBase"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
2.Create "BaseActivity.java"
public class BaseActivity extends Activity {
ImageView image;
LinearLayout linBase;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.base_layout);
image = (ImageView)findViewById(R.id.ImageView01);
image.setImageResource(R.drawable.header);
linBase = (LinearLayout)findViewById(R.id.linBase);
}
#Override
public void setContentView(int id) {
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(id, linBase);
}
}
and
public class SomeActivity extends BaseActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.some_layout);
//rest of code
}
}
The only thing I noticed so far was that when requesting a progress bar (requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) this needs to be done before calling super.onCreate. I think this is because nothing can be drawn yet before calling this function.
This worked great for me and hopefully you will find this useful in your own coding.
There is something like that, but only available on api 11+ (3.2 and Android 4.0.x Ice Cream Sandwich). Its called actionbar ( http://developer.android.com/reference/android/app/ActionBar.html).
I have done this using XML file.
I am just creating runtime view from XML file , and add it to the Activity layout.
I have created method for that
public static void setLoginview(Context ctx, RelativeLayout layout) {
LayoutInflater linflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = linflater.inflate(R.layout.loginheader, null);
layout.addView(myView);
try {
layout.getChildAt(0).setPadding(0, 50, 0, 0);
} catch (Exception e) {
}
}
ctx is the application contetx and layout is the layout in which i want to add that view.
I'm trying to use inflate while using ViewFlipper to access to the data inside my view. I've done sample project that crashes.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
FlipViewBug.java
package android.FlipViewBug;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
public class FlipViewBug extends Activity {
private static LayoutInflater inflater = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
}
When I rotate emulator from horizontal to vertical orientation CTRL+F11 app crashes with stopped unexpectedly.
If I remove line
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
app works fine. Am I trying to do something wrong? In my app I have more complex LinnarView that ViewFlipper is nested and the results are the same.
I was checking this on android 1.5, 2.2 and galaxy tab. There is no problem while rotating form vertical view to horizontal.
As a rule of thumb if you're storing UI objectrefs in static data you're probably doing something wrong. :) Even when things appear to work, you are likely to be leaking memory until Android decides to kill your process. See Romain Guy's article on this for more details.
So basically you answered your own question... don't do that! If you want to delay inflation of flipped-out views until they are flipped-in (i.e. as a performance improvement) I'd suggest you look into ViewStub.
I'm new at java and OpenGL.
I'm trying to get a camera preview screen with the ability to
display 3d objects simultaneously. Having gone through the samples at
the api demos, I thought combining the code for the the examples at
the api demo would suffice. But somehow its not working. The forces me
to shut down upon startup and the error is mentioned as null pointer
exception. Could someone share with me where did I go wrong and how to
proceed from there. How I did the combination for the code is as shown
below:
myoverview.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.opengl.GLSurfaceView
android:id="#+id/cubes"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<SurfaceView
android:id="#+id/camera"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
myoverview.java
import android.app.Activity;
import android.os.Bundle;
import android.view.SurfaceView;
import android.view.Window;
public class MyOverView extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Hide the window title.
requestWindowFeature(Window.FEATURE_NO_TITLE);
// camera view as the background
SurfaceView cameraView = (SurfaceView) findViewById(R.id.camera);
cameraView = new CameraView(this);
// visual of both cubes
GLSurfaceView cubesView = (GLSurfaceView) findViewById(R.id.cubes);
cubesView = new GLSurfaceView(this);
cubesView.setRenderer(new CubeRenderer(false));
// set view
setContentView(R.layout.myoverview);
}
}
GLSurfaceView.java
import android.content.Context;
class GLSurfaceView extends android.opengl.GLSurfaceView {
public GLSurfaceView(Context context) {
super(context);
}
}
NOTE :
I didn't list the rest of the files as they are just copies of
the api demos. The cameraView refers to the camerapreview.java example
and the CubeRenderer refers to the CubeRenderer.java and Cube.java
example. Any help would be appreciated.
Sorry, didn't realize that the coding was out of place due to formatting mistakes.
the reason you are getting a null pointer exception when working with .xml is because ur actually creating new Views in your java code.. instead of using the ones from the .xml file to which you might have passed in properties(if u did pass in properties that is..).. the new View would obviously have a null value.. thus throwing a null pointer exception... for example --
cubesView = new GLSurfaceView(this);
is actually not needed in the code if you already created the View in the .xml file containing FrameLayout..
This is very simple actually...if you want to define your view in XML you just have to implement
Public GLSurfaceView(Context context, AttributeSet attrs) {
...
super(context, attrs);
}
instead of GLSurfaceView(Context context)
That's the one that gets called automatically when the view is initialized from the XML. I had the same problem and that's how it was fixed.
Found out how to solve it... via the java way... just use addContentView instead of using xml.... well at least its solved. :)
I actually did that here in this SO link which provides a complete implementation.