I want to have two Ribbon XML in one Outlook Add-In. Ribbon2 is a button in a context menu and Ribbon1 is a tab in Outlook Mail Read. I did this - VSTO - Is it possible to have both designer and XML ribbons?, but then getLabel, getVisible, etc, doesn't work! Can you please help me? Thanks!!
mardi 4 août 2015
ImageView in SurfaceView without XML
My question is if is possible add an ImageView in a SurfaceView without XML. If yes, how? I have a main class that has the function of GamePanel, and for apply a Method i need to call it with an ImageView, but i don't know if it is possible. Thanks you in advance.
XMLStreamReader how to work with nested elements of same type
I'm working with the XMLStreamReader and parsing the following XML:
<root>
<element>
<attribute>level0</attribute>
<element>
<attribute>level1</attribute>
<element>
<attribute>level2</attribute>
</element>
</element>
</element>
</root>
I'm building out my XMLStreamReader:
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
new ByteArrayInputStream(document.getBytes()));
Unfortunately, when I get to the first closing element tag with reader.next();, I get the following exception:
javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,14]
Message: XML document structures must start and end within the same entity.
Is there a way to override the default behavior of the XMLStreamReader to get around with this?
Android Application is able to run smoothly but show up blank page
In my database I have 2 tables, table category, and table menu. In the category table, each restaurant has different category(i.e Restaurant1: {category: food, beverage}, Restaurant2: {category: snacks,dessert}. Now I want to retrieve the menu for each category of the selected restaurant as an expandable list. the category name as the group list and the menu in that category as the child list. So far I have managed to retrieve the array of data and tried to use my own custom adapter to create the expandablelist, but the app is able to run but shows a blank page.
MainActivity.java
package com.example.ed.expandablelistview;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainActivity extends Activity {
HashMap<String, List<String>> countriesHashMap;
List<String> countriesHashMapKeys;
ExpandableListView expandableListView;
MyCustomAdapter adapter;
private static final String TAG_SUCCESS = "success";
private static final String TAG_CAT_LIST = "cat_list";
private static final String TAG_MENU_LIST = "menu_list";
private static final String TAG_CAT = "category";
private static final String TAG_ITEM = "item";
private static String url_get_menu_list = "http://ift.tt/1N7UEJV";
private static String url_get_cat_list = "http://ift.tt/1VZuYVP";
ArrayList<HashMap<String, String>> catList;
JSONArray menu_list = null;
List<String> catFoodList = new ArrayList<String>();
HashMap<String, List<String>> menuHashMap = new HashMap<String, List<String>>();
JSONParser jParser = new JSONParser();
JSONArray cat_list = null;
String rest_name, rest_pid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ShowMenu().execute();
expandableListView = (ExpandableListView) findViewById(R.id.expandableList);
countriesHashMap = menuHashMap;
countriesHashMapKeys = new ArrayList<String>(countriesHashMap.keySet());
adapter = new MyCustomAdapter(this, countriesHashMap, countriesHashMapKeys);
expandableListView.setAdapter(adapter);
}
public class ShowMenu extends AsyncTask<String, HashMap<String, List<String>>, String> {
protected String doInBackground(String... args) {
rest_name = "Restaurant";
rest_pid = "2";
catList = new ArrayList<HashMap<String, String>>();
//building params
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("rest", rest_name));
params.add(new BasicNameValuePair("pid", rest_pid));
//getting JSON string from url
JSONObject json = jParser.makeHttpRequest(url_get_cat_list, "GET", params);
//check log cat for response
Log.d("Menu : ", json.toString());
//Get Array of category list
try {
//check for success tag
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
//get array of menu
cat_list = json.getJSONArray(TAG_CAT_LIST);
//looping through all cat_list
for (int i = 0; i < cat_list.length(); i++) {
JSONObject c = cat_list.getJSONObject(i);
//storing each json in variable
String category = c.getString(TAG_CAT);
//creating new hashmap
HashMap<String, String> map = new HashMap<String, String>();
//adding each child node to hashmap key => value
map.put(TAG_CAT, category);
//add hashlist to arraylist
catList.add(map);
//Build params to get menu of category
List<NameValuePair> mparams = new ArrayList<NameValuePair>();
mparams.add(new BasicNameValuePair("get_cat", category));
mparams.add(new BasicNameValuePair("get_pid", rest_pid));
//get menu of category
JSONObject menujson = jParser.makeHttpRequest(url_get_menu_list, "GET", mparams);
//check log cat for response
Log.d("Menu : ", menujson.toString());
try {
//check for success tag
int msuccess = menujson.getInt(TAG_SUCCESS);
if (msuccess == 1) {
//get array of menu
menu_list = json.getJSONArray(TAG_MENU_LIST);
for (int m = 0; m < menu_list.length(); m++) {
JSONObject l = menu_list.getJSONObject(m);
String item = l.getString(TAG_ITEM);
catFoodList.add(item);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
menuHashMap.put(category, catFoodList);
}
} else {
//no category found
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
}
MyCustomAdapter.java
package com.example.ed.expandablelistview;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.HashMap;
import java.util.List;
public class MyCustomAdapter extends BaseExpandableListAdapter {
private Context context;
private HashMap<String, List<String>> countriesHashMap;
private List<String> countryList;
public MyCustomAdapter(Context context,
HashMap<String, List<String>> hashMap,
List<String> list) {
countriesHashMap = hashMap;
this.context = context;
this.countriesHashMap = hashMap;
this.countryList = list;
}
@Override
public int getGroupCount() {
return countriesHashMap.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return countriesHashMap.get(countryList.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return countryList.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return countriesHashMap.get(countryList.get(groupPosition)).get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String groupTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.parent_layout, parent, false);
}
TextView parentTextView = (TextView) convertView.findViewById(R.id.textViewParent);
parentTextView.setText(groupTitle);
return convertView;
}
@Override
public View getChildView(int groupPosition,
int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
String childTitle = (String) getChild(groupPosition, childPosition);
if(convertView == null) {
LayoutInflater inflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_layout, parent, false);
}
TextView childTextView = (TextView) convertView.findViewById(R.id.textViewChild);
childTextView.setText(childTitle);
TextView childTextView2 = (TextView) convertView.findViewById(R.id.textViewChild2);
childTextView2.setText("test");
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<ExpandableListView
android:id="@+id/expandableList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/green"
android:dividerHeight="10dp"
android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
></ExpandableListView>
</RelativeLayout>
parent_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/textViewParent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/red"
android:textStyle="bold"/>
</LinearLayout>
child_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:id="@+id/textViewChild"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/orange_dark"
android:gravity="center_horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/white"
/>
</LinearLayout>
I have managed to retrieve the data of the category and the menu from my database as an array, which I put in the hashmap and use the adapter to the expandablelist, but the app shows blank page. All answers and suggestions are greatly welcomed. Thanks in advance.
Two relatives, same height
I have two RelativeLayouts (one next to each other). A White RelativeLayout and red RelativeLayout. As the amount of the text of the white side increases, I want the the red side grow.
what is the best data model to represent mathematical range (in database,xml,json...)?
mathematical range,for example:
greater or equal to 50 and smaller than 100 (>=50 && < 100)
smaller than 10 or greater than 40 (<10 || >40)
I have been thinking about how to represent mathematical range in a file and database, the range may be input by non programmer and I need to keep the input simple,but at another side, it also need to keep the input easy to convert to data and easy to check error input e.g.:"<10 || >100" seems the most simple but it is harder for me to parse the string to get the data,also need to consider input format error
I have been considering some input methods,using >=50 && < 100 as example,which is in key value form:
1.using 1 string to represent whole range:
<rangeInString>=50 && < 100</rangeInString>
2.separate 2 strings,one represent lower bound and another one represent upper bound,then parse each string in program:
<lowerBound> >=50 </lowerBound>
<upperBound> <100 </upperBound>
3.separate lower and upper bound,also separate the sign from number:
<lowerBound>
<sign> >= </sign>
<data>50</data>
</lowerBound>
<upperBound>
<sign> < </sign>
<data>100</data>
</upperBound>
4.separate lower bound and upper bound,also separate sign, and also separate the case that if includes the equal condition:
<lowerBound>
<sign> > </sign>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</lowerBound>
<upperBound>
<sign> < </sign>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</upperBound>
5.auto detect using "&&" or "||",e.g.:>= A with < B,if A < B,must be "&&" e.g.(>= 50 && <100),otherwise it is "||" e.g.(>= 100 || <50):
<A>
<sign> > </sign>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</A>
<B>
<sign> < </sign>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</B>
6.use a field "isAnd" to separate >=50 && < 100 (true) and <=50 || > 100 (false)instead of using field sign "<" and ">" :
<lowerBound>
<isIncludeEqual>true</isIncludeEqual>
<data>50</data>
</lowerBound>
<upperBound>
<isIncludeEqual>false</isIncludeEqual>
<data>100</data>
</upperBound>
<isAnd>true</isAnd>
7.other data model...
I need to consider somethings:
1.easy for non programmer to input
2.easy to convert or parse to data into program
3.easy to check error ,for example,parse string increase the complexity of converting data and checking incorrect format,also there may have other incorrect format,e.g.:<=50 && >100 should not be valid, I may allow auto detect using "&&" or "||" by the sign of input,but it may increase the complexity of the code
can anyone have idea?
Which one better for XML data Mongodb or orientdb
I cannot use an XML base database. Have to choose from mongo DB or orient DB. Which one will be more suitable for XML based data. where I can directly save or fetch XMLs, run xpath, jquery.