| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 import android.view.ViewGroup; | 42 import android.view.ViewGroup; |
| 43 import android.view.ViewGroup.LayoutParams; | 43 import android.view.ViewGroup.LayoutParams; |
| 44 import android.view.Window; | 44 import android.view.Window; |
| 45 import android.widget.Button; | 45 import android.widget.Button; |
| 46 import android.widget.LinearLayout; | 46 import android.widget.LinearLayout; |
| 47 import android.widget.TextView; | 47 import android.widget.TextView; |
| 48 | 48 |
| 49 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
istener | 49 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
istener |
| 50 { | 50 { |
| 51 private static final String TAG = "AdblockBrowser.StartPane"; | 51 private static final String TAG = "AdblockBrowser.StartPane"; |
| 52 private int currentStep = 1; | 52 private int currentStep = 0; |
| 53 private static final int NUMBER_OF_STEPS = 3; | 53 private static final boolean SKIP_BETA_COMMUNITY_PAGE = true; |
| 54 private static final HashMap<String, Integer> FONTS = new HashMap<String, Inte
ger>(); | 54 private static final HashMap<String, Integer> FONTS = new HashMap<String, Inte
ger>(); |
| 55 private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>(
); | 55 private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>(
); |
| 56 | 56 |
| 57 private static final int[] BETA_RESOURCE_LIST = |
| 58 { |
| 59 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_1, |
| 60 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_2, |
| 61 R.layout.abb_start_pane_step_3, R.string.abb_frp_button_3 |
| 62 }; |
| 63 |
| 64 private static final int[] RELEASE_RESOURCE_LIST = |
| 65 { |
| 66 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_2, |
| 67 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_3 |
| 68 }; |
| 69 |
| 70 private static final int[] PAGES_RESOURCE_LIST = SKIP_BETA_COMMUNITY_PAGE ? |
| 71 RELEASE_RESOURCE_LIST : BETA_RESOURCE_LIST; |
| 72 |
| 57 static | 73 static |
| 58 { | 74 { |
| 59 FONTS.put("ttf_opensans_light", R.raw.opensans_light); | 75 FONTS.put("ttf_opensans_light", R.raw.opensans_light); |
| 60 FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold); | 76 FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold); |
| 61 } | 77 } |
| 62 | 78 |
| 63 static Typeface typefaceFromResource(final Context context, final int resId) | 79 static Typeface typefaceFromResource(final Context context, final int resId) |
| 64 { | 80 { |
| 65 Typeface ret = null; | 81 Typeface ret = null; |
| 66 try | 82 try |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 { | 147 { |
| 132 super.onActivityCreated(savedInstanceState); | 148 super.onActivityCreated(savedInstanceState); |
| 133 final Window window = getDialog().getWindow(); | 149 final Window window = getDialog().getWindow(); |
| 134 window.setBackgroundDrawable(null); | 150 window.setBackgroundDrawable(null); |
| 135 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | 151 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
| 136 } | 152 } |
| 137 | 153 |
| 138 @Override | 154 @Override |
| 139 public void onClick(View v) | 155 public void onClick(View v) |
| 140 { | 156 { |
| 141 if (this.currentStep < NUMBER_OF_STEPS) | 157 final int nextStep = this.currentStep + 1; |
| 158 if (nextStep * 2 < PAGES_RESOURCE_LIST.length) |
| 142 { | 159 { |
| 143 this.currentStep++; | 160 this.currentStep = nextStep; |
| 144 this.updateContents(this.getView()); | 161 this.updateContents(this.getView()); |
| 145 } | 162 } |
| 146 else | 163 else |
| 147 { | 164 { |
| 148 this.dismissAllowingStateLoss(); | 165 this.dismissAllowingStateLoss(); |
| 149 } | 166 } |
| 150 } | 167 } |
| 151 | 168 |
| 152 @Override | 169 @Override |
| 153 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) | 170 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) |
| 154 { | 171 { |
| 155 if (keyCode == KeyEvent.KEYCODE_BACK) | 172 if (keyCode == KeyEvent.KEYCODE_BACK) |
| 156 { | 173 { |
| 157 if (event.getAction() == KeyEvent.ACTION_DOWN && this.currentStep > 1) | 174 if (event.getAction() == KeyEvent.ACTION_DOWN && this.currentStep > 0) |
| 158 { | 175 { |
| 159 this.currentStep--; | 176 this.currentStep--; |
| 160 this.updateContents(this.getView()); | 177 this.updateContents(this.getView()); |
| 161 } | 178 } |
| 162 return true; | 179 return true; |
| 163 } | 180 } |
| 164 return false; | 181 return false; |
| 165 } | 182 } |
| 166 | 183 |
| 167 private static List<View> listViews(final View parent) | 184 private static List<View> listViews(final View parent) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 185 } | 202 } |
| 186 } | 203 } |
| 187 | 204 |
| 188 private void updateContents(final View view) | 205 private void updateContents(final View view) |
| 189 { | 206 { |
| 190 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte
nt); | 207 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte
nt); |
| 191 ll.removeAllViews(); | 208 ll.removeAllViews(); |
| 192 | 209 |
| 193 final LayoutInflater inflater = (LayoutInflater) this.getActivity() | 210 final LayoutInflater inflater = (LayoutInflater) this.getActivity() |
| 194 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | 211 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 195 inflater.inflate( | 212 inflater.inflate(PAGES_RESOURCE_LIST[this.currentStep * 2], ll, true); |
| 196 this.getResources().getIdentifier("abb_start_pane_step_" + this.currentS
tep, | 213 this.setButtonText(view, R.id.abb_frp_button, PAGES_RESOURCE_LIST[this.curre
ntStep * 2 + 1]); |
| 197 "layout", | |
| 198 this.getActivity().getPackageName()), ll, true); | |
| 199 | |
| 200 this.setButtonText(view, R.id.abb_frp_button, | |
| 201 this.getResources().getIdentifier("abb_frp_button_" + this.currentStep, | |
| 202 "string", | |
| 203 this.getActivity().getPackageName())); | |
| 204 | 214 |
| 205 final List<View> views = listViews(view); | 215 final List<View> views = listViews(view); |
| 206 for (View v : views) | 216 for (View v : views) |
| 207 { | 217 { |
| 208 final Object tag = v.getTag(); | 218 final Object tag = v.getTag(); |
| 209 if (tag != null) | 219 if (tag != null) |
| 210 { | 220 { |
| 211 Typeface t = this.loadedFonts.get(tag.toString()); | 221 Typeface t = this.loadedFonts.get(tag.toString()); |
| 212 if (t != null) | 222 if (t != null) |
| 213 { | 223 { |
| 214 if (v instanceof TextView) | 224 if (v instanceof TextView) |
| 215 { | 225 { |
| 216 ((TextView) v).setTypeface(t); | 226 ((TextView) v).setTypeface(t); |
| 217 } | 227 } |
| 218 else if (v instanceof Button) | 228 else if (v instanceof Button) |
| 219 { | 229 { |
| 220 ((Button) v).setTypeface(t); | 230 ((Button) v).setTypeface(t); |
| 221 } | 231 } |
| 222 } | 232 } |
| 223 } | 233 } |
| 224 } | 234 } |
| 225 } | 235 } |
| 226 | 236 |
| 227 private void setButtonText(final View view, final int viewId, final int resId) | 237 private void setButtonText(final View view, final int viewId, final int resId) |
| 228 { | 238 { |
| 229 final Button button = (Button) view.findViewById(viewId); | 239 final Button button = (Button) view.findViewById(viewId); |
| 230 button.setText(this.getString(resId)); | 240 button.setText(this.getString(resId)); |
| 231 } | 241 } |
| 232 } | 242 } |
| OLD | NEW |