Skip to content

Commit

Permalink
Added User setting activity and integrated Gimbal code to Home Activi…
Browse files Browse the repository at this point in the history
…ty (has to be moved to a service later)
  • Loading branch information
aravindanck committed Mar 18, 2015
1 parent f522130 commit 18e1e60
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 19 deletions.
10 changes: 9 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ android {
}
}

packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}

}

dependencies {
Expand All @@ -26,5 +31,8 @@ dependencies {
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:support-v13:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'

compile files('libs/gimbal-dev-logging.jar')
compile files('libs/gimbal.jar')
compile files('libs/spring-android-core-1.0.1.RELEASE.jar')
compile files('libs/spring-android-rest-template-1.0.1.RELEASE.jar')
}
Binary file added app/libs/gimbal-dev-logging.jar
Binary file not shown.
Binary file added app/libs/gimbal.jar
Binary file not shown.
Binary file added app/libs/spring-android-core-1.0.1.RELEASE.jar
Binary file not shown.
Binary file not shown.
22 changes: 10 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.avnet.gears.codes.gimbal.store">
package="com.avnet.gears.codes.gimbal.store" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Expand All @@ -22,7 +22,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme" >

<!-- Required for applications which use Google Play Services. -->
<meta-data
Expand All @@ -31,28 +31,27 @@

<activity
android:name=".activity.HomeActivity"
android:label="@string/app_name">
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<activity
android:name=".activity.FeedListActivity"
android:label="@string/title_activity_feed_list" />
<activity
android:name=".activity.ProductsListActivity"
android:label="@string/title_activity_products_list">
android:label="@string/title_activity_products_list" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.avnet.gears.codes.gimbal.store.activity.HomeActivity" />
</activity>
<activity
android:name=".activity.ProductDetailsActivity"
android:label="@string/title_activity_product_details"
android:parentActivityName=".activity.ProductsListActivity">
android:parentActivityName=".activity.ProductsListActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.avnet.gears.codes.gimbal.store.activity.ProductsListActivity" />
Expand All @@ -61,7 +60,7 @@
<service
android:name=".service.StoreAuthenticationService"
android:enabled="true"
android:exported="true">
android:exported="true" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
Expand All @@ -81,7 +80,7 @@

<receiver
android:name=".receiver.StoreGcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />

Expand All @@ -91,11 +90,10 @@

<activity
android:name=".activity.NotificationsListActivity"
android:label="@string/title_activity_notifications_list"></activity>
android:label="@string/title_activity_notifications_list" />
<activity
android:name=".activity.TestDummyActivity"
android:label="@string/title_activity_test_dummy">

android:name=".activity.UserSettingsActivity"
android:label="@string/title_activity_user_settings" >
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.avnet.gears.codes.gimbal.store.R;
import com.avnet.gears.codes.gimbal.store.async.response.processor.impl.AuthTokenReceiverProcessor;
Expand All @@ -38,9 +39,19 @@
import com.avnet.gears.codes.gimbal.store.utils.ServerURLUtil;
import com.avnet.gears.codes.gimbal.store.utils.TypeConversionUtil;

import com.gimbal.android.Beacon;
import com.gimbal.android.BeaconEventListener;
import com.gimbal.android.BeaconManager;
import com.gimbal.android.BeaconSighting;
import com.gimbal.android.Gimbal;
import com.gimbal.android.PlaceEventListener;
import com.gimbal.android.PlaceManager;
import com.gimbal.android.Visit;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand All @@ -64,11 +75,19 @@ public class HomeActivity extends Activity
private ProgressDialog progressDialog;
private AccountManager accountManager;

//Gimbal
private PlaceEventListener placeEventListener;
private BeaconEventListener beaconSightingListener;
private BeaconManager beaconManager;

private static final int SETTINGS_RESULT = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

gimbalInitialize();

mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
Expand Down Expand Up @@ -111,6 +130,65 @@ protected void onCreate(Bundle savedInstanceState) {
processCategoryListData();
}

private void gimbalInitialize() {
Toast t = Toast.makeText(getApplicationContext(), "Gimbal initialise", Toast.LENGTH_SHORT);
t.show();
Gimbal.setApiKey(this.getApplication(), "70e4f8df-8332-46fd-99de-efa092ee57f9");
final TextView placeView = (TextView)findViewById(R.id.placeView);
final TextView sightingView = (TextView)findViewById(R.id.sightingView);
final TextView sightingRssiView = (TextView) findViewById(R.id.sightingRssiView);
final TextView beaconDetailsView = (TextView) findViewById(R.id.beaconDetailsView);

placeEventListener = new PlaceEventListener() {
@Override
public void onVisitStart(Visit visit) {

placeView.setText("Place : Enter: " + visit.getPlace().getName() + ", at: " + new Date(visit.getArrivalTimeInMillis()));
// This will be invoked when a place is entered. Example below shows a simple log upon enter
Log.i("Info:", "Enter: " + visit.getPlace().getName() + ", at: " + new Date(visit.getArrivalTimeInMillis()));

boolean setting = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("example_checkbox", true);
Toast t = Toast.makeText(getApplicationContext(), "Onvisitstart : " + String.valueOf(setting), Toast.LENGTH_SHORT);
t.show();
}

@Override
public void onVisitEnd(Visit visit) {

placeView.setText("Place : Exit: " + visit.getPlace().getName() + ", at: " + new Date(visit.getDepartureTimeInMillis()));
// This will be invoked when a place is exited. Example below shows a simple log upon exit
Log.i("Info:", "Exit: " + visit.getPlace().getName() + ", at: " + new Date(visit.getDepartureTimeInMillis()));

boolean setting = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("example_checkbox", true);
Toast t = Toast.makeText(getApplicationContext(), "Onvisitend : " + String.valueOf(setting), Toast.LENGTH_SHORT);
t.show();
}
};

PlaceManager.getInstance().addListener(placeEventListener);

beaconSightingListener = new BeaconEventListener() {
@Override
public void onBeaconSighting(BeaconSighting sighting) {

sightingView.setText("BeaconSighting");
sightingRssiView.setText("RSSI : " + sighting.getRSSI() + "\nTime in Millis : " + new Date(sighting.getTimeInMillis()));

Beacon beacon = sighting.getBeacon();
beaconDetailsView.setText("Beacon Name : " + beacon.getName() +
"\nIdentifier : " + beacon.getIdentifier() +
"\nBattery Level : " + beacon.getBatteryLevel() +
"\nBeacon Temperature : " + beacon.getTemperature());
Log.i("INFO", sighting.toString());
}
};
beaconManager = new BeaconManager();
beaconManager.addListener(beaconSightingListener);

PlaceManager.getInstance().startMonitoring();
beaconManager.startListening();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down Expand Up @@ -230,13 +308,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == android.R.id.home) {

} else if (!AndroidUtil.processSettingsAction(this, id)) {
// do some custom action processing
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Log.d("Options Selected", "Settings clicked");
Intent i = new Intent(getApplicationContext(), UserSettingsActivity.class);
startActivityForResult(i, SETTINGS_RESULT);
}

return super.onOptionsItemSelected(item);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.avnet.gears.codes.gimbal.store.activity;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.util.Log;

import com.avnet.gears.codes.gimbal.store.R;

import java.util.List;

/**
* A {@link PreferenceActivity} that presents a set of application settings. On
* handset devices, settings are presented as a single list. On tablets,
* settings are split by category, with category headers shown to the left of
* the list of settings.
* <p/>
* See <a href="http://developer.android.com/design/patterns/settings.html">
* Android Design: Settings</a> for design guidelines and the <a
* href="http://developer.android.com/guide/topics/ui/settings.html">Settings
* API Guide</a> for more information on developing a Settings UI.
*/
public class UserSettingsActivity extends PreferenceActivity {
/**
* Determines whether to always show the simplified settings UI, where
* settings are presented in a single list. When false, settings are shown
* as a master/detail two-pane view on tablets. When true, a single pane is
* shown on tablets.
*/
private static final boolean ALWAYS_SIMPLE_PREFS = false;


@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);

setupSimplePreferencesScreen();
}

/**
* Shows the simplified settings UI if the device configuration if the
* device configuration dictates that a simplified, single-pane UI should be
* shown.
*/
private void setupSimplePreferencesScreen() {
System.out.println("Setupsimple preferences");
if (!isSimplePreferences(this)) {
return;
}

// Add 'general' preferences.
addPreferencesFromResource(R.xml.pref_general);
bindPreferenceSummaryToValue(findPreference("gimbal_notif_enabled_checkbox"));
}

/**
* {@inheritDoc}
*/
@Override
public boolean onIsMultiPane() {
return isXLargeTablet(this) && !isSimplePreferences(this);
}

/**
* Helper method to determine if the device has an extra-large screen. For
* example, 10" tablets are extra-large.
*/
private static boolean isXLargeTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout
& Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}

/**
* Determines whether the simplified settings UI should be shown. This is
* true if this is forced via {@link #ALWAYS_SIMPLE_PREFS}, or the device
* doesn't have newer APIs like {@link PreferenceFragment}, or the device
* doesn't have an extra-large screen. In these cases, a single-pane
* "simplified" settings UI should be shown.
*/
private static boolean isSimplePreferences(Context context) {
return ALWAYS_SIMPLE_PREFS
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB
|| !isXLargeTablet(context);
}

/**
* {@inheritDoc}
*/
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onBuildHeaders(List<Header> target) {
}

/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object value) {

Log.d("UserSetting", "Pref " + preference.getKey() + " changed to " + value.toString());
return true;
}
};

/**
* Binds a preference's summary to its value. More specifically, when the
* preference's value is changed, its summary (line of text below the
* preference title) is updated to reflect the value. The summary is also
* immediately updated upon calling this method. The exact display format is
* dependent on the type of preference.
*
* @see #sBindPreferenceSummaryToValueListener
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
}
}
Loading

0 comments on commit 18e1e60

Please sign in to comment.