This is my library project .
public class myads extends Activity implements AdListener {
public static int num;
public static InterstitialAd interstitialAds;
static AdRequest adr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitialAds = new InterstitialAd(this, "ca-app-pub-*************/**********");
interstitialAds.setAdListener(this);
adr=new AdRequest();
interstitialAds.loadAd(adr);
interstitialAds.show();
}
public static void intenr(Context c){
interstitialAds.loadAd(adr);
interstitialAds.show();
Toast.makeText(c, "Sample", Toast.LENGTH_LONG).show();
num=3;
}
#Override
public void onDismissScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLeaveApplication(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onPresentScreen(Ad arg0) {
// TODO Auto-generated method stub
}
#Override
public void onReceiveAd(Ad arg0) {
// TODO Auto-generated method stub
interstitialAds.show();
}
}
It has unfortunately stopped Error and not working when I call it(this library project) from another project.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myads.intenr(this);
}
If I remove int.load and int.show from library project , It is working and toasting , got passed int. I also added internet permission and google activity tag properly. Thank you for interesting my problem.
It may be useful-
private InterstitialAd interstitial;
private AdRequest adRequestFullScreen;
private LocalBroadcastManager localBroadcastManager;
private NotificationReciever notificationReciever;
private Dialog answerDialog, chatReqDialog, questionDialog;
private boolean isShowAd = true, isRecieverRegistered = false,
isNetDialogShowing = false, isGpsDialogShowing = false;
private String notificationData = "", notificationType;
// Ad
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(getString(R.string.admob_fullscreen_ad));
// live
// adRequestFullScreen = new AdRequest.Builder().build();
// test
adRequestFullScreen = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("").build();
loadAd();
public void loadAd() {
interstitial.loadAd(adRequestFullScreen);
}
public void showAd() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
#Override
public void onDestroy() {
if (isRecieverRegistered) {
unregisterReceiver(internetConnectionReciever);
unregisterReceiver(GpsChangeReceiver);
}
AndyUtils.removeSimpleProgressDialog();
if (isShowAd) {
showAd();
}
Mint.closeSession(getApplicationContext());
stopLocationUpdate();
super.onDestroy();
}
Related
My code for scanning devices in Bluetooth LE scenario is not working. It is running fine without any exception or error. But onLeScan() function (in leScanCallback) is not calling at all while other Bluetooth Low Energy device is in vicinity...
public class ScanBle extends Activity {
private BluetoothAdapter myAdapter;
private Handler bleHandler;
private long SCAN_PERIOD = 10000;
ArrayList<BluetoothDevice> allBleDevice;
ArrayAdapter<String> listAdaptor;
private String TagBle = "ScanBle";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BluetoothManager bm = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
myAdapter = bm.getAdapter();
listAdaptor = new ArrayAdapter<>(this, R.layout.activity_scan_ble);
allBleDevice = new ArrayList<BluetoothDevice>();
bleHandler = new Handler();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if(myAdapter == null || !myAdapter.isEnabled())
{
Intent enableBt = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBt);
finish();
return;
}
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
{
Toast.makeText(getApplicationContext(), "No Le Feature", Toast.LENGTH_SHORT).show();
finish();
return;
}
startScan(true);
if(listAdaptor.getCount()>0)
{
ListView lv = new ListView(this);
lv.setAdapter(listAdaptor);
setContentView(lv);
}
else
{
Toast.makeText(this, "No Ble devices Found Bazingaaa", Toast.LENGTH_SHORT).show();
}
}
public void startScan(final boolean enable) {
Log.d(TagBle , "startScan() started");
// TODO Auto-generated method stub
if(enable)
{
Toast.makeText(getApplicationContext(), "Scan is running...", Toast.LENGTH_SHORT).show();
bleHandler.postDelayed(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
myAdapter.stopLeScan(callbackBle);
}
}, SCAN_PERIOD );
myAdapter.startLeScan(callbackBle);
}
else
{
myAdapter.stopLeScan(callbackBle);
}
}
public BluetoothAdapter.LeScanCallback callbackBle = new BluetoothAdapter.LeScanCallback() {
#Override
public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
// TODO Auto-generated method stub
Log.d(TagBle , "callBackBle() Running");
runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
BluetoothDevice tempDevice = device;
allBleDevice.add(tempDevice);
listAdaptor.add(tempDevice.getName()+"\n"+tempDevice.getAddress());
}
});
}
};
}
I have a thread named runner. I want to stop this thread onBackPressed but this is not happening. Here is the code:
public class StrobeLightConfig extends Activity {
Camera cam;
StrobeRunner runner;
Thread bw;
CheckBox strobe;
private boolean isFlashOn;
private boolean hasFlash;
private Parameters params;
private MediaPlayer mp;
VerticalSeekBar skbar, skbaroff;
ToggleButton togglebutton;
public final Handler mHandler = new Handler();
public final Runnable mShowToastRunnable = new Runnable() {
public void run() {
showMessage();
}
};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
skbar = (VerticalSeekBar) findViewById(R.id.SeekBar01);
strobe = (CheckBox) findViewById(R.id.checkBox1);
togglebutton = (ToggleButton) findViewById(R.id.ToggleButton01);
skbaroff = (VerticalSeekBar) findViewById(R.id.SeekBar02);
hasFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
turnOnFlash();
strobe.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (buttonView.isChecked()) {
cam.release();
Toast.makeText(getApplicationContext(), "Released 1", 0)
.show();
} else {
cam.release();
Toast.makeText(getApplicationContext(), "Released 2", 0)
.show();
}
}
});
runner = StrobeRunner.getInstance();
runner.controller = this;
if (runner.isRunning) {
} else {
try {
if (cam == null) {
cam = Camera.open();
}
} catch (RuntimeException ex) {
togglebutton.setEnabled(false);
TextView t = (TextView) findViewById(R.id.TextViewHW2);
t.setText(R.string.nocamera);
Toast.makeText(getApplicationContext(),
"Error connecting to camera flash.", Toast.LENGTH_LONG)
.show();
return;
}
}
togglebutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (strobe.isChecked()) {
if (togglebutton.isChecked()) {
turnOnStrobe();
} else {
turnOffStrobe();
}
} else {
if (isFlashOn) {
// turn off flash
turnOffFlash();
} else {
----------------- runner.requeststop working here---------------------
turnOnFlash();
}
}
}
});
skbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
runner.delay = progress;
}
});
skbaroff.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
runner.delayoff = progress;
}
});
}
private void getCamera() {
if (cam == null) {
try {
cam = Camera.open();
params = cam.getParameters();
} catch (RuntimeException e) {
Log.e("Camera Error. Failed to Open. Error: ", e.getMessage());
}
}
}
/*
* Turning On flash
*/
private void turnOnFlash() {
if (!isFlashOn) {
togglebutton.setChecked(true);
cam = Camera.open();
params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(params);
cam.startPreview();
isFlashOn = true;
strobe.setEnabled(false);
}
}
private void turnOffFlash() {
if (isFlashOn) {
togglebutton.setChecked(false);
params = cam.getParameters();
params.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(params);
cam.stopPreview();
cam.release();
isFlashOn = false;
strobe.setEnabled(true);
}
}
private void turnOnStrobe() {
if (!isFlashOn) {
strobe.setEnabled(false);
bw = new Thread(runner);
bw.start();
}
}
private void turnOffStrobe() {
if (isFlashOn) {
runner.requestStop = true;
strobe.setEnabled(true);
}
}
#Override
protected void onDestroy() {
super.onDestroy();
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onRestart() {
super.onRestart();
}
public void showMessage() {
String err = runner.errorMessage;
runner.errorMessage = "";
if (!err.equals("")) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, err, duration);
toast.show();
}
ToggleButton togglebutton = (ToggleButton) findViewById(R.id.ToggleButton01);
togglebutton.setChecked(false);
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
if (strobe.isChecked()) {
turnOffStrobe();
} else {
if (isFlashOn) {
----------------- runner.requeststop needs to work here---------------------
turnOffFlash();
finish();
moveTaskToBack(true);
}
}
}
}
However if I write
runner.requestStop = true;
strobe.setEnabled(true);
at the place of TurnoffStrobe in the oncreate (not onBackPressed), its working. What can I do to have runner.requeststop working outside onCreate.?
Try
your_thread.isInterrupted(); inside onBackpress()
I have a custom DialogFragment. I want to show this dialog while switching my activities.
Scenario:-
1) In actvity1 I start the dialog.
2) Start a asynctask class.
3) Do some authentication in doInBackground().
4) Start new actvity from onPostExecute().
Issue:-
The dialog stops before the asynctask.
Here is my code:-
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public void onPageStarted(WebView view, String url,
Bitmap favicon)
{
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
redirected =view.getUrl();
redirected= Uri.decode(redirected);
if(redirected!=null && redirected.contains(string1))
{
myprogressDialog.show(getFragmentManager(), "Wait");
}
}
#Override
public void onPageFinished(WebView view, String url)
{
// TODO Auto-generated method stub
super.onPageFinished(view, url);
if(redirected!=null && redirected.contains(mystring) )
{
myWebView.stopLoading();
String authorizationContentString = myurl
new Authentication(Activity2.this, myprogressDialog, url).execute(authorizationString);
}
private static class ProgressDialogFragment extends DialogFragment
{
public static ProgressDialogFragment newInstance()
{
return new ProgressDialogFragment();
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, android.R.style.Theme_Translucent);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_dialog_progress, container, false);
}
}
Authentication.java
#Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
/* progDia.show(man, "wait");
progDia= new Utility.ProgressDialogFragment().newInstance();*/
}
public AuthenticateDevice(Details1 myContext, ProgressDialogFragment myprogressDialog, String Url)
{
// TODO Auto-generated constructor stub
mContext = myContext;
this.progDia = myprogressDialog;
this.Url = Url;
this.mActivity = myContext;
}
#Override
protected Void doInBackground(String... params)
{
// TODO Auto-generated method stub
//Some authentication
return null;
}
#Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
if(progDia!=null&&progDia.isVisible())
{
progDia.dismiss();
}
Intent myIntent = new Intent(mContext, Activity2.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mContext.startActivity(myIntent);
mActivity.finish();
}
Try following code to show progress dialog in async
ProgressDialog pd;
class MYAsync extends AsyncTask<Void , Void, String>{
#Override
protected void onPreExecute() {
// pd.setTitle("Please Wait");
pd.setMessage("Working...");
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.show();
}
#Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
return null;
}
#Override
protected void onPostExecute(String sResponse) {
pd.dismiss();
pd.cancel();
}
}
}
I tried to recreate it, it appears to be working fine. this below method has comments explaining your actions.
private void myWOrk() {
try {
final ProgressDialog Dialog = new ProgressDialog(this);
Dialog.setMessage("Loading route...");
Dialog.show();
Thread.sleep(2000);// load url and redirect
//Toast.makeText(LoginActivity.this, "redirect caught", Toast.LENGTH_SHORT).show();
new AsyncTask<Object, Object, Object>() {
protected String doInBackground(Object... params) {
try {
Thread.sleep(2000);// authenticate
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Object result) {
Toast.makeText(LoginActivity.this, "onPostExecute", Toast.LENGTH_SHORT).show();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Dialog.dismiss();// start your new activity here
};
}.execute(null, null, null);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}`
I am working on a game. Its all working well, the only thing I need is for my animation to pause when I press the home or on/off button on my phone. As far as I log correct, the pause script (as found here) works well. It keeps incrementing the time and applies it to the animation. However when I resume my game, the animations all resume on the left side of the screen instead of the position it originally was in when I paused it in. This is my stripped code. I really hope someone can help me.
public class GameView extends Activity{
ImageView peanut;
TranslateAnim movePeanut;
AnimationSet animSet = new AnimationSet(true);
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameviewlayout);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
movePeanut = new TranslateAnim(width,0,0,0);
movePeanut.setDuration(5000);
movePeanut.setRepeatCount(-1);
movePeanut.setRepeatMode(Animation.REVERSE);
animSet.addAnimation(movePeanut);
animSet.setFillAfter(true);
peanut = (ImageView) findViewById(R.id.imgview1);
peanut.startAnimation(animSet);
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
movePeanut.resume();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
movePeanut.pause();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
public void finish (){
Intent intent = new Intent (GameView.this, MainActivity.class);
startActivity(intent);
}
public class TranslateAnim extends TranslateAnimation{
public TranslateAnim(float fromXDelta, float toXDelta, float fromYDelta,
float toYDelta) {
super(fromXDelta, toXDelta, fromYDelta, toYDelta);
// TODO Auto-generated constructor stub
}
private long mElapsedAtPause=0;
private boolean mPaused=false;
#Override
public boolean getTransformation(long currentTime, Transformation outTransformation) {
if(mPaused && mElapsedAtPause==0) {
mElapsedAtPause=currentTime-getStartTime();
}
if(mPaused)
setStartTime(currentTime-mElapsedAtPause);
boolean returnValue = super.getTransformation(currentTime, outTransformation);
return returnValue;
}
public void pause() {
mElapsedAtPause=0;
mPaused=true;
}
public void resume() {
mPaused=false;
}
}
}
I have this problem. I need to send a call to my SAX Parser (every time user tries enter name of the student) to get the names. What I am doing right now is sending a token-string to my HttpHandler which is returning 10 records every time because total no of students are about 40K so I can't parse them all at once. I am calling my AsyncTask for ParsingXML in onTextChanged event of AutoCompletetextview. but still I am not able to set the adapter to Autocomplete.
public ArrayList<AutoCompleteUserDataGetterSetter> parsexml(String token)
{
try {
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL(xyz.com/xyz.ashx?token=+"token"); // URL of the XML
AutoCompleteUserDataXMLHandler myXMLHandler = new AutoCompleteUserDataXMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
} catch (Exception e) {
System.out.println(e);
}
return data=AutoCompleteUserDataXMLHandler.getArrayData();
}
Here is my AutoCompleteTextViewAdapter Code
ArrayList<AutoCompleteUserDataGetterSetter> data=new ArrayList<AutoCompleteUserDataGetterSetter>();
public UserNewMessageAutoCompleteAdapater(Context context,
int textViewResourceId,
ArrayList<AutoCompleteUserDataGetterSetter>data) {
super(context, textViewResourceId, data);
// TODO Auto-generated constructor stub
this.context = context;
this.data=data;
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
final AutoCompleteUserDataGetterSetter i = this.data.get(position);
if (i != null) {
Log.d("adapter", "in here");
AutoCompleteUserDataGetterSetter si = (AutoCompleteUserDataGetterSetter) i;
v = vi.inflate(R.layout.autocompletetext_layout, null);
final TextView title = (TextView) v
.findViewById(R.id.autocomplete_name);
TextView userid = (TextView) v
.findViewById(R.id.autocompleteuserid);
if (title != null)
title.setText(si.GetFullName());
userid.setText(si.GetUserId());
}
return v;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
#Override
public AutoCompleteUserDataGetterSetter getItem(int arg0) {
// TODO Auto-generated method stub
return data.get(arg0);
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
and here is my AsyncTask Class
class SomeTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(UserMessagesComposeNewActivity.this);
#Override
protected void onPreExecute() {
}
#Override
protected Void doInBackground(Void... voids) {
UserMessagesComposeNewActivity.this.data=parsexml(users.getText().toString());
for(int i=0;i<data.size();i++)
{
nameadapter.add(data.get(i).GetFullName());
useridadapter.add(data.get(i).GetUserId());
}
if(data==null)
{
AutoCompleteUserDataGetterSetter umsgs=new AutoCompleteUserDataGetterSetter();
umsgs.SetFullName(" ");
umsgs.SetUserID("");
data.add(umsgs);
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
users.setAdapter(nameadapter);
}
}
Finally after some head-desking finally sorted the issue Finally!
I gave up the custom adapter approach and used the ArrayAdapter approach. so here is the complete code for my Sending Messages to users via selecting their names.
public class UserMessagesComposeNewActivity extends Activity implements TextWatcher{
ArrayList<AutoCompleteUserDataGetterSetter> data=new
ArrayList<AutoCompleteUserDataGetterSetter>();
Long login;
Boolean shouldAutoComplete;
UserNewMessageAutoCompleteAdapater cdapater;
String TO,FROM;
Button btn;
AutoCompleteTextView users;
EditText edTextSubject,edTextMessage;
AutoCompleteWidget myAutoComplete;
List<String> nameadapter=new ArrayList<String>();
ArrayAdapter<String> dataAdapter ;
UserNewMessageAutoCompleteAdapater atAdapter;
String ResultEmail;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
setContentView(R.layout.user_messages_compose_new);
login=intent.getLongExtra("EmployeedId", 0);
btn=(Button)findViewById(R.id.userNewmessageSendButton);
edTextSubject=(EditText)findViewById(R.id.userNewmessageSubject);
edTextMessage=(EditText)findViewById(R.id.userNewmessageMessage);
users=(AutoCompleteTextView)findViewById(R.id.userNewmessageAutoCT);
users.addTextChangedListener(this);
users.setThreshold(4);
//Here we get the selected value from autocompletetextview dropdown
users.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
for(int i=0;i<data.size();i++)
{
if(data.get(i).GetFullName().equals(users.getText().toString()))
{
TO=data.get(i).GetUserId();
}
else
{
TO="0";
}
}
}
});
//here we call the Send Email method.
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new DomParserEmail().execute();
}
});
}
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length()>=4)
{
new SomeTask().execute();
}
}
class SomeTask extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(UserMessagesComposeNewActivity.this);
#Override
protected void onPreExecute() {
}
#Override
protected Void doInBackground(Void... voids) {
//Here we are parsing the xml
UserMessagesComposeNewActivity.this.data=parsexml(users.getText().toString());
if(data==null)
{
AutoCompleteUserDataGetterSetter umsgs=new AutoCompleteUserDataGetterSetter();
umsgs.SetFullName(" ");
umsgs.SetUserID("");
data.add(umsgs);
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
UserMessagesComposeNewActivity.this.nameadapter.clear();
for(int i=0;i<data.size();i++)
{
UserMessagesComposeNewActivity.this.nameadapter.add(UserMessagesComposeNewActivity.this.data.get(i).GetFullName());
}
dataAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_dropdown_item_1line, nameadapter);
dataAdapter.notifyDataSetChanged();
users.setAdapter(dataAdapter);
users.showDropDown();
}
}
public ArrayList<AutoCompleteUserDataGetterSetter> parsexml(String token)
{
try {
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("blah blah"); // URL of the XML
/**
* Create the Handler to handle each of the XML tags.
**/
AutoCompleteUserDataXMLHandler myXMLHandler = new AutoCompleteUserDataXMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
} catch (Exception e) {
System.out.println(e);
}
return data=AutoCompleteUserDataXMLHandler.getArrayData();
}
class DomParserEmail extends AsyncTask<Void, Void, Void> {
private final ProgressDialog dialog = new ProgressDialog(UserMessagesComposeNewActivity.this);
#Override
protected void onPreExecute() {
this.dialog.setMessage("Sending your message");
this.dialog.setTitle("Please Wait");
this.dialog.show();
}
#Override
protected Void doInBackground(Void... voids) {
// download and parse
UserMessagesComposeNewActivity.this.ResultEmail=EmailSuccessMessage(UserMessagesComposeNewActivity.this.edTextSubject.getText().toString(),UserMessagesComposeNewActivity.this.edTextMessage.getText().toString(),UserMessagesComposeNewActivity.this.TO,UserMessagesComposeNewActivity.this.login.toString());
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
if (this.dialog.isShowing()) {
this.dialog.dismiss();
Toast toast=Toast.makeText(getApplicationContext(),UserMessagesComposeNewActivity.this.ResultEmail,Toast.LENGTH_LONG );
toast.show();
}
}
}
public String EmailSuccessMessage(String subject,String content,String To, String From) throws FactoryConfigurationError
{
try {
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("abc.com/abc.asahx?blah blah");
/**
* Create the Handler to handle each of the XML tags.
**/
UserReplyMessageXMLParsing myXMLHandler = new UserReplyMessageXMLParsing();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
}
catch (Exception e)
{
System.out.println(e);
UserMessagesComposeNewActivity.this.ResultEmail="Email Not Sent";
}
UserReplyMessageXMLParsing usmx=new UserReplyMessageXMLParsing();
UserMessagesComposeNewActivity.this.ResultEmail=usmx.GetEmailStatus();
return UserMessagesComposeNewActivity.this.ResultEmail;
}
}