1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Fixed dips to pixels rounding

This commit is contained in:
Christophe Beyls 2016-12-12 18:22:53 +01:00
parent 7e90352750
commit d24a9dd5a9
3 changed files with 13 additions and 14 deletions

View file

@ -24,7 +24,6 @@ import android.widget.ListView;
* A PreferenceFragment for the support library. Based on the platform's code with some removed features and a basic ListView layout. * A PreferenceFragment for the support library. Based on the platform's code with some removed features and a basic ListView layout.
* *
* @author Christophe Beyls * @author Christophe Beyls
*
*/ */
public abstract class PreferenceFragment extends Fragment { public abstract class PreferenceFragment extends Fragment {
@ -32,19 +31,19 @@ public abstract class PreferenceFragment extends Fragment {
static final int MSG_BIND_PREFERENCES = 1; static final int MSG_BIND_PREFERENCES = 1;
static final int MSG_REQUEST_FOCUS = 2; static final int MSG_REQUEST_FOCUS = 2;
private static final String PREFERENCES_TAG = "android:preferences"; private static final String PREFERENCES_TAG = "android:preferences";
private static final float HC_HORIZONTAL_PADDING = 16; private static final float HC_HORIZONTAL_PADDING = 16f;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
private final Handler mHandler = new Handler() { private final Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
switch (msg.what) { switch (msg.what) {
case MSG_BIND_PREFERENCES: case MSG_BIND_PREFERENCES:
bindPreferences(); bindPreferences();
break; break;
case MSG_REQUEST_FOCUS: case MSG_REQUEST_FOCUS:
mList.focusableViewAvailable(mList); mList.focusableViewAvailable(mList);
break; break;
} }
} }
}; };
@ -70,7 +69,7 @@ public abstract class PreferenceFragment extends Fragment {
ListView listView = new ListView(getActivity()); ListView listView = new ListView(getActivity());
listView.setId(android.R.id.list); listView.setId(android.R.id.list);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
final int horizontalPadding = (int) (HC_HORIZONTAL_PADDING * getResources().getDisplayMetrics().density); final int horizontalPadding = (int) (HC_HORIZONTAL_PADDING * getResources().getDisplayMetrics().density + 0.5f);
listView.setPadding(horizontalPadding, 0, horizontalPadding, 0); listView.setPadding(horizontalPadding, 0, horizontalPadding, 0);
} }
return listView; return listView;

View file

@ -24,7 +24,7 @@ import be.digitalia.fosdem.widgets.ContentLoadingProgressBar;
*/ */
public class RecyclerViewFragment extends Fragment { public class RecyclerViewFragment extends Fragment {
private static final int DEFAULT_EMPTY_VIEW_PADDING_DIPS = 16; private static final float DEFAULT_EMPTY_VIEW_PADDING_DIPS = 16f;
static class ViewHolder { static class ViewHolder {
FrameLayout container; FrameLayout container;
@ -90,7 +90,7 @@ public class RecyclerViewFragment extends Fragment {
protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) { protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView textView = new TextView(inflater.getContext()); TextView textView = new TextView(inflater.getContext());
textView.setGravity(Gravity.CENTER); textView.setGravity(Gravity.CENTER);
int textPadding = (int) (getResources().getDisplayMetrics().density * DEFAULT_EMPTY_VIEW_PADDING_DIPS); int textPadding = (int) (getResources().getDisplayMetrics().density * DEFAULT_EMPTY_VIEW_PADDING_DIPS + 0.5f);
textView.setPadding(textPadding, textPadding, textPadding, textPadding); textView.setPadding(textPadding, textPadding, textPadding, textPadding);
return textView; return textView;
} }

View file

@ -24,7 +24,7 @@ import be.digitalia.fosdem.widgets.ContentLoadingProgressBar;
*/ */
public class SmoothListFragment extends Fragment { public class SmoothListFragment extends Fragment {
private static final int DEFAULT_EMPTY_VIEW_PADDING_DIPS = 16; private static final float DEFAULT_EMPTY_VIEW_PADDING_DIPS = 16f;
static class ViewHolder { static class ViewHolder {
FrameLayout container; FrameLayout container;
@ -52,7 +52,7 @@ public class SmoothListFragment extends Fragment {
protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) { protected View onCreateEmptyView(LayoutInflater inflater, ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView textView = new TextView(inflater.getContext()); TextView textView = new TextView(inflater.getContext());
textView.setGravity(Gravity.CENTER); textView.setGravity(Gravity.CENTER);
int textPadding = (int) (getResources().getDisplayMetrics().density * DEFAULT_EMPTY_VIEW_PADDING_DIPS); int textPadding = (int) (getResources().getDisplayMetrics().density * DEFAULT_EMPTY_VIEW_PADDING_DIPS + 0.5f);
textView.setPadding(textPadding, textPadding, textPadding, textPadding); textView.setPadding(textPadding, textPadding, textPadding, textPadding);
return textView; return textView;
} }