-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically choose a new color for additional layers of the same type
Fixes #2197
- Loading branch information
1 parent
5c85dad
commit 8eb68d8
Showing
5 changed files
with
139 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/de/blau/android/layer/StyleableFileLayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.blau.android.layer; | ||
|
||
import java.io.InputStream; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import androidx.annotation.NonNull; | ||
import de.blau.android.contract.FileExtensions; | ||
import de.blau.android.util.Hash; | ||
|
||
/** | ||
* StyleableLayer that is loaded from a file | ||
* | ||
* @author simon | ||
* | ||
*/ | ||
public abstract class StyleableFileLayer extends StyleableLayer { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* State file file name | ||
*/ | ||
protected String stateFileName; | ||
|
||
protected String contentId; // could potentially be transient | ||
|
||
protected StyleableFileLayer(@NonNull String contentId, String defaultStateFileName) { | ||
this.contentId = contentId; | ||
this.stateFileName = defaultStateFileName; | ||
} | ||
|
||
/** | ||
* Check if we have a state file | ||
* | ||
* @param context an Android Context | ||
* @return true if a state file exists | ||
*/ | ||
protected boolean hasStateFile(@NonNull Context context) { | ||
setStateFileName(Uri.parse(contentId).getEncodedPath()); | ||
try (InputStream stream = context.openFileInput(stateFileName)) { | ||
return true; | ||
} catch (Exception ex) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Set the name of the state file | ||
* | ||
* This needs to be unique across all instances so best an encoded uri, to avoid filename length issues we use the | ||
* SHA-256 hash | ||
* | ||
* @param baseName the base name for this specific instance | ||
*/ | ||
protected void setStateFileName(@NonNull String baseName) { | ||
stateFileName = Hash.sha256(baseName) + "." + FileExtensions.RES; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters