Skip to content

Commit

Permalink
Merge branch 'release/4.4-beta8'
Browse files Browse the repository at this point in the history
  • Loading branch information
yukuku committed Sep 8, 2016
2 parents f256d18 + 353a801 commit 61db4d3
Show file tree
Hide file tree
Showing 47 changed files with 747 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android:
- tools

# The BuildTools version used by your project
- build-tools-24.0.0
- build-tools-24.0.1

# The SDK version used to compile your project
- android-24
Expand Down
26 changes: 24 additions & 2 deletions Afw/src/main/java/yuku/afw/storage/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,39 @@ public static int getInt(@StringRes final int keyStringResId, @IntegerRes final
}
}

public static boolean getBoolean(@StringRes final int keyStringResId, @BoolRes final int defaultIntResId) {
public static boolean getBoolean(@StringRes final int keyStringResId, @BoolRes final int defaultBoolResId) {
final Resources r = App.context.getResources();
final String key = r.getString(keyStringResId);
final Object value = get(key);
if (value == null) {
return r.getBoolean(defaultIntResId);
return r.getBoolean(defaultBoolResId);
} else {
return (boolean) value;
}
}

public static String getString(@StringRes final int keyStringResId, @StringRes final int defaultStringResId) {
final Resources r = App.context.getResources();
final String key = r.getString(keyStringResId);
final Object value = get(key);
if (value == null) {
return r.getString(defaultStringResId);
} else {
return (String) value;
}
}

public static String getString(@StringRes final int keyStringResId) {
final Resources r = App.context.getResources();
final String key = r.getString(keyStringResId);
final Object value = get(key);
if (value == null) {
return null;
} else {
return (String) value;
}
}

@TargetApi(9) private synchronized static void commitIfNotHeld() {
if (held > 0) {
// don't do anything now
Expand Down
4 changes: 2 additions & 2 deletions Alkitab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId 'yuku.alkitab.debug'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 14000267
versionName '4.4.0-beta7'
versionCode 14000268
versionName '4.4.0-beta8'
multiDexEnabled true
// Keep this synced with build.gradle resConfigs!
resConfigs 'af', 'bg', 'cs', 'da', 'de', 'es', 'fr', 'in', 'ja', 'lv', 'ms', 'nl', 'pl', 'pt', 'ro', 'ru', 'th', 'uk', 'zh-rCN', 'zh-rTW'
Expand Down
11 changes: 11 additions & 0 deletions Alkitab/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\.PDB" />
<data android:pathPattern="/.*\\..*\\..*\\..*\\..*\\..*\\.PDB" />
</intent-filter>
<!-- chemical/x-pdb -->
<intent-filter android:label="@string/intent_filter_open_pdb_file">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="chemical/x-pdb" />
</intent-filter>
<!-- last: any file with application/octet-stream type -->
<intent-filter android:label="@string/intent_filter_open_pdb_or_yes_file">
<action android:name="android.intent.action.VIEW" />
Expand Down
52 changes: 47 additions & 5 deletions Alkitab/src/main/java/yuku/alkitab/base/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.Build;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.multidex.MultiDex;
import android.support.v4.content.LocalBroadcastManager;
Expand Down Expand Up @@ -145,7 +146,7 @@ public synchronized static void staticInit() {
PreferenceManager.setDefaultValues(context, preferenceResId, false);
}

updateConfigurationWithPreferencesLocale();
forceUpdateConfiguration();

// all activities need at least the activeVersion from S, so initialize it here.
synchronized (S.class) {
Expand Down Expand Up @@ -173,6 +174,10 @@ public synchronized static void staticInit() {
if (Preferences.contains(Prefkey.sync_simpleToken)) {
Sync.notifySyncNeeded(SyncShadow.ALL_SYNC_SET_NAMES);
}

if (BuildConfig.DEBUG) {
Log.d(TAG, "Font scale: " + context.getResources().getConfiguration().fontScale);
}
}

private static void forceOverflowMenu() {
Expand All @@ -199,7 +204,7 @@ private static void forceOverflowMenu() {
}

private static Locale getLocaleFromPreferences() {
final String lang = Preferences.getString(context.getString(R.string.pref_language_key), context.getString(R.string.pref_language_default));
final String lang = Preferences.getString(R.string.pref_language_key, R.string.pref_language_default);
if (lang == null || "DEFAULT".equals(lang)) {
return Locale.getDefault();
}
Expand All @@ -214,20 +219,57 @@ private static Locale getLocaleFromPreferences() {
}
}

private static float getFontScaleFromPreferences() {
float res = 0.f;

final String forceFontScale = Preferences.getString(R.string.pref_forceFontScale_key);
if (forceFontScale != null && !context.getString(R.string.pref_forceFontScale_default).equals(forceFontScale)) {
if (context.getString(R.string.pref_forceFontScale_value_x1_5).equals(forceFontScale)) {
res = 1.5f;
} else if (context.getString(R.string.pref_forceFontScale_value_x1_7).equals(forceFontScale)) {
res = 1.7f;
} else if (context.getString(R.string.pref_forceFontScale_value_x2_0).equals(forceFontScale)) {
res = 2.0f;
}
}

if (res == 0.f) {
final float defFontScale = Settings.System.getFloat(context.getContentResolver(), Settings.System.FONT_SCALE, 1.f);
if (BuildConfig.DEBUG) Log.d(TAG, "defFontScale: " + defFontScale);
res = defFontScale;
}

return res;
}

@Override public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

Log.d(TAG, "@@onConfigurationChanged: config changed to: " + newConfig);
updateConfigurationWithPreferencesLocale();
forceUpdateConfiguration();
}

public static void updateConfigurationWithPreferencesLocale() {
public static void forceUpdateConfiguration() {
final Configuration config = context.getResources().getConfiguration();
boolean updated = false;

final Locale locale = getLocaleFromPreferences();
if (!U.equals(config.locale.getLanguage(), locale.getLanguage()) || !U.equals(config.locale.getCountry(), locale.getCountry())) {
Log.d(TAG, "@@updateConfigurationWithPreferencesLocale: locale will be updated to: " + locale);
if (BuildConfig.DEBUG) Log.d(TAG, "@@forceUpdateConfiguration: locale will be updated to: " + locale);

config.locale = locale;
updated = true;
}

final float fontScale = getFontScaleFromPreferences();
if (config.fontScale != fontScale) {
if (BuildConfig.DEBUG) Log.d(TAG, "@@forceUpdateConfiguration: fontScale will be updated to: " + fontScale);

config.fontScale = fontScale;
updated = true;
}

if (updated) {
context.getResources().updateConfiguration(config, null);
}
}
Expand Down
33 changes: 19 additions & 14 deletions Alkitab/src/main/java/yuku/alkitab/base/IsiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,28 @@ private void applyPreferences() {

void bGoto_click() {
App.trackEvent("nav_goto_button_click");
startActivityForResult(GotoActivity.createIntent(this.activeBook.bookId, this.chapter_1, lsSplit0.getVerseBasedOnScroll()), REQCODE_goto);

final Runnable r = () -> startActivityForResult(GotoActivity.createIntent(this.activeBook.bookId, this.chapter_1, lsSplit0.getVerseBasedOnScroll()), REQCODE_goto);

if (!Preferences.getBoolean(Prefkey.history_button_understood, false) && history.getSize() > 0) {
new MaterialDialog.Builder(this)
.content(R.string.goto_button_history_tip)
.positiveText(R.string.ok)
.onPositive((dialog, which) -> {
Preferences.setBoolean(Prefkey.history_button_understood, true);
r.run();
})
.show();
} else {
r.run();
}
}

void bGoto_longClick() {
App.trackEvent("nav_goto_button_long_click");
if (history.getSize() > 0) {
MaterialDialogAdapterHelper.show(new MaterialDialog.Builder(this), new HistoryAdapter());
Preferences.setBoolean(Prefkey.history_button_understood, true);
} else {
Snackbar.make(root, R.string.recentverses_not_available, Snackbar.LENGTH_SHORT).show();
}
Expand Down Expand Up @@ -1226,7 +1241,6 @@ public void onBindViewHolder(final RecyclerView.ViewHolder _holder_, final int p
final int ari = history.getAri(which);
jumpToAri(ari);
history.add(ari);
Preferences.setBoolean(Prefkey.history_button_understood, true);
});
}

Expand Down Expand Up @@ -1352,19 +1366,15 @@ void updateToolbarLocation() {
public void onWindowFocusChanged(final boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

final View decorView = getWindow().getDecorView();
Log.d(TAG, "@@onWindowFocusChanged bef hasFocus=" + hasFocus + " 0x" + Integer.toHexString(decorView.getSystemUiVisibility()));

if (hasFocus && fullScreen) {
if (Build.VERSION.SDK_INT >= 19) {
final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_IMMERSIVE
);
}
}

Log.d(TAG, "@@onWindowFocusChanged aft hasFocus=" + hasFocus + " 0x" + Integer.toHexString(decorView.getSystemUiVisibility()));
}

void setShowTextAppearancePanel(boolean yes) {
Expand Down Expand Up @@ -1637,12 +1647,7 @@ int display(int chapter_1, int verse_1, boolean uncheckAllVerses) {

// set goto button text
final String reference = this.activeBook.reference(chapter_1);
if (Preferences.getBoolean(Prefkey.history_button_understood, false) || history.getSize() == 0) {
bGoto.setText(reference);
} else {
// TODO show something to indicate user can long press on goto button
bGoto.setText(reference);
}
bGoto.setText(reference.replace(' ', '\u00a0'));

if (fullScreen) {
if (fullScreenToast == null) {
Expand Down Expand Up @@ -1713,7 +1718,7 @@ static boolean loadChapterToVersesView(VersesView versesView, Version version, S
}

@Override public boolean onKeyUp(int keyCode, KeyEvent event) {
final String volumeButtonsForNavigation = Preferences.getString(getString(R.string.pref_volumeButtonNavigation_key), getString(R.string.pref_volumeButtonNavigation_default));
final String volumeButtonsForNavigation = Preferences.getString(R.string.pref_volumeButtonNavigation_key, R.string.pref_volumeButtonNavigation_default);
if (! U.equals(volumeButtonsForNavigation, "default")) { // consume here
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) return true;
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) return true;
Expand Down
57 changes: 45 additions & 12 deletions Alkitab/src/main/java/yuku/alkitab/base/ac/AboutActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package yuku.alkitab.base.ac;

import android.annotation.SuppressLint;
import android.app.LoaderManager;
import android.content.AsyncTaskLoader;
import android.content.Intent;
import android.content.Loader;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.res.ResourcesCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.widget.ContentLoadingProgressBar;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -48,6 +52,11 @@ public class AboutActivity extends BaseActivity {
TextView tAnnouncements;
ContentLoadingProgressBar progressAnnouncements;

final AtomicBoolean backgroundAnimationStarted = new AtomicBoolean(false);
int baseHue = 0;
final float[] hsl = new float[3];
final int[] colors = new int[6];

enum AnnouncementState {
init,
loading,
Expand Down Expand Up @@ -102,7 +111,8 @@ public void onLoaderReset(final Loader<long[]> loader) {
}
};

@Override protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

Expand Down Expand Up @@ -149,14 +159,10 @@ public void onLoaderReset(final Loader<long[]> loader) {
.content(R.string.about_enable_beta_confirmation)
.positiveText(R.string.ok)
.negativeText(R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(final MaterialDialog dialog) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/apps/testing/" + getPackageName())));
} catch (Exception ignored) {
// just ignore, this is not important if fails.
}
.onPositive((dialog, which) -> {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/apps/testing/" + getPackageName())));
} catch (Exception ignored) {
}
})
.show();
Expand All @@ -181,7 +187,7 @@ public void onPositive(final MaterialDialog dialog) {

imgLogo.setImageDrawable(ResourcesCompat.getDrawableForDensity(getResources(), R.drawable.ic_launcher, DisplayMetrics.DENSITY_XXXHIGH, null));

imgLogo.setOnTouchListener((v,event) -> {
imgLogo.setOnTouchListener((v, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
final float x = event.getX();
final float y = event.getY();
Expand All @@ -204,6 +210,7 @@ public void onPositive(final MaterialDialog dialog) {

void bAnnouncements_click() {
switch (announcementState) {
case init:
case loading:
// do nothing
break;
Expand Down Expand Up @@ -245,16 +252,42 @@ void setAnnouncementState(final AnnouncementState state) {
}
}

View.OnTouchListener root_touch = (v, event) -> {
final View.OnTouchListener root_touch = (v, event) -> {
if (event.getPointerCount() == 4) {
getWindow().setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.BR_TL, new int[] {0xffaaffaa, 0xffaaffff, 0xffaaaaff, 0xffffaaff, 0xffffaaaa, 0xffffffaa}));
startBackgroundAnimation();
} else if (event.getPointerCount() == 5 && event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
showSecretDialog();
}

return false;
};

@SuppressLint("HandlerLeak")
private void startBackgroundAnimation() {
if (!backgroundAnimationStarted.compareAndSet(false, true)) {
return;
}

new Handler() {
@Override
public void handleMessage(final Message msg) {
if (isFinishing()) return; // don't leak

final int baseColor = 0xff99ff99;
ColorUtils.colorToHSL(baseColor, hsl);
for (int i = 0; i < colors.length; i++) {
hsl[0] = (baseHue + i * 60) % 360;
colors[i] = ColorUtils.HSLToColor(hsl);
}

getWindow().setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.BR_TL, colors));

baseHue += 2;
sendEmptyMessageDelayed(0, 16);
}
}.sendEmptyMessage(0);
}

private void showSecretDialog() {
new MaterialDialog.Builder(this)
.items(List("Secret settings", "Crash me"))
Expand Down
Loading

0 comments on commit 61db4d3

Please sign in to comment.