Alert Dialog pops up 27 times in handler - android

My alert dialog keep pops up for 27 times. I have implement handler and inside the handler, i use the CountDownTimer. Alert dialog code is on CountDownTimer's onFinish. Below are my codes.
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.face_detect_surface_view);
mOpenCvCameraView = (Tutorial3View) findViewById(R.id.tutorial3_activity_java_surface_view);
mOpenCvCameraView.setCvCameraViewListener(this);
mPath=getFilesDir()+"/facerecogOCV/";
labelsFile= new labels(mPath);
Iv=(ImageView)findViewById(R.id.imageView1);
textresult = (TextView) findViewById(R.id.textView1);
mHandler = new Handler() {
#Override
public void handleMessage( Message msg) {
Log.e("X", (String) msg.obj);
if (msg.obj=="IMG")
{
Canvas canvas = new Canvas();
canvas.setBitmap(mBitmap);
Iv.setImageBitmap(mBitmap);
if (countImages>=MAXIMG-1)
{
toggleButtonGrabar.setChecked(false);
grabarOnclick();
}
}
else
{
textresult.setText(msg.obj.toString());
textpercent.setVisibility(View.VISIBLE);
textpercent.setText( mLikely + "%");
new CountDownTimer(5000, 1000) {
#Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
mOpenCvCameraView.enableView();
}
#Override
public void onFinish() {
// TODO Auto-generated method stub
final AlertDialog ad = new AlertDialog.Builder(FdActivity.this).create();
ad.setTitle("Recognition Status");
ad.setMessage("Criminal ID :" + textresult.getText().toString() + "\nSimilarities : " + textpercent.getText().toString() );
ad.setButton("Rescan", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getApplicationContext(),
"Rescanning", Toast.LENGTH_SHORT).show();
Bundle configBundle = new Bundle();
onCreate(configBundle);
mOpenCvCameraView.enableView();
}
});
ad.show();//pops out 27 times
mOpenCvCameraView.disableView();
buttonSearch.setChecked(false);
}
}.start();
}
}
};
text=(EditText)findViewById(R.id.editText1);
buttonCatalog=(Button)findViewById(R.id.buttonCat);
toggleButtonGrabar=(ToggleButton)findViewById(R.id.toggleButtonGrabar);
buttonSearch=(ToggleButton)findViewById(R.id.buttonBuscar);
toggleButtonTrain=(ToggleButton)findViewById(R.id.toggleButton1);
textState= (TextView)findViewById(R.id.textViewState);
textpercent = (TextView)findViewById(R.id.textViewpercent);
imCamera=(ImageButton)findViewById(R.id.imageButton1);
textpercent.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.INVISIBLE);
toggleButtonGrabar.setVisibility(View.INVISIBLE);
text.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((text.getText().toString().length()>0)&&(toggleButtonTrain.isChecked()))
toggleButtonGrabar.setVisibility(View.VISIBLE);
else
toggleButtonGrabar.setVisibility(View.INVISIBLE);
return false;
}
});
toggleButtonTrain.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (toggleButtonTrain.isChecked()) {
textState.setText(getResources().getString(R.string.SEnter));
buttonSearch.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.VISIBLE);
text.setVisibility(View.VISIBLE);
textresult.setText(getResources().getString(R.string.SFaceName));
if (text.getText().toString().length() > 0)
toggleButtonGrabar.setVisibility(View.VISIBLE);
textpercent.setVisibility(View.INVISIBLE);
} else {
textState.setText(R.string.Straininig);
textresult.setText("");
text.setVisibility(View.INVISIBLE);
buttonSearch.setVisibility(View.VISIBLE);
;
textresult.setText("");
{
toggleButtonGrabar.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
}
Toast.makeText(getApplicationContext(), getResources().getString(R.string.Straininig), Toast.LENGTH_LONG).show();
fr.train();
textState.setText(getResources().getString(R.string.BLANK));
}
}
});
toggleButtonGrabar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
grabarOnclick();
}
});
imCamera.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mChooseCamera==frontCam)
{
mChooseCamera=backCam;
mOpenCvCameraView.setCamBack();
}
else
{
mChooseCamera=frontCam;
mOpenCvCameraView.setCamFront();
}
}
});
buttonSearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (buttonSearch.isChecked())
{
if (!fr.canPredict())
{
buttonSearch.setChecked(false);
Toast.makeText(getApplicationContext(), getResources().getString(R.string.SCanntoPredic), Toast.LENGTH_LONG).show();
return;
}
textState.setText(getResources().getString(R.string.SSearching));
toggleButtonGrabar.setVisibility(View.INVISIBLE);
toggleButtonTrain.setVisibility(View.INVISIBLE);
text.setVisibility(View.INVISIBLE);
faceState=SEARCHING;
textresult.setVisibility(View.VISIBLE);
}
else
{
faceState=IDLE;
textState.setText(getResources().getString(R.string.SIdle));
toggleButtonGrabar.setVisibility(View.INVISIBLE);
toggleButtonTrain.setVisibility(View.VISIBLE);
text.setVisibility(View.INVISIBLE);
textresult.setVisibility(View.INVISIBLE);
}
}
});
boolean success=(new File(mPath)).mkdirs();
if (!success)
{
Log.e("Error", "Error creating directory");
}
}
Somebody please help me to fix this problem. I am still a learner in Android Programming. I did not have idea on how to fix this.
Thanks

I think your handler gets passed that amount of messages. You could verify that with a
Log.e("X", msg.obj);
and check the logcat for that output.

Related

AdMob rewarded videos always onRewardedVideoAdFailedToLoad

My code is here
I have test it on my device I also integrate this app on firebase.
but it never go to onRewarded it always call onRewardedFaild why sir?
can anyone help me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this,APP_ID);
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
// Create the "retry" button, which tries to show an interstitial between game plays.
mRetryButton = ((Button) findViewById(R.id.retry_button));
mRetryButton.setVisibility(View.INVISIBLE);
mRetryButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startGame();
}
});
// Create the "show" button, which shows a rewarded video if one is loaded.
mShowVideoButton = ((Button) findViewById(R.id.watch_video));
mShowVideoButton.setVisibility(View.INVISIBLE);
mShowVideoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showRewardedVideo();
}
});
// Display current coin count to user.
mCoinCountText = ((TextView) findViewById(R.id.coin_count_text));
mCoinCount = 0;
mCoinCountText.setText("Coins: " + mCoinCount);
startGame();
}
#Override
public void onPause() {
super.onPause();
pauseGame();
mRewardedVideoAd.pause(this);
}
#Override
public void onResume() {
super.onResume();
if (!mGameOver && mGamePaused) {
resumeGame();
}
mRewardedVideoAd.resume(this);
}
private void pauseGame() {
mCountDownTimer.cancel();
mGamePaused = true;
}
private void resumeGame() {
createTimer(mTimeRemaining);
mGamePaused = false;
}
private void loadRewardedVideoAd() {
if (!mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.loadAd(AD_UNIT_ID, new AdRequest.Builder().build());
/* AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("40C4DDA8F53FFA9BA5B61261E0CA28AB") // Test devices don't work work with rewarded video ads.
.build();
mRewardedVideoAd.loadAd(AD_UNIT_ID, adRequest);*/
}
}
private void addCoins(int coins) {
mCoinCount = mCoinCount + coins;
mCoinCountText.setText("Coins: " + mCoinCount);
}
private void startGame() {
// Hide the retry button, load the ad, and start the timer.
mRetryButton.setVisibility(View.INVISIBLE);
mShowVideoButton.setVisibility(View.VISIBLE);
loadRewardedVideoAd();
createTimer(COUNTER_TIME);
mGamePaused = false;
mGameOver = false;
}
// Create the game timer, which counts down to the end of the level
// and shows the "retry" button.
private void createTimer(long time) {
final TextView textView = ((TextView) findViewById(R.id.timer));
if (mCountDownTimer != null) {
mCountDownTimer.cancel();
}
mCountDownTimer = new CountDownTimer(time * 1000, 50) {
#Override
public void onTick(long millisUnitFinished) {
mTimeRemaining = ((millisUnitFinished / 1000) + 1);
textView.setText("seconds remaining: " + mTimeRemaining);
}
#Override
public void onFinish() {
if (mRewardedVideoAd.isLoaded()) {
mShowVideoButton.setVisibility(View.VISIBLE);
}
textView.setText("You Lose!");
addCoins(GAME_OVER_REWARD);
mRetryButton.setVisibility(View.VISIBLE);
mGameOver = true;
}
};
mCountDownTimer.start();
}
private void showRewardedVideo() {
mShowVideoButton.setVisibility(View.INVISIBLE);
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
}
#Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdClosed() {
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
// Preload the next video ad.
loadRewardedVideoAd();
}
#Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewarded(RewardItem reward) {
Toast.makeText(this,
String.format(" onRewarded! currency: %s amount: %d", reward.getType(),
reward.getAmount()),
Toast.LENGTH_SHORT).show();
addCoins(reward.getAmount());
}
#Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
I am using my Ad_Unit_ID Live not tested Device ID

Android: slow time in changing between activities

is there a way to speed up the time when changing to another activity? or is there something wrong with my code?
public void connectedAnim(){
final Dialog dialog = new Dialog(LogIn.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.connected);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
IVcon = (ImageView)dialog.findViewById(R.id.IVcon);
IVcon.setBackgroundResource(R.anim.connectedanim);
final AnimationDrawable animcon = (AnimationDrawable)IVcon.getBackground();
dialog.setCancelable(true);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
animcon.start();
Toast.makeText(getApplicationContext(), "Connected to HC-05", Toast.LENGTH_SHORT).show();
}
});
dialog.show();
new Handler().postDelayed(new Runnable() {
public void run() {
dialog.dismiss();
}
}, 1000);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
Intent Menu = new Intent(LogIn.this, Menu.class);
LogIn.this.startActivity(Menu);
}
});
}
this is my method that is to be called when i connected my bluetooth to arduino, and i have an animation to it so after the animation comes the change to a new activity. this is how i called the connectedAnim() method
pwordtxt.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable sa) {
}
#Override
public void beforeTextChanged(CharSequence sa, int start,
int count, int after) {
}
#Override
public void onTextChanged(CharSequence sa, int start,
int before, int count) {
if (sa.length() == 4) {
progressDialog = ProgressDialog.show(LogIn.this, "", "Loading..");
password = getPass("password", getApplicationContext());
Runnable runnable = new Runnable() {
#Override
public void run() {
if ((password.equals(""))) {
if (s.toString().equals("1234")) {
findBT();
try {
openBT();
}
catch (IOException e) {}
beginListenForData();
handler.post(new Runnable() {
#Override
public void run() {
progressDialog.dismiss();
connectedAnim();
}
});
} else {
Toast.makeText(LogIn.this, "Incorrect Password", Toast.LENGTH_SHORT).show();
}
} else {
realpass = getPass("password", getApplicationContext());
if (s.toString().equals(realpass)) {
findBT();
} else {
Toast.makeText(LogIn.this, "Incorrect Password", Toast.LENGTH_SHORT).show();
}
}
}
};
new Thread(runnable).start();
}
}
});
}

Cognalys : Error 551& 550 (ANDROID)

Getting Error of 551 & 550 in this,
Here is my code :
findViewById(R.id.verifybutton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!TextUtils.isEmpty(phoneNumbTv.getText().toString())) {
verify();
}
else {
Toast.makeText(getApplicationContext(), "Please enter your phone number to verify", 3500).show();
}
}
});
private void verify() {
timerLayout.setVisibility(View.VISIBLE);
countDownTimer = new CountDownTimer(60000, 1000) {
#Override
public void onTick(long millisUntilFinished) {
timertv.setText("" + millisUntilFinished / 1000);
}
#Override
public void onFinish() {
timerLayout.setVisibility(View.GONE);
}
};
countDownTimer.start();
Cognalys.verifyMobileNumber(MainActivity.this, "TOKEN", "ID", phoneNumbTv.getText().toString(), new VerificationListner() {
#Override
public void onVerificationStarted() {
// TODO Auto-generated method stub
}
#Override
public void onVerificationSuccess() {
countDownTimer.cancel();
timerLayout.setVisibility(View.GONE);
Log.d("", "SUCCESS");
showAlert("Your number has been verified\n\nThanks!!", true);
}
#Override
public void onVerificationFailed(ArrayList<String> errorList) {
countDownTimer.cancel();
timerLayout.setVisibility(View.GONE);
for (String error : errorList) {
Log.d("abx", "error............:" + error);
}
showAlert("Something went wrong.\n please try again", false);
}
});
}
private void showAlert(String message, boolean status) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
ImageView mImageView = (ImageView) dialog.findViewById(R.id.verify_im);
TextView messageTv = (TextView) dialog.findViewById(R.id.messagetv);
if (status) {
mImageView.setImageResource(R.drawable.blue_tick);
}
else {
mImageView.setImageResource(R.drawable.wrong);
}
messageTv.setText(message);
dialog.show();
}
NOTE: Registered app package name in Cognalys site..
Sorry, I cant add the "Cognalys tag" coz I'm not having 1500 reputation
Thanks

How can I make a view invisible after 3 seconds?

I am using a handler in the adapter file to make the view invisible after 3 sconds, but it does not update the view. Where is my problem and how can I fix it?
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
try {
Bundle bun = getIntent().getExtras();
if (!bun.isEmpty()) {
selecte_pos = bun.getInt("pos");
}
} catch (Exception e) {
}
Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();
System.out.println("full image activity");
ar = getIntent().getStringArrayListExtra("PhotoList");
System.out.println("full list size: " + ar.size());
imageLoader = new ImageLoader(this);
setContentView(R.layout.full_image_view_layout);
mPager = (ViewPager) findViewById(R.id.full_image_view_pager);
adapter = new MyPagerAdapter();
mPager.setAdapter(adapter);
mPager.setCurrentItem(selecte_pos);
}
class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return ar.size();
}
Handler pagerHandler=new Handler(){
public void handleMessage(Message msg){
if(msg.what==1){
//if (istimer == true) {
System.out.println("page handler");
System.out.println("");
Toast.makeText(getApplicationContext(), "hi", 1).show();
shareLayout.setVisibility(View.INVISIBLE);
adapter.notifyDataSetChanged();
//}
}
}
};
#Override
public Object instantiateItem(ViewGroup container, final int position) {
System.out.println("view page clciking");
LayoutInflater layoutInflater = (LayoutInflater) container
.getContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View v = layoutInflater.inflate(R.layout.imageview, null);
try {
final ImageView imageView = (ImageView) v
.findViewById(R.id.full_pager_adapter_iv);
shareLayout = (LinearLayout) v.findViewById(R.id.buttonslayout);
shareLayout.setVisibility(View.VISIBLE);
imageLoader.DisplayImage(ar.get(position), imageView);
if (first) {
System.out.println("fisr condition");
first = false;
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
pagerHandler.sendEmptyMessage(1);
//adapter.notifyDataSetChanged();
}
}, SPLASH_DISPLAY_LENGHT);
}
/**if(istimer1== true)
{
System.out.println("else part");
istimer1 = false;
shareLayout.setVisibility(View.VISIBLE);
adapter.notifyDataSetChanged();
}**/
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("img clicking");
if (shareLayout.getVisibility() == View.INVISIBLE) {
System.out.println("invisible");
istimer = false;
istimer1 = true;
shareLayout.setVisibility(View.VISIBLE);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
//istimer = true;
//istimer1 = false;
pagerHandler.sendEmptyMessage(1);
//adapter.notifyDataSetChanged();
}
}, SPLASH_DISPLAY_LENGHT);
adapter.notifyDataSetChanged();
}
if (shareLayout.getVisibility() == View.VISIBLE) {
System.out.println("visible");
istimer = true;
istimer1 = false;
shareLayout.setVisibility(View.INVISIBLE);
adapter.notifyDataSetChanged();
}
}
});
LinearLayout btnshare = (LinearLayout) v
.findViewById(R.id.btnshare);
btnshare.setTag(position);
btnshare.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int pos = (Integer) v.getTag();
String s = ar.get(pos);
// String s = bean.getImagePath();
File file = new File(s);
Intent sendMailIntent = new Intent(Intent.ACTION_SEND);
sendMailIntent.setType("image/jpeg");
sendMailIntent.putExtra(
android.content.Intent.EXTRA_TEXT, "");
sendMailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(file));
/* sendMailIntent.setType("image/*"); */
startActivity(Intent.createChooser(sendMailIntent, ""));
}
});
} catch (Exception e) {
}
((ViewPager) container).addView(v, 0);
return v;
}
#Override
public void destroyItem(ViewGroup collection, int position, Object view) {
((ViewPager) collection).removeView((View) view);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return POSITION_NONE;
}
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
finish();
}
private Handler mTimerHandler = new Handler();
private void stopTimer() {
if (mTimer1 != null) {
mTimer1.cancel();
mTimer1.purge();
}
}
private void startTimer() {
mTimer1 = new Timer();
mTt1 = new TimerTask() {
public void run() {
mTimerHandler.post(new Runnable() {
public void run() {
System.out.println("timesatrs");
// TODO
if (shareLayout.getVisibility() == View.VISIBLE) {
System.out.println("time completed");
shareLayout.setVisibility(View.INVISIBLE);
}
}
});
}
};
mTimer1.schedule(mTt1, 6000);
}
}
getWindow().getDecorView().getRootView().postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
yourView.setVisibility(View.VISIBLE);
}
}, 5000);
// Call this when u initalise view in onCreate
You don't need to create a new handler every time, when you need to send message to handler which you already created. You can send delayed message like this pagerHandler.sendEmptyMessageDelayed(1, SPLASH_DISPLAY_LENGHT);
And are you sure, you are trying to update current shareLayout ?
Add the below coding in your class file.
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
view.setVisibility(View.GONE); }
}, 3000);
This will helps you in achieving what you want.

Getting URL of the media to play from media server with Cling

I'm working on the example upnpBrowser of Cling upnp stack on android and I browse the content of the merdia server and i can display the list of media in every folder and now i want to extract the URL of the video to play it on a player, but I'm blocked how to extract that URL !!!
UDN serverUdn = ((UpnpControlApplication)getApplicationContext()).server_udn;
//Device server = ((UpnpControlApplication)getApplicationContext()).server;
Device server = upnpService.getRegistry().getDevice(serverUdn, true);
listAdapter.clear();
if(server == null)
{
Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
}
else
{
if(server.findService(new UDAServiceType("ContentDirectory")) == null)
Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
upnpService.getControlPoint().execute(new Browse(server.findService(new UDAServiceType("ContentDirectory")),id, BrowseFlag.DIRECT_CHILDREN)
{
#Override
public void received(ActionInvocation actionInvocation, DIDLContent didl) {
final List<Item> items = didl.getItems();
String st=didl.getItems().get(0).getFirstResource().getValue();
public void browseServer(final String id)
{
if(((UpnpControlApplication)getApplicationContext()).server_udn == null)
{
new AlertDialog.Builder(this)
.setTitle("Bad")
.setMessage("pas de serveur sélectionné, allez à la section LAN et cliquez sur Parcourir pour sélectionner le serveur!")
.setPositiveButton("OK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
})
.setNegativeButton("Annuler", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when cancel got clicked
}
})
.show();
}
else
{
UDN serverUdn = ((UpnpControlApplication)getApplicationContext()).server_udn;
//Device server = ((UpnpControlApplication)getApplicationContext()).server;
Device server = upnpService.getRegistry().getDevice(serverUdn, true);
listAdapter.clear();
if(server == null)
{
Toast.makeText(this, "désolé", Toast.LENGTH_LONG).show();
}
else
{
if(server.findService(new UDAServiceType("ContentDirectory")) == null)
Toast.makeText(this, "pbm", Toast.LENGTH_LONG).show();
upnpService.getControlPoint().execute(new Browse(server.findService(new UDAServiceType("ContentDirectory")),id, BrowseFlag.DIRECT_CHILDREN)
{
#Override
public void received(ActionInvocation actionInvocation, DIDLContent didl) {
final List<Item> items = didl.getItems();
//String st = items.getImportUri();
//String st=didl.getItems().get(0).getFirstResource().getValue();
//Log.d("URL IS",st);
//Item item = didl.getItems().get(0);
//Item item = didl.getItems().get(0);
//String url = item.getFirstResource().getValue();
//System.out.println(" this is the url of item" +item.getTitle());
// System.out.println(" this is the url of the media");
//System.out.println(url);
/*final DIDLContent b = didl;
String str1 = "bieda";
try
{
str1 = parser.generate(b);
}
catch(Exception e)
{
str1 = "smuta";
}
final String str=str1;
runOnUiThread(new Runnable()
{
public void run()
{
adb.setTitle("XML").setMessage(str).setPositiveButton("OK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
}).show();
}
});*/
runOnUiThread(new Runnable(){
public void run()
{
listAdapter.insert(new ServerContentContainer(s.peek()), 0);
}
});
final List<Container> containers = didl.getContainers();
for(final Container c: containers)
{
runOnUiThread(new Runnable(){
public void run()
{
int pos = listAdapter.getPosition(new ServerContentContainer(c));
if(pos >= 0)
{
listAdapter.remove(new ServerContentContainer(c));
listAdapter.insert(new ServerContentContainer(c), pos);
System.out.println("eulooooooooo");
}
else
listAdapter.add(new ServerContentContainer(c));
}
});
}
for(final Item i: items)
{
runOnUiThread(new Runnable(){
public void run()
{
int pos = listAdapter.getPosition(new ServerContentItem(i));
if(pos >= 0)
{
listAdapter.remove(new ServerContentItem(i));
listAdapter.insert(new ServerContentItem(i), pos);
}
else
listAdapter.add(new ServerContentItem(i));
}
});
}
}
#Override
public void updateStatus(Status arg0) {
// TODO Auto-generated method stub
}
#Override
public void failure(ActionInvocation arg0, UpnpResponse arg1,
String arg2) {
// TODO Auto-generated method stub
}
});
}
}
}
and this is the class ServerContentItem :
protected class ServerContentItem extends ServerContent
{
private Item i;
public Item getItem()
{
return i;
}
ServerContentItem(Item i)
{
this.i = i;
}
public void select()
{
if(((UpnpControlApplication)getApplicationContext()).renderer_udn != null)
{
Device renderer = upnpService.getRegistry().getDevice(((UpnpControlApplication)getApplicationContext()).renderer_udn, false);
final Service service = renderer.findService(new UDAServiceType("AVTransport"));
upnpService.getControlPoint().execute(new SetAVTransportURI(service, i.getFirstResource().getValue()){
#Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
adb.setTitle("Bad").setMessage("No!")
.setPositiveButton("OK",new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
}).show();
}
#Override
public void success(ActionInvocation invocation)
{
upnpService.getControlPoint().execute(new Play(service){
#Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
adb.setTitle("Bad").setMessage("Non réussi!")
.setPositiveButton("OK",new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
}).show();
}
});
}
});
}
else
{
adb.setTitle("Bad")
.setMessage("selection ! need a media player ")
.setPositiveButton("OK",new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
Log.e("bla","blablaa");
Intent intent = new Intent().setClass(BrowseServerActivity.this, Newactivity.class);
startActivity(intent);
}
}).show();
}
}
#Override
public String toString()
{
return i.getTitle();
}
#Override
public boolean equals(Object o)
{
if(this == o)
return true;
if(getClass() != o.getClass())
return false;
return i.equals(((ServerContentItem)o).i);
}
}
I hope that's the code is clear. thx
The Cling Ressource class contains a URI field , get it and try .
Res CLING Support 1.0.5 API

Categories

Resources