Ignore:
Timestamp:
05/04/12 17:14:40 (13 years ago)
Author:
remons
Message:

Added ObjectSerializer?.class

Location:
trunk/TagTracker/src/nl/deadpixel/tagtracker/beta
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/TagTracker/src/nl/deadpixel/tagtracker/beta/FileHandler.java

    r3 r5  
    4343                }
    4444        }
    45         public void writeUID(String uid, String time, String note)
     45        public void writeUID(String uid, String time)
    4646        {
    4747                try {
     
    5252                                "       <tag uid=\"" + uid + "\">\r\n" +
    5353                                "               <time>" + time + "</time>\r\n" +
    54                                 "               <note>" + note + "</note>\r\n" +
    5554                                "       </tag>\r\n";
    56                         Log.i("TagTracker", "Writing tag " + uid);
    5755                writer.append(tag);
    58                 Log.i("TagTracker", "Wrote tag " + uid);
    5956                writer.flush();
    6057                writer.close();
     
    6562        }
    6663       
     64        public void writeNote(String note)
     65        {
     66                try {
     67                        File root = new File(Environment.getExternalStorageDirectory(), "TagTracker");
     68                    File xmlfile = new File(root, "tags.log");
     69                    FileWriter writer = new FileWriter(xmlfile,true);
     70                        String tag =
     71                                "       <note>\r\n" +
     72                                "       " + note +
     73                                "       <note>\r\n";
     74                writer.append(tag);
     75                writer.flush();
     76                writer.close();
     77                } catch (IOException e) {
     78                        Log.e("TagTracker", "" + e.getMessage());
     79                }
     80               
     81        }
    6782        public void writeStart(String starttime)
    6883        {
     
    7691                                "<tags>\r\n" +
    7792                                "       <start time=\""+starttime+"\" />\r\n";
    78                 Log.i("TagTracker", "Writing start...");
     93                //Log.i("TagTracker", "Writing start...");
    7994                writer.write(start);
    80                 Log.i("TagTracker", "Wrote start...");
     95                //Log.i("TagTracker", "Wrote start...");
    8196                writer.flush();
    8297                writer.close();
     
    97112                                "<end time=\""+endtime+"\" />\r\n" +
    98113                                "</tags>";
    99                 Log.i("TagTracker", "Writing end...");
     114                //Log.i("TagTracker", "Writing end...");
    100115                writer.append(end);
    101                 Log.i("TagTracker", "Wrote end...");
     116                //Log.i("TagTracker", "Wrote end...");
    102117                writer.flush();
    103118                writer.close();
  • trunk/TagTracker/src/nl/deadpixel/tagtracker/beta/TagTrackerActivity.java

    r4 r5  
    22
    33
     4import java.io.File;
    45import java.io.IOException;
    56import java.text.DateFormat;
     
    89
    910import android.app.Activity;
     11import android.app.AlertDialog;
    1012import android.app.PendingIntent;
    1113import android.content.Context;
     14import android.content.DialogInterface;
    1215import android.content.Intent;
    1316import android.content.IntentFilter;
    1417import android.content.IntentFilter.MalformedMimeTypeException;
     18import android.content.SharedPreferences;
    1519import android.media.AudioManager;
    1620import android.media.MediaPlayer;
     
    2024import android.nfc.tech.NfcA;
    2125import android.os.Bundle;
     26import android.os.Environment;
    2227import android.os.Handler;
    2328import android.os.PowerManager;
     
    2631import android.view.Menu;
    2732import android.view.MenuInflater;
     33import android.view.MenuItem;
    2834import android.view.View;
    2935import android.widget.Button;
     36import android.widget.EditText;
    3037import android.widget.RelativeLayout;
    31 import android.widget.TextView;
    3238import android.widget.ToggleButton;
    3339
     
    4248    private RelativeLayout mScreen;
    4349   
    44     @Override
     50    @SuppressWarnings("unchecked")
     51        @Override
    4552    public void onCreate(Bundle savedState) {
    4653        super.onCreate(savedState);
     
    5158        button.setOnClickListener(new View.OnClickListener() {
    5259            public void onClick(View v) {
    53            
     60                zenden();
    5461            }
    5562        });
     63        SharedPreferences p = getPreferences(MODE_PRIVATE);
     64        writeAllow = p.getBoolean("writeAllow", false);
     65        cardID = (ArrayList<String>) ObjectSerializer.deserialize(p.getString("cardID", ObjectSerializer.serialize(new ArrayList<String>())));
     66        ToggleButton tg = (ToggleButton) findViewById(R.id.status);
     67        tg.setChecked(writeAllow);
    5668        mScreen = (RelativeLayout) findViewById(R.id.Screen);
    5769        mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,"");   
     
    116128                                if(!cardID.contains(uid))
    117129                                {
    118                                         Log.i("Foreground dispatch", "Discovered tag with ID: " + uid);
     130                                        //Log.i("Foreground dispatch", "Discovered tag with ID: " + uid);
    119131                                    //mText.append("\r\n["+time+"] Discovered tag " + ++mCount + " with ID: " + uid);
    120                                     fh.writeUID(uid, time, "");
     132                                    fh.writeUID(uid, time);
    121133                                    cardID.add(uid);
    122134                                    setBackground(0xFF00FF00, 200);
     
    170182                mScreen.setBackgroundColor(android.R.color.white);
    171183             }
    172         }, time);
    173        
    174        
     184        }, time);       
    175185    }
    176186    @Override
    177187    public void onPause() {
    178188        super.onPause();
     189        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
     190        SharedPreferences.Editor editor = preferences.edit();
     191        editor.putBoolean("writeAllow", writeAllow); // value to store
     192        editor.putString("cardID", ObjectSerializer.serialize(cardID));
     193        editor.commit();
    179194        if (mAdapter != null) mAdapter.disableForegroundDispatch(this);
    180195    }
     196
    181197    @Override
    182198    public boolean onCreateOptionsMenu(Menu menu) {
     
    185201        return true;
    186202    }
     203    @Override
     204    public boolean onOptionsItemSelected(MenuItem item) {
     205        // Handle item selection
     206        switch (item.getItemId()) {
     207            case R.id.add_uid:
     208                addUID();
     209                return true;
     210            case R.id.add_note:
     211                addNote();
     212                return true;
     213            case R.id.stopsend:
     214                stopSend();
     215                return true;
     216            default:
     217                return super.onOptionsItemSelected(item);
     218        }
     219    }
     220   
     221    public void addUID()
     222    {
     223        if(writeAllow)
     224        {
     225                AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
     226                alert.setTitle("UID Toevoegen"); 
     227       
     228                // Set an EditText view to get user input   
     229                final EditText input = new EditText(this);
     230                alert.setView(input);
     231
     232            alert.setPositiveButton("Toevoegen", new DialogInterface.OnClickListener() { 
     233            public void onClick(DialogInterface dialog, int whichButton) { 
     234                String value = input.getText().toString();
     235                fh.writeUID(value, DateFormat.getDateTimeInstance().format(new Date()));
     236                return;                 
     237               } 
     238             }); 
     239
     240            alert.setNegativeButton("Annuleren", new DialogInterface.OnClickListener() {
     241
     242                public void onClick(DialogInterface dialog, int which) {
     243                    // TODO Auto-generated method stub
     244                    return;   
     245                }
     246            });
     247            alert.show();
     248        }
     249        else
     250        {
     251                AlertDialog.Builder alert = new AlertDialog.Builder(this, 4);                 
     252                alert.setTitle("Oeps!");
     253                alert.setMessage("Druk op start om een UID toe te voegen");
     254                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
     255                               
     256                                public void onClick(DialogInterface dialog, int which) {
     257                                        // TODO Auto-generated method stub
     258                                        return;
     259                                }
     260                        });
     261                alert.show();
     262        }
     263    }
     264   
     265    public void addNote()
     266    {
     267        if(writeAllow)
     268        {
     269                AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
     270                alert.setTitle("Notitie Toevoegen"); 
     271       
     272                // Set an EditText view to get user input   
     273                final EditText input = new EditText(this);
     274                alert.setView(input);
     275
     276            alert.setPositiveButton("Toevoegen", new DialogInterface.OnClickListener() { 
     277            public void onClick(DialogInterface dialog, int whichButton) { 
     278                String value = input.getText().toString();
     279                fh.writeNote(value);
     280                return;                 
     281               } 
     282             }); 
     283
     284            alert.setNegativeButton("Annuleren", new DialogInterface.OnClickListener() {
     285
     286                public void onClick(DialogInterface dialog, int which) {
     287                    // TODO Auto-generated method stub
     288                    return;   
     289                }
     290            });
     291            alert.show();
     292        }
     293        else
     294        {
     295                AlertDialog.Builder alert = new AlertDialog.Builder(this, 4);                 
     296                alert.setTitle("Oeps!");
     297                alert.setMessage("Druk op start om een Notitie toe te voegen");
     298                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
     299                               
     300                                public void onClick(DialogInterface dialog, int which) {
     301                                        // TODO Auto-generated method stub
     302                                        return;
     303                                }
     304                        });
     305                alert.show();
     306        }
     307    }
     308    public void stopSend()
     309    {
     310        writeAllow = false;
     311        ToggleButton tg = (ToggleButton) findViewById(R.id.status);
     312        tg.setChecked(writeAllow);
     313        AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
     314        alert.setTitle("Email Zenden"); 
     315
     316        // Set an EditText view to get user input   
     317        final EditText input = new EditText(this);
     318        input.setHint("Email");
     319        input.setInputType(32);
     320        alert.setView(input);
     321
     322            alert.setPositiveButton("Verder", new DialogInterface.OnClickListener() { 
     323            public void onClick(DialogInterface dialog, int whichButton) { 
     324                String value = input.getText().toString();
     325                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
     326                emailIntent.setType("text/xml");
     327                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
     328                {value});
     329                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
     330                "Tag Track from " + DateFormat.getDateTimeInstance().format(new Date()));
     331                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
     332                "XML Attached");
     333                File root = new File(Environment.getExternalStorageDirectory(), "TagTracker");
     334                    File xmlfile = new File(root, "tags.log");
     335                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ xmlfile));
     336                startActivity(Intent.createChooser(emailIntent, "Stuur Email"));
     337                return;                 
     338               } 
     339             }); 
     340            alert.show();
     341    }
     342    public void zenden()
     343    {
     344        if(!writeAllow)
     345        {
     346                AlertDialog.Builder alert = new AlertDialog.Builder(this);                 
     347                alert.setTitle("Email Zenden"); 
     348
     349                // Set an EditText view to get user input   
     350                final EditText input = new EditText(this);
     351                input.setHint("Email");
     352                input.setInputType(32);
     353                alert.setView(input);
     354
     355            alert.setPositiveButton("Verder", new DialogInterface.OnClickListener() { 
     356            public void onClick(DialogInterface dialog, int whichButton) { 
     357                String value = input.getText().toString();
     358                Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
     359                emailIntent.setType("text/xml");
     360                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
     361                {value});
     362                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
     363                "Tag Track from " + DateFormat.getDateTimeInstance().format(new Date()));
     364                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
     365                "XML Attached");
     366                File root = new File(Environment.getExternalStorageDirectory(), "TagTracker");
     367                    File xmlfile = new File(root, "tags.log");
     368                emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ xmlfile));
     369                startActivity(Intent.createChooser(emailIntent, "Stuur Email"));
     370                return;                 
     371               } 
     372             }); 
     373            alert.show();
     374        }
     375        else
     376        {
     377                AlertDialog.Builder alert = new AlertDialog.Builder(this, 4);                 
     378                alert.setTitle("Oeps!");
     379                alert.setMessage("Druk op stop om te verzenden");
     380                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
     381                               
     382                                public void onClick(DialogInterface dialog, int which) {
     383                                        // TODO Auto-generated method stub
     384                                        return;
     385                                }
     386                        });
     387                alert.show();
     388        }
     389    }
    187390}
Note: See TracChangeset for help on using the changeset viewer.