aboutsummaryrefslogtreecommitdiffstats
path: root/files/android.el
blob: 5c662186c0c1c92a07a00084420b6de6b76423e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
;;;; Copyright 2007 The Android Open Source Project

;;; Set up GUD+JDB to attach to a Java process running on the phone or
;;; under the emulator.

(defvar android-jdb-port-history '("8700")
 "history of ports supplied to `android-jdb'")

(defvar android-jdb-project-root-history '()
 "history of project roots supplied to `android-jdb'")
(defvar android-jdb-history nil
 "history of commands supplied to `android-jdb'")

(defvar android-jdb-activity-class-history ()
 "history of activity classes supplied to `start-android-activity'")

(defcustom  android-jdb-command-name "jdb"
  "Name of Java debugger."
  :type 'string
  :group 'android)

(defgroup android nil
  "Android Applications."
  :group 'applications)

(defcustom android-project-root nil
 "This is where your Android project root is stored."
  :type 'directory
 :group 'android )

(defcustom android-apk nil
 "This is where your Android Application Package is stored."
 :type 'string
 :group 'android)

(defcustom android-activity-class nil
 "This is where your Android Activity class is stored."
 :type 'string
 :group 'android)

(defun android-read-project-root ()
 (if (or (string-match "XEmacs" emacs-version)
         (>= emacs-major-version 22))
     (read-file-name "Android project root: "
                     android-project-root
                     nil
                     t
                     nil
                     'file-directory-p)
   (labels ((read-directory ()
                            (read-file-name "Android project root: "
                                            android-project-root
                                            nil
                                            t
                                            nil)))
     (do ((entered-root (read-directory) (read-directory)))
         ((and entered-root
               (file-directory-p entered-root))
          (expand-file-name entered-root))))))

(defun android-jdb (port root)
 "Set GUD+JDB up to run against Android on PORT in directory ROOT."
 (interactive
  (list
   (read-from-minibuffer "Activity's JDWP DDMS port: "
                     (car android-jdb-port-history)
                     nil
                     t
                     'android-jdb-port-history)
                    (android-read-project-root)))
 (setq android-project-root root)
 (let ((jdb-command
        (format "%s -attach localhost:%s -sourcepath%s"
                android-jdb-command-name
                port
                (format "%s/src" root))))
   (if (not (string= jdb-command (car android-jdb-history)))
       (push jdb-command android-jdb-history))
   (jdb jdb-command)))

(defun android-emulate ()
 "Run the Android emulator. This expects the SDK tools directory to be in the current path."
 (interactive)
 (compile "emulator"))

(defun android-install-app (apk)
  "Install an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path."
  (interactive (list (expand-file-name
                      (read-file-name "Android Application Package (.apk): "
                                      nil
                                      android-apk
                                      t
                                      nil
                                      nil))))
  (setq android-apk apk)
  (compile (format "adb install -r %s" apk)))

(defun android-uninstall-app (package-name)
  "Uninstall an Android application package APK in the Android emulator. This expects the SDK tools directory to be in the current path.
Specify the package name --- and not the name of the application e.g., com.android.foo."
  (interactive
   (list
    (read-from-minibuffer "Package: ")))
  (compile (format "adb uninstall %s" package-name)))

(defun android-start-activity (package class)
 "Start the activity PACKAGE/CLASS in the Android emulator. This expects the SDK tools directory to be in the current path."
 (interactive
  (list
   (read-from-minibuffer "Package: ")
   (read-from-minibuffer "Activity Java class: "
         (car android-jdb-activity-class-history)
         nil
         t
         'android-jdb-activity-class-history)))
 (compile (format "adb shell am start -n %s/%s" package class)))

(defun android-debug-activity (package class)
 "Start the activity PACKAGE/CLASS within the debugger in the Android emulator. This expects the SDK tools directory to be in the current path."
 (interactive
  (list
   (read-from-minibuffer "Package: ")
   (read-from-minibuffer "Activity Java class: "
         (car android-jdb-activity-class-history)
         nil
         t
         'android-jdb-activity-class-history)))
 (compile (format "adb shell am start -D -n %s/%s" package class)))

(provide 'android)