forked from organicmaps/organicmaps
Keep screen on while downloading maps.
This commit is contained in:
parent
3676c9ca2b
commit
97e0e26edd
4 changed files with 23 additions and 19 deletions
|
@ -13,6 +13,7 @@ import android.widget.TextView;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmListFragment;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.util.Utils;
|
||||
|
||||
public class DownloadFragment extends BaseMwmListFragment implements View.OnClickListener, ActiveCountryTree.ActiveCountryListener, OnBackPressListener
|
||||
{
|
||||
|
@ -232,11 +233,14 @@ public class DownloadFragment extends BaseMwmListFragment implements View.OnClic
|
|||
public void onCountryStatusChanged(int group, int position, int oldStatus, int newStatus)
|
||||
{
|
||||
if (isAdded())
|
||||
{
|
||||
updateToolbar();
|
||||
Utils.keepScreenOn(ActiveCountryTree.isDownloadingActive(), getActivity().getWindow());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCountryGroupChanged(int oldGroup, int oldPosition, int newGroup, int newPosition) { }
|
||||
public void onCountryGroupChanged(int oldGroup, int oldPosition, int newGroup, int newPosition) {}
|
||||
|
||||
@Override
|
||||
public void onCountryOptionsChanged(int group, int position, int newOptions, int requestOptions)
|
||||
|
|
|
@ -231,7 +231,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
LocationHelper.INSTANCE.removeLocationListener(this);
|
||||
// Enable automatic turning screen off while app is idle
|
||||
Utils.automaticIdleScreen(true, getWindow());
|
||||
Utils.keepScreenOn(false, getWindow());
|
||||
mLocationPredictor.pause();
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ public class MWMActivity extends BaseMwmFragmentActivity
|
|||
{
|
||||
LocationHelper.INSTANCE.addLocationListener(this);
|
||||
// Do not turn off the screen while displaying position
|
||||
Utils.automaticIdleScreen(false, getWindow());
|
||||
Utils.keepScreenOn(true, getWindow());
|
||||
mLocationPredictor.resume();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ public enum MapStorage
|
|||
public static final int GROUP = -2;
|
||||
public static final int COUNTRY = -1;
|
||||
|
||||
/// This constants should be equal with storage/storage.hpp, storage::TStatus
|
||||
// This constants should be equal with storage/storage_defines.hpp, storage::TStatus
|
||||
public static final int ON_DISK = 0;
|
||||
public static final int NOT_DOWNLOADED = 1;
|
||||
public static final int DOWNLOAD_FAILED = 2;
|
||||
|
@ -28,9 +28,9 @@ public enum MapStorage
|
|||
*/
|
||||
public interface Listener
|
||||
{
|
||||
public void onCountryStatusChanged(Index idx);
|
||||
void onCountryStatusChanged(Index idx);
|
||||
|
||||
public void onCountryProgress(Index idx, long current, long total);
|
||||
void onCountryProgress(Index idx, long current, long total);
|
||||
}
|
||||
|
||||
public static class Index implements Serializable
|
||||
|
@ -55,11 +55,6 @@ public enum MapStorage
|
|||
mRegion = region;
|
||||
}
|
||||
|
||||
public boolean isEqual(Index idx)
|
||||
{
|
||||
return (mGroup == idx.mGroup && mCountry == idx.mCountry && mRegion == idx.mRegion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -116,10 +111,10 @@ public enum MapStorage
|
|||
|
||||
private void runDownloadCountries(Index[] indexes)
|
||||
{
|
||||
for (int i = 0; i < indexes.length; ++i)
|
||||
for (Index index : indexes)
|
||||
{
|
||||
if (indexes[i] != null)
|
||||
Framework.downloadCountry(indexes[i]);
|
||||
if (index != null)
|
||||
Framework.downloadCountry(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,14 +68,19 @@ public class Utils
|
|||
return false;
|
||||
}
|
||||
|
||||
// if enabled, screen will be turned off automatically by the system
|
||||
// if disabled, screen will be always turn on
|
||||
public static void automaticIdleScreen(boolean enable, Window w)
|
||||
/**
|
||||
* Enable to keep screen on
|
||||
* Disable to let system turn it off automatically
|
||||
*
|
||||
* @param enable
|
||||
* @param w
|
||||
*/
|
||||
public static void keepScreenOn(boolean enable, Window w)
|
||||
{
|
||||
if (enable)
|
||||
w.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
w.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
w.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
|
||||
public static float getAttributeDimension(Activity activity, int attr)
|
||||
|
|
Loading…
Add table
Reference in a new issue