Permalink
Browse files

license-controlled geotag enabling widget!

  • Loading branch information...
dichro committed Dec 15, 2011
1 parent 8ef3f61 commit ec51f52cc1ae8f9c202e10fef4b4788b442144a8
View
@@ -4,5 +4,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
@@ -1,7 +1,14 @@
<TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<TableRow>
- <CheckBox android:layout_height="wrap_content" android:id="@+id/checkBox1" android:layout_width="wrap_content" android:text="@string/geotag_enable" android:onClick="enableGeotagging"></CheckBox>
+
+ <CheckBox
+ android:id="@+id/enable_geotag"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:onClick="enableGeotagging"
+ android:text="@string/geotag_enable" >
+</CheckBox>
</TableRow>
<TableRow>
<TextView android:id="@+id/textView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/geotag_window"></TextView>
@@ -18,7 +18,6 @@
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
-import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.AdapterView.AdapterContextMenuInfo;
@@ -4,10 +4,13 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
-import android.content.ContentResolver;
+import android.content.ActivityNotFoundException;
+import android.content.ComponentName;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
+import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -29,6 +32,44 @@
private TextView offset;
private ImageButton save;
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch(requestCode) {
+ case 0:
+ if(resultCode == 1)
+ enableGeotagging();
+ }
+ }
+
+ boolean checkBetaLicense(int requestCode, String feature) {
+ Log.d(TAG, "checkBetaLicense " + requestCode + " " + feature);
+ Intent i = new Intent();
+ i.setComponent(new ComponentName("to.rcpt.license.fefi", "to.rcpt.license.fefi.LicensingActivity"));
+ i.setAction("to.rcpt.license.CHECK");
+ i.putExtra("to.rcpt.license.feature", feature);
+ i.putExtra("to.rcpt.license.version", 1);
+ try {
+ Log.d(TAG, "sending license intent");
+ startActivityForResult(i, requestCode);
+ Log.d(TAG, "sent intent");
+ } catch(ActivityNotFoundException e) {
+ Log.d(TAG, "activity not found");
+ AlertDialog.Builder b = new AlertDialog.Builder(this);
+ b.setMessage("You need to buy a beta license from the market to use this feature.")
+ .setPositiveButton("Tell Me More?", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=to.rcpt.license.fefi")));
+ }
+ })
+ .setNegativeButton("Never mind!", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ }).show();
+ }
+ Log.d(TAG, "returning false");
+ return false;
+ }
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -43,6 +84,9 @@ public void onCreate(Bundle savedInstanceState) {
save = (ImageButton)findViewById(R.id.save);
save.setEnabled(false);
+ CheckBox b = (CheckBox)findViewById(R.id.enable_geotag);
+ b.setChecked(preferences.getBoolean("enable_geotag", false));
+
offset = (TextView)findViewById(R.id.geotag_offset);
offset.setText("" + window);
offset.addTextChangedListener(new TextWatcher() {
@@ -80,6 +124,17 @@ public void savePreferences(View v) {
public void enableGeotagging(View v) {
CheckBox b = (CheckBox)v;
Log.d(TAG, "enableGeo " + b.isChecked());
+ if(b.isChecked()) {
+ if(!checkBetaLicense(0, "enableGeotagging"))
+ b.setChecked(false);
+ } else
+ preferences.edit().putBoolean("enable_geotag", false).commit();
+ }
+
+ private void enableGeotagging() {
+ CheckBox b = (CheckBox)findViewById(R.id.enable_geotag);
+ b.setChecked(true);
+ preferences.edit().putBoolean("enable_geotag", true).commit();
}
public void clearSavedLocations(View v) {
@@ -10,7 +10,6 @@
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.text.format.DateFormat;
-import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

0 comments on commit ec51f52

Please sign in to comment.