Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/org/adblockplus/android/RefreshableListPreference.java

Issue 8493083: ABP/Android UI (Closed)
Patch Set: Created Oct. 5, 2012, 9:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/org/adblockplus/android/RefreshableListPreference.java
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/org/adblockplus/android/RefreshableListPreference.java
@@ -0,0 +1,56 @@
+package org.adblockplus.android;
+
+import android.content.Context;
+import android.preference.ListPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+
+/**
+ * ListPreference UI with refresh button.
+ */
+public class RefreshableListPreference extends ListPreference
+{
+ private OnClickListener refreshClickListener;
+
+ public RefreshableListPreference(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ }
+
+ @Override
+ protected void onBindView(View view)
+ {
+ super.onBindView(view);
+ final ImageView refreshImage = new ImageView(getContext());
+ final ViewGroup widgetFrameView = ((ViewGroup) view.findViewById(android.R.id.widget_frame));
Felix Dahlke 2012/10/09 14:27:29 Why is widgetFrameView final?
Andrey Novikov 2012/10/12 13:19:14 Done.
+ if (widgetFrameView == null)
+ return;
+ widgetFrameView.setVisibility(View.VISIBLE);
+ final int rightPaddingDip = android.os.Build.VERSION.SDK_INT < 14 ? 8 : 5;
+ final float mDensity = getContext().getResources().getDisplayMetrics().density;
Felix Dahlke 2012/10/09 14:27:29 Why prefix this variable with "m"? It's local.
Andrey Novikov 2012/10/12 13:19:14 Copy/paste problems.
+ if (widgetFrameView instanceof LinearLayout)
+ {
+ ((LinearLayout) widgetFrameView).setOrientation(LinearLayout.HORIZONTAL);
+ }
+ widgetFrameView.addView(refreshImage, 0);
+ refreshImage.setImageResource(R.drawable.ic_menu_refresh);
+ refreshImage.setPadding(refreshImage.getPaddingLeft(), refreshImage.getPaddingTop(), (int) (mDensity * rightPaddingDip), refreshImage.getPaddingBottom());
+ refreshImage.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v)
+ {
+ if (refreshClickListener != null)
+ refreshClickListener.onClick(refreshImage);
+ }
+ });
+ }
+
+ public void setOnRefreshClickListener(OnClickListener l)
+ {
+ refreshClickListener = l;
+ }
+}

Powered by Google App Engine
This is Rietveld