Related
I have google this and searched here but I have hit a wall.
I have a function which is to return an Int. It tells me I need to add another return expression to the overall function but I can't figure out where it needs to go to be done correctly, i have tried a few variations including adding the same return I use within the if statements but before the closing tag which throws up errors within the rest of the code
I call the function like this;
var ans = GetQuestion(1)
fun GetQuestion(cat:Int): Int {
val btn1 = findViewById(R.id.button1) as Button
val btn2 = findViewById(R.id.button2) as Button
val btn3 = findViewById(R.id.button3) as Button
val btn4 = findViewById(R.id.button4) as Button
btn1.setVisibility(View.VISIBLE)
btn2.setVisibility(View.VISIBLE)
btn3.setVisibility(View.VISIBLE)
btn4.setVisibility(View.VISIBLE)
val initialimageview = findViewById(R.id.imageview_Qresponse) as ImageView
initialimageview.setBackgroundResource(R.drawable.question_2);
val viewQ = findViewById(R.id.textview_question) as TextView
if (cat==1) { // Multiplication
var a = rand(5,80)
var b = rand(2,50)
val ans = a * b
var opType = " X "
viewQ.text = ("" + a + " " + opType + " " + b + "?");
val listOfAns = mutableListOf(ans,ans-a,ans-b,ans+a)
listOfAns.shuffle()
btn1.text=("" + listOfAns.elementAt(0))
btn2.text=("" + listOfAns.elementAt(1))
btn3.text=("" + listOfAns.elementAt(2))
btn4.text=("" + listOfAns.elementAt(3))
return ans
listOfAns.clear()
}
if (cat==2) { // Addition
var a = rand(5,250)
var b = rand(2,140)
val ans = a + b
var opType = " + "
viewQ.text = ("" + a + " " + opType + " " + b + "?");
val listOfAns = mutableListOf(ans,ans+rand(2,4),ans+rand(5,10),ans-rand(2,10))
listOfAns.shuffle()
btn1.text=("" + listOfAns.elementAt(0))
btn2.text=("" + listOfAns.elementAt(1))
btn3.text=("" + listOfAns.elementAt(2))
btn4.text=("" + listOfAns.elementAt(3))
return ans
listOfAns.clear()
}
if (cat==3) { // Subtraction
var a = rand(80,150)
var b = rand(2,79)
var ans = a - b
var opType = " - "
viewQ.text = ("" + a + " " + opType + " " + b + "?");
val listOfAns = mutableListOf(ans,ans+rand(2,5),ans+rand(6,10),ans-rand(2,10))
listOfAns.shuffle()
btn1.text=("" + listOfAns.elementAt(0))
btn2.text=("" + listOfAns.elementAt(1))
btn3.text=("" + listOfAns.elementAt(2))
btn4.text=("" + listOfAns.elementAt(3))
return ans
listOfAns.clear()
}
if (cat==4) { // Division
var safedivision = rand(3,16)
var b = rand(2,20)
var a = b * safedivision
var ans = a / b
var opType = " / "
viewQ.text = ("" + a + " " + opType + " " + b + "?");
val listOfAns = mutableListOf(ans,ans+rand(2,5),ans+rand(6,10),ans-rand(2,10))
listOfAns.shuffle()
btn1.text=("" + listOfAns.elementAt(0))
btn2.text=("" + listOfAns.elementAt(1))
btn3.text=("" + listOfAns.elementAt(2))
btn4.text=("" + listOfAns.elementAt(3))
return ans
listOfAns.clear()
}
}
As a side note I wasn't sure if I have to use var of val when writing var ans = GetQuestion(1) however both methods throw up the same return error so I can amend that later if required
You can keep variable ans at the top of the function as below -
var ans = 0
and replace val ans from the all if conditions with ans. Before the last }
add return statement
return ans
If your function body doesn't have return keyword, then both sides of if-else must have return in them, for example:
fun dummyFunc(Int a):Int{
if (a > 0){
return 5
}else{
return -5
}
}
In this case, you don't need to add another return at the end of your code. But in your code, you don't have else block, so either you will do like the above answer by Priyanka Rajput or you will ad else statement. And after all, your code has reused code in if blocks, you can extract them and add after all the ifs you have written:
fun GetQuestion(cat:Int): Int {
val btn1 = findViewById(R.id.button1) as Button
val btn2 = findViewById(R.id.button2) as Button
val btn3 = findViewById(R.id.button3) as Button
val btn4 = findViewById(R.id.button4) as Button
btn1.setVisibility(View.VISIBLE)
btn2.setVisibility(View.VISIBLE)
btn3.setVisibility(View.VISIBLE)
btn4.setVisibility(View.VISIBLE)
val initialimageview = findViewById(R.id.imageview_Qresponse) as ImageView
initialimageview.setBackgroundResource(R.drawable.question_2);
val viewQ = findViewById(R.id.textview_question) as TextView
var a = 0
var b = 0
var ans = 0
var opType = ""
var viewQText = ""
var listOfAns = mutableListOf()
if (cat==1) { // Multiplication
var a = rand(5,80)
var b = rand(2,50)
val ans = a * b
var opType = " X "
viewQText = ("" + a + " " + opType + " " + b + "?");
val listOfAns = mutableListOf(ans,ans-a,ans-b,ans+a)
}
if (cat==2) { // Addition
a = rand(5,250)
b = rand(2,140)
ans = a + b
opType = " + "
viewQText = ("" + a + " " + opType + " " + b + "?");
listOfAns = mutableListOf(ans,ans+rand(2,4),ans+rand(5,10),ans-rand(2,10))
}
if (cat==3) { // Subtraction
a = rand(80,150)
b = rand(2,79)
ans = a - b
opType = " - "
viewQText = ("" + a + " " + opType + " " + b + "?");
listOfAns = mutableListOf(ans,ans+rand(2,5),ans+rand(6,10),ans-rand(2,10))
}
if (cat==4) { // Division
safedivision = rand(3,16)
b = rand(2,20)
a = b * safedivision
ans = a / b
opType = " / "
viewQText = ("" + a + " " + opType + " " + b + "?");
listOfAns = mutableListOf(ans,ans+rand(2,5),ans+rand(6,10),ans-rand(2,10))
}
viewQ.text = viewQText
listOfAns.shuffle()
btn1.text=("" + listOfAns.elementAt(0))
btn2.text=("" + listOfAns.elementAt(1))
btn3.text=("" + listOfAns.elementAt(2))
btn4.text=("" + listOfAns.elementAt(3))
return ans
listOfAns.clear()
}
While doing this, I have realized that you have a lot of style and coding problems. First, you mustn't call findViewById method too much, it's expensive. You must declare your Views as global variables and initialize them in your onCreate method. Second, you don't use listOfAns, maybe you have other plans for it, you will later use, I don't know, but all I know is, your code runs till the line with return keyword, which means listofAns.clear() will not be executed. And it would be better if you used when instead of if-else
I'm installing Hybrid Ranking algorithm for Linked Data Extraction & Context on Android. Documents you can search Google for the keywords above.
And now I'm installing semantic similarity between two uri1 and uri2.
Input: two DBpedia URIs
Output: a value representing their similarity
private float similarity(String uri1, String uri2) {
float wikipedia = wikiS(uri1, uri2);
float abtract = abtractS(uri1, uri2);
float google = engineS(uri1, uri2, google);
float yahoo = engineS(uri1, uri2, yahoo);
float bing = engineS(uri1, uri2, bing);
float dilicious = engineS(uri1, uri2, dilicicous);
return wikipedia + abtract + google + yahoo + bing + dilicious;
}
And with each child function, I have to query data using SPARQL dbpedia, google, yahoo, bing, dilicious using provided API. The results obtained will be calculated to the parser and returns the corresponding float value.
Example for abtractS(uri1, uri2) below:
private float abstractS(String uri1, String uri2, final float wikiS){
String url = createUrlAbstractS(uri1, uri2);
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
float abtractS = 0.0f;
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray data = jsonObject.getJSONObject("results").getJSONArray("bindings");
if(data.length() == 0){
showLogAndToast("No result");
}else{
JSONObject element = data.getJSONObject(0);
String label1 = element.getJSONObject("label1").getString("value");
String abtract1 = element.getJSONObject("abtract1").getString("value");
String label2 = element.getJSONObject("label2").getString("value");
String abtract2 = element.getJSONObject("abtract2").getString("value");
abtractS = calWordContained(label1, abtract2) + calWordContained(label2, abtract1) + wikiS;
//TODO: RESULT ABTRACTS HERE. How next?
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(request);
return 0.0f;//HERE: no results
}
private float calWordContained(String label, String abtract){
if(label.length() == 0 || abtract.length() == 0){
return 0.0f;
}
List<String> words = Arrays.asList(label.split(" "));
int count = 0;
float length = words.size();
for(int i = 0; i < length; i++){
if(abtract.toLowerCase().contains(words.get(i).toLowerCase())){
count++;
}
}
return (count/length);
}
public String createUrlAbstractS(String uri1, String uri2){
private String BASE_URL_DBPEDIA = "http://dbpedia.org/sparql?default-graph-uri=&query=";
String query = createQueryAbstractS(uri1, uri2);
String url = "";
try {
url = Config.BASE_URL_DBPEDIA + URLEncoder.encode(query, "UTF-8") + Config.RESULT_JSON_TYPE;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return url;
}
private String createQueryAbstractS(String uri1, String uri2){
String query = Config.PREFIX_DBPEDIA + " \n" +
"prefix dbpedia-owl: <http://dbpedia.org/ontology/>\n" +
"\n" +
"\n" +
"select ?label1, ?label2, ?abtract1, ?abtract2 where\n" +
"{\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri1 + "> rdfs:label ?label1 ;\n" +
" dbpedia-owl:abstract ?abtract1 .\n" +
" FILTER langMatches(lang(?abtract1),'en') . \n" +
" FILTER langMatches(lang(?label1),'en') .\n" +
" }\n" +
" }\n" +
"\n" +
"\n" +
" {\n" +
" select *\n" +
" where{\n" +
" <" + uri2 + "> rdfs:label ?label2 ;\n" +
" dbpedia-owl:abstract ?abtract2 .\n" +
" FILTER langMatches(lang(?label2),'en') . \n" +
" FILTER langMatches(lang(?abtract2),'en') .\n" +
" }\n" +
" }\n" +
"}";
return query;
}
but how to do this on, I could not get the results I wanted in the similarity function (uri1, uri2). Therefore it will affect the results in different functions.
So I'm asking is: how can I get all the results of the function Wikis, abtractS, engine (google), engine (bing), engine (yahoo), engine (dilicious) in a simple way Best. I currently do on Android and data load times is very important.
Thank you very much!
I have created an app that receives data from a bt transmitter (Bluegiga). The readings are from EEG signals. The data rate is 1Khz (I have to admit it's high). Anyway, I acquire some data for some seconds and then the Bluetooth acts like there is no incoming data (which is not true). If I try to disconnect the Bluetooth using the app is clear that there is no more communication with the bt module at the EEG board since it doesn't respond to the desconnection (It has a led that indicates when is connected, and it doesn't turn of/on or anything).
If I decrease the data rate to (let's say 500hz) the app works ok, with some occasional 'quits', but tolerable. If I decrease it more the app works with no problems.
Of curse, by design, my app must work at 1Khz data rate so here is where the problem comes.
I have check some other post, trying to hit some kind of sns but nothing match my problem exactly (anyway I have tried to use the information on them but with no success obviously).
Sometimes I get this message, "dm_pm_timer expires", sometimes no (after the bt stops working).
Sadly there is no indication, Exception or message that can tell me what's going on.
Here is my Code for the BT reception Thread
class BluetoothReadThread extends Thread {
private final InputStream iStream;
private final OutputStream mmOutputStream;
private boolean continueReading = true;
public BluetoothReadThread() {
InputStream tmp = null;
OutputStream tmp2 = null;
try {
tmp = btSocket.getInputStream();
tmp2 = btSocket.getOutputStream();
} catch (IOException e) {
}
iStream = tmp;
mmOutputStream = tmp2;
}
#Override
public void run() {
int c;
int waitCount = 0;
while (continueReading) {
try {
if (iStream.available() > 0) {
waitCount = 0;
c = iStream.read();
readBuffer[readBufferPosition++] = c;
if (readBufferPosition == bitsExpected) {
if (bitsExpected == 22) {
ch1 = MultiplicationCombine(readBuffer[4], readBuffer[3]);
ch2 = MultiplicationCombine(readBuffer[6], readBuffer[5]);
ch3 = MultiplicationCombine(readBuffer[8], readBuffer[7]);
ch4 = MultiplicationCombine(readBuffer[10], readBuffer[9]);
ch5 = MultiplicationCombine(readBuffer[12], readBuffer[11]);
ch6 = MultiplicationCombine(readBuffer[14], readBuffer[13]);
ch7 = MultiplicationCombine(readBuffer[16], readBuffer[15]);
ch8 = MultiplicationCombine(readBuffer[18], readBuffer[17]);
} else {
ch1 = (int) filter_3((double)MultiplicationCombine(readBuffer[5], readBuffer[4], readBuffer[3]));
ch2 = (int) filter_4((double)MultiplicationCombine(readBuffer[8], readBuffer[7], readBuffer[6]));
ch3 = (int) filter_2((double)MultiplicationCombine(readBuffer[11], readBuffer[10], readBuffer[9]));
ch4 = (int) filter_2((double)MultiplicationCombine(readBuffer[14], readBuffer[13], readBuffer[12]));
ch5 = (int) filter_2((double)MultiplicationCombine(readBuffer[17], readBuffer[16], readBuffer[15]));
ch6 = (int) filter_2((double)MultiplicationCombine(readBuffer[20], readBuffer[19], readBuffer[18]));
ch7 = (int) filter_2((double)MultiplicationCombine(readBuffer[23], readBuffer[22], readBuffer[21]));
ch8 = (int) filter_2((double)MultiplicationCombine(readBuffer[26], readBuffer[25], readBuffer[24]));
}
Header_int = readBuffer[0];
PK_ID_int = readBuffer[1];
PK_Counter_int = readBuffer[2];
if (downsample++ == downsample_value) {
addEntry(ch1 / scaCh1, ch2 / scaCh2, ch3 / scaCh3, ch4 / scaCh4, ch5 / scaCh5, ch6 / scaCh6, ch7 / scaCh7, ch8 / scaCh8);
downsample = 0;
}
//ProgrNum,PacketType,Ch1,Ch2,Ch3,Ch4,Ch5,Ch6,Ch7,Ch8,MRK
if (write_open) {
osw.write(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + "," + bolOpenClose + "\n");
//osw.write(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + "," + "\n");
}
System.out.println(PK_Counter_int + "," + PK_ID_int + "," + ch1 + "," + ch2 + "," + ch3 + "," + ch4 + "," + ch5 + "," + ch6 + "," + ch7 + "," + ch8 + ", AV=" + iStream.available() );
mmOutputStream.write(valueSTR.getBytes());
// if(downsample++==14) { safe_copy(readBuffer); plot=true; downsample=0;}
readBufferPosition = 0;
try {
Thread.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
} catch (IOException e) {
System.out.println(e + "\nError sending data + :" + e);
// Bluetooth error! Stop reading.
//this.stopAndSendIntent();
}
}
}
/*
public void stopAndSendIntent() {
this.cancel();
Intent intent = new Intent();
intent.setAction(BLUETOOTH_ACTION_DONE_READING);
sendBroadcast(intent);
}
*/
public void cancel() {
System.out.println("-----Cancelling readThread!!");
try {
iStream.close();
} catch (IOException e) {
} catch (NullPointerException e) {
}
;
continueReading = false;
}
}
It works like this:
I read a received character (c=iStream.read()).
Then I copy this character to an int array until I reach the length of the packet (it can be 22 or 28 (bitsExpected)).
The following part is just filtering and plotting of the signal.
I have tried many other implementations but I get the same result.
Even if I eliminate the part of the filtering and plotting (just reading data) the problem persists.
If instead of working with array, I work with string, i.e, using append() (which should be the same?) I manage to get an working connection (no quits) but, as soon as I manipulate the program using the array everything is the same.
I'm stuck with this for 1 month already, so I will really appreciate any comments, past experience or suggestions.
Thanks in advance.
I just added this piece of code
if (PK_Counter_int % 100 == 0) mmOutputStream.write(startTring.getBytes());
and it works just fine so far.
This is activityresult1
Button buttonorder;
TextView textviewcard;
private static final int REQUEST_CODE = 10;
int[] image ={R.drawable.friednoodle, R.drawable.friedrice, R.drawable.steamfish,R.drawable.tehice};
String[] item = {"Fried Noodle", "Fried Rice", "Steam Fish","Iced Tea"};
String[] description = {"Classic Chinese stir fried noodle with prawn and Pork", "Special sauce Fried Rice using indian rice", "HongKong Style Steamed Fish ","HongKong classical iced tea"};
String[] cost={"6","5","25","2"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activityresult1);
Bundle extras = getIntent().getExtras();
String strcardnumber = extras.getString("Card Number");
textviewcard = (TextView) findViewById(R.id.textviewcard);
textviewcard.setText("Welcome, " + strcardnumber + " !" + "\nPlease select the food you want ! : ");
itemList = new ArrayList<DataInfo>();
itemList.add(new DataInfo(item[0], image[0], description[0], cost[0]));
itemList.add(new DataInfo(item[1], image[1], description[1], cost[1]));
itemList.add(new DataInfo(item[2], image[2], description[2], cost[2]));
itemList.add(new DataInfo(item[3], image[3], description[3], cost[3]));
final MenuAdapter adapter = new MenuAdapter(this);
ListView listView = (ListView)findViewById(R.id.list);
LVAdapter lvAdapter = new LVAdapter(this, itemList);
//listView.setAdapter(lvAdapter);
listView.setAdapter(adapter);
for (int i = 0; i < item.length; i++) {
adapter.addData(String.valueOf(i), item[i], image[i], description[i], cost[i]);
}
buttonorder = (Button) findViewById(R.id.suborder);
buttonorder.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String[] a = adapter.getQuantity();
Toast.makeText(getApplicationContext(), "Noodle: " + a[0] + "\nRice: " + a[1] + "\nSteam fish: " + a[2] + "\nIced tea: " + a[3], Toast.LENGTH_LONG).show();
int sum = Integer.parseInt(adapter.getQuantity()[0])*Integer.parseInt(cost[0]) +
Integer.parseInt(adapter.getQuantity()[1])*Integer.parseInt(cost[1]) +
Integer.parseInt(adapter.getQuantity()[2])*Integer.parseInt(cost[2]) +
Integer.parseInt(adapter.getQuantity()[3])*Integer.parseInt(cost[3]);
Intent myIntent = new Intent(activityresult1.this, activityresult2.class);
myIntent.putExtra("sum",sum);
startActivity(myIntent);
Intent intent = new Intent(getApplicationContext(), activityresult2.class);
Bundle bundle = new Bundle();
bundle.putString("Noodle quantity", adapter.getQuantity()[0]);
bundle.putString("Rice quantity", adapter.getQuantity()[1]);
bundle.putString("Fish quantity", adapter.getQuantity()[2]);
bundle.putString("Iced tea", adapter.getQuantity()[3]);
bundle.putInt("sum", sum);
bundle.putBoolean("ANI", adapter.getItem(0).isAddInisCheck());//add noodle ingredients
bundle.putBoolean("ARI", adapter.getItem(1).isAddInisCheck()); // add rice ingredients
bundle.putBoolean("AFI", adapter.getItem(2).isAddInisCheck());// add fish ingredients
bundle.putBoolean("AIT", adapter.getItem(3).isAddInisCheck()); // add ice tea ingredients
intent.putExtras(bundle);
startActivityForResult(intent, REQUEST_CODE);
}
});
}
how do i sent the calculated sum from activityresult1 to activityresult2
static public String txtOrder ="";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activityresult2);
Bundle bundle = getIntent().getExtras();
String strfnq = bundle.getString("Noodle quantity");
String strfrq = bundle.getString("Rice quantity");
String strfsq = bundle.getString("Fish quantity");
String stricq = bundle.getString("Iced tea");
Integer strsum = bundle.getInt("sum");
boolean addNingc = bundle.getBoolean("ANI");
boolean addRingc = bundle.getBoolean("ARI");
boolean addFingc = bundle.getBoolean("AFI");
boolean addTingc = bundle.getBoolean("AIT");
// boolean addmoneyc = bundle.getBoolean("AMY");
Intent mIntent = getIntent();
int sum = mIntent.getIntExtra("sum",strsum);
TextView costtext = (TextView)findViewById(R.id.costtext);
costtext.setText(getIntent().getExtras().getString("sum"));
TextView foodorders = (TextView) findViewById(R.id.foodordershow);
foodorders.setText(getIntent().getExtras().getString("Quantity"));
String addNdlThing = "";
if (addNingc) {
addNdlThing = " with addition of ingredients";
}
String addRlThing = "";
if (addRingc) {
addRlThing = " with addition of ingredients";
}
String addSlThing = "";
if ( addFingc) {
addSlThing = " with addition of ingredients";
}
String addTeac = "";
if ( addTingc ) {
addTeac = " with addition of ingredients";
}
foodorders = (TextView) findViewById(R.id.foodordershow);
if(strfnq.equals("") && strfrq.equals("") && strfsq.equals("")&& stricq.equals("")){
txtOrder = "Sorry, You've not ordered any thing , please return to previous menu to order";
}else if (!strfnq.equals("") && !strfrq.equals("") && !strfsq.equals("")&& stricq.equals("")) {
txtOrder = "Thank you , You've ordered\n" + strfnq + " fried noodle" + addNdlThing +" and\n"+ strfrq
+ " fried rice" + addRlThing +" and\n" + strfsq + " Steam fish " + addSlThing + "and\n" + stricq + " Steam fish " + addTeac;
} else {
txtOrder = "Thank you , You've ordered\n";
if(!strfnq.equals("")){
txtOrder = txtOrder + strfnq + " fried noodle" + addNdlThing;
}
if(!strfrq.equals("")){
txtOrder = txtOrder + strfrq + " fried rice" + addRlThing;
}
if(!strfsq.equals("")){
txtOrder = txtOrder + strfsq + " Steam fish" + addSlThing;
}
if(!stricq.equals("")){
txtOrder = txtOrder + stricq + " Iced Tea"+ addTeac;
}
}
foodorders.setText(txtOrder);
}
i want to calculate the money spent in result1 and display it in result 2
i have tried using the method they written at the bottom but it dont work as i dont know what to fill in for some . please help me , i really need help on this , and i am typing alot to make the word count so i can post , as i have too much codes they say , and please stop disliking this post , dont be such persons , like this and it will be happy for both parties , asking question dont mean i am stupid
You can sent the value of the sum to the next activity and get it via Bundle in the other activity like this. Think that your are sending it to the activity B
Intent i= new Intent(this,B.class);
i.putExtra("sum",sum);
startActivity(i);
you can send the context to the activity B through either one of the following this,getActivity(),getApplicationContext()
Then inactivity B you can add these lines in onCreate() method, to get the passed content
Bundle MainActivityData= getIntent().getExtras();
int sum= MainActivityData.getString("sum");
I have a listview which inflates 4 different types of row layouts depending on the position(overriden getViewTypeCount() and getItemViewType(int position) to achieve it) .Each row has an Image and other textviews and buttons . I am loading the image in a seaparate thread . I am using android viewholder pattern to cache the viewholders for each row type .
When I scroll from one kind of row layout to another row layout I observe a jerkiness in scrolling .
Any pointers to improve will be appreciated.
public View getView(int arg0, View arg1, ViewGroup arg2) {
int width = (Utils.getWidth(mCtx)-Utils.dpToPx(40, mCtx)) ;
final FeedViewData mFeedViewData = getFeedViewData().get(arg0);
if( getItemViewType(arg0) == Utils.SMALL_OBJECT_LEFT){
ObjectViewHolder viewHolderLeft = new ObjectViewHolder() ;
float imgWidth = (width-Utils.dpToPx(1, mCtx))*(0.6f);
float descWidth = (width-Utils.dpToPx(1, mCtx))*(0.4f) ;
float rowHeight = (width-Utils.dpToPx(1, mCtx))*(0.6f)*Utils.PRODUCT_PRI_ASPECT_RATIO;
if(arg1==null){
LayoutInflater inflater = ((Activity)mCtx).getLayoutInflater();
arg1 = inflater.inflate(R.layout.view_multipane_left_image, arg2, false);
viewHolderLeft.row = arg1.findViewById(R.id.rowLayout);
viewHolderLeft.imagesLayout = (RelativeLayout)arg1.findViewById(R.id.layout_image);
viewHolderLeft.objImg = (ImageView)arg1.findViewById(R.id.img_object);
viewHolderLeft.price = (TextView)arg1.findViewById(R.id.text_price);
viewHolderLeft.paneMargin = arg1.findViewById(R.id.pane_margin);
viewHolderLeft.descriptionsLayout = (LinearLayout)arg1.findViewById(R.id.layout_description);
viewHolderLeft.likeActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_like);
viewHolderLeft.likeCount = (TextView)arg1.findViewById(R.id.text_like_count);
viewHolderLeft.shareActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_share);
viewHolderLeft.shareCount = (TextView)arg1.findViewById(R.id.text_share_count);
viewHolderLeft.commentActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_comment);
viewHolderLeft.commentCount = (TextView)arg1.findViewById(R.id.text_share_comment);
viewHolderLeft.activityLayout = (LinearLayout)arg1.findViewById(R.id.layout_activity);
viewHolderLeft.userImg = (ImageView)arg1.findViewById(R.id.img_user);
viewHolderLeft.userActivity = (TextView)arg1.findViewById(R.id.text_activity);
viewHolderLeft.timeline = (TextView)arg1.findViewById(R.id.text_timeline);
RelativeLayout.LayoutParams imgLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
imgLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
viewHolderLeft.objImg.setLayoutParams(imgLp);
RelativeLayout.LayoutParams rlLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
rlLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
rlLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
viewHolderLeft.imagesLayout.setLayoutParams(rlLp);
RelativeLayout.LayoutParams marginLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams(Utils.dpToPx(1,mCtx),(int)rowHeight));
marginLp.addRule(RelativeLayout.RIGHT_OF,R.id.layout_image);
viewHolderLeft.paneMargin.setLayoutParams(marginLp);
RelativeLayout.LayoutParams descLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)descWidth,(int)rowHeight));
descLp.addRule(RelativeLayout.RIGHT_OF,R.id.pane_margin);
descLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
viewHolderLeft.descriptionsLayout.setLayoutParams(descLp);
ImageSizeUtils.defineTargetSizeForView(viewHolderLeft.objImg, (int)imgWidth,(int)rowHeight);
arg1.setTag(viewHolderLeft);
}
else{
viewHolderLeft = (ObjectViewHolder)arg1.getTag();
ImageSizeUtils.defineTargetSizeForView(viewHolderLeft.objImg, (int)imgWidth,(int)rowHeight);
}
String mLeftImgUrl = null;
mLeftImgUrl = Utils.m_img_base_url+
mFeedViewData.getProductId() + "/pri-" + mFeedViewData.getFileidn()+".jpg";
try{
ImageLoader.getInstance().displayImage(mLeftImgUrl, viewHolderLeft.objImg,
new SingleImageListener(mFeedViewData,viewHolderLeft.objImg));
}
catch(Exception e){
return null;
}
viewHolderLeft.objImg.setOnClickListener(new ProdImageOnClickListener(mFeedViewData));
if(mFeedViewData.getIsLoved())
viewHolderLeft.likeActionLayout.setBackgroundColor(mCtx.getResources().getColor(R.color.auth_btn_color_normal));
else
viewHolderLeft.likeActionLayout.setBackgroundResource(R.drawable.selector_pink_button);
viewHolderLeft.likeActionLayout.setOnClickListener(new LikeActionListener(mFeedViewData,viewHolderLeft.likeActionLayout));
viewHolderLeft.shareActionLayout.setOnClickListener(new ShareClickListener(mLeftImgUrl));
viewHolderLeft.commentActionLayout.setOnClickListener(new OnCommentClickListener(mFeedViewData));
viewHolderLeft.price.setTypeface(Utils.getFontForRupeeSymb(mCtx));
viewHolderLeft.price.setText(Html.fromHtml( "` " + "</font>" + "<b>" + mFeedViewData.getPrice() + "</b>"));
if(!mFeedViewData.getLikeCount().equals("0"))
viewHolderLeft.likeCount.setText(" (" + mFeedViewData.getLikeCount() + ")");
if(!mFeedViewData.getShareCount().equals("0"))
viewHolderLeft.shareCount.setText(" (" + mFeedViewData.getShareCount() + ")");
if(!mFeedViewData.getRevCount().equals("0"))
viewHolderLeft.commentCount.setText(" (" + mFeedViewData.getRevCount() + ")");
int minutes=0;
if(mFeedViewData.getTimestamp()!=""){
long timeDiff = System.currentTimeMillis() - Long.parseLong(mFeedViewData.getTimestamp());
minutes = (int)((int) (timeDiff/1000))/60;
}
if(mFeedViewData.getUsername().length()>0){
ImageLoader.getInstance().displayImage(mFeedViewData.getTnPic(), viewHolderLeft.userImg,new UserImageListener(viewHolderLeft.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getUsername() + "</b>" + " "+ mFeedViewData.getActivity()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getDoer()), 0, mFeedViewData.getUsername().length(), Spanned.SPAN_COMPOSING);
viewHolderLeft.userActivity.setText(ss);
if(minutes!=0){
viewHolderLeft.timeline.setText( minutes + " minutes ago");
}
viewHolderLeft.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getReview()!=null){
ImageLoader.getInstance().displayImage(mFeedViewData.getReview().getTnUrl(), viewHolderLeft.userImg,new UserImageListener(viewHolderLeft.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getReview().getReviewerName() + "</b>" + " "+ mFeedViewData.getReview().getReview()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getReview().getId()), 0, mFeedViewData.getReview().getReviewerName().length(), Spanned.SPAN_COMPOSING);
viewHolderLeft.userActivity.setText(ss);
if(minutes!=0){
viewHolderLeft.timeline.setText( minutes + " minutes ago");
}
viewHolderLeft.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getActivity().length()>0){
String activityText;
if(mFeedViewData.getActivity().equals("null"))
activityText = Html.fromHtml("<b>" + "A user: "+ "</b>" + "" +" ").toString();
else
activityText = Html.fromHtml("<b>" + "A user: "+ "</b>" + "" +" "+ mFeedViewData.getActivity()).toString();
viewHolderLeft.userActivity.setText(activityText);
if(minutes!=0){
viewHolderLeft.timeline.setText( minutes + " minutes ago");
}
viewHolderLeft.userImg.setImageResource(R.drawable.ic_blank_profile);
}
if(feedType == Utils.ADAPTER_FEED_TUTORIAL){
viewHolderLeft.userActivity.setClickable(false);
viewHolderLeft.objImg.setClickable(false);
}
}
else if(getItemViewType(arg0) == Utils.SMALL_OBJECT_RIGHT){
ObjectViewHolder viewHolderRight = new ObjectViewHolder();
float imgWidth = (width-Utils.dpToPx(1, mCtx))*(0.6f);
float descWidth = (width-Utils.dpToPx(1, mCtx))*(0.4f) ;
float rowHeight = (width-Utils.dpToPx(1, mCtx))*(0.6f)*Utils.PRODUCT_PRI_ASPECT_RATIO;
if(arg1==null){
LayoutInflater inflater = ((Activity)mCtx).getLayoutInflater();
arg1 = inflater.inflate(R.layout.view_multipane_right_image, arg2, false);
viewHolderRight.row = arg1.findViewById(R.id.rowLayout);
viewHolderRight.imagesLayout = (RelativeLayout)arg1.findViewById(R.id.layout_image);
viewHolderRight.objImg = (ImageView)arg1.findViewById(R.id.img_object);
viewHolderRight.price = (TextView)arg1.findViewById(R.id.text_price);
viewHolderRight.paneMargin = arg1.findViewById(R.id.pane_margin);
viewHolderRight.descriptionsLayout = (LinearLayout)arg1.findViewById(R.id.layout_description);
viewHolderRight.likeActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_like);
viewHolderRight.likeCount = (TextView)arg1.findViewById(R.id.text_like_count);
viewHolderRight.shareActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_share);
viewHolderRight.shareCount = (TextView)arg1.findViewById(R.id.text_share_count);
viewHolderRight.commentActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_comment);
viewHolderRight.commentCount = (TextView)arg1.findViewById(R.id.text_share_comment);
viewHolderRight.activityLayout = (LinearLayout)arg1.findViewById(R.id.layout_activity);
viewHolderRight.userImg = (ImageView)arg1.findViewById(R.id.img_user);
viewHolderRight.userActivity = (TextView)arg1.findViewById(R.id.text_activity);
viewHolderRight.timeline = (TextView)arg1.findViewById(R.id.text_timeline);
RelativeLayout.LayoutParams descLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)descWidth,(int)rowHeight));
descLp.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
descLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
viewHolderRight.descriptionsLayout.setLayoutParams(descLp);
RelativeLayout.LayoutParams marginLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams(Utils.dpToPx(1,mCtx),(int)rowHeight));
marginLp.addRule(RelativeLayout.RIGHT_OF,R.id.layout_description);
viewHolderRight.paneMargin.setLayoutParams(marginLp);
RelativeLayout.LayoutParams imgLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
imgLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
viewHolderRight.objImg.setLayoutParams(imgLp);
RelativeLayout.LayoutParams rlLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
rlLp.addRule(RelativeLayout.RIGHT_OF,R.id.pane_margin);
rlLp.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
viewHolderRight.imagesLayout.setLayoutParams(rlLp);
ImageSizeUtils.defineTargetSizeForView(viewHolderRight.objImg, (int)imgWidth,(int)rowHeight);
arg1.setTag(viewHolderRight);
}
else{
viewHolderRight = (ObjectViewHolder)arg1.getTag();
ImageSizeUtils.defineTargetSizeForView(viewHolderRight.objImg, (int)imgWidth,(int)rowHeight);
}
String mRightImgUrl = null;
mRightImgUrl = Utils.m_img_base_url+
mFeedViewData.getProductId() + "/pri-" + mFeedViewData.getFileidn()+".jpg";
try{
ImageLoader.getInstance().displayImage(mRightImgUrl, viewHolderRight.objImg,
new SingleImageListener(mFeedViewData,viewHolderRight.objImg));
}
catch(Exception e){
return null;
}
viewHolderRight.objImg.setOnClickListener(new ProdImageOnClickListener(mFeedViewData));
if(mFeedViewData.getIsLoved())
viewHolderRight.likeActionLayout.setBackgroundColor(mCtx.getResources().getColor(R.color.auth_btn_color_normal));
else
viewHolderRight.likeActionLayout.setBackgroundResource(R.drawable.selector_pink_button);
viewHolderRight.likeActionLayout.setOnClickListener(new LikeActionListener(mFeedViewData,viewHolderRight.likeActionLayout));
viewHolderRight.shareActionLayout.setOnClickListener(new ShareClickListener(mRightImgUrl));
viewHolderRight.commentActionLayout.setOnClickListener(new OnCommentClickListener(mFeedViewData));
viewHolderRight.price.setTypeface(Utils.getFontForRupeeSymb(mCtx));
viewHolderRight.price.setText(Html.fromHtml( "` " + "</font>" + "<b>" + mFeedViewData.getPrice() + "</b>"));
if(!mFeedViewData.getLikeCount().equals("0"))
viewHolderRight.likeCount.setText(" (" + mFeedViewData.getLikeCount() + ")");
if(!mFeedViewData.getShareCount().equals("0"))
viewHolderRight.shareCount.setText(" (" + mFeedViewData.getShareCount() + ")");
if(!mFeedViewData.getRevCount().equals("0"))
viewHolderRight.commentCount.setText(" (" + mFeedViewData.getRevCount() + ")");
int minutes=0;
if(mFeedViewData.getTimestamp()!=""){
long timeDiff = System.currentTimeMillis() - Long.parseLong(mFeedViewData.getTimestamp());
minutes = (int)((int) (timeDiff/1000))/60;
}
if(mFeedViewData.getUsername().length()>0){
ImageLoader.getInstance().displayImage(mFeedViewData.getTnPic(), viewHolderRight.userImg,new UserImageListener(viewHolderRight.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getUsername() + "</b>" + " "+ mFeedViewData.getActivity()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getDoer()), 0, mFeedViewData.getUsername().length(), Spanned.SPAN_COMPOSING);
viewHolderRight.userActivity.setText(ss);
if(minutes!=0){
viewHolderRight.timeline.setText( minutes + " minutes ago");
}
viewHolderRight.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getReview()!=null){
ImageLoader.getInstance().displayImage(mFeedViewData.getReview().getTnUrl(), viewHolderRight.userImg,new UserImageListener(viewHolderRight.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getReview().getReviewerName() + "</b>" + " "+ mFeedViewData.getReview().getReview()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getReview().getId()), 0, mFeedViewData.getReview().getReviewerName().length(), Spanned.SPAN_COMPOSING);
viewHolderRight.userActivity.setText(ss);
if(minutes!=0){
viewHolderRight.timeline.setText( minutes + " minutes ago");
}
viewHolderRight.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getActivity().length()>0){
String activityText = Html.fromHtml("<b>" + "A user: "+ "</b>" + " "+ mFeedViewData.getActivity()).toString();
viewHolderRight.userActivity.setText(activityText);
if(minutes!=0){
viewHolderRight.timeline.setText( minutes + " minutes ago");
}
viewHolderRight.userImg.setImageResource(R.drawable.ic_blank_profile);
}
if(feedType == Utils.ADAPTER_FEED_TUTORIAL){
viewHolderRight.userActivity.setClickable(false);
viewHolderRight.objImg.setClickable(false);
}
}
else if(getItemViewType(arg0) == Utils.MAGAZINE_OBJECT){
MagazineViewHolder viewHolderMag = new MagazineViewHolder();
float imgWidth = width/2;
float descWidth = width;
float rowHeight = ((width)/2)*Utils.MAG_ASPECT_RATIO;
if(arg1==null){
LayoutInflater inflater = ((Activity)mCtx).getLayoutInflater();
arg1 = inflater.inflate(R.layout.view_magazine, arg2, false);
viewHolderMag.row = arg1.findViewById(R.id.rowLayout);
viewHolderMag.imagesLayout = (RelativeLayout)arg1.findViewById(R.id.layout_image);
viewHolderMag.magImgLeft = (ImageView)arg1.findViewById(R.id.img_object_1);
viewHolderMag.magImgRight = (ImageView)arg1.findViewById(R.id.img_object_2);
viewHolderMag.price = (TextView)arg1.findViewById(R.id.text_price);
viewHolderMag.likeActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_like);
viewHolderMag.likeCount = (TextView)arg1.findViewById(R.id.text_like_count);
viewHolderMag.shareActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_share);
viewHolderMag.shareCount = (TextView)arg1.findViewById(R.id.text_share_count);
viewHolderMag.commentActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_comment);
viewHolderMag.commentCount = (TextView)arg1.findViewById(R.id.text_share_comment);
viewHolderMag.activityLayout = (LinearLayout)arg1.findViewById(R.id.layout_activity);
viewHolderMag.userImg = (ImageView)arg1.findViewById(R.id.img_user);
viewHolderMag.userActivity = (TextView)arg1.findViewById(R.id.text_activity);
viewHolderMag.timeline = (TextView)arg1.findViewById(R.id.text_timeline);
LinearLayout.LayoutParams imgLp1 = new LinearLayout.LayoutParams(
new LinearLayout.LayoutParams((int)imgWidth,(int)rowHeight));
imgLp1.gravity = Gravity.CENTER;
viewHolderMag.magImgLeft.setLayoutParams(imgLp1);
viewHolderMag.magImgRight.setLayoutParams(imgLp1);
RelativeLayout.LayoutParams rlLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)descWidth,(int)rowHeight));
viewHolderMag.imagesLayout.setLayoutParams(rlLp);
ImageSizeUtils.defineTargetSizeForView(viewHolderMag.magImgLeft,(int) imgWidth,(int)rowHeight);
ImageSizeUtils.defineTargetSizeForView(viewHolderMag.magImgRight,(int) imgWidth,(int)rowHeight);
arg1.setTag(viewHolderMag);
}
else{
viewHolderMag = (MagazineViewHolder)arg1.getTag();
ImageSizeUtils.defineTargetSizeForView(viewHolderMag.magImgLeft,(int) imgWidth,(int)rowHeight);
ImageSizeUtils.defineTargetSizeForView(viewHolderMag.magImgRight,(int) imgWidth,(int)rowHeight);
}
String mImgUrlLeft = Utils.m_img_mag_base_url+mFeedViewData.getFileidn().split("-")[1]+".jpg";
String mImgUrlRight = Utils.m_img_mag_base_url+mFeedViewData.getFileidn().split("-")[2];
try{
ImageLoader.getInstance().displayImage(mImgUrlLeft, viewHolderMag.magImgLeft,
new MagazineImageListener(viewHolderMag.magImgLeft));
ImageLoader.getInstance().displayImage(mImgUrlRight, viewHolderMag.magImgRight,
new MagazineImageListener(viewHolderMag.magImgRight));
}
catch(Exception e){
return null;
}
viewHolderMag.imagesLayout.setOnClickListener(new ProdImageOnClickListener(mFeedViewData));
viewHolderMag.price.setTypeface(Utils.getFontForRupeeSymb(mCtx));
viewHolderMag.price.setText(Html.fromHtml( "` " + "</font>" + "<b>" + mFeedViewData.getPrice() + "</b>"));
//TODO: Remove once mag has price
viewHolderMag.price.setVisibility(View.GONE);
if(!mFeedViewData.getLikeCount().equals("0"))
viewHolderMag.likeCount.setText(" (" + mFeedViewData.getLikeCount() + ")");
if(!mFeedViewData.getShareCount().equals("0"))
viewHolderMag.shareCount.setText(" (" + mFeedViewData.getShareCount() + ")");
if(!mFeedViewData.getRevCount().equals("0"))
viewHolderMag.commentCount.setText(" (" + mFeedViewData.getRevCount() + ")");
if(mFeedViewData.getIsLoved())
viewHolderMag.likeActionLayout.setBackgroundColor(mCtx.getResources().getColor(R.color.auth_btn_color_normal));
else
viewHolderMag.likeActionLayout.setBackgroundResource(R.drawable.selector_pink_button);
viewHolderMag.shareActionLayout.setOnClickListener(new ShareClickListener(mFeedViewData.getMagImage()));
viewHolderMag.likeActionLayout.setOnClickListener(new LikeActionListener(mFeedViewData,viewHolderMag.likeActionLayout));
viewHolderMag.commentActionLayout.setOnClickListener(new OnCommentClickListener(mFeedViewData));
int minutes=0;
if(mFeedViewData.getTimestamp()!=""){
long timeDiff = System.currentTimeMillis() - Long.parseLong(mFeedViewData.getTimestamp());
minutes = (int)((int) (timeDiff/1000))/60;
}
if(mFeedViewData.getUsername().length()>0){
ImageLoader.getInstance().displayImage(mFeedViewData.getTnPic(), viewHolderMag.userImg,new UserImageListener(viewHolderMag.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getUsername() + "</b>" + " "+ mFeedViewData.getActivity()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getDoer()), 0, mFeedViewData.getUsername().length(), Spanned.SPAN_COMPOSING);
viewHolderMag.userActivity.setText(ss);
if(minutes!=0){
viewHolderMag.timeline.setText( minutes + " minutes ago");
}
viewHolderMag.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getReview()!=null){
ImageLoader.getInstance().displayImage(mFeedViewData.getReview().getTnUrl(), viewHolderMag.userImg,new UserImageListener(viewHolderMag.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getReview().getReviewerName() + "</b>" + " "+ mFeedViewData.getReview().getReview()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getReview().getId()), 0, mFeedViewData.getReview().getReviewerName().length(), Spanned.SPAN_COMPOSING);
viewHolderMag.userActivity.setText(ss);
if(minutes!=0){
viewHolderMag.timeline.setText( minutes + " minutes ago");
}
viewHolderMag.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getActivity().length()>0){
String activityText = Html.fromHtml("<b>" + "A user: "+ "</b>" + " "+ mFeedViewData.getActivity()).toString();
viewHolderMag.userActivity.setText(activityText);
if(minutes!=0){
viewHolderMag.timeline.setText( minutes + " minutes ago");
}
viewHolderMag.userImg.setImageResource(R.drawable.ic_blank_profile);
}
if(feedType == Utils.ADAPTER_FEED_TUTORIAL){
viewHolderMag.userActivity.setClickable(false);
viewHolderMag.imagesLayout.setClickable(false);
}
}
else if(getItemViewType(arg0) == Utils.SCRAP_OBJECT){
ObjectViewHolder viewHolderScrap = new ObjectViewHolder();
float imgWidth = width;
float rowHeight = (width)*Utils.SCRAPBOOK_ASPECT_RATIO;
if(arg1==null){
LayoutInflater inflater = ((Activity)mCtx).getLayoutInflater();
arg1 = inflater.inflate(R.layout.view_single_pane, arg2, false);
viewHolderScrap.row = arg1.findViewById(R.id.rowLayout);
viewHolderScrap.imagesLayout = (RelativeLayout)arg1.findViewById(R.id.layout_image);
viewHolderScrap.objImg = (ImageView)arg1.findViewById(R.id.img_object);
viewHolderScrap.price = (TextView)arg1.findViewById(R.id.text_price);
viewHolderScrap.likeActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_like);
viewHolderScrap.likeCount = (TextView)arg1.findViewById(R.id.text_like_count);
viewHolderScrap.shareActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_share);
viewHolderScrap.shareCount = (TextView)arg1.findViewById(R.id.text_share_count);
viewHolderScrap.commentActionLayout = (RelativeLayout)arg1.findViewById(R.id.layout_action_comment);
viewHolderScrap.commentCount = (TextView)arg1.findViewById(R.id.text_share_comment);
viewHolderScrap.activityLayout = (LinearLayout)arg1.findViewById(R.id.layout_activity);
viewHolderScrap.userImg = (ImageView)arg1.findViewById(R.id.img_user);
viewHolderScrap.userActivity = (TextView)arg1.findViewById(R.id.text_activity);
viewHolderScrap.timeline = (TextView)arg1.findViewById(R.id.text_timeline);
RelativeLayout.LayoutParams imgLp1 = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
viewHolderScrap.objImg.setLayoutParams(imgLp1);
RelativeLayout.LayoutParams rlLp = new RelativeLayout.LayoutParams(
new RelativeLayout.LayoutParams((int)imgWidth,(int)rowHeight));
viewHolderScrap.imagesLayout.setLayoutParams(rlLp);
ImageSizeUtils.defineTargetSizeForView(viewHolderScrap.objImg,(int) imgWidth,(int)rowHeight);
arg1.setTag(viewHolderScrap);
}
else{
viewHolderScrap = (ObjectViewHolder)arg1.getTag();
ImageSizeUtils.defineTargetSizeForView(viewHolderScrap.objImg,(int) imgWidth,(int)rowHeight);
}
String mNormalImgUrl = null;
mNormalImgUrl = Utils.m_img_scrap_base_url + mFeedViewData.getScrapId() + ".png";
try{
ImageLoader.getInstance().displayImage(mNormalImgUrl, viewHolderScrap.objImg,
new SingleImageListener(mFeedViewData,viewHolderScrap.objImg));
}
catch(Exception e){
return null;
}
viewHolderScrap.objImg.setOnClickListener(new ProdImageOnClickListener(mFeedViewData));
if(mFeedViewData.getIsLoved())
viewHolderScrap.likeActionLayout.setBackgroundColor(mCtx.getResources().getColor(R.color.auth_btn_color_normal));
else
viewHolderScrap.likeActionLayout.setBackgroundResource(R.drawable.selector_pink_button);
viewHolderScrap.likeActionLayout.setOnClickListener(new LikeActionListener(mFeedViewData,viewHolderScrap.likeActionLayout));
viewHolderScrap.shareActionLayout.setOnClickListener(new ShareClickListener(mNormalImgUrl));
viewHolderScrap.commentActionLayout.setOnClickListener(new OnCommentClickListener(mFeedViewData));
viewHolderScrap.price.setTypeface(Utils.getFontForRupeeSymb(mCtx));
viewHolderScrap.price.setText(Html.fromHtml( "` " + "</font>" + "<b>" + mFeedViewData.getPrice() + "</b>"));
//TODO:Remove once scrap has price
viewHolderScrap.price.setVisibility(View.GONE);
if(!mFeedViewData.getLikeCount().equals("0"))
viewHolderScrap.likeCount.setText(" (" + mFeedViewData.getLikeCount() + ")");
if(!mFeedViewData.getShareCount().equals("0"))
viewHolderScrap.shareCount.setText(" (" + mFeedViewData.getShareCount() + ")");
if(!mFeedViewData.getRevCount().equals("0"))
viewHolderScrap.commentCount.setText(" (" + mFeedViewData.getRevCount() + ")");
int minutes=0;
if(mFeedViewData.getTimestamp()!=""){
long timeDiff = System.currentTimeMillis() - Long.parseLong(mFeedViewData.getTimestamp());
minutes = (int)((int) (timeDiff/1000))/60;
}
if(mFeedViewData.getUsername().length()>0 && (!mFeedViewData.getActivity().equals("null")) && mFeedViewData.getActivity().length()>0){
ImageLoader.getInstance().displayImage(mFeedViewData.getTnPic(), viewHolderScrap.userImg,new UserImageListener(viewHolderScrap.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getUsername() + "</b>" + " "+ mFeedViewData.getActivity()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getDoer()), 0, mFeedViewData.getUsername().length(), Spanned.SPAN_COMPOSING);
viewHolderScrap.userActivity.setText(ss);
if(minutes!=0){
viewHolderScrap.timeline.setText( minutes + " minutes ago");
}
viewHolderScrap.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getReview()!=null){
ImageLoader.getInstance().displayImage(mFeedViewData.getReview().getTnUrl(), viewHolderScrap.userImg,new UserImageListener(viewHolderScrap.userImg));
String activityText = Html.fromHtml("<b>" + mFeedViewData.getReview().getReviewerName() + "</b>" + " "+ mFeedViewData.getReview().getReview()).toString();
SpannableString ss = new SpannableString(activityText);
ss.setSpan(new MyClickableSpan(activityText, mFeedViewData.getReview().getId()), 0, mFeedViewData.getReview().getReviewerName().length(), Spanned.SPAN_COMPOSING);
viewHolderScrap.userActivity.setText(ss);
if(minutes!=0){
viewHolderScrap.timeline.setText( minutes + " minutes ago");
}
viewHolderScrap.userActivity.setMovementMethod(LinkMovementMethod.getInstance());
}
else if(mFeedViewData.getActivity().length()>0){
String activityText = Html.fromHtml("<b>" + "A user: "+ "</b>" + " "+ mFeedViewData.getActivity()).toString();
viewHolderScrap.userActivity.setText(activityText);
if(minutes!=0){
viewHolderScrap.timeline.setText( minutes + " minutes ago");
}
viewHolderScrap.userImg.setImageResource(R.drawable.ic_blank_profile);
}
if(feedType == Utils.ADAPTER_FEED_TUTORIAL){
viewHolderScrap.userActivity.setClickable(false);
viewHolderScrap.objImg.setClickable(false);
}
}
return arg1;
}
Make sure you do not load or process any images in Adapter.getView() method. If you need to do so, do it in a separate AsyncTask. If you download images from Internet you should better use some helper libraries like Volley or Picasso
I use this library to load images in list view, I never had a problem:Android Image Loader