UPDATE: September 2016: This blog pages covers the "old" Gear Fit model. The current model works completely different.
A couple of things caught my attention during developing for the Gear Fit:
A couple of things caught my attention during developing for the Gear Fit:
- The Programmers Guide is not fully in line with the 1.0.0 Version of the jar file. There is no setAnimationType() call availanle. The Guide does mention it, but never explains the specifics.
- Built-in apps use a bar to separate UI elements. This is also not mentioned in the guide. Fortunately enough, there is a class for it in the SDK.
- Build-in apps use a vertical orientation, while the custom apps use a horizontal orientation. When wearing the watch, the portrait mode is better readable.
Below, I'm
describing how to adress the above listed points.
Using setAnimationType()
The programmers
guide lists a couple of constants for the animation type, but does explain their meaning. The types are:
ANIMATION_ALPHA,
ANIMATION_NONE,
ANIMATION_ROTATE_X,
ANIMATION_SCALE,
ANIMATION_TRANSLATE
ANIMATION_TRANSLATE_REVERSE
The animation type
determines how an dialog widget is drawn. By default it "just"
appears. By using specific animation types, it appears with an effect. For example
the ANIMATION_ALPHA results in an effect where the dialog fades in.
TIn order to expose
the setAnimationType API, access to the ScupCommunicator class is needed. This
class is declared private. So it is only visible to classes inside the same
package. This means that we have to extend the SDK package with our helper
class:
package
com.samsung.android.sdk.cup;
import
android.content.Context;
import
com.samsung.android.sdk.cup.ScupCommunicatorFactory;
public class
ScupHelper {
public
static final int ANIMATION_ALPHA = 3;
public
static final int ANIMATION_NONE = 0;
public
static final int ANIMATION_ROTATE_X = 2;
public
static final int ANIMATION_SCALE = 3;
public
static final int ANIMATION_TRANSLATE = 1;
public
static final int ANIMATION_TRANSLATE_REVERSE = 4;
public
static final int ANIMATION_WITHOUT_BUTTON = 256;
private
static ScupCommunicator instance =
null;
private
static final byte FUNC_SET_ANIMATION = 40;
public
void initialize(Context context) {
instance
= ScupCommunicatorFactory.getCommunicator(context);
}
/**
*
* @param paramInt ANIMATION_ALPHA,
ANIMATION_NONE, ANIMATION_ROTATE_X, ANIMATION_SCALE, ANIMATION_TRANSLATE, or
ANIMATION_TRANSLATE_REVERSE
* @param id
- get this is by calling getId() on ScupDialog instance
*/
public
void setAnimationType(int paramInt, short id) {
if
(instance == null)
return;
instance.packCommand(id,
id, 2, FUNC_SET_ANIMATION);
instance.packIntParam(paramInt,
false);
instance.send();
}
As the SDK defines
the ANIMATION_ constants as private, a public definition is added to this
class.
In order to use the
helper class, it needs to be initialized first:
ScupHelper sh=new
ScupHelper();
sh.initialize(context);
sh.setAnimationType(ScupHelper.ANIMATION_ALPHA, getId());
The context needs to
be obtained from the android application which executes this code. The getId()
is a member of the ScupDialog class. The sample above assumes that this code is
part of a derived class:
public class
HelloCupDialog extends ScupDialog {
private Context context;
public HelloCupDialog(Context context) {
super(context);
this.context=context;
}
@Override
protected void
onCreate() {
super.onCreate();
ScupHelper
sh=new
ScupHelper();
sh.initialize(context);
sh.setAnimationType(ScupHelper.ANIMATION_ALPHA, getId());
....
The animation seems
to be not working in combination with the potrait mode (described below).
Changing to Portrait
Mode
We add this function
to the helper class created above:
private static final byte FUNC_SET_POTRAIT_MODE=4;
public void
setPotraitMode(short id) {
if (instance ==
null)
return;
instance.packCommand(id, id, 2, FUNC_SET_POTRAIT_MODE);
instance.send();
}
By default, widgets
appear in landscape mode. If an app should use the potrait mode, it needs to be
set explicitly. There seems to be no way back from the mode for a dialog - so
once it is set, it remains set.
ScupHelper sh=new
ScupHelper();
sh.initialize(context);
sh.setPotraitMode(getId());
Using Separators
The ScupSeparattor
class can be used to separate widgets on the UI.
ScupSeparator
sep=new
ScupSeparator(this);
sep.setLineColor(Color.RED);
sep.setLineThickness(1.0f);
sep.setWidth(100);
sep.show();
The width parameter
seems to be percent value. The thickness cannot be more than 5.0f.