Surespot: Prepare for 63-fdroid (63)
This commit is contained in:
parent
157177c59f
commit
48a553a7dc
|
@ -49,21 +49,71 @@ Build:61-fdroid,61
|
||||||
popd && \
|
popd && \
|
||||||
sed -i -e 's#android {#android {\nlintOptions {\nabortOnError false\n}\n#' build.gradle
|
sed -i -e 's#android {#android {\nlintOptions {\nabortOnError false\n}\n#' build.gradle
|
||||||
|
|
||||||
|
Build:63-fdroid,63
|
||||||
|
disable=needs cleaning
|
||||||
|
commit=aa83369736b7533cb8ab824ee36be032b40271bf
|
||||||
|
patch=Ex.patch,Im.patch
|
||||||
|
gradle=yes
|
||||||
|
prebuild=pwd && \
|
||||||
|
rm '._.DS_Store' && \
|
||||||
|
rm 'surespot/src/main/res/raw/ffmpegpie' && \
|
||||||
|
rm 'surespot/src/main/res/raw/ffmpeg' && \
|
||||||
|
rm 'surespotcommon/libs/acra-4.5.0.jar' && \
|
||||||
|
touch 'surespot/src/main/res/raw/ffmpegpie' && \
|
||||||
|
touch 'surespot/src/main/res/raw/ffmpeg' && \
|
||||||
|
cp build.gradle build.gradle__BAK && \
|
||||||
|
echo " " >> build.gradle && \
|
||||||
|
cat surespot/build.gradle >> build.gradle && \
|
||||||
|
ln -s surespot/libs libs && \
|
||||||
|
sed -i -e 's#jcenter()#maven { url "https://jcenter.bintray.com" }#g' build.gradle && \
|
||||||
|
sed -i -e 's#com.google.android.gms:play-services-drive:7.8.0#com.android.support:support-v4:19.0.1#' surespot/build.gradle && \
|
||||||
|
sed -i -e 's#com.google.android.gms:play-services-drive:7.8.0#com.android.support:support-v4:19.0.1#' build.gradle && \
|
||||||
|
mkdir -p src/main && \
|
||||||
|
mkdir -p surespotcommon/src/main/res/raw && \
|
||||||
|
sed -i -e 's#Build.VERSION_CODES.M#23#' surespot/src/main/java/com/twofours/surespot/identity/IdentityController.java && \
|
||||||
|
printf 'ssl_strict=true\nbaseUrl=https://server.surespot.me:443\n' > surespotcommon/src/main/res/raw/configuration.properties && \
|
||||||
|
sed -i -e 's#import java.util.Properties;#import java.util.Properties;\nimport com.twofours.surespot.common.R;\n#g' surespotcommon/src/main/java/com/twofours/surespot/common/SurespotConfiguration.java && \
|
||||||
|
ln -s ../../surespot/src/main/AndroidManifest.xml src/main/AndroidManifest.xml && \
|
||||||
|
sed -i -e 's#@integer/google_play_services_version#4030500#' src/main/AndroidManifest.xml && \
|
||||||
|
sed -i -e 's#@integer/google_play_services_version#4030500#' surespot/src/main/AndroidManifest.xml && \
|
||||||
|
ln -s ../../surespot/src/main/aidl src/main/aidl && \
|
||||||
|
ln -s ../../surespot/src/main/java src/main/java && \
|
||||||
|
ln -s ../../surespot/src/main/res src/main/res && \
|
||||||
|
sed -i -e 's#@integer/google_play_services_version#4030500#' src/main/AndroidManifest.xml && \
|
||||||
|
sed -i -e 's#@integer/google_play_services_version#4030500#' surespot/src/main/AndroidManifest.xml && \
|
||||||
|
ln -s surespot/src/main/res && \
|
||||||
|
ln -s surespot/proguard-project.txt && \
|
||||||
|
awk 'NR<=21||NR>=62' proguard-project.txt > proguard-project.txt_ && \
|
||||||
|
mv proguard-project.txt_ proguard-project.txt && \
|
||||||
|
ln -s surespot/proguard-google-api-client.txt && \
|
||||||
|
sed -i -e 's#import org.acra.ACRA;##' androidasynchttp/src/main/java/com/loopj/android/http/AsyncHttpRequest.java && \
|
||||||
|
sed -i -e 's#import org.acra.ACRA;##' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#import org.acra.ReportingInteractionMode;##' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#import org.acra.annotation.ReportsCrashes;##' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#ACRA.init(this);##' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#@ReportsCrashes#// @ReportsCrashes#' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#formUri = "ht#// formUri = "ht#' surespot/src/main/java/com/twofours/surespot/SurespotApplication.java && \
|
||||||
|
sed -i -e 's#compile files(.libs/gcm.jar.)##' build.gradle && \
|
||||||
|
sed -i -e 's#compile files(.*libs.*)##' build.gradle && \
|
||||||
|
rm surespot/src/main/java/com/twofours/surespot/backup/DriveHelper.java && \
|
||||||
|
sed -i -e 's#android {#android {\nlintOptions {\nabortOnError false\n}\n#' build.gradle && \
|
||||||
|
rm surespot/libs/gcm.jar && \
|
||||||
|
rm surespot/libs/* && \
|
||||||
|
git clone https://code.google.com/r/yugandharguduri-yugandhar/ && \
|
||||||
|
cd yugandharguduri-yugandhar && \
|
||||||
|
git checkout 7f647288103bac2c5552af881f0e217c5b95d78a && \
|
||||||
|
cd .. && \
|
||||||
|
cp -av yugandharguduri-yugandhar/gcm-client-deprecated/src/com ./surespot/src/main/java/ && \
|
||||||
|
find yugandharguduri-yugandhar/ -name '*.jar' -exec rm {} \; && \
|
||||||
|
find .google_apis -name '*.jar' -exec rm {} \;
|
||||||
|
novcheck=yes
|
||||||
|
|
||||||
Maintainer Notes:
|
Maintainer Notes:
|
||||||
* Voice function removed
|
* Voice function removed
|
||||||
|
* Export/Import of Identityfile removed (for now)
|
||||||
./surespot/libs/google-api-services-drive-v2-rev103-1.17.0-rc.jar
|
|
||||||
./surespot/libs/jsr305-1.3.9.jar
|
|
||||||
./surespot/libs/google-oauth-client-1.17.0-rc.jar
|
|
||||||
./surespot/libs/google-api-client-android-1.17.0-rc.jar
|
|
||||||
./surespot/libs/google-api-client-1.17.0-rc.jar
|
|
||||||
./surespot/libs/google-http-client-1.17.0-rc.jar
|
|
||||||
./surespot/libs/google-http-client-android-1.17.0-rc.jar
|
|
||||||
./surespot/libs/gcm.jar
|
|
||||||
|
|
||||||
.
|
.
|
||||||
|
|
||||||
Auto Update Mode:None
|
Auto Update Mode:None
|
||||||
Update Check Mode:Tags
|
Update Check Mode:Tags
|
||||||
Current Version:63
|
Current Version:63-fdroid
|
||||||
Current Version Code:63
|
Current Version Code:63
|
||||||
|
|
525
metadata/com.twofours.surespot/Ex-63.patch
Normal file
525
metadata/com.twofours.surespot/Ex-63.patch
Normal file
|
@ -0,0 +1,525 @@
|
||||||
|
diff --git a/surespot/src/main/java/com/twofours/surespot/backup/ExportIdentityActivity.java b/tmp/E3.java
|
||||||
|
index 99ec8f1..70d59bc 100644
|
||||||
|
--- a/surespot/src/main/java/com/twofours/surespot/backup/ExportIdentityActivity.java
|
||||||
|
+++ b/tmp/E3.java
|
||||||
|
@@ -41,15 +41,15 @@ import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.Menu;
|
||||||
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
-import com.google.android.gms.auth.GoogleAuthUtil;
|
||||||
|
-import com.google.android.gms.common.AccountPicker;
|
||||||
|
-import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
|
||||||
|
-import com.google.api.client.http.ByteArrayContent;
|
||||||
|
-import com.google.api.services.drive.Drive;
|
||||||
|
-import com.google.api.services.drive.model.ChildList;
|
||||||
|
-import com.google.api.services.drive.model.ChildReference;
|
||||||
|
-import com.google.api.services.drive.model.FileList;
|
||||||
|
-import com.google.api.services.drive.model.ParentReference;
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
import com.twofours.surespot.R;
|
||||||
|
import com.twofours.surespot.common.FileUtils;
|
||||||
|
import com.twofours.surespot.common.SurespotConstants;
|
||||||
|
@@ -64,11 +64,11 @@ import com.twofours.surespot.ui.UIUtils;
|
||||||
|
public class ExportIdentityActivity extends SherlockActivity {
|
||||||
|
private static final String TAG = "ExportIdentityActivity";
|
||||||
|
private List<String> mIdentityNames;
|
||||||
|
- private DriveHelper mDriveHelper;
|
||||||
|
+
|
||||||
|
private Spinner mSpinner;
|
||||||
|
|
||||||
|
private TextView mAccountNameDisplay;
|
||||||
|
- public static final String[] ACCOUNT_TYPE = new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE};
|
||||||
|
+ public static final String[] ACCOUNT_TYPE = new String[]{"dummy"};
|
||||||
|
private SingleProgressDialog mSpd;
|
||||||
|
private SingleProgressDialog mSpdBackupDir;
|
||||||
|
private AlertDialog mDialog;
|
||||||
|
@@ -79,439 +79,41 @@ public class ExportIdentityActivity extends SherlockActivity {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_export_identity);
|
||||||
|
|
||||||
|
- Utils.configureActionBar(this, getString(R.string.identity), getString(R.string.backup), true);
|
||||||
|
- final String identityDir = FileUtils.getIdentityExportDir().toString();
|
||||||
|
-
|
||||||
|
- TextView tvBackupWarning = (TextView) findViewById(R.id.backupIdentitiesWarning);
|
||||||
|
- Spannable s1 = new SpannableString(getString(R.string.help_backupIdentities1));
|
||||||
|
- s1.setSpan(new ForegroundColorSpan(Color.RED), 0, s1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
- tvBackupWarning.setText(s1);
|
||||||
|
-
|
||||||
|
- final TextView tvPath = (TextView) findViewById(R.id.backupLocalLocation);
|
||||||
|
- mSpinner = (Spinner) findViewById(R.id.identitySpinner);
|
||||||
|
-
|
||||||
|
- final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.sherlock_spinner_item);
|
||||||
|
- adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
|
||||||
|
- mIdentityNames = IdentityController.getIdentityNames(this);
|
||||||
|
-
|
||||||
|
- for (String name : mIdentityNames) {
|
||||||
|
- adapter.add(name);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- mSpinner.setAdapter(adapter);
|
||||||
|
-
|
||||||
|
- String backupUsername = getIntent().getStringExtra("backupUsername");
|
||||||
|
- getIntent().removeExtra("backupUsername");
|
||||||
|
-
|
||||||
|
- mSpinner.setSelection(adapter.getPosition(backupUsername == null ? IdentityController.getLoggedInUser() : backupUsername));
|
||||||
|
- mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
-
|
||||||
|
- String identityFile = identityDir + File.separator + IdentityController.caseInsensitivize(adapter.getItem(position))
|
||||||
|
- + IdentityController.IDENTITY_EXTENSION;
|
||||||
|
- tvPath.setText(identityFile);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- Button exportToSdCardButton = (Button) findViewById(R.id.bExportSd);
|
||||||
|
-
|
||||||
|
- exportToSdCardButton.setEnabled(FileUtils.isExternalStorageMounted());
|
||||||
|
-
|
||||||
|
- exportToSdCardButton.setOnClickListener(new OnClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onClick(View v) {
|
||||||
|
- // TODO progress
|
||||||
|
- final String user = (String) mSpinner.getSelectedItem();
|
||||||
|
- mDialog = UIUtils.passwordDialog(ExportIdentityActivity.this, getString(R.string.backup_identity, user),
|
||||||
|
- getString(R.string.enter_password_for, user), new IAsyncCallback<String>() {
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(String result) {
|
||||||
|
- if (!TextUtils.isEmpty(result)) {
|
||||||
|
- exportIdentity(user, result);
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this, getString(R.string.no_identity_exported));
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- mDriveHelper = new DriveHelper(getApplicationContext(), true);
|
||||||
|
- Button exportToGoogleDriveButton = (Button) findViewById(R.id.bBackupDrive);
|
||||||
|
-
|
||||||
|
- exportToGoogleDriveButton.setOnClickListener(new OnClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onClick(View v) {
|
||||||
|
- if (mDriveHelper.getDriveAccount() != null) {
|
||||||
|
- if (mDriveHelper.getDriveService() != null) {
|
||||||
|
- backupIdentityDrive(true);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- chooseAccount(false);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- mAccountNameDisplay = (TextView) findViewById(R.id.exportDriveAccount);
|
||||||
|
- String account = getSharedPreferences(IdentityController.getLoggedInUser(), Context.MODE_PRIVATE).getString("pref_google_drive_account",
|
||||||
|
- getString(R.string.no_google_account_selected));
|
||||||
|
- mAccountNameDisplay.setText(account);
|
||||||
|
-
|
||||||
|
- Button chooseAccountButton = (Button) findViewById(R.id.bSelectDriveAccount);
|
||||||
|
- chooseAccountButton.setOnClickListener(new OnClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onClick(View v) {
|
||||||
|
-
|
||||||
|
- chooseAccount(true);
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
}
|
||||||
|
|
||||||
|
// //////// Local
|
||||||
|
private void exportIdentity(String user, String password) {
|
||||||
|
- IdentityController.exportIdentity(ExportIdentityActivity.this, user, password, new IAsyncCallback<String>() {
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(String response) {
|
||||||
|
- if (response == null) {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this, getString(R.string.no_identity_exported));
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeLongToast(ExportIdentityActivity.this, response);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
}
|
||||||
|
|
||||||
|
// //////// DRIVE
|
||||||
|
|
||||||
|
private void chooseAccount(boolean ask) {
|
||||||
|
- Intent accountPickerIntent = AccountPicker.newChooseAccountIntent(null, null, ACCOUNT_TYPE, ask, null, null, null, null);
|
||||||
|
-
|
||||||
|
- try {
|
||||||
|
- startActivityForResult(accountPickerIntent, SurespotConstants.IntentRequestCodes.CHOOSE_GOOGLE_ACCOUNT);
|
||||||
|
- }
|
||||||
|
- catch (ActivityNotFoundException e) {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this, getString(R.string.device_does_not_support_google_drive));
|
||||||
|
- SurespotLog.i(TAG, e, "chooseAccount");
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAccount() {
|
||||||
|
- SharedPreferences.Editor editor = getSharedPreferences(IdentityController.getLoggedInUser(), Context.MODE_PRIVATE).edit();
|
||||||
|
- editor.remove("pref_google_drive_account");
|
||||||
|
- editor.commit();
|
||||||
|
-
|
||||||
|
- mAccountNameDisplay.setText(R.string.no_google_account_selected);
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
- switch (requestCode) {
|
||||||
|
- case SurespotConstants.IntentRequestCodes.CHOOSE_GOOGLE_ACCOUNT:
|
||||||
|
- if (data != null) {
|
||||||
|
-
|
||||||
|
- SurespotLog.w("Preferences", "SELECTED ACCOUNT WITH EXTRA: %s", data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
|
||||||
|
- Bundle b = data.getExtras();
|
||||||
|
-
|
||||||
|
- String accountName = b.getString(AccountManager.KEY_ACCOUNT_NAME);
|
||||||
|
-
|
||||||
|
- SurespotLog.d("Preferences", "Selected account: " + accountName);
|
||||||
|
- if (accountName != null && accountName.length() > 0) {
|
||||||
|
-
|
||||||
|
- mDriveHelper.setDriveAccount(accountName);
|
||||||
|
- mAccountNameDisplay.setText(accountName);
|
||||||
|
- backupIdentityDrive(true);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- break;
|
||||||
|
-
|
||||||
|
- case SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH:
|
||||||
|
- if (resultCode == Activity.RESULT_OK) {
|
||||||
|
- Drive drive = mDriveHelper.getDriveService();
|
||||||
|
- if (drive != null) {
|
||||||
|
- backupIdentityDrive(false);
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void backupIdentityDrive(final boolean firstAttempt) {
|
||||||
|
- if (mSpdBackupDir == null) {
|
||||||
|
- mSpdBackupDir = new SingleProgressDialog(this, getString(R.string.progress_drive_dir_check), 1000);
|
||||||
|
- }
|
||||||
|
- mSpdBackupDir.show();
|
||||||
|
- new AsyncTask<Void, Void, String>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- protected String doInBackground(Void... params) {
|
||||||
|
-
|
||||||
|
- return ensureDriveIdentityDirectory();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- protected void onPostExecute(final String identityDirId) {
|
||||||
|
- mSpdBackupDir.hide();
|
||||||
|
- if (identityDirId == null) {
|
||||||
|
- if (!firstAttempt) {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this, getString(R.string.could_not_backup_identity_to_google_drive));
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- SurespotLog.d(TAG, "identity file id: %s", identityDirId);
|
||||||
|
- final String user = (String) mSpinner.getSelectedItem();
|
||||||
|
- mDialog = UIUtils.passwordDialog(ExportIdentityActivity.this, getString(R.string.backup_identity, user),
|
||||||
|
- getString(R.string.enter_password_for, user), new IAsyncCallback<String>() {
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(final String password) {
|
||||||
|
- if (!TextUtils.isEmpty(password)) {
|
||||||
|
- if (mSpd == null) {
|
||||||
|
- mSpd = new SingleProgressDialog(ExportIdentityActivity.this, getString(R.string.progress_backup_identity_drive), 0);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- mSpd.show();
|
||||||
|
-
|
||||||
|
- IdentityController.getExportIdentity(ExportIdentityActivity.this, user, password,
|
||||||
|
- new IAsyncCallbackTuple<byte[], String>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(byte[] identityData, final String message) {
|
||||||
|
-
|
||||||
|
- if (identityData == null) {
|
||||||
|
-
|
||||||
|
- ExportIdentityActivity.this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- mSpd.hide();
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this,
|
||||||
|
- message == null ? getString(R.string.could_not_backup_identity_to_google_drive)
|
||||||
|
- : message);
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- final boolean backedUp = updateIdentityDriveFile(identityDirId, user, identityData);
|
||||||
|
-
|
||||||
|
- ExportIdentityActivity.this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- mSpd.hide();
|
||||||
|
- if (!backedUp) {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this,
|
||||||
|
- getString(R.string.could_not_backup_identity_to_google_drive));
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this,
|
||||||
|
- getString(R.string.identity_successfully_backed_up_to_google_drive));
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeToast(ExportIdentityActivity.this, getString(R.string.no_identity_exported));
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- ;
|
||||||
|
-
|
||||||
|
- }.execute();
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
public String ensureDriveIdentityDirectory() {
|
||||||
|
String identityDirId = null;
|
||||||
|
- try {
|
||||||
|
- // see if identities directory exists
|
||||||
|
-
|
||||||
|
- FileList identityDir = mDriveHelper.getDriveService().files().list()
|
||||||
|
- .setQ("title = '" + SurespotConstants.DRIVE_IDENTITY_FOLDER + "' and trashed = false").execute();
|
||||||
|
- List<com.google.api.services.drive.model.File> items = identityDir.getItems();
|
||||||
|
-
|
||||||
|
- if (items.size() > 0) {
|
||||||
|
- for (com.google.api.services.drive.model.File file : items) {
|
||||||
|
- if (!file.getLabels().getTrashed()) {
|
||||||
|
- SurespotLog.d(TAG, "identity folder already exists");
|
||||||
|
- identityDirId = file.getId();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- if (identityDirId == null) {
|
||||||
|
- com.google.api.services.drive.model.File file = new com.google.api.services.drive.model.File();
|
||||||
|
- file.setTitle(SurespotConstants.DRIVE_IDENTITY_FOLDER);
|
||||||
|
- file.setMimeType(SurespotConstants.MimeTypes.DRIVE_FOLDER);
|
||||||
|
-
|
||||||
|
- com.google.api.services.drive.model.File insertedFile = mDriveHelper.getDriveService().files().insert(file).execute();
|
||||||
|
-
|
||||||
|
- identityDirId = insertedFile.getId();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (UserRecoverableAuthIOException e) {
|
||||||
|
- try {
|
||||||
|
- startActivityForResult(e.getIntent(), SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH);
|
||||||
|
- }
|
||||||
|
- catch (NullPointerException npe) {
|
||||||
|
- return null;
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- }
|
||||||
|
- catch (SecurityException e) {
|
||||||
|
- SurespotLog.e(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- // when key is revoked on server this happens...should return userrecoverable it seems
|
||||||
|
- // was trying to figure out how to test this
|
||||||
|
- // seems like the only way around this is to remove and re-add android account:
|
||||||
|
- // http://stackoverflow.com/questions/5805657/revoke-account-permission-for-an-app
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ExportIdentityActivity.this, getString(R.string.re_add_google_account));
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
return identityDirId;
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean updateIdentityDriveFile(String idDirId, String username, byte[] identityData) {
|
||||||
|
- try {
|
||||||
|
- // gzip identity for consistency - fucked up on this, now have to add code to handle both (gzipped and not gzipped) on restore from google drive
|
||||||
|
- // RM#260
|
||||||
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
- GZIPOutputStream gzout = new GZIPOutputStream(out);
|
||||||
|
- gzout.write(identityData);
|
||||||
|
- gzout.close();
|
||||||
|
- byte[] gzIdData = out.toByteArray();
|
||||||
|
-
|
||||||
|
- ByteArrayContent content = new ByteArrayContent("application/octet-stream", gzIdData);
|
||||||
|
- String caseInsensitiveUsername = IdentityController.caseInsensitivize(username);
|
||||||
|
- String filename = caseInsensitiveUsername + IdentityController.IDENTITY_EXTENSION;
|
||||||
|
-
|
||||||
|
- // see if identity exists
|
||||||
|
- com.google.api.services.drive.model.File file = null;
|
||||||
|
- ChildReference idFile = getIdentityFile(idDirId, caseInsensitiveUsername);
|
||||||
|
- if (idFile != null) {
|
||||||
|
-
|
||||||
|
- // update
|
||||||
|
- file = mDriveHelper.getDriveService().files().get(idFile.getId()).execute();
|
||||||
|
- if (file != null && !file.getLabels().getTrashed()) {
|
||||||
|
- SurespotLog.d(TAG, "updateIdentityDriveFile, updating existing identity file: %s", filename);
|
||||||
|
- mDriveHelper.getDriveService().files().update(file.getId(), file, content).execute();
|
||||||
|
- return true;
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- // create
|
||||||
|
- SurespotLog.d(TAG, "updateIdentityDriveFile, inserting new identity file: %s", filename);
|
||||||
|
-
|
||||||
|
- file = new com.google.api.services.drive.model.File();
|
||||||
|
- ParentReference pr = new ParentReference();
|
||||||
|
- pr.setId(idDirId);
|
||||||
|
- ArrayList<ParentReference> parent = new ArrayList<ParentReference>(1);
|
||||||
|
- parent.add(pr);
|
||||||
|
- file.setParents(parent);
|
||||||
|
- file.setTitle(filename);
|
||||||
|
- file.setMimeType(SurespotConstants.MimeTypes.SURESPOT_IDENTITY);
|
||||||
|
-
|
||||||
|
- com.google.api.services.drive.model.File insertedFile = mDriveHelper.getDriveService().files().insert(file, content).execute();
|
||||||
|
- return true;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (UserRecoverableAuthIOException e) {
|
||||||
|
- startActivityForResult(e.getIntent(), SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH);
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "updateIdentityDriveFile");
|
||||||
|
- }
|
||||||
|
- catch (SecurityException e) {
|
||||||
|
- SurespotLog.e(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- // when key is revoked on server this happens...should return userrecoverable it seems
|
||||||
|
- // was trying to figure out how to test this
|
||||||
|
- // seems like the only way around this is to remove and re-add android account:
|
||||||
|
- // http://stackoverflow.com/questions/5805657/revoke-account-permission-for-an-app
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ExportIdentityActivity.this, getString(R.string.re_add_google_account));
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
+/*
|
||||||
|
private ChildReference getIdentityFile(String identityDirId, String username) throws IOException {
|
||||||
|
ChildReference idFile = null;
|
||||||
|
-
|
||||||
|
- // "title = '" + username + "'";
|
||||||
|
- ChildList identityFileList = mDriveHelper.getDriveService().children().list(identityDirId)
|
||||||
|
- .setQ("title='" + username + IdentityController.IDENTITY_EXTENSION + "' and trashed = false").execute();
|
||||||
|
- List<ChildReference> items = identityFileList.getItems();
|
||||||
|
-
|
||||||
|
- if (items.size() == 1) {
|
||||||
|
- SurespotLog.d(TAG, "getIdentityFile, found identity file for: %s", username);
|
||||||
|
- idFile = items.get(0);
|
||||||
|
- // for (ChildReference file : items) {
|
||||||
|
- // if (!file.getLabels().getTrashed()) {
|
||||||
|
- // SurespotLog.d(TAG, "identity folder already exists");
|
||||||
|
- // identityDirId = file.getId();
|
||||||
|
- // }
|
||||||
|
- // }
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- if (items.size() > 1) {
|
||||||
|
- // delete all but one identity...should never happen
|
||||||
|
- SurespotLog.w(TAG, "$d identities with the same filename found on google drive: %s", items.size(), username);
|
||||||
|
-
|
||||||
|
- for (int i = items.size(); i > 1; i--) {
|
||||||
|
- SurespotLog.w(TAG, "deleting identity file from google drive %s", username);
|
||||||
|
- mDriveHelper.getDriveService().files().delete(items.get(i - 1).getId()).execute();
|
||||||
|
- }
|
||||||
|
- idFile = items.get(0);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
return idFile;
|
||||||
|
}
|
||||||
|
+*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
@@ -527,25 +129,6 @@ public class ExportIdentityActivity extends SherlockActivity {
|
||||||
|
finish();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
- case R.id.menu_help:
|
||||||
|
- View view = LayoutInflater.from(this).inflate(R.layout.dialog_help_backup, null);
|
||||||
|
-
|
||||||
|
- TextView tv = (TextView) view.findViewById(R.id.helpBackup1);
|
||||||
|
- UIUtils.setHtml(this, tv, R.string.help_backup_what);
|
||||||
|
-
|
||||||
|
- TextView t1 = (TextView) view.findViewById(R.id.helpBackup2);
|
||||||
|
- t1.setText(Html.fromHtml(getString(R.string.help_backup_local)));
|
||||||
|
- t1.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
|
-
|
||||||
|
- TextView t2 = (TextView) view.findViewById(R.id.helpBackup3);
|
||||||
|
- UIUtils.setHtml(this, t2, R.string.help_backup_drive1);
|
||||||
|
-
|
||||||
|
- t2 = (TextView) view.findViewById(R.id.helpBackup4);
|
||||||
|
- t2.setText(R.string.help_backup_drive2);
|
||||||
|
-
|
||||||
|
- mDialog = UIUtils.showHelpDialog(this, R.string.surespot_help, view, false);
|
||||||
|
- return true;
|
||||||
|
-
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
@@ -563,13 +146,6 @@ public class ExportIdentityActivity extends SherlockActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
- if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||||
|
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
- openOptionsMenuDeferred();
|
||||||
|
- }
|
||||||
|
- return true;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
|
824
metadata/com.twofours.surespot/Im-63.patch
Normal file
824
metadata/com.twofours.surespot/Im-63.patch
Normal file
|
@ -0,0 +1,824 @@
|
||||||
|
diff --git a/surespot/src/main/java/com/twofours/surespot/backup/ImportIdentityActivity.java b/tmp/I3.java
|
||||||
|
index 59d7759..039ec79 100644
|
||||||
|
--- a/surespot/src/main/java/com/twofours/surespot/backup/ImportIdentityActivity.java
|
||||||
|
+++ b/tmp/I3.java
|
||||||
|
@@ -32,15 +32,15 @@ import android.widget.ViewSwitcher;
|
||||||
|
|
||||||
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
-import com.google.android.gms.auth.GoogleAuthUtil;
|
||||||
|
-import com.google.android.gms.common.AccountPicker;
|
||||||
|
-import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
|
||||||
|
-import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||||
|
-import com.google.api.client.util.DateTime;
|
||||||
|
-import com.google.api.services.drive.Drive;
|
||||||
|
-import com.google.api.services.drive.model.ChildList;
|
||||||
|
-import com.google.api.services.drive.model.ChildReference;
|
||||||
|
-import com.google.api.services.drive.model.FileList;
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+
|
||||||
|
import com.twofours.surespot.R;
|
||||||
|
import com.twofours.surespot.activities.MainActivity;
|
||||||
|
import com.twofours.surespot.common.FileUtils;
|
||||||
|
@@ -59,11 +59,11 @@ public class ImportIdentityActivity extends SherlockActivity {
|
||||||
|
|
||||||
|
private TextView mAccountNameDisplay;
|
||||||
|
private boolean mShowingLocal;
|
||||||
|
- private DriveHelper mDriveHelper;
|
||||||
|
+
|
||||||
|
private ListView mDriveListview;
|
||||||
|
private SingleProgressDialog mSpd;
|
||||||
|
private SingleProgressDialog mSpdLoadIdentities;
|
||||||
|
- public static final String[] ACCOUNT_TYPE = new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE };
|
||||||
|
+ public static final String[] ACCOUNT_TYPE = new String[] { "dummy" };
|
||||||
|
private static final String ACTION_DRIVE_OPEN = "com.google.android.apps.drive.DRIVE_OPEN";
|
||||||
|
private static final String EXTRA_FILE_ID = "resourceId";
|
||||||
|
private String mFileId;
|
||||||
|
@@ -81,778 +81,33 @@ public class ImportIdentityActivity extends SherlockActivity {
|
||||||
|
Utils.configureActionBar(this, getString(R.string.identity), getString(R.string.restore), true);
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
-
|
||||||
|
- Utils.logIntent(TAG, intent);
|
||||||
|
- mSignup = intent.getBooleanExtra("signup", false);
|
||||||
|
- mSpdLoadIdentities = new SingleProgressDialog(ImportIdentityActivity.this, getString(R.string.progress_loading_identities), 0);
|
||||||
|
-
|
||||||
|
- final String action = intent.getAction();
|
||||||
|
-
|
||||||
|
- // Make sure the Action is DRIVE_OPEN.
|
||||||
|
- if (ACTION_DRIVE_OPEN.equals(action)) {
|
||||||
|
- // Get the Drive file ID.
|
||||||
|
- mFileId = intent.getStringExtra(EXTRA_FILE_ID);
|
||||||
|
- mMode = MODE_DRIVE;
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- mMode = MODE_NORMAL;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- mDriveHelper = new DriveHelper(getApplicationContext(), mMode == MODE_NORMAL);
|
||||||
|
-
|
||||||
|
- Account account = mDriveHelper.getDriveAccount();
|
||||||
|
- mAccountNameDisplay = (TextView) findViewById(R.id.restoreDriveAccount);
|
||||||
|
- mAccountNameDisplay.setText(account == null ? getString(R.string.no_google_account_selected) : account.name);
|
||||||
|
-
|
||||||
|
- Button chooseAccountButton = (Button) findViewById(R.id.bSelectDriveAccount);
|
||||||
|
- chooseAccountButton.setOnClickListener(new OnClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onClick(View v) {
|
||||||
|
- chooseAccount(true);
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- mDriveListview = (ListView) findViewById(R.id.lvDriveIdentities);
|
||||||
|
- mDriveListview.setEmptyView(findViewById(R.id.no_drive_identities));
|
||||||
|
-
|
||||||
|
- mDriveListview.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
|
- if (IdentityController.getIdentityCount(ImportIdentityActivity.this) >= SurespotConstants.MAX_IDENTITIES) {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.login_max_identities_reached, SurespotConstants.MAX_IDENTITIES));
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- @SuppressWarnings("unchecked")
|
||||||
|
- final Map<String, String> map = (Map<String, String>) mDriveAdapter.getItem(position);
|
||||||
|
-
|
||||||
|
- final String user = map.get("name");
|
||||||
|
-
|
||||||
|
- // make sure file we're going to save to is writable
|
||||||
|
- // before we
|
||||||
|
- // start
|
||||||
|
- if (!IdentityController.ensureIdentityFile(ImportIdentityActivity.this, user, true)) {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_restore_identity_name, user));
|
||||||
|
- if (mMode == MODE_DRIVE) {
|
||||||
|
- finish();
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- mDialog = UIUtils.passwordDialog(ImportIdentityActivity.this, getString(R.string.restore_identity, user),
|
||||||
|
- getString(R.string.enter_password_for, user), new IAsyncCallback<String>() {
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(final String password) {
|
||||||
|
- if (!TextUtils.isEmpty(password)) {
|
||||||
|
- if (mSpd == null) {
|
||||||
|
- mSpd = new SingleProgressDialog(ImportIdentityActivity.this, getString(R.string.progress_restoring_identity), 0);
|
||||||
|
- }
|
||||||
|
- mSpd.show();
|
||||||
|
-
|
||||||
|
- final String url = map.get("url");
|
||||||
|
-
|
||||||
|
- new AsyncTask<Void, Void, Void>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- protected Void doInBackground(Void... params) {
|
||||||
|
- byte[] identityBytes = mDriveHelper.getFileContent(url);
|
||||||
|
- identityBytes = FileUtils.gunzipIfNecessary(identityBytes);
|
||||||
|
-
|
||||||
|
- IdentityController.importIdentityBytes(ImportIdentityActivity.this, user, password, identityBytes,
|
||||||
|
- new IAsyncCallback<IdentityOperationResult>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(final IdentityOperationResult response) {
|
||||||
|
- Utils.clearIntent(getIntent());
|
||||||
|
- ImportIdentityActivity.this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- mSpd.hide();
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, response.getResultText());
|
||||||
|
-
|
||||||
|
- if (response.getResultSuccess()) {
|
||||||
|
- // if
|
||||||
|
- // launched
|
||||||
|
- // from
|
||||||
|
- // signup
|
||||||
|
- // and
|
||||||
|
- // successful
|
||||||
|
- // import,
|
||||||
|
- // go
|
||||||
|
- // to
|
||||||
|
- // login
|
||||||
|
- // screen
|
||||||
|
- if (mSignup || mMode == MODE_DRIVE) {
|
||||||
|
- IdentityController.logout();
|
||||||
|
-
|
||||||
|
- Intent intent = new Intent(ImportIdentityActivity.this, MainActivity.class);
|
||||||
|
- intent.putExtra(SurespotConstants.ExtraNames.MESSAGE_TO, user);
|
||||||
|
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
- startActivity(intent);
|
||||||
|
- finish();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- });
|
||||||
|
- return null;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }.execute();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.no_identity_imported));
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- mSwitcher = (ViewSwitcher) findViewById(R.id.restoreViewSwitcher);
|
||||||
|
- RadioButton rbRestoreLocal = (RadioButton) findViewById(R.id.rbRestoreLocal);
|
||||||
|
- RadioButton rbRestoreDrive = (RadioButton) findViewById(R.id.rbRestoreDrive);
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
-
|
||||||
|
- rbRestoreLocal.setTag("local");
|
||||||
|
- rbRestoreLocal.setChecked(true);
|
||||||
|
- mShowingLocal = true;
|
||||||
|
-
|
||||||
|
- rbRestoreDrive.setTag("drive");
|
||||||
|
-
|
||||||
|
- OnClickListener rbClickListener = new OnClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onClick(View view) {
|
||||||
|
- // Is the button now checked?
|
||||||
|
- boolean checked = ((RadioButton) view).isChecked();
|
||||||
|
-
|
||||||
|
- if (checked) {
|
||||||
|
- if (view.getTag().equals("drive")) {
|
||||||
|
- if (mShowingLocal) {
|
||||||
|
-
|
||||||
|
- mDriveListview.setAdapter(null);
|
||||||
|
- mSwitcher.showNext();
|
||||||
|
- mShowingLocal = false;
|
||||||
|
-
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
- if (mDriveHelper.getDriveAccount() != null) {
|
||||||
|
- Drive drive = mDriveHelper.getDriveService();
|
||||||
|
- if (drive != null) {
|
||||||
|
- mSpdLoadIdentities.show();
|
||||||
|
- new AsyncTask<Void, Void, Void>() {
|
||||||
|
- @Override
|
||||||
|
- protected Void doInBackground(Void... params) {
|
||||||
|
- populateDriveIdentities(true);
|
||||||
|
-
|
||||||
|
- return null;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }.execute();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- chooseAccount(false);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- if (!mShowingLocal) {
|
||||||
|
- mSwitcher.showPrevious();
|
||||||
|
- mShowingLocal = true;
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- };
|
||||||
|
-
|
||||||
|
- rbRestoreDrive.setOnClickListener(rbClickListener);
|
||||||
|
- rbRestoreLocal.setOnClickListener(rbClickListener);
|
||||||
|
- setupLocal();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- rbRestoreLocal.setVisibility(View.GONE);
|
||||||
|
- rbRestoreDrive.setChecked(true);
|
||||||
|
- mSwitcher.showNext();
|
||||||
|
- mShowingLocal = false;
|
||||||
|
-
|
||||||
|
- new AsyncTask<Void, Void, Void>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- protected Void doInBackground(Void... params) {
|
||||||
|
- restoreExternal(true);
|
||||||
|
- return null;
|
||||||
|
- }
|
||||||
|
- }.execute();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupLocal() {
|
||||||
|
-
|
||||||
|
- ListView lvIdentities = (ListView) findViewById(R.id.lvLocalIdentities);
|
||||||
|
- lvIdentities.setEmptyView(findViewById(R.id.no_local_identities));
|
||||||
|
-
|
||||||
|
- List<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
|
||||||
|
-
|
||||||
|
- // query the filesystem for identities
|
||||||
|
- final File exportDir = FileUtils.getIdentityExportDir();
|
||||||
|
- File[] files = IdentityController.getExportIdentityFiles(this, exportDir.getPath());
|
||||||
|
-
|
||||||
|
- TextView tvLocalLocation = (TextView) findViewById(R.id.restoreLocalLocation);
|
||||||
|
-
|
||||||
|
- if (files != null) {
|
||||||
|
- TreeMap<Long, File> sortedFiles = new TreeMap<Long, File>(new Comparator<Long>() {
|
||||||
|
- public int compare(Long o1, Long o2) {
|
||||||
|
- return o2.compareTo(o1);
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- for (File file : files) {
|
||||||
|
- sortedFiles.put(file.lastModified(), file);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- for (File file : sortedFiles.values()) {
|
||||||
|
- long lastModTime = file.lastModified();
|
||||||
|
- String date = DateFormat.getDateFormat(this).format(lastModTime) + " " + DateFormat.getTimeFormat(this).format(lastModTime);
|
||||||
|
-
|
||||||
|
- HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
- map.put("name", IdentityController.getIdentityNameFromFile(file));
|
||||||
|
- map.put("date", date);
|
||||||
|
- items.add(map);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- final SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.identity_item, new String[] { "name", "date" }, new int[] {
|
||||||
|
- R.id.identityBackupName, R.id.identityBackupDate });
|
||||||
|
- tvLocalLocation.setText(exportDir.toString());
|
||||||
|
- lvIdentities.setVisibility(View.VISIBLE);
|
||||||
|
-
|
||||||
|
- lvIdentities.setAdapter(adapter);
|
||||||
|
- lvIdentities.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
- if (IdentityController.getIdentityCount(ImportIdentityActivity.this) >= SurespotConstants.MAX_IDENTITIES) {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.login_max_identities_reached, SurespotConstants.MAX_IDENTITIES));
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- @SuppressWarnings("unchecked")
|
||||||
|
- Map<String, String> map = (Map<String, String>) adapter.getItem(position);
|
||||||
|
-
|
||||||
|
- final String user = map.get("name");
|
||||||
|
-
|
||||||
|
- // make sure file we're going to save to is writable before we
|
||||||
|
- // start
|
||||||
|
- if (!IdentityController.ensureIdentityFile(ImportIdentityActivity.this, user, true)) {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_import_identity));
|
||||||
|
- if (mMode == MODE_DRIVE) {
|
||||||
|
- finish();
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- UIUtils.passwordDialog(ImportIdentityActivity.this, getString(R.string.restore_identity, user), getString(R.string.enter_password_for, user),
|
||||||
|
- new IAsyncCallback<String>() {
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(String result) {
|
||||||
|
- if (!TextUtils.isEmpty(result)) {
|
||||||
|
- IdentityController.importIdentity(ImportIdentityActivity.this, exportDir, user, result,
|
||||||
|
- new IAsyncCallback<IdentityOperationResult>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void handleResponse(IdentityOperationResult response) {
|
||||||
|
-
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, response.getResultText());
|
||||||
|
-
|
||||||
|
- if (response.getResultSuccess()) {
|
||||||
|
- // if launched
|
||||||
|
- // from
|
||||||
|
- // signup and
|
||||||
|
- // successful
|
||||||
|
- // import, go to
|
||||||
|
- // login
|
||||||
|
- // screen
|
||||||
|
- if (mSignup) {
|
||||||
|
- IdentityController.logout();
|
||||||
|
-
|
||||||
|
- Intent intent = new Intent(ImportIdentityActivity.this, MainActivity.class);
|
||||||
|
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
- startActivity(intent);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.no_identity_imported));
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restoreExternal(boolean firstTime) {
|
||||||
|
- if (!firstTime) {
|
||||||
|
-
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_import_identity));
|
||||||
|
- finish();
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- if (mDriveHelper.getDriveAccount() == null) {
|
||||||
|
- chooseAccount(false);
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- List<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
|
||||||
|
- try {
|
||||||
|
- com.google.api.services.drive.model.File file = mDriveHelper.getDriveService().files().get(mFileId).execute();
|
||||||
|
-
|
||||||
|
- if (!file.getLabels().getTrashed()) {
|
||||||
|
-
|
||||||
|
- DateTime lastModTime = file.getModifiedDate();
|
||||||
|
-
|
||||||
|
- String date = DateFormat.getDateFormat(this).format(lastModTime.getValue()) + " "
|
||||||
|
- + DateFormat.getTimeFormat(this).format(lastModTime.getValue());
|
||||||
|
- HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
- String name = IdentityController.getIdentityNameFromFilename(file.getTitle());
|
||||||
|
- map.put("name", name);
|
||||||
|
- map.put("date", date);
|
||||||
|
- map.put("url", file.getDownloadUrl());
|
||||||
|
- items.add(map);
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- SurespotLog.w(TAG, "could not retrieve identity from google drive");
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_import_identity));
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- finish();
|
||||||
|
-
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (UserRecoverableAuthIOException e) {
|
||||||
|
- try {
|
||||||
|
- startActivityForResult(e.getIntent(), SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH);
|
||||||
|
- }
|
||||||
|
- catch (NullPointerException npe) {
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (GoogleJsonResponseException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "could not retrieve identity from google drive");
|
||||||
|
-
|
||||||
|
- // if they're restoring from drive, selecting different account in
|
||||||
|
- // surespot will cause 404
|
||||||
|
- if (e.getStatusCode() == 404 && mMode == MODE_DRIVE) {
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.could_not_import_identity_drive_404));
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "could not retrieve identity from google drive");
|
||||||
|
-
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_import_identity));
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- finish();
|
||||||
|
- return;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (SecurityException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- // when key is revoked on server this happens...should return
|
||||||
|
- // userrecoverable it seems
|
||||||
|
- // was trying to figure out how to test this
|
||||||
|
- // seems like the only way around this is to remove and re-add
|
||||||
|
- // android account:
|
||||||
|
- // http://stackoverflow.com/questions/5805657/revoke-account-permission-for-an-app
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.re_add_google_account));
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- finish();
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- SurespotLog.v(TAG, "loaded %d identities from google drive", items.size());
|
||||||
|
-
|
||||||
|
- mDriveAdapter = new SimpleAdapter(this, items, R.layout.identity_item, new String[] { "name", "date" }, new int[] { R.id.identityBackupName,
|
||||||
|
- R.id.identityBackupDate });
|
||||||
|
-
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
-
|
||||||
|
- mDriveListview.setAdapter(mDriveAdapter);
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateDriveIdentities(boolean firstAttempt) {
|
||||||
|
-
|
||||||
|
- String identityDirId = ensureDriveIdentityDirectory();
|
||||||
|
- if (identityDirId == null) {
|
||||||
|
- if (!firstAttempt) {
|
||||||
|
-
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_list_identities_from_google_drive));
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- List<HashMap<String, String>> items = new ArrayList<HashMap<String, String>>();
|
||||||
|
- try {
|
||||||
|
- // query the drive for identities
|
||||||
|
- ChildList fileList = getIdentityFiles(identityDirId);
|
||||||
|
- if (fileList == null) {
|
||||||
|
- SurespotLog.v(TAG, "no identity backup files found on google drive");
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- mSpdLoadIdentities.hide();
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- return;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- List<ChildReference> refs = fileList.getItems();
|
||||||
|
-
|
||||||
|
- if (refs.size() == 0) {
|
||||||
|
- SurespotLog.v(TAG, "no identity backup files found on google drive");
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- mSpdLoadIdentities.hide();
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- if (refs.size() > 0) {
|
||||||
|
- TreeMap<Long, com.google.api.services.drive.model.File> sortedFiles = new TreeMap<Long, com.google.api.services.drive.model.File>(
|
||||||
|
- new Comparator<Long>() {
|
||||||
|
- public int compare(Long o1, Long o2) {
|
||||||
|
- return o2.compareTo(o1);
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
- for (ChildReference ref : refs) {
|
||||||
|
- com.google.api.services.drive.model.File file = mDriveHelper.getDriveService().files().get(ref.getId()).execute();
|
||||||
|
-
|
||||||
|
- if (!file.getLabels().getTrashed()) {
|
||||||
|
- DateTime lastModTime = file.getModifiedDate();
|
||||||
|
- sortedFiles.put(lastModTime.getValue(), file);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- for (com.google.api.services.drive.model.File file : sortedFiles.values()) {
|
||||||
|
- DateTime lastModTime = file.getModifiedDate();
|
||||||
|
- String date = DateFormat.getDateFormat(this).format(lastModTime.getValue()) + " "
|
||||||
|
- + DateFormat.getTimeFormat(this).format(lastModTime.getValue());
|
||||||
|
- HashMap<String, String> map = new HashMap<String, String>();
|
||||||
|
- String name = IdentityController.getIdentityNameFromFilename(file.getTitle());
|
||||||
|
- map.put("name", name);
|
||||||
|
- map.put("date", date);
|
||||||
|
- map.put("url", file.getDownloadUrl());
|
||||||
|
- items.add(map);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- catch (UserRecoverableAuthIOException e) {
|
||||||
|
- try {
|
||||||
|
- startActivityForResult(e.getIntent(), SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH);
|
||||||
|
- }
|
||||||
|
- catch (NullPointerException npe) {
|
||||||
|
- }
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "could not retrieve identities from google drive");
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.could_not_list_identities_from_google_drive));
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- return;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (SecurityException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- // when key is revoked on server this happens...should return
|
||||||
|
- // userrecoverable it seems
|
||||||
|
- // was trying to figure out how to test this
|
||||||
|
- // seems like the only way around this is to remove and re-add
|
||||||
|
- // android account:
|
||||||
|
- // http://stackoverflow.com/questions/5805657/revoke-account-permission-for-an-app
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.re_add_google_account));
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- return;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- SurespotLog.v(TAG, "loaded %d identities from google drive", items.size());
|
||||||
|
-
|
||||||
|
- mDriveAdapter = new SimpleAdapter(this, items, R.layout.identity_item, new String[] { "name", "date" }, new int[] { R.id.identityBackupName,
|
||||||
|
- R.id.identityBackupDate });
|
||||||
|
-
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
-
|
||||||
|
- mSpdLoadIdentities.hide();
|
||||||
|
- mDriveListview.setAdapter(mDriveAdapter);
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
+/*
|
||||||
|
private ChildList getIdentityFiles(String identityDirId) {
|
||||||
|
ChildList identityFileList = null;
|
||||||
|
- try {
|
||||||
|
- identityFileList = mDriveHelper.getDriveService().children().list(identityDirId).execute();
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "getIdentityFiles");
|
||||||
|
- }
|
||||||
|
return identityFileList;
|
||||||
|
}
|
||||||
|
-
|
||||||
|
+*/
|
||||||
|
public String ensureDriveIdentityDirectory() {
|
||||||
|
String identityDirId = null;
|
||||||
|
- try {
|
||||||
|
- // see if identities directory exists
|
||||||
|
-
|
||||||
|
- FileList identityDir = mDriveHelper.getDriveService().files().list()
|
||||||
|
- .setQ("title = '" + SurespotConstants.DRIVE_IDENTITY_FOLDER + "' and trashed = false").execute();
|
||||||
|
- List<com.google.api.services.drive.model.File> items = identityDir.getItems();
|
||||||
|
-
|
||||||
|
- if (items.size() > 0) {
|
||||||
|
- for (com.google.api.services.drive.model.File file : items) {
|
||||||
|
- if (!file.getLabels().getTrashed()) {
|
||||||
|
- SurespotLog.d(TAG, "identity folder already exists");
|
||||||
|
- identityDirId = file.getId();
|
||||||
|
- break;
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- if (identityDirId == null) {
|
||||||
|
- com.google.api.services.drive.model.File file = new com.google.api.services.drive.model.File();
|
||||||
|
- file.setTitle(SurespotConstants.DRIVE_IDENTITY_FOLDER);
|
||||||
|
- file.setMimeType(SurespotConstants.MimeTypes.DRIVE_FOLDER);
|
||||||
|
-
|
||||||
|
- com.google.api.services.drive.model.File insertedFile = mDriveHelper.getDriveService().files().insert(file).execute();
|
||||||
|
-
|
||||||
|
- identityDirId = insertedFile.getId();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- catch (UserRecoverableAuthIOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- //try {
|
||||||
|
- startActivityForResult(e.getIntent(), SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH);
|
||||||
|
-// }
|
||||||
|
-// catch (NullPointerException npe) {
|
||||||
|
-// return null;
|
||||||
|
-// }
|
||||||
|
- }
|
||||||
|
- catch (IOException e) {
|
||||||
|
- SurespotLog.w(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- }
|
||||||
|
- catch (SecurityException e) {
|
||||||
|
- SurespotLog.e(TAG, e, "createDriveIdentityDirectory");
|
||||||
|
- // when key is revoked on server this happens...should return
|
||||||
|
- // userrecoverable it seems
|
||||||
|
- // was trying to figure out how to test this
|
||||||
|
- // seems like the only way around this is to remove and re-add
|
||||||
|
- // android account:
|
||||||
|
- // http://stackoverflow.com/questions/5805657/revoke-account-permission-for-an-app
|
||||||
|
- this.runOnUiThread(new Runnable() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- public void run() {
|
||||||
|
- Utils.makeLongToast(ImportIdentityActivity.this, getString(R.string.re_add_google_account));
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
return identityDirId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// //////// DRIVE
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
- switch (requestCode) {
|
||||||
|
- case SurespotConstants.IntentRequestCodes.CHOOSE_GOOGLE_ACCOUNT:
|
||||||
|
-
|
||||||
|
- if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
|
-
|
||||||
|
- SurespotLog.w("Preferences", "SELECTED ACCOUNT WITH EXTRA: %s", data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME));
|
||||||
|
- Bundle b = data.getExtras();
|
||||||
|
-
|
||||||
|
- String accountName = b.getString(AccountManager.KEY_ACCOUNT_NAME);
|
||||||
|
-
|
||||||
|
- SurespotLog.d("Preferences", "Selected account: " + accountName);
|
||||||
|
- if (accountName != null && accountName.length() > 0) {
|
||||||
|
-
|
||||||
|
- mDriveHelper.setDriveAccount(accountName);
|
||||||
|
- mAccountNameDisplay.setText(accountName);
|
||||||
|
- if (mDriveListview != null) {
|
||||||
|
- mDriveListview.setAdapter(null);
|
||||||
|
- }
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
- mSpdLoadIdentities.show();
|
||||||
|
- }
|
||||||
|
- new AsyncTask<Void, Void, Void>() {
|
||||||
|
- @Override
|
||||||
|
- protected Void doInBackground(Void... params) {
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
- populateDriveIdentities(true);
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- restoreExternal(true);
|
||||||
|
- }
|
||||||
|
- return null;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- }.execute();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
- break;
|
||||||
|
-
|
||||||
|
- case SurespotConstants.IntentRequestCodes.REQUEST_GOOGLE_AUTH:
|
||||||
|
- if (resultCode == Activity.RESULT_OK) {
|
||||||
|
- SurespotLog.v(TAG, "onActivityResult OK");
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
- mSpdLoadIdentities.show();
|
||||||
|
- }
|
||||||
|
- new AsyncTask<Void, Void, Boolean>() {
|
||||||
|
-
|
||||||
|
- @Override
|
||||||
|
- protected Boolean doInBackground(Void... params) {
|
||||||
|
- Drive drive = mDriveHelper.getDriveService();
|
||||||
|
- if (drive != null) {
|
||||||
|
- if (mMode == MODE_NORMAL) {
|
||||||
|
- populateDriveIdentities(false);
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- restoreExternal(false);
|
||||||
|
- }
|
||||||
|
- return true;
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- return false;
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- protected void onPostExecute(Boolean result) {
|
||||||
|
- if (!result) {
|
||||||
|
- mSpdLoadIdentities.hide();
|
||||||
|
- }
|
||||||
|
- };
|
||||||
|
- }.execute();
|
||||||
|
-
|
||||||
|
- }
|
||||||
|
- else {
|
||||||
|
- SurespotLog.v(TAG, "onActivityResult not OK");
|
||||||
|
- mSpdLoadIdentities.hide();
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chooseAccount(boolean ask) {
|
||||||
|
- String descriptionText = null;
|
||||||
|
- if (mMode == MODE_DRIVE) {
|
||||||
|
- descriptionText = getString(R.string.pick_same_drive_account);
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- Intent accountPickerIntent = AccountPicker.newChooseAccountIntent(null, null, ACCOUNT_TYPE, ask || mMode == MODE_DRIVE, descriptionText, null, null,
|
||||||
|
- null);
|
||||||
|
- try {
|
||||||
|
- startActivityForResult(accountPickerIntent, SurespotConstants.IntentRequestCodes.CHOOSE_GOOGLE_ACCOUNT);
|
||||||
|
- }
|
||||||
|
- catch (ActivityNotFoundException e) {
|
||||||
|
- Utils.makeToast(ImportIdentityActivity.this, getString(R.string.device_does_not_support_google_drive));
|
||||||
|
- SurespotLog.i(TAG, e, "chooseAccount");
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
Loading…
Reference in a new issue