Skip to content

Commit 026d465

Browse files
committed
Further code cleanup
1 parent 335a766 commit 026d465

File tree

7 files changed

+18
-54
lines changed

7 files changed

+18
-54
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android {
2020
}
2121
}
2222

23-
if (new File(projectDir.toString() + java.io.File.separator + "signing.gradle").exists()) {
23+
if (new File(projectDir.toString() + File.separator + "signing.gradle").exists()) {
2424
apply from: 'signing.gradle';
2525
}
2626

app/src/main/java/de/th_ht/ambilike/Hue.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,8 @@ public void setColor(int[] rgb, int brightness)
297297

298298
public List<PHLight> getLights()
299299
{
300-
List<PHLight> list = cache.getAllLights();
301300

302-
return list;
301+
return cache.getAllLights();
303302
}
304303

305304
public void setLights(List<Integer> _lights)

app/src/main/java/de/th_ht/ambilike/HueReceiver.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,12 @@
2525

2626
public class HueReceiver extends BroadcastReceiver
2727
{
28-
private static int rCounter = 0;
29-
30-
public HueReceiver()
31-
{
32-
super();
33-
}
34-
3528
@Override
3629
public void onReceive(Context context, Intent intent)
3730
{
3831
Hue hue = MainActivity.getHue();
3932

40-
Bundle bundle = (Bundle) intent.getBundleExtra("Stuff");
33+
Bundle bundle = intent.getBundleExtra("Stuff");
4134
int[] rgb = bundle.getIntArray("rgb");
4235
int bri = bundle.getInt("bri", 128);
4336

app/src/main/java/de/th_ht/ambilike/HueService.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ public class HueService extends Service
4141
private NotificationManager mNM;
4242
private int NOTIFICATION = 0;
4343

44-
public HueService()
45-
{
46-
}
47-
4844
@Override
4945
public void onCreate()
5046
{
@@ -95,7 +91,7 @@ private void showNotification()
9591
// Set the icon, scrolling text and timestamp
9692
Notification notification = new Notification.Builder(getApplicationContext())
9793
.setContentTitle("HueService")
98-
.setContentText("HueService started")
94+
.setContentText(text)
9995
.setContentIntent(contentIntent)
10096
.setOngoing(true)
10197
.setSmallIcon(R.drawable.app_icon)
@@ -114,14 +110,11 @@ private class HueThread implements Runnable
114110
public void run()
115111
{
116112
killed = false;
117-
boolean first = true;
118113
boolean good = true;
119114
while (!killed)
120115
{
121-
if (first)
122-
{
123-
good = screenshot.snap();
124-
}
116+
good = screenshot.snap();
117+
125118
if (good)
126119
{
127120
int clr = screenshot.getDominantColor();
@@ -147,9 +140,5 @@ public void kill()
147140

148141
public class LocalBinder extends Binder
149142
{
150-
HueService getService()
151-
{
152-
return HueService.this;
153-
}
154143
}
155144
}

app/src/main/java/de/th_ht/ambilike/MainActivity.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,11 @@ public class MainActivity extends ActionBarActivity
5656
private NumberPicker numberMaxBri;
5757
private HueReceiver huereceiver;
5858

59-
static public String getMyFilesDir()
60-
{
61-
return myFilesDir;
62-
}
63-
6459
public static Hue getHue()
6560
{
6661
return hue;
6762
}
6863

69-
public static DisplayMetrics getMetric()
70-
{
71-
return metric;
72-
}
73-
7464
@Override
7565
protected void onCreate(Bundle savedInstanceState)
7666
{
@@ -183,17 +173,11 @@ public void onClick(View view)
183173
for (PHLight cur_light : lights)
184174
{
185175
lights_strings[i] = cur_light.getName();
186-
if (chosenLights.contains(i))
187-
{
188-
lights_checked[i] = true;
189-
} else
190-
{
191-
lights_checked[i] = false;
192-
}
176+
lights_checked[i] = chosenLights.contains(i);
193177
i++;
194178
}
195179

196-
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
180+
new AlertDialog.Builder(MainActivity.this)
197181
.setTitle("Please choose lights")
198182
.setMultiChoiceItems(lights_strings, lights_checked, new DialogInterface.OnMultiChoiceClickListener()
199183
{
@@ -208,7 +192,7 @@ public void onClick(DialogInterface dialogInterface, int i, boolean b)
208192
@Override
209193
public void onClick(DialogInterface dialogInterface, int i)
210194
{
211-
List<Integer> lights_chosen = new ArrayList<Integer>();
195+
List<Integer> lights_chosen = new ArrayList<>();
212196
for (int j = 0; j < lights_checked.length; j++)
213197
{
214198
if (lights_checked[j])
@@ -319,7 +303,7 @@ public boolean onOptionsItemSelected(MenuItem item)
319303
private List<Integer> getLightsFromPreference()
320304
{
321305
SharedPreferences prefs = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE);
322-
List<Integer> lights = new ArrayList<Integer>();
306+
List<Integer> lights = new ArrayList<>();
323307
int nLights = prefs.getInt("NLights", 0);
324308
for (int i = 0; i < nLights; i++)
325309
{

app/src/main/java/de/th_ht/ambilike/Screenshot.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import android.support.v7.graphics.Palette;
2626
import android.widget.ImageView;
2727

28-
import org.apache.http.util.ByteArrayBuffer;
29-
3028
import java.io.BufferedInputStream;
3129
import java.io.File;
3230
import java.io.FileInputStream;
@@ -39,10 +37,9 @@
3937

4038
public class Screenshot implements Serializable
4139
{
42-
protected Bitmap shot, oldshot;
40+
protected Bitmap shot;
4341
private String myFilesDir;
4442
private String cmdline;
45-
private ByteArrayBuffer buf;
4643
private int displaywidth, displayheight;
4744
private Semaphore semaphore;
4845
private Process sh;
@@ -51,7 +48,6 @@ public class Screenshot implements Serializable
5148

5249
public Screenshot(int _displaywidth, int _displayheight, Context appContext)
5350
{
54-
buf = new ByteArrayBuffer(0);
5551
shot = Bitmap.createBitmap(1920, 1280, Bitmap.Config.ARGB_8888);
5652
displaywidth = _displaywidth;
5753
displayheight = _displayheight;
@@ -193,7 +189,6 @@ public int getDominantColor()
193189
final int targetWidth = 400;
194190
int targetHeight = (int) (shot.getHeight() / (shot.getWidth() / (double) targetWidth));
195191
scaledShot = Bitmap.createScaledBitmap(shot, targetWidth, targetHeight, true);
196-
oldshot = scaledShot;
197192
Palette pal = Palette.generate(scaledShot, 20);
198193
List<Palette.Swatch> swatches = pal.getSwatches();
199194

@@ -217,7 +212,13 @@ public int getDominantColor()
217212
}
218213
}
219214

220-
clr = curSwatch.getRgb();
215+
try
216+
{
217+
clr = curSwatch.getRgb();
218+
} catch (NullPointerException e)
219+
{
220+
clr = oldClr;
221+
}
221222
oldClr = clr;
222223

223224
semaphore.release();

gradle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,3 @@
1616
# This option should only be used with decoupled projects. More details, visit
1717
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1818
# org.gradle.parallel=true
19-
20-
Ambilike.signing='C:/Users/th/Documents/owncloud/stuff/privat/android/thht'

0 commit comments

Comments
 (0)