/*First of all i used "ListViews"(instead of TableLayout) to implement this,but that doesnot work in all sized screens.Because Large screens has extra 'Dip' value to display each character on emulator...So to solve that i use TableLayout(I implemented this code in MemoScreen.java file on 'LegelPlex' Project..) */
SampleListView.java:-
package org.Dharani.ExpandListview;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.TableLayout.LayoutParams;
public class SampleListView extends Activity {
TableLayout tablelayout;
String[] s={"Dedication means spending whatever time or energy is necessary to accomplish the task at hand. A leader inspires dedication by example, doing whatever it takes to complete the next step toward the vision. By setting an excellent example, leaders can show followers that there are no nine-to-five jobs on the team, only opportunities to achieve something great",
"Magnanimity means giving credit where it is due. A magnanimous leader ensures that credit for successes is spread as widely as possible throughout the company. Conversely, a good leader takes personal responsibility for failures. This sort of reverse magnanimity helps other people feel good about themselves and draws the team closer together. To spread the fame and take the blame is a hallmark of effective leadership",
"Leaders with humility recognize that they are no better or worse than other members of the team. A humble leader is not self-effacing but rather tries to elevate everyone. Leaders with humility also understand that their status does not make them a god. Mahatma Gandhi is a role model for Indian leaders, and he pursued a “follower-centric” leadership role."
,"Openness means being able to listen to new ideas, even if they do not conform to the usual way of thinking. Good leaders are able to suspend judgment while listening to others’ ideas, as well as accept new ways of doing things that someone else thought of. Openness builds mutual respect and trust between leaders and followers, and it also keeps the team well supplied with new ideas that can further its vision",
"venkata krishna has the above for qualities"};
boolean[] countflag={false,false,false,false,false}; //here 5 'false' values taken because String array having 5-"String" values
int[] maxlinecount={4,4,4,4,4};//here 5 '4' values taken because String array having 5-"String" values...where 4 reprasents ,max lines of each row to display More btn
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_list);
tablelayout=(TableLayout) findViewById(R.id.tablelayout);
System.out.println("size??"+s.length);
renderUI();
}
public void renderUI()
{
try {
tablelayout.removeAllViews();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<s.length;i++)
{
TableRow tr=new TableRow(this);
View genericView=null;
LayoutInflater inflater = LayoutInflater.from(this);
genericView = inflater.inflate(R.layout.sample, null);
final TextView textView1=(TextView) genericView.findViewById(R.id.textView1);
final Button morebutton=(Button) genericView.findViewById(R.id.button1);
textView1.setText(s[i]);
ViewTreeObserver vto = textView1.getViewTreeObserver();
final int c=i;
vto = textView1.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(textView1.getLineCount()>4)
{
morebutton.setVisibility(View.VISIBLE);
textView1.setMaxLines(maxlinecount[c]);
}
else{
morebutton.setVisibility(View.GONE);
}
} });
//less...
if(countflag[i])
{
morebutton.setText("less");
}
else{
morebutton.setText("more");
}
morebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/*countflag[0]=false;
countflag[1]=false;
countflag[2]=false;
countflag[3]=false;
countflag[4]=false;
maxlinecount[0]=4;
maxlinecount[1]=4;
maxlinecount[2]=4;
maxlinecount[3]=4;
maxlinecount[4]=4;*/
for(int i=0;i<s.length;i++){
countflag[i]=false;
maxlinecount[i]=4;
}
if(morebutton.getText().toString().equals("more"))
{
countflag[c]=true;
maxlinecount[c]=textView1.getLineCount();
renderUI();
}else{
countflag[c]=false;
maxlinecount[c]=4;
renderUI();
}
}
});
tr.addView(genericView);
tablelayout.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
}
}
sample_list.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/tablelayout"
android:layout_width="fill_parent"
android:shrinkColumns="0"
android:stretchColumns="0,1"
android:layout_height="wrap_content" >
</TableLayout>
</ScrollView>
</LinearLayout>
sample.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="15dip"
android:layout_marginTop="10dip"
android:maxLines="4"
android:singleLine="false"
android:textColor="@android:color/white"
android:text="" />
<Button
android:id="@+id/button1"
android:layout_marginTop="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="more" />
</LinearLayout>
----------------------------------------------------------------------------------------------------------
//example code will be end here,here below code i implemented in MemoScreen.java file of LegelPlex Proj.
package com.dharani.android.legalplex.PresentationLayer;(This code having some issues like ,When u expand the row and close that screen and again open that screen,then after some time screen(layout) will be gone)).I fixed that issue and modified code exists on below..)
import java.util.ArrayList;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableLayout.LayoutParams;
import android.widget.TableRow;
import android.widget.TextView;
import com.dharani.android.legalplex.R;
import com.dharani.android.legalplex.BusinessLayer.BLCommonOperations;
import com.dharani.android.legalplex.DataLayer.Case.clsCase;
import com.dharani.android.legalplex.DataLayer.Memo.clsMemo;
public class MemoScreen extends abstractActivity {
Bundle bundle =null;
clsCase objCase=null;
static ArrayList<clsMemo> memoArryList=null;
TableLayout tablelayout;
boolean[] countflag;
int[] maxlinecount;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.memo_screen);
getAllIds();
//code to get objects from bundle
bundle = getIntent().getExtras();
//code to get all objects using Bundle from previous activity
if(bundle!=null){
//objSearchDetail=(clsSearchDetail) bundle.getSerializable("clsSearchDetailObj");
objCase = (clsCase) bundle.getParcelable("clsCaseObj");
bundle=null;
}
if(objCase!=null){
memoArryList = new ArrayList<clsMemo>();
//code to copy CasePerson arrayList of objCase to newly created CasePersonArryList
memoArryList=(ArrayList<clsMemo>) objCase.getCaseMemos();
}
if(memoArryList!=null){
if(memoArryList.size()>0){
countflag= new boolean[memoArryList.size()];
maxlinecount=new int[memoArryList.size()];
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
renderUI();
}
}
Button addMemoButton=(Button)findViewById(R.id.addMemoButton);
addMemoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MemoScreen.this,AddMemoScreen.class);
i.putExtra("memoCaseID", objCase.getCaseID());
i.putExtra("memoCaseSLNO", objCase.getId());
startActivityForResult(i,0);
}
});
}//onCreate()..
public void memoCloseBtnClick(View v){
finish();
}
private void getAllIds() {
tablelayout=(TableLayout) findViewById(R.id.tablelayout);
}
public void renderUI()
{
try {
tablelayout.removeAllViews();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0;i<memoArryList.size();i++)
{
final TableRow tableRow=new TableRow(this);
tableRow.setClickable(true);
View genericView=null;
LayoutInflater inflater = LayoutInflater.from(this);
genericView = inflater.inflate(R.layout.memo_row, null);
final TextView memoAddedByEmpNameDateTxtViw=(TextView) genericView.findViewById(R.id.memoAddedByEmpNameDateTxtViw);
final TextView memoTextTxtViw=(TextView) genericView.findViewById(R.id.memoTextTxtViw);
final TextView memoMoreBtn=(TextView) genericView.findViewById(R.id.memoMoreBtn);
final TextView memoEditBtn=(TextView) genericView.findViewById(R.id.memoEditBtn);
final ImageView lineImageView=(ImageView)genericView.findViewById(R.id.lineImageView);
//code for hiding the line image for last row
if(i==memoArryList.size()-1)
lineImageView.setVisibility(View.GONE);
else
lineImageView.setVisibility(View.VISIBLE);
//File added by employee name on added date...
if(memoArryList.get(i).getMemoCreatedByEmployeeID()!=0 && memoArryList.get(i).getMemoAddedTimeStamp()!=null)
{
memoAddedByEmpNameDateTxtViw.setVisibility(View.VISIBLE);
BLCommonOperations objBLCommonOperations=new BLCommonOperations();
String memoAddedDate=objBLCommonOperations.DateForDisplayInUIWithProperFormat(objBLCommonOperations.convertTimeToLocalTimeZone(objBLCommonOperations.convertDateToString(memoArryList.get(i).getMemoAddedTimeStamp())));
if(memoAddedDate==null) memoAddedDate="";
memoAddedByEmpNameDateTxtViw.setText("Added By "+objBLCommonOperations.getEmployeeFirstNameLastName(memoArryList.get(i).getMemoCreatedByEmployeeID())+" on "+memoAddedDate);
objBLCommonOperations=null;
}
else{
memoAddedByEmpNameDateTxtViw.setVisibility(View.GONE);
}
memoTextTxtViw.setText(memoArryList.get(i).getMemoText());
ViewTreeObserver vto = memoTextTxtViw.getViewTreeObserver();
final int c=i;
vto = memoTextTxtViw.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(memoTextTxtViw.getLineCount()>4)
{
memoMoreBtn.setVisibility(View.VISIBLE);
memoTextTxtViw.setMaxLines(maxlinecount[c]);
}
else{
memoMoreBtn.setVisibility(View.GONE);
tableRow.setFocusable(false); tableRow.setClickable(false); //code to disable the row click...
}
} });
//less...
if(countflag[i])
{
memoMoreBtn.setText("less");
}
else{
memoMoreBtn.setText("more");
}
if(memoArryList.get(i).getMemoCaseID()>0)
{
if(memoArryList.get(i).getMemoID()>0){
memoEditBtn.setVisibility(View.VISIBLE);
}else{
memoEditBtn.setVisibility(View.GONE);
}
}
else{
memoEditBtn.setVisibility(View.GONE);
}
//code for Edit button click...
memoEditBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(MemoScreen.this, UpdateMemoScreen.class);
Bundle b=new Bundle();
b.putParcelable("clsMemo", memoArryList.get(c));
intent.putExtras(b);
startActivityForResult(intent,1);
}
});
memoMoreBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
if(memoMoreBtn.getText().toString().equals("more"))
{
countflag[c]=true;
maxlinecount[c]=memoTextTxtViw.getLineCount();
renderUI();
}else{
countflag[c]=false;
maxlinecount[c]=4;
renderUI();
}
}
});
//setting listener for TableRow...
tableRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
if(memoMoreBtn.getText().toString().equals("more"))
{
countflag[c]=true;
maxlinecount[c]=memoTextTxtViw.getLineCount();
renderUI();
}else{
countflag[c]=false;
maxlinecount[c]=4;
renderUI();
}
}
});
tableRow.addView(genericView);
tablelayout.addView(tableRow,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
}
@Override
public void onDestroy() {
super.onDestroy();
objCase=null;
memoArryList=null;
bundle =null;
tablelayout=null;
countflag=null;
maxlinecount=null;
}
/*class MemoArrayAdapter extends BaseAdapter
{
@Override
public int getCount() {
return memoArryList.size();
}
Activity context;
public MemoArrayAdapter(Activity context) {
super();
Log.d("hh","sgbdfjfdgfk");
this.context = context;
}
class ViewHolder {
TextView memoTextTxtViw,memoAddedByEmpNameDateTxtViw,memoMoreBtn;
TextView memoEditBtn;
}
public View getView(final int position, View convertView, ViewGroup parent){//here we inflating the layout "R.layout.cars_row"
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.memo_row, null, true);
holder = new ViewHolder();
holder.memoAddedByEmpNameDateTxtViw=(TextView) rowView.findViewById(R.id.memoAddedByEmpNameDateTxtViw);
holder.memoTextTxtViw=(TextView) rowView.findViewById(R.id.memoTextTxtViw);
holder.memoMoreBtn=(TextView) rowView.findViewById(R.id.memoMoreBtn);
holder.memoEditBtn=(TextView) rowView.findViewById(R.id.memoEditBtn);
rowView.setTag(holder);
}
else
{
holder = (ViewHolder) rowView.getTag();
}
i++;
//File added by employee name on added date...
if(memoArryList.get(position).getMemoCreatedByEmployeeID()!=0 && memoArryList.get(position).getMemoAddedTimeStamp()!=null)
{
holder.memoAddedByEmpNameDateTxtViw.setVisibility(View.VISIBLE);
BLCommonOperations objBLCommonOperations=new BLCommonOperations();
String memoAddedDate=objBLCommonOperations.DateForDisplayInUIWithProperFormat(objBLCommonOperations.convertTimeToLocalTimeZone(objBLCommonOperations.convertDateToString(memoArryList.get(position).getMemoAddedTimeStamp())));
if(memoAddedDate==null) memoAddedDate="";
holder.memoAddedByEmpNameDateTxtViw.setText("Added By "+objBLCommonOperations.getEmployeeFirstNameLastName(memoArryList.get(position).getMemoCreatedByEmployeeID())+" on "+memoAddedDate);
objBLCommonOperations=null;
}
else{
holder.memoAddedByEmpNameDateTxtViw.setVisibility(View.GONE);
}
String reviewernotesstring=memoArryList.get(position).getMemoText();
if(reviewernotesstring!=null){
if(reviewernotesstring.length()>0){
int coefficient=0;
holder.memoMoreBtn.setVisibility(View.VISIBLE);//Gone elements will be visible here..
holder.memoTextTxtViw.setVisibility(View.VISIBLE);
System.out.println("***** reviewernotesstring-->"+reviewernotesstring);
System.out.println("***** reviewernotesstring length-->"+reviewernotesstring.length());
///code to remove '\n' (i.e new lines) from existing string.(This case is mainly used to handle the memo added by .Net/iphone teams).
for(int i=0;i<reviewernotesstring.length();i++){
char c = reviewernotesstring.charAt(i);
if( c == '\n' ) {
reviewernotesstring=reviewernotesstring.replace('\n', ' ');
}
}
System.out.println("-----------myString----------"+reviewernotesstring);
//code to devide the string into different n.of lines..
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenWidth = display.getWidth();
System.out.println("***** screenWidthwid-->"+screenWidth);
float scale = getBaseContext().getResources().getDisplayMetrics().density;
System.out.println("-----------scale----------"+scale);
float dips = (screenWidth-10) / scale;
System.out.println("-----------dipValue----------"+dips);
// 'screenWidth/8' wil return the number of characters one row will have
int numbrOfRowsPossible=(int)dips/7; ///each caharacter having 8-pixels
System.out.println("***** numbrOfRowsPossible-->"+numbrOfRowsPossible);
//this code used to maintain Array of rows having More-1 / Less-0 values
if(countFlag==0){//its a first time thing..means this part executed only frst time
System.out.println(" ,,,,,,,,,,,countFlag,,,,,,,,,,"+countFlag);
if(memoArryList.get(position).getMemoText().length()<= (numbrOfRowsPossible*4)){
moreLessArray[position]=0;//its having Less Button
holder.memoMoreBtn.setVisibility(View.GONE);
}
else
moreLessArray[position]=1;//its having More Button
}
else
{
System.out.println(" ,,,,,,,,,,,countFlag,,,,,,,,,,"+countFlag);
if(moreLessArray[position]==0)
holder.memoMoreBtn.setVisibility(View.GONE);
else
holder.memoMoreBtn.setVisibility(View.VISIBLE);
}
if(i==memoArryList.size()){
countFlag++; //disable 'countFlag' to execute above block on second time of calling the adapter..
for(int i=0;i<moreLessArray.length;i++)
System.out.println(".......moreLessArray->"+i+"="+moreLessArray[i]);
}
String tempString ="";
if(reviewernotesstring.length()>numbrOfRowsPossible){ //means user entered string will farm more than one row..
int count=1;
int nbLines = 1;
int start=0,end;
end=numbrOfRowsPossible;
for(int i=1;i<=reviewernotesstring.length();i++)
{
if(count==numbrOfRowsPossible && numbrOfRowsPossible<reviewernotesstring.length()){
if(end>reviewernotesstring.length()){
tempString=tempString+reviewernotesstring.substring(start, reviewernotesstring.length())+"\n";
nbLines++;
} else{
tempString=tempString+reviewernotesstring.substring(start, end)+"\n";
nbLines++;
}
System.out.println(" %%%%% tempString %%"+tempString);
System.out.println(" %%%%% tempString length %%"+tempString.length());
start=end;//for getting substring of next line,with start and end elements..
end=start+numbrOfRowsPossible;
count=1;
}
count++;
} //for loop
System.out.println("***** lines-->"+nbLines);
System.out.println("***** start-->"+start);
System.out.println("***** end-->"+end);
System.out.println("***** count-->"+count);
System.out.println("***** tempString-->"+tempString);
System.out.println("***** tempString len-->"+tempString.length());
System.out.println("***** reviewernotesstring len-->"+reviewernotesstring.length());
System.out.println("***** attornyAsignmntArryList-->"+memoArryList.get(position).getMemoText());
System.out.println("***** attornyAsignmntArryList len-->"+memoArryList.get(position).getMemoText().length());
coefficient=tempString.length()/numbrOfRowsPossible;//because tempString having more length after adding '\n' to it..here we get how many '\n' values added to 'tempString'
System.out.println("***** coefficient-->"+coefficient);
System.out.println("***** (4*numbrOfRowsPossible)+coefficient+1-->"+(4*numbrOfRowsPossible)+coefficient+1);
if((tempString.length()-coefficient)<reviewernotesstring.length())//means if user enters only '4*numbrOfRowsPossible' chars
tempString=tempString+reviewernotesstring.substring(start, reviewernotesstring.length());//adding remaiming string(half part of String) after adding complete rows
}
if(flag && clickedItemPosition==position && holder.textViewmobilName.getText().equals("More")){
System.out.println("########### flag && clickedItemPosition==position ");
holder.memoMoreBtn.setText("Less");
moreTextFlag[position]=0;//reprasents this row having text of 'Less'
holder.memoTextTxtViw.setText(tempStringattornyAsignmntArryList[position]); //display all chars
}else{
System.out.println("########### else part ");
if(reviewernotesstring.length()<=(4*numbrOfRowsPossible)){
if(reviewernotesstring.length()<=numbrOfRowsPossible){//block used for display string having only one row..
rowView.setFocusable(true); rowView.setClickable(true); //code to disable the row click...
holder.memoTextTxtViw.setText(reviewernotesstring);
holder.memoMoreBtn.setText("Less");
moreTextFlag[position]=0;//reprasents this row having text of 'Less'
}else{
holder.memoTextTxtViw.setText(tempString); //display all chars if formated string having two rows exactly..
rowView.setFocusable(true); rowView.setClickable(true); //code to disable the row click...
holder.memoMoreBtn.setText("Less");
moreTextFlag[position]=0;//reprasents this row having text of 'Less'
}
} else{
holder.memoTextTxtViw.setText(tempString.substring(0, (4*numbrOfRowsPossible)+4));//display only two rows(lines) if lineCount > 4(Here '4' reprasents adding 4-'\n' lengths,because adding '\n' causes to increase string length)
holder.memoMoreBtn.setText("More");
rowView.setFocusable(false); rowView.setClickable(false); //code to disable the row click...
moreTextFlag[position]=1;//reprasents this row having text of 'More'
}
}//if-flag
}//if - reviewernotesstring.length()>0
else{
holder.memoMoreBtn.setVisibility(View.GONE);
holder.memoTextTxtViw.setVisibility(View.GONE);
}
}//if - reviewernotesstring!=null
else{
holder.memoMoreBtn.setVisibility(View.GONE);
holder.memoTextTxtViw.setVisibility(View.GONE);
}
if(memoArryList.get(position).getMemoCaseID()>0)
{
if(memoArryList.get(position).getMemoID()>0){
holder.memoEditBtn.setVisibility(View.VISIBLE);
}else{
holder.memoEditBtn.setVisibility(View.GONE);
}
}
else{
holder.memoEditBtn.setVisibility(View.GONE);
}
//code for Edit button click...
holder.memoEditBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(MemoScreen.this, UpdateMemoScreen.class);
Bundle b=new Bundle();
b.putParcelable("clsMemo", memoArryList.get(position));
intent.putExtras(b);
startActivityForResult(intent,1);
}
});
//code for More button click....
holder.memoMoreBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
layoutInflateMethod(position);
}
});
return rowView;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
}*/
private static boolean containsId(){
ArrayList<Integer> memoidsarray = null;
if(memoArryList!=null)
{
memoidsarray=new ArrayList<Integer>();
for( clsMemo item : memoArryList ) {
if(memoidsarray.contains(item.getMemoCaseID()))
//attorneyidsarray.add(item.getAttorneyAssignmentEmployeeID());
return true;
}
}
return false;
}
public static void memoListRefresh(boolean fromSync){
if(fromSync){
if(containsId()){
}
}else{
/*
memoArryList=(ArrayList<clsMemo>) objCase.getCaseMemos();
if(memoArryList!=null){
if(memoArryList.size()>0){
countFlag=0;//it is more important to,because if u frst time inflate the list its value must be zero..
moreTextFlag=new int[memoArryList.size()]; ///this array will be used for to observing the text(i.e More/Less) in TextView of each row. //used for allocating memory for newly added record....
moreLessArray=new int[memoArryList.size()];
if(memoArryList.size()==1){//block used to add first starting event row at first time..
//objMemoArrayAdapter=new MemoArrayAdapter(this);
listView.setAdapter(objMemoArrayAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
layoutInflateMethod(position);
}
});
objMemoArrayAdapter=null;
}
else{
listView.setAdapter(new MemoArrayAdapter(this));
}
}
}
*/}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Log.d("CaseMemoscreen","onactivity for result method called???request code??"+requestCode+"??result code??"+resultCode);
//from AddCasePersonScreen....RenderScreen 1 means caseperson added succefully....
if(resultCode==1)
{
memoArryList=(ArrayList<clsMemo>) objCase.getCaseMemos();
if(memoArryList!=null){
if(memoArryList.size()>0){
countflag= new boolean[memoArryList.size()];
maxlinecount=new int[memoArryList.size()];
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
renderUI();
}
}
}
if(resultCode==2)
{
memoArryList=(ArrayList<clsMemo>) objCase.getCaseMemos();
if(memoArryList!=null){
if(memoArryList.size()>0){
countflag= new boolean[memoArryList.size()];
maxlinecount=new int[memoArryList.size()];
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
renderUI();
}
}
}
}
}
MemoScreen.Java:- (Modified java class after fixing some issues)
package com.dharani.android.legalplex.PresentationLayer;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableLayout.LayoutParams;
import android.widget.TableRow;
import android.widget.TextView;
import com.dharani.android.legalplex.R;
import com.dharani.android.legalplex.SharedVariables;
import com.dharani.android.legalplex.BusinessLayer.BLCommonOperations;
import com.dharani.android.legalplex.BusinessLayer.BLParentToChildCommonOperations;
import com.dharani.android.legalplex.DataLayer.Case.clsCase;
import com.dharani.android.legalplex.DataLayer.Memo.clsMemo;
public class MemoScreen extends abstractActivity {
Bundle bundle =null;
static clsCase objCase=null;
static List<clsMemo> memoArryList=null;
static TableLayout tablelayout;
static boolean[] countflag;
static int[] maxlinecount;
static int[] actualLineCount;
static Context context=null;
static Activity activity=null;
static boolean localFlag=true;
static TextView nomemosdiplaytext,memoHeaderTextView;
static ViewTreeObserver observerMemo ;
static ViewTreeObserver vto=null;
static boolean observerFlag=true; static int k=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.memo_screen);
context=this;
activity=this;
k=0;
getAllIds();
//code to get objects from bundle
bundle = getIntent().getExtras();
//code to get all objects using Bundle from previous activity
if(bundle!=null){
//objSearchDetail=(clsSearchDetail) bundle.getSerializable("clsSearchDetailObj");
objCase = (clsCase) bundle.getParcelable("clsCaseObj");
bundle=null;
}
if(objCase!=null){
memoListRefresh(false, null);
}
RelativeLayout addMemoButton=(RelativeLayout)findViewById(R.id.addMemoButtonlayout);
addMemoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent i=new Intent(MemoScreen.this,AddMemoScreen.class);
i.putExtra("memoCaseID", objCase.getCaseID());
i.putExtra("memoCaseSLNO", objCase.getId());
startActivityForResult(i,0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}//onCreate()..
public void memoCloseBtnClick(View v){
finish();
}
private void getAllIds() {
tablelayout=(TableLayout) findViewById(R.id.tablelayout);
nomemosdiplaytext=(TextView) findViewById(R.id.nomemosdiplaytext);
memoHeaderTextView=(TextView) findViewById(R.id.memoHeaderTextView);
nomemosdiplaytext.setText(SharedVariables.memos_empty_list_message);
nomemosdiplaytext.setTypeface(SharedVariables.font,Typeface.BOLD);
memoHeaderTextView.setTypeface(SharedVariables.font,Typeface.BOLD);
}
public static void renderUI()
{
System.out.println("^^^^^^^ tempVariable ^^^^^^^^"+SharedVariables.tempVariable);
//Below code is more important ,because it used to compress already expanded row when user press back button after expand any row,and reopen memo screen
if(SharedVariables.tempVariable!=-1 && localFlag){
countflag[SharedVariables.tempVariable]=false;
maxlinecount[SharedVariables.tempVariable]=4;
localFlag=false;
SharedVariables.tempVariable=-1;
}
try {
tablelayout.removeAllViews();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(memoArryList!=null)
for(int i=0;i<memoArryList.size();i++)
{
final TableRow tableRow=new TableRow(context);
tableRow.setClickable(true);
View genericView=null;
LayoutInflater inflater = LayoutInflater.from(context);
genericView = inflater.inflate(R.layout.memo_row, null);
LinearLayout memoaddedbytextlayout=(LinearLayout) genericView.findViewById(R.id.memoaddedbytextlayout);
LinearLayout memoaddedbydatelayout=(LinearLayout) genericView.findViewById(R.id.memoaddedbydatelayout);
final TextView memoEmpNameTxtViw=(TextView) genericView.findViewById(R.id.memoaddedbytext);
final TextView memoAddedDatetxtViw=(TextView) genericView.findViewById(R.id.memoaddedbydate);
final TextView memoTextTxtViw=(TextView) genericView.findViewById(R.id.memoname);
final TextView memoMoreBtn=(TextView) genericView.findViewById(R.id.memomoreimage);
final TextView memoEditBtn=(TextView) genericView.findViewById(R.id.memoeditimage);
memoEmpNameTxtViw.setTypeface(SharedVariables.font);
memoAddedDatetxtViw.setTypeface(SharedVariables.font);
memoTextTxtViw.setTypeface(SharedVariables.font,Typeface.BOLD);
memoMoreBtn.setTypeface(SharedVariables.font);
memoEditBtn.setTypeface(SharedVariables.font);
BLCommonOperations objBLCommonOperations=new BLCommonOperations();
//File added attorney...
try {
String empname=objBLCommonOperations.getEmployeeFirstNameLastName(memoArryList.get(i).getMemoCreatedByEmployeeID());
if(empname!=null)
{
if(empname.length()>0)
{
memoaddedbytextlayout.setVisibility(View.VISIBLE);
memoEmpNameTxtViw.setText(empname);
}else{
memoaddedbytextlayout.setVisibility(View.GONE);
}
}else{
memoaddedbytextlayout.setVisibility(View.GONE);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
memoaddedbytextlayout.setVisibility(View.GONE);
}
//File Added date....
if(memoArryList.get(i).getMemoAddedTimeStamp()!=null)
{
try {
String date=objBLCommonOperations.DateForDisplayInUIWithProperFormat(objBLCommonOperations.convertDateToString(memoArryList.get(i).getMemoAddedTimeStamp()), false,true);
if(date!=null)
{
if(date.length()>0)
{
memoaddedbydatelayout.setVisibility(View.VISIBLE);
memoAddedDatetxtViw.setText(date);
}else{
memoaddedbydatelayout.setVisibility(View.GONE);
}
}else{
memoaddedbydatelayout.setVisibility(View.GONE);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
memoaddedbydatelayout.setVisibility(View.GONE);
}
}
else{
memoaddedbydatelayout.setVisibility(View.GONE);
}
objBLCommonOperations=null;
memoTextTxtViw.setText(memoArryList.get(i).getMemoText());
final int c=i;
vto = memoTextTxtViw.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
System.out.println("$$$$$$$$ getViewTreeObserver $$$$$"+c+"??? line count???"+memoTextTxtViw.getLineCount());
if(memoTextTxtViw.getLineCount()>4)
{
memoMoreBtn.setVisibility(View.VISIBLE);
memoTextTxtViw.setMaxLines(maxlinecount[c]);
}
else{
memoMoreBtn.setVisibility(View.GONE);
tableRow.setClickable(false); //code to disable the row click...
}
} });
//less...
System.out.println("-----"+memoArryList.get(i).getMemoText());
System.out.println("--*---"+memoArryList.get(c).getMemoText());
System.out.println("--**---"+maxlinecount[i]);
System.out.println("--***---"+maxlinecount[c]);
/*if(maxlinecount[c]>4)
memoMoreBtn.setVisibility(View.VISIBLE);
else{
memoMoreBtn.setVisibility(View.GONE);
tableRow.setFocusable(false); tableRow.setClickable(false); //code to disable the row click...
}*/
if(countflag[i])
{
memoTextTxtViw.setMaxLines(maxlinecount[c]);
memoTextTxtViw.setText(memoArryList.get(i).getMemoText());
memoMoreBtn.setText("less");
}
else{
memoTextTxtViw.setMaxLines(4);
memoTextTxtViw.setText(memoArryList.get(i).getMemoText());
memoMoreBtn.setText("more");
}
if(memoArryList.get(i).getMemoCaseID()>0)
{
if(memoArryList.get(i).getMemoID()>0){
memoEditBtn.setVisibility(View.VISIBLE);
}else{
memoEditBtn.setVisibility(View.GONE);
}
}
else{
memoEditBtn.setVisibility(View.GONE);
}
//code for Edit button click...
memoEditBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, UpdateMemoScreen.class);
Bundle b=new Bundle();
b.putParcelable("clsMemo", memoArryList.get(c));
intent.putExtras(b);
activity.startActivityForResult(intent,1);
}
});
memoMoreBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(memoArryList!=null)
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
if(memoMoreBtn.getText().toString().equals("more"))
{
SharedVariables.tempVariable=c;
countflag[c]=true;
maxlinecount[c]=memoTextTxtViw.getLineCount();
renderUI();
}else{
SharedVariables.tempVariable=-1;
countflag[c]=false;
maxlinecount[c]=4;
renderUI();
}
}
});
//setting listener for TableRow...
tableRow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(memoArryList!=null)
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
if(memoMoreBtn.getText().toString().equals("more"))
{
SharedVariables.tempVariable=c;
countflag[c]=true;
maxlinecount[c]=memoTextTxtViw.getLineCount();
renderUI();
}else{
SharedVariables.tempVariable=-1;
countflag[c]=false;
maxlinecount[c]=4;
renderUI();
}
}
});
tableRow.addView(genericView);
tablelayout.addView(tableRow,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
}
@Override
public void onDestroy() {
super.onDestroy();
/* bundle =null;objCase=null;*/
/* if(memoArryList!=null)
{
memoArryList.clear();
memoArryList=null;
}
try {
tablelayout.removeAllViews();
tablelayout=null;
} catch (Exception e) {
e.printStackTrace();
}*/
/* context=null;
activity=null;*/
}
public static void memoListRefresh(boolean fromSync,ArrayList<Integer> memoCaseIdArray){
if(fromSync){
System.out.println("####### fromSync-1 ##########"+fromSync);
if(objCase!=null)
{
if(memoCaseIdArray.contains(objCase.getCaseID()))
{
BLParentToChildCommonOperations objBLParentToChildCommonOperations=new BLParentToChildCommonOperations();
memoArryList=objBLParentToChildCommonOperations.getMemos(objCase);
objBLParentToChildCommonOperations=null;
if(memoArryList!=null){
if(memoArryList.size()>0){
SharedVariables.new_memo_added_for_clientdetails_refersh=true;
nomemosdiplaytext.setVisibility(View.GONE);
countflag= new boolean[memoArryList.size()];
maxlinecount=new int[memoArryList.size()];
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
renderUI();
}else{
nomemosdiplaytext.setVisibility(View.VISIBLE);
}
}else{
nomemosdiplaytext.setVisibility(View.VISIBLE);
}
}
}
}
else{
System.out.println("####### fromSync-2 ##########"+fromSync);
if(objCase!=null)
{
BLParentToChildCommonOperations objBLParentToChildCommonOperations=new BLParentToChildCommonOperations();
memoArryList=objBLParentToChildCommonOperations.getMemos(objCase);
objBLParentToChildCommonOperations=null;
if(memoArryList!=null){
if(memoArryList.size()>0){
nomemosdiplaytext.setVisibility(View.GONE);
countflag= new boolean[memoArryList.size()];
maxlinecount=new int[memoArryList.size()];
for(int i=0;i<memoArryList.size();i++){
countflag[i]=false;
maxlinecount[i]=4;
}
renderUI();
}else{
nomemosdiplaytext.setVisibility(View.VISIBLE);
}
}else{
nomemosdiplaytext.setVisibility(View.VISIBLE);
}
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Log.d("CaseMemoscreen","onactivity for result method called???request code??"+requestCode+"??result code??"+resultCode);
//from AddCasePersonScreen....RenderScreen 1 means caseperson added succefully....
if(resultCode==1)
{
memoListRefresh(false,null);
}
else if(resultCode==2)
{
memoListRefresh(false,null);
}
}
}
memo_screen.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/details_screen_background"
>
<RelativeLayout android:id="@+id/memoLayout"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="@drawable/toolbarx"
android:padding="6dip">
<RelativeLayout
android:id="@+id/addMemoButtonlayout"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
>
<ImageView
android:id="@+id/addseadrchcaseButton"
android:layout_width="20dip"
android:layout_height="25dip"
android:layout_centerInParent="true"
android:src="@drawable/add_icon"
/>
</RelativeLayout>
<ImageView
android:layout_height="50dip"
android:id="@+id/addsearchcaseButtonline"
android:layout_width="3dip"
android:src="@drawable/linex"
android:layout_toLeftOf="@+id/addMemoButtonlayout"/>
<Button
android:id="@+id/memoCloseBtn"
android:layout_width="45dip"
android:layout_height="45dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/close_new_button"
android:onClick="memoCloseBtnClick" />
<ImageView
android:layout_height="50dip"
android:layout_width="3dip"
android:src="@drawable/linex"
android:layout_toRightOf="@+id/memoCloseBtn"/>
<TextView
android:id="@+id/memoHeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text=" Memos "
android:textSize="22dip"
android:textStyle="bold"
android:textColor="@color/fontColorDark" />
</RelativeLayout>
<LinearLayout android:id="@+id/ll_country"
android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_below="@+id/memoLayout">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<TableLayout
android:id="@+id/tablelayout"
android:layout_width="fill_parent"
android:stretchColumns="0,1"
android:shrinkColumns="0"
android:layout_height="wrap_content" />
</ScrollView> </LinearLayout>
<TextView
android:id="@+id/nomemosdiplaytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="20dip"
android:layout_centerInParent="true"
android:text="No Memos "
/>
</RelativeLayout>
memo_row.xml:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:paddingTop="5dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dip"
android:id="@+id/memoaddedbytextlayout"
android:layout_marginTop="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_gravity="center_vertical"
android:src="@drawable/lawyer_icon" />
<TextView
android:id="@+id/memoaddedbytext"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:textSize="16dip"
android:textColor="@color/fontColorDark"
android:text="empname " />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dip"
android:id="@+id/memoaddedbydatelayout"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="20dip"
android:layout_height="20dip"
android:layout_gravity="center_vertical"
android:src="@drawable/events_icon" />
<TextView
android:id="@+id/memoaddedbydate"
android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
android:singleLine="true"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:textSize="16dip"
android:textColor="@color/fontColorDark"
android:text="addedDate" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/memolayout"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="20dip"
android:layout_gravity="top"
android:layout_height="20dip"
android:src="@drawable/file_icon" />
<TextView
android:id="@+id/memoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_gravity="center_vertical"
android:textColor="@color/fontColorDark"
android:textSize="18dip"
android:textStyle="bold"
android:maxLines="4"
android:text="File Name" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/fffmemolayout"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
>
<TextView
android:id="@+id/memoeditimage"
android:layout_width="wrap_content"
android:layout_height="28dip"
android:background="@drawable/edit_bg"
android:layout_alignParentLeft="true"
android:text="Edit"
android:gravity="center"
android:textSize="17dip"
android:textStyle="normal"
android:layout_marginBottom="10dip"
android:textColor="#ffffff"
android:visibility="visible" />
<TextView
android:id="@+id/memomoreimage"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="28dip"
android:background="@drawable/edit_bg"
android:layout_alignParentRight="true"
android:text="more"
android:textSize="17dip"
android:textStyle="normal"
android:layout_marginBottom="10dip"
android:textColor="#ffffff"
android:visibility="visible" />
</RelativeLayout>
<ImageView
android:id="@+id/lineImageView"
android:layout_width="fill_parent"
android:layout_height="2dip"
android:src="@drawable/line" />
</LinearLayout>
Comments
Post a Comment