EditorActivity.java (2463B)
1 package de.openrat.android.client; 2 3 import java.io.IOException; 4 import java.util.Map; 5 6 import android.app.Activity; 7 import android.os.Bundle; 8 import android.view.View; 9 import android.view.View.OnClickListener; 10 import android.widget.Button; 11 import android.widget.CheckBox; 12 import android.widget.EditText; 13 import android.widget.Toast; 14 import de.openrat.android.client.util.OpenRatClientAsyncTask; 15 import de.openrat.client.OpenRatClient; 16 17 public class EditorActivity extends Activity 18 { 19 public final static String ELEMENTID = "elementid"; 20 public final static String OBJECTID = "objectid"; 21 // public final static String TYPE = "type"; 22 public static final String CLIENT = "client"; 23 private OpenRatClient client; 24 private String objectid; 25 private String elementid; 26 private String type; 27 private Map<String, String> properties; 28 29 @Override 30 protected void onCreate(Bundle savedInstanceState) 31 { 32 super.onCreate(savedInstanceState); 33 34 this.client = (OpenRatClient) getIntent().getSerializableExtra(CLIENT); 35 this.objectid = getIntent().getStringExtra(OBJECTID); 36 this.elementid = getIntent().getStringExtra(ELEMENTID); 37 38 new OpenRatClientAsyncTask(this, R.string.waitingforcontent) 39 { 40 41 @Override 42 protected void callServer() throws IOException 43 { 44 properties = client.getValue(objectid, elementid); 45 type = properties.get("type"); 46 } 47 48 protected void doOnSuccess() 49 { 50 if (type.equals("longtext")) 51 { 52 setContentView(R.layout.editor); 53 final EditText view = (EditText) findViewById(R.id.text); 54 view.setText(properties.get("text")); 55 56 Button button = (Button) findViewById(R.id.save); 57 button.setOnClickListener(new OnClickListener() 58 { 59 60 @Override 61 public void onClick(View v) 62 { 63 final String text = view.getEditableText() 64 .toString(); 65 final CheckBox releaseBox = (CheckBox) findViewById(R.id.release); 66 67 new OpenRatClientAsyncTask(EditorActivity.this, 68 R.string.waitingforsave) 69 { 70 71 @Override 72 protected void callServer() throws IOException 73 { 74 client.setValue(objectid, elementid, 75 "longtext", text, releaseBox.isChecked(), false); 76 } 77 78 protected void doOnSuccess() 79 { 80 Toast.makeText(EditorActivity.this, 81 R.string.saved, Toast.LENGTH_SHORT); 82 EditorActivity.this.finish(); 83 }; 84 }.execute(); 85 86 } 87 88 }); 89 } 90 } 91 }.execute(); 92 } 93 }