Salve developers,
non ho il permesso per accedere al file, in quanto mi serve di cancellare le sharedpreferences, internet suggerisce di trovare adb in modo tale da settare i permessi di eclipse cosi da poter vedere da ddms i files( che al momento non posso vedere causa permessi), ma siccome lavoro dall'ufficio non posso andare con cmd.exe in adb causa restrizioni dell'azienda.
esiste un modo per cancellare il file?
codice:
mport java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import android.os.Build;
public class ImageActivity extends ActionBarActivity implements
PointCollectorListener {
private static final String PASSWORD_SET = "PASSWORD_SET";
private PointCollector pointCollector = new PointCollector();
private Database db = new Database(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image);
Log.d(MainActivity.TAG, "10 On Create go to ");
addTouchListener();
showSetPasspointPrompt();
Log.d(MainActivity.TAG, "20 out from addTouchListener() and showSetPasspointPrompt/l going to the last /n+ method in on create pointCollector.setListener(this);");
pointCollector.setListener(this);
Log.d(MainActivity.TAG, "35 end instructions on OnCreate.. the program is waiting for a click");
}
private void addTouchListener() {
ImageView image = (ImageView) findViewById(R.id.touch_image);
image.setOnTouchListener(pointCollector);
}
private void showSetPasspointPrompt() {
AlertDialog.Builder builder = new Builder(this);
builder.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(ImageActivity.this, "YEP", Toast.LENGTH_LONG)
.show();
}
});
builder.setNegativeButton("Cancel", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(ImageActivity.this, "olaaaaa", Toast.LENGTH_LONG)
.show();
}
});
builder.setTitle("Create your Passpoint sequence");
builder.setMessage("Touch four poins on the image to set the passpoint sequence");
AlertDialog dlg = builder.create();
dlg.show();
}
/*
* @Override public boolean onCreateOptionsMenu(Menu menu) {
*
* // Inflate the menu; this adds items to the action bar if it is present.
* getMenuInflater().inflate(R.menu.image, menu); return true; }
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void savePasspoints(final List<Point> points) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.hello_world);
final AlertDialog dlg = builder.create();
dlg.show();
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
db.storePoints(points);
Log.d(MainActivity.TAG, "Points saved: " + points.size());
return null;
}
// this code will run when doInBackground finished running
@Override
protected void onPostExecute(Void result) {
Log.d(MainActivity.TAG, "80 on postexecute AsyncTask");
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(PASSWORD_SET, true);
editor.commit();
Log.d(MainActivity.TAG,"editor clean ");
pointCollector.clear();
dlg.dismiss();
}
};
// you have to execute all
task.execute();
/*
* Log.d(MainActivity.TAG, "Collected points: "+ points.size());
* db.storePoints(points); Log.d(MainActivity.TAG, "riuscito ");
* List<Point> list= db.getPoints(); for(Point point:list){
* Log.d(MainActivity.TAG, String.format("Got Points:(%d, %d)",
* point.x, point.y));
*/
}
private void verifyPasspoints(final List<Point> points) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("checking passpoints...");
final AlertDialog dlg =builder.create();
dlg.show();
AsyncTask<Void, Void, Boolean> task= new AsyncTask<Void, Void, Boolean>(){
@Override
protected Boolean doInBackground(Void... params) {
//we cannot give instruction for GUI here, no dlg because is a background process.
return true;
}
@Override
protected void onPostExecute(Boolean pass) {
dlg.dismiss();
pointCollector.clear();
if(pass==true){
Intent i= new Intent(ImageActivity.this, MainActivity.class);
startActivity(i);
}else{
Toast.makeText(ImageActivity.this, "Access denied.", Toast.LENGTH_LONG).show();
}
}
};
task.execute();
}
@Override
// make variable final, so cannot assign points
public void pointsCollected(final List<Point> points) {
Log.d(MainActivity.TAG, "60 ora sono da pointCollected in ImageActivity");
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
Boolean passpointSet = prefs.getBoolean(PASSWORD_SET, false);
//prefs.edit().clear().commit();
Log.d(MainActivity.TAG, "70 Sharedpreferences ");
if (!passpointSet) {
Log.d(MainActivity.TAG, "Saving passpoint..");
savePasspoints(points);
} else {
Log.d(MainActivity.TAG, "Verifying passpoint..");
///should be verifying passpoints(points)
verifyPasspoints(points);
}
}
}
l altra classe '
codice:
public class PointCollector implements OnTouchListener {
///makes an array because we have to collect four points every Point has 2 integers inside
private List<Point> points =new ArrayList<Point>();
private PointCollectorListener listener;
public boolean onTouch(View v, MotionEvent event) {
int x=Math.round(event.getX());
int y=Math.round(event.getY());
Log.d(MainActivity.TAG, "40 I am on PointCollector.Ontouch, are you triggering to me, click... and i continue to listen");
String message =String.format("Coordinates: (%d, %d)",x,y);
Log.d(MainActivity.TAG,message);
points.add(new Point(x,y));
if(points.size()==4){
if(listener != null){
Log.d(MainActivity.TAG, " 50 e mo basta ... mi hai cliccato 4 volte e sei entrato nel if points.size=4 che punta a ");
listener.pointsCollected(points);
}
}
return false;
}
public void setListener(PointCollectorListener listener) {
Log.d(MainActivity.TAG, "30 sto nel set setListener(PointCollectorListener listener ..) /l /n gli assegno this.listener to Class PointCollector..and waiting for a touch");
this.listener = listener;
}
public void clear(){
points.clear();
}
}
altra classe e'