Remove watch face

Found that using Settings on phone to remove a watch face app did not remove the watch face from the Android Wear app or from the wearable. This method worked.

  1. Connect phone and wearable to Android Studio as if you were going to run/install an app.
  2. In Android Studio terminal enter ‘adb devices’ to get device names.
  3. Enter ‘adb -s device-name uninstall com.your.package-name’ for each device (ie the phone and the wearable).
Posted in Android | Leave a comment

Toolbar overlapping listView

I had a layout with an AppBarLayout and toolbar that overlapped the first item on the ListView below it.  It appears to have been fixed by adding this line

app:layout_behavior="@string/appbar_scrolling_view_behavior"

But the problem was where to add it. The answer was in the layout of the included xml file (second file below).

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="uk.co.jit.daryltest1.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
             />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main"
        />

</android.support.design.widget.CoordinatorLayout>

content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <ListView
        android:id="@+id/lvItems"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="1dp" />

</LinearLayout>

 

Posted in Android | Leave a comment

Simple date-time using xml

A simple way to display date-time using xml.

<android.widget.TextClock
android:id=”@+id/time”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:timeZone=”GMT+0000″ <!–Greenwich –>
android:format24Hour=”k:mm”
android:format12Hour=”@null”
android:textAppearance=”?android:attr/textAppearanceMedium”
android:layout_centerVertical=”true”
android:layout_centerHorizontal=”true” />
Omit the timeZone to pick up local settings from phone.

Posted in Android | Leave a comment

How to vibrate wearable

Thanks to stackoverflow.

Add this to manifest.

<uses-permission android:name="android.permission.VIBRATE"/>

Then in code

Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        long[] vibrationPattern = {0, 500, 50, 300};
        //-1 - don't repeat
        final int indexInPatternToRepeat = -1;
        vibrator.vibrate(vibrationPattern, indexInPatternToRepeat);

If you don’t need a pattern then you can simply specify a duration in milliseconds.

Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        vibrator.vibrate(100);

 

Posted in Android, Wearable | Leave a comment

Colour wheel colour picker

Added a colour wheel-style colour picker in the following way. Documentation here and code here. Copyright 2012 Lars Werkman

Created new activity and layout, into Build, Edit libraries and dependencies and added com.larswerkman.holocolorpicker as a library dependency.

In the layout added:

    <com.larswerkman.holocolorpicker.ColorPicker
        android:id="@+id/picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <com.larswerkman.holocolorpicker.SaturationBar
        android:id="@+id/saturationbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/picker"
        android:layout_alignParentEnd="true" />

    <com.larswerkman.holocolorpicker.ValueBar
        android:id="@+id/valuebar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/saturationbar"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:layout_below="@+id/valuebar">

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Change Color"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text Color"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:layout_weight="1" />

    </LinearLayout>

In the activity implement ColorPicker.OnColorChangedListener and declare these:

    private ColorPicker picker;
    private SaturationBar saturationBar;
    private ValueBar valueBar;
    private Button button;
    private TextView text;

Then in onCreate

        picker = (ColorPicker) findViewById(R.id.picker);
        saturationBar = (SaturationBar) findViewById(R.id.saturationbar);
        valueBar = (ValueBar) findViewById(R.id.valuebar);
        button = (Button) findViewById(R.id.button1);
        text = (TextView) findViewById(R.id.textView1);
        picker.addSaturationBar(saturationBar);
        picker.addValueBar(valueBar);
        picker.setOnColorChangedListener(this);
        valueBar.setOnValueChangedListener(new ValueBar.OnValueChangedListener() {
            @Override
            public void onValueChanged(int value) {

            }
        });
        saturationBar.setOnSaturationChangedListener(new SaturationBar.OnSaturationChangedListener() {
            @Override
            public void onSaturationChanged(int saturation) {

            }
        });

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //try to get hex of colour
                text.setText(Integer.toHexString(picker.getColor()).substring(2));

                text.setTextColor(picker.getColor());
                picker.setOldCenterColor(picker.getColor());
            }
        });

Finally add

    @Override
    public void onColorChanged(int color) {
        //gives the color when it's changed.
    }

 

Posted in Android | Leave a comment

Prepare to publish wearable

The steps for me for Wear 1.x (for which wear module must be inside handheld module) were the following.

  1. Ensure both handheld and wearable modules had same permissions and package names in their manifest files.
  2. Ensure both modules had the same version number in their build.gradle files.
  3. Ensure build.gradle of handheld module includes ‘wearApp project(‘:wearable’)’ within dependencies clause.
  4. Click Build, Generate Signed APK and select handheld module. Enter release key (see separate post).
  5. Publish handheld apk, which should contain wearable apk.

To publish Wear 2.0 wear app (which can be independent or semi-independent of handheld app) I did the following.

  1. Ensured all references to API level in wear modules build file were to 25, followed by sync and any prompted updates to support files.
  2. Add standalone meta data entry to wear manifest (see below).
  3. Click Build, Generate Signed APK and select wear module. Enter release key (see separate post).
  4. Publish wear apk. [This is currently being tested. Will update soon]
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />

 

Posted in Android | Leave a comment

Using Eclipse release key in Android Studio

I found that this stackoverflow post had some correct and some slightly misleading comments. The following worked for me.

  1. In Android Studio select Build, Generate signed APK and navigate to the release key previously used in Eclipse.
  2. Enter your keystore password.
  3. Click on the small box to the right of alias and select your key alias. If the password was not correct in the previous step then you will see a message suggesting the keystore is corrupted. Change the password and try again.
  4. Enter the same password again as the key password.
Posted in Android | Leave a comment

Create assets folder

To create assets folder in Android Studio, right click on module and select New, Folder, Assets folder.

Posted in Android | Leave a comment

How to use Log.isLoggable

Copied in some code that had code such as:

if (Log.isLoggable(TAG, Log.DEBUG)) {
  Log.d(TAG, "onConnected: " + connectionHint);
}

and I couldn’t find any logs in logcat. If I remove the if statement then log commands appear. Solution was to enter a command (eg in Terminal in Android Studio)¬†such as

adb shell setprop log.tag.<tagname> DEBUG

 

Posted in Android | Leave a comment

Difficult to properly install intelhaxm

To run virtual device for emulation of wearable app need to install Intel x86 emulator Accelerator. I read that the recommended method is to use the SDK. Ran the SDK manager from Android Studio, found the option under SDK Tools and installed it – but virtual devices still do not start, saying the accelerator is not installed.

The missing step seems to be that I then had to find the SDK directory (mine was c:\Users\username\AppDate\Local\Android\sdk, which was only visible after changing the setting to show hidden files at the username level) then go to Extras, Intel, Hardware_Accelerated_Execution_Manager and run intelhaxm-android.exe. Once that completed and Android Studio was restarted then the virtual devices would start.

Posted in Android | Leave a comment