Android - Why the click event isn't trigged - android

I'm facing a problem with the focus on my application. I'm trying to catch the click event to animate my edittext, but for a reason I don't understand, sometimes my edittext is focused but the click event is not trigged.
The user has to click a 2nd time to start the animation.
I've got 2 AutocompleteTextView in my SherlockFragment.
Is it possible that come from the animation I'm doing ?
Edit:
mEtWhere.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d(TAG, "mEtWhere've been clicked");
if (!mllWhereHasBeenClicked) {
mllWhereHasBeenClicked = true;
if (mAlphaFrameLayout != null) {
animate(mAlphaFrameLayout).setDuration(ANIM_DURATION / 2).alpha(0.9f);
}
if (mllWhere != null) {
oldllWhereYpos = ViewHelper.getY(mllWhere);
Log.v(TAG, "OldYWhereLLpos: " + oldllWhereYpos);
animate(mllWhere).setDuration(ANIM_DURATION).y(25.0f);
mBringToFrontView(mllWhere);
}
}
}
});
This is the code to reset the position of all my edittexts
private void resetPositionViews() {
closeKeyBoard();
if (mAlphaFrameLayout != null && ViewHelper.getAlpha(mAlphaFrameLayout) > 0.0f) {
animate(mAlphaFrameLayout).setDuration((7 / 4) * ANIM_DURATION).alpha(0.0f);
mBringToFrontView(mAlphaFrameLayout);
}
if (ViewHelper.getY(mllWho) == 25.0f && mEtWho.isFocused() && mllWhoHasBeenClicked) {
Log.i(TAG, "mEtWho has the focus");
Log.i(TAG, "Back to oldllWhoYpos: " + oldllWhoYpos);
animate(mllWho).setDuration(ANIM_DURATION).y(oldllWhoYpos);
mllWhoHasBeenClicked = false;
}
if (ViewHelper.getY(mllWhere) == 25.0f && mEtWhere.isFocused() && mllWhereHasBeenClicked) {
Log.i(TAG, "mEtWho has the focus");
Log.i(TAG, "Back to oldllWhoYpos: " + oldllWhereYpos);
animate(mllWhere).setDuration(ANIM_DURATION).y(oldllWhereYpos);
mllWhereHasBeenClicked = false;
}
}

Related

How to make imageView background change one time

if (buttonClicked.contains(1) && buttonClicked.contains(2)) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
if (buttonClicked.contains(3) && buttonClicked.contains(4) && buttonClicked.contains(5)) {
if (playerOneLastClicked) {
imgViewBackground2.setImageResource(R.drawable.rca)
} else {
imgViewBackground4.setImageResource(R.drawable.wac)
}
}
when player1 or player2 last click in (buttonClicked.contains(1) && buttonClicked.contains(2)) imgViewBackgound1 change but when the players click button 3,4 or 5 imgViewBackground keep changing.
I want when imgViewBackground1 take (R.drawable.rca) or (R.drawable.wac) don't change any more.
If imgViewBackground is not going to have an imageview you could just add an extra check e.g.
if (imgViewBackground1.drawable == null) {
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}
or if it would have an imageview already and you don't want it set again
if (imgViewBackground1.drawable != resources.getDrawable(R.drawable.rcs, null)
|| imgViewBackground1.drawable != resources.getDrawable(R.drawable.wac, null))
if (playerOneLastClicked) {
imgViewBackground1.setImageResource(R.drawable.rca)
} else {
imgViewBackground1.setImageResource(R.drawable.wac)
}
}
}

MediaPlayer is not running the previous sound in android either after released the object and initialized its again

There are two onClickListener one for move forward and the second one is to move backward. I have an array of images, sounds and texts. by pressing forward it moves to the next record and with backward it moves to previous. I faced an issue that if a sound played for a single time at any position. when i tried to move on it by pressing backward then the sound isn't plays. it only plays for a single time if i want to plays it more than one time it isn't plays and break and generates an exception of null pointer to global_media_player. Here global_media_player is the global object.
forward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (count >= 0 && count < (list.size() - 1)) {
count++;
Toast.makeText(getApplicationContext(),"Before Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
// if(global_media_player.isPlaying()) {
// global_media_player.stop();
// Toast.makeText(getApplicationContext(),"During Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
// }
BookData data = list.get(count);
textView.setText(data.getName());
imageView.setImageDrawable(data.getImage());
Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
textView.startAnimation(slide);
try {
Toast.makeText(getApplicationContext(),"Before Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
if (global_media_player != null) {
global_media_player.release();
Toast.makeText(getApplicationContext(),"During Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(),"Before Initialing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
global_media_player = data.getAudio();
Toast.makeText(getApplicationContext(),"Before Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
global_media_player.start();
Toast.makeText(getApplicationContext(),"After Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
backward.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (count > 0 && count < list.size()) {
count--;
Toast.makeText(getApplicationContext(),"Before Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
// if(global_media_player.isPlaying()) {
// global_media_player.stop();
// Toast.makeText(getApplicationContext(),"During Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
// }
BookData data = list.get(count);
textView.setText(data.getName());
imageView.setImageDrawable(data.getImage());
Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
textView.startAnimation(slide);
try {
Toast.makeText(getApplicationContext(),"Before Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
if (global_media_player != null) {
global_media_player.release();
global_media_player = null;
Toast.makeText(getApplicationContext(),"During Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(),"Before Initialing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
global_media_player = data.getAudio();
Toast.makeText(getApplicationContext(),"Before Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
global_media_player.start();
Toast.makeText(getApplicationContext(),"After Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}
}
}
});

How to do google inapp purchase in an adapter class

I am developing an app which has google in app purchase. There is a button buy now and after clicking the button I have to call inapp purchase but here is the problem I am facing, the buy now button is in an adapter class hence how can I do inapp purchase in an adapter class
here is my code
public void onClick(View v) {
switch (v.getId()) {
case R.id.loadmore_btn:
// call a url with ofset & limit with Thread
if (getbookItems.getContentName() == "LoadMore") {
booksItemsInfo.remove(booksItemsInfo.size() - 1);
}
if (UIAndDataLoader.offset < bookcategoryItem.getCount()) {
if (UIAndDataLoader.offset < DBTotalContentCount) {
UIAndDataLoader.offset = UIAndDataLoader.offset + 10;
UIAndDataLoader.loadFlag = 0;
myActivity.Tostart();
} else {
myActivity.URLConfig = MagURLConfig.bURL
+ MagURLConfig.uMAILIDNAME
+ _Settings.getString("setEmail-ID", null)
+ MagURLConfig.uPASSWORD
+ _Settings.getString("setPassword", null)
+ MagURLConfig.CATEGORYID
+ bookcategoryItem.getCatId() + MagURLConfig.OFFSET
+ DBTotalContentCount + MagURLConfig.LIMIT;
UIAndDataLoader.bookcountlimit = 1;
myActivity.toStartRefresh(true);
}
}
break;
case R.id.btn_buynow:
// System.out.println("this is buy btn------------->");
BookDataLoader.ActionButtonOnclick(btn_txt, action_btn,
getbookItems, "");
break;
case R.id.preview:
BookDataLoader.ActionButtonOnclick(btn_txt, action_btn,
getbookItems, "Preview");
break;
}
}
}
You can declare the adapter class in the same activity.thats why you can user mHelper object.
I done the same functionality in one of application for in puchase item.
like:-
holder.relative_layout_btn_buy.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
if(isOnline())
mHelper.launchPurchaseFlow(OnlineStoreList.this,"android.test.purchased",RC_REQUEST,mPurchaseFinishedListener, "");
else
{
NetworkAlert();
}
} catch (Exception e) {
// Toast.makeText(getApplicationContext(),"Please wait...Try after some time!! " ,1).show();
Log.e("Exception", "===>" + e.toString());
complain(e.getMessage());
}
}
});
I hope with will help.Thanks!!

Chromecast SDK (Android) - is there a way to check whether the media playing on the cast device has finished playing?

Is there an onFinished listener of some sort? Or do we have to compare the current stream position against the duration of the track?
It's not pretty but you can make this call:
if (mRemoteMediaPlayer.getMediaStatus().getPlayerState() == MediaStatus.PLAYER_STATE_IDLE
&& mRemoteMediaPlayer.getMediaStatus().getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) {
...
}
Prem,
There is currently no callback to register for such event. One alternative (and-not-so-pretty) approach is the following: on the receiver, listen for "ended" event of the media element and send an event back to the sender through a private channel. Another approach is what you suggested: check position against duration. When SDK graduates to general availability, better and cleaner approaches will be available to accomplish what you want.
Here is solution:
You just need to take one more variable mIdleReason.
1) Initialize mIdleReason as
public int mIdleReason=MediaStatus.IDLE_REASON_NONE;
2) Update value at method loadMedia
public void loadMedia(String url, MediaMetadata movieMetadata, CastSession castSession, boolean autoPlay, long position) {
if (castSession == null || !castSession.isConnected()) {
return;
}
MediaInfo mediaInfo = new MediaInfo.Builder(url)
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.setContentType("videos/m3u8")
.setMetadata(movieMetadata)
.build();
mRemoteMediaClient = castSession.getRemoteMediaClient();
mRemoteMediaClient.addListener(mRemoteMediaClientListener);
mRemoteMediaClient.load(mediaInfo, autoPlay, position);
mIdleReason = MediaStatus.IDLE_REASON_NONE;
}
3) Update value at onStatusUpdate:
private RemoteMediaClient.Listener mRemoteMediaClientListener = new RemoteMediaClient.Listener() {
#Override
public void onStatusUpdated() {
if (mRemoteMediaClient == null || mediaPlayerListener == null) {
return;
}
MediaStatus mediaStatus = mRemoteMediaClient.getMediaStatus();
if (mediaStatus != null) {
int playerStatus = mediaStatus.getPlayerState();
Log.d("PlayerState", "onStatusUpdated() called, progress= "+mSeekBar.getProgress() +", stream duration= "+ mRemoteMediaClient.getStreamDuration()+" mSeekBar.getProgress() == mRemoteMediaClient.getStreamDuration()="+(mSeekBar.getProgress() == mRemoteMediaClient.getStreamDuration()));
Log.d("PlayerState", "onStatusUpdated() called playerStatus="+playerStatus+", idleReason="+mediaStatus.getIdleReason());
if (playerStatus == MediaStatus.PLAYER_STATE_PLAYING) {
mediaPlayerListener.playing();
mIdleReason = MediaStatus.IDLE_REASON_FINISHED;
} else if (playerStatus == MediaStatus.PLAYER_STATE_BUFFERING) {
mediaPlayerListener.buffering();
mIdleReason = MediaStatus.IDLE_REASON_FINISHED;
} else if (playerStatus == MediaStatus.PLAYER_STATE_PAUSED) {
mediaPlayerListener.paused();
} else if (playerStatus == MediaStatus.IDLE_REASON_INTERRUPTED) {
mediaPlayerListener.error();
} else if (playerStatus == MediaStatus.IDLE_REASON_ERROR) {
mediaPlayerListener.error();
}else if(playerStatus == MediaStatus.PLAYER_STATE_IDLE && mediaStatus.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED&& mIdleReason == MediaStatus.IDLE_REASON_FINISHED){
mediaPlayerListener.played();
}
}
}
#Override
public void onMetadataUpdated() {
Log.d("", "onMetadataUpdated: ");
}
#Override
public void onQueueStatusUpdated() {
Log.d("", "onQueueStatusUpdated: ");
}
#Override
public void onPreloadStatusUpdated() {
Log.d("", "onPreloadStatusUpdated: ");
}
#Override
public void onSendingRemoteMediaRequest() {
Log.d("", "onSendingRemoteMediaRequest: ");
}
#Override
public void onAdBreakStatusUpdated() {
Log.d("", "onAdBreakStatusUpdated: ");
}
};

on scrolling in listview get force close

i write a code in onScrollStateChanged event of listview .
but when scroll changed fast, get force close .
public void onScrollStateChanged(AbsListView arg0, int arg1) {
try {
int getCur = (lstName.getLastVisiblePosition() + 1) % maxName;
if (myCR != null) {
if (getCur == 0) {
Parcelable state = lstName.onSaveInstanceState();
fillList();
lstName.onRestoreInstanceState(state);
}
}
} catch (Exception e) {
}
}
Completed Logcat :
http://up.persianscript.ir/uploads/137181658700741.zip

Categories

Resources