Skip to content

Commit

Permalink
Version 2.1 - Preferences to switch themes
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelevy committed Nov 10, 2014
1 parent c1a9bac commit 37b4d3b
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/build/
/.gradle/
/bin/
/gen/
/gen/
/market/
Binary file added releases/androidsoft-permission-2.1.0.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class Constants
{
public static final String TAG = "androidsoft.org";
public static final String LOG_TAG = "PFA-androidsoft.org";
public static final String PREFS = "permission_prefs";
public static final String KEY_TRUSTED_APP = "trusted_app";
public static final String KEY_TRUSTED_COUNT = "trusted_count";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
*/
public class PermissionService
{

private static final String TAG = "androidsoft";
private static NameComparator mNameComparator = new NameComparator();
private static ScoreComparator mScoreComparator = new ScoreComparator();
private static List<String> mTrustedApps;
Expand Down Expand Up @@ -139,7 +137,7 @@ public static List<PermissionGroup> getPermissions(String[] permissions, Package
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Permission name not found : " + permission);
Log.e(Constants.LOG_TAG, "Permission name not found : " + permission);
}
}
}
Expand Down Expand Up @@ -358,14 +356,14 @@ private static int getScore(String packageName, PackageManager pm)
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Permission name not found : " + permission);
Log.e(Constants.LOG_TAG, "Permission name not found : " + permission);
}
}
}
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Error getting package info : " + packageName);
Log.e(Constants.LOG_TAG, "Error getting package info : " + packageName);
}
return score;
}
Expand Down Expand Up @@ -399,7 +397,7 @@ private static void log(String text, List<String> trustedPackages)
{
for (String trusted : trustedPackages)
{
Log.d(TAG, text + trusted);
Log.d(Constants.LOG_TAG, text + trusted);
}
}

Expand All @@ -424,14 +422,14 @@ private static void registerPermissionApp(AppInfo app, String packageName, Packa
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Permission name not found : " + permission);
Log.e(Constants.LOG_TAG, "Permission name not found : " + permission);
}
}
}
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Error getting package info : " + packageName);
Log.e(Constants.LOG_TAG, "Error getting package info : " + packageName);
}
}

Expand Down Expand Up @@ -482,14 +480,14 @@ private static boolean isAppRequirePermission(Context context, AppInfo app, Stri
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Permission name not found : " + permission);
Log.e(Constants.LOG_TAG, "Permission name not found : " + permission);
}
}
}
}
catch (NameNotFoundException ex)
{
Log.e(TAG, "Error getting package info : " + app.getPackageName());
Log.e(Constants.LOG_TAG, "Error getting package info : " + app.getPackageName());
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;
import java.util.ArrayList;
import org.androidsoft.app.permission.Constants;

/**
* Preferences Service
Expand All @@ -26,14 +28,12 @@
*/
public class PreferencesService
{


private static final String PREF_NAME = "PermissionFriendlyAppsPreferences";
private static final String PREF_THEME = "Theme";
private static final int THEME_LIGHT = 0;
private static final int THEME_DARK = 1;

private static int mTheme = 1;
private static int mTheme;
private static ArrayList<ThemeChangesListener> mThemeListeners = new ArrayList<ThemeChangesListener>();

public static int getThemeId()
Expand All @@ -42,11 +42,11 @@ public static int getThemeId()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
nThemeId = isThemeDark() ? android.R.style.Theme_Material : android.R.style.Theme_Material_Light;
nThemeId = isThemeDark() ? android.R.style.Theme_Material : android.R.style.Theme_Material_Light_DarkActionBar;
}
else
{
nThemeId = isThemeDark() ? android.R.style.Theme_Holo : android.R.style.Theme_Holo_Light;
nThemeId = isThemeDark() ? android.R.style.Theme_Holo : android.R.style.Theme_Holo_Light_DarkActionBar;
}
return nThemeId;
}
Expand All @@ -61,17 +61,25 @@ public static void addThemeListener( ThemeChangesListener listener )
mThemeListeners.add(listener);
}

public static void notifyThemeListeners( Context context, boolean bDarkTheme )
public static void notifyThemeListeners( Context context , boolean bDarkTheme )
{
mTheme = ( bDarkTheme ) ? THEME_DARK : THEME_LIGHT;
SharedPreferences prefs = context.getSharedPreferences( PREF_NAME, Context.MODE_PRIVATE );
SharedPreferences.Editor editor = prefs.edit();
editor.putInt( PREF_THEME, mTheme );
editor.apply();
Log.i( Constants.LOG_TAG, "New theme stored : " + mTheme );
for( ThemeChangesListener listener : mThemeListeners )
{
listener.onChangeTheme();
}
}

public static void loadPreferences(Context context)
{
SharedPreferences prefs = context.getSharedPreferences( PREF_NAME, Context.MODE_PRIVATE );
mTheme = prefs.getInt( PREF_THEME, THEME_LIGHT );
Log.i( Constants.LOG_TAG, "Theme loaded : " + mTheme );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void updateApplication(Activity activity, String packageName)
}
catch (NameNotFoundException ex)
{
Log.e(Constants.TAG, "Package name not found : " + packageName);
Log.e(Constants.LOG_TAG, "Package name not found : " + packageName);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void onCreate(Bundle icicle)
{
super.onCreate(icicle);

PreferencesService.loadPreferences( this );
setTheme( PreferencesService.getThemeId() );

setContentView(R.layout.splash);
Expand Down
Binary file modified src/main/res/drawable-hdpi/dangerous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-hdpi/no_permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-hdpi/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/res/drawable-hdpi/trusted_row.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/main/res/drawable/round_shadow.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="#ffbbbbbb"/>
<stroke android:width="3px" android:color="#ffdddddd" />
<solid android:color="#30000000"/>
<stroke android:width="5px" android:color="#20000000" />
</shape>
3 changes: 2 additions & 1 deletion src/main/res/layout/application_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:padding="@dimen/padding" >

<ImageView android:id="@+id/icon"
android:contentDescription="@string/iv_application_icon"
Expand Down
4 changes: 2 additions & 2 deletions src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dimen name="bar_font">16sp</dimen>
<dimen name="icon">120dp</dimen>
<dimen name="icon_small_app">70dp</dimen>
<dimen name="icon_score">45dp</dimen>
<dimen name="icon_score">65dp</dimen>
<dimen name="padding_icon">8dp</dimen>
<dimen name="padding">10dp</dimen>
<dimen name="padding_pane">10dp</dimen>
Expand All @@ -37,6 +37,6 @@
<dimen name="font_button_round">24sp</dimen>
<dimen name="button_round">70dp</dimen>
<dimen name="round_icon_padding">25dp</dimen>
<dimen name="round_shadow_offset">14px</dimen>
<dimen name="round_shadow_offset">20px</dimen>
<dimen name="round_shape_offset">4px</dimen>
</resources>

0 comments on commit 37b4d3b

Please sign in to comment.