mirror of https://github.com/tasks/tasks
Add ActivityPreferences, remove AstridPreferences
parent
7b3be55752
commit
f645f21631
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.utility;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.astrid.api.AstridApiConstants;
|
||||
|
||||
public class AstridPreferences {
|
||||
|
||||
/* ======================================================================
|
||||
* ========================================================= public prefs
|
||||
* ====================================================================== */
|
||||
|
||||
/** Get publicly readable preferences */
|
||||
public static SharedPreferences getPublicPrefs(Context context) {
|
||||
context = context.getApplicationContext();
|
||||
return context.getSharedPreferences(AstridApiConstants.PUBLIC_PREFS,
|
||||
Context.MODE_WORLD_READABLE);
|
||||
}
|
||||
|
||||
/* ======================================================================
|
||||
* ========================================================= system prefs
|
||||
* ====================================================================== */
|
||||
|
||||
public static boolean useTabletLayout(Context context) {
|
||||
return AndroidUtilities.isTabletSized(context);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
import static java.lang.annotation.ElementType.FIELD;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PARAMETER;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Qualifier
|
||||
@Target({FIELD, PARAMETER, METHOD})
|
||||
@Documented
|
||||
@Retention(RUNTIME)
|
||||
public @interface ForActivity {
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package org.tasks.preferences;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import org.tasks.injection.ForActivity;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class ActivityPreferences extends Preferences {
|
||||
|
||||
public static final int MIN_TABLET_WIDTH = 550;
|
||||
public static final int MIN_TABLET_HEIGHT = 800;
|
||||
|
||||
@Inject
|
||||
public ActivityPreferences(@ForActivity Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public boolean useTabletLayout() {
|
||||
return isTabletSized(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the screen is large or xtra large
|
||||
*/
|
||||
public static boolean isTabletSized(Context context) {
|
||||
if (context.getPackageManager().hasSystemFeature("com.google.android.tv")) { //$NON-NLS-1$
|
||||
return true;
|
||||
}
|
||||
int size = context.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK;
|
||||
|
||||
if (size == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
|
||||
return true;
|
||||
} else if (size == Configuration.SCREENLAYOUT_SIZE_LARGE) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
float width = metrics.widthPixels / metrics.density;
|
||||
float height = metrics.heightPixels / metrics.density;
|
||||
|
||||
float effectiveWidth = Math.min(width, height);
|
||||
float effectiveHeight = Math.max(width, height);
|
||||
|
||||
return (effectiveWidth >= MIN_TABLET_WIDTH && effectiveHeight >= MIN_TABLET_HEIGHT);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue