-
This commit is contained in:
parent
6fcf2f3985
commit
ed1445dd4e
@ -4,10 +4,12 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -30,6 +32,7 @@ public class MainActivity extends Activity
|
||||
{
|
||||
Button bExport;
|
||||
RadioButton rbRcs, rbSms, rbMms;
|
||||
ProgressBar pbStatus;
|
||||
|
||||
final static int typeSMS = 0;
|
||||
final static int typeMMS = 1;
|
||||
@ -49,6 +52,7 @@ public class MainActivity extends Activity
|
||||
rbRcs = (RadioButton)findViewById(R.id.rbRcs);
|
||||
rbSms = (RadioButton)findViewById(R.id.rbSms);
|
||||
rbMms = (RadioButton)findViewById(R.id.rbMms);
|
||||
pbStatus = (ProgressBar)findViewById(R.id.pbStatus);
|
||||
|
||||
bExport.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
@ -72,6 +76,11 @@ public class MainActivity extends Activity
|
||||
{
|
||||
case requestCodeExport:
|
||||
if (resultCode == RESULT_OK)
|
||||
{
|
||||
AsyncTask<Void, Integer, Void> asyncTaskExport = new AsyncTask<Void, Integer, Void>()
|
||||
{
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids)
|
||||
{
|
||||
Uri uriTree = data.getData();
|
||||
String dataToWrite = getExportString();
|
||||
@ -79,13 +88,26 @@ public class MainActivity extends Activity
|
||||
exportFiles(uriTree, dataToWrite);
|
||||
else
|
||||
Toast.makeText(MainActivity.this, "Error reading messages. Can\'t export.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(Integer... values)
|
||||
{
|
||||
super.onProgressUpdate(values);
|
||||
pbStatus.setProgress(values[0]);
|
||||
}
|
||||
};
|
||||
|
||||
asyncTaskExport.execute();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String getExportString()
|
||||
String getExportString(AsyncTask<Void,Integer,Void> asyncTaskReference)
|
||||
{
|
||||
List<Map<String,String>> response;
|
||||
|
||||
@ -100,6 +122,8 @@ public class MainActivity extends Activity
|
||||
{
|
||||
messageCount = response.size();
|
||||
|
||||
asyncTaskReference.publishProgress((int)Math.round(messageCount/response.size()));
|
||||
|
||||
StringBuilder export = new StringBuilder();
|
||||
|
||||
export.append("<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>");
|
||||
@ -122,9 +146,14 @@ public class MainActivity extends Activity
|
||||
type: 2 = outbound
|
||||
*/
|
||||
|
||||
export.append("<sms protocol=\"0\"");
|
||||
|
||||
if(!StringUtils.isEmpty(response.get(i).get("remote_uri")))
|
||||
export.append(" address=\"" + response.get(i).get("remote_uri").replace("tel:", "") + "\"");
|
||||
else
|
||||
export.append(" address=\"" + response.get(i).get("address") + "\"");
|
||||
|
||||
export.append(
|
||||
"<sms protocol=\"0\"" +
|
||||
" address=\"" + response.get(i).get("remote_uri").replace("tel:", "") + "\"" +
|
||||
" date=\"" + response.get(i).get("date") + "\"" +
|
||||
" type=\"" + response.get(i).get("type") + "\"" +
|
||||
" subject=\"null\"" +
|
||||
@ -238,7 +267,10 @@ public class MainActivity extends Activity
|
||||
}
|
||||
Log.i("Message", "Message nr. " + messageCounter + " " + message);
|
||||
|
||||
if(!StringUtils.isEmpty(messageMap.get("body")))
|
||||
returnList.add(messageMap);
|
||||
else
|
||||
Log.i("Message", "Skipping a message with an empty body.");
|
||||
}
|
||||
while (cursor.moveToNext());
|
||||
}
|
||||
|
@ -38,6 +38,15 @@
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbStatus"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:minHeight="50dp"
|
||||
android:max="100" />
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/bExport"
|
||||
android:layout_width="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user