Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made themes changeable and some fixes #162

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
android:icon="@drawable/foto_gallery"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme"
android:theme="@style/AppTheme.Light"
>
<activity android:name=".FotoGalleryActivity"
android:icon="@drawable/foto_gallery"
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/de/k3b/android/GuiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

package de.k3b.android;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.preference.PreferenceManager;

import de.k3b.android.androFotoFinder.R;

/**
* gui utils
Expand All @@ -36,4 +40,17 @@ public static String getAppVersionName(final Context context) {
}
return null;
}
public static void setTheme(Activity act) {
final String theme = PreferenceManager.getDefaultSharedPreferences(act).getString("user_theme", "Light");
switch (theme) {
case "Light":
act.setTheme(R.style.AppTheme_Light);
break;
case "Dark":
act.setTheme(R.style.AppTheme_Dark);
break;
default:
throw new RuntimeException("Invalid theme selected");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.File;

import de.k3b.LibGlobal;
import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.imagedetail.HugeImageLoader;
import de.k3b.android.util.PhotoPropertiesMediaFilesScanner;
import de.k3b.android.util.PhotoPropertiesMediaFilesScannerExifInterface;
Expand All @@ -61,6 +62,83 @@ public class SettingsActivity extends PreferenceActivity {

private int INSTALL_REQUEST_CODE = 1927;

@Override
protected void onCreate(final Bundle savedInstanceState) {
GuiUtil.setTheme(this); // this activity doesn't extent ActivityWithCallContext
LocalizedActivity.fixLocale(this); // #21: Support to change locale at runtime
super.onCreate(savedInstanceState);

if (Global.debugEnabled) {
// todo create junit integration tests with arabic locale from this.
StringFormatResourceTests.test(this);
}

final Intent intent = getIntent();
if (Global.debugEnabled && (intent != null)){
Log.d(Global.LOG_CONTEXT, "SettingsActivity onCreate " + intent.toUri(Intent.URI_INTENT_SCHEME));
}

this.addPreferencesFromResource(R.xml.preferences);
prefsInstance = PreferenceManager
.getDefaultSharedPreferences(this);
global2Prefs(this.getApplication());

// #21: Support to change locale at runtime
defaultLocalePreference =
(ListPreference) findPreference(Global.PREF_KEY_USER_LOCALE);
defaultLocalePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
setLanguage((String) newValue);
LocalizedActivity.recreate(SettingsActivity.this);
return true; // change is allowed
}
});

mediaUpdateStrategyPreference =
(ListPreference) findPreference("mediaUpdateStrategy");
mediaUpdateStrategyPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LibGlobal.mediaUpdateStrategy = (String) newValue;
setPref(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names);
return true;
}
});
setPref(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names);

findPreference("debugClearLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
onDebugClearLogCat();
return false; // donot close
}
});
findPreference("debugSaveLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
onDebugSaveLogCat();
return false; // donot close
}
});
findPreference("translate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
onTranslate();
return false; // donot close
}
});

// #21: Support to change locale at runtime
updateSummary();
}

@Override
public void onPause() {
prefs2Global(this);
super.onPause();
}

public static void global2Prefs(Context context) {
fixDefaults(context, null, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import android.os.Bundle;
import android.util.Log;

import de.k3b.android.GuiUtil;
import de.k3b.android.androFotoFinder.Global;

/**
* An activity that memorizes the activity call stack (parent Activities) for debugging purposes.
*
* <p>
* Created by k3b on 25.08.2018.
*/
public class ActivityWithCallContext extends Activity {
Expand All @@ -42,7 +43,9 @@ public class ActivityWithCallContext extends Activity {
*/
public static final Boolean isCallContextEnabled = true;

/** what the current activity is doing. This will become part of the callstack when a child activity is invoked */
/**
* what the current activity is doing. This will become part of the callstack when a child activity is invoked
*/
public static String additionalCallContext = "";

/**
Expand Down Expand Up @@ -73,6 +76,7 @@ public static void addContext(String debugContext, Intent targetIntent, Activity

@Override
protected void onCreate(Bundle savedInstanceState) {
GuiUtil.setTheme(this); // Almost every activity extends this so use this to set theme
super.onCreate(savedInstanceState);

if (isCallContextEnabled) {
Expand All @@ -93,6 +97,7 @@ public static String readCallContext(Intent intent) {
public boolean hasParentCallContext() {
return this.parentCallContext.length() > 0;
}

@Override
protected void onResume() {
super.onResume();
Expand All @@ -110,7 +115,9 @@ public String getCallContext() {
return parentCallContext + "\n=> " + getCallerDescription(this);
}

/** called by all variants of startActivity(ForResult): add context to call.*/
/**
* called by all variants of startActivity(ForResult): add context to call.
*/
@Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
startActivityForResultImpl(intent, requestCode, options);
Expand All @@ -131,7 +138,9 @@ public void startActivity(Intent intent) {
startActivityForResultImpl(intent, -1, null);
}

/** called by all variants of startActivity(ForResult): add context to call.*/
/**
* called by all variants of startActivity(ForResult): add context to call.
*/
private void startActivityForResultImpl(Intent intent, int requestCode, Bundle options) {
addContext(additionalCallContext, intent, this);
additionalCallContext = "";
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/drawable/grid_color_selector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@

<item android:drawable="@color/blue" android:state_pressed="true" />
<item android:drawable="@color/blue" android:state_selected="true" />
<item android:drawable="@color/white" />

</selector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_gallery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
<!--Removed ObsoleteLayoutParam: layout_alignParentTop-->
</HorizontalScrollView>


<GridView android:orientation="horizontal"
android:background="#f0f0f0"
android:id="@+id/gridView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_tags.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
android:layout_alignParentBottom="true"
/>

<TextView android:id="@id/android:empty"
<TextView android:id="@android:id/empty"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:text="@string/tags_search_no_matching_items_found"
android:layout_below="@+id/myFilter"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@
<item>00000</item>
</string-array>

<string-array name="pref_available_themes" translatable="false">
<item>Light</item>
<item>Dark</item>
</string-array>

<string-array name="pref_themes_names" translatable="true">
<item>@string/theme_light</item>
<item>@string/theme_dark</item>
</string-array>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<resources>
<color name="blue">#00abea</color>
<color name="white">#ffffff</color>
<!--<color name="primary_background">@android:color/black</color>-->
<color name="image_label_background">#70ffffff</color>
<color name="drag_to">@android:color/black</color>
<color name="search_layover_bg">#50000000</color>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,16 @@ You can undo hiding by calling the mediascanner from gallery-menu."</string>

<!-- when should backup start ? -->
<string name="lbl_when">When: </string>
<string name="settings_theme">Theme</string>
<string name="theme_light">Holo light</string>
<string name="theme_dark">Holo dark</string>
<!-- #108 Zip-file export/backup will be implemented later
< ! - - what type of data should be saven ? - - >
<string name="lbl_what">What: </string>
-->

<!-- #155: android10 -->
<string name="load_db_menu_title">(Re)Load Media Database</string>

</resources>

6 changes: 5 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<style name="AppTheme.Light" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->

</style>
<style name="AppTheme.Dark" parent="android:Theme.Holo">

</style>
<style name="MSV_ImageButton">
<item name="android:layout_width">wrap_content</item>
Expand Down
Loading