Before starting development, you need to set up the API Key. Define the API Key provided by Nothing in the AndroidManifest.xml
file of your application, within the <application>
tag. Here is how to do it:
<meta-data android:name="NothingKey" android:value="{API Key}"/>
Be sure to replace {API Key} with the actual API key that has been provided to you.
If you are in the debug phase, there is no need to set up the true API Key. Instead, use a test key in your AndroidManifest.xml like this:
<meta-data android:name="NothingKey" android:value="test"/>
Only foreground applications are allowed to be used.
Debugging can be enabled via adb command.
adb shell settings put global nt_glyph_interface_debug_enable 1
Once successfully activated, you will receive a notification.
register()
function to grant permission for SDK usage.openSession()
. When not using Glyph, be sure to close the session to release resources.Add two segments to AndroidManifest.xml
<uses-permission android:name="com.nothing.ketchum.permission.ENABLE"/>
<!-- This tag should be added in application tag -->
<meta-data android:name="NothingKey" android:value="{Your APIKey}" />
Help to distinguish between smartphone model.
Constants | |
---|---|
String | DEVICE_20111 |
String | DEVICE_22111 |
String | DEVICE_23111 |
Methods | |
---|---|
boolean | is20111() Whether model is Phone (1) |
boolean | is22111() Whether model is Phone (2) |
boolean | is23111() Whether model are Phone (2a) and Phone (2a) Plus |
How the Glyph Interface is indexed
Constants | ArrayIndex | |
---|---|---|
int | A1 | 0 |
int | B1 | 1 |
int | C1 - C4 | 2 - 5 |
int | D1_1 - D1_8 Where D1_1 is the bottom and D1_8 is the top |
7 - 14 |
int | E1 | 6 |
Constants | ArrayIndex | |
---|---|---|
int | A1 | 0 |
int | A2 | 1 |
int | B1 | 2 |
int | C1_1 - C1_16 Where C1_1 is bottom right and C1_16 is top left of C1 |
3 - 18 |
int | C2 - C6 | 19 - 23 |
int | D1_1 - D1_8 Where D1_1 is the bottom and D1_8 is the top |
25 - 32 |
int | E1 | 24 |
Constants | ArrayIndex | |
---|---|---|
int | A | 25 |
int | B | 24 |
int | C1 - C24 Where C_1 is bottom left and C_24 is top right of C |
0 - 23 |
To indicate the Glyph to be used.
Methods | |
---|---|
int | getPeriod() Get the duration of the GlyphFrame is to be turned on, measured in milliseconds. |
int | getCycles() Get number of cycles the GlyphFrame is to be turned on for. |
int | getInterval() Get the interval between cycles. |
int[] | getChannel() Get the array of Glyph channels that are included in the GlyphFrame. |
To create the group of Glyphs to be used.
Constructor |
---|
GlyphFrame.Builder() Create the GlyphFrame class. Default value is 22111. |
GlyphFrame.Builder(String device) Create the GlyphFrame class. Select between the other devices. |
Methods | |
---|---|
GlyphFrame.Builder | buildPeriod(int period) Set the duration of the GlyphFrame is to be turned on, measured in milliseconds. |
GlyphFrame.Builder | buildCycles(int cycles) Set the number of cycles the GlyphFrame is to be turned on for. |
GlyphFrame.Builder | buildInterval(int interval) Set the interval between cycles. |
GlyphFrame.Builder | buildChannel(int channel) Set the Glyph to be used. Please refer to the Glyph class above. |
GlyphFrame.Builder | buildChannel?() ?: A - E Quickly set a zone of Glyphs to be used. Please refer to the Glyph class above. |
GlyphFrame | build() Create the instance of the GlyphFrame. |
Used to control the Glyph Interface.
Static Methods |
---|
getInstance(Context context) Obtaining an instance of GlyphManager. |
Methods | ||
---|---|---|
void | init(GlyphManager.Callback callback) Used for binding the Service. It is recommended to be called in the onCreate method. |
|
void | unInit() Used for unbinding the Service. It is recommended to be called in the onDestroy method. |
|
boolean | register() Used to verify if this application is authorized to use this SDK. If the application does not make the call, it will fail. |
|
boolean | register(String targetDevice) Used to verify if this application is authorized to use this SDK. If the application does not make the call, it will fail and mark the adapted device. |
|
GlyphFrame.Builder | getGlyphFrameBuilder() Get the GlyphFrame.Builder currently to be adapted. |
|
void | openSession() Used to open a session for controlling the Glyph Interface. Only to be called after successfully calling onServiceConnected(ComponentName componentName). |
|
void | closeSession() Used to close the session that was originally used to control Glyph. |
|
void | toggle(GlyphFrame frame) Used to enable/disable the channels set in the GlyphFrame. |
|
void | animate(GlyphFrame frame) Used for animating a breathing animation using the parameters of channels, period, and interval set in the GlyphFrame. |
|
void | displayProgress(GlyphFrame frame, int progress) Used to display a progress value on C1 / D1. Limited to D1 only for Phone (1). |
|
void | displayProgress(GlyphFrame frame, int progress, bool reverse) Used to display the progress value on C1 / D1. Limited to D1 only for Phone (1). |
|
void | displayProgressAndToggle(GlyphFrame frame, int progress, boolean isReverse) Used to simultaneously toggle all Glyphs except C1 / D1 and display the progress value on C1 / D1. Limited to D1 only for Phone (1). |
|
void | turnOff() Used to turn off any showing glyph. |
Used to verify if GlyphManager has successfully connected to the Service.
Interface | |
---|---|
void | onServiceConnected(ComponentName componentName) Used to inform GlyphService about a successful connection. |
void | onServiceDisconnected(ComponentName componentName) Used to inform GlyphService about a failed connection or disconnection. |
public class MainActivity extends AppCompatActivity {
private GlyphManager mGM = null;
private GlyphManager.Callback mCallback = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
mGM = GlyphManager.getInstance(getApplicationContext());
mGM.init(mCallback);
}
@Override
public void onDestroy() {
try {
mGM.closeSession();
} catch (GlyphException e) {
Log.e(TAG, e.getMessage());
}
mGM.unInit();
super.onDestroy();
}
private void init() {
mCallback = new GlyphManager.Callback() {
@Override
public void onServiceConnected(ComponentName componentName) {
if (Common.is20111()) mGM.register(Common.DEVICE_20111);
if (Common.is22111()) mGM.register(Common.DEVICE_22111);
if (Common.is23111()) mGM.register(Common.DEVICE_23111);
try {
mGM.openSession();
} catch(GlyphException e) {
Log.e(TAG, e.getMessage());
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
mGM.closeSession();
}
};
}
private void initView() {
channelABtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GlyphFrame.Builder builder = mGM.getGlyphFrameBuilder();
GlyphFrame frame = builder.buildChannelA().build();
mGM.toggle(frame);
}
});
channelBBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GlyphFrame.Builder builder = mGM.getGlyphFrameBuilder();
GlyphFrame frame = builder.buildChannelB().buildInterval(10)
.buildCycles(2).buildPeriod(3000).build();
mGM.animate(frame);
}
});
channelCBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GlyphFrame.Builder builder = mGM.getGlyphFrameBuilder();
GlyphFrame frame = builder.buildChannelC().build();
mGM.animate(frame);
}
});
channelDBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mGM.turnOff();
}
});
}
}
We are trying to turn on B1 and C1_4, then A2 and C1_2. When toggling frame2, frame1 will be toggled off.
GlyphFrame.Builder builder = mGM.getGlyphFrameBuilder();
GlyphFrame frame1 = builder.buildChannel(Glyph.B1).buildChannel(Glyph.C1_4).build();
mGM.toggle(frame1);
GlyphFrame frame2 = builder.buildChannel(Glyph.A2).buildChannel(Glyph.C1_2).build();
mGM.toggle(frame2);