use of com.asksven.betterbatterystats.data.Reading in project BetterBatteryStats by asksven.
the class StatsActivity method getShareDialog.
public AlertDialog getShareDialog() {
final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>();
AlertDialog.Builder dialog = new AlertDialog.Builder(StatsActivity.this);
/*
dialog.setTitle("Alert");
dialog.setMessage("Alert message to be shown");
dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
return dialog;
*/
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true);
boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false);
boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false);
if (saveDumpfile) {
selectedSaveActions.add(0);
}
if (saveLogcat) {
selectedSaveActions.add(1);
}
if (saveDmesg) {
selectedSaveActions.add(2);
}
// ----
LinearLayout layout = new LinearLayout(this);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(parms);
layout.setGravity(Gravity.CLIP_VERTICAL);
layout.setPadding(2, 2, 2, 2);
final TextView editTitle = new TextView(StatsActivity.this);
editTitle.setText(R.string.share_dialog_edit_title);
editTitle.setPadding(40, 40, 40, 40);
editTitle.setGravity(Gravity.LEFT);
editTitle.setTextSize(20);
final EditText editDescription = new EditText(StatsActivity.this);
LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
tv1Params.bottomMargin = 5;
layout.addView(editTitle, tv1Params);
layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
// ----
// Set the dialog title
dialog.setTitle(R.string.title_share_dialog).setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg }, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the
// selected items
selectedSaveActions.add(which);
} else if (selectedSaveActions.contains(which)) {
// Else, if the item is already in the array,
// remove it
selectedSaveActions.remove(Integer.valueOf(which));
}
}
}).setView(layout).setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
ArrayList<Uri> attachements = new ArrayList<Uri>();
Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this);
Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this);
Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);
// save as text is selected
if (selectedSaveActions.contains(0)) {
Uri fileUri = reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString());
File file = new File(fileUri.getPath());
Uri shareableUri = FileProvider.getUriForFile(StatsActivity.this, StatsActivity.this.getPackageName() + ".provider", file);
attachements.add(shareableUri);
}
// save logcat if selected
if (selectedSaveActions.contains(1)) {
Uri fileUri = StatsProvider.getInstance().writeLogcatToFile();
File file = new File(fileUri.getPath());
Uri shareableUri = FileProvider.getUriForFile(StatsActivity.this, StatsActivity.this.getPackageName() + ".provider", file);
attachements.add(shareableUri);
}
// save dmesg if selected
if (selectedSaveActions.contains(2)) {
// attachements.add();
Uri fileUri = StatsProvider.getInstance().writeDmesgToFile();
File file = new File(fileUri.getPath());
Uri shareableUri = FileProvider.getUriForFile(StatsActivity.this, StatsActivity.this.getPackageName() + ".provider", file);
attachements.add(shareableUri);
}
if (!attachements.isEmpty()) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements);
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Share info to.."));
}
}
}).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
try {
Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this);
Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this);
Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo);
// save as text is selected
if (selectedSaveActions.contains(0)) {
reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString());
}
// save logcat if selected
if (selectedSaveActions.contains(1)) {
StatsProvider.getInstance().writeLogcatToFile();
}
// save dmesg if selected
if (selectedSaveActions.contains(2)) {
StatsProvider.getInstance().writeDmesgToFile();
}
Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written) + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(TAG, "an error occured writing files: " + e.getMessage());
Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error, Snackbar.LENGTH_LONG).show();
}
}
}).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// do nothing
}
});
return dialog.create();
}
use of com.asksven.betterbatterystats.data.Reading in project BetterBatteryStats by asksven.
the class WriteTimeSeriesService method doWork.
private void doWork(JobParameters jobParameters, String refFrom, String refTo) {
try {
Wakelock.aquireWakelock(this);
// restore any available references if required
Reference myReferenceFrom = ReferenceStore.getReferenceByName(refFrom, this);
Reference myReferenceTo = ReferenceStore.getReferenceByName(refTo, this);
if (myReferenceFrom != null && myReferenceTo != null) {
Reading data = new Reading(this, myReferenceFrom, myReferenceTo);
// @todo: we want to separate-out the shipping of the data
// 1. we want the collection (this job) to happen fast
// 2. for the shipping we can afford to wait until more data has been collected
// and for ideal network connectivity (unmetered)
// data.writeTimeSeries(this);
} else {
Log.i(TAG, "No time series were collected as one of the references was null");
}
} catch (Exception e) {
Log.e(TAG, "An error occured: " + e.getMessage());
} finally {
Wakelock.releaseWakelock();
}
jobFinished(jobParameters, false);
}
use of com.asksven.betterbatterystats.data.Reading in project BetterBatteryStats by asksven.
the class WriteDumpfileService method onHandleIntent.
@Override
public void onHandleIntent(Intent intent) {
Log.i(TAG, "Called at " + DateUtils.now());
String refFrom = intent.getStringExtra(WriteDumpfileService.STAT_TYPE_FROM);
String refTo = intent.getStringExtra(WriteDumpfileService.STAT_TYPE_TO);
String output = intent.getStringExtra(WriteDumpfileService.OUTPUT);
if (refTo == null) {
refTo = Reference.CURRENT_REF_FILENAME;
}
// if we want a reading until "current" make sure to update that ref
if (refTo == Reference.CURRENT_REF_FILENAME) {
StatsProvider.getInstance().setCurrentReference(0);
}
Log.i(TAG, "Called with extra " + refFrom + " and " + refTo);
if ((refTo != null) && (refFrom != null) && !refFrom.equals("") && !refTo.equals("")) {
try {
Wakelock.aquireWakelock(this);
// restore any available references if required
Reference myReferenceFrom = ReferenceStore.getReferenceByName(refFrom, this);
Reference myReferenceTo = ReferenceStore.getReferenceByName(refTo, this);
Reading data = new Reading(this, myReferenceFrom, myReferenceTo);
data.writeDumpfile(this, "");
} catch (Exception e) {
Log.e(TAG, "An error occured: " + e.getMessage());
} finally {
Wakelock.releaseWakelock();
}
} else {
Log.i(TAG, "No dumpfile written: " + refFrom + " and " + refTo);
}
}
Aggregations