i created audio activity with seekbar, it was played but i have problem when seekbar in progress there is cutting each 1 second in sound because i used (Thread.sleep).
i check another solution in Internet, all codes i checked were use same concept.
this is my code
public class PlaySounds extends Activity implements Runnable {
SeekBar seeksounds;
MediaPlayer mp;
Handler handler = new Handler();
int id;
public boolean isFileExists(String fileName) {
try {
File myFile = new File(fileName);
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
return true;
} catch (Exception e) {
return false;
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playsounds);
seeksounds = (SeekBar) findViewById(R.id.seeksounds);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
String path = Environment.getExternalStorageDirectory().toString() + "/dowload/splash.mp3";
if (isFileExists(path)) {
mp = new MediaPlayer();
try {
mp.setDataSource(path);
mp.prepare();
mp.start();
int maxD = mp.getDuration();
int currentD = mp.getCurrentPosition();
seeksounds.setMax(maxD);
seeksounds.setProgress(currentD);
new Thread(this).start();
seeksounds.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar arg0, int progress,
boolean arg2) {
mp.seekTo(progress);
seeksounds.setProgress(progress);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
mp.release();
}
#Override
public void run() {
int currentPosition= 0;
int total = mp.getDuration();
while (mp!=null && currentPosition<total) {
try {
Thread.sleep(1000);
currentPosition= mp.getCurrentPosition();
seeksounds.setProgress(currentPosition);
} catch (Exception e) {
return;
}
}
}
}
Try to add mp = null; here
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
mp.release();
mp = null;
}
Related
Here is my MainActivity Where I want to send the chosen GIF To the Wallpaper Service class using Uri :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(i, 0);
}
});
Button btn1;
btn1 = findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0){
Uri uri = data.getData();
Intent i = new Intent(MainActivity.this,one.class);
i.putExtra("ayush",uri.toString());
startActivity(i);
////////////////
}
}
}
And here is my Second Activity where I want to Receive the Gif data and put it on the movie decode stream. Please Suggest me some ways. Please suggest me some ways to do it.
public void onDestroy() {
super.onDestroy();
}
#Override
public Engine onCreateEngine() {
// TODO Auto-generated method stub
try {
//Movie movie=Movie.decodeStream(getResources().getMovie(R.drawable.endless_staircase));
Movie movie = getResources().getMovie(Intent.getIntent(Uri.parse(//I want to use the get intent extra here )));
return new GIFWallpaperEngine(movie);
} catch (Exception e) {
// TODO: handle exception
Log.d("GIF", "Could Not load Asset");
return null;
}
}
private class GIFWallpaperEngine extends Engine {
private final int frameDuration = 20;
private SurfaceHolder holder;
private Movie movie;
private boolean visible;
private Handler handler;
int mWhen;
long mStart;
float mScaleX, mScaleY;
public GIFWallpaperEngine(Movie movie) {
this.movie = movie;
handler = new Handler();
mWhen = -1;
}
#Override
public void onCreate(SurfaceHolder surfaceHolder) {
// TODO Auto-generated method stub
super.onCreate(surfaceHolder);//tick();
this.holder = surfaceHolder;
}
private void draw() {
tick();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
canvas.save();
canvas.scale(mScaleX, mScaleY);
if (canvas != null) {
movie.draw(canvas, 0, 0);
}
canvas.restore();
// holder.unlockCanvasAndPost(canvas);
//movie.setTime(((int)(SystemClock.uptimeMillis()-SystemClock.uptimeMillis())%(movie.duration())));
//movie.setTime((int)((System.currentTimeMillis()%movie.duration())));
movie.setTime(mWhen);
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(drawGIF);
if (visible) handler.postDelayed(drawGIF, 1000L / 25L);
}
void tick() {
int dur = movie.duration();
if (mWhen == -1L) {
mWhen = 0;
mStart = SystemClock.uptimeMillis();
} else {
long mDiff = SystemClock.uptimeMillis() - mStart;
mWhen = (int) (mDiff % dur);
}
}
#Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
super.onSurfaceChanged(holder, format, width, height);
mScaleX = width / (1f * movie.width());
mScaleY = height / (1f * movie.height());
draw();
}
private Runnable drawGIF = new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
draw();
}
};
#Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
handler.removeCallbacks(drawGIF);
}
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
//super.onVisibilityChanged(visible);
this.visible = visible;
if (visible) {
handler.post(drawGIF);
} else {
handler.removeCallbacks(drawGIF);
}
}
}
}
Please Suggest me Some Ways to do it.
this is my code, i am almost certain the problem is with the while loop.
public void start(View view) {
int currentPosition = 0;
player = MediaPlayer.create(this, R.raw.sound);
player.start();
int total = player.getDuration();
progressBar.setProgress(0);
progressBar.setMax(player.getDuration());
while (player != null && currentPosition < total) {
// try {
// Thread.sleep(500);
currentPosition = player.getCurrentPosition();
// } catch (InterruptedException e) {
// return;
// } catch (Exception e) {
// return;
// }
progressBar.setProgress(currentPosition);
}
}
public void stop(View view) {
player.stop();
}
whether or not i have the sleep intervals my result is the same; the sound starts playing but i cant stop it, and the progress bar doesn't move.
i would appreciate some help
I used this code in my app for using seekBar with MediaPlayer. It implements Runnable to keep the seekBar updating as the music plays. Take a look at the code:
public class MainActivity extends Activity implements Runnable,
OnClickListener, OnSeekBarChangeListener {
private SeekBar seekBar;
private Button startMedia;
private Button stopMedia;
private MediaPlayer mp;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
startMedia = (Button) findViewById(R.id.button1);
stopMedia = (Button) findViewById(R.id.button2);
startMedia.setOnClickListener(this);
stopMedia.setOnClickListener(this);
seekBar.setOnSeekBarChangeListener(this);
seekBar.setEnabled(false);
}
public void run() {
int currentPosition = mp.getCurrentPosition();
int total = mp.getDuration();
while (mp != null && currentPosition < total) {
try {
Thread.sleep(1000);
currentPosition = mp.getCurrentPosition();
} catch (InterruptedException e) {
return;
} catch (Exception e) {
return;
}
seekBar.setProgress(currentPosition);
}
}
public void onClick(View v) {
if (v.equals(startMedia)) {
if (mp == null) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.song2);
seekBar.setEnabled(true);
}
if (mp.isPlaying()) {
mp.pause();
startMedia.setText("play");
} else {
mp.start();
startMedia.setText("pause");
seekBar.setMax(mp.getDuration());
new Thread(this).start();
}
}
if (v.equals(stopMedia) && mp != null) {
if (mp.isPlaying() || mp.getDuration() > 0) {
mp.stop();
mp = null;
startMedia.setText("play");
seekBar.setProgress(0);
}
}
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
try {
if (mp.isPlaying() || mp != null) {
if (fromUser)
mp.seekTo(progress);
} else if (mp == null) {
Toast.makeText(getApplicationContext(), "Media is not running",
Toast.LENGTH_SHORT).show();
seekBar.setProgress(0);
}
} catch (Exception e) {
Log.e("seek bar", "" + e);
seekBar.setEnabled(false);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
Thanks to: Sridhar Kulkarni
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 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;
}
}