Added back exit button but in About page, replacing the report issue button

This commit is contained in:
Sylvain Berfini 2013-03-22 14:44:25 +01:00
parent e3da406e0d
commit 52844b6678
2 changed files with 9 additions and 124 deletions

View file

@ -34,11 +34,11 @@
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:id="@+id/AboutText"/> android:id="@+id/AboutText"/>
<Button android:id="@+id/about_report_issue" <Button android:id="@+id/exit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/about_report_issue" android:text="@string/menu_exit"
android:visibility="gone" android:visibility="visible"
android:layout_marginTop="30sp"/> android:layout_marginTop="30sp"/>
</LinearLayout> </LinearLayout>

View file

@ -18,34 +18,21 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class AboutFragment extends Fragment implements OnClickListener { public class AboutFragment extends Fragment implements OnClickListener {
private Handler mHandler = new Handler();
private FragmentsAvailable about = FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT; private FragmentsAvailable about = FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -63,12 +50,10 @@ public class AboutFragment extends Fragment implements OnClickListener {
Log.e(e, "cannot get version name"); Log.e(e, "cannot get version name");
} }
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); View issue = view.findViewById(R.id.exit);
if (pref.getBoolean(getString(R.string.pref_debug_key), false)) { issue.setOnClickListener(this);
View issue = view.findViewById(R.id.about_report_issue); issue.setVisibility(View.VISIBLE);
issue.setOnClickListener(this);
issue.setVisibility(View.VISIBLE);
}
return view; return view;
} }
@ -81,110 +66,10 @@ public class AboutFragment extends Fragment implements OnClickListener {
} }
} }
private Thread thread;
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (thread != null) return; if (LinphoneActivity.isInstanciated()) {
Toast.makeText(getActivity(), getString(R.string.about_reading_logs), Toast.LENGTH_LONG).show(); LinphoneActivity.instance().exit();
thread = new ReadLogThread();
thread.start();
}
private File writeLogs(String logs, File directory) {
File tempFile = null;
try {
tempFile = File.createTempFile("bugreport", ".txt", directory);
tempFile.deleteOnExit();
FileWriter writer = new FileWriter(tempFile);
writer.append(logs);
writer.close();
return tempFile;
} catch (IOException e) {
Toast.makeText(getActivity(), getString(R.string.about_error_generating_bugreport_attachement), Toast.LENGTH_LONG).show();
Log.e(e, "couldn't write to temporary file");
return null;
}
}
private void onLogsRead(String logs) {
if (logs == null) {
Toast.makeText(getActivity(), getString(R.string.about_logs_not_found), Toast.LENGTH_SHORT).show();
} else {
File tempFile = writeLogs(logs, null);
if (tempFile == null) {
// If writing to temporary file to default location failed
// Write one to our storage place
tempFile = writeLogs(logs, getActivity().getFilesDir());
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{getString(R.string.about_bugreport_email)});
intent.putExtra(Intent.EXTRA_SUBJECT,"Bug report " + getString(R.string.app_name) + "-android");
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.about_bugreport_email_text));
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));
intent = Intent.createChooser(intent,getString(R.string.about_mailer_chooser_text));
startActivityForResult(intent, 0);
}
}
private class ReadLogThread extends Thread {
@Override
public void run() {
final String logs = readLogs();
mHandler.post(new Runnable() {
@Override
public void run() {
onLogsRead(logs);
thread=null;
}
});
super.run();
}
}
private String readLogs() {
StringBuilder sb1 = null;
StringBuilder sb2 = null;
BufferedReader br = null;
Process p = null;
try {
p = Runtime.getRuntime().exec(new String[] {"logcat", "-d"});
br = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
String line;
while ((line = br.readLine()) != null) {
if (line.contains(LinphoneService.START_LINPHONE_LOGS)) {
if (sb1 != null) {
sb2 = sb1;
}
sb1 = new StringBuilder();
}
if (sb1 != null) {
sb1.append(line).append('\n');
}
}
if (sb1 == null) return null;
if (sb2 != null) {
sb1.append(sb2);
}
return sb1.toString();
} catch (IOException e) {
Log.e(e, "Error while reading logs");
return null;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {}
}
if (p != null) {
p.destroy();
}
} }
} }
} }