Skip to content

Commit

Permalink
Merge pull request #61 from futurice/bugfix_and_screen_off_when_not_c…
Browse files Browse the repository at this point in the history
…harging

Bugfix and screen off when not charging
  • Loading branch information
izrailit authored Nov 17, 2017
2 parents eb3d828 + cd716f9 commit 6a6bb95
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {

defaultConfig {
applicationId "com.futurice.android.reservator"
versionCode 19
versionName "5.1.0"
versionCode 20
versionName "5.1.1"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public void onResume() {
showLoadingCount = 0; //TODO better fix
proxy = this.getResApplication().getDataProxy();
proxy.addDataUpdatedListener(this);
ab.addDataUpdatedListener(this);
if (ab == null) {
ab = getResApplication().getAddressBook();
}
if (ab != null) {
ab.addDataUpdatedListener(this);
}
refreshRoomInfo();
}

Expand Down Expand Up @@ -225,7 +230,11 @@ public void roomListUpdated(Vector<Room> rooms) {
continue;
}
updateLoadingWindow(1);
proxy.refreshRoomReservations(r);
if (proxy == null) {
proxy = this.getResApplication().getDataProxy();
} if (proxy != null) {
proxy.refreshRoomReservations(r);
}
}
updateLoadingWindow(-1);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.futurice.android.reservator;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.WindowManager;
import android.widget.Toast;

Expand All @@ -17,21 +23,35 @@ public class ReservatorActivity extends Activity {
private final ReservatorAppHandler handler = new ReservatorAppHandler();
private GoToFavouriteRoom goToFavouriteRoomRunable;
protected boolean havePermissions = false;
BatteryStateReceiver batteryStateReceiver = new BatteryStateReceiver();
IntentFilter filter = new IntentFilter();

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
filter.addAction(Intent.ACTION_POWER_CONNECTED);
filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = registerReceiver(null, ifilter);
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = (status == BatteryManager.BATTERY_STATUS_CHARGING || status ==
BatteryManager.BATTERY_STATUS_FULL);
if (isCharging) {
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
goToFavouriteRoomRunable = new GoToFavouriteRoom(this);
}

public void onResume() {
super.onResume();
startAutoGoToFavouriteRoom();
registerReceiver(batteryStateReceiver, filter);
}

public void onPause() {
super.onPause();
stopAutoGoToFavouriteRoom();
unregisterReceiver(batteryStateReceiver);
}

public void onUserInteraction() {
Expand Down Expand Up @@ -106,4 +126,22 @@ public void run() {
}
}

class BatteryStateReceiver extends BroadcastReceiver {

private int status = -1;

@Override
public void onReceive(Context context, Intent intent) {
status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
if (isCharging()) {
ReservatorActivity.this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
ReservatorActivity.this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
}

public boolean isCharging() {
return (status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ public ArrayList<String> getRoomNames() {
Room room = it.next();
roomNames.add(room.getName());
}
Collections.sort(roomNames, Collator.getInstance());
Collator collator = Collator.getInstance();
if (collator != null) {
Collections.sort(roomNames, collator);
} else {
Collections.sort(roomNames);
}
return roomNames;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.futurice.android.reservator.R;
Expand All @@ -28,9 +29,9 @@ public class EditReservationPopup extends Dialog {
private Reservation reservation;

@BindView(R.id.cancelButton)
Button cancelButton;
ImageButton cancelButton;
@BindView(R.id.roomName)
Button roomName;
TextView roomName;
@BindView(R.id.reservationInfo)
TextView reservationInfoTextView;
@BindView(R.id.cancelReservationButton)
Expand Down

0 comments on commit 6a6bb95

Please sign in to comment.