Wednesday, 19 June 2019

How to Remove the Duplicates from ArrayList with Objects ?

List<Event> events = // fill with your events.
List<Event> noRepeat = new ArrayList<Event>();

for (Event event : events ) {    boolean isFound = false;
    // check if the event name exists in noRepeat
    for (Event e : noRepeat) {
        if (e.getName().equals(event.getName()) || (e.equals(event))) {
            isFound = true;        
            break;
        }
    }
    if (!isFound) noRepeat.add(event);
}


Friday, 17 June 2016

How to start the Wearable Development in Eclipse instead of Android Studio ?

STEP 1:

Download the Eclipse ..and Android SDK manger .

open the Eclipse preferences and set the SDK location..


for the Installed Android SDK we need to Update the ADT

just try to update the ADT .

go to Help in the Eclipse and check for the Updates if any updates means install them.


if any problem facing just update the ADT manually go to help ..install new software ...

click the button ADD and then enter the


give it any name.
It will list the updates available- which should ideally be adt 20.xx
Eclipse will restart and hopefully everything should work fine for you.

STEP 2 :

Create new Android Project  SampleWerable

Make sure the support  Android support Library is the Latest ..

get the wearable Library .. or create the werableLibs manually

create a sample project named as werable LIbrary open the Lib folder ,,, copy the wearable library present in the in your system
sdk\extras\google\m2repository\com\google\android\wearable\wearable.arr
change that the .arr file to .zip copy the jar file ..into Libs of newly created project.
check the checkbox to make the project as Lib..
now attach library folder to the  SampleWerable project ..




I hope you are stetted the all the Development set up as per my previous post ....


and make sure  about the latest Werable libraries 1.4  ..


MainActivity.java


package android.support.wearable.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Bundle;
import android.os.Build.VERSION;
import android.support.annotation.CallSuper;
import com.google.android.wearable.compat.WearableActivityController;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.reflect.Method;

@TargetApi(21)
public abstract class WearableActivity extends Activity {
    private final String TAG = WearableActivity.class.getSimpleName() + "[" + this.getClass().getSimpleName() + "]";
    private static final String WEARABLE_CONTROLLER_CLASS_NAME = "com.google.android.wearable.compat.WearableActivityController";
    private static volatile boolean sAmbientCallbacksVerifiedPresent;
    public static final String EXTRA_BURN_IN_PROTECTION = "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION";
    public static final String EXTRA_LOWBIT_AMBIENT = "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT";
    private WearableActivityController mWearableController;
    private boolean mSuperCalled;

    public WearableActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.initAmbientSupport();
        if(this.mWearableController != null) {
            this.mWearableController.onCreate();
        }

    }

    protected void onResume() {
        super.onResume();
        if(this.mWearableController != null) {
            this.mWearableController.onResume();
        }

    }

    protected void onPause() {
        if(this.mWearableController != null) {
            this.mWearableController.onPause();
        }

        super.onPause();
    }

    protected void onStop() {
        if(this.mWearableController != null) {
            this.mWearableController.onStop();
        }

        super.onStop();
    }

    protected void onDestroy() {
        if(this.mWearableController != null) {
            this.mWearableController.onDestroy();
        }

        super.onDestroy();
    }

    public final void setAmbientEnabled() {
        if(this.mWearableController != null) {
            this.mWearableController.setAmbientEnabled();
        }

    }

    public final boolean isAmbient() {
        return this.mWearableController != null?this.mWearableController.isAmbient():false;
    }

    @CallSuper
    public void onEnterAmbient(Bundle ambientDetails) {
        this.mSuperCalled = true;
    }

    @CallSuper
    public void onUpdateAmbient() {
    }

    @CallSuper
    public void onExitAmbient() {
        this.mSuperCalled = true;
    }

    private void initAmbientSupport() {
        if(VERSION.SDK_INT > 21) {
            try {
                Class.forName("com.google.android.wearable.compat.WearableActivityController");
            } catch (ClassNotFoundException var2) {
                throw new IllegalStateException("Could not find wearable shared library classes. Please add <uses-library android:name=\"com.google.android.wearable\" android:required=\"false\" /> to the application manifest");
            }

            this.mWearableController = new WearableActivityController(this.TAG, this, new WearableActivity.AmbientCallback());
            verifyAmbientCallbacksPresent();
        }
    }

    private static void verifyAmbientCallbacksPresent() {
        if(!sAmbientCallbacksVerifiedPresent) {
            try {
                Method e = WearableActivity.AmbientCallback.class.getDeclaredMethod("onEnterAmbient", new Class[]{Bundle.class});
                if(!".onEnterAmbient".equals("." + e.getName())) {
                    throw new NoSuchMethodException();
                }
            } catch (NoSuchMethodException var1) {
                throw new IllegalStateException("Could not find a required method for ambient support, likely due to proguard optimization. Please add com.google.android.wearable:wearable jar to the list of library jars for your project");
            }

            sAmbientCallbacksVerifiedPresent = true;
        }
    }

    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
        if(this.mWearableController != null) {
            this.mWearableController.dump(prefix, fd, writer, args);
        }

    }

    private class AmbientCallback extends com.google.android.wearable.compat.WearableActivityController.AmbientCallback {
        private AmbientCallback() {
        }

        public void onEnterAmbient(Bundle ambientDetails) {
            WearableActivity.this.mSuperCalled = false;
            WearableActivity.this.onEnterAmbient(ambientDetails);
            if(!WearableActivity.this.mSuperCalled) {
                throw new IllegalStateException("Activity " + WearableActivity.this.toString() + " did not call through to super.onEnterAmbient()");
            }
        }

        public void onExitAmbient() {
            WearableActivity.this.mSuperCalled = false;
            WearableActivity.this.onExitAmbient();
            if(!WearableActivity.this.mSuperCalled) {
                throw new IllegalStateException("Activity " + WearableActivity.this.toString() + " did not call through to super.onExitAmbient()");
            }
        }

        public void onUpdateAmbient() {
            WearableActivity.this.onUpdateAmbient();
        }
    }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.wearable.view.BoxInsetLayout    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:id="@+id/container"    tools:context="com.example.arajendra.wearaleapp.MainActivity"    tools:deviceIds="wear">

    <TextView        android:id="@+id/text"        app:layout_box="all"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:text="@string/hello_world" />

    <TextView        android:id="@+id/clock"        app:layout_box="all"        android:layout_gravity="bottom|start"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textColor="@android:color/white" />

</android.support.wearable.view.BoxInsetLayout>





Write a simple Hello Wearable program in Android Wearable ?




I hope you are stetted the all the Development set up as per my previous post ....


and make sure  about the latest Werable libraries 1.4  ..


MainActivity.java


package android.support.wearable.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Bundle;
import android.os.Build.VERSION;
import android.support.annotation.CallSuper;
import com.google.android.wearable.compat.WearableActivityController;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.reflect.Method;

@TargetApi(21)
public abstract class WearableActivity extends Activity {
    private final String TAG = WearableActivity.class.getSimpleName() + "[" + this.getClass().getSimpleName() + "]";
    private static final String WEARABLE_CONTROLLER_CLASS_NAME = "com.google.android.wearable.compat.WearableActivityController";
    private static volatile boolean sAmbientCallbacksVerifiedPresent;
    public static final String EXTRA_BURN_IN_PROTECTION = "com.google.android.wearable.compat.extra.BURN_IN_PROTECTION";
    public static final String EXTRA_LOWBIT_AMBIENT = "com.google.android.wearable.compat.extra.LOWBIT_AMBIENT";
    private WearableActivityController mWearableController;
    private boolean mSuperCalled;

    public WearableActivity() {
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.initAmbientSupport();
        if(this.mWearableController != null) {
            this.mWearableController.onCreate();
        }

    }

    protected void onResume() {
        super.onResume();
        if(this.mWearableController != null) {
            this.mWearableController.onResume();
        }

    }

    protected void onPause() {
        if(this.mWearableController != null) {
            this.mWearableController.onPause();
        }

        super.onPause();
    }

    protected void onStop() {
        if(this.mWearableController != null) {
            this.mWearableController.onStop();
        }

        super.onStop();
    }

    protected void onDestroy() {
        if(this.mWearableController != null) {
            this.mWearableController.onDestroy();
        }

        super.onDestroy();
    }

    public final void setAmbientEnabled() {
        if(this.mWearableController != null) {
            this.mWearableController.setAmbientEnabled();
        }

    }

    public final boolean isAmbient() {
        return this.mWearableController != null?this.mWearableController.isAmbient():false;
    }

    @CallSuper
    public void onEnterAmbient(Bundle ambientDetails) {
        this.mSuperCalled = true;
    }

    @CallSuper
    public void onUpdateAmbient() {
    }

    @CallSuper
    public void onExitAmbient() {
        this.mSuperCalled = true;
    }

    private void initAmbientSupport() {
        if(VERSION.SDK_INT > 21) {
            try {
                Class.forName("com.google.android.wearable.compat.WearableActivityController");
            } catch (ClassNotFoundException var2) {
                throw new IllegalStateException("Could not find wearable shared library classes. Please add <uses-library android:name=\"com.google.android.wearable\" android:required=\"false\" /> to the application manifest");
            }

            this.mWearableController = new WearableActivityController(this.TAG, this, new WearableActivity.AmbientCallback());
            verifyAmbientCallbacksPresent();
        }
    }

    private static void verifyAmbientCallbacksPresent() {
        if(!sAmbientCallbacksVerifiedPresent) {
            try {
                Method e = WearableActivity.AmbientCallback.class.getDeclaredMethod("onEnterAmbient", new Class[]{Bundle.class});
                if(!".onEnterAmbient".equals("." + e.getName())) {
                    throw new NoSuchMethodException();
                }
            } catch (NoSuchMethodException var1) {
                throw new IllegalStateException("Could not find a required method for ambient support, likely due to proguard optimization. Please add com.google.android.wearable:wearable jar to the list of library jars for your project");
            }

            sAmbientCallbacksVerifiedPresent = true;
        }
    }

    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
        if(this.mWearableController != null) {
            this.mWearableController.dump(prefix, fd, writer, args);
        }

    }

    private class AmbientCallback extends com.google.android.wearable.compat.WearableActivityController.AmbientCallback {
        private AmbientCallback() {
        }

        public void onEnterAmbient(Bundle ambientDetails) {
            WearableActivity.this.mSuperCalled = false;
            WearableActivity.this.onEnterAmbient(ambientDetails);
            if(!WearableActivity.this.mSuperCalled) {
                throw new IllegalStateException("Activity " + WearableActivity.this.toString() + " did not call through to super.onEnterAmbient()");
            }
        }

        public void onExitAmbient() {
            WearableActivity.this.mSuperCalled = false;
            WearableActivity.this.onExitAmbient();
            if(!WearableActivity.this.mSuperCalled) {
                throw new IllegalStateException("Activity " + WearableActivity.this.toString() + " did not call through to super.onExitAmbient()");
            }
        }

        public void onUpdateAmbient() {
            WearableActivity.this.onUpdateAmbient();
        }
    }
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><android.support.wearable.view.BoxInsetLayout    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:id="@+id/container"    tools:context="com.example.arajendra.wearaleapp.MainActivity"    tools:deviceIds="wear">

    <TextView        android:id="@+id/text"        app:layout_box="all"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:text="@string/hello_world" />

    <TextView        android:id="@+id/clock"        app:layout_box="all"        android:layout_gravity="bottom|start"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textColor="@android:color/white" />

</android.support.wearable.view.BoxInsetLayout>

How to setup The Android Studio for wearable Development ?


Step 1:

Install the Java 1.8 version

Step 2:

set the java JDK path in  Environment variables --system variables..


Step 3:

Download the Latest Android studio 

make sure wear system images or installed or not .


Step 4:

Create AVD with the android wear ..make sure skin is either Round or square .


Step 5:

Create a project with the 4.4w, and start the Development. 

Thursday, 9 June 2016

How to start the Wearable Android App Development ?

The Android Wear SDK was officially launched at Google I/O back in June 2014.Android Wear is a version of Google’s Android operating system designed for smartwatches and other wearables. It helps display notifications and integrates the Google Now functionality by pairing with mobile phones. The Wear SDKincludes code samples, documentation required to build applications that directly run on wearable, create custom user interfaces and sync data between mobile phones and wearables.
However, it is important for developers to first setup their environment in order to create wearable applications. This tutorial helps to setup up the Eclipse IDE for Android Wear development.
Pre-requisites: Eclipse IDE, Android Wear SDK
Step 1: Install Android Wear SDK and support repository
Before creating wearable applications, one needs to download and install the Android Wear SDK from the SDK manager as shown below. One also needs to install the Android support repository from the Extras section.


Step 2: Create support library project
Once the Android Wear SDK has been installed successfully, one will find thewearable folder present under,
{ANDROID_SDK}\extras\google\m2repository\com\google\android\support\
Next, rename the wearable-1.0.0.aar file as wearable-1.0.0.zip and extract the .zip file to obtain the wearable Android project. Now, launch Eclipse IDE and choose File –> Import –> Existing Android code into workspace. Navigate to the path where the project exists and import the same. Finally, create a libsfolder and move the classes.jar in the libs folder. Right click the imported project, go to Android, select build target as Android 4.4W.2 and tick the checkbox Is Library. This makes sure that the project is setup as a library project targeting Android API 20.


Create library project
Our final project structure would look something like this,

Project Structure
One can now create a new Android Wear project, or import one of the samples that come with the SDK, and add the above Wear support library as a dependency.
That’s it for this tutorial.  :)