Left: | ||
Right: |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.browser; | 18 package org.adblockplus.browser; |
19 | 19 |
20 import java.io.BufferedReader; | |
21 import java.io.InputStreamReader; | |
22 | |
23 import org.mozilla.gecko.R; | 20 import org.mozilla.gecko.R; |
24 | 21 |
25 import android.content.Context; | 22 import android.content.Context; |
26 import android.content.DialogInterface; | 23 import android.content.DialogInterface; |
27 import android.content.DialogInterface.OnKeyListener; | 24 import android.content.DialogInterface.OnKeyListener; |
28 import android.os.Bundle; | 25 import android.os.Bundle; |
29 import android.support.v4.app.DialogFragment; | 26 import android.support.v4.app.DialogFragment; |
30 import android.text.Html; | 27 import android.text.Html; |
31 import android.util.Log; | |
32 import android.view.KeyEvent; | 28 import android.view.KeyEvent; |
33 import android.view.LayoutInflater; | 29 import android.view.LayoutInflater; |
34 import android.view.View; | 30 import android.view.View; |
35 import android.view.View.OnClickListener; | 31 import android.view.View.OnClickListener; |
36 import android.view.ViewGroup; | 32 import android.view.ViewGroup; |
37 import android.view.ViewGroup.LayoutParams; | 33 import android.view.ViewGroup.LayoutParams; |
38 import android.view.Window; | 34 import android.view.Window; |
39 import android.widget.Button; | 35 import android.widget.Button; |
40 import android.widget.LinearLayout; | 36 import android.widget.LinearLayout; |
41 import android.widget.TextView; | 37 import android.widget.TextView; |
42 | 38 |
43 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener | 39 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener |
44 { | 40 { |
45 private static final String TAG = "AdblockBrowser.StartPane"; | 41 private static final String TAG = "AdblockBrowser.StartPane"; |
46 private int currentStep = 1; | 42 private int currentStep = 1; |
43 private static final int MAXIMUM_STEPS = 3; | |
Felix Dahlke
2015/05/06 07:49:37
Nit: NUM_STEPS or something rather? We always have
René Jeschke
2015/05/06 10:41:56
Done.
| |
47 | 44 |
48 @Override | 45 @Override |
49 public void onCreate(Bundle savedInstanceState) | 46 public void onCreate(Bundle savedInstanceState) |
50 { | 47 { |
51 super.onCreate(savedInstanceState); | 48 super.onCreate(savedInstanceState); |
52 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0); | 49 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0); |
53 } | 50 } |
54 | 51 |
55 @Override | 52 @Override |
56 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) | 53 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) |
(...skipping 14 matching lines...) Expand all Loading... | |
71 { | 68 { |
72 super.onActivityCreated(savedInstanceState); | 69 super.onActivityCreated(savedInstanceState); |
73 final Window window = getDialog().getWindow(); | 70 final Window window = getDialog().getWindow(); |
74 window.setBackgroundDrawable(null); | 71 window.setBackgroundDrawable(null); |
75 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | 72 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
76 } | 73 } |
77 | 74 |
78 @Override | 75 @Override |
79 public void onClick(View v) | 76 public void onClick(View v) |
80 { | 77 { |
81 if (this.currentStep < 2) | 78 if (this.currentStep < MAXIMUM_STEPS) |
82 { | 79 { |
83 this.currentStep++; | 80 this.currentStep++; |
84 this.updateContents(this.getView()); | 81 this.updateContents(this.getView()); |
85 } | 82 } |
86 else | 83 else |
87 { | 84 { |
88 this.dismissAllowingStateLoss(); | 85 this.dismissAllowingStateLoss(); |
89 } | 86 } |
90 } | 87 } |
91 | 88 |
92 @Override | 89 @Override |
93 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) | 90 public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) |
94 { | 91 { |
95 if (keyCode == KeyEvent.KEYCODE_BACK) | 92 if (keyCode == KeyEvent.KEYCODE_BACK) |
96 { | 93 { |
97 if (this.currentStep > 1) | 94 if (event.getAction() == KeyEvent.ACTION_DOWN && this.currentStep > 1) |
98 { | 95 { |
99 this.currentStep--; | 96 this.currentStep--; |
100 this.updateContents(this.getView()); | 97 this.updateContents(this.getView()); |
101 } | 98 } |
102 return true; | 99 return true; |
103 } | 100 } |
104 return false; | 101 return false; |
105 } | 102 } |
106 | 103 |
107 private void updateContents(final View view) | 104 private void updateContents(final View view) |
108 { | 105 { |
109 switch (this.currentStep) | |
110 { | |
111 default: | |
112 case 1: | |
113 this.createStepOneContents(view); | |
114 break; | |
115 case 2: | |
116 this.createStepTwoContents(view); | |
117 break; | |
118 } | |
119 } | |
120 | |
121 private void createStepOneContents(final View view) | |
122 { | |
123 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt); | 106 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt); |
124 ll.removeAllViews(); | 107 ll.removeAllViews(); |
125 | 108 |
126 final LayoutInflater inflater = (LayoutInflater) this.getActivity() | 109 final LayoutInflater inflater = (LayoutInflater) this.getActivity() |
127 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | 110 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
128 inflater.inflate(R.layout.abb_start_pane_step_one, ll, true); | 111 inflater.inflate( |
112 this.getResources().getIdentifier("abb_start_pane_step_" + this.currentS tep, | |
113 "layout", | |
114 this.getActivity().getPackageName()), ll, true); | |
129 | 115 |
130 setTextViewTextHtml(view, R.id.abb_frp_main_text, | 116 this.setButtonText(view, R.id.abb_frp_button, |
131 this.readRawTextFile(R.raw.abb_frp_acceptable_ads)); | 117 this.getResources().getIdentifier("abb_frp_button_" + this.currentStep, |
132 | 118 "string", |
133 this.setButtonText(view, R.id.abb_frp_button, R.string.abb_frp_button_next); | 119 this.getActivity().getPackageName())); |
134 } | |
135 | |
136 private void createStepTwoContents(final View view) | |
137 { | |
138 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt); | |
139 ll.removeAllViews(); | |
140 | |
141 final LayoutInflater inflater = (LayoutInflater) this.getActivity() | |
142 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
143 inflater.inflate(R.layout.abb_start_pane_step_two, ll, true); | |
144 | |
145 setTextViewTextHtml(view, R.id.abb_frp_main_text, | |
146 this.readRawTextFile(R.raw.abb_frp_bug_reports)); | |
147 | |
148 this.setButtonText(view, R.id.abb_frp_button, R.string.abb_frp_button_finish ); | |
149 } | 120 } |
150 | 121 |
151 private void setTextViewTextHtml(final View view, final int viewId, final Stri ng text) | 122 private void setTextViewTextHtml(final View view, final int viewId, final Stri ng text) |
152 { | 123 { |
153 final TextView tv = (TextView) view.findViewById(viewId); | 124 final TextView tv = (TextView) view.findViewById(viewId); |
154 tv.setText(Html.fromHtml(text)); | 125 tv.setText(Html.fromHtml(text)); |
155 } | 126 } |
156 | 127 |
157 private void setButtonText(final View view, final int viewId, final int resId) | 128 private void setButtonText(final View view, final int viewId, final int resId) |
158 { | 129 { |
159 final Button button = (Button) view.findViewById(viewId); | 130 final Button button = (Button) view.findViewById(viewId); |
160 button.setText(this.getString(resId)); | 131 button.setText(this.getString(resId)); |
161 } | 132 } |
162 | |
163 private String readRawTextFile(final int id) | |
164 { | |
165 final StringBuilder text = new StringBuilder(); | |
166 try | |
167 { | |
168 final BufferedReader buf = new BufferedReader(new InputStreamReader(this.g etResources() | |
169 .openRawResource(id))); | |
170 | |
171 try | |
172 { | |
173 String line; | |
174 while ((line = buf.readLine()) != null) | |
175 { | |
176 text.append(line); | |
177 text.append('\n'); | |
178 } | |
179 } | |
180 finally | |
181 { | |
182 buf.close(); | |
183 } | |
184 } | |
185 catch (final Exception e) | |
186 { | |
187 Log.e(TAG, "Failed loading raw resource " + id + ": " + e.getMessage(), e) ; | |
188 } | |
189 return text.toString(); | |
190 } | |
191 } | 133 } |
192 | |
OLD | NEW |