Search in sources :

Example 1 with GamesBackupSummaryAdapter

use of com.nolanlawson.keepscore.data.GamesBackupSummaryAdapter in project KeepScore by nolanlawson.

the class MainActivity method showLoadBackupDialogFinished.

private void showLoadBackupDialogFinished(List<GamesBackupSummary> summaries) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final GamesBackupSummaryAdapter adapter = new GamesBackupSummaryAdapter(MainActivity.this, displayMetrics, summaries);
    new AlertDialog.Builder(MainActivity.this).setCancelable(true).setTitle(R.string.title_choose_backup).setNegativeButton(android.R.string.cancel, null).setAdapter(adapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            GamesBackupSummary summary = adapter.getItem(which);
            Uri uri = Uri.fromFile(SdcardHelper.getFile(summary.getFilename(), Location.Backups));
            Format format = summary.getFilename().endsWith(".gz") ? Format.GZIP : Format.XML;
            loadBackup(summary, uri, format);
        }
    }).show();
}
Also used : AlertDialog(android.app.AlertDialog) GamesBackupSummaryAdapter(com.nolanlawson.keepscore.data.GamesBackupSummaryAdapter) Format(com.nolanlawson.keepscore.helper.SdcardHelper.Format) DialogInterface(android.content.DialogInterface) GamesBackupSummary(com.nolanlawson.keepscore.serialization.GamesBackupSummary) OnClickListener(android.view.View.OnClickListener) DisplayMetrics(android.util.DisplayMetrics) Uri(android.net.Uri)

Example 2 with GamesBackupSummaryAdapter

use of com.nolanlawson.keepscore.data.GamesBackupSummaryAdapter in project KeepScore by nolanlawson.

the class MainActivity method loadBackupFileFromShare.

/**
     * if the user opened up a games-20xxxxxxxxx.xml.gz file from a file browser, open it here.
     * @param intent
     */
private void loadBackupFileFromShare(final Intent intent) {
    if (intent == null || intent.getData() == null) {
        // no intent data, so abort
        return;
    }
    // this functionality is not supported in Eclair
    if (VersionHelper.getVersionSdkIntCompat() < VersionHelper.VERSION_FROYO) {
        return;
    }
    if (uriIntentsConfirmedByUser.contains(intent.getDataString())) {
        // user already dismissed or confirmed the dialog; no need to show it again
        return;
    }
    log.i("Received intent: %s", intent);
    log.i("Received data: %s", intent.getData());
    GamesBackupSummary summary;
    try {
        summary = GamesBackupSerializer.readGamesBackupSummary(intent.getData(), Format.XML, getContentResolver());
    } catch (Exception e) {
        log.e(e, "Unexpected error loading %s", intent.getData());
        ToastHelper.showLong(this, R.string.toast_error_with_backup);
        return;
    }
    final GamesBackupSummary finalSummary = summary;
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    GamesBackupSummaryAdapter adapter = new GamesBackupSummaryAdapter(this, displayMetrics, new ArrayList<GamesBackupSummary>(Collections.singleton(finalSummary)));
    DialogInterface.OnClickListener onOk = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            uriIntentsConfirmedByUser.add(intent.getDataString());
            loadBackup(finalSummary, intent.getData(), Format.XML);
        }
    };
    DialogInterface.OnClickListener onCancel = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            uriIntentsConfirmedByUser.add(intent.getDataString());
        }
    };
    new AlertDialog.Builder(this).setCancelable(true).setTitle(R.string.title_choose_backup).setNegativeButton(android.R.string.cancel, onCancel).setPositiveButton(android.R.string.ok, onOk).setAdapter(adapter, onOk).show();
}
Also used : GamesBackupSummaryAdapter(com.nolanlawson.keepscore.data.GamesBackupSummaryAdapter) DialogInterface(android.content.DialogInterface) GamesBackupSummary(com.nolanlawson.keepscore.serialization.GamesBackupSummary) OnClickListener(android.view.View.OnClickListener) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

DialogInterface (android.content.DialogInterface)2 DisplayMetrics (android.util.DisplayMetrics)2 OnClickListener (android.view.View.OnClickListener)2 GamesBackupSummaryAdapter (com.nolanlawson.keepscore.data.GamesBackupSummaryAdapter)2 GamesBackupSummary (com.nolanlawson.keepscore.serialization.GamesBackupSummary)2 AlertDialog (android.app.AlertDialog)1 Uri (android.net.Uri)1 Format (com.nolanlawson.keepscore.helper.SdcardHelper.Format)1