SplashScreen - Time to close - android

I deployed a splash screen in my application with an Internet code, everything is working but cannot set a time for this activity close and open the main application could help me. I've tried the shape of the handler but closes the application after time.
package com.packpage.application;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;
import com.packpage.application.FontelloTextView;
import com.packpage.application.KenBurnsView;
public class SplashScreensActivity extends Activity {
public static final String SPLASH_SCREEN_OPTION = "com.packpage.application.SplashScreensActivity";
public static final String SPLASH_SCREEN_OPTION_1 = "Option 1";
public static final String SPLASH_SCREEN_OPTION_2 = "Option 2";
public static final String SPLASH_SCREEN_OPTION_3 = "Option 3";
private KenBurnsView mKenBurns;
private FontelloTextView mLogo;
private TextView welcomeText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE); //Removing ActionBar
setContentView(R.layout.activity_splash_screen);
mKenBurns = (KenBurnsView) findViewById(R.id.ken_burns_images);
mLogo = (FontelloTextView) findViewById(R.id.logo);
welcomeText = (TextView) findViewById(R.id.welcome_text);
mKenBurns.setImageResource(R.drawable.splash_screen_background);
String category = SPLASH_SCREEN_OPTION_1;
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey(SPLASH_SCREEN_OPTION)) {
category = extras.getString(SPLASH_SCREEN_OPTION, SPLASH_SCREEN_OPTION_1);
}
setAnimation(category);
}
/** Animation depends on category.
* */
private void setAnimation(String category) {
if (category.equals(SPLASH_SCREEN_OPTION_1)) {
animation1();
} else if (category.equals(SPLASH_SCREEN_OPTION_2)) {
animation2();
} else if (category.equals(SPLASH_SCREEN_OPTION_3)) {
animation2();
animation3();
}
}
private void animation1() {
ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(mLogo, "scaleX", 5.0F, 1.0F);
scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
scaleXAnimation.setDuration(1200);
ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(mLogo, "scaleY", 5.0F, 1.0F);
scaleYAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
scaleYAnimation.setDuration(1200);
ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(mLogo, "alpha", 0.0F, 1.0F);
alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
alphaAnimation.setDuration(1200);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(scaleXAnimation).with(scaleYAnimation).with(alphaAnimation);
animatorSet.setStartDelay(500);
animatorSet.start();
}
private void animation2() {
mLogo.setAlpha(1.0F);
Animation anim = AnimationUtils.loadAnimation(this, R.anim.translate_top_to_center);
mLogo.startAnimation(anim);
}
private void animation3() {
ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(welcomeText, "alpha", 0.0F, 1.0F);
alphaAnimation.setStartDelay(1700);
alphaAnimation.setDuration(500);
alphaAnimation.start();
}
}

Take a look at this tutorial
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Use Handler
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
SPLASH_TIME_OUT is time in milliseconds. Start your next activity inside run method

Related

Remove View after animation

I have a view that does an animation and then should be removed or at least sent to the back so i can reuse it. I'm having trouble attaching a listener to it.
I've been stuck on this for about 2 weeks so any help at all is really appreciated.
I'm just trying to get the card to fling off the screen, disappear and then be deleted.
package com.example.trevorwood.biggles.study;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.example.trevorwood.biggles.R;
public class StudyActivity extends AppCompatActivity {
LinearLayout mFlipCardLinearLayout;
LinearLayout mCardFlippedButtons;
FrameLayout mCardFrame;
View mCurrentAnimCardContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_study);
Intent intent = getIntent();
// String value = intent.getStringExtra("key");
Toolbar toolbar = (Toolbar) findViewById(R.id.study_toolbar);
toolbar.setTitleTextColor(Color.WHITE);//0xAARRGGBB
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mFlipCardLinearLayout = (LinearLayout) findViewById(R.id.flip_card_linear_layout);
mCardFlippedButtons = (LinearLayout) findViewById(R.id.card_flipped_buttons);
mCardFrame = (FrameLayout) findViewById(R.id.card_frame);
final Drawable upArrow = getResources().getDrawable(R.drawable.ic_back_arrow);
upArrow.setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
makeNewCard();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/HomeFragment button
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onBackPressed() {
super.onBackPressed();
}
public void onCardClick(View view) {
flipCard();
}
public void onCardFlippedButtonsClick(View view) {
Integer numberPressed;
switch (view.getId()){
case R.id.color_button_1:numberPressed = 1;break;
case R.id.color_button_2:numberPressed = 2;break;
case R.id.color_button_3:numberPressed = 3;break;
case R.id.color_button_4:numberPressed = 4;break;
case R.id.color_button_5:numberPressed = 5;break;
default:numberPressed = 0;
}
saveCardStats(numberPressed);
flingCardAway();
resetForNewCard();
makeNewCard();
}
private void flipCard() {
FrameLayout cardFrame = (FrameLayout) findViewById(R.id.card_frame);
Integer childCount = cardFrame.getChildCount();
Log.d("Simple","childCount: "+childCount);
View cardContainer = findViewById(R.id.card_container);
View cardFace = findViewById(R.id.card_front);
View cardBack = findViewById(R.id.card_back);
FlipAnimation flipAnimation = new FlipAnimation(cardFace, cardBack);
if (cardFace.getVisibility() == View.GONE) {
mFlipCardLinearLayout.setVisibility(View.VISIBLE);
mCardFlippedButtons.setVisibility(View.GONE);
flipAnimation.reverse();
}else{
mFlipCardLinearLayout.setVisibility(View.GONE);
mCardFlippedButtons.setVisibility(View.VISIBLE);
}
cardContainer.startAnimation(flipAnimation);
}
private void saveCardStats(Integer numberPressed){
}
private void flingCardAway(){
mCurrentAnimCardContainer = findViewById(R.id.card_container);
ViewCompat.setTranslationZ(mCurrentAnimCardContainer, 1.0f);
AnimationSet anim = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,-45, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF,0.5f );
rotate1.setStartOffset(100);
rotate1.setDuration(500);
anim.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, -0.1f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
trans1.setDuration(600);
anim.addAnimation(trans1);
AlphaAnimation opacity1 = new AlphaAnimation(1.0f, 0.0f);
opacity1.setDuration(400);
opacity1.setStartOffset(200);
anim.addAnimation(opacity1);
mCurrentAnimCardContainer.setAnimation(anim);
mCurrentAnimCardContainer.setVisibility(View.VISIBLE);
final FrameLayout cardFrame = (FrameLayout) findViewById(R.id.card_frame);
anim.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationStart(Animation arg0) {
}
#Override
public void onAnimationRepeat(Animation arg0) {
}
#Override
public void onAnimationEnd(Animation arg0) {
//The problem area, also this is not always called
// ((ViewGroup)mCurrentAnimCardContainer.getParent()).removeView(mCurrentAnimCardContainer);
// cardFrame.removeAllViews();
}
});
}
private void resetForNewCard(){
mFlipCardLinearLayout.setVisibility(View.VISIBLE);
mCardFlippedButtons.setVisibility(View.GONE);
}
private void makeNewCard(){
Integer childCount = mCardFrame.getChildCount();
Log.d("Simple","childCount: "+childCount);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.study_card, mCardFrame);
}
}
Is it just me or does making an Android app feel like you're constantly swimming against the current in a river.
Edit: If you want to see real improvement, explain why you think this is a bad question rather than just down voting.
I took out onAnimationEnd and just put the removeAllView method outside of it and it worked. Honestly I have no idea how this works. One would imagine that if you remove a View it cannot have an animation work on it.
private void flingCardAway(){
View currentAnimCardContainer = findViewById(R.id.card_container);
ViewCompat.setTranslationZ(currentAnimCardContainer, 1.0f);
AnimationSet anim = new AnimationSet(true);
RotateAnimation rotate1 = new RotateAnimation(0,-45, Animation.RELATIVE_TO_SELF,0.5f , Animation.RELATIVE_TO_SELF, 0.5f );
rotate1.setStartOffset(1);
rotate1.setDuration(400);
anim.addAnimation(rotate1);
TranslateAnimation trans1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.0f, Animation.RELATIVE_TO_PARENT, -1.5f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -0.5f);
trans1.setStartOffset(1);
trans1.setDuration(550);
anim.addAnimation(trans1);
AlphaAnimation opacity1 = new AlphaAnimation(1.0f, 0.0f);
opacity1.setStartOffset(300);
opacity1.setDuration(600);
anim.addAnimation(opacity1);
currentAnimCardContainer.startAnimation(anim);
mCardFrame.removeAllViews();
}

Closing Android Game After 5 Seconds

I'm tring to build an simple android game.
Users answer the questions, when the answer is correct, it is continue..
I want to add time control for each answer.
I tried to add handler function, but I didn't.
My Code;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class EasyGameActivity extends Activity {
public int score = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_easygame);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
finishScreen();
}
}, 5000);
startGame();
}
private void startGame() {
// TODO Auto-generated method stub
Button b1 = (Button)findViewById(R.id.answer_one);
Button b2 = (Button)findViewById(R.id.answer_two);
Button b3 = (Button)findViewById(R.id.answer_three);
Button b4 = (Button)findViewById(R.id.answer_four);
Random number = new Random();
int first = number.nextInt(100)+1;
int second = number.nextInt(100)+1;
int answer = first + second;
int rnd1 = answer + 1;
int rnd2 = answer + 2;
int rnd3 = answer - 1;
final String a = Integer.toString(answer);
String b = Integer.toString(rnd1);
String c = Integer.toString(rnd2);
String d = Integer.toString(rnd3);
((TextView) findViewById(R.id.display)).setText(Integer.toString(first) + '+' + Integer.toString(second));
List<Button> buttons = Arrays.asList(b1, b2, b3, b4);
List<String> texts = Arrays.asList(a, b, c, d);
Collections.shuffle(texts);
int i = 0;
OnClickListener onClick = new OnClickListener() {
public void onClick(View view) {
Button button = (Button) view;
String value = (String) button.getText();
if(value == a) {
checkTrue();
} else {
finishScreen();
}
}
};
for(Button button : buttons) {
button.setText(texts.get(i++));
button.setOnClickListener(onClick);
}
}
private void checkTrue() {
score++;
((TextView) findViewById(R.id.score)).setText(Integer.toString(score));
startGame();
}
private void finishScreen() {
score = 0;
startActivity (new Intent("com.bsinternet.mathfast.RESTARTGAMESCREEN"));
finish();
}
}
How can I add time control. Thanks.
This bit of code doesn't look right
if(value == a) {
checkTrue();
} else {
finishScreen();
}
You should be using equals() to check for String equality. At the moment you are checking only object equality, which will evaluate to False, and the code will never call checkTrue().
Do this instead:
if(value.equals(a) {
checkTrue();
} else {
finishScreen();
}

View Animation for updating progress

I am using a horizontal progress bar and I am trying to animate the bar filling up ( I load the amount of progress before the bar shows up).
This is what I'm doing so far but its not working:
progressBar = (ProgressBar)v.findViewById(R.id.rewards_progress);
Animation animation = new Animation() {
#Override
public void start() {
progressBar.setInterpolator(new AccelerateDecelerateInterpolator());
progressBar.setProgress(currentProgress);
}
};
animation.setDuration(1000);
animation.start();
Any suggestions?
If you just want to update the ProgressBar and as we said in previous comments, you need to do it in another thread, look at this dummy example based in the official Android doc:
package com.example.progressbar;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
private ProgressBar mProgress;
private static int mProgressStatus = 0;
private Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgress = (ProgressBar) findViewById(R.id.rewards_progress);
new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 100) {
doWork();
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
private void doWork(){
try {
Thread.sleep(100);
mProgressStatus+=2;
} catch (InterruptedException e) {
}
}
}
However, if you want to animate the ProgressBar update effect, there are several ways to achieve it. One particular way described in this post looks and works pretty good could be easily done by:
package com.example.progressbar;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
private ProgressBar mProgress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgress = (ProgressBar) findViewById(R.id.rewards_progress);
ProgressBarAnimation anim = new ProgressBarAnimation(mProgress, 0, 100);
anim.setDuration(5000);
mProgress.startAnimation(anim);
}
public class ProgressBarAnimation extends Animation{
private ProgressBar progressBar;
private float from;
private float to;
public ProgressBarAnimation(ProgressBar progressBar, float from, float to) {
super();
this.progressBar = progressBar;
this.from = from;
this.to = to;
}
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
super.applyTransformation(interpolatedTime, t);
float value = from + (to - from) * interpolatedTime;
progressBar.setProgress((int) value);
}
}
}
Note that you should customize ProgressBarAnimation's parameters from and to in order to apply it in a realistic approach.

Need help fixing my class: 'This Handler class should be static or leaks might occur'

I created a simple crossfade image class for use in my app. But... i have an error i can't fix due to lack of knowledge. I found this post This Handler class should be static or leaks might occur: IncomingHandler but i have no clue how to fix this in my class. It is a very straightforward class. Create, initialize and start to use it.
I hope someone can help me fix this warning and while we are at it, some hints and tips on my code or comments are very welcome too ;)
MainActivity.java
package com.example.crossfadeimage;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
Xfade xfade = new Xfade();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// INIT(current activity, image id's, time between fades, fade speed)
xfade.init(this, new int[]{ R.id.image1, R.id.image2, R.id.image3 }, 3000, 500);
xfade.start();
}
}
Xfade.java
package com.example.crossfadeimage;
import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.ImageView;
public class Xfade {
private Activity activity;
// Handler
private Handler handlerTimer = new Handler();
private static final int UPDATE_STUFF_ON_DIALOG = 999;
private int updateTime;
private Animation fadeIn;
private Animation fadeOut;
public int[] xfadeImages;
public int xfadeCounter = 1;
public void init(Activity thisActivity, int[] images, int time,
int animationSpeed) {
activity = thisActivity;
xfadeImages = images;
updateTime = time;
// Set Animations
fadeIn = new AlphaAnimation(0, 1);
fadeIn.setDuration(animationSpeed);
fadeOut = new AlphaAnimation(1, 0);
fadeOut.setDuration(animationSpeed);
// Hide all images except the first
// which is always visible
for (int image = 1; image < xfadeImages.length; image++) {
ImageView thisImage = (ImageView) activity
.findViewById(xfadeImages[image]);
thisImage.setVisibility(4);
}
}
public void start() {
handlerTimer.removeCallbacks(taskUpdateStuffOnDialog);
handlerTimer.postDelayed(taskUpdateStuffOnDialog, updateTime);
}
private Runnable taskUpdateStuffOnDialog = new Runnable() {
public void run() {
Message msg = new Message();
msg.what = UPDATE_STUFF_ON_DIALOG;
handlerEvent.sendMessage(msg);
// Repeat this after 'updateTime'
handlerTimer.postDelayed(this, updateTime);
}
};
private Handler handlerEvent = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case UPDATE_STUFF_ON_DIALOG: {
crossFade();
}
break;
default: {
super.handleMessage(msg);
}
break;
}
}
};
public void crossFade() {
if (xfadeCounter == 0) {
ImageView lastImage = (ImageView) activity
.findViewById(xfadeImages[xfadeImages.length - 1]);
lastImage.setVisibility(4);
}
if (xfadeCounter < xfadeImages.length) {
ImageView thisImage = (ImageView) activity
.findViewById(xfadeImages[xfadeCounter]);
thisImage.setVisibility(0);
thisImage.startAnimation(fadeIn);
xfadeCounter++;
} else {
// Hide all images except the first
// before fading out the last image
for (int image = 1; image < xfadeImages.length; image++) {
ImageView thisImage = (ImageView) activity
.findViewById(xfadeImages[image]);
thisImage.setVisibility(4);
}
// Fadeout
ImageView lastImage = (ImageView) activity
.findViewById(xfadeImages[xfadeImages.length - 1]);
lastImage.startAnimation(fadeOut);
// LastImage is faded to alpha 0 so it doesn't have to be hidden
// anymore
xfadeCounter = 1;
}
}
}
This allows you to modify views and have your handler set to static.
package com.testing.test;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class MainActivity extends Activity implements Runnable {
private static final int THREAD_RESULT = 1000;
private TextView mTextView;
private static Handler mHandler;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text);
}
#Override
protected void onResume() {
super.onResume();
mHandler = new CustomHandler(this);
new Thread(this).start();
}
#Override
public void run() {
// Do some threaded work
// Tell the handler the thread is finished
mHandler.post(new Runnable() {
#Override
public void run() {
mHandler.sendEmptyMessage(THREAD_RESULT);
}
});
}
private class CustomHandler extends Handler {
private MainActivity activity;
public CustomHandler(MainActivity activity) {
super();
this.activity = activity;
}
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case THREAD_RESULT:
activity.mTextView.setText("Success!");
break;
}
}
}
}

Android stop SoundPool loop across multi activities. Or stop all playing sounds when changing pages

I have only been programming with Android and Java for a few weeks now, trying to make a guitar tuner to tune your guitar by ear. A simple reference tuner. I have used much of this website code to construct it.
How can I make a SoundPool stop when I click to another page/activity.
Currently I have two pages, each with 7 sound buttons. When you click any button it loops indefinitely until you click another button, then that loops and so on... If I click the button for the next page and then click a new button, the sound from the last page is still playing! rather annoying when you are trying to tune your guitar by ear!
Maybe just a simple stop button to stop the entire SoundPool would be a good idea?
Here is my SoundManager code
package org.gtdb.guitar_tuners;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
public class SoundManager
{
private Context pContext;
private SoundPool sndPool;
private float rate = 1.0f;
private float masterVolume = 1.0f;
private float leftVolume = 1.0f;
private float rightVolume = 1.0f;
private float balance = 0.5f;
// Constructor, setup the audio manager and store the app context
public SoundManager(Context appContext)
{
sndPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100);
pContext = appContext;
}
// Load up a sound and return the id
public int load(int sound_id)
{
return sndPool.load(pContext, sound_id, 1);
}
// Play a sound
public void play(int sound_id)
{
sndPool.play(sound_id, leftVolume, rightVolume, 100, -1, rate);
}
// Set volume values based on existing balance value
public void setVolume(float vol)
{
masterVolume = vol;
if(balance < 1.0f)
{
leftVolume = masterVolume;
rightVolume = masterVolume * balance;
}
else
{
rightVolume = masterVolume;
leftVolume = masterVolume * ( 2.0f - balance );
}
}
public void setSpeed(float speed)
{
rate = speed;
// Speed of zero is invalid
if(rate < 0.01f)
rate = 0.01f;
// Speed has a maximum of 2.0
if(rate > 2.0f)
rate = 2.0f;
}
public void setBalance(float balVal)
{
balance = balVal;
// Recalculate volume levels
setVolume(masterVolume);
}
// Free ALL the things!
public void unloadAll()
{
sndPool.release();
}
}
Here is my Activity code Main.java
package org.gtdb.guitar_tuners;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import android.widget.LinearLayout;
public class Main extends Activity {
SoundManager snd;
int string1, string2, string3, string4, string5, string6, string7;
OnClickListener buttZonClick;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout) findViewById(R.id.adMobUnit);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
AdView adView = new AdView(this, AdSize.IAB_MRECT, "aaaaaaaaaaaaa");
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
// Create an instance of our sound manger
snd = new SoundManager(getApplicationContext());
// Load the samples from res/raw
string1 = snd.load(R.raw.eadgbe1);
string2 = snd.load(R.raw.eadgbe2);
string3 = snd.load(R.raw.eadgbe3);
string4 = snd.load(R.raw.eadgbe4);
string5 = snd.load(R.raw.eadgbe5);
string6 = snd.load(R.raw.eadgbe6);
string7 = snd.load(R.raw.eadgbestrum);
/** Tuner Link **/
Button b1 = (Button) findViewById(R.id.tuner1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Main.this, Dadgad.class));
}
});
/** Tuner Link **/
Button b2 = (Button) findViewById(R.id.tuner2);
b2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Main.this, Daefce.class));
}
});
/** gtdb.org Link **/
ImageButton b7 = (ImageButton) findViewById(R.id.imageButton1);
b7.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://www.gtdb.org/stats/click.php?id=17"));
startActivity(i);
}
});
}
public int count = 0;
// Button listener assigned in XML layout
public void clickHandler(View v) {
int id = v.getId(); // Use the button id to determine which sample
// should be played
switch (id) {
case R.id.button1:
snd.play(1);
break;
case R.id.button2:
snd.play(2);
break;
case R.id.button3:
snd.play(3);
break;
case R.id.button4:
snd.play(4);
break;
case R.id.button5:
snd.play(5);
break;
case R.id.button6:
snd.play(6);
break;
case R.id.button7:
snd.play(7);
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.item1) {
Toast.makeText(Main.this,
"Android Guitar Tuner App from Guitar Tunings Database - www.gtdb.org",
Toast.LENGTH_LONG).show();
}
return super.onOptionsItemSelected(item);
}
}
Apologies for the code, I might imagine that it's a mess as I am basically a newbie at Java and Android. I have been piecing together from other peoples code and from watching lynda.com videos.
The current version of my tuner is on the market but it has no loop on the sounds so you can go through the pages and listen. but without a loop on it you have to keep pressing the button to tune your guitar! you can see that here
Does Soundpool.stop(int) work for you? If so, why not just override the Activity.onPause() method and put it there?

Categories

Resources