ads
This commit is contained in:
		@@ -3,8 +3,8 @@
 | 
			
		||||
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
		  package="org.solovyev.android.calculator"
 | 
			
		||||
		  a:installLocation="auto"
 | 
			
		||||
		  a:versionCode="23"
 | 
			
		||||
		  a:versionName="1.2.23">
 | 
			
		||||
		  a:versionCode="24"
 | 
			
		||||
		  a:versionName="1.2.24">
 | 
			
		||||
 | 
			
		||||
	<uses-permission a:name="android.permission.VIBRATE"/>
 | 
			
		||||
	<uses-permission a:name="android.permission.INTERNET"/>
 | 
			
		||||
@@ -16,7 +16,7 @@
 | 
			
		||||
 | 
			
		||||
	<application a:icon="@drawable/icon"
 | 
			
		||||
				 a:label="@string/c_app_name"
 | 
			
		||||
				 a:name=".ApplicationContext">
 | 
			
		||||
				 a:name=".CalculatorApplication">
 | 
			
		||||
 | 
			
		||||
		<activity a:name=".CalculatorActivity"
 | 
			
		||||
				  a:windowSoftInputMode="adjustPan"
 | 
			
		||||
@@ -33,7 +33,7 @@
 | 
			
		||||
				  a:label="@string/c_app_settings"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
		<activity a:name=".history.CalculatorHistoryActivity"
 | 
			
		||||
		<activity a:name=".history.CalculatorHistoryTabActivity"
 | 
			
		||||
				  a:label="@string/c_app_history"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
@@ -73,11 +73,11 @@
 | 
			
		||||
				  a:label="@string/c_help"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
        <activity a:name=".math.edit.CalculatorFunctionsActivity"
 | 
			
		||||
        <activity a:name=".math.edit.CalculatorFunctionsTabActivity"
 | 
			
		||||
                  a:label="@string/c_functions"
 | 
			
		||||
                  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
		<activity a:name=".math.edit.CalculatorFunctionsTabActivity"
 | 
			
		||||
		<activity a:name=".math.edit.CalculatorFunctionsActivity"
 | 
			
		||||
				  a:label="@string/c_functions"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
@@ -85,18 +85,18 @@
 | 
			
		||||
				  a:label="@string/c_operators"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
        <activity a:name=".math.edit.CalculatorVarsActivity"
 | 
			
		||||
        <activity a:name=".math.edit.CalculatorVarsTabActivity"
 | 
			
		||||
                  a:label="@string/c_vars_and_constants"
 | 
			
		||||
                  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
		<activity a:name=".math.edit.CalculatorVarsTabActivity"
 | 
			
		||||
		<activity a:name=".math.edit.CalculatorVarsActivity"
 | 
			
		||||
				  a:label="@string/c_vars_and_constants"
 | 
			
		||||
				  a:configChanges="orientation|keyboardHidden"/>
 | 
			
		||||
 | 
			
		||||
		<activity a:name=".CalculatorPlotActivity"
 | 
			
		||||
				  a:label="@string/c_plot_graph"/>
 | 
			
		||||
 | 
			
		||||
<!--		<activity a:name="com.google.ads.AdActivity"
 | 
			
		||||
		<activity a:name="com.google.ads.AdActivity"
 | 
			
		||||
				  a:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
 | 
			
		||||
 | 
			
		||||
		<service a:name="net.robotmedia.billing.BillingService"/>
 | 
			
		||||
@@ -106,7 +106,7 @@
 | 
			
		||||
				<action a:name="com.android.vending.billing.RESPONSE_CODE"/>
 | 
			
		||||
				<action a:name="com.android.vending.billing.PURCHASE_STATE_CHANGED"/>
 | 
			
		||||
			</intent-filter>
 | 
			
		||||
		</receiver>-->
 | 
			
		||||
		</receiver>
 | 
			
		||||
 | 
			
		||||
	</application>
 | 
			
		||||
</manifest>
 | 
			
		||||
@@ -1,30 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
 | 
			
		||||
<!--
 | 
			
		||||
  ~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
 | 
			
		||||
  ~ For more information, please, contact se.solovyev@gmail.com
 | 
			
		||||
  ~ or visit http://se.solovyev.org
 | 
			
		||||
  -->
 | 
			
		||||
 | 
			
		||||
<TabHost xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
		 a:id="@android:id/tabhost"
 | 
			
		||||
		 a:layout_width="fill_parent"
 | 
			
		||||
		 a:layout_height="fill_parent">
 | 
			
		||||
 | 
			
		||||
	<LinearLayout
 | 
			
		||||
			a:orientation="vertical"
 | 
			
		||||
			a:layout_width="fill_parent"
 | 
			
		||||
			a:layout_height="fill_parent">
 | 
			
		||||
 | 
			
		||||
		<TabWidget
 | 
			
		||||
				a:id="@android:id/tabs"
 | 
			
		||||
				a:layout_width="fill_parent"
 | 
			
		||||
				a:layout_height="wrap_content"/>
 | 
			
		||||
 | 
			
		||||
		<FrameLayout
 | 
			
		||||
				a:id="@android:id/tabcontent"
 | 
			
		||||
				a:layout_width="fill_parent"
 | 
			
		||||
				a:layout_height="fill_parent"/>
 | 
			
		||||
 | 
			
		||||
	</LinearLayout>
 | 
			
		||||
</TabHost>
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
  -->
 | 
			
		||||
 | 
			
		||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
	a:id="@+id/ad_parent_view"
 | 
			
		||||
    a:orientation="vertical"
 | 
			
		||||
    a:layout_width="fill_parent"
 | 
			
		||||
    a:layout_height="fill_parent">
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
 | 
			
		||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    a:orientation="vertical"
 | 
			
		||||
	a:id="@+id/ad_parent_view"
 | 
			
		||||
    a:layout_width="fill_parent"
 | 
			
		||||
    a:layout_height="fill_parent">
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,7 @@
 | 
			
		||||
 | 
			
		||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    a:orientation="vertical"
 | 
			
		||||
	a:id="@+id/ad_parent_view"
 | 
			
		||||
    a:layout_width="fill_parent"
 | 
			
		||||
    a:layout_height="fill_parent">
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -167,4 +167,6 @@
 | 
			
		||||
	<string name="c_error">Ошибка</string>
 | 
			
		||||
	<string name="c_billing_error">Биллинг не поддерживается!</string>
 | 
			
		||||
 | 
			
		||||
	<string name="c_calc_ad_free_title">Избавиться от рекламы!</string>
 | 
			
		||||
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -167,4 +167,6 @@
 | 
			
		||||
	<string name="c_error">Error</string>
 | 
			
		||||
	<string name="c_billing_error">Billing is not supported!</string>
 | 
			
		||||
 | 
			
		||||
	<string name="c_calc_ad_free_title">Get rid of ads!</string>
 | 
			
		||||
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -3,12 +3,11 @@
 | 
			
		||||
<PreferenceScreen xmlns:a="http://schemas.android.com/apk/res/android"
 | 
			
		||||
				  xmlns:range="http://schemas.android.com/apk/res/org.solovyev.android.calculator">
 | 
			
		||||
 | 
			
		||||
<!--	<SwitchPreference
 | 
			
		||||
			a:key="@string/p_calc_round_result_key"
 | 
			
		||||
			a:summary="@string/c_calc_round_result_summary"
 | 
			
		||||
			a:title="@string/c_calc_round_result_title"
 | 
			
		||||
	<Preference
 | 
			
		||||
			a:key="@string/p_calc_ad_free_key"
 | 
			
		||||
			a:title="@string/c_calc_ad_free_title"
 | 
			
		||||
			a:defaultValue="false"
 | 
			
		||||
		/>-->
 | 
			
		||||
		/>
 | 
			
		||||
 | 
			
		||||
	<PreferenceCategory a:title="@string/c_prefs_calculations_category">
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,8 @@ import com.google.ads.AdSize;
 | 
			
		||||
import com.google.ads.AdView;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 12/21/11
 | 
			
		||||
@@ -92,7 +94,10 @@ public final class AndroidUtils {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	public static AdView createAndInflateAdView(@NotNull Activity activity, int layoutId, String admobAccountId) {
 | 
			
		||||
	public static AdView createAndInflateAdView(@NotNull Activity activity,
 | 
			
		||||
												@NotNull String admobAccountId,
 | 
			
		||||
												int layoutId,
 | 
			
		||||
												@NotNull List<String> keywords) {
 | 
			
		||||
		// Create the adView
 | 
			
		||||
		final AdView adView = new AdView(activity, AdSize.BANNER, admobAccountId);
 | 
			
		||||
 | 
			
		||||
@@ -104,7 +109,16 @@ public final class AndroidUtils {
 | 
			
		||||
		layout.addView(adView);
 | 
			
		||||
 | 
			
		||||
		// Initiate a generic request to load it with an ad
 | 
			
		||||
		adView.loadAd(new AdRequest());
 | 
			
		||||
		final AdRequest adRequest = new AdRequest();
 | 
			
		||||
 | 
			
		||||
		// todo serso: revert - only for tests
 | 
			
		||||
		adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
 | 
			
		||||
		adRequest.addTestDevice("DB3C2F605A1296971898F0E60224A927");
 | 
			
		||||
 | 
			
		||||
		for (String keyword : keywords) {
 | 
			
		||||
			adRequest.addKeyword(keyword);
 | 
			
		||||
		}
 | 
			
		||||
		adView.loadAd(adRequest);
 | 
			
		||||
 | 
			
		||||
		return adView;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,44 +0,0 @@
 | 
			
		||||
package org.solovyev.android.calculator;
 | 
			
		||||
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 12/1/11
 | 
			
		||||
 * Time: 1:21 PM
 | 
			
		||||
 */
 | 
			
		||||
public class ApplicationContext extends android.app.Application {
 | 
			
		||||
 | 
			
		||||
	public static final String AD_FREE = "ad_free";
 | 
			
		||||
	public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	private static ApplicationContext instance;
 | 
			
		||||
 | 
			
		||||
	public ApplicationContext() {
 | 
			
		||||
		instance = this;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	public static ApplicationContext getInstance() {
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate() {
 | 
			
		||||
		super.onCreate();
 | 
			
		||||
		/*BillingController.setDebug(true);
 | 
			
		||||
		BillingController.setConfiguration(new BillingController.IConfiguration() {
 | 
			
		||||
 | 
			
		||||
			@Override
 | 
			
		||||
			public byte[] getObfuscationSalt() {
 | 
			
		||||
				return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			@Override
 | 
			
		||||
			public String getPublicKey() {
 | 
			
		||||
				return "org.solovyev.android.calculator";
 | 
			
		||||
			}
 | 
			
		||||
		});*/
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -52,7 +52,6 @@ import java.util.Map;
 | 
			
		||||
public class CalculatorActivity extends Activity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
 | 
			
		||||
 | 
			
		||||
	private static final int HVGA_WIDTH_PIXELS = 320;
 | 
			
		||||
	public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
 | 
			
		||||
 | 
			
		||||
	public static class Preferences {
 | 
			
		||||
		@NotNull
 | 
			
		||||
@@ -121,7 +120,7 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		ResourceCache.instance.initCaptions(ApplicationContext.getInstance(), R.string.class);
 | 
			
		||||
		ResourceCache.instance.initCaptions(CalculatorApplication.getInstance(), R.string.class);
 | 
			
		||||
		firstTimeInit(preferences);
 | 
			
		||||
 | 
			
		||||
		vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
 | 
			
		||||
 
 | 
			
		||||
@@ -9,11 +9,11 @@ import org.achartengine.ChartFactory;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.solovyev.android.calculator.about.CalculatorAboutTabActivity;
 | 
			
		||||
import org.solovyev.android.calculator.help.CalculatorHelpTabActivity;
 | 
			
		||||
import org.solovyev.android.calculator.history.CalculatorHistoryActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsActivity;
 | 
			
		||||
import org.solovyev.android.calculator.history.CalculatorHistoryTabActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorOperatorsActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity;
 | 
			
		||||
import org.solovyev.android.calculator.math.edit.CalculatorVarsActivity;
 | 
			
		||||
import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -24,7 +24,7 @@ import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
public class CalculatorActivityLauncher {
 | 
			
		||||
 | 
			
		||||
	public static void showHistory(@NotNull final Context context) {
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorHistoryActivity.class));
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorHistoryTabActivity.class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void showHelp(@NotNull final Context context) {
 | 
			
		||||
@@ -40,7 +40,7 @@ public class CalculatorActivityLauncher {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void showFunctions(@NotNull final Context context) {
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorFunctionsActivity.class));
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorFunctionsTabActivity.class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void showOperators(@NotNull final Context context) {
 | 
			
		||||
@@ -48,7 +48,7 @@ public class CalculatorActivityLauncher {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void showVars(@NotNull final Context context) {
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorVarsActivity.class));
 | 
			
		||||
		context.startActivity(new Intent(context, CalculatorVarsTabActivity.class));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static void plotGraph(@NotNull final Context context, @NotNull Generic generic, @NotNull Constant constant){
 | 
			
		||||
@@ -63,9 +63,9 @@ public class CalculatorActivityLauncher {
 | 
			
		||||
		if (calculatorModel.getDisplay().isValid() ) {
 | 
			
		||||
			final String varValue = calculatorModel.getDisplay().getText().toString();
 | 
			
		||||
			if (!StringUtils.isEmpty(varValue)) {
 | 
			
		||||
				if (CalculatorVarsTabActivity.isValidValue(varValue)) {
 | 
			
		||||
					final Intent intent = new Intent(context, CalculatorVarsActivity.class);
 | 
			
		||||
					intent.putExtra(CalculatorVarsTabActivity.CREATE_VAR_EXTRA_STRING, varValue);
 | 
			
		||||
				if (CalculatorVarsActivity.isValidValue(varValue)) {
 | 
			
		||||
					final Intent intent = new Intent(context, CalculatorVarsTabActivity.class);
 | 
			
		||||
					intent.putExtra(CalculatorVarsActivity.CREATE_VAR_EXTRA_STRING, varValue);
 | 
			
		||||
					context.startActivity(intent);
 | 
			
		||||
				} else {
 | 
			
		||||
					Toast.makeText(context, R.string.c_not_valid_result, Toast.LENGTH_SHORT).show();
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,95 @@
 | 
			
		||||
package org.solovyev.android.calculator;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import com.google.ads.AdView;
 | 
			
		||||
import net.robotmedia.billing.BillingController;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 12/1/11
 | 
			
		||||
 * Time: 1:21 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorApplication extends android.app.Application {
 | 
			
		||||
 | 
			
		||||
	public static final String AD_FREE_PRODUCT_ID = "ad_free";
 | 
			
		||||
	public static final String AD_FREE_P_KEY = "org.solovyev.android.calculator_ad_free";
 | 
			
		||||
 | 
			
		||||
	public static final String ADMOB_USER_ID = "a14f02cf9c80cbc";
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	private static CalculatorApplication instance;
 | 
			
		||||
 | 
			
		||||
	public CalculatorApplication() {
 | 
			
		||||
		instance = this;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	public static CalculatorApplication getInstance() {
 | 
			
		||||
		return instance;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static boolean isAdFreeApprox(@NotNull Context context) {
 | 
			
		||||
		return BillingController.isPurchased(context.getApplicationContext(), AD_FREE_PRODUCT_ID);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static boolean isAdFree(@NotNull Context context) {
 | 
			
		||||
		// check if user already bought this product
 | 
			
		||||
		boolean purchased = isAdFreeApprox(context);
 | 
			
		||||
		if (!purchased) {
 | 
			
		||||
			// we must to restore all transactions done by user to guarantee that product was purchased or not
 | 
			
		||||
			BillingController.restoreTransactions(context);
 | 
			
		||||
 | 
			
		||||
			// todo serso: may be call net.robotmedia.billing.BillingController.restoreTransactions() always before first check and get rid of second check
 | 
			
		||||
			// check the billing one more time
 | 
			
		||||
			purchased = isAdFreeApprox(context);
 | 
			
		||||
		}
 | 
			
		||||
		return purchased;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Nullable
 | 
			
		||||
	public static AdView inflateAd(@NotNull Activity activity) {
 | 
			
		||||
		return inflateAd(activity, R.id.ad_parent_view);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Nullable
 | 
			
		||||
	public static AdView inflateAd(@NotNull Activity activity, int parentViewId) {
 | 
			
		||||
		AdView result = null;
 | 
			
		||||
		if ( !isAdFreeApprox(activity) ) {
 | 
			
		||||
			Log.d(activity.getClass().getName(), "Application is not ad free - inflating ad!");
 | 
			
		||||
			//final List<String> keywords = Arrays.asList("math", "mathematics", "finance", "physics", "dynamics");
 | 
			
		||||
			final List<String> keywords = Collections.emptyList();
 | 
			
		||||
			result = AndroidUtils.createAndInflateAdView(activity, ADMOB_USER_ID, parentViewId, keywords);
 | 
			
		||||
		} else {
 | 
			
		||||
			Log.d(activity.getClass().getName(), "Application is ad free - no ads!");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate() {
 | 
			
		||||
		super.onCreate();
 | 
			
		||||
 | 
			
		||||
		BillingController.setConfiguration(new BillingController.IConfiguration() {
 | 
			
		||||
 | 
			
		||||
			@Override
 | 
			
		||||
			public byte[] getObfuscationSalt() {
 | 
			
		||||
				return new byte[]{81, -114, 32, -127, -32, -104, -40, -15, -47, 57, -13, -41, -33, 67, -114, 7, -11, 53, 126, 82};
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			@Override
 | 
			
		||||
			public String getPublicKey() {
 | 
			
		||||
				return CalculatorSecurity.PK;
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		BillingController.checkBillingSupported(this);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -27,34 +27,25 @@ public class CalculatorPreferencesActivity extends PreferenceActivity implements
 | 
			
		||||
 | 
			
		||||
		addPreferencesFromResource(R.xml.main_preferences);
 | 
			
		||||
 | 
			
		||||
		/*final Preference buyPref = findPreference(ApplicationContext.AD_FREE_APPLICATION_P_KEY);
 | 
			
		||||
		buyPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
 | 
			
		||||
			// при нажатии на кнопку Убрать рекламу в настройках
 | 
			
		||||
		final Preference addFreePreference = findPreference(CalculatorApplication.AD_FREE_P_KEY);
 | 
			
		||||
 | 
			
		||||
		addFreePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
 | 
			
		||||
			public boolean onPreferenceClick(Preference preference) {
 | 
			
		||||
				// проверяем поддерживается ли покупка в приложениях
 | 
			
		||||
 | 
			
		||||
				// check billing availability
 | 
			
		||||
				if (BillingController.checkBillingSupported(CalculatorPreferencesActivity.this) != BillingController.BillingStatus.SUPPORTED) {
 | 
			
		||||
					// показываем сообщение, что покупка не поддерживается
 | 
			
		||||
					// warn about not supported billing
 | 
			
		||||
					new AlertDialog.Builder(CalculatorPreferencesActivity.this).setTitle(R.string.c_error).setMessage(R.string.c_billing_error).create().show();
 | 
			
		||||
				} else {
 | 
			
		||||
					// проверяем не купил ли пользователь уже нашу опцию
 | 
			
		||||
					boolean purchased = BillingController.isPurchased(getApplicationContext(), ApplicationContext.AD_FREE_APPLICATION);
 | 
			
		||||
					if (!purchased) {
 | 
			
		||||
						// если не купил (или мы просто об этом пока не знаем? пользователь удалял
 | 
			
		||||
						// приложение со всем данными?), то пытаемся восстановить транзакции
 | 
			
		||||
						BillingController.restoreTransactions(CalculatorPreferencesActivity.this);
 | 
			
		||||
						// следующая строка (проверка еще раз не купил ли пользователь приложение) -
 | 
			
		||||
						// не очень правильный подход - вызвав restoreTransactions,
 | 
			
		||||
						// ответ мы получим не сразу
 | 
			
		||||
						purchased = BillingController.isPurchased(getApplicationContext(), ApplicationContext.AD_FREE_APPLICATION);
 | 
			
		||||
						if (!purchased) {
 | 
			
		||||
							// наконец, показываем пользователю стандартное окно для покупки опции
 | 
			
		||||
							BillingController.requestPurchase(CalculatorPreferencesActivity.this, ApplicationContext.AD_FREE_APPLICATION);
 | 
			
		||||
						}
 | 
			
		||||
					if (!CalculatorApplication.isAdFree(CalculatorPreferencesActivity.this)) {
 | 
			
		||||
						// not purchased => show purchase window for user
 | 
			
		||||
						BillingController.requestPurchase(CalculatorPreferencesActivity.this, CalculatorApplication.AD_FREE_PRODUCT_ID);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
		});*/
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		final SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
 | 
			
		||||
		preferences.registerOnSharedPreferenceChangeListener(this);
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2009-2012. Created by serso aka se.solovyev.
 | 
			
		||||
 * For more information, please, contact se.solovyev@gmail.com
 | 
			
		||||
 * or visit http://se.solovyev.org
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 1/4/12
 | 
			
		||||
 * Time: 1:23 AM
 | 
			
		||||
 */
 | 
			
		||||
public final class CalculatorSecurity {
 | 
			
		||||
 | 
			
		||||
	public static final String PK = "org.solovyev.android.calculator";
 | 
			
		||||
 | 
			
		||||
	private CalculatorSecurity() {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright (c) 2009-2012. Created by serso aka se.solovyev.
 | 
			
		||||
 * For more information, please, contact se.solovyev@gmail.com
 | 
			
		||||
 * or visit http://se.solovyev.org
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.help;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import com.google.ads.AdView;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorApplication;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 1/4/12
 | 
			
		||||
 * Time: 12:34 AM
 | 
			
		||||
 */
 | 
			
		||||
public class AbstractHelpActivity extends Activity {
 | 
			
		||||
 | 
			
		||||
	private final int layoutId;
 | 
			
		||||
 | 
			
		||||
	@Nullable
 | 
			
		||||
	private AdView adView;
 | 
			
		||||
 | 
			
		||||
	protected AbstractHelpActivity(int layoutId) {
 | 
			
		||||
		this.layoutId = layoutId;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		setContentView(layoutId);
 | 
			
		||||
 | 
			
		||||
		adView = CalculatorApplication.inflateAd(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onDestroy() {
 | 
			
		||||
		if (this.adView != null) {
 | 
			
		||||
			this.adView.destroy();
 | 
			
		||||
		}
 | 
			
		||||
		super.onDestroy();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -27,7 +27,7 @@ public class CalculatorHelpTabActivity extends TabActivity {
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		setContentView(R.layout.help);
 | 
			
		||||
		setContentView(R.layout.tabs);
 | 
			
		||||
 | 
			
		||||
		final TabHost tabHost = getTabHost();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,9 +6,6 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.help;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -16,12 +13,9 @@ import org.solovyev.android.calculator.R;
 | 
			
		||||
 * Date: 11/19/11
 | 
			
		||||
 * Time: 11:37 AM
 | 
			
		||||
 */
 | 
			
		||||
public class HelpFaqActivity extends Activity {
 | 
			
		||||
public class HelpFaqActivity extends AbstractHelpActivity {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		setContentView(R.layout.help_faq);
 | 
			
		||||
	public HelpFaqActivity() {
 | 
			
		||||
		super(R.layout.help_faq);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -6,9 +6,6 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.help;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -16,12 +13,9 @@ import org.solovyev.android.calculator.R;
 | 
			
		||||
 * Date: 11/19/11
 | 
			
		||||
 * Time: 11:37 AM
 | 
			
		||||
 */
 | 
			
		||||
public class HelpHintsActivity extends Activity {
 | 
			
		||||
public class HelpHintsActivity extends AbstractHelpActivity {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
	super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		setContentView(R.layout.help_hints);
 | 
			
		||||
	public HelpHintsActivity() {
 | 
			
		||||
		super(R.layout.help_hints);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -6,9 +6,6 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.help;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -16,12 +13,10 @@ import org.solovyev.android.calculator.R;
 | 
			
		||||
 * Date: 11/19/11
 | 
			
		||||
 * Time: 11:38 AM
 | 
			
		||||
 */
 | 
			
		||||
public class HelpScreensActivity extends Activity {
 | 
			
		||||
public class HelpScreensActivity extends AbstractHelpActivity{
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
	public HelpScreensActivity() {
 | 
			
		||||
		super(R.layout.help_screens);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		setContentView(R.layout.help_screens);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -16,8 +16,10 @@ import android.widget.AdapterView;
 | 
			
		||||
import android.widget.ArrayAdapter;
 | 
			
		||||
import android.widget.EditText;
 | 
			
		||||
import android.widget.ListView;
 | 
			
		||||
import com.google.ads.AdView;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorApplication;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.jscl.JsclOperation;
 | 
			
		||||
@@ -56,12 +58,17 @@ public abstract class AbstractHistoryActivity extends ListActivity {
 | 
			
		||||
	@NotNull
 | 
			
		||||
	private ArrayAdapter<CalculatorHistoryState> adapter;
 | 
			
		||||
 | 
			
		||||
	@Nullable
 | 
			
		||||
	private AdView adView;
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		setContentView(R.layout.history_activity);
 | 
			
		||||
 | 
			
		||||
		adView = CalculatorApplication.inflateAd(this);
 | 
			
		||||
 | 
			
		||||
		adapter = new HistoryArrayAdapter(this, getLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
 | 
			
		||||
		setListAdapter(adapter);
 | 
			
		||||
 | 
			
		||||
@@ -111,6 +118,14 @@ public abstract class AbstractHistoryActivity extends ListActivity {
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onDestroy() {
 | 
			
		||||
		if ( this.adView != null ) {
 | 
			
		||||
			this.adView.destroy();
 | 
			
		||||
		}
 | 
			
		||||
		super.onDestroy();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected abstract int getLayoutId();
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@ import org.solovyev.android.calculator.R;
 | 
			
		||||
 * Date: 12/18/11
 | 
			
		||||
 * Time: 7:37 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorHistoryActivity extends TabActivity {
 | 
			
		||||
public class CalculatorHistoryTabActivity extends TabActivity {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
@@ -35,5 +35,4 @@ public class CalculatorHistoryActivity extends TabActivity {
 | 
			
		||||
 | 
			
		||||
        AndroidUtils.centerAndWrapTabsFor(tabHost);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -15,8 +15,10 @@ import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.view.ViewGroup;
 | 
			
		||||
import android.widget.*;
 | 
			
		||||
import com.google.ads.AdView;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorApplication;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.model.AndroidMathRegistry;
 | 
			
		||||
@@ -50,6 +52,9 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
 | 
			
		||||
    @Nullable
 | 
			
		||||
    private String category;
 | 
			
		||||
 | 
			
		||||
	@Nullable
 | 
			
		||||
	private AdView adView;
 | 
			
		||||
 | 
			
		||||
	static void createTab(@NotNull Context context,
 | 
			
		||||
                          @NotNull TabHost tabHost,
 | 
			
		||||
                          @NotNull String tabId,
 | 
			
		||||
@@ -85,6 +90,8 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
 | 
			
		||||
 | 
			
		||||
        setContentView(getLayoutId());
 | 
			
		||||
 | 
			
		||||
		adView = CalculatorApplication.inflateAd(this);
 | 
			
		||||
 | 
			
		||||
		final Intent intent = getIntent();
 | 
			
		||||
        if ( intent != null ) {
 | 
			
		||||
            category = intent.getStringExtra(MATH_ENTITY_CATEGORY_EXTRA_STRING);
 | 
			
		||||
@@ -122,6 +129,14 @@ public abstract class AbstractMathEntityListActivity<T extends MathEntity> exten
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onDestroy() {
 | 
			
		||||
		if (this.adView != null) {
 | 
			
		||||
			this.adView.destroy();
 | 
			
		||||
		}
 | 
			
		||||
		super.onDestroy();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	protected abstract List<AMenuItem<T>> getMenuItemsOnLongClick(@NotNull T item);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,35 +6,217 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.math.edit;
 | 
			
		||||
 | 
			
		||||
import android.app.TabActivity;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.widget.TabHost;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
import android.text.ClipboardManager;
 | 
			
		||||
import jscl.math.function.Function;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
import org.solovyev.android.calculator.model.CalculatorEngine;
 | 
			
		||||
import org.solovyev.android.view.AMenuItem;
 | 
			
		||||
import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 12/21/11
 | 
			
		||||
 * Time: 10:33 PM
 | 
			
		||||
 * Date: 10/29/11
 | 
			
		||||
 * Time: 4:55 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorFunctionsActivity extends TabActivity {
 | 
			
		||||
public class CalculatorFunctionsActivity extends AbstractMathEntityListActivity<Function> {
 | 
			
		||||
 | 
			
		||||
	private static enum LongClickMenuItem implements AMenuItem<Function>{
 | 
			
		||||
		use(R.string.c_use) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
 | 
			
		||||
				if (context instanceof Activity) {
 | 
			
		||||
					((Activity) context).finish();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		/*edit(R.string.c_edit) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				if (context instanceof AbstractMathEntityListActivity) {
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},*/
 | 
			
		||||
 | 
			
		||||
		copy_description(R.string.c_copy_description) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				final String text = CalculatorEngine.instance.getFunctionsRegistry().getDescription(context, data.getName());
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
		private final int captionId;
 | 
			
		||||
 | 
			
		||||
		LongClickMenuItem(int captionId) {
 | 
			
		||||
			this.captionId = captionId;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@NotNull
 | 
			
		||||
		@Override
 | 
			
		||||
		public String getCaption(@NotNull Context context) {
 | 
			
		||||
			return context.getString(captionId);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
    public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.tabs);
 | 
			
		||||
		/*getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
 | 
			
		||||
				final Function function = (Function) parent.getItemAtPosition(position);
 | 
			
		||||
				if (function instanceof CustomFunction) {
 | 
			
		||||
					createEditVariableDialog(CalculatorFunctionsTabActivity.this,
 | 
			
		||||
							((CustomFunction) function),
 | 
			
		||||
							function.getName(),
 | 
			
		||||
							((CustomFunction) function).getContent(),
 | 
			
		||||
							((CustomFunction) function).getParameterNames(),
 | 
			
		||||
							null);
 | 
			
		||||
				}
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
		});*/
 | 
			
		||||
 | 
			
		||||
        final TabHost tabHost = getTabHost();
 | 
			
		||||
		/*final Intent intent = getIntent();
 | 
			
		||||
		if (intent != null) {
 | 
			
		||||
			final String varValue = intent.getStringExtra(CREATE_FUN_EXTRA_STRING);
 | 
			
		||||
			if (!StringUtils.isEmpty(varValue)) {
 | 
			
		||||
				createEditVariableDialog(this, null, null, varValue, null, null);
 | 
			
		||||
 | 
			
		||||
        for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
 | 
			
		||||
            AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorFunctionsTabActivity.class, null);
 | 
			
		||||
				// in order to stop intent for other tabs
 | 
			
		||||
				intent.removeExtra(CREATE_FUN_EXTRA_STRING);
 | 
			
		||||
			}
 | 
			
		||||
		}*/
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
        AndroidUtils.centerAndWrapTabsFor(tabHost);
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<AMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
 | 
			
		||||
		List<AMenuItem<Function>> result = new ArrayList<AMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
 | 
			
		||||
		
 | 
			
		||||
		if ( StringUtils.isEmpty(CalculatorEngine.instance.getFunctionsRegistry().getDescription(this, item.getName())) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_description);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
/*	private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<Function> activity,
 | 
			
		||||
												 @Nullable final CustomFunction function,
 | 
			
		||||
												 @Nullable final String name,
 | 
			
		||||
												 @Nullable final String expression,
 | 
			
		||||
												 @Nullable final String[] parameterNames,
 | 
			
		||||
												 @Nullable final String description) {
 | 
			
		||||
		if (function == null || !function.isSystem()) {
 | 
			
		||||
 | 
			
		||||
			final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
			final View editView = layoutInflater.inflate(R.layout.var_edit, null);
 | 
			
		||||
 | 
			
		||||
			final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
 | 
			
		||||
 | 
			
		||||
			final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
 | 
			
		||||
			editName.setText(name);
 | 
			
		||||
			editName.addTextChangedListener(new TextWatcher() {
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void onTextChanged(CharSequence s, int start, int before, int count) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void afterTextChanged(Editable s) {
 | 
			
		||||
					for (int i = 0; i < s.length(); i++) {
 | 
			
		||||
						char c = s.charAt(i);
 | 
			
		||||
						if (!acceptableChars.contains(c)) {
 | 
			
		||||
							s.delete(i, i + 1);
 | 
			
		||||
							Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
 | 
			
		||||
			if (!StringUtils.isEmpty(expression)) {
 | 
			
		||||
				editValue.setText(expression);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
 | 
			
		||||
			editDescription.setText(description);
 | 
			
		||||
 | 
			
		||||
			final CustomFunction.Builder functionBuilder;
 | 
			
		||||
			if (function != null) {
 | 
			
		||||
				functionBuilder = new CustomFunction.Builder(function);
 | 
			
		||||
			} else {
 | 
			
		||||
				functionBuilder = new CustomFunction.Builder();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
 | 
			
		||||
					.setCancelable(true)
 | 
			
		||||
					.setNegativeButton(R.string.c_cancel, null)
 | 
			
		||||
					.setPositiveButton(R.string.c_save, new FunctionEditorSaver(functionBuilder, function, editView, activity, CalculatorEngine.instance.getFunctionsRegistry(), new FunctionEditorSaver.EditorCreator<Function>() {
 | 
			
		||||
 | 
			
		||||
						@Override
 | 
			
		||||
						public void showEditor(@NotNull AbstractMathEntityListActivity<Function> activity, @Nullable CustomFunction editedInstance, @Nullable String name, @Nullable String value, @Nullable String[] parameterNames, @Nullable String description) {
 | 
			
		||||
							createEditVariableDialog(activity, editedInstance, name, value, parameterNames, description);
 | 
			
		||||
						}
 | 
			
		||||
					}))
 | 
			
		||||
					.setView(editView);
 | 
			
		||||
 | 
			
		||||
			if (function != null) {
 | 
			
		||||
				// EDIT mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_edit_var);
 | 
			
		||||
				builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<Function>(function, new DialogInterface.OnClickListener() {
 | 
			
		||||
					@Override
 | 
			
		||||
					public void onClick(DialogInterface dialog, int which) {
 | 
			
		||||
						createEditVariableDialog(activity, function, name, expression, parameterNames, description);
 | 
			
		||||
					}
 | 
			
		||||
				}, CalculatorEngine.instance.getFunctionsRegistry(), activity));
 | 
			
		||||
			} else {
 | 
			
		||||
				// CREATE mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_create_var);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			builder.create().show();
 | 
			
		||||
		} else {
 | 
			
		||||
			Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
 | 
			
		||||
		}
 | 
			
		||||
	}*/
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected MathEntityDescriptionGetter getDescriptionGetter() {
 | 
			
		||||
		return new MathEntityDescriptionGetterImpl(CalculatorEngine.instance.getFunctionsRegistry());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<Function> getMathEntities() {
 | 
			
		||||
		return new ArrayList<Function>(CalculatorEngine.instance.getFunctionsRegistry().getEntities());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected String getMathEntityCategory(@NotNull Function function) {
 | 
			
		||||
		return CalculatorEngine.instance.getFunctionsRegistry().getCategory(function);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,217 +6,34 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.math.edit;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.app.TabActivity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.text.ClipboardManager;
 | 
			
		||||
import jscl.math.function.Function;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import android.widget.TabHost;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.model.CalculatorEngine;
 | 
			
		||||
import org.solovyev.android.view.AMenuItem;
 | 
			
		||||
import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import org.solovyev.android.calculator.model.AndroidFunctionsMathRegistry;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 10/29/11
 | 
			
		||||
 * Time: 4:55 PM
 | 
			
		||||
 * Date: 12/21/11
 | 
			
		||||
 * Time: 10:33 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorFunctionsTabActivity extends AbstractMathEntityListActivity<Function> {
 | 
			
		||||
 | 
			
		||||
	private static enum LongClickMenuItem implements AMenuItem<Function>{
 | 
			
		||||
		use(R.string.c_use) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
 | 
			
		||||
				if (context instanceof Activity) {
 | 
			
		||||
					((Activity) context).finish();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		/*edit(R.string.c_edit) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				if (context instanceof AbstractMathEntityListActivity) {
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},*/
 | 
			
		||||
 | 
			
		||||
		copy_description(R.string.c_copy_description) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull Function data, @NotNull Context context) {
 | 
			
		||||
				final String text = CalculatorEngine.instance.getFunctionsRegistry().getDescription(context, data.getName());
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
		private final int captionId;
 | 
			
		||||
 | 
			
		||||
		LongClickMenuItem(int captionId) {
 | 
			
		||||
			this.captionId = captionId;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@NotNull
 | 
			
		||||
		@Override
 | 
			
		||||
		public String getCaption(@NotNull Context context) {
 | 
			
		||||
			return context.getString(captionId);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static final String CREATE_FUN_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorFunctionsTabActivity_create_fun";
 | 
			
		||||
public class CalculatorFunctionsTabActivity extends TabActivity {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
    public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		/*getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
 | 
			
		||||
				final Function function = (Function) parent.getItemAtPosition(position);
 | 
			
		||||
				if (function instanceof CustomFunction) {
 | 
			
		||||
					createEditVariableDialog(CalculatorFunctionsTabActivity.this,
 | 
			
		||||
							((CustomFunction) function),
 | 
			
		||||
							function.getName(),
 | 
			
		||||
							((CustomFunction) function).getContent(),
 | 
			
		||||
							((CustomFunction) function).getParameterNames(),
 | 
			
		||||
							null);
 | 
			
		||||
				}
 | 
			
		||||
				return true;
 | 
			
		||||
			}
 | 
			
		||||
		});*/
 | 
			
		||||
        setContentView(R.layout.tabs);
 | 
			
		||||
 | 
			
		||||
		/*final Intent intent = getIntent();
 | 
			
		||||
		if (intent != null) {
 | 
			
		||||
			final String varValue = intent.getStringExtra(CREATE_FUN_EXTRA_STRING);
 | 
			
		||||
			if (!StringUtils.isEmpty(varValue)) {
 | 
			
		||||
				createEditVariableDialog(this, null, null, varValue, null, null);
 | 
			
		||||
        final TabHost tabHost = getTabHost();
 | 
			
		||||
 | 
			
		||||
				// in order to stop intent for other tabs
 | 
			
		||||
				intent.removeExtra(CREATE_FUN_EXTRA_STRING);
 | 
			
		||||
			}
 | 
			
		||||
		}*/
 | 
			
		||||
        for (AndroidFunctionsMathRegistry.Category category : AndroidFunctionsMathRegistry.Category.getCategoriesByTabOrder()) {
 | 
			
		||||
            AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorFunctionsActivity.class, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<AMenuItem<Function>> getMenuItemsOnLongClick(@NotNull Function item) {
 | 
			
		||||
		List<AMenuItem<Function>> result = new ArrayList<AMenuItem<Function>>(Arrays.asList(LongClickMenuItem.values()));
 | 
			
		||||
		
 | 
			
		||||
		if ( StringUtils.isEmpty(CalculatorEngine.instance.getFunctionsRegistry().getDescription(this, item.getName())) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_description);
 | 
			
		||||
        AndroidUtils.centerAndWrapTabsFor(tabHost);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
/*	private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<Function> activity,
 | 
			
		||||
												 @Nullable final CustomFunction function,
 | 
			
		||||
												 @Nullable final String name,
 | 
			
		||||
												 @Nullable final String expression,
 | 
			
		||||
												 @Nullable final String[] parameterNames,
 | 
			
		||||
												 @Nullable final String description) {
 | 
			
		||||
		if (function == null || !function.isSystem()) {
 | 
			
		||||
 | 
			
		||||
			final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
			final View editView = layoutInflater.inflate(R.layout.var_edit, null);
 | 
			
		||||
 | 
			
		||||
			final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
 | 
			
		||||
 | 
			
		||||
			final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
 | 
			
		||||
			editName.setText(name);
 | 
			
		||||
			editName.addTextChangedListener(new TextWatcher() {
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void onTextChanged(CharSequence s, int start, int before, int count) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void afterTextChanged(Editable s) {
 | 
			
		||||
					for (int i = 0; i < s.length(); i++) {
 | 
			
		||||
						char c = s.charAt(i);
 | 
			
		||||
						if (!acceptableChars.contains(c)) {
 | 
			
		||||
							s.delete(i, i + 1);
 | 
			
		||||
							Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
 | 
			
		||||
			if (!StringUtils.isEmpty(expression)) {
 | 
			
		||||
				editValue.setText(expression);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
 | 
			
		||||
			editDescription.setText(description);
 | 
			
		||||
 | 
			
		||||
			final CustomFunction.Builder functionBuilder;
 | 
			
		||||
			if (function != null) {
 | 
			
		||||
				functionBuilder = new CustomFunction.Builder(function);
 | 
			
		||||
			} else {
 | 
			
		||||
				functionBuilder = new CustomFunction.Builder();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
 | 
			
		||||
					.setCancelable(true)
 | 
			
		||||
					.setNegativeButton(R.string.c_cancel, null)
 | 
			
		||||
					.setPositiveButton(R.string.c_save, new FunctionEditorSaver(functionBuilder, function, editView, activity, CalculatorEngine.instance.getFunctionsRegistry(), new FunctionEditorSaver.EditorCreator<Function>() {
 | 
			
		||||
 | 
			
		||||
						@Override
 | 
			
		||||
						public void showEditor(@NotNull AbstractMathEntityListActivity<Function> activity, @Nullable CustomFunction editedInstance, @Nullable String name, @Nullable String value, @Nullable String[] parameterNames, @Nullable String description) {
 | 
			
		||||
							createEditVariableDialog(activity, editedInstance, name, value, parameterNames, description);
 | 
			
		||||
						}
 | 
			
		||||
					}))
 | 
			
		||||
					.setView(editView);
 | 
			
		||||
 | 
			
		||||
			if (function != null) {
 | 
			
		||||
				// EDIT mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_edit_var);
 | 
			
		||||
				builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<Function>(function, new DialogInterface.OnClickListener() {
 | 
			
		||||
					@Override
 | 
			
		||||
					public void onClick(DialogInterface dialog, int which) {
 | 
			
		||||
						createEditVariableDialog(activity, function, name, expression, parameterNames, description);
 | 
			
		||||
					}
 | 
			
		||||
				}, CalculatorEngine.instance.getFunctionsRegistry(), activity));
 | 
			
		||||
			} else {
 | 
			
		||||
				// CREATE mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_create_var);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			builder.create().show();
 | 
			
		||||
		} else {
 | 
			
		||||
			Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
 | 
			
		||||
		}
 | 
			
		||||
	}*/
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected MathEntityDescriptionGetter getDescriptionGetter() {
 | 
			
		||||
		return new MathEntityDescriptionGetterImpl(CalculatorEngine.instance.getFunctionsRegistry());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<Function> getMathEntities() {
 | 
			
		||||
		return new ArrayList<Function>(CalculatorEngine.instance.getFunctionsRegistry().getEntities());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected String getMathEntityCategory(@NotNull Function function) {
 | 
			
		||||
		return CalculatorEngine.instance.getFunctionsRegistry().getCategory(function);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,39 +6,280 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.math.edit;
 | 
			
		||||
 | 
			
		||||
import android.app.TabActivity;
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.app.AlertDialog;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.DialogInterface;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.widget.TabHost;
 | 
			
		||||
import android.text.ClipboardManager;
 | 
			
		||||
import android.text.Editable;
 | 
			
		||||
import android.text.TextWatcher;
 | 
			
		||||
import android.view.*;
 | 
			
		||||
import android.widget.EditText;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
import jscl.math.function.IConstant;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.model.VarCategory;
 | 
			
		||||
import org.solovyev.android.calculator.math.MathType;
 | 
			
		||||
import org.solovyev.android.calculator.model.CalculatorEngine;
 | 
			
		||||
import org.solovyev.android.calculator.model.Var;
 | 
			
		||||
import org.solovyev.android.view.AMenuItem;
 | 
			
		||||
import org.solovyev.common.utils.CollectionsUtils;
 | 
			
		||||
import org.solovyev.common.utils.Finder;
 | 
			
		||||
import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 12/21/11
 | 
			
		||||
 * Time: 11:05 PM
 | 
			
		||||
 * Date: 9/28/11
 | 
			
		||||
 * Time: 10:55 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorVarsActivity extends TabActivity {
 | 
			
		||||
public class CalculatorVarsActivity extends AbstractMathEntityListActivity<IConstant> {
 | 
			
		||||
 | 
			
		||||
	private static enum LongClickMenuItem implements AMenuItem<IConstant>{
 | 
			
		||||
		use(R.string.c_use) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
 | 
			
		||||
				if (context instanceof Activity) {
 | 
			
		||||
					((Activity) context).finish();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		edit(R.string.c_edit) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				if (context instanceof AbstractMathEntityListActivity) {
 | 
			
		||||
					createEditVariableDialog((AbstractMathEntityListActivity<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		copy_value(R.string.c_copy_value) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				final String text = data.getValue();
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		copy_description(R.string.c_copy_description) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				final String text = CalculatorEngine.instance.getVarsRegistry().getDescription(context, data.getName());
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
		private final int captionId;
 | 
			
		||||
 | 
			
		||||
		LongClickMenuItem(int captionId) {
 | 
			
		||||
			this.captionId = captionId;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@NotNull
 | 
			
		||||
		@Override
 | 
			
		||||
		public String getCaption(@NotNull Context context) {
 | 
			
		||||
			return context.getString(captionId);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
    public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
	protected int getLayoutId() {
 | 
			
		||||
		return R.layout.vars;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
		super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.tabs);
 | 
			
		||||
		final Intent intent = getIntent();
 | 
			
		||||
		if (intent != null) {
 | 
			
		||||
			final String varValue = intent.getStringExtra(CREATE_VAR_EXTRA_STRING);
 | 
			
		||||
			if (!StringUtils.isEmpty(varValue)) {
 | 
			
		||||
				createEditVariableDialog(this, null, null, varValue, null);
 | 
			
		||||
 | 
			
		||||
        final TabHost tabHost = getTabHost();
 | 
			
		||||
				// in order to stop intent for other tabs
 | 
			
		||||
				intent.removeExtra(CREATE_VAR_EXTRA_STRING);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
        for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
 | 
			
		||||
            if (category == VarCategory.my) {
 | 
			
		||||
                AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorVarsTabActivity.class, getIntent());
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<AMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
 | 
			
		||||
		final List<AMenuItem<IConstant>> result = new ArrayList<AMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
 | 
			
		||||
		
 | 
			
		||||
		if ( item.isSystem() ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.edit);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( StringUtils.isEmpty(CalculatorEngine.instance.getVarsRegistry().getDescription(this, item.getName())) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_description);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( StringUtils.isEmpty(item.getValue()) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_value);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected MathEntityDescriptionGetter getDescriptionGetter() {
 | 
			
		||||
		return new MathEntityDescriptionGetterImpl(CalculatorEngine.instance.getVarsRegistry());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@SuppressWarnings({"UnusedDeclaration"})
 | 
			
		||||
	public void addVarButtonClickHandler(@NotNull View v) {
 | 
			
		||||
		createEditVariableDialog(this, null, null, null, null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<IConstant> getMathEntities() {
 | 
			
		||||
		final List<IConstant> result = new ArrayList<IConstant>(CalculatorEngine.instance.getVarsRegistry().getEntities());
 | 
			
		||||
 | 
			
		||||
		CollectionsUtils.removeAll(result, new Finder<IConstant>() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public boolean isFound(@Nullable IConstant var) {
 | 
			
		||||
				return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected String getMathEntityCategory(@NotNull IConstant var) {
 | 
			
		||||
		return CalculatorEngine.instance.getVarsRegistry().getCategory(var);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<IConstant> activity,
 | 
			
		||||
												 @Nullable final IConstant var,
 | 
			
		||||
												 @Nullable final String name,
 | 
			
		||||
												 @Nullable final String value,
 | 
			
		||||
												 @Nullable final String description) {
 | 
			
		||||
		if (var == null || !var.isSystem()) {
 | 
			
		||||
 | 
			
		||||
			final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
			final View editView = layoutInflater.inflate(R.layout.var_edit, null);
 | 
			
		||||
 | 
			
		||||
			final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
 | 
			
		||||
 | 
			
		||||
			final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
 | 
			
		||||
			editName.setText(name);
 | 
			
		||||
			editName.addTextChangedListener(new TextWatcher() {
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void onTextChanged(CharSequence s, int start, int before, int count) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void afterTextChanged(Editable s) {
 | 
			
		||||
					for (int i = 0; i < s.length(); i++) {
 | 
			
		||||
						char c = s.charAt(i);
 | 
			
		||||
						if (!acceptableChars.contains(c)) {
 | 
			
		||||
							s.delete(i, i + 1);
 | 
			
		||||
							Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
 | 
			
		||||
			if (!StringUtils.isEmpty(value)) {
 | 
			
		||||
				editValue.setText(value);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
 | 
			
		||||
			editDescription.setText(description);
 | 
			
		||||
 | 
			
		||||
			final Var.Builder varBuilder;
 | 
			
		||||
			if (var != null) {
 | 
			
		||||
				varBuilder = new Var.Builder(var);
 | 
			
		||||
			} else {
 | 
			
		||||
                AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorVarsTabActivity.class, null);
 | 
			
		||||
				varBuilder = new Var.Builder();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
 | 
			
		||||
					.setCancelable(true)
 | 
			
		||||
					.setNegativeButton(R.string.c_cancel, null)
 | 
			
		||||
					.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, editView, activity, CalculatorEngine.instance.getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() {
 | 
			
		||||
						@Override
 | 
			
		||||
						public void showEditor(@NotNull AbstractMathEntityListActivity<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
 | 
			
		||||
							createEditVariableDialog(activity, editedInstance, name, value, description);
 | 
			
		||||
						}
 | 
			
		||||
					}))
 | 
			
		||||
					.setView(editView);
 | 
			
		||||
 | 
			
		||||
			if (var != null) {
 | 
			
		||||
				// EDIT mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_edit_var);
 | 
			
		||||
				builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
 | 
			
		||||
					@Override
 | 
			
		||||
					public void onClick(DialogInterface dialog, int which) {
 | 
			
		||||
						createEditVariableDialog(activity, var, name, value, description);
 | 
			
		||||
					}
 | 
			
		||||
				}, CalculatorEngine.instance.getVarsRegistry(), activity));
 | 
			
		||||
			} else {
 | 
			
		||||
				// CREATE mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_create_var);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			builder.create().show();
 | 
			
		||||
		} else {
 | 
			
		||||
			Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
        tabHost.setCurrentTab(0);
 | 
			
		||||
        AndroidUtils.centerAndWrapTabsFor(tabHost);
 | 
			
		||||
	public static boolean isValidValue(@NotNull String value) {
 | 
			
		||||
		// now every string might be constant
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onCreateOptionsMenu(Menu menu) {
 | 
			
		||||
		final MenuInflater menuInflater = getMenuInflater();
 | 
			
		||||
		menuInflater.inflate(R.menu.var_menu, menu);
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onOptionsItemSelected(MenuItem item) {
 | 
			
		||||
		boolean result;
 | 
			
		||||
 | 
			
		||||
		switch (item.getItemId()) {
 | 
			
		||||
			case R.id.var_menu_add_var:
 | 
			
		||||
				createEditVariableDialog(this, null, null, null, null);
 | 
			
		||||
				result = true;
 | 
			
		||||
				break;
 | 
			
		||||
			default:
 | 
			
		||||
				result = super.onOptionsItemSelected(item);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,280 +6,39 @@
 | 
			
		||||
 | 
			
		||||
package org.solovyev.android.calculator.math.edit;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.app.AlertDialog;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.DialogInterface;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.app.TabActivity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.text.ClipboardManager;
 | 
			
		||||
import android.text.Editable;
 | 
			
		||||
import android.text.TextWatcher;
 | 
			
		||||
import android.view.*;
 | 
			
		||||
import android.widget.EditText;
 | 
			
		||||
import android.widget.Toast;
 | 
			
		||||
import jscl.math.function.IConstant;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import android.widget.TabHost;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
import org.solovyev.android.calculator.CalculatorModel;
 | 
			
		||||
import org.solovyev.android.AndroidUtils;
 | 
			
		||||
import org.solovyev.android.calculator.R;
 | 
			
		||||
import org.solovyev.android.calculator.math.MathType;
 | 
			
		||||
import org.solovyev.android.calculator.model.CalculatorEngine;
 | 
			
		||||
import org.solovyev.android.calculator.model.Var;
 | 
			
		||||
import org.solovyev.android.view.AMenuItem;
 | 
			
		||||
import org.solovyev.common.utils.CollectionsUtils;
 | 
			
		||||
import org.solovyev.common.utils.Finder;
 | 
			
		||||
import org.solovyev.common.utils.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import org.solovyev.android.calculator.model.VarCategory;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: serso
 | 
			
		||||
 * Date: 9/28/11
 | 
			
		||||
 * Time: 10:55 PM
 | 
			
		||||
 * Date: 12/21/11
 | 
			
		||||
 * Time: 11:05 PM
 | 
			
		||||
 */
 | 
			
		||||
public class CalculatorVarsTabActivity extends AbstractMathEntityListActivity<IConstant> {
 | 
			
		||||
 | 
			
		||||
	private static enum LongClickMenuItem implements AMenuItem<IConstant>{
 | 
			
		||||
		use(R.string.c_use) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				CalculatorModel.instance.processDigitButtonAction(data.getName(), false);
 | 
			
		||||
				if (context instanceof Activity) {
 | 
			
		||||
					((Activity) context).finish();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		edit(R.string.c_edit) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				if (context instanceof AbstractMathEntityListActivity) {
 | 
			
		||||
					createEditVariableDialog((AbstractMathEntityListActivity<IConstant>)context, data, data.getName(), StringUtils.getNotEmpty(data.getValue(), ""), data.getDescription());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		copy_value(R.string.c_copy_value) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				final String text = data.getValue();
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		copy_description(R.string.c_copy_description) {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void doAction(@NotNull IConstant data, @NotNull Context context) {
 | 
			
		||||
				final String text = CalculatorEngine.instance.getVarsRegistry().getDescription(context, data.getName());
 | 
			
		||||
				if (!StringUtils.isEmpty(text)) {
 | 
			
		||||
					final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
 | 
			
		||||
					clipboard.setText(text);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
		private final int captionId;
 | 
			
		||||
 | 
			
		||||
		LongClickMenuItem(int captionId) {
 | 
			
		||||
			this.captionId = captionId;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@NotNull
 | 
			
		||||
		@Override
 | 
			
		||||
		public String getCaption(@NotNull Context context) {
 | 
			
		||||
			return context.getString(captionId);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static final String CREATE_VAR_EXTRA_STRING = "org.solovyev.android.calculator.math.edit.CalculatorVarsTabActivity_create_var";
 | 
			
		||||
public class CalculatorVarsTabActivity extends TabActivity {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
	protected int getLayoutId() {
 | 
			
		||||
		return R.layout.vars;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
    public void onCreate(@Nullable Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
		final Intent intent = getIntent();
 | 
			
		||||
		if (intent != null) {
 | 
			
		||||
			final String varValue = intent.getStringExtra(CREATE_VAR_EXTRA_STRING);
 | 
			
		||||
			if (!StringUtils.isEmpty(varValue)) {
 | 
			
		||||
				createEditVariableDialog(this, null, null, varValue, null);
 | 
			
		||||
        setContentView(R.layout.tabs);
 | 
			
		||||
 | 
			
		||||
				// in order to stop intent for other tabs
 | 
			
		||||
				intent.removeExtra(CREATE_VAR_EXTRA_STRING);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
        final TabHost tabHost = getTabHost();
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<AMenuItem<IConstant>> getMenuItemsOnLongClick(@NotNull IConstant item) {
 | 
			
		||||
		final List<AMenuItem<IConstant>> result = new ArrayList<AMenuItem<IConstant>>(Arrays.asList(LongClickMenuItem.values()));
 | 
			
		||||
		
 | 
			
		||||
		if ( item.isSystem() ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.edit);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( StringUtils.isEmpty(CalculatorEngine.instance.getVarsRegistry().getDescription(this, item.getName())) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_description);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if ( StringUtils.isEmpty(item.getValue()) ) {
 | 
			
		||||
			result.remove(LongClickMenuItem.copy_value);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected MathEntityDescriptionGetter getDescriptionGetter() {
 | 
			
		||||
		return new MathEntityDescriptionGetterImpl(CalculatorEngine.instance.getVarsRegistry());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@SuppressWarnings({"UnusedDeclaration"})
 | 
			
		||||
	public void addVarButtonClickHandler(@NotNull View v) {
 | 
			
		||||
		createEditVariableDialog(this, null, null, null, null);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Override
 | 
			
		||||
	protected List<IConstant> getMathEntities() {
 | 
			
		||||
		final List<IConstant> result = new ArrayList<IConstant>(CalculatorEngine.instance.getVarsRegistry().getEntities());
 | 
			
		||||
 | 
			
		||||
		CollectionsUtils.removeAll(result, new Finder<IConstant>() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public boolean isFound(@Nullable IConstant var) {
 | 
			
		||||
				return var != null && CollectionsUtils.contains(var.getName(), MathType.INFINITY_JSCL, MathType.NAN);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	protected String getMathEntityCategory(@NotNull IConstant var) {
 | 
			
		||||
		return CalculatorEngine.instance.getVarsRegistry().getCategory(var);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static void createEditVariableDialog(@NotNull final AbstractMathEntityListActivity<IConstant> activity,
 | 
			
		||||
												 @Nullable final IConstant var,
 | 
			
		||||
												 @Nullable final String name,
 | 
			
		||||
												 @Nullable final String value,
 | 
			
		||||
												 @Nullable final String description) {
 | 
			
		||||
		if (var == null || !var.isSystem()) {
 | 
			
		||||
 | 
			
		||||
			final LayoutInflater layoutInflater = (LayoutInflater) activity.getSystemService(LAYOUT_INFLATER_SERVICE);
 | 
			
		||||
			final View editView = layoutInflater.inflate(R.layout.var_edit, null);
 | 
			
		||||
 | 
			
		||||
			final String errorMsg = activity.getString(R.string.c_char_is_not_accepted);
 | 
			
		||||
 | 
			
		||||
			final EditText editName = (EditText) editView.findViewById(R.id.var_edit_name);
 | 
			
		||||
			editName.setText(name);
 | 
			
		||||
			editName.addTextChangedListener(new TextWatcher() {
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void onTextChanged(CharSequence s, int start, int before, int count) {
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				@Override
 | 
			
		||||
				public void afterTextChanged(Editable s) {
 | 
			
		||||
					for (int i = 0; i < s.length(); i++) {
 | 
			
		||||
						char c = s.charAt(i);
 | 
			
		||||
						if (!acceptableChars.contains(c)) {
 | 
			
		||||
							s.delete(i, i + 1);
 | 
			
		||||
							Toast.makeText(activity, String.format(errorMsg, c), Toast.LENGTH_SHORT).show();
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			final EditText editValue = (EditText) editView.findViewById(R.id.var_edit_value);
 | 
			
		||||
			if (!StringUtils.isEmpty(value)) {
 | 
			
		||||
				editValue.setText(value);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final EditText editDescription = (EditText) editView.findViewById(R.id.var_edit_description);
 | 
			
		||||
			editDescription.setText(description);
 | 
			
		||||
 | 
			
		||||
			final Var.Builder varBuilder;
 | 
			
		||||
			if (var != null) {
 | 
			
		||||
				varBuilder = new Var.Builder(var);
 | 
			
		||||
        for (VarCategory category : VarCategory.getCategoriesByTabOrder()) {
 | 
			
		||||
            if (category == VarCategory.my) {
 | 
			
		||||
                AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorVarsActivity.class, getIntent());
 | 
			
		||||
            } else {
 | 
			
		||||
				varBuilder = new Var.Builder();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			final AlertDialog.Builder builder = new AlertDialog.Builder(activity)
 | 
			
		||||
					.setCancelable(true)
 | 
			
		||||
					.setNegativeButton(R.string.c_cancel, null)
 | 
			
		||||
					.setPositiveButton(R.string.c_save, new VarEditorSaver<IConstant>(varBuilder, var, editView, activity, CalculatorEngine.instance.getVarsRegistry(), new VarEditorSaver.EditorCreator<IConstant>() {
 | 
			
		||||
						@Override
 | 
			
		||||
						public void showEditor(@NotNull AbstractMathEntityListActivity<IConstant> activity, @Nullable IConstant editedInstance, @Nullable String name, @Nullable String value, @Nullable String description) {
 | 
			
		||||
							createEditVariableDialog(activity, editedInstance, name, value, description);
 | 
			
		||||
						}
 | 
			
		||||
					}))
 | 
			
		||||
					.setView(editView);
 | 
			
		||||
 | 
			
		||||
			if (var != null) {
 | 
			
		||||
				// EDIT mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_edit_var);
 | 
			
		||||
				builder.setNeutralButton(R.string.c_remove, new MathEntityRemover<IConstant>(var, new DialogInterface.OnClickListener() {
 | 
			
		||||
					@Override
 | 
			
		||||
					public void onClick(DialogInterface dialog, int which) {
 | 
			
		||||
						createEditVariableDialog(activity, var, name, value, description);
 | 
			
		||||
					}
 | 
			
		||||
				}, CalculatorEngine.instance.getVarsRegistry(), activity));
 | 
			
		||||
			} else {
 | 
			
		||||
				// CREATE mode
 | 
			
		||||
 | 
			
		||||
				builder.setTitle(R.string.c_var_create_var);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			builder.create().show();
 | 
			
		||||
		} else {
 | 
			
		||||
			Toast.makeText(activity, activity.getString(R.string.c_sys_var_cannot_be_changed), Toast.LENGTH_LONG).show();
 | 
			
		||||
                AbstractMathEntityListActivity.createTab(this, tabHost, category.name(), category.name(), category.getCaptionId(), CalculatorVarsActivity.class, null);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
	public static boolean isValidValue(@NotNull String value) {
 | 
			
		||||
		// now every string might be constant
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onCreateOptionsMenu(Menu menu) {
 | 
			
		||||
		final MenuInflater menuInflater = getMenuInflater();
 | 
			
		||||
		menuInflater.inflate(R.menu.var_menu, menu);
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean onOptionsItemSelected(MenuItem item) {
 | 
			
		||||
		boolean result;
 | 
			
		||||
 | 
			
		||||
		switch (item.getItemId()) {
 | 
			
		||||
			case R.id.var_menu_add_var:
 | 
			
		||||
				createEditVariableDialog(this, null, null, null, null);
 | 
			
		||||
				result = true;
 | 
			
		||||
				break;
 | 
			
		||||
			default:
 | 
			
		||||
				result = super.onOptionsItemSelected(item);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return result;
 | 
			
		||||
        tabHost.setCurrentTab(0);
 | 
			
		||||
        AndroidUtils.centerAndWrapTabsFor(tabHost);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -112,7 +112,7 @@ public class FunctionEditorSaver implements DialogInterface.OnClickListener{
 | 
			
		||||
							error = null;
 | 
			
		||||
						} else {
 | 
			
		||||
							// value is not empty => must be a number
 | 
			
		||||
							boolean valid = CalculatorVarsTabActivity.isValidValue(value);
 | 
			
		||||
							boolean valid = CalculatorVarsActivity.isValidValue(value);
 | 
			
		||||
 | 
			
		||||
							if (valid) {
 | 
			
		||||
								varBuilder.setName(name);
 | 
			
		||||
 
 | 
			
		||||
@@ -109,7 +109,7 @@ class VarEditorSaver<T extends MathEntity> implements DialogInterface.OnClickLis
 | 
			
		||||
							error = null;
 | 
			
		||||
						} else {
 | 
			
		||||
							// value is not empty => must be a number
 | 
			
		||||
							boolean valid = CalculatorVarsTabActivity.isValidValue(value);
 | 
			
		||||
							boolean valid = CalculatorVarsActivity.isValidValue(value);
 | 
			
		||||
 | 
			
		||||
							if (valid) {
 | 
			
		||||
								varBuilder.setName(name);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user