when i try to get a true/false value from a different class it seems that it is defaulting to false. here are the snippets of my code that should be the problem. the first snippet is the class i'm getting the values from, the second one is the one that is requesting that information. and at the bottom of the second class is the function that should make the class render on the apps screen but seems to not work at all every time. you should be able to understand my coding cause i practice the art of commenting profusely.
private boolean AddProb;
private boolean SubProb;
private boolean MultiProb;
private boolean DivisProb;
public int ANum = 0;
public int SNum;
public int MNum;
public int DNum;
//ProblemSelector PS = new ProblemSelector();
CheckBox checkbox1, checkbox2, checkbox3, checkbox4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_problem_selector);
checkbox1 = (CheckBox) findViewById(R.id.checkBox1);
checkbox2 = (CheckBox) findViewById(R.id.checkBox2);
checkbox3 = (CheckBox) findViewById(R.id.checkBox3);
checkbox4 = (CheckBox) findViewById(R.id.checkBox4);
/** waits for checkbox1 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
AddProb = true;
Toast.makeText(getBaseContext(), "Addition: True", Toast.LENGTH_SHORT).show();
System.out.println("Addition: True");
if(AddProb) {
Log.d("ProblemSelector.java","AddProb did successfully change to true");
} else if(!AddProb){
Log.d("ProblemSelector.java","AddProb did not successfully change to true");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 50-56");
}
} else {
AddProb = false;
Toast.makeText(getBaseContext(), "Addition: False", Toast.LENGTH_SHORT).show();
System.out.println("Addition: False");
if(AddProb) {
Log.d("ProblemSelector.java","AddProb did successfully change to false");
} else if(!AddProb) {
Log.d("ProblemSelector.java","AddProb did not successfully change to false");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 61-67");
}
}
}
});
/** waits for checkbox2 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
SubProb = true;
Toast.makeText(getBaseContext(), "Subtraction: True", Toast.LENGTH_SHORT).show();
System.out.println("Subtraction: True");
if(SubProb) {
Log.d("ProblemSelector.java","SubProb did successfully change to true");
} else if(!SubProb) {
Log.d("ProblemSelector.java","SubProb did not successfully change to true");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 82-88");
}
if(AddProb == false) {
SNum = 0;
}
else if(AddProb == true) {
SNum = 1;
}
} else {
SubProb = false;
Toast.makeText(getBaseContext(), "Subtraction: False", Toast.LENGTH_SHORT).show();
System.out.println("Subtraction: False");
if(SubProb) {
Log.d("ProblemSelector.java","SubProb did successfully change to false");
} else if(!SubProb) {
Log.d("ProblemSelector.java","SubProb did not successfully change to false");
} else {
Log.d("ProblemSelector.java","Something went horribly wrong at line: 99-105");
}
}
}
});
/** waits for checkbox3 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
checkbox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
MultiProb = true;
Toast.makeText(getBaseContext(), "Multiplication: True", Toast.LENGTH_SHORT).show();
System.out.println("Multiplication: True");
if(MultiProb) {
Log.d("ProblemSelector.java","MultiProb did successfully change to true");
} else if(!MultiProb) {
Log.d("ProblemSelector.java","MultiProb did not successfully change to true");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 120-126");
}
if(AddProb == false && SubProb == false) {
MNum = 0;
}
else if(AddProb == true && SubProb == false || AddProb == false && SubProb == true) {
MNum = 1;
}
else if(AddProb == true && SubProb == true) {
MNum = 2;
}
} else {
MultiProb = false;
Toast.makeText(getBaseContext(), "Multiplication: False", Toast.LENGTH_SHORT).show();
System.out.println("Multiplication: False");
if(MultiProb) {
Log.d("ProblemSelector.java","MultiProb did successfully change to false");
} else if(!MultiProb) {
Log.d("ProblemSelector.java","MultiProb did not successfully change to false");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 140-146");
}
}
}
});
/** waits for checkbox4 to be clicked then triggers the arguments below it **/
/** also sets the lists position if the other problems for training have been selected to practice **/
/** and determines if the value of the boolean for this function has changed successfully or not **/
checkbox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b) {
DivisProb = true;
Toast.makeText(getBaseContext(), "Division: True", Toast.LENGTH_SHORT).show();
System.out.println("Division: True");
if(DivisProb) {
Log.d("ProblemSelector.java","DivisProb did successfully change to true");
} else if(!DivisProb) {
Log.d("ProblemSelector.java","DivisProb did not successfully change to true");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 162-168");
}
if(AddProb == false && SubProb == false && MultiProb == false) {
DNum = 0;
}
else if(AddProb == true && SubProb == false && MultiProb == false || AddProb == false && SubProb == true && MultiProb == false || AddProb == false && SubProb == false && MultiProb == true) {
DNum = 1;
}
else if(AddProb == true && SubProb == true && MultiProb == false || AddProb == false && SubProb == true && MultiProb == true || AddProb == true && SubProb == false && MultiProb == true) {
DNum = 2;
}
else if(AddProb == true && SubProb == true && MultiProb == true) {
DNum = 3;
}
} else {
DivisProb = false;
Toast.makeText(getBaseContext(), "Division: False", Toast.LENGTH_SHORT).show();
System.out.println("Division: False");
if(DivisProb) {
Log.d("ProblemSelector.java","DivisProb did successfully change to false");
} else if(!DivisProb) {
Log.d("ProblemSelector.java","DivisProb did not successfully change to false");
} else {
Log.e("ProblemSelector.java","Something went horribly wrong at line: 184-189");
}
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_problem_selector, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/** this is called when the user hits the continue button **/
public void DifficultyMenu(View view) {
String S1 = String.valueOf(AddProb);
Log.d("ProblemSelector.java","AddProb: " + S1);
Intent DifficultyView = new Intent(this, DifficultyMenu.class);
//DifficultyView.putExtra("addProb", PS.AddProb);
//DifficultyView.putExtra("subProb", PS.SubProb);
//DifficultyView.putExtra("multiProb", PS.MultiProb);
//DifficultyView.putExtra("divisProb", PS.DivisProb);
startActivity(DifficultyView);
}
/** this converts the 1st version bools to 2nd version bools and outputs the values to the command line **/
public boolean AddP = AddProb;
public boolean SubP = SubProb;
public boolean MultiP = MultiProb;
public boolean DivisP = DivisProb;
}
here is the second class.
private boolean AddP = PS.AddP;
private boolean SubP = PS.SubP;
private boolean MultiP = PS.MultiP;
private boolean DivisP = PS.DivisP;
private int ANum = PS.ANum;
private int SNum = PS.SNum;
private int MNum = PS.MNum;
private int DNum = PS.DNum;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_difficulty_menu);
// here you'll retrieve the data sent...you can google how to do that.
// get the list view
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// List view Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// List view Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// List view Group collapsed listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// List view on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT)
.show();
/** converts the selected number in the expandable list to a usable integer variable **/
/** also detects if a Difficulty has been selected for each for of problem to practice **/
/** also gives an error to debug console level if something unexpected has happened **/
if(listDataHeader.get(groupPosition).equals("AdditionDifficulty")) {
String St1 = listDataHeader.get(childPosition);
int AddDiff = Integer.parseInt(St1);
if(PS.AddP) {
AChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 123 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("SubtractionDifficulty")) {
String St2 = listDataHeader.get(childPosition);
int SubDiff = Integer.parseInt(St2);
if(PS.SubP) {
SChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 132 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("MultiplicationDifficulty")) {
String St3 = listDataHeader.get(childPosition);
int MultiDIff = Integer.parseInt(St3);
if(PS.MultiP) {
MChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 141 : for some reason this seems to have happened");
}
}
else if(listDataHeader.get(groupPosition).equals("DivisionDifficulty")) {
String St4 = listDataHeader.get(childPosition);
int DivisDiff = Integer.parseInt(St4);
if(PS.DivisP) {
DChecked = true;
} else {
Log.e("DifficultyMenu.java","Somehow got to line: 150 : for some reason this seems to have happened");
}
}
else {
Log.e("DifficultyMenu.java","could not parse a group position when user selected a field");
}
return false;
}
});
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<>();
listDataChild = new HashMap<>();
// Adding child data
if(AddP) { listDataHeader.add("AdditionDifficulty"); }
if(SubP) { listDataHeader.add("SubtractionDifficulty"); }
if(MultiP) { listDataHeader.add("MultiplicationDifficulty"); }
if(DivisP) { listDataHeader.add("DivisionDifficulty"); }
System.out.println(listDataHeader);
/** this removes fields that the user has not selected to practice **/
// if(!PS.AddProb) { listDataHeader.remove("AdditionDifficulty"); }
// if(!PS.SubProb) { listDataHeader.remove("SubtractionDifficulty"); }
// if(!PS.MultiProb) { listDataHeader.remove("MultiplicationDifficulty"); }
// if(!PS.DivisProb) { listDataHeader.remove("DivisionDifficulty"); }
// Adding child data
List<String> AdditionDifficulty = new ArrayList<>();
while (true) {
if (T1 < 11) {
String S1 = Integer.toString(T1);
AdditionDifficulty.add(S1);
T1++;
} else {
break;
}
}
List<String> SubtractionDifficulty = new ArrayList<>();
while (true) {
if (T2 < 11) {
String S2 = Integer.toString(T2);
SubtractionDifficulty.add(S2);
T2++;
} else {
break;
}
}
List<String> MultiplicationDifficulty = new ArrayList<>();
while (true) {
if (T3 < 11) {
String S3 = Integer.toString(T3);
MultiplicationDifficulty.add(S3);
T3++;
} else {
break;
}
}
List<String> DivisionDifficulty = new ArrayList<>();
while (true) {
if (T4 < 11) {
String S4 = Integer.toString(T4);
DivisionDifficulty.add(S4);
T4++;
} else {
break;
}
}
/** this draws out the Expandable lists **/
if(AddP) {
listDataChild.put(listDataHeader.get(ANum), AdditionDifficulty);
} else {
Log.d("DifficultyMenu.java","Something went wrong at line: 230");
}
if(SubP) {
listDataChild.put(listDataHeader.get(SNum), SubtractionDifficulty);
} else {
Log.d("DifficultyMenu.java","Something went wrong at line: 231");
}
if(MultiP) {
listDataChild.put(listDataHeader.get(MNum), MultiplicationDifficulty);
} else {Log.d("DifficultyMenu.java","Something went wrong at line: 232");
}
if(DivisP) {
listDataChild.put(listDataHeader.get(DNum), DivisionDifficulty);
} else {Log.d("DifficultyMenu.java","Something went wrong at line: 233");
}
}
Related
I have implemented recycler view in the following manner :
now on the click of any one of the rows, the view is expanded like this :
now the problem i am facing is that when i try to expand the last item of the recycler view , the view is expanded but we cannot understand as the recycler view does not scroll up. so it is expaned in real but since it is below the screen the user thinks that nothing has happened.
Like in the 1st image if we click on the last item, i.e. photograph the row is expanded but we donot understand untill we actually scroll it up like this :
so now how do i acheive this ? i mean if the last item on the screen is expanded how to i scroll it a bit up so the user understands the difference.
CODE :
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof ViewHolder)
{
final ViewHolder bodyholder = (ViewHolder) holder;
if (UtilInsta.PendingDoc.get(position).name.length() == 0) {
pd = new InstaDrawer();
bodyholder.penddoc_tv.setText(UtilInsta.PendingDoc.get(position).DOC_NAME);
if (UtilInsta.PendingDoc.get(position).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
bodyholder.pending_row.setId(position);
bodyholder.pending_row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// crop(position);
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (bodyholder.pend_ll.getVisibility() == View.VISIBLE) {
UtilInsta.PendingDoc.get(v.getId()).option = false;
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
if (bodyholder.remarks_layout.getVisibility() == View.VISIBLE) {
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = false;
UtilInsta.PendingDoc.get(v.getId()).unable_chek = false;
}
} else {
bodyholder.pend_ll.setVisibility(View.VISIBLE);
// setHide(v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
UtilInsta.PendingDoc.get(v.getId()).option = true;
if (UtilInsta.PendingDoc.get(v.getId()).MIN_DOC == "Y") {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
}
}
if(expandedpos>=0 && expandedpos!=v.getId())
{
int prev = expandedpos;
notifyItemChanged(prev);
}
expandedpos = v.getId();
}
});
// holder.acct_name_tv.setText(pendingDocLists.get(position).CUST_NAME);
bodyholder.camera.setId(position);
bodyholder.camera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
if (Util.isNetworkConnected(con))
DocumentInfo(0, v.getId());
else
Util.shownointernet(con);
}
else {
UtilInsta.setFILE_NAME(con, "");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
( con.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || con.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)){
ActivityCompat.requestPermissions(((Activity)con),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, com.app.hdfc.Manifest.permission.CAMERA},
MyConstants.READ_EXTERNAL_STORAGE_PERMISSION_CAM);
}
else
{
if(UtilInsta.PendingDoc.get(v.getId()).DOC_NAME.equalsIgnoreCase("Photograph"))
{
Intent intent = new Intent(con, FrontCamera.class);
UtilInsta.CUST_NO = UtilInsta.PendingDoc.get(v.getId()).CUST_NO;
(con).startActivity(intent);
((Activity)con).finish();
}else {
Intent intent = new Intent(con, CroppingActivity.class);
intent.putExtra("camera_gallery", 0);
intent.putExtra("fromRecycler", true);
intent.putExtra("position", v.getId());
intent.putExtra("DOC_NAME", UtilInsta.PendingDoc.get(v.getId()).DOC_NAME);
UtilInsta.doc_name = UtilInsta.PendingDoc.get(v.getId()).DOC_NAME;
Log.d("Recycler", UtilInsta.doc_name);
intent.putExtra("CUST_NO", UtilInsta.PendingDoc.get(v.getId()).CUST_NO);
(con).startActivity(intent);
((Activity) con).finish();
}
}
}
}
});
bodyholder.gallery.setId(position);
bodyholder.gallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
InstaDrawer.pendingDocList= UtilInsta.PendingDoc.get(v.getId());
UtilInsta.setPosition(con, v.getId());
if (UtilInsta.PendingDoc.get(v.getId()).ADDININFO_FLAG.equalsIgnoreCase("Y"))
if(Util.isNetworkConnected(con))
DocumentInfo(1, v.getId());
else
Util.shownointernet(con);
else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
con.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(((Activity)con),
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MyConstants.READ_EXTERNAL_STORAGE_PERMISSION);
}
else {
UtilInsta.setFILE_NAME(con, "");
Intent intent = new Intent(con, CroppingActivity.class);
intent.putExtra("camera_gallery", 1);
intent.putExtra("fromRecycler", true);
intent.putExtra("position", v.getId());
intent.putExtra("DOC_NAME", UtilInsta.PendingDoc.get(v.getId()).DOC_NAME);
UtilInsta.doc_name = UtilInsta.PendingDoc.get(v.getId()).DOC_NAME;
Log.d("Recycler", UtilInsta.doc_name);
intent.putExtra("CUST_NO", UtilInsta.PendingDoc.get(v.getId()).CUST_NO);
(con).startActivity(intent);
((Activity) con).finish();
}
}
}
});
if (UtilInsta.PendingDoc.get(position).MIN_DOC.equalsIgnoreCase("Y")) {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
} else {
bodyholder.provie_later.setVisibility(View.VISIBLE);
bodyholder.unable_submit.setVisibility(View.VISIBLE);
}
bodyholder.provie_later.setId(position);
bodyholder.provie_later.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (remark == 1) {
remark = 0;
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = false;
} else if (remark == 0 || remark == 2) {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
remark = 1;
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(v.getId()).will_chek = true;
}
}
});
bodyholder.unable_submit.setId(position);
bodyholder.unable_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (remark == 2) {
remark = 0;
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(v.getId()).unable_chek = false;
} else if (remark == 0 || remark == 1) {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
remark = 2;
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(v.getId()).unable_chek = true;
}
}
});
bodyholder.tv_clickforkyc.setId(position);
bodyholder.tv_clickforkyc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (Util.isNetworkConnected(con))
DocumentInfo(2, v.getId()); // 2 for kyc list
else
Util.shownointernet(con);
}
});
bodyholder.remarks_submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String remark_str = bodyholder.remarks_edittext.getText().toString().trim();
if (remark_str.equalsIgnoreCase("")) {
Toast.makeText(con, "Please enter some remark", Toast.LENGTH_LONG).show();
} else if (remark_str.length() > 100) {
Toast.makeText(con, "Please enter remark less than 100 characters", Toast.LENGTH_LONG).show();
} else {
//Toast.makeText(con, "Remark : " + remark + " Submitted", Toast.LENGTH_LONG).show();
String remarktype = "";
if (remark == 1) {
remarktype = "PROVIDE_LATER";
} else if (remark == 2) {
remarktype = "NOT_AVAILABLE";
}
Log.e("Remarktype", remarktype + "1 " + remark);
if(Util.isNetworkConnected(con)) {
uploddoc(remarktype, remark_str);
bodyholder.remarks_edittext.setText("");
}
else
Util.shownointernet(con);
bodyholder.remarks_layout.setVisibility(View.GONE);
bodyholder.pend_ll.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).option = false;
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
}
});
// if (!UtilInsta.PendingDoc.get(position).REMARKS.equalsIgnoreCase("")) {
// bodyholder.remarks_tv.setVisibility(View.VISIBLE);
// bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
if (UtilInsta.PendingDoc.get(position).STATUS.equalsIgnoreCase("NOT_AVAILABLE")) {
bodyholder.remarks_tv.setVisibility(View.VISIBLE);
bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_edittext.setText(UtilInsta.PendingDoc.get(position).REMARKS);
UtilInsta.PendingDoc.get(position).unable_chek =true;
} else if (UtilInsta.PendingDoc.get(position).STATUS.equalsIgnoreCase("PROVIDE_LATER")) {
bodyholder.remarks_tv.setVisibility(View.VISIBLE);
bodyholder.remarks_tv.setText("*Remark - " + UtilInsta.PendingDoc.get(position).REMARKS);
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
bodyholder.remarks_edittext.setText(UtilInsta.PendingDoc.get(position).REMARKS);
UtilInsta.PendingDoc.get(position).will_chek =true;
}
else {
bodyholder.remarks_tv.setVisibility(View.GONE);
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_edittext.setText("");
}
bodyholder.pending_row.setVisibility(View.VISIBLE);
bodyholder.acct_name_tv.setVisibility(View.GONE);
if (UtilInsta.PendingDoc.get(position).unable_chek) {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.unable_submit.setImageResource(R.drawable.circle2_hover);
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(position).unable_chek = true;
} else {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).unable_chek = false;
}
if (UtilInsta.PendingDoc.get(position).will_chek) {
bodyholder.unable_submit.setImageResource(R.drawable.circle2);
bodyholder.provie_later.setImageResource(R.drawable.circle1_hover);
bodyholder.remarks_layout.setVisibility(View.VISIBLE);
UtilInsta.PendingDoc.get(position).will_chek = true;
} else {
bodyholder.provie_later.setImageResource(R.drawable.circle1);
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).will_chek = false;
}
if (UtilInsta.PendingDoc.get(position).option) {
bodyholder.pend_ll.setVisibility(View.VISIBLE);
if (UtilInsta.PendingDoc.get(position).ADDININFO_FLAG.equalsIgnoreCase("Y")) {
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
} else {
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
UtilInsta.PendingDoc.get(position).option = true;
if (UtilInsta.PendingDoc.get(position).MIN_DOC == "Y") {
bodyholder.provie_later.setVisibility(View.GONE);
bodyholder.unable_submit.setVisibility(View.GONE);
}
} else {
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
if (bodyholder.remarks_layout.getVisibility() == View.VISIBLE) {
bodyholder.remarks_layout.setVisibility(View.GONE);
UtilInsta.PendingDoc.get(position).will_chek = false;
UtilInsta.PendingDoc.get(position).unable_chek = false;
}
}
} else if (UtilInsta.PendingDoc.get(position).name.length() > 0) {
bodyholder.pending_row.setVisibility(View.GONE);
bodyholder.acct_name_tv.setVisibility(View.VISIBLE);
bodyholder.acct_name_tv.setText(UtilInsta.PendingDoc.get(position).name);
//continue comeback;
}
if(expandedpos == position)
{
bodyholder.pend_ll.setVisibility(View.VISIBLE);
if(UtilInsta.PendingDoc.get(position).option)
bodyholder.tv_clickforkyc.setVisibility(View.VISIBLE);
else
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}else
{
bodyholder.pend_ll.setVisibility(View.GONE);
bodyholder.tv_clickforkyc.setVisibility(View.GONE);
}
}else if (holder instanceof FooterViewHoldrer){
FooterViewHoldrer footerViewHoldrer = (FooterViewHoldrer) holder;
if(UtilInsta.PendingDoc.size()==0)
{
footerViewHoldrer.empty_pendingdoc.setVisibility(View.VISIBLE);
footerViewHoldrer.pending_continue.setVisibility(View.GONE);
footerViewHoldrer.loan_sanctioned.setVisibility(View.GONE);
}
else
{
footerViewHoldrer.empty_pendingdoc.setVisibility(View.GONE);
footerViewHoldrer.pending_continue.setVisibility(View.VISIBLE);
footerViewHoldrer.loan_sanctioned.setVisibility(View.VISIBLE);
}
if(submit_activate)
{
footerViewHoldrer.pending_continue.setBackgroundResource(R.drawable.background_button);
}else
{
footerViewHoldrer.pending_continue.setBackgroundResource(R.color.myblack);
}
footerViewHoldrer.pending_continue.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(submit_activate) {
// Toast.makeText(con,"Button Activated.",Toast.LENGTH_SHORT).show();
if(Util.isNetworkConnected(con))
new UpdateStep().execute();
else
Util.shownointernet(con);
}else
{
Toast.makeText(con,"Submit/Remark all Documents",Toast.LENGTH_SHORT).show();
}
}
});
}
}
Try This:
yourRecyclerView.scrollToPosition(position);
the variable position will be having the value of the expanded position.
In android , i create a application based on RFID Card Reader on mobile. While i tapping Card on RFID Reader it generates same value at many times until the card untapped from the reader.
I want to show only one value per tapping card on RFID reader. Here i place my code and Sample snapshot of my application.
Guide me and tell solution for my problem.
public static MediaPlayer mp;
FT_Device ftDev = null;
int DevCount = -1;
int currentIndex = -1;
int openIndex = 0;
/*graphical objects*/
EditText readText;
Button readEnButton;
static int iEnableReadFlag = 1;
/*local variables*/
int baudRate; /*baud rate*/
byte stopBit; /*1:1stop bits, 2:2 stop bits*/
byte dataBit; /*8:8bit, 7: 7bit*/
byte parity; /* 0: none, 1: odd, 2: even, 3: mark, 4: space*/
byte flowControl; /*0:none, 1: flow control(CTS,RTS)*/
int portNumber; /*port number*/
long wait_sec=3000;
byte[] readData; //similar to data.
public static final int readLength = 1024; // changed length from 512
public int iavailable = 0;
char[] readDataToText;
//char readDataToTextSudha;
public boolean bReadThreadGoing = false;
public readThread read_thread;
public static D2xxManager ftD2xx = null;
boolean uart_configured = false;
// Empty Constructor
public MainActivity() {
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
readData = new byte[readLength];
readDataToText = new char[readLength];
//readDataToTextSudha = new char;
readText = (EditText) findViewById(R.id.ReadValues);
readText.setInputType(0);
readEnButton = (Button) findViewById(R.id.readEnButton);
baudRate = 9600;
/* default is stop bit 1 */
stopBit = 1;
/* default data bit is 8 bit */
dataBit = 8;
/* default is none */
parity = 0;
/* default flow control is is none */
flowControl = 0;
portNumber = 1;
try {
ftD2xx = D2xxManager.getInstance(this);
} catch (D2xxManager.D2xxException ex) {
ex.printStackTrace();
}
//Opening Coding
if (DevCount <= 0) {
createDeviceList();
} else {
connectFunction();
}
//Configuration coding
if (DevCount <= 0 || ftDev == null) {
Toast.makeText(getApplicationContext(), "Device not open yet...", Toast.LENGTH_SHORT).show();
} else {
SetConfig(baudRate, dataBit, stopBit, parity, flowControl);
}
readEnButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (DevCount <= 0 || ftDev == null) {
Toast.makeText(getApplicationContext(), "Device not open yet...", Toast.LENGTH_SHORT).show();
} else if (uart_configured == false) {
Toast.makeText(getApplicationContext(), "UART not configure yet...", Toast.LENGTH_SHORT).show();
return;
} else {
EnableRead();
}
}
});
}
public void EnableRead() {
iEnableReadFlag = (iEnableReadFlag + 1) % 2;
if (iEnableReadFlag == 1) {
ftDev.purge((byte) (D2xxManager.FT_PURGE_TX));
ftDev.restartInTask();
readEnButton.setText("Read Enabled");
Toast.makeText(getApplicationContext(),"Read Enabled",Toast.LENGTH_LONG).show();
} else {
ftDev.stopInTask();
readEnButton.setText("Read Disabled");
Toast.makeText(getApplicationContext(),"Read Disabled",Toast.LENGTH_LONG).show();
}
}
public void createDeviceList() {
int tempDevCount = ftD2xx.createDeviceInfoList(getApplicationContext());
if (tempDevCount > 0) {
if (DevCount != tempDevCount) {
DevCount = tempDevCount;
updatePortNumberSelector();
}
} else {
DevCount = -1;
currentIndex = -1;
}
};
public void disconnectFunction() {
DevCount = -1;
currentIndex = -1;
bReadThreadGoing = false;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (ftDev != null) {
synchronized (ftDev) {
if (true == ftDev.isOpen()) {
ftDev.close();
}
}
}
}
public void connectFunction() {
int tmpProtNumber = openIndex + 1;
if (currentIndex != openIndex) {
if (null == ftDev) {
ftDev = ftD2xx.openByIndex(getApplicationContext(), openIndex);
} else {
synchronized (ftDev) {
ftDev = ftD2xx.openByIndex(getApplicationContext(), openIndex);
}
}
uart_configured = false;
} else {
Toast.makeText(getApplicationContext(), "Device port " + tmpProtNumber + " is already opened", Toast.LENGTH_LONG).show();
return;
}
if (ftDev == null) {
Toast.makeText(getApplicationContext(), "open device port(" + tmpProtNumber + ") NG, ftDev == null", Toast.LENGTH_LONG).show();
return;
}
if (true == ftDev.isOpen()) {
currentIndex = openIndex;
Toast.makeText(getApplicationContext(), "open device port(" + tmpProtNumber + ") OK", Toast.LENGTH_SHORT).show();
if (false == bReadThreadGoing) {
read_thread = new readThread(handler);
read_thread.start();
bReadThreadGoing = true;
}
} else {
Toast.makeText(getApplicationContext(), "open device port(" + tmpProtNumber + ") NG", Toast.LENGTH_LONG).show();
}
}
public void updatePortNumberSelector() {
if (DevCount == 2) {
Toast.makeText(getApplicationContext(), "2 port device attached", Toast.LENGTH_SHORT).show();
} else if (DevCount == 4) {
Toast.makeText(getApplicationContext(), "4 port device attached", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "1 port device attached", Toast.LENGTH_SHORT).show();
}
}
public void SetConfig(int baud, byte dataBits, byte stopBits, byte parity, byte flowControl) {
if (ftDev.isOpen() == false) {
Log.e("j2xx", "SetConfig: device not open");
return;
}
ftDev.setBitMode((byte) 0, D2xxManager.FT_BITMODE_RESET);
ftDev.setBaudRate(baud);
ftDev.setDataCharacteristics(dataBits, stopBits, parity);
uart_configured = true;
Toast.makeText(getApplicationContext(), "Config done", Toast.LENGTH_SHORT).show();
}
final Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
if (iavailable > 0) {
mp = MediaPlayer.create(MainActivity.this, R.raw.beep);
mp.start();
readText.append(String.copyValueOf(readDataToText, 0, iavailable));
}
}
};
private class readThread extends Thread {
Handler mHandler;
readThread(Handler h) {
mHandler = h;
this.setPriority(Thread.MIN_PRIORITY);
}
#Override
public void run() {
int i;
while (true == bReadThreadGoing) {
try {
Thread.sleep(1000); //changed
} catch (InterruptedException e) {
}
synchronized (ftDev) {
iavailable = ftDev.getQueueStatus();
if (iavailable > 0) {
if (iavailable > readLength) {
iavailable = readLength;
}
ftDev.read(readData, iavailable,wait_sec);
for (i = 0; i < iavailable; i++) {
readDataToText[i] = (char) readData[i];
}
Message msg = mHandler.obtainMessage();
mHandler.sendMessage(msg);
}
}
}
}
}
#Override
public void onResume() {
super.onResume();
DevCount = 0;
createDeviceList();
if (DevCount > 0) {
connectFunction();
SetConfig(baudRate, dataBit, stopBit, parity, flowControl);
}
}
}
My problem would snapped here
Getting Value continuously from Reader
I want this type of value when i tap the card
If i tap some other cards, old card value replaces from the new one.
Guide me.
Thanks in Advance
I got the answer by using of Threads. When the card tapping it get some values after sleep of one or two seconds only the next value have to get from the reader.
public void run() {
int i;
while (true == bReadThreadGoing) { // Means Make sure , getting value from Reader
try {
Thread.sleep(1000); // Wait for a second to get another value.
clearText(); //clear the old value and get new value.
} catch (InterruptedException e) {
}
And clearing the edittext by using this command.
public void clearText() {
runOnUiThread(new Runnable() {
public void run() {
readText.setText("");
}
});
}
public class Demo extends LayoutGameActivity implements SampleApplicationControl,SampleAppMenuInterface {
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
private static final float AUTOWRAP_WIDTH = 720 - 50 - 50;
private EditText mEditText;
private Font mFont;
private Text mText;
private Line mRight;
private Line mLeft;
private static final String LOGTAG = "ImageTargets";
SampleApplicationSession vuforiaAppSession;
private DataSet mCurrentDataset;
private int mCurrentDatasetSelectionIndex = 0;
private int mStartDatasetsIndex = 0;
private int mDatasetsNumber = 0;
private ArrayList<String> mDatasetStrings = new ArrayList<String>();
// Our OpenGL view:
private SampleApplicationGLView mGlView;
// Our renderer:
private ImageTargetRenderer mRenderer;
private GestureDetector mGestureDetector;
// The textures we will use for rendering:
private Vector<Texture> mTextures;
private boolean mSwitchDatasetAsap = false;
private boolean mFlash = false;
private boolean mContAutofocus = false;
private boolean mExtendedTracking = false;
private View mFlashOptionView;
private RelativeLayout mUILayout;
private SampleAppMenu mSampleAppMenu;
LoadingDialogHandler loadingDialogHandler = new LoadingDialogHandler(this);
// Alert Dialog used to display SDK errors
private AlertDialog mErrorDialog;
boolean mIsDroidDevice = false;
// Called when the activity first starts or the user navigates back to an
// activity.
// Process Single Tap event to trigger autofocus
private class GestureListener extends
GestureDetector.SimpleOnGestureListener
{
// Used to set autofocus one second after a manual focus is triggered
private final Handler autofocusHandler = new Handler();
#Override
public boolean onDown(MotionEvent e)
{
return true;
}
#Override
public boolean onSingleTapUp(MotionEvent e)
{
// Generates a Handler to trigger autofocus
// after 1 second
autofocusHandler.postDelayed(new Runnable()
{
public void run()
{
boolean result = CameraDevice.getInstance().setFocusMode(
CameraDevice.FOCUS_MODE.FOCUS_MODE_TRIGGERAUTO);
if (!result)
Log.e("SingleTapUp", "Unable to trigger focus");
}
}, 1000L);
return true;
}
}
// We want to load specific textures from the APK, which we will later use
// for rendering.
private void loadTextures()
{
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBrass.png",
getAssets()));
mTextures.add(Texture.loadTextureFromApk("TextureTeapotBlue.png",
getAssets()));
mTextures.add(Texture.loadTextureFromApk("TextureTeapotRed.png",
getAssets()));
mTextures.add(Texture.loadTextureFromApk("ImageTargets/Buildings.jpeg",
getAssets()));
}
// Called when the activity will start interacting with the user.
#Override
protected void onResume()
{
Log.d(LOGTAG, "onResume");
super.onResume();
vuforiaAppSession = new SampleApplicationSession(this);
startLoadingAnimation();
mDatasetStrings.add("StonesAndChips.xml");
mDatasetStrings.add("Tarmac.xml");
// mDatasetStrings.add("my_first.xml");
vuforiaAppSession
.initAR(this, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mGestureDetector = new GestureDetector(this, new GestureListener());
// Load any sample specific textures:
mTextures = new Vector<Texture>();
loadTextures();
mIsDroidDevice = android.os.Build.MODEL.toLowerCase().startsWith(
"droid");
// This is needed for some Droid devices to force portrait
if (mIsDroidDevice)
{
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
try
{
vuforiaAppSession.resumeAR();
} catch (SampleApplicationException e)
{
Log.e(LOGTAG, e.getString());
}
// Resume the GL view:
if (mGlView != null)
{
mGlView.setVisibility(View.VISIBLE);
mGlView.onResume();
}
}
// Callback for configuration changes the activity handles itself
#Override
public void onConfigurationChanged(Configuration config)
{
Log.d(LOGTAG, "onConfigurationChanged");
super.onConfigurationChanged(config);
vuforiaAppSession.onConfigurationChanged();
}
// Called when the system is about to start resuming a previous activity.
#Override
protected void onPause()
{
Log.d(LOGTAG, "onPause");
super.onPause();
if (mGlView != null)
{
mGlView.setVisibility(View.INVISIBLE);
mGlView.onPause();
}
// Turn off the flash
if (mFlashOptionView != null && mFlash)
{
// OnCheckedChangeListener is called upon changing the checked state
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
((Switch) mFlashOptionView).setChecked(false);
} else
{
((CheckBox) mFlashOptionView).setChecked(false);
}
}
try
{
vuforiaAppSession.pauseAR();
} catch (SampleApplicationException e)
{
Log.e(LOGTAG, e.getString());
}
}
// The final call you receive before your activity is destroyed.
#Override
protected void onDestroy()
{
Log.d(LOGTAG, "onDestroy");
super.onDestroy();
try
{
vuforiaAppSession.stopAR();
} catch (SampleApplicationException e)
{
Log.e(LOGTAG, e.getString());
}
// Unload texture:
mTextures.clear();
mTextures = null;
System.gc();
}
// Initializes AR application components.
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
}
private void startLoadingAnimation()
{
LayoutInflater inflater = LayoutInflater.from(this);
mUILayout = (RelativeLayout) inflater.inflate(R.layout.camera_overlay,
null, false);
mUILayout.setVisibility(View.VISIBLE);
mUILayout.setBackgroundColor(Color.BLACK);
// Gets a reference to the loading dialog
loadingDialogHandler.mLoadingDialogContainer = mUILayout
.findViewById(R.id.loading_indicator);
// Shows the loading indicator at start
loadingDialogHandler
.sendEmptyMessage(LoadingDialogHandler.SHOW_LOADING_DIALOG);
// Adds the inflated layout to the view
addContentView(mUILayout, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
}
// Methods to load and destroy tracking data.
#Override
public boolean doLoadTrackersData()
{
TrackerManager tManager = TrackerManager.getInstance();
ObjectTracker objectTracker = (ObjectTracker) tManager
.getTracker(ObjectTracker.getClassType());
if (objectTracker == null)
return false;
if (mCurrentDataset == null)
mCurrentDataset = objectTracker.createDataSet();
if (mCurrentDataset == null)
return false;
if (!mCurrentDataset.load(
mDatasetStrings.get(mCurrentDatasetSelectionIndex),
STORAGE_TYPE.STORAGE_APPRESOURCE))
return false;
if (!objectTracker.activateDataSet(mCurrentDataset))
return false;
int numTrackables = mCurrentDataset.getNumTrackables();
for (int count = 0; count < numTrackables; count++)
{
Trackable trackable = mCurrentDataset.getTrackable(count);
if(isExtendedTrackingActive())
{
trackable.startExtendedTracking();
}
String name = "Current Dataset : " + trackable.getName();
trackable.setUserData(name);
Log.d(LOGTAG, "UserData:Set the following user data "
+ (String) trackable.getUserData());
}
return true;
}
#Override
public boolean doUnloadTrackersData()
{
// Indicate if the trackers were unloaded correctly
boolean result = true;
TrackerManager tManager = TrackerManager.getInstance();
ObjectTracker objectTracker = (ObjectTracker) tManager
.getTracker(ObjectTracker.getClassType());
if (objectTracker == null)
return false;
if (mCurrentDataset != null && mCurrentDataset.isActive())
{
if (objectTracker.getActiveDataSet().equals(mCurrentDataset)
&& !objectTracker.deactivateDataSet(mCurrentDataset))
{
result = false;
} else if (!objectTracker.destroyDataSet(mCurrentDataset))
{
result = false;
}
mCurrentDataset = null;
}
return result;
}
#Override
public void onInitARDone(SampleApplicationException exception)
{
if (exception == null)
{
initApplicationAR();
mRenderer.mIsActive = true;
// Now add the GL surface view. It is important
// that the OpenGL ES surface view gets added
// BEFORE the camera is started and video
// background is configured.
addContentView(mGlView, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
// Sets the UILayout to be drawn in front of the camera
mUILayout.bringToFront();
// Sets the layout background to transparent
mUILayout.setBackgroundColor(Color.TRANSPARENT);
try
{
vuforiaAppSession.startAR(CameraDevice.CAMERA.CAMERA_DEFAULT);
} catch (SampleApplicationException e)
{
Log.e(LOGTAG, e.getString());
}
boolean result = CameraDevice.getInstance().setFocusMode(
CameraDevice.FOCUS_MODE.FOCUS_MODE_CONTINUOUSAUTO);
if (result)
mContAutofocus = true;
else
Log.e(LOGTAG, "Unable to enable continuous autofocus");
mSampleAppMenu = new SampleAppMenu(this, this, "Image Targets",
mGlView, mUILayout, null);
setSampleAppMenuSettings();
} else
{
Log.e(LOGTAG, exception.getString());
showInitializationErrorMessage(exception.getString());
}
}
// Shows initialization error messages as System dialogs
public void showInitializationErrorMessage(String message)
{
final String errorMessage = message;
runOnUiThread(new Runnable()
{
public void run()
{
if (mErrorDialog != null)
{
mErrorDialog.dismiss();
}
// Generates an Alert Dialog to show the error message
AlertDialog.Builder builder = new AlertDialog.Builder(
Demo.this);
builder
.setMessage(errorMessage)
.setTitle(getString(R.string.INIT_ERROR))
.setCancelable(false)
.setIcon(0)
.setPositiveButton(getString(R.string.button_OK),
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
finish();
}
});
mErrorDialog = builder.create();
mErrorDialog.show();
}
});
}
#Override
public void onQCARUpdate(State state)
{
if (mSwitchDatasetAsap)
{
mSwitchDatasetAsap = false;
TrackerManager tm = TrackerManager.getInstance();
ObjectTracker ot = (ObjectTracker) tm.getTracker(ObjectTracker
.getClassType());
if (ot == null || mCurrentDataset == null
|| ot.getActiveDataSet() == null)
{
Log.d(LOGTAG, "Failed to swap datasets");
return;
}
doUnloadTrackersData();
doLoadTrackersData();
}
}
#Override
public boolean doInitTrackers()
{
// Indicate if the trackers were initialized correctly
boolean result = true;
TrackerManager tManager = TrackerManager.getInstance();
Tracker tracker;
// Trying to initialize the image tracker
tracker = tManager.initTracker(ObjectTracker.getClassType());
if (tracker == null)
{
Log.e(
LOGTAG,
"Tracker not initialized. Tracker already initialized or the camera is already started");
result = false;
} else
{
Log.i(LOGTAG, "Tracker successfully initialized");
}
return result;
}
#Override
public boolean doStartTrackers()
{
// Indicate if the trackers were started correctly
boolean result = true;
Tracker objectTracker = TrackerManager.getInstance().getTracker(
ObjectTracker.getClassType());
if (objectTracker != null)
objectTracker.start();
return result;
}
#Override
public boolean doStopTrackers()
{
// Indicate if the trackers were stopped correctly
boolean result = true;
Tracker objectTracker = TrackerManager.getInstance().getTracker(
ObjectTracker.getClassType());
if (objectTracker != null)
objectTracker.stop();
return result;
}
#Override
public boolean doDeinitTrackers()
{
// Indicate if the trackers were deinitialized correctly
boolean result = true;
TrackerManager tManager = TrackerManager.getInstance();
tManager.deinitTracker(ObjectTracker.getClassType());
return result;
}
#Override
public boolean onTouchEvent(MotionEvent event)
{
// Process the Gestures
if (mSampleAppMenu != null && mSampleAppMenu.processEvent(event))
return true;
return mGestureDetector.onTouchEvent(event);
}
boolean isExtendedTrackingActive()
{
return mExtendedTracking;
}
final public static int CMD_BACK = -1;
final public static int CMD_EXTENDED_TRACKING = 1;
final public static int CMD_AUTOFOCUS = 2;
final public static int CMD_FLASH = 3;
final public static int CMD_CAMERA_FRONT = 4;
final public static int CMD_CAMERA_REAR = 5;
final public static int CMD_DATASET_START_INDEX = 6;
// This method sets the menu's settings
private void setSampleAppMenuSettings()
{
SampleAppMenuGroup group;
group = mSampleAppMenu.addGroup("", false);
group.addTextItem(getString(R.string.menu_back), -1);
group = mSampleAppMenu.addGroup("", true);
group.addSelectionItem(getString(R.string.menu_extended_tracking),
CMD_EXTENDED_TRACKING, false);
group.addSelectionItem(getString(R.string.menu_contAutofocus),
CMD_AUTOFOCUS, mContAutofocus);
mFlashOptionView = group.addSelectionItem(
getString(R.string.menu_flash), CMD_FLASH, false);
CameraInfo ci = new CameraInfo();
boolean deviceHasFrontCamera = false;
boolean deviceHasBackCamera = false;
for (int i = 0; i < Camera.getNumberOfCameras(); i++)
{
Camera.getCameraInfo(i, ci);
if (ci.facing == CameraInfo.CAMERA_FACING_FRONT)
deviceHasFrontCamera = true;
else if (ci.facing == CameraInfo.CAMERA_FACING_BACK)
deviceHasBackCamera = true;
}
if (deviceHasBackCamera && deviceHasFrontCamera)
{
group = mSampleAppMenu.addGroup(getString(R.string.menu_camera),
true);
group.addRadioItem(getString(R.string.menu_camera_front),
CMD_CAMERA_FRONT, false);
group.addRadioItem(getString(R.string.menu_camera_back),
CMD_CAMERA_REAR, true);
}
group = mSampleAppMenu
.addGroup(getString(R.string.menu_datasets), true);
mStartDatasetsIndex = CMD_DATASET_START_INDEX;
mDatasetsNumber = mDatasetStrings.size();
group.addRadioItem("Stones & Chips", mStartDatasetsIndex, true);
group.addRadioItem("Tarmac", mStartDatasetsIndex + 1, false);
// group.addRadioItem("my_first", mStartDatasetsIndex + 2, false);
mSampleAppMenu.attachMenu();
}
#SuppressLint("NewApi") #Override
public boolean menuProcess(int command)
{
boolean result = true;
switch (command)
{
case CMD_BACK:
finish();
break;
case CMD_FLASH:
result = CameraDevice.getInstance().setFlashTorchMode(!mFlash);
if (result)
{
mFlash = !mFlash;
} else
{
showToast(getString(mFlash ? R.string.menu_flash_error_off
: R.string.menu_flash_error_on));
Log.e(LOGTAG,
getString(mFlash ? R.string.menu_flash_error_off
: R.string.menu_flash_error_on));
}
break;
case CMD_AUTOFOCUS:
if (mContAutofocus)
{
result = CameraDevice.getInstance().setFocusMode(
CameraDevice.FOCUS_MODE.FOCUS_MODE_NORMAL);
if (result)
{
mContAutofocus = false;
} else
{
showToast(getString(R.string.menu_contAutofocus_error_off));
Log.e(LOGTAG,
getString(R.string.menu_contAutofocus_error_off));
}
} else
{
result = CameraDevice.getInstance().setFocusMode(
CameraDevice.FOCUS_MODE.FOCUS_MODE_CONTINUOUSAUTO);
if (result)
{
mContAutofocus = true;
} else
{
showToast(getString(R.string.menu_contAutofocus_error_on));
Log.e(LOGTAG,
getString(R.string.menu_contAutofocus_error_on));
}
}
break;
case CMD_CAMERA_FRONT:
case CMD_CAMERA_REAR:
// Turn off the flash
if (mFlashOptionView != null && mFlash)
{
// OnCheckedChangeListener is called upon changing the checked state
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
((Switch) mFlashOptionView).setChecked(false);
} else
{
((CheckBox) mFlashOptionView).setChecked(false);
}
}
vuforiaAppSession.stopCamera();
try
{
vuforiaAppSession
.startAR(command == CMD_CAMERA_FRONT ? CameraDevice.CAMERA.CAMERA_FRONT
: CameraDevice.CAMERA.CAMERA_BACK);
} catch (SampleApplicationException e)
{
showToast(e.getString());
Log.e(LOGTAG, e.getString());
result = false;
}
doStartTrackers();
break;
case CMD_EXTENDED_TRACKING:
for (int tIdx = 0; tIdx < mCurrentDataset.getNumTrackables(); tIdx++)
{
Trackable trackable = mCurrentDataset.getTrackable(tIdx);
if (!mExtendedTracking)
{
if (!trackable.startExtendedTracking())
{
Log.e(LOGTAG,
"Failed to start extended tracking target");
result = false;
} else
{
Log.d(LOGTAG,
"Successfully started extended tracking target");
}
} else
{
if (!trackable.stopExtendedTracking())
{
Log.e(LOGTAG,
"Failed to stop extended tracking target");
result = false;
} else
{
Log.d(LOGTAG,
"Successfully started extended tracking target");
}
}
}
if (result)
mExtendedTracking = !mExtendedTracking;
break;
default:
if (command >= mStartDatasetsIndex
&& command < mStartDatasetsIndex + mDatasetsNumber)
{
mSwitchDatasetAsap = true;
mCurrentDatasetSelectionIndex = command
- mStartDatasetsIndex;
}
break;
}
return result;
}
private void showToast(String text)
{
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}
#Override
protected void onCreate(Bundle pSavedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(pSavedInstanceState);
}
#Override
public EngineOptions onCreateEngineOptions() {
final org.andengine.engine.camera.Camera camera = new org.andengine.engine.camera.Camera(0, 0, Demo.CAMERA_WIDTH, Demo.CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(Demo.CAMERA_WIDTH, Demo.CAMERA_HEIGHT), camera);
}
private void updateText() {
final String string = this.mEditText.getText().toString();
this.mText.setText(string);
final float left = (this.mText.getWidth() * 0.5f) - (this.mText.getLineWidthMaximum() * 0.5f);
this.mLeft.setPosition(left, 0, left, Demo.CAMERA_HEIGHT);
final float right = (this.mText.getWidth() * 0.5f) + (this.mText.getLineWidthMaximum() * 0.5f);
this.mRight.setPosition(right, 0, right, Demo.CAMERA_HEIGHT);
}
#Override
protected int getLayoutID() {
// TODO Auto-generated method stub
return R.layout.camera_overlay;
}
#Override
protected int getRenderSurfaceViewID() {
// TODO Auto-generated method stub
return R.id.textbreakexample_rendersurfaceview;
}
#Override
protected void onSetContentView() {
// TODO Auto-generated method stub
super.onSetContentView();
}
#Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws IOException {
// TODO Auto-generated method stub
}
#Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws IOException {
// TODO Auto-generated method stub
}
#Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback)
throws IOException {
// TODO Auto-generated method stub
}
}
I am using andEngine for Developing game and I also use vuforia for AR (Augmented Reality).But if i combine both the codes then i getting error as surfaceview null.
**and if it's not supported then what is the use for augmented reality object tracking in andenginre **
I'm trying to understand how to make a button that latches onto a value when it is pressed, when it's pressed again it unlatches.
My method for this is as follows:
boolean r1 = false;
boolean r2 = true;
private boolean flipFlop(boolean read, int i)
{
if(read == true)
{
if (r1 == true && r2 == false)
{
r1 = false;
r2 = true;
}
else if(r1 == false && r2 == true)
{
r1 = true;
r2 = false;
}
}
return r1;
}
flipFlop method is called under onTouch, like so:
public boolean onTouch(View view, MotionEvent motion)
{
boolean pressCheck = false;
switch(motion.getAction())
{
case MotionEvent.ACTION_UP:
{
pressCheck = flipFlop(view.isPressed(), 1);
textView.setText("State is: " + pressCheck);
}
case MotionEvent.ACTION_DOWN:
{
pressCheck = flipFlop(view.isPressed(), 1);
textView.setText("State is: " + pressCheck);
}
}
return false;
}
When clicking once, the state is set to false and doesn't change.
When double-clicking, it flipflops between the two states. Why is that?
Also, when I tried making it with an array to hold the states, it latched to true and Doesn't change when double-tapping:
private boolean[][] latch = {{false, false, false}, {true, true, true}};
public boolean flipFlop(boolean read, int i)
{
if(read == true)
{
if(latch[i][2] == true && latch[i][1] == false)
{
latch[i][1] = true;
latch[i][2] = false;
}
else if(latch[i][2] == false && latch[i][1] == true)
{
latch[i][1] = false;
latch[i][2] = true;
}
}
return latch[i][1];
}
I am working with ASYNTask. And I have used a custom progressbar. It stops working after sometime of spinning, and after that a blank(black colored) screen comes for 2 secs and then my UI for the next screen loads on.
public class LoginActivity extends Activity {
/** Variable define here. */
private EditText metLoginUserName, metLoginPassword;
private Button mbtnLogin;
private ImageView ivRegister;
private String Host, username, password;
private int Port;
private UserChatActivity xmppClient;
public static ArrayList<String> all_user = new ArrayList<String>();
public static CustomProgressDialog mCustomProgressDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginlayout);
metLoginUserName = (EditText) this.findViewById(R.id.etLoginUserName);
metLoginPassword = (EditText) this.findViewById(R.id.etLoginPassword);
mbtnLogin = (Button) findViewById(R.id.btnLogin);
ivRegister = (ImageView) findViewById(R.id.ivRegister);
/** Set the hint in username and password edittext */
metLoginUserName = CCMStaticMethod.setHintEditText(metLoginUserName,
getString(R.string.hint_username), true);
metLoginPassword = CCMStaticMethod.setHintEditText(metLoginPassword,
getString(R.string.hint_password), true);
/** Click on login button */
mbtnLogin.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
/** Login Activity */
username = metLoginUserName.getText().toString();
password = metLoginPassword.getText().toString();
CCMStaticVariable.musername = username;
CCMStaticVariable.musername = password;
if(CCMStaticMethod.isInternetAvailable(LoginActivity.this)){
LoginUserTask loginUserTask = new LoginUserTask(v.getContext());
loginUserTask.execute();
}
}
});
/** Click on forgot button */
this.findViewById(R.id.ivForgot).setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,
ForgotPassActivity.class));
}
});
/** Click on register button */
ivRegister.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,
RegisterActivity.class));
}
});
}
public class LoginUserTask extends AsyncTask<Void, Void, XMPPConnection> {
public LoginUserTask(Context context) {
super();
this.context = context;
}
private Context context;
#Override
protected void onPostExecute(XMPPConnection result) {
if (result != null) {
/**Start services*/
startService(new Intent(LoginActivity.this, UpdaterService.class));
/**Call usermenu activity*/
finish();
startActivity(new Intent(LoginActivity.this,UserMenuActivity.class));
} else {
DialogInterface.OnClickListener LoginUnSuccessOkAlertListener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
};
CCMStaticMethod.showAlert(context, "Login",
"Invalid Username or Password. Try Again !", R.drawable.unsuccess,
true, true, "Ok", LoginUnSuccessOkAlertListener, null,
null);
}
mCustomProgressDialog.dismiss();
}
#Override
protected void onPreExecute() {
mCustomProgressDialog = CustomProgressDialog.createDialog(
LoginActivity.this, "", "");
mCustomProgressDialog.show();
}
#Override
protected XMPPConnection doInBackground(Void... params) {
CCMStaticVariable.CommonConnection = XMPPConn.checkXMPPConnection(username,
password);
return CCMStaticVariable.CommonConnection;
}
}
}
UserMenuActivity
public class UserMenuActivity extends ExpandableListActivity {
private XMPPConnection connection;
String name,availability,subscriptionStatus;
TextView tv_Status;
public static final String ACTION_UPDATE = "ACTION_UPDATE";
/** Variable Define here */
private String[] data = { "View my profile", "New Multiperson Chat",
"New Broad Cast Message", "New Contact Category", "New Group",
"Invite to CCM", "Search", "Expand All", "Settings", "Help",
"Close" };
private String[] data_Contact = { "Rename Category","Move Contact to Category", "View my profile",
"New Multiperson Chat", "New Broad Cast Message",
"New Contact Category", "New Group", "Invite to CCM", "Search",
"Expand All", "Settings", "Help", "Close" };
private String[] data_child_contact = { "Open chat", "Delete Contact","View my profile",
"New Multiperson Chat", "New Broad Cast Message",
"New Contact Category", "New Group", "Invite to CCM", "Search",
"Expand All", "Settings", "Help", "Close" };
private String[] menuItem = { "Chats", "Contacts", "CGM Groups", "Pending","Request" };
private List<String> menuItemList = Arrays.asList(menuItem);
private int commonGroupPosition = 0;
private String etAlertVal;
private DatabaseHelper dbHelper;
private int categoryID, listPos;
/** New Code here.. */
private ArrayList<String> groupNames;
private ArrayList<ArrayList<ChildItems>> childs;
private UserMenuAdapter adapter;
private Object object;
private CustomProgressDialog mCustomProgressDialog;
private String[] data2 = { "PIN Michelle", "IP Call" };
private ListView mlist2;
private ImageButton mimBtnMenu;
private LinearLayout mllpopmenu;
private View popupView;
private PopupWindow popupWindow;
private AlertDialog.Builder alert;
private EditText input;
private TextView mtvUserName, mtvUserTagLine;
private ExpandableListView mExpandableListView;
public static List<CategoryDataClass> categoryList;
public static ArrayList<String> chatUser;
private boolean menuType = false;
private String childValContact="";
public static Context context;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.usermenulayout);
dbHelper = new DatabaseHelper(UserMenuActivity.this);
XMPPConn.getContactList();
connection = CCMStaticVariable.CommonConnection;
registerReceiver(UpdateList, new IntentFilter(ACTION_UPDATE));
}
#Override
public void onBackPressed() {
if (mllpopmenu.getVisibility() == View.VISIBLE) {
mllpopmenu.setVisibility(View.INVISIBLE);
} else {
if (CCMStaticVariable.CommonConnection.isConnected()) {
CCMStaticVariable.CommonConnection.disconnect();
}
super.onBackPressed();
}
}
#SuppressWarnings("unchecked")
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
if (mllpopmenu.getVisibility() == View.VISIBLE) {
mllpopmenu.setVisibility(View.INVISIBLE);
} else {
if (commonGroupPosition >= 4 && menuType == true) {
if(childValContact == ""){
mllpopmenu.setVisibility(View.VISIBLE);
mlist2.setAdapter(new ArrayAdapter(UserMenuActivity.this,
R.layout.listviewtext, R.id.tvMenuText,
data_Contact));
}else{
mllpopmenu.setVisibility(View.VISIBLE);
mlist2.setAdapter(new ArrayAdapter(UserMenuActivity.this,
R.layout.listviewtext, R.id.tvMenuText,
data_child_contact));
}
} else if (commonGroupPosition == 0) {
mllpopmenu.setVisibility(View.VISIBLE);
mlist2.setAdapter(new ArrayAdapter(UserMenuActivity.this,
R.layout.listviewtext, R.id.tvMenuText, data));
}
}
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
protected void onResume() {
super.onResume();
mCustomProgressDialog = CustomProgressDialog.createDialog(
UserMenuActivity.this, "", "");
mCustomProgressDialog.show();
new Thread(){
public void run() {
XMPPConn.getContactList();
expendableHandle.sendEmptyMessage(0);
};
}.start();
super.onResume();
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
unregisterReceiver(UpdateList);
}
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
if(groupPosition == 0){
Intent intent = new Intent(UserMenuActivity.this,UserChatActivity.class);
intent.putExtra("userNameVal",chatUser.get(childPosition));
intent.putExtra("message","");
startActivity(intent);
}else if (groupPosition == 1 && childPosition == 0) {
startActivity(new Intent(UserMenuActivity.this,
InvitetoCCMActivity.class));
} else if (groupPosition == 1 && childPosition != 0) {
Intent intent = new Intent(UserMenuActivity.this,
UserChatActivity.class);
intent.putExtra("userNameVal",
XMPPConn.mfriendList.get(childPosition - 1).friendName);
intent.putExtra("message","");
startActivity(intent);
} else if (groupPosition == 2 && childPosition == 0) {
startActivity(new Intent(UserMenuActivity.this,
CreateGroupActivity.class));
} else if (groupPosition == 2 && childPosition != 0) {
String GROUP_NAME = childs.get(groupPosition).get(childPosition)
.getName().toString();
int end = GROUP_NAME.indexOf("(");
CCMStaticVariable.groupName = GROUP_NAME.substring(0, end).trim();
startActivity(new Intent(UserMenuActivity.this,
GroupsActivity.class));
} else if (groupPosition >= 4) {
childValContact = childs.get(groupPosition).get(childPosition).getName().trim();
showToast("user==>"+childValContact, 0);
}
return false;
}
private void setExpandableListView() {
/***###############GROUP ARRAY ############################*/
final ArrayList<String> groupNames = new ArrayList<String>();
chatUser = dbHelper.getChatUser();
groupNames.add("Chats ("+chatUser.size()+")");
groupNames.add("Contacts (" + XMPPConn.mfriendList.size() + ")");
groupNames.add("CGM Groups (" + XMPPConn.mGroupList.size() + ")");
groupNames.add("Pending (1)");
XMPPConn.getGroup();
categoryList = dbHelper.getAllCategory();
/**Group From Sever*/
if (XMPPConn.mGroupList.size() > 0) {
for (int g = 0; g < XMPPConn.mGroupList.size(); g++) {
XMPPConn.getGroupContact(XMPPConn.mGroupList.get(g).groupName);
groupNames.add(XMPPConn.mGroupList.get(g).groupName + "("
+ XMPPConn.mGroupContactList.size()+ ")");
}
}
if(categoryList.size() > 0){
for (int cat = 0; cat < categoryList.size(); cat++) {
groupNames.add(categoryList.get(cat).getCategoryName()+ "(0)");
}
}
this.groupNames = groupNames;
/*** ###########CHILD ARRAY * #################*/
ArrayList<ArrayList<ChildItems>> childs = new ArrayList<ArrayList<ChildItems>>();
ArrayList<ChildItems> child = new ArrayList<ChildItems>();
if(chatUser.size() > 0){
for(int i = 0; i < chatUser.size(); i++){
child.add(new ChildItems(userName(chatUser.get(i)), "",0,null));
}
}else{
child.add(new ChildItems("--No History--", "",0,null));
}
childs.add(child);
child = new ArrayList<ChildItems>();
child.add(new ChildItems("", "",0,null));
if (XMPPConn.mfriendList.size() > 0) {
for (int n = 0; n < XMPPConn.mfriendList.size(); n++) {
child.add(new ChildItems(XMPPConn.mfriendList.get(n).friendNickName,
XMPPConn.mfriendList.get(n).friendStatus,
XMPPConn.mfriendList.get(n).friendState,
XMPPConn.mfriendList.get(n).friendPic));
}
}
childs.add(child);
/************** CGM Group Child here *********************/
child = new ArrayList<ChildItems>();
child.add(new ChildItems("", "",0,null));
if (XMPPConn.mGroupList.size() > 0) {
for (int grop = 0; grop < XMPPConn.mGroupList.size(); grop++) {
child.add(new ChildItems(
XMPPConn.mGroupList.get(grop).groupName + " ("
+ XMPPConn.mGroupList.get(grop).groupUserCount
+ ")", "",0,null));
}
}
childs.add(child);
child = new ArrayList<ChildItems>();
child.add(new ChildItems("Shuchi",
"Pending (Waiting for Authorization)",0,null));
childs.add(child);
/************************ Group Contact List *************************/
if (XMPPConn.mGroupList.size() > 0) {
for (int g = 0; g < XMPPConn.mGroupList.size(); g++) {
/** Contact List */
XMPPConn.getGroupContact(XMPPConn.mGroupList.get(g).groupName);
child = new ArrayList<ChildItems>();
for (int con = 0; con < XMPPConn.mGroupContactList.size(); con++) {
child.add(new ChildItems(
XMPPConn.mGroupContactList.get(con).friendName,
XMPPConn.mGroupContactList.get(con).friendStatus,0,null));
}
childs.add(child);
}
}
if(categoryList.size() > 0){
for (int cat = 0; cat < categoryList.size(); cat++) {
child = new ArrayList<ChildItems>();
child.add(new ChildItems("-none-", "",0,null));
childs.add(child);
}
}
this.childs = childs;
/** Set Adapter here */
adapter = new UserMenuAdapter(this, groupNames, childs);
setListAdapter(adapter);
object = this;
mlist2 = (ListView) findViewById(R.id.list2);
mimBtnMenu = (ImageButton) findViewById(R.id.imBtnMenu);
mllpopmenu = (LinearLayout) findViewById(R.id.llpopmenu);
mtvUserName = (TextView) findViewById(R.id.tvUserName);
mtvUserTagLine = (TextView) findViewById(R.id.tvUserTagLine);
//Set User name..
System.out.println("CCMStaticVariable.loginUserName==="
+ CCMStaticVariable.loginUserName);
if (!CCMStaticVariable.loginUserName.equalsIgnoreCase("")) {
mtvUserName.setText("" + CCMStaticVariable.loginUserName);
}
/** Expandable List set here.. */
mExpandableListView = (ExpandableListView) this
.findViewById(android.R.id.list);
mExpandableListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
if (parent.isGroupExpanded(groupPosition)) {
commonGroupPosition = 0;
}else{
commonGroupPosition = groupPosition;
}
String GROUP_NAME = groupNames.get(groupPosition);
int end = groupNames.get(groupPosition).indexOf("(");
String GROUP_NAME_VALUE = GROUP_NAME.substring(0, end).trim();
if (menuItemList.contains(GROUP_NAME_VALUE)) {
menuType = false;
CCMStaticVariable.groupCatName = GROUP_NAME_VALUE;
} else {
menuType = true;
CCMStaticVariable.groupCatName = GROUP_NAME_VALUE;
}
long findCatId = dbHelper.getCategoryID(GROUP_NAME_VALUE);
if (findCatId != 0) {
categoryID = (int) findCatId;
}
childValContact="";
//showToast("Clicked on==" + GROUP_NAME_VALUE, 0);
return false;
}
});
/** Click on item */
mlist2.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,long arg3) {
if (commonGroupPosition >= 4) {
if(childValContact == ""){
if (pos == 0) {
showAlertEdit(CCMStaticVariable.groupCatName);
}
/** Move contact to catgory */
if (pos == 1) {
startActivity(new Intent(UserMenuActivity.this,AddContactCategoryActivity.class));
}
}else{
if(pos == 0){
Intent intent = new Intent(UserMenuActivity.this,UserChatActivity.class);
intent.putExtra("userNameVal",childValContact);
startActivity(intent);
}
if(pos == 1){
XMPPConn.removeEntry(childValContact);
showToast("Contact deleted sucessfully", 0);
Intent intent = new Intent(UserMenuActivity.this,UserMenuActivity.class);
}
}
} else {
/** MyProfile */
if (pos == 0) {
startActivity(new Intent(UserMenuActivity.this,
MyProfileActivity.class));
}
/** New multiperson chat start */
if (pos == 1) {
startActivity(new Intent(UserMenuActivity.this,
NewMultipersonChatActivity.class));
}
/** New Broadcast message */
if (pos == 2) {
startActivity(new Intent(UserMenuActivity.this,
NewBroadcastMessageActivity.class));
}
/** Click on add category */
if (pos == 3) {
showAlertAdd();
}
if (pos == 4) {
startActivity(new Intent(UserMenuActivity.this,
CreateGroupActivity.class));
}
if (pos == 5) {
startActivity(new Intent(UserMenuActivity.this,
InvitetoCCMActivity.class));
}
if (pos == 6) {
startActivity(new Intent(UserMenuActivity.this,
SearchActivity.class));
}
if (pos == 7) {
onGroupExpand(2);
for (int i = 0; i < groupNames.size(); i++) {
mExpandableListView.expandGroup(i);
}
}
/** Click on settings */
if (pos == 8) {
startActivity(new Intent(UserMenuActivity.this,
SettingsActivity.class));
}
if (pos == 10) {
System.exit(0);
}
if (pos == 14) {
if (mllpopmenu.getVisibility() == View.VISIBLE) {
mllpopmenu.setVisibility(View.INVISIBLE);
if (popupWindow.isShowing()) {
popupWindow.dismiss();
}
} else {
mllpopmenu.setVisibility(View.VISIBLE);
mlist2.setAdapter(new ArrayAdapter(
UserMenuActivity.this,
R.layout.listviewtext, R.id.tvMenuText,
data));
}
}
}
}
});
}
/** Toast message display here.. */
private void showToast(String msg, int time) {
Toast.makeText(this, msg, time).show();
}
/** Show EditAlert Box */
private void showAlertEdit(String msg) {
alert = new AlertDialog.Builder(UserMenuActivity.this);
input = new EditText(UserMenuActivity.this);
input.setSingleLine();
input.setText(msg);
alert.setTitle("Edit Category Name");
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
etAlertVal = input.getText().toString();
/** isGroupFromServerOrMobile */
RosterGroup isGroupExists = CCMStaticVariable.CommonConnection
.getRoster().getGroup(CCMStaticVariable.groupCatName);
if (isGroupExists == null) {
dbHelper.updateCategory(categoryID, etAlertVal);
Intent intent = new Intent(UserMenuActivity.this,
UserMenuActivity.class);
startActivity(intent);
showToast("Category updated sucessfully", 0);
} else {
CCMStaticVariable.CommonConnection.getRoster()
.getGroup(CCMStaticVariable.groupCatName)
.setName(etAlertVal);
Intent intent = new Intent(UserMenuActivity.this,
UserMenuActivity.class);
startActivity(intent);
showToast("Category updated sucessfully", 0);
}
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alert.show();
}
/** ShowAlertBox Edit */
private void showAlertAdd() {
alert = new AlertDialog.Builder(UserMenuActivity.this);
input = new EditText(UserMenuActivity.this);
input.setSingleLine();
alert.setTitle("New Category Name");
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
etAlertVal = input.getText().toString();
if (!etAlertVal.equalsIgnoreCase("request")) {
long lastInsertedId = dbHelper.insertCategory(etAlertVal);
CCMStaticVariable.groupCatName = etAlertVal;
Intent intent = new Intent(UserMenuActivity.this,AddContactCategoryActivity.class);
startActivity(intent);
}
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alert.show();
}
public String showSubscriptionStatus(String friend){
return friend;
}
public String userName(String jid){
String username = "";
if(jid.contains("#")){
int index = jid.indexOf("#");
username = jid.substring(0, index);
}else{
username = jid;
}
return username;
}
/**Set expandable handler here..*/
Handler expendableHandle = new Handler(){
public void handleMessage(android.os.Message msg) {
mCustomProgressDialog.dismiss();
setExpandableListView();
};
};
BroadcastReceiver UpdateList = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(UserMenuActivity.this, "CALLED", Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
}
};
}
Please suggest me what is the problem here. I have seen so many posts and have tried a lot of things regarding the same. But It has not worked for me. Please tell me.
Thanks
This
startActivity(new Intent(LoginActivity.this,UserMenuActivity.class));
This
CCMStaticMethod.showAlert(context, "Login",
"Invalid Username or Password. Try Again !", R.drawable.unsuccess,
true, true, "Ok", LoginUnSuccessOkAlertListener, null,
null);
}
and this
mCustomProgressDialog.dismiss();
Do not perform UI events from an async task. Use activity.runOnUiThread() instead.