If you think the Android project sthlmtraveling listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2009-2014 Johan Nilsson <http://markupartist.com>
*//fromwww.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.markupartist.sthlmtraveling.ui.view;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.Toast;
import com.flurry.android.FlurryAgent;
import com.markupartist.sthlmtraveling.R;
import com.markupartist.sthlmtraveling.utils.Analytics;
import com.markupartist.sthlmtraveling.utils.IntentUtil;
/**
* Dialog that shows options when buying a SMS ticket.
* <p/>
* To be refactored to a DialogFragment when we've modernized the app.
*/publicclass SmsTicketDialog {
publicstatic Dialog createDialog(final Context context, final String tariffZones) {
Analytics.getInstance(context).event("Ticket", "Open Dialog");
CharSequence[] smsOptions = {
context.getText(R.string.sms_ticket_price_full) + " " + getFullPrice(tariffZones),
context.getText(R.string.sms_ticket_price_reduced) + " " + getReducedPrice(tariffZones)
};
returnnew AlertDialog.Builder(context)
.setTitle(String.format("%s (%s)", context.getText(R.string.sms_ticket_label), tariffZones))
.setItems(smsOptions, new DialogInterface.OnClickListener() {
publicvoid onClick(DialogInterface dialog, int item) {
switch (item) {
case 0:
sendSms(context, false, tariffZones);
break;
case 1:
sendSms(context, true, tariffZones);
break;
}
}
}).create();
}
privatestatic CharSequence getFullPrice(final String tariffZones) {
finalint[] PRICE = newint[]{ 36, 54, 72 };
return PRICE[tariffZones.length() - 1] + " kr";
}
privatestatic CharSequence getReducedPrice(final String tariffZones) {
finalint[] PRICE = newint[]{ 20, 30, 40 };
return PRICE[tariffZones.length() - 1] + " kr";
}
/**
* Invokes the Messaging application.
*
* @param reducedPrice True if the price is reduced, false otherwise.
*/privatestaticvoid sendSms(final Context context, finalboolean reducedPrice, final String tariffZones) {
FlurryAgent.onEvent("Buy SMS Ticket");
Toast.makeText(context, R.string.sms_ticket_notice_message, Toast.LENGTH_LONG).show();
String price = reducedPrice ? "R" : "H";
Analytics.getInstance(context).event("Ticket", "Buy SMS Ticket", price);
String number = "0767201010";
IntentUtil.smsIntent(context, number, price + tariffZones);
}
}