Skip to content

Commit

Permalink
SetClip/.install-hook: Add debug hook
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
baohaojun committed Oct 28, 2016
1 parent 134c974 commit 029879f
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 15 deletions.
8 changes: 7 additions & 1 deletion SetClip/.install-hook
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
67 changes: 55 additions & 12 deletions SetClip/src/com/bhj/setclip/PutClipService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions Wrench.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<qresource prefix="/skin/default">
<file>resources/capture-screen.png</file>
<file>resources/phone-screen.png</file>
<file>resources/MOBILE_PHONE.png</file>
<file>resources/picture.png</file>
<file>resources/emoji.png</file>
<file>resources/com_sina_weibo_icon.png</file>
Expand Down
Binary file added resources/MOBILE_PHONE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion wrench.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local right_button_x = 984
local t1_call, t1_run, t1_adb_mail, t1_save_mail_heads
local adb_push, adb_pull, adb_install
local shell_quote, putclip, t1_post, push_text, t1_post2, kill_android_vnc
local adb_start_activity
local adb_start_activity, launch_apps
local picture_to_weixin_share, picture_to_weibo_share, picture_to_qq_share
local picture_to_momo_share, t1_add_mms_receiver
local adb_get_input_window_dump, adb_top_window
Expand Down Expand Up @@ -1523,6 +1523,29 @@ file_exists = function(name)
end
end

launch_apps = function()
if not file_exists("apps.info") then
if adb_start_service_and_wait_file("com.bhj.setclip/.PutClipService --ei listapps 1", "/sdcard/Wrench/apps.info") then
adb_pull{"/sdcard/Wrench/apps.info", "apps.info"}
else
log("Can't get apps.info")
end
end
apps_file = io.open("apps.info")
local apps_txt = apps_file:read("*a")
local apps = split("\n", apps_txt)
for i = 1, #apps do
line = apps[i]
local s = split("=", line)
local class_ = s[1]
local package_ = s[2]
local label_ = s[3]
if not file_exists(class_ .. ".png") then
adb_pull{"/sdcard/Wrench/" .. class_ .. ".png", class_ .. ".png"}
end
end
end

t1_post = function(text) -- use weixin
local window = adb_focused_window()
debug("sharing text: %s for window: %s", text, window)
Expand Down Expand Up @@ -2490,6 +2513,7 @@ M.adb_get_input_window_dump = adb_get_input_window_dump
M.putclip = putclip
M.start_weibo_share = start_weibo_share
M.t1_post = t1_post
M.launch_apps = launch_apps
M.kill_android_vnc = kill_android_vnc
M.t1_find_weixin_contact = t1_find_weixin_contact
M.adb_shell = adb_shell
Expand Down
5 changes: 5 additions & 0 deletions wrenchmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,8 @@ void WrenchMainWindow::moveEvent(QMoveEvent* ev)
QTimer::singleShot(100, this, SLOT(moveVncMainWinWhenMoving()));
}
}

void WrenchMainWindow::on_tbLauncher_clicked()
{
mLuaThread->addScript(QStringList() << "launch_apps");
}
2 changes: 2 additions & 0 deletions wrenchmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ private slots:

void on_tbPhoneScreen_toggled(bool checked);

void on_tbLauncher_clicked();

private:

bool anyShareChecked();
Expand Down
16 changes: 15 additions & 1 deletion wrenchmainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>580</width>
<width>618</width>
<height>592</height>
</rect>
</property>
Expand Down Expand Up @@ -245,6 +245,20 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbLauncher">
<property name="toolTip">
<string>Launcher (start apps)</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="Wrench.qrc">
<normaloff>:/skin/default/resources/MOBILE_PHONE.png</normaloff>:/skin/default/resources/MOBILE_PHONE.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="tbThumbsUp">
<property name="toolTip">
Expand Down

0 comments on commit 029879f

Please sign in to comment.