From 029879fcf4a31b54241334dde179f74f5b860136 Mon Sep 17 00:00:00 2001 From: Bao Haojun Date: Sat, 29 Oct 2016 00:25:21 +0800 Subject: [PATCH] SetClip/.install-hook: Add debug hook SetClip/src/com/bhj/setclip/PutClipService.java: Add apps info list Wrench.qrc: add mobile launcher wrench.lua: add apps loader wrenchmainwindow.cpp: add launcher wrenchmainwindow.ui: add launcher Signed-off-by: Bao Haojun --- SetClip/.install-hook | 8 ++- .../src/com/bhj/setclip/PutClipService.java | 67 ++++++++++++++---- Wrench.qrc | 1 + resources/MOBILE_PHONE.png | Bin 0 -> 2793 bytes wrench.lua | 26 ++++++- wrenchmainwindow.cpp | 5 ++ wrenchmainwindow.h | 2 + wrenchmainwindow.ui | 16 ++++- 8 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 resources/MOBILE_PHONE.png diff --git a/SetClip/.install-hook b/SetClip/.install-hook index 4f9a973d..90c26da5 100755 --- a/SetClip/.install-hook +++ b/SetClip/.install-hook @@ -1,7 +1,13 @@ #!/bin/bash +apk=SetClip-release.apk + +if test "$ANT_DEBUG_BUILD" = true; then + apk=SetClip-debug.apk +fi + ( - cp bin/SetClip-release.apk ~/src/github/Wrench/release/Setclip.apk + cp bin/$apk ~/src/github/Wrench/release/Setclip.apk cd ~/src/github/Wrench/release/ md5sum Setclip.apk > Setclip.apk.md5 adb push Setclip.apk.md5 /sdcard/ diff --git a/SetClip/src/com/bhj/setclip/PutClipService.java b/SetClip/src/com/bhj/setclip/PutClipService.java index 3ce2457b..e476cde8 100644 --- a/SetClip/src/com/bhj/setclip/PutClipService.java +++ b/SetClip/src/com/bhj/setclip/PutClipService.java @@ -1,11 +1,11 @@ package com.bhj.setclip; -import android.app.ActivityManager.RunningTaskInfo; import android.app.ActivityManager; +import android.app.ActivityManager.RunningTaskInfo; import android.app.Notification; import android.app.Service; -import android.content.ClipData; import android.content.ClipboardManager; +import android.content.ClipData; import android.content.ContentProvider; import android.content.ContentResolver; import android.content.Context; @@ -16,22 +16,23 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Environment; import android.os.IBinder; +import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.Contacts.Entity; import android.provider.ContactsContract.Data; import android.provider.ContactsContract.RawContacts; -import android.provider.ContactsContract; import android.telephony.TelephonyManager; import android.util.Log; import java.io.File; +import java.io.FilenameFilter; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; -import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -183,18 +184,55 @@ private boolean saveBitmapToFile(File dir, String fileName, Bitmap bm, return false; } - private void loadApps() { + + + private static Bitmap drawableToBitmap (Drawable drawable) { + Bitmap bitmap = null; + + if (drawable instanceof BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + if(bitmapDrawable.getBitmap() != null) { + return bitmapDrawable.getBitmap(); + } + } + + if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { + bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel + } else { + bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + } + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + return bitmap; + } + + + private void loadApps() throws IOException { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mApps = getPackageManager().queryIntentActivities(mainIntent, 0); - ResolveInfo info = mApps.get(0); - Drawable icon = info.activityInfo.loadDefaultIcon(getPackageManager()); - Bitmap bm = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bm); - icon.draw(canvas); - saveBitmapToFile(sdcard, "hello-world.png", bm, Bitmap.CompressFormat.PNG, 100); + File wrenchDir = new File(sdcard, "Wrench"); + wrenchDir.mkdir(); + + FileWriter appListFile = new FileWriter(new File(wrenchDir, "apps.txt")); + + for (int i = 0; i < mApps.size(); i++) { + ResolveInfo info = mApps.get(i); + appListFile.write( + String.format("%s=%s=%s\n", + info.activityInfo.name, + info.activityInfo.packageName, + info.activityInfo.loadLabel(getPackageManager()))); + Drawable icon = info.activityInfo.loadIcon(getPackageManager()); + Bitmap bm = drawableToBitmap(icon); + saveBitmapToFile(wrenchDir, String.format("%s.png", info.activityInfo.name), bm, Bitmap.CompressFormat.PNG, 100); + } + appListFile.close(); + new File(wrenchDir, "apps.txt").renameTo(new File(wrenchDir, "apps.info")); } @Override @@ -230,7 +268,12 @@ public int onStartCommand(Intent intent, int flags, int startId) { String mPhoneNumber = tMgr.getLine1Number(); writeFile(mPhoneNumber); } else if (intent.getIntExtra("listapps", 0) == 1) { - loadApps(); + try { + loadApps(); + } catch (IOException e) { + Log.e("bhj", String.format("%s:%d: ", "PutClipService.java", 273), e); + } + } else if (intent.getIntExtra("listcontacts", 0) == 1) { String data2 = intent.getStringExtra("data2"); String data3 = intent.getStringExtra("data3"); diff --git a/Wrench.qrc b/Wrench.qrc index 189cc738..85192698 100644 --- a/Wrench.qrc +++ b/Wrench.qrc @@ -12,6 +12,7 @@ resources/capture-screen.png resources/phone-screen.png + resources/MOBILE_PHONE.png resources/picture.png resources/emoji.png resources/com_sina_weibo_icon.png diff --git a/resources/MOBILE_PHONE.png b/resources/MOBILE_PHONE.png new file mode 100644 index 0000000000000000000000000000000000000000..75c62f38e7de2907395b36b0e6450939ff575f63 GIT binary patch literal 2793 zcmV004R>004l5008;`004mK004C`008P>0026e000+ooVrmw00006 zVoOIv0RI600RN!9r;`8x00(qQO+^RZ3lReXH}hDpzyJUV?MXyIRA}DqnOkg>#}&ta zGqZQEZ`j^|!GIeZ0tr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){Io)TlN^zL>+qOrVHzg55POz*} z3L(I@M+_5>$LZ?oTDf5vCB6uKRFyalZI@*?VXE9E*t zLB1c8b#kn~6sJrQHpLVc6c7y$Ptox%f(IQotQHhVF+hR#7 z&idgFoK6=kDZ!GGifA`WVljMvKbgWJv^HG3Q-Nh!6c^{?H3_=AyRj^5@h-N;gl4l@ z>g(%iZf-^hk!!fdA2{~R>2v~+$z-NoGbT44kLRu)7v*Ykd>XYZ3(K;mT`Q%epr9ak z!E1~m5{XQE6*)E*{aR%%+%(4E_xs7q%VTJ02!NuZB5d0x91hP4U_4zXdu_oyFxy(M z*GnJ}!0Yt_;P?BnZJVK?p|8gST5B=ewfcAf(P)&Ck`gK^Dga2OQe3}&eNGe_4`jgr zq*AH0l#BWu^LMF>HAdwY&fGg;QQZK|rOP)dQ9&>mJXKj)S-)%7uBTpj;RSj5@?}Dy(1LzuEiEl&)22;mt+{aF zLVIIl<6nDwdlM^GteA1{Ts4qOmoDADW5addScript(QStringList() << "launch_apps"); +} diff --git a/wrenchmainwindow.h b/wrenchmainwindow.h index 0c1d04ed..d0490310 100644 --- a/wrenchmainwindow.h +++ b/wrenchmainwindow.h @@ -102,6 +102,8 @@ private slots: void on_tbPhoneScreen_toggled(bool checked); + void on_tbLauncher_clicked(); + private: bool anyShareChecked(); diff --git a/wrenchmainwindow.ui b/wrenchmainwindow.ui index 9955e20a..5f0c51f8 100644 --- a/wrenchmainwindow.ui +++ b/wrenchmainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 580 + 618 592 @@ -245,6 +245,20 @@ + + + + Launcher (start apps) + + + ... + + + + :/skin/default/resources/MOBILE_PHONE.png:/skin/default/resources/MOBILE_PHONE.png + + +