public class FragmentActivity extends Activity implements OnItemClickListener{
private ListView discrepancy_list;
private DiscrepancyListAdapter list_adapter = null;
private ArrayList<CommonEntity> discrepancyList = new ArrayList<CommonEntity>();
private RelativeLayout objRelativeLayout;
private static int X_CO_ordinate;
private static int Y_CO_ordinate;
private ArrayList<String> arrlstCo_ordinate;
private ArrayList<String> arrlst_Count;
private boolean touch = true,isOnLaunch = false;
private int editText_ID=1,count=1;
private EditText objEditText;
private SortedMap<Integer,String> mapDefect=null;
private int final_position;
private ImageButton objImageButton;
private DatabaseHandler db;
Bitmap StoredBitmap;
Drawable StoredDrawable;
private static int dataSet = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapDefect=new TreeMap<Integer, String>();
arrlstCo_ordinate=new ArrayList<String>();
arrlst_Count=new ArrayList<String>();
discrepancy_list = (ListView)findViewById(R.id.number_list);
discrepancy_list.setOnItemClickListener(this);
db = new DatabaseHandler(this);
objRelativeLayout=(RelativeLayout) findViewById(R.id.RelativeLayout);
objRelativeLayout.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event){
String strEditText;
if(!checkForDataSaved()){
if(touch){
Log.d("ON", "onTouch called");
X_CO_ordinate=(int) event.getX() ;
Y_CO_ordinate=(int) event.getY();
boolean isNotDuplicate=checkDuplicateElement(X_CO_ordinate,Y_CO_ordinate);
if(isNotDuplicate){
Log.d("TOUCH", "TOUCH"+X_CO_ordinate+"|"+Y_CO_ordinate+"|"+"Touch :");
if(objEditText != null){
strEditText=objEditText.getText().toString();
Log.d("Err", "EditText not null"+strEditText);
if(strEditText != null && strEditText.length() != 0){
// if(chekMapEntry(objEditText.getId(), objEditText.getText().toString(), ""+X_CO_ordinate+"|"+Y_CO_ordinate))
// {
arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
mapDefect.put(objEditText.getId(),objEditText.getText().toString());
Log.d("Err", "In Touch Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
objEditText.setVisibility(View.INVISIBLE);
//}else{Toast.makeText(FragmentActivity.this, "Duplicate map entry", Toast.LENGTH_LONG).show();}
addEditText();
Log.d("Err", "String not null");
}else{
Log.d("Err", "String null");
Toast.makeText(FragmentActivity.this, "Please log the defect ::: in onTouch()", Toast.LENGTH_LONG).show();
}
}else{
Log.d("Err", "EditText null");
arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
Log.d("Err", "In Touch else Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
Drawable relative_image_bg = objRelativeLayout.getBackground();
Bitmap bitmap = ((BitmapDrawable)relative_image_bg).getBitmap();
Bitmap bitmap2 = ((BitmapDrawable)(getResources().getDrawable(R.drawable.no_image_screen_new))).getBitmap();
if(bitmap.sameAs(bitmap2)){
Toast.makeText(FragmentActivity.this, "Please capture the image", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(FragmentActivity.this, "Not equal..", Toast.LENGTH_LONG).show();
addEditText();
}
}
}
touch=false;
}else{
touch=true;
}
}
return true;
}
private boolean checkDuplicateElement(int x_CO_ordinate,int y_CO_ordinate){
String strX=String.valueOf(x_CO_ordinate);
String strY=String.valueOf(y_CO_ordinate);
for(int i=0;i<arrlstCo_ordinate.size();i++){
String strResult=arrlstCo_ordinate.get(i);
String []arrResult=StringUtils.split(strResult, "|");
String strTemp_X=arrResult[0];
String strTemp_Y=arrResult[1];
Log.d("CO", ""+strTemp_X+strTemp_Y+"|"+strX+strY);
if(strTemp_X.equalsIgnoreCase(strX) || strTemp_Y.equalsIgnoreCase(strY)){
Log.d("DUP", "Duplicate element is not allow");
Toast.makeText(FragmentActivity.this, "Duplicate element is not allow", Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
});
//add list in main.xml
addList();
getDefects();
}
private void addList(){
discrepancyList = LocalDatabaseOperations.callDBToGetList(this);
list_adapter = new DiscrepancyListAdapter(this, discrepancyList);
discrepancy_list.setAdapter(list_adapter);
isOnLaunch = true;
discrepancy_list.performItemClick(null, 0, discrepancy_list.getFirstVisiblePosition());
}
private void getDefects(){
if(LocalDatabaseOperations.callDBToGetDefects(this) == true){
fechCoordinate();
addViewEditText();
}
}
因此,这是在LHS上加载“差异列表”的活动,以及有关片段RHS列表中第一项的信息。在新活动的启动时(首次启动应用程序时),屏幕的RHS将填充DB中存在的先前值(“缺陷”)。这是输入的数据,最后一个应用程序被执行。