So I have seen some other posts similar, but not quite answering what I am looking for.
Basically onCreate is loading in the content (being textviews and image) and it also opens up another thread to prepare the media player so that when the button is pressed it plays a specific song. If this activity is opened and the button is pressed quickly it does not play anything (which I am assuming because it hasn't had a chance to prepare). If I open the activity and give it a few moments it works just fine. I do realize that it is not best to run the content being loaded in onCreate, but I have tried to get it to load in other threads and it failed miserably. It is all fine with me what I really want to happen is this.
I need some way to prevent use of the button or let them know it is loading for about 3-5 seconds. So either make the button be faded out and unusable for 3-5 seconds and then it becomes active or a loading screen that is some what transparent that covers the activity for about 3-5 seconds. If you mention using other threads could you please demonstrate it if it isn't asking to much or show me something like a tutorial (other than googles notes). I don't understand threads very well yet (pretty new to them) and the AsyncThread is pretty confusing to me.
If you need code let me know what you would want posted. Thanks and I appreciate any help.
You can set an setOnPreparedListener on your MediaPlayer, in this listener you enable your button and be save that the song can be played.
Docs
I would create an xml selector file governing button behaviour. Something like:
<?xml version="1.0" encoding="utf-8"?>
<item android:state_enabled="true" android:drawable="#drawable/lbl_black_matte" />
<item android:state_enabled="false" android:drawable="#android:color/transparent">
</item>
Then, in your activity:
private Button mActivate;
mActivate = (Button) findViewById(R.id.activate);
mActivate.setOnClickListener(this);
Then somewhere, you'll check to see if the magic is ready, and activate the button if so:
if (mEnabled) {
mActivate.setEnabled(true);
}
Finally, you'll have to reference the button behaviour selector in the xml document in which the button is created.
android:layout_width="match_parent">
<Button android:id="#+id/activate"
android:background="#drawable/b_behaviour" android:layout_height="wrap_content"
android:layout_margin="8dip" android:layout_width="match_parent"
android:text="#string/setup_label_enable" android:textColor="#android:color/white"
android:textStyle="bold">
</Button>
Please let me know if that's clear or if you need me to explain how to create the click listener.
Good luck!
Related
I have a 'Play'button set up in an XML layout file,
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="play"
android:onClick="playButton"
/>
and I want to make it so that when I click on the button, an action dialog shows in which there are two buttons that say 'Play' and 'Stop'.
When I click on the Play button I want the app to record whatever the user is saying to the microphone and when the 'Stop' button is pressed, save that mp3 into resources.
How can I make this? I'm right now really confused because my
and yes, I've seen the Android documentation & sample codes on Media Recorder and I still don't get it...
try to see this resource on Github android-MediaRecorder
make something similar that you dear, but use camera of the devices. By the way you can start from here and make some adjustment
By the way , you can find more project like this, ad example this AndroidAudioRecorder
that are already did.
Maybe this can be help you
Have a nice work!
How can one create a wave like animation, like the one which appears when one touches the screen on an Android 4.0 lock screen.
I have something similar in one of my app. The way I did is putting the whole wave as one big image then you repeatedly change it's source in background to give it animated look & feel.
Basically, when onTouchUp you start the animation and have it loop and update the image sources until finish. Then you switch its source to the original image in onAnimationFinish.
That's just from the top of my head so I'm not sure if it's accurate or not. I reckon you get the idea anyway. If there's easier way to pull it off then I'm willing to listen as well.
here is the solution you want to implement let me know if it doesn't work.
Code sample :-
Add a TitanicTextView to your layout:
<com.romainpiel.titanic.TitanicTextView
android:id="#+id/titanic_tv"
android:text="#string/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#212121"
android:textSize="70sp"/>
To start the animation:
titanic = new Titanic();
titanic.start(myTitanicTextView);
You may want to keep track of the titanic instance after the animation is started if you want to stop it.
To stop it:
titanic.cancel();
I've read several example programs and tutorials to try and solve my problem but they all seem to go the same way. I've used a couple Activities and xml documents to create a menu that loads when my game starts. When the user clicks the "Start The Game" button, it loads a new Activity that sets the view with my game thread and all of the game properties. I know this activity works because I've run it alone as its own project, but every way I've tried to start it after the Menu, I get a nullPointerException and it force closes. I read the SurfaceViewOverlay tutorial and attempted to use that implementation, but I'm using a SurfaceView, not a GLSurfaceView. I'm debating rewriting my entire program to use OpenGL but I figured I would see if anyone else knows what I'm doing wrong here. If you need the code snippets I can paste some here, but it's not really the specific code that's wrong, I think it's the way I'm using(abusing) the language...
Thanks for any help,
Aaron
I discovered my problem quite some time ago, but figured I would come back and give an answer to anyone else having my problem. When using a SurfaceView it must be part of the activity that created it and be in some sort of FrameLayout in the xml for that activity.
For example:
<com.example.MySurfaceView
android:id="#+id/mySurfaceView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
You can add any other layout elements you would like, but this is required to create the SurfaceView. I hope this helps anyone else who had my problem, for any further questions just ask and I'll be sure to elaborate if necessary.
First off I am a beginner in Android development; I have been doing a lot of research into how to get the various tasks I am trying to complete. I have yet to find any similar issue to this, which is why I am asking it.
This is a multipart question.
Overview of program and problems: I have a program (for Android 2.1 and higher) that has multiple fullscreen Activities. I am required to have a different animation for transitioning to each one. So I reconfigured a couple files and made a ViewFlipper to do the transitions. Unfortunately some of these activities use a title. At the same time the transitions that I have tried applying based on the tutorials I have found online are not working as expected. The transition begins, the second screen is shown (faded) and the background is black, as the second screen nears completion of the transition the first screen reappears before disappearing again.
Question 1: Is there a way to display some layouts with a title and some without? If not then is there a way to change the transition used when startActivity is used?
Question 2: Is there some method of doing a fade transition without it flashing the original screen? I looked up the "flicker" issue but the solutions are not working for my project.
Question 3: In a similar manner to the 2nd question, the first layout shown is a loading screen, then the main screen. This happens just fine but for some reason the loading screen is shown, then slides off (as if startActivity is called) and then it fades into existence again (this time with a title which isn't supposed to be there), then switches to the main screen correctly. What might be happening here?
If you have any questions, feel free to ask.
Q1: yes it's possible, you can set the flag for each activity
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
or in xml via style:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
Q2: yes, that should be the usual way. But to answer your question we need to see the code you're using. If you want to change the transitions of an activity (not view), you can put in it's onCreate method:
super.overridePendingTransition(R.anim.bounce, R.anim.fadeout);
to define which animation to show when the activity enters the screen. You can use the same method in onFinish().
Q3: as Q2: need to see your code.
I have an app widget which runs neatly. However, I am unable to highlight a click on a linked item. I've seen it in the standard app widgets like 'Music' and 'Power Control', for instance. Moreover, I've also been studying the Music app widget's source at album_appwidget.xml. The only thing I could think of is the LinearLayout defined at lines 23-35 which states
android:clickable="true"
Unfortunately, this does not work for me. So does anyone have a hint on how to highlight a click on an app widget? I've tried the LinearLayout, TextView and Button. None of them displayed a border as a highlight.
Thanks in advance,
Steff
you need to create images for those states like focussed state, pressed etc like in a button and define them in your background.
Try looking at the custom buttons where its explained how to accomplish the task thats similar to your needs.
http://www.gersic.com/blog.php?id=56.
if you want to look more and add more states you may ge better idea if you look at the android source code for buttons where they have images for each state of the button and every other widget.