| 1 | package net.mandaria.tippytipper.activities; |
| 2 | |
| 3 | import java.util.HashMap; |
| 4 | import java.util.Map; |
| 5 | |
| 6 | import com.flurry.android.FlurryAgent; |
| 7 | |
| 8 | import net.mandaria.tippytipper.R; |
| 9 | import net.mandaria.tippytipper.TippyTipperApplication; |
| 10 | import android.app.Activity; |
| 11 | import android.content.Intent; |
| 12 | import android.os.Bundle; |
| 13 | import android.view.View; |
| 14 | import android.view.View.OnClickListener; |
| 15 | import android.widget.EditText; |
| 16 | import android.view.Menu; |
| 17 | import android.view.MenuInflater; |
| 18 | import android.view.MenuItem; |
| 19 | import android.view.View.OnLongClickListener; |
| 20 | |
| 21 | public class TippyTipper extends Activity { |
| 22 | |
| 23 | /** Called when the activity is first created. */ |
| 24 | @Override |
| 25 | public void onCreate(Bundle savedInstanceState) { |
| 26 | super.onCreate(savedInstanceState); |
| 27 | setContentView(R.layout.main); |
| 28 | |
| 29 | bindData(); |
| 30 | |
| 31 | // Setup click listeners for buttons |
| 32 | View btn_one = findViewById(R.id.btn_one); |
| 33 | btn_one.setOnClickListener(new OnClickListener() |
| 34 | { |
| 35 | public void onClick(View v) |
| 36 | { |
| 37 | addBillAmount("1"); |
| 38 | FlurryAgent.onEvent("1 Button"); |
| 39 | } |
| 40 | }); |
| 41 | View btn_two = findViewById(R.id.btn_two); |
| 42 | btn_two.setOnClickListener(new OnClickListener() |
| 43 | { |
| 44 | public void onClick(View v) |
| 45 | { |
| 46 | addBillAmount("2"); |
| 47 | FlurryAgent.onEvent("2 Button"); |
| 48 | } |
| 49 | }); |
| 50 | View btn_three = findViewById(R.id.btn_three); |
| 51 | btn_three.setOnClickListener(new OnClickListener() |
| 52 | { |
| 53 | public void onClick(View v) |
| 54 | { |
| 55 | addBillAmount("3"); |
| 56 | FlurryAgent.onEvent("3 Button"); |
| 57 | } |
| 58 | }); |
| 59 | View btn_four = findViewById(R.id.btn_four); |
| 60 | btn_four.setOnClickListener(new OnClickListener() |
| 61 | { |
| 62 | public void onClick(View v) |
| 63 | { |
| 64 | addBillAmount("4"); |
| 65 | FlurryAgent.onEvent("4 Button"); |
| 66 | } |
| 67 | }); |
| 68 | View btn_five = findViewById(R.id.btn_five); |
| 69 | btn_five.setOnClickListener(new OnClickListener() |
| 70 | { |
| 71 | public void onClick(View v) |
| 72 | { |
| 73 | addBillAmount("5"); |
| 74 | FlurryAgent.onEvent("5 Button"); |
| 75 | } |
| 76 | }); |
| 77 | View btn_six = findViewById(R.id.btn_six); |
| 78 | btn_six.setOnClickListener(new OnClickListener() |
| 79 | { |
| 80 | public void onClick(View v) |
| 81 | { |
| 82 | addBillAmount("6"); |
| 83 | FlurryAgent.onEvent("6 Button"); |
| 84 | } |
| 85 | }); |
| 86 | View btn_seven = findViewById(R.id.btn_seven); |
| 87 | btn_seven.setOnClickListener(new OnClickListener() |
| 88 | { |
| 89 | public void onClick(View v) |
| 90 | { |
| 91 | addBillAmount("7"); |
| 92 | FlurryAgent.onEvent("7 Button"); |
| 93 | } |
| 94 | }); |
| 95 | View btn_eight = findViewById(R.id.btn_eight); |
| 96 | btn_eight.setOnClickListener(new OnClickListener() |
| 97 | { |
| 98 | public void onClick(View v) |
| 99 | { |
| 100 | addBillAmount("8"); |
| 101 | FlurryAgent.onEvent("8 Button"); |
| 102 | } |
| 103 | }); |
| 104 | View btn_nine = findViewById(R.id.btn_nine); |
| 105 | btn_nine.setOnClickListener(new OnClickListener() |
| 106 | { |
| 107 | public void onClick(View v) |
| 108 | { |
| 109 | addBillAmount("9"); |
| 110 | FlurryAgent.onEvent("9 Button"); |
| 111 | } |
| 112 | }); |
| 113 | View btn_zero = findViewById(R.id.btn_zero); |
| 114 | btn_zero.setOnClickListener(new OnClickListener() |
| 115 | { |
| 116 | public void onClick(View v) |
| 117 | { |
| 118 | addBillAmount("0"); |
| 119 | FlurryAgent.onEvent("0 Button"); |
| 120 | } |
| 121 | }); |
| 122 | View btn_delete = findViewById(R.id.btn_delete); |
| 123 | btn_delete.setOnClickListener(new OnClickListener() |
| 124 | { |
| 125 | public void onClick(View v) |
| 126 | { |
| 127 | removeBillAmount(); |
| 128 | FlurryAgent.onEvent("Delete Button"); |
| 129 | } |
| 130 | }); |
| 131 | |
| 132 | btn_delete.setOnLongClickListener(new OnLongClickListener() |
| 133 | { |
| 134 | public boolean onLongClick(View v) |
| 135 | { |
| 136 | clearBillAmount(); |
| 137 | return true; |
| 138 | } |
| 139 | }); |
| 140 | |
| 141 | // Added Clear Button -- Maintained the Long-Click Delete -- SPDJR |
| 142 | View btn_clear = findViewById(R.id.btn_clear); |
| 143 | btn_clear.setOnClickListener(new OnClickListener() |
| 144 | { |
| 145 | public void onClick(View v) |
| 146 | { |
| 147 | clearBillAmount(); |
| 148 | FlurryAgent.onEvent("Clear Button"); |
| 149 | } |
| 150 | }); |
| 151 | |
| 152 | btn_clear.setOnLongClickListener(new OnLongClickListener() |
| 153 | { |
| 154 | public boolean onLongClick(View v) |
| 155 | { |
| 156 | clearBillAmount(); |
| 157 | return true; |
| 158 | } |
| 159 | }); |
| 160 | |
| 161 | |
| 162 | // Drawable d_delete = findViewById(R.id.btn_delete).getBackground(); |
| 163 | // int red = Color.parseColor("#8E1609"); |
| 164 | // PorterDuffColorFilter filter_red = new PorterDuffColorFilter(red, PorterDuff.Mode.SRC_ATOP); |
| 165 | // d_delete.setColorFilter(filter_red); |
| 166 | |
| 167 | View btn_ok = findViewById(R.id.btn_ok); |
| 168 | btn_ok.setOnClickListener(new OnClickListener() |
| 169 | { |
| 170 | public void onClick(View v) |
| 171 | { |
| 172 | calcualteTipWithDefaultTipPercentage(); |
| 173 | |
| 174 | Intent i = new Intent(getBaseContext(), Total.class);//new Intent(this, Total.class); |
| 175 | startActivity(i); |
| 176 | } |
| 177 | }); |
| 178 | // Drawable d_ok = findViewById(R.id.btn_ok).getBackground(); |
| 179 | // int green = Color.parseColor("#216C2A"); |
| 180 | // PorterDuffColorFilter filter_green = new PorterDuffColorFilter(green, PorterDuff.Mode.SRC_ATOP); |
| 181 | // d_ok.setColorFilter(filter_green); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public void onStart() |
| 186 | { |
| 187 | super.onStart(); |
| 188 | boolean enableErrorLogging = Settings.getEnableErrorLogging(getBaseContext()); |
| 189 | String API = getString(R.string.flurrykey); |
| 190 | if(!API.equals("") && enableErrorLogging == true) |
| 191 | { |
| 192 | FlurryAgent.setContinueSessionMillis(30000); |
| 193 | FlurryAgent.onStartSession(this, API); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public void onStop() |
| 199 | { |
| 200 | super.onStop(); |
| 201 | |
| 202 | FlurryAgent.onEndSession(this); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onDestroy() |
| 207 | { |
| 208 | super.onDestroy(); |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public boolean onCreateOptionsMenu(Menu menu) |
| 213 | { |
| 214 | super.onCreateOptionsMenu(menu); |
| 215 | MenuInflater inflater = getMenuInflater(); |
| 216 | inflater.inflate(R.menu.menu, menu); |
| 217 | FlurryAgent.onEvent("Menu Button"); |
| 218 | return true; |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public boolean onOptionsItemSelected(MenuItem item) |
| 223 | { |
| 224 | switch(item.getItemId()) |
| 225 | { |
| 226 | case R.id.settings: |
| 227 | startActivity(new Intent(this, Settings.class)); |
| 228 | FlurryAgent.onEvent("Settings Button"); |
| 229 | return true; |
| 230 | case R.id.about: |
| 231 | startActivity(new Intent(this, About.class)); |
| 232 | FlurryAgent.onEvent("About Button"); |
| 233 | return true; |
| 234 | } |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | private void calcualteTipWithDefaultTipPercentage() |
| 239 | { |
| 240 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 241 | double defaultTipPercentage = Settings.getDefaultTipPercentage(getBaseContext()); |
| 242 | float excludeTaxRate = Settings.getExcludeTaxRate(getBaseContext()); |
| 243 | boolean enableExcludeTaxRate = Settings.getEnableExcludeTaxRate(getBaseContext()); |
| 244 | if(enableExcludeTaxRate == false) |
| 245 | excludeTaxRate = 0; |
| 246 | |
| 247 | Map<String, String> params = new HashMap<String, String>(); |
| 248 | params.put("Default Tip Percentage", String.valueOf(defaultTipPercentage)); |
| 249 | params.put("Exclude Tax Rate", String.valueOf(excludeTaxRate)); |
| 250 | params.put("Bill Amount", appState.service.getBillAmount()); |
| 251 | FlurryAgent.onEvent("OK Button", params); |
| 252 | |
| 253 | appState.service.calculateTip(defaultTipPercentage/100.0, excludeTaxRate/100.0); |
| 254 | } |
| 255 | |
| 256 | private void addBillAmount(String number) |
| 257 | { |
| 258 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 259 | appState.service.appendNumberToBillAmount(number); |
| 260 | |
| 261 | bindData(); |
| 262 | } |
| 263 | |
| 264 | private void removeBillAmount() |
| 265 | { |
| 266 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 267 | appState.service.removeEndNumberFromBillAmount(); |
| 268 | |
| 269 | bindData(); |
| 270 | } |
| 271 | |
| 272 | private void clearBillAmount() |
| 273 | { |
| 274 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 275 | appState.service.clearBillAmount(); |
| 276 | |
| 277 | bindData(); |
| 278 | } |
| 279 | |
| 280 | private void bindData() |
| 281 | { |
| 282 | TippyTipperApplication appState = ((TippyTipperApplication)this.getApplication()); |
| 283 | |
| 284 | EditText txt_amount = (EditText)findViewById(R.id.txt_amount); |
| 285 | txt_amount.setText(appState.service.getBillAmount()); |
| 286 | } |
| 287 | |
| 288 | } |