summaryrefslogtreecommitdiffstats
path: root/src/org/codeaurora/gallery3d/ext/IActivityHooker.java
blob: fa1b5c0a0b96349937499f84ebc4bd06beabc72a (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
package org.codeaurora.gallery3d.ext;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

/**
 * Activity action hooker class. Host app's activity will call this hooker's
 * functions in its lifecycle. For example:
 * HostActivity.onCreate()-->hooker.onCreate(). But void init(Activity context,
 * Intent intent) will be called before other functions. <br/>
 * IActivityHooker objects may show menus, but we should give a unique menu id
 * to every menus. Hooker can call getMenuActivityId(int) to get a global unique
 * menu id to be used in menu.add(), and can call getMenuOriginalId(int) to get
 * the original menu id. the example: class Hooker implements IActivityHooker {
 * private static final int MENU_EXAMPLE = 1;
 *
 * @Override public boolean onCreateOptionsMenu(Menu menu) {
 *           super.onCreateOptionsMenu(menu); menu.add(0,
 *           getMenuActivityId(MENU_EXAMPLE), 0, android.R.string.ok); return
 *           true; }
 * @Override public boolean onOptionsItemSelected(MenuItem item) {
 *           switch(getMenuOriginalId(item.getItemId())) { case MENU_EXAMPLE:
 *           //do something return true; default: return false; } } }
 */
public interface IActivityHooker {

    /**
     * Will be called in Host Activity.onCreateOptionsMenu(Menu menu)
     *
     * @param menu
     * @return
     */
    boolean onCreateOptionsMenu(Menu menu);

    /**
     * Will be called in Host Activity.onPrepareOptionsMenu(Menu menu)
     *
     * @param menu
     * @return
     */
    boolean onPrepareOptionsMenu(Menu menu);

    /**
     * Will be called in Host Activity.onOptionsItemSelected(MenuItem item)
     *
     * @param item
     * @return
     */
    boolean onOptionsItemSelected(MenuItem item);

    /**
     * Should be called before any other functions.
     *
     * @param context
     * @param intent
     */
    void init(Activity context, Intent intent);

    /**
     * @return return activity set by init(Activity context, Intent intent)
     */
    Activity getContext();

    /**
     * @return return intent set by init(Activity context, Intent intent)
     */
    Intent getIntent();

    /**
     * IActivityHooker objects may show menus, but we should give a unique menu
     * id to every menus. Hooker can call this function to get a global unique
     * menu id to be used in menu.add()
     *
     * @param id
     * @return
     */
    int getMenuActivityId(int id);

    /**
     * When onOptionsItemSelected is called, we can get menu's id from
     * parameter. You can get the original menu id by calling this function.
     *
     * @param id
     * @return
     */
    int getMenuOriginalId(int id);

    /**
     * Host activity will call this function to set parameter to hooker
     * activity.
     *
     * @param key
     * @param value
     */
    void setParameter(String key, Object value);
}