forked from QuestCraftPlusPlus/Pojlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port of Commit 72032ca from QC's Pojlib
- Loading branch information
Showing
8 changed files
with
319 additions
and
314 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
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
32 changes: 16 additions & 16 deletions
32
src/main/java/pojlib/util/Constants.java → src/main/java/pojlib/Constants.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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
package pojlib.util; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
|
||
public class Constants { | ||
private static String filesDir; | ||
|
||
@SuppressLint("SdCardPath") | ||
public static String getFilesDir(Context activity) { | ||
if (filesDir == null) { | ||
filesDir = activity.getFilesDir().getAbsolutePath(); | ||
} | ||
return filesDir; | ||
} | ||
} | ||
package pojlib; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
|
||
public class Constants { | ||
private static String filesDir; | ||
|
||
@SuppressLint("SdCardPath") | ||
public static String getFilesDir(Context activity) { | ||
if (filesDir == null) { | ||
filesDir = activity.getFilesDir().getAbsolutePath(); | ||
} | ||
return filesDir; | ||
} | ||
} |
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
178 changes: 89 additions & 89 deletions
178
src/main/java/pojlib/util/Logger.java → src/main/java/pojlib/Logger.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 |
---|---|---|
@@ -1,89 +1,89 @@ | ||
package pojlib.util; | ||
|
||
import android.app.Activity; | ||
import androidx.annotation.Keep; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.lang.ref.WeakReference; | ||
|
||
/** Singleton class made to log on one file | ||
* The singleton part can be removed but will require more implementation from the end-dev | ||
*/ | ||
@Keep | ||
public class Logger { | ||
// getFilesDir | ||
/* Instance variables */ | ||
private final File mLogFile; | ||
private PrintStream mLogStream; | ||
private WeakReference<eventLogListener> mLogListenerWeakReference = null; | ||
|
||
private Logger(Activity activity){ | ||
mLogFile = new File(activity.getExternalFilesDir(null), "latestlog.txt"); | ||
// Make a new instance of the log file | ||
mLogFile.delete(); | ||
try { | ||
mLogFile.createNewFile(); | ||
mLogStream = new PrintStream(mLogFile.getAbsolutePath()); | ||
}catch (IOException e){e.printStackTrace();} | ||
|
||
} | ||
|
||
private static Logger logger; | ||
|
||
public static Logger getInstance(Activity activity){ | ||
if (logger == null) { | ||
logger = new Logger(activity); | ||
} | ||
return logger; | ||
} | ||
|
||
|
||
/** Print the text to the log file if not censored */ | ||
public void appendToLog(String text){ | ||
if(shouldCensorLog(text)) return; | ||
appendToLogUnchecked(text); | ||
} | ||
|
||
/** Print the text to the log file, no china censoring there */ | ||
public void appendToLogUnchecked(String text){ | ||
mLogStream.println(text); | ||
notifyLogListener(text); | ||
} | ||
|
||
/** Reset the log file, effectively erasing any previous logs */ | ||
public void reset(){ | ||
try{ | ||
mLogFile.delete(); | ||
mLogFile.createNewFile(); | ||
mLogStream = new PrintStream(mLogFile.getAbsolutePath()); | ||
}catch (IOException e){ e.printStackTrace();} | ||
} | ||
|
||
/** | ||
* Perform various checks to see if the log is safe to print | ||
* Subclasses may want to override this behavior | ||
* @param text The text to check | ||
* @return Whether the log should be censored | ||
*/ | ||
private static boolean shouldCensorLog(String text){ | ||
return text.contains("Session ID is"); | ||
} | ||
|
||
/** Small listener for anything listening to the log */ | ||
public interface eventLogListener { | ||
void onEventLogged(String text); | ||
} | ||
|
||
/** Notifies the event listener, if it exists */ | ||
private void notifyLogListener(String text){ | ||
if(mLogListenerWeakReference == null) return; | ||
eventLogListener logListener = mLogListenerWeakReference.get(); | ||
if(logListener == null){ | ||
mLogListenerWeakReference = null; | ||
return; | ||
} | ||
logListener.onEventLogged(text); | ||
} | ||
} | ||
package pojlib; | ||
|
||
import android.app.Activity; | ||
import androidx.annotation.Keep; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
import java.lang.ref.WeakReference; | ||
|
||
/** Singleton class made to log on one file | ||
* The singleton part can be removed but will require more implementation from the end-dev | ||
*/ | ||
@Keep | ||
public class Logger { | ||
// getFilesDir | ||
/* Instance variables */ | ||
private final File mLogFile; | ||
private PrintStream mLogStream; | ||
private WeakReference<eventLogListener> mLogListenerWeakReference = null; | ||
|
||
private Logger(Activity activity){ | ||
mLogFile = new File(activity.getExternalFilesDir(null), "latestlog.txt"); | ||
// Make a new instance of the log file | ||
mLogFile.delete(); | ||
try { | ||
mLogFile.createNewFile(); | ||
mLogStream = new PrintStream(mLogFile.getAbsolutePath()); | ||
}catch (IOException e){e.printStackTrace();} | ||
|
||
} | ||
|
||
private static Logger logger; | ||
|
||
public static Logger getInstance(Activity activity){ | ||
if (logger == null) { | ||
logger = new Logger(activity); | ||
} | ||
return logger; | ||
} | ||
|
||
|
||
/** Print the text to the log file if not censored */ | ||
public void appendToLog(String text){ | ||
if(shouldCensorLog(text)) return; | ||
appendToLogUnchecked(text); | ||
} | ||
|
||
/** Print the text to the log file, no china censoring there */ | ||
public void appendToLogUnchecked(String text){ | ||
mLogStream.println(text); | ||
notifyLogListener(text); | ||
} | ||
|
||
/** Reset the log file, effectively erasing any previous logs */ | ||
public void reset(){ | ||
try{ | ||
mLogFile.delete(); | ||
mLogFile.createNewFile(); | ||
mLogStream = new PrintStream(mLogFile.getAbsolutePath()); | ||
}catch (IOException e){ e.printStackTrace();} | ||
} | ||
|
||
/** | ||
* Perform various checks to see if the log is safe to print | ||
* Subclasses may want to override this behavior | ||
* @param text The text to check | ||
* @return Whether the log should be censored | ||
*/ | ||
private static boolean shouldCensorLog(String text){ | ||
return text.contains("Session ID is"); | ||
} | ||
|
||
/** Small listener for anything listening to the log */ | ||
public interface eventLogListener { | ||
void onEventLogged(String text); | ||
} | ||
|
||
/** Notifies the event listener, if it exists */ | ||
private void notifyLogListener(String text){ | ||
if(mLogListenerWeakReference == null) return; | ||
eventLogListener logListener = mLogListenerWeakReference.get(); | ||
if(logListener == null){ | ||
mLogListenerWeakReference = null; | ||
return; | ||
} | ||
logListener.onEventLogged(text); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/pojlib/util/VLoader.java → src/main/java/pojlib/VLoader.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package pojlib.util; | ||
package pojlib; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
|
Oops, something went wrong.