Skip to content

Commit

Permalink
Wi-Fi以外の接続(LTE等)がActiveな時,にそれがわかるように状況表示を改善した
Browse files Browse the repository at this point in the history
  • Loading branch information
tateisu committed Mar 15, 2017
1 parent 8483d8f commit 4257494
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 67 deletions.
20 changes: 14 additions & 6 deletions app/src/main/java/jp/juggler/fadownloader/DownloadService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class DownloadService extends Service{
.build();
mGoogleApiClient.connect();

location_tracker = new LocationTracker( log, mGoogleApiClient, new LocationTracker.Callback(){
location_tracker = new LocationTracker( this,log, mGoogleApiClient, new LocationTracker.Callback(){
@Override public void onLocationChanged( Location location ){
DownloadService.location = location;
}
Expand Down Expand Up @@ -286,11 +286,19 @@ public static String getStatusForActivity( Context context ){
}

StringBuilder sb = new StringBuilder();
sb.append( context.getString( R.string.service_running_status
, service_instance.wake_lock.isHeld() ? "ON" : "OFF"
, service_instance.wifi_lock.isHeld() ? "ON" : "OFF"

) );
sb.append( context.getString( R.string.service_running ));
sb.append( "WakeLock=" )
.append( service_instance.wake_lock.isHeld() ? "ON" : "OFF" )
.append( ", " )
.append( "WiFiLock=" )
.append( service_instance.wifi_lock.isHeld() ? "ON" : "OFF" )
.append( ", " )
.append( "Location=" )
.append( service_instance.location_tracker.getStatus() )
.append( ", " )
.append( "Network=" );
service_instance.wifi_tracker.getStatus(sb);
sb.append('\n');

if( service_instance.worker == null || ! service_instance.worker.isAlive() ){
sb.append( context.getString( R.string.thread_not_running_status ) );
Expand Down
39 changes: 31 additions & 8 deletions app/src/main/java/jp/juggler/fadownloader/LocationTracker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jp.juggler.fadownloader;

import android.content.Context;
import android.location.Location;
import android.support.annotation.NonNull;

Expand Down Expand Up @@ -60,18 +61,21 @@ int getUpdatePriority(){
}
}

interface Callback {
void onLocationChanged(Location location);
interface Callback{

void onLocationChanged( Location location );
}

final Context context;
final Callback callback;
final LogWriter log;
final GoogleApiClient mGoogleApiClient;
Location mCurrentLocation;
Setting location_setting;
boolean is_disposed = false;

public LocationTracker( LogWriter log, GoogleApiClient client ,Callback callback){
public LocationTracker( Context context, LogWriter log, GoogleApiClient client, Callback callback ){
this.context = context;
this.log = log;
this.mGoogleApiClient = client;
this.callback = callback;
Expand Down Expand Up @@ -100,6 +104,25 @@ public synchronized void updateSetting( Setting setting ){

private boolean isTracked = false;

public String getStatus(){
if( ! isTracked ) return "OFF";
switch( location_setting.mode ){
default:
return "?";
case NO_LOCATION_UPDATE:
return context.getString( R.string.location_mode_0 );
case LOCATION_NO_POWER:
return context.getString( R.string.location_mode_1 );
case LOCATION_LOW_POWER:
return context.getString( R.string.location_mode_2 );
case LOCATION_BALANCED:
return context.getString( R.string.location_mode_3 );
case LOCATION_HIGH_ACCURACY:
return context.getString( R.string.location_mode_4 );

}
}

private void tracking_end(){
if( ! isTracked ) return;

Expand All @@ -123,23 +146,23 @@ private void tracking_end(){
}
}catch( Throwable ex ){
ex.printStackTrace();
log.e( ex, "removeLocationUpdates() failed.");
log.e( ex, "removeLocationUpdates() failed." );
}finally{
isTracked = false;
}
}

private void tracking_start(){

if( location_setting ==null || !location_setting.isUpdateRequired()){
if( location_setting == null || ! location_setting.isUpdateRequired() ){
return;
}

if( is_disposed ){
log.d( "tracking_start: tracker is already disposed." );
return;
}

if( ! mGoogleApiClient.isConnected() ){
log.d( "tracking_start: api not connected." );
return;
Expand Down Expand Up @@ -180,10 +203,10 @@ private void tracking_start(){
}
} );
}catch( SecurityException ex ){
log.e( ex,"requestLocationUpdates() failed." );
log.e( ex, "requestLocationUpdates() failed." );
}catch( Throwable ex ){
ex.printStackTrace();
log.e( ex,"requestLocationUpdates() failed." );
log.e( ex, "requestLocationUpdates() failed." );
}
}
}
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/jp/juggler/fadownloader/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static class FileInfo{
}
}

static @NonNull Map<String,String> getSecondaryStorageVolumesMap( Context context){
static @NonNull Map<String, String> getSecondaryStorageVolumesMap( Context context ){
Map<String, String> result = new HashMap<>();
try{

Expand All @@ -506,7 +506,7 @@ static class FileInfo{

Method getVolumeList = sm.getClass().getMethod( "getVolumeList" );
Object[] volumes = (Object[]) getVolumeList.invoke( sm );
//
//
for( Object volume : volumes ){
Class<?> volume_clazz = volume.getClass();

Expand All @@ -521,10 +521,21 @@ static class FileInfo{
if( ! TextUtils.isEmpty( uuid ) ) result.put( uuid, path );
}
}
}catch(Throwable ex){
ex.printStackTrace( );
}catch( Throwable ex ){
ex.printStackTrace();
}
return result;
}

public static String toCamelCase( String src ){
StringBuilder sb = new StringBuilder();
for( String s : src.split( "_" ) ){
if( TextUtils.isEmpty( s ) ) continue;
sb.append( Character.toUpperCase( s.charAt( 0 ) ) );
sb.append( s.substring( 1, s.length() ).toLowerCase() );
}
return sb.toString();
}

}

Loading

0 comments on commit 4257494

Please sign in to comment.