Skip to content

Commit

Permalink
setup wizard now working pretty well :D
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotstocker committed Jan 13, 2017
1 parent 49d8cd0 commit 0e24f38
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 10 deletions.
6 changes: 4 additions & 2 deletions LC1/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,17 @@
<activity
android:name=".zoneSetupWizard"
android:label="Setup Wizard"
android:theme="@style/Theme.AppCompat.Light">
android:theme="@style/Theme.AppCompat.Light"
android:parentActivityName=".controller">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".zoneSetup"
android:label="Zone Setup"
android:theme="@style/Theme.AppCompat.Light">
android:theme="@style/Theme.AppCompat.Light"
android:parentActivityName=".zoneSetupWizard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,14 +677,13 @@ public void setupZone(int zone) {
Intent i = new Intent();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName(context.getPackageName(), zoneSetup.class.getCanonicalName()));
if(!prefs.getBoolean("rgbw_enabled", false)) {
zone += 5;
}
int z = zone;
if(z > 4) {
intent.putExtra("type", "white");
if(z > 8) {
z = 0;
} else {
z -= 4;
}
z -= 5;
} else {
intent.putExtra("type", "color");
}
Expand Down
107 changes: 105 additions & 2 deletions LC1/src/main/java/tv/piratemedia/lightcontroler/zoneSetup.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package tv.piratemedia.lightcontroler;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
* Created by eliotstocker on 22/10/2016.
*/

public class zoneSetup extends ActionBarActivity {
public boolean adding = true;
private static controlCommands Controller;
private Handler mHandler;

private String Type;
private int Zone;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -20,8 +31,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
return;
}

String Type = getIntent().getStringExtra("type");
int Zone = getIntent().getIntExtra("zone", -1);
Type = getIntent().getStringExtra("type");
Zone = getIntent().getIntExtra("zone", -1);
Log.d("Zone Setup", "setting up '"+Type+"' lights in Zone: "+Zone);

final controller.ControllerPager cp = new controller.ControllerPager(getSupportFragmentManager(), null, this);

Expand All @@ -34,5 +46,96 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
title = cp.getPageTitle(cp.getIndex(Type, Zone)).toString();
}
info.setText("Setup " + Type + " Zone: " + title);

mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what == 999) {
step3Complete();
}
}
};

Controller = new controlCommands(this, mHandler);
}

public void AddBulb(final View v) {
adding = true;
findViewById(R.id.step1).setVisibility(View.GONE);
findViewById(R.id.step2).setVisibility(View.VISIBLE);
}

public void RemoveBulb(final View v) {
adding = false;
findViewById(R.id.step1).setVisibility(View.GONE);
findViewById(R.id.step2).setVisibility(View.VISIBLE);
}

public void step2Next(final View v) {
findViewById(R.id.step2).setVisibility(View.GONE);
findViewById(R.id.step3).setVisibility(View.VISIBLE);
}

public void step3Next(final View v) {
findViewById(R.id.step3).setVisibility(View.GONE);
findViewById(R.id.running).setVisibility(View.VISIBLE);
new Thread(new Runnable() {
@Override
public void run() {
try {
if(Type.equals("white") && !adding) {
Thread.sleep(500);
for(int i = 0; i < 5; i++) {
Log.d("Zone Setup", "Sending Lights on for '"+Type+"' zone:"+Zone);
Controller.LightsOn(Type, Zone);
Thread.sleep(200);
}
} else {
Controller.LightsOn(Type, Zone);
if (!adding) {
Controller.setToWhite(Type, Zone);
}
Thread.sleep(500);
Controller.LightsOn(Type, Zone);
if (!adding) {
Controller.setToWhite(Type, Zone);
}
Thread.sleep(1000);
Controller.LightsOn(Type, Zone);
if (!adding) {
Controller.setToWhite(Type, Zone);
}
Thread.sleep(1000);
Controller.LightsOn(Type, Zone);
if (!adding) {
Controller.setToWhite(Type, Zone);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(999);
}
}).start();
}

public void step3Complete() {
findViewById(R.id.running).setVisibility(View.GONE);
findViewById(R.id.step4).setVisibility(View.VISIBLE);
if(adding) {
((TextView) findViewById(R.id.finishedtext)).setText(R.string.zone_setup_add_bulb_step3);
} else {
((TextView) findViewById(R.id.finishedtext)).setText(R.string.zone_setup_remove_bulb_step3);
}
}

public void end(final View v) {
finish();
}

public void restart(final View v) {
findViewById(R.id.step4).setVisibility(View.GONE);
findViewById(R.id.step1).setVisibility(View.VISIBLE);
}
}
138 changes: 137 additions & 1 deletion LC1/src/main/res/layout/activity_zonesetup.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<TextView
android:text="Setup Zone..."
Expand All @@ -11,5 +13,139 @@
android:gravity="center"
android:padding="30dp" />

<ProgressBar
android:layout_marginTop="30dp"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/running"
android:visibility="gone"/>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/step1"
android:layout_marginTop="30dp">

<TextView
android:text="What would you like to do?"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView11"
android:layout_weight="1"
android:gravity="center"/>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:text="Add Bulb(s)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_weight="1"
android:onClick="AddBulb" />

<Button
android:text="Remove Bulb(s)"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_weight="1"
android:onClick="RemoveBulb" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/step2"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"
android:visibility="gone">
<TextView
android:text="Turn off the light at the switch and press the next button bellow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView7"
android:gravity="center"
android:textAlignment="center"/>

<Button
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:layout_marginTop="10dp"
android:onClick="step2Next"/>

</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="30dp"
android:visibility="gone"
android:id="@+id/step3">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView8"
android:gravity="center"
android:text="turn on the lights at the switch and then imediately press the next button bellow" />

<Button
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:layout_marginTop="10dp"
android:onClick="step3Next"/>
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:visibility="gone"
android:id="@+id/step4">

<TextView
android:text="@string/zone_setup_add_bulb_step3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/finishedtext"
android:gravity="center" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">

<Button
android:text="Back to Menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button6"
android:layout_weight="1"
android:onClick="end"/>

<Button
android:text="Start Again"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button7"
android:layout_weight="1"
android:onClick="restart"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
3 changes: 3 additions & 0 deletions LC1/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<string name="menu_action_wifi_setup">Controller Wifi Setup</string>
<string name="menu_action_zone_setup">Zone Setup</string>

<string name="zone_setup_add_bulb_step3">if the light(s) flashed several times they have been successfully added to the group, if this didn\'t happen, please start again</string>
<string name="zone_setup_remove_bulb_step3">if the light(s) flashed several times they have been successfully removed from the group, if this didn\'t happen, please start again</string>

<string-array name="modes_array">
<item>Disco Mode</item>
<item>Music Mode</item>
Expand Down

0 comments on commit 0e24f38

Please sign in to comment.