Browse Source

Android fixes and clean-ups.

tags/2021-05-28
jules 12 years ago
parent
commit
b0302ce30f
3 changed files with 44 additions and 36 deletions
  1. +0
    -3
      modules/juce_core/native/java/JuceAppActivity.java
  2. +22
    -7
      modules/juce_core/native/juce_posix_SharedCode.h
  3. +22
    -26
      modules/juce_core/time/juce_Time.cpp

+ 0
- 3
modules/juce_core/native/java/JuceAppActivity.java View File

@@ -81,9 +81,6 @@ public final class JuceAppActivity extends Activity
@Override
protected final void onPause()
{
if (viewHolder != null)
viewHolder.onPause();
suspendApp();
super.onPause();
}


+ 22
- 7
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -190,7 +190,7 @@ void JUCE_CALLTYPE Thread::sleep (int millisecs)
struct timespec time;
time.tv_sec = millisecs / 1000;
time.tv_nsec = (millisecs % 1000) * 1000000;
nanosleep (&time, 0);
nanosleep (&time, nullptr);
}
@@ -1168,8 +1168,10 @@ private:
static void* timerThread (void* param)
{
#if ! JUCE_ANDROID
int dummy;
pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, &dummy);
#endif
reinterpret_cast<Pimpl*> (param)->timerThread();
return nullptr;
@@ -1192,7 +1194,7 @@ private:
struct Clock
{
#if JUCE_MAC || JUCE_IOS
Clock (double millis)
Clock (double millis) noexcept
{
mach_timebase_info_data_t timebase;
(void) mach_timebase_info (&timebase);
@@ -1200,7 +1202,7 @@ private:
time = mach_absolute_time();
}
void wait()
void wait() noexcept
{
time += delta;
mach_wait_until (time);
@@ -1208,16 +1210,29 @@ private:
uint64_t time, delta;
#elif JUCE_ANDROID
Clock (double millis) noexcept : delta ((uint64) (millis * 1000000))
{
}
void wait() noexcept
{
struct timespec t;
t.tv_sec = (time_t) (delta / 1000000000);
t.tv_nsec = (long) (delta % 1000000000);
nanosleep (&t, nullptr);
}
uint64 delta;
#else
Clock (double millis)
: delta ((int64) (millis * 1000000))
Clock (double millis) noexcept : delta ((uint64) (millis * 1000000))
{
struct timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
time = 1000000000 * (int64) t.tv_sec + t.tv_nsec;
}
void wait()
void wait() noexcept
{
time += delta;
@@ -1228,7 +1243,7 @@ private:
clock_nanosleep (CLOCK_MONOTONIC, TIMER_ABSTIME, &t, nullptr);
}
int64 time, delta;
uint64 time, delta;
#endif
};


+ 22
- 26
modules/juce_core/time/juce_Time.cpp View File

@@ -85,26 +85,32 @@ namespace TimeHelpers
: (value - ((value / modulo) + 1) * modulo));
}
static int doFTime (CharPointer_UTF32 dest, const size_t maxChars,
const String& format, const struct tm* const tm) noexcept
static inline String formatString (const String& format, const struct tm* const tm)
{
#if JUCE_ANDROID
HeapBlock <char> tempDest;
tempDest.calloc (maxChars + 2);
const int result = (int) strftime (tempDest, maxChars, format.toUTF8(), tm);
if (result > 0)
dest.writeAll (CharPointer_UTF8 (tempDest.getData()));
return result;
typedef CharPointer_UTF8 StringType;
#elif JUCE_WINDOWS
HeapBlock <wchar_t> tempDest;
tempDest.calloc (maxChars + 2);
const int result = (int) wcsftime (tempDest, maxChars, format.toWideCharPointer(), tm);
if (result > 0)
dest.writeAll (CharPointer_UTF16 (tempDest.getData()));
return result;
typedef CharPointer_UTF16 StringType;
#else
return (int) wcsftime (dest.getAddress(), maxChars, format.toUTF32(), tm);
typedef CharPointer_UTF32 StringType;
#endif
for (size_t bufferSize = 256; ; bufferSize += 256)
{
HeapBlock<StringType::CharType> buffer (bufferSize);
#if JUCE_ANDROID
const size_t numChars = strftime (buffer, bufferSize - 1, format.toUTF8(), tm);
#elif JUCE_WINDOWS
const size_t numChars = wcsftime (buffer, bufferSize - 1, format.toWideCharPointer(), tm);
#else
const size_t numChars = wcsftime (buffer, bufferSize - 1, format.toUTF32(), tm);
#endif
if (numChars > 0)
return String (StringType (buffer),
StringType (buffer) + numChars);
}
}
static uint32 lastMSCounterValue = 0;
@@ -313,18 +319,8 @@ String Time::toString (const bool includeDate,
String Time::formatted (const String& format) const
{
size_t bufferSize = 128;
HeapBlock<juce_wchar> buffer (128);
struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
while (TimeHelpers::doFTime (CharPointer_UTF32 (buffer.getData()), bufferSize, format, &t) <= 0)
{
bufferSize += 128;
buffer.malloc (bufferSize);
}
return CharPointer_UTF32 (buffer.getData());
return TimeHelpers::formatString (format, &t);
}
//==============================================================================


Loading…
Cancel
Save