Sunday, 1 September 2013

Using HTML5 and CSS display 2 images level with each other, and each with a list below

Using HTML5 and CSS display 2 images level with each other, and each with
a list below

I'm new to CSS. I want to code a page in HTML5 that has 2 rather large
images of equal size and level with each other and with space between
them. I also want a left-margin between the left image and the left edge
of the page.
Directly below each image there will be an unnumbered list of 6 or so
items. Would someone be so kind as to draft the code for this? I know one
way to use CSS for spacing the images:
img { margin-right: 38px; margin-left: 50px; }
But what to do about the lists?
Thanks

Saturday, 31 August 2013

how to retrieve the orderID from custom list view in Android

how to retrieve the orderID from custom list view in Android

Can any one help me in retrieving the order id from custom list view with
check box. I need to get the order id, which are checked, when the show
button is clicked, i need to get the order id which is added to the
mopenOrders array list . the checked/selected order id's from the custom
list view i must retrieve, below is the List view and my code
My main activity:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
ListView mListView;
Button btnShowCheckedItems;
ArrayList<Product> mProducts;
ArrayList<OpenOrders> mOpenOrders;
MultiSelectionAdapter<OpenOrders> mAdapter;
public String serverStatus =null;
private InputStream is;
private AssetManager assetManager;
ArrayList<String> order_Item_Values =new
ArrayList<String>();
int mMAX_ORDERS_TOBEPICKED; //Parameter passed from
server for the selection of max order
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
assetManager=getAssets();
bindComponents();
init();
addListeners();
}
private void bindComponents() {
// TODO Auto-generated method stub
mListView = (ListView) findViewById(android.R.id.list);
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
btnShowCheckedItems = (Button)
findViewById(R.id.btnShowCheckedItems);
}
private void init() {
// TODO Auto-generated method stub
try {
is = assetManager.open("open_order_item_details.txt");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String jString = getStringFromInputStream(is);
String fileContent=jString;
JSONObject jobj = null;
JSONObject jobj1 = null;
JSONObject ItemObj=null;
try {
jobj = new JSONObject(fileContent);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
System.out.println("READ/PARSING JSON");
serverStatus = jobj.getString("SERVER_STATUS");
System.out.println("serverStatusObj: "+serverStatus);
JSONArray serverResponseArray2=jobj.getJSONArray("SERVER_RESPONSE");
for (int m = 0; m < serverResponseArray2.length(); m++) {
String SERVER_RESPONSE = serverResponseArray2.getString(m);
JSONObject Open_Orders_obj = new JSONObject(SERVER_RESPONSE);
mMAX_ORDERS_TOBEPICKED =
Open_Orders_obj.getInt("MAX_ORDERS_TOBEPICKED");
JSONArray ja =
Open_Orders_obj.getJSONArray("ORDER_ITEM_DETAILS");
order_Item_Values.clear();
mOpenOrders = new ArrayList<OpenOrders>();
for(int i=0; i<ja.length(); i++){
String ORDER_ITEM_DETAILS = ja.getString(i);
// System.out.println(ORDER_ITEM_DETAILS);
jobj1 = new JSONObject(ORDER_ITEM_DETAILS);
String ORDERNAME = jobj1.getString("ORDERNAME");
String ORDERID = jobj1.getString("ORDERID");
mOpenOrders.add(new OpenOrders(ORDERID,ORDERNAME));
}
}
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mAdapter = new MultiSelectionAdapter<OpenOrders>(this, mOpenOrders);
mListView.setAdapter(mAdapter);
}
private void addListeners() {
// TODO Auto-generated method stub
btnShowCheckedItems.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(mAdapter != null) {
SparseBooleanArray checked = mListView.getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++) {
if (checked.valueAt(i)) {
int pos = checked.keyAt(i);
Object o = mListView.getAdapter().getItem(pos);
// do something with your item. print it, cast it, add
it to a list, whatever..
Log.d(MainActivity.class.getSimpleName(), "cheked Items: " +
o.toString());
Toast.makeText(getApplicationContext(), "chked Items:: "
+o.toString(), Toast.LENGTH_LONG).show();
}
}
ArrayList<OpenOrders> mArrayProducts = mAdapter.getCheckedItems();
Log.d(MainActivity.class.getSimpleName(), "Selected Items: " +
mArrayProducts.toString());
}
}
private static String getStringFromInputStream(InputStream is) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
}
MultiSelectionAdapter.java
import java.util.ArrayList;
import android.content.Context;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class MultiSelectionAdapter<T> extends BaseAdapter{
Context mContext;
LayoutInflater mInflater;
ArrayList<T> mList;
SparseBooleanArray mSparseBooleanArray;
public MultiSelectionAdapter(Context context, ArrayList<T> list) {
// TODO Auto-generated constructor stub
this.mContext = context;
mInflater = LayoutInflater.from(mContext);
mSparseBooleanArray = new SparseBooleanArray();
mList = new ArrayList<T>();
this.mList = list;
}
public ArrayList<T> getCheckedItems() {
ArrayList<T> mTempArry = new ArrayList<T>();
for(int i=0;i<mList.size();i++) {
if(mSparseBooleanArray.get(i)) {
mTempArry.add(mList.get(i));
}
}
return mTempArry;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup
parent) {
// TODO Auto-generated method stub
if(convertView == null) {
convertView = mInflater.inflate(R.layout.row, null);
}
TextView tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
tvTitle.setText(mList.get(position).toString());
CheckBox mCheckBox = (CheckBox)
convertView.findViewById(R.id.chkEnable);
mCheckBox.setTag(position);
///mCheckBox.setTag(mList.get(position).toString());
mCheckBox.setChecked(mSparseBooleanArray.get(position));
mCheckBox.setOnCheckedChangeListener(mCheckedChangeListener);
return convertView;
}
OnCheckedChangeListener mCheckedChangeListener = new
OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
// TODO Auto-generated method stub
mSparseBooleanArray.put((Integer) buttonView.getTag(), isChecked);
}
};
}
OpenOrders.java
public class OpenOrders {
private String orderID;
private String orderName;
private String itemID;
private String itemName;
public OpenOrders(String orderID, String orderName) {
super();
this.orderID = orderID;
this.orderName = orderName;
}
public String getOrderID() {
return orderID;
}
public void setOrderID(String orderID) {
this.orderID = orderID;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
@Override
public String toString() {
return this.orderName;
}
public void OpenOrderItems(String itemID, String itemName) {
this.itemID = itemID;
this.itemName = itemName;
}
public String getItemID() {
return itemID;
}
public void setItemID(String itemID) {
this.itemID = itemID;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
}
My json: { "SERVER_STATUS": "1", "SERVER_RESPONSE": [ {
"MAX_ORDERS_TOBEPICKED":3, "ORDER_ITEM_DETAILS": [ { "ORDERNAME":
"ORDER1", "ORDERID": "1", "ITEMS": [ { "ITEMNUMBER": 1, "ITEMNAME":
"APPLE-LAPTOP", "CATEGORY":"ELECTRONICS", "ORDERQUANTITY": "5",
"PICKEDQUANTITY": "", "PRICE": "4500 DHMS", "SHOPNAME": "Indico Icon Kits
403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" }, {
"ITEMNUMBER": 2, "ITEMNAME": "DEL-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731094558Victorinox%20Aug%204.JPG",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731094558Victorinox%20Aug%204.JPG"
}, { "ITEMNUMBER": 3, "ITEMNAME": "FUJI-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122832COLLECTOR-ENSEMBLE-RVB%204.JPG",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122832COLLECTOR-ENSEMBLE-RVB%204.JPG"
} ] }, { "ORDERNAME": "ORDER2", "ORDERID": "2", "ITEMS": [ { "ITEMNUMBER":
4, "ITEMNAME": "APPLE-LAPTOP", "CATEGORY":"ELECTRONICS", "ORDERQUANTITY":
"5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS", "SHOPNAME": "Indico Icon
Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg"
}, { "ITEMNUMBER": 5, "ITEMNAME": "DEL-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731125233Boss%204.JPG",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731125233Boss%204.JPG"
}, { "ITEMNUMBER": 6, "ITEMNAME": "FUJI-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg"
} ] }, { "ORDERNAME": "ORDER3", "ORDERID": "3", "ITEMS": [ { "ITEMNUMBER":
7, "ITEMNAME": "APPLE-LAPTOP", "CATEGORY":"ELECTRONICS", "ORDERQUANTITY":
"5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS", "SHOPNAME": "Indico Icon
Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg"
}, { "ITEMNUMBER": 8, "ITEMNAME": "DEL-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg"
}, { "ITEMNUMBER": 9, "ITEMNAME": "FUJI-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" } ] }, {
"ORDERNAME": "ORDER4", "ORDERID": "4", "ITEMS": [ { "ITEMNUMBER": 10,
"ITEMNAME": "AsusE-LAPTOP", "CATEGORY":"ELECTRONICS", "ORDERQUANTITY":
"5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS", "SHOPNAME": "Indico Icon
Kits 403", "ITEMIMAGEURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://www.dubaidutyfree.com/Content/upload/products/20130731122312DG_INTENSE_EDP_100ML_conv%204.jpg"
}, { "ITEMNUMBER": 11, "ITEMNAME": "hp-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" }, {
"ITEMNUMBER": 12, "ITEMNAME": "FUJI-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" } ] }, {
"ORDERNAME": "ORDER5", "ORDERID": "5", "ITEMS": [ { "ITEMNUMBER": 13,
"ITEMNAME": "Asus-k-LAPTOP", "CATEGORY":"ELECTRONICS", "ORDERQUANTITY":
"5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS", "SHOPNAME": "Indico Icon
Kits 403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" }, {
"ITEMNUMBER": 14, "ITEMNAME": "wio-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"SHOPNAME": "Indico Icon Kits 403", "ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" }, {
"ITEMNUMBER": 15, "ITEMNAME": "Accer-LAPTOP", "CATEGORY":"ELECTRONICS",
"ORDERQUANTITY": "5", "PICKEDQUANTITY": "", "PRICE": "4500 DHMS",
"ITEMIMAGEURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg",
"ITEMIMAGEFULLVIEWURL":
"http://s0.geograph.org.uk/photos/43/03/430378_cc40fae8.jpg" } ] } ] } ],
"ERROR_STATUS": "0", "ERROR_RESPONSE": [ { "ERROR_MESSAGE": "" } ] }

iOS block release and self retain cycle

iOS block release and self retain cycle

Im doing some research on blocks, the code here
typedef NSString* (^MyBlock)(void);
@property(copy,nonatomic) MyBlock block1;
in viewdidload
self.block1 = ^{
self
NSLog(@"do block");
return @"a";
};
of course the self is retained, then I do a
self.block = nil;
by checking the retain count of self, I found it reduced by 1, no retain
cycle.
I believe this is the correct situation, the block retains self, when
release the block, self gets released. retaincount reduced.
I made a litte change, and things coms strange: make block a local variable.
in viewdidload
MyBlock block1 = ^{
self
NSLog(@"do block");
return @"a";
};
[block copy]; // retain count of self gets added.
[block release]; // retain count of sell still the same
why? I tried Block_release(), its the same. and when putting a local
variable like NSArray in the block, the retain count fellows the same rule
as self.
there must be some thing different inside of @property, anyone researched
this before? pls help.
Additionally, I do this in ARC, a local variable block will made the
retain cycle, and a instance variable didnt, due to the autorelease, it
holds the self, and few seconds later, it released and self object get
released normally.
is it because the instance variable and local variable are alloc on
different parts in memory? stack ? heap?, are they both copied to heap
when do a [block copy]?
EDIT : not instance variable and local variable. using @property makes it
different, any explanations?

How to solve the CharacterControl issue?

How to solve the CharacterControl issue?

We who use jme3 have a problem with the BetterCharacterControl that
setMaxSlope is not implemented. The developer of the engine says that we
can solve this for ourselves using the new controller:
http://hub.jmonkeyengine.org/forum/topic/setmaxslope-for-bettercharactercontrol/
And I would really like a solution since my game needs this.
I asked about this before but we didn't solve it:
How to improve character control for my 3D game?
Can you help us progress? I've recorded a video with the problem:
http://www.youtube.com/watch?v=PF_UzoOXD0E

__init__() got an unexpected keyword argument 'instance'

__init__() got an unexpected keyword argument 'instance'

Im getting the above error when I run this code. This is happening when I
return return modelformset_factory in def get_form_class(self): But its ok
when I use return modelform_factory. What could be the issue with the
code? Thanks
class ModelAdminMixin(LoginRequiredMixin, PermissionMixin):
model = None
#--------------------------------------------------------------------------
def get_form(self, form_class):
form_class = self.get_form_class()
form_kwargs = self.get_form_kwargs()
if hasattr(self, 'request'):
request = self.request
form_kwargs['request'] = request
return form_class(**form_kwargs)
#--------------------------------------------------------------------------
def get_form_class(self):
# if the View sent has it's own form - use it
if getattr(self, 'form_class', None) is not None:
return self.form_class
# check the global form_override settings
form = None
if self.get_model() in form_mapping:#There is a form_mapping.py file
# format is Model: Form
form = form_mapping[self.get_model()]
# if no overriding found - use the standard
if form is None:
form = form_mapping['default']
# create model form dynamically
return modelformset_factory(self.get_model(), extra=2)
#--------------------------------------------------------------------------
def get_model(self):
return self.model
def get_queryset(self):
""" Default queryset is all model's instances
"""
return self.get_model()._default_manager.all()
#--------------------------------------------------------------------------
def get_context_data(self, **kwargs):
""" Inject models into context
"""
context = super(ModelAdminMixin, self).get_context_data(**kwargs)
context['model'] = self.get_model()
context['model_str'] = str(self.get_model())
return context
#--------------------------------------------------------------------------
def dispatch(self, request, *args, **kwargs):
""" Dynamic model import
"""
app = self.kwargs.get('app')
model = self.kwargs.get('model')
if self.model is None and app and model:
app = __import__(app)
app_models = getattr(app, 'models')
model = getattr(app_models, model)
self.model = model
return super(ModelAdminMixin, self).dispatch(request, *args, **kwargs)

How to remove each item that appeares in first collection from second collection using linq?

How to remove each item that appeares in first collection from second
collection using linq?

Suppose I have 2 collections:
1) {1, 2, 3, 5}
2) {2, 5}
I want to remove each item that appears in second collection from first
collection, so I will get:
{1, 3}
Questions:
How can I do this with Join OP (better with extension methods syntax)?
And is there any way I can iterate over two collections as I do with
nested for/foreach loops?

pushViewController doesn't work

pushViewController doesn't work

I have a UIViewController, I want to navigate from this view to my second
view controller
SecondView *secondView=[[SecondView alloc] initWithNibName:@"SecondView"
bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
It doesn't work. It doesn't do anything and there is no error. What I'm
missing?