From fd7f564e11abc566e6d9bb2d3fcc5c6a7eb59342 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 24 Sep 2017 14:32:58 -0700 Subject: [PATCH] add debug menu to copy git info to clipboard Makes it easier to find out what the diffs were. --- xwords4/android/app/build.gradle | 10 ++++-- .../android/xw4/GamesListDelegate.java | 5 +++ .../java/org/eehouse/android/xw4/Utils.java | 32 +++++++++++++++++++ .../app/src/main/res/menu/games_list_menu.xml | 3 ++ .../app/src/main/res/values/strings.xml | 1 + 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index 6cdb233a1..62e4504c7 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -3,6 +3,7 @@ def VERSION_CODE_BASE = 125 def VERSION_NAME = '4.4.129' def FABRIC_API_KEY = System.getenv("FABRIC_API_KEY") def GCM_SENDER_ID = System.getenv("GCM_SENDER_ID") +def BUILD_INFO_NAME = "build-info.txt" boolean forFDroid = hasProperty('forFDroid') @@ -57,6 +58,10 @@ android { flavorDimensions "variant"//, "abi" productFlavors { + all { + buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" + } + xw4 { dimension "variant" applicationId "org.eehouse.android.xw4" @@ -254,15 +259,14 @@ afterEvaluate { task makeBuildAssets() { def assetsDir = android.sourceSets.main.assets.srcDirs.toArray()[0] - String path = new File(assetsDir, 'build-info.txt').getAbsolutePath() - File file = new File(path); + String path = new File(assetsDir, BUILD_INFO_NAME).getAbsolutePath() String out = "git: ${GITREV}\n" String diff = "git diff".execute().text.trim() if (diff) { out += "\n" + diff } - file.write(out) + new File(path).write(out) } gradle.projectsEvaluated { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index e98aecd9f..caf6ca581 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -564,6 +564,7 @@ public class GamesListDelegate extends ListDelegateBase private static final int[] DEBUG_ITEMS = { // R.id.games_menu_loaddb, R.id.games_menu_storedb, + R.id.games_menu_writegit, }; private static final int[] NOSEL_ITEMS = { R.id.games_menu_newgroup, @@ -1597,6 +1598,10 @@ public class GamesListDelegate extends ListDelegateBase Action.STORAGE_CONFIRMED, itemID ); break; + case R.id.games_menu_writegit: + Utils.gitInfoToClip( m_activity ); + break; + default: handled = handleSelGamesItem( itemID, selRowIDs ) || handleSelGroupsItem( itemID, getSelGroupIDs() ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index e76107259..de49a2c2f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -32,7 +32,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.res.AssetManager; import android.content.res.Configuration; +import android.text.ClipboardManager; import android.database.Cursor; import android.media.Ringtone; @@ -55,9 +57,12 @@ import android.widget.Toast; import org.json.JSONException; import org.json.JSONObject; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; @@ -187,6 +192,33 @@ public class Utils { context.startActivity( Intent.createChooser( intent, chooserMsg ) ); } + static void gitInfoToClip( Context context ) + { + StringBuilder sb; + try { + InputStream is = context.getAssets().open( BuildConfig.BUILD_INFO_NAME, + AssetManager.ACCESS_BUFFER ); + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + sb = new StringBuilder(); + for ( ; ; ) { + String line = reader.readLine(); + if ( null == line ) { + break; + } + sb.append( line ).append( "\n" ); + } + reader.close(); + } catch ( Exception ex ) { + sb = null; + } + + if ( null != sb ) { + ClipboardManager clipboard = (ClipboardManager) + context.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText( sb.toString() ); + } + } + public static void postNotification( Context context, Intent intent, int titleID, int bodyID, int id ) { diff --git a/xwords4/android/app/src/main/res/menu/games_list_menu.xml b/xwords4/android/app/src/main/res/menu/games_list_menu.xml index fb964160a..078a860ad 100644 --- a/xwords4/android/app/src/main/res/menu/games_list_menu.xml +++ b/xwords4/android/app/src/main/res/menu/games_list_menu.xml @@ -120,5 +120,8 @@ + diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 9d592eb22..d7831a755 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2491,6 +2491,7 @@ %1$s/%2$s Write games to SD card Load games from SD card + Copy git info to clipboard Accept duplicate invites Fake locale for translation Accept invitations more than once