Android OpenGL ES 2.0 Live Wallpaper - GLSurface methods not calling - java

I follow next tutorial (first part of it), but with slightly simple class structure
http://www.learnopengles.com/how-to-use-opengl-es-2-in-an-android-live-wallpaper/
I get next chain of events when i try to select wallpaper (preview)
onCreateEngine()->onCreate() -> onResume()->onPause()->onResume()->onPause()
Why i get onResume()->onPause() two times?
When i hit "Set wallpaper" i get extra onPause()->onResume() and live wallpaper crashes (well maybe because onPause() called 2 times)
Also i don't see calls of OGLES2Renderer like onSurfaceCreated(), onDrawFrame() in preview or on setting wallpaper.
What i missed out of view?
Android manifest (part of it)
<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<service
android:name="com.aristarhys.lw.LW"
android:label="#string/app_name"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/lw" />
res/xml/lw.xml
<?xml version="1.0" encoding="UTF-8"?>
<wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="#drawable/ic_launcher"
android:description="#string/app_desc"/>
LW.java
public class LW extends WallpaperService
{
public class OGLES2Engine extends Engine
{
private class OGLES2SV extends GLSurfaceView
{
public OGLES2SV(Context context)
{
super(context);
}
public void onDestroy()
{
super.onDetachedFromWindow();
}
}
private OGLES2SV SV = null;
#Override
public void onCreate(SurfaceHolder surfaceHolder)
{
super.onCreate(surfaceHolder);
SV = new OGLES2SV(LW.this);
SV.setEGLContextClientVersion(2);
SV.setRenderer(new OGLES2Renderer());
}
#Override
public void onVisibilityChanged(boolean visible)
{
if (!visible)
SV.onResume();
else
SV.onPause();
super.onVisibilityChanged(visible);
}
#Override
public void onDestroy()
{
SV.onDestroy();
super.onDestroy();
}
}
#Override
public Engine onCreateEngine()
{
return new OGLES2Engine();
}
}
OGLES2Renderer.java
public class OGLES2Renderer implements GLSurfaceView.Renderer
{
private static final String LOG_TAG = "GL2Surface";
#Override
public void onDrawFrame(GL10 unused)
{
Log.i(LOG_TAG, "Draw frame");
}
#Override
public void onSurfaceChanged(GL10 unused, int width, int height)
{
Log.i(LOG_TAG, "Surface changed");
}
#Override
public void onSurfaceCreated(GL10 unused_, EGLConfig _unused)
{
Log.i(LOG_TAG, "Surface created");
}
}

You can use andengine Wallpaper extension to implement this.

Related

Why getVoiceInteractor () returns null?

I'm trying to get VoiceInteractor, but the getVoiceInteractor() method always returns null. In the manifest, I wrote the following:
<activity android:name=".Activity_2">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.VOICE" />
</intent-filter>
</activity>
Activity_1:
protected void onCreate(Bundle savedInstanceState) {
startActivity(new Intent(Activity_1.this, Activity_2.class));
}
Activity_2:
protected void onCreate(Bundle savedInstanceState) {
VoiceInteractor mInteractor;
mInteractor = getVoiceInteractor();
}
The documentation seems a bit unclear, but I found the following clues:
startLocalVoiceInteraction() seems to be needed to be able to get the VoiceInteractor
onLocalVoiceInteractionStarted() seems to indicate when you can call getVoiceInteractor
The last clue came from onGetDirectAction where it states:
To get the voice interactor you need to call getVoiceInteractor() which would return non null only if there is an ongoing voice interaction session
This means your code should look something like this:
public class YourActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
startLocalVoiceInteraction(new Bundle());
}
#Override
public void onLocalVoiceInteractionStarted() {
getVoiceInteractor(); // Should be non-null here
}
}

Out of memory Even though my pictures are less than 2 MB

I am making a animated login screen...my code is as follows
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
ImageView i = (ImageView)findViewById(R.id.img1);
if (i == null) throw new AssertionError();
i.setBackgroundResource(R.drawable.animation_pulse);
AnimationDrawable pro = (AnimationDrawable)i.getDrawable();
pro.start();
but when I execute the app in the emulator, it says
java.lang.OutOfMemoryError: Failed to allocate a 17280012 byte allocation with
4194304 free bytes and 15MB until OOM
though my my drawable files are less than 2mb and even the following code doesn't help.
android:largeHeap="true"
Please add this on your manifest file and then look at the magic,
android:largeHeap="true"
android:hardwareAccelerated="false"
Happy coding!!
tru this on anroidmenifest.xml
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
For the moment, move the image from res/drawable/ to res/drawable-nodpi/. res/drawable/ is a synonym for res/drawable-mdpi/, and so you are saying that 800x600 is the resolution that you want for -mdpi screens (around 160dpi). On higher density devices, Android will automatically scale such resources to keep the same physical size (5" x 3.5"), and that is increasing the memory consumption of your image.
While that change will help, you will still run into OutOfMemoryErrors on many devices. You will need to get rid of this animation entirely, or replace it with something else that does not require ~60MB of heap space (800 pixels x 600 pixels x 4 bytes/pixel x 33 images).
Try to use some imageloader library. That will fix oom.
Glide
Picasso
Uml
Fresco
out of these Glide is best :)
the gradle dependencies:
// if you need jar ,please download it from https://mvnrepository.com/artifact/com.github.bumptech.glide/glide
compile group: 'com.github.bumptech.glide', name: 'glide', version: '3.8.0'
the sample code:
Glide.with(context)
.load(your drawable)
.override(yoursize, yoursize)
.into(new Target<Drawable>() {
#Override
public void onStart() {
}
#Override
public void onStop() {
}
#Override
public void onDestroy() {
}
#Override
public void onLoadStarted(Drawable placeholder) {
}
#Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
}
#Override
public void onResourceReady(Drawable resource, GlideAnimation<? super Drawable> glideAnimation) {
imageview.setImageDrawable(resource);
//start animation here
}
#Override
public void onLoadCleared(Drawable placeholder) {
}
#Override
public void getSize(SizeReadyCallback cb) {
}
#Override
public void setRequest(Request request) {
}
#Override
public Request getRequest() {
return null;
}
})

How to prevent theme.dialog activity to allow outside touch?

I have an activity that is using the Theme.Dialog style. It's a popup for my quiz game, for the wrong answer. But I have a problem. User can click outside the popup dialog themed activity and click on the next question. How to prevent that? I blocked back button and that works fine.
Also, when a user clicks on the popup or outside of it, it starts counting the ON time again. My popup stays ON for 2500 ms. How to prevent that also?
So, basically I don't want to allow any click outside my popup and don't want to reset my delay time when someone clicks on the screen.
Here's the code of the popup window:
public class WrongAnswer extends Activity{
MediaPlayer sound;
TextView wrong;
String correctAnswer, correct;
public final int delayTime = 2500;
private Handler myHandler = new Handler();
public void onUserInteraction(){
myHandler.removeCallbacks(closePopup);
myHandler.postDelayed(closePopup, delayTime);
}
private Runnable zatvoriPopup = new Runnable(){
public void run(){
finish();
}
};
#Override
public void onBackPressed() {
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.wrong);
Bundle extras = getIntent().getExtras();
if(extras !=null) {
tacno = extras.getString("correctAnswer");
}
inicijalizujVarijable();
myHandler.postDelayed(closePopup, delayTime);
}
private void inicijalizujVarijable() {
wrong = (TextView) findViewById(R.id.tvWrong);
wrong.setText("Wrong answer!\nCorrect answer is:\n\n" + correct);
}
}
My activity in manifest:
<activity
android:name="com.myquiz.myquizgame.WrongAnswer"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="com.myquiz.myquizgame.WRONGANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
If I got you correctly, this question had been already asked. Here is the answer, and according to it you need to call a setter method on activity, that will close your activity dialog:
this.setFinishOnTouchOutside(false);
I hope it will help you.
Second, every time when user touches WrongAnswer activity — you start new delayed task and cancel previous one here:
public void onUserInteraction() {
myHandler.removeCallbacks(zatvoriPopup);
myHandler.postDelayed(zatvoriPopup, delayTime);
}
that's why you have problems with timer

Airpush SmartWall "clicking" itself whenever loading is completed, using LibGDX

I have been struggling with this problem for a while now and would be very grateful if anyone could help me out.
The problem is that when I´ve successfully loaded an airpush "smartwall" it "clicks" itself and I immediately go to wherever the ad takes you. Before the ad has completed loading I can see the graphical representation of the ad loading.
I´ve contacted AP-support several times but I´m still having the same problem no matter what I do.
The problem seems to be that the smartwall is running on the wrong thread, I am using a UIThread handler for other stuff and it works fine (leadbolt interstitials, alertdialogs and other native android stuff).
Things I´ve tried:
AsyncTask
#Override
public void showAP() {
uiThread.post(new Runnable(){
public void run(){
new Async().execute();
}
});
}
private class Async extends AsyncTask<String, Integer, String[]>{
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String[] doInBackground(String... params) {
if(apSmartWall == null)
apSmartWall = new ApSmartWall(MainActivity.this, adCallbackListener);
apSmartWall.startSmartWallAd();
return null;
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
#Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);
}
}
Handler
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
apSmartWall = new ApSmartWall(MainActivity.this, adCallbackListener);
// Create the layout
layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
gameView = initializeForView(new Game(this), true);
// Add the libgdx view
layout.addView(gameView);
context = this;
uiThread = new Handler();
... (adding another view for mopub here, but removing this doesn´t change anything)
// Hook it all up
setContentView(layout);
}
#Override
public void showAP() {
uiThread.post(new Runnable(){
public void run(){
apSmartWall.startSmartWallAd();
}
});
}
libGDX Thread stuff: https://code.google.com/p/libgdx/wiki/TheArchitecture#The_Graphics_Module
I also tried using libGDX built in handler method, AndroidApplication.runOnUiThread() but that didn´t work either. I am by no means experienced when it comes to native Android so there might be something I´ve done wrong. But like I said it´s working fine for other stuff that runs on the UI Thread, for example this works fine:
#Override
public void resumeAds() {
uiThread.post(new Runnable(){
public void run() {
moPubView = new MoPubView(context);
// non-tablet
if(width >= 728)
moPubView.setAdUnitId(TABLET_SIZE);
else
moPubView.setAdUnitId(PHONE_SIZE);
moPubView.loadAd();
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(moPubView, adParams);
}
});
}
AndroidManifest.xml airpush things
<meta-data android:name="com.package.APPID" android:value="appid" />
<meta-data android:name="com.package.APIKEY" android:value="android*key"/>
<activity android:exported="false" android:name="com.package.SmartWallActivity"
android:configChanges="orientation|screenSize"
android:theme="#android:style/Theme.Translucent" />
<activity android:name="com.package.BrowserActivity"
android:configChanges="orientation|screenSize" />

Activity switching not working android

I am working on an android app that has two activities. One is the menu screen and the other is the one that the user actually uses once they have made a selection. The second activity does all of its processing in a worker thread. When I make the selection to move on to the second activity, it "flashes" the activity for about 100ms. I found some logs that look like they would tell me what I need to fix if I knew what they meant.
02-29 10:52:33.850: I/ActivityManager(1255): Starting activity: Intent { cmp=com.wcf.imageShare/.ImageShareActivity }
02-29 10:52:33.920: W/InputManagerService(1255): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy#45c0a198 (uid=10097 pid=24918)
02-29 10:52:33.936: W/WindowManager(1255): No window to dispatch pointer action
02-29 10:52:33.952: I/ActivityManager(1255): Displayed activity com.wcf.imageShare/.ImageShareActivity: 96 ms (total 96 ms)
02-29 10:52:34.000: W/WindowManager(1255): No window to dispatch pointer action 1
The program itself is not crashing, it just takes me back to the menuview and displays my choices again. Here is the code I am using to switch activities
lstServers.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Beacon.activeServer = position;
Intent uploadIntent = new Intent(inst,ImageShareActivity.class);
inst.startActivity(uploadIntent);
}
});
inst holds the 'this' variable of the activity that the code is running in since I couldn't reference it by using 'this'
Here is the onCreate of the activity I am trying to switch to:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
progBar = (ProgressBar)findViewById(R.id.progressbar_Horizontal);
tv = (TextView)findViewById(R.id.prog_txt);
btnCancel = (Button)findViewById(R.id.cancel);
btnCancel.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
try {
uploaderThread.interrupt();
Uploader.CancelUpload();
} catch (Exception e) {
e.printStackTrace();
}
}
});
uploaderThread.start();
}
catch(Exception e)
{
Log.d("Uploader ERROR",e.getMessage());
}
}
And finally the part of the manifest file that has to do with the two activities.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".ImageShareActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name=".ServerChoiceActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="image/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
Does anyone have any suggestions or know of something that I am missing?
Thanks
Nick Long
Change this to this :
lstServers.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Beacon.activeServer = position;
Intent uploadIntent = new Intent(your_current_activty.this,ImageShareActivity.class);
uploadIntent.startActivity();
}
});

Categories

Resources