Make a Call from ListView (OnitemClick) - javascript

I want to try make a call from ListView, (change "Toast" to direct call on ListView).
I hope you guys to help me.
ContactListActiviy.java
package com.ngohung.view;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.markupartist.android.widget.ActionBar;
import com.ngohung.example.adapter.ExampleContactAdapter;
import com.ngohung.example.models.ExampleContactItem;
import com.ngohung.example.models.ExampleDataSource;
import com.ngohung.widget.ContactItemComparator;
import com.ngohung.widget.ContactItemInterface;
import com.ngohung.widget.ContactListView;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class ContactListActivity extends Activity implements TextWatcher {
private ExampleContactListView listview;
private EditText searchBox;
private String searchString;
private Object searchLock = new Object();
boolean inSearchMode = false;
private final static String TAG = "com.ngohung.view.ContactListActivity";
List<ContactItemInterface> contactList;
List<ContactItemInterface> filterList;
private SearchListTask curSearchTask = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_list);
final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
actionBar.setTitle("Layanan Publik Kendari");
actionBar.setHomeLogo(R.drawable.ic_launcher);
filterList = new ArrayList<ContactItemInterface>();
contactList = ExampleDataSource.getSampleContactList();
ExampleContactAdapter adapter = new ExampleContactAdapter(this, R.layout.example_contact_item, contactList);
listview = (ExampleContactListView) this.findViewById(R.id.listview);
listview.setFastScrollEnabled(true);
listview.setAdapter(adapter);
// use this to process individual clicks
// cannot use OnClickListener as the touch event is overrided by IndexScroller
// use last touch X and Y if want to handle click for an individual item within the row
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView parent, View v, int position,
long id) {
List<ContactItemInterface> searchList = inSearchMode ? filterList : contactList ;
float lastTouchX = listview.getScroller().getLastTouchDownEventX();
if(lastTouchX < 45 && lastTouchX > -1){
Toast.makeText(ContactListActivity.this, "User image is clicked ( " + searchList.get(position).getItemForIndex() + ")", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(ContactListActivity.this, "Nomor: " + searchList.get(position).getItemForIndex() , Toast.LENGTH_SHORT).show();
}
});
//My Trial to Add Call
//listview.setOnClickListener(new View.OnClickListener() {
// #Override
//public void onClick(View arg0) {
// TODO Auto-generated method stub
// String phone_no= listview.getScroller().toString().replaceAll("-", ""); //Create "getNumber" exampleContactListView
//Intent callIntent = new Intent(Intent.ACTION_CALL);
//callIntent.setData(Uri.parse(phone_no));
//callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//startActivity(callIntent);
//}
// });
//END Trial
searchBox = (EditText) findViewById(R.id.input_search_query);
searchBox.addTextChangedListener(this);
}
#Override
public void afterTextChanged(Editable s) {
searchString = searchBox.getText().toString().trim().toUpperCase();
if(curSearchTask!=null && curSearchTask.getStatus() != AsyncTask.Status.FINISHED)
{
try{
curSearchTask.cancel(true);
}
catch(Exception e){
Log.i(TAG, "Fail to cancel running search task");
}
}
curSearchTask = new SearchListTask();
curSearchTask.execute(searchString); // put it in a task so that ui is not freeze
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// do nothing
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// do nothing
}
private class SearchListTask extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
filterList.clear();
String keyword = params[0];
inSearchMode = (keyword.length() > 0);
if (inSearchMode) {
// get all the items matching this
for (ContactItemInterface item : contactList) {
ExampleContactItem contact = (ExampleContactItem)item;
if ((contact.getNama().toUpperCase().indexOf(keyword) > -1) ) {
filterList.add(item);
}
}
}
return null;
}
protected void onPostExecute(String result) {
synchronized(searchLock)
{
if(inSearchMode){
ExampleContactAdapter adapter = new ExampleContactAdapter(ContactListActivity.this, R.layout.example_contact_item, filterList);
adapter.setInSearchMode(true);
listview.setInSearchMode(true);
listview.setAdapter(adapter);
}
else{
ExampleContactAdapter adapter = new ExampleContactAdapter(ContactListActivity.this, R.layout.example_contact_item, contactList);
adapter.setInSearchMode(false);
listview.setInSearchMode(false);
listview.setAdapter(adapter);
}
}
}
}
}
ExampleDataSource.java (Btw I'm using an "ArrayList")
package com.ngohung.example.models;
import java.util.ArrayList;
import java.util.List;
import com.ngohung.widget.ContactItemInterface;
public class ExampleDataSource {
public static List<ContactItemInterface> getSampleContactList(){
List<ContactItemInterface> list = new ArrayList<ContactItemInterface> ();
list.add(new ExampleContactItem("Polda SULTRA" , "3195040" ,"Sentral PABX jl haluoleo 1" ) );
list.add(new ExampleContactItem("Polda SULTRA" ,"3195041" , "Sentral PABX jl haluoleo 1") );
list.add(new ExampleContactItem("Polda SULTRA" ,"3195042" , "Sentral PABX jl haluoleo 1" ) );
list.add(new ExampleContactItem("Direktorat diklat" , "3190549" , "Sentral PABX jl haluoleo 1") );
list.add(new ExampleContactItem("Direktorat intelkam" , "3190041", "Jl mayjen di panjaitan 1" ) );
list.add(new ExampleContactItem("Direktorat samapta" ,"3005114", "Jl mayjen di panjaitan") );
list.add(new ExampleContactItem("Direktorat lantas" , "3006112" , "Jl mayjen di panjaitan" ) );
list.add(new ExampleContactItem("Direktorat pol air" , "3007604", "Jl mayjen di panjaitan" ) );
return list;
}
}
Thanks..

Add <uses-permission android:name="android.permission.CALL_PHONE" /> permission to your AndroidManifest file.
Then just start an activity in your list item click listener:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:43..." ));
startActivity(intent);
UPDATE:
Just add the above code in your item click:
#Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
List<ContactItemInterface> searchList = inSearchMode ? filterList : contactList ;
float lastTouchX = listview.getScroller().getLastTouchDownEventX();
if(lastTouchX < 45 && lastTouchX > -1){
Toast.makeText(ContactListActivity.this, "User image is clicked ( " + searchList.get(position).getItemForIndex() + ")", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(ContactListActivity.this, "Nomor: " + searchList.get(position).getItemForIndex() , Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:xxx" ));// replcae "xxx" with the desired number
startActivity(intent);
}
}

Related

Creating a simple search functionality

I was trying to understand how to make a search functions in an app. I go through the Creating a Search Interface documentation, but its quite hard and yea i need help. However, i do succeed to just create a search interface, displaying results based from a string arrray. It does work, but it doesnt had any activity behind it or any intent. It more like a simple text-search. I just wondering can i put int that can simultaneously work with string ?
Or any solution and ideas, really appreciate it.
for now here is my homefragment class
package com.example.testtt;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SearchView;
import androidx.annotation.Nullable;
import java.util.ArrayList;
public class HomeFragment extends Fragment implements View.OnClickListener {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_home, container, false);
//define
RelativeLayout drawerlayouthome;
ListView list;
ListViewAdapter adapter;
SearchView editsearch;
ArrayList<DoaSearchIndex> arrayList = new ArrayList<DoaSearchIndex>();
String[] doasearchindex = getActivity().getResources().getStringArray(R.array.doasearchindex);
//locatelistview
list = v.findViewById(R.id.searchlistview);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
list.setVisibility(View.INVISIBLE);
}
});
for (int i = 0; i < doasearchindex.length; i++) {
DoaSearchIndex doaSearchIndex = new DoaSearchIndex(doasearchindex[i]);
arrayList.add(doaSearchIndex);
}
//pass result to listviewadapter.class
adapter = new ListViewAdapter(this.getActivity(), arrayList);
//binds adapter to listview
list.setAdapter(adapter);
list.setVisibility(View.INVISIBLE);
//locatesearchview
editsearch = v.findViewById(R.id.searchview);
editsearch.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
#Override
public boolean onQueryTextSubmit(String query) {
return false;
}
#Override
public boolean onQueryTextChange(String newText) {
if(TextUtils.isEmpty(newText)){
list.clearTextFilter();
adapter.filter("");
list.setVisibility(View.INVISIBLE);
} else {
adapter.filter(newText);
list.setVisibility(View.VISIBLE);
}
return true;
}
});
drawerlayouthome = v.findViewById(R.id.drawer_layouthome);
drawerlayouthome.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
list.setVisibility(View.INVISIBLE);
editsearch.clearFocus();
}
});
//definingcardview
CardView doacard = v.findViewById(R.id.doacard);
CardView ziarahcard = v.findViewById(R.id.ziarahcard);
//setcardviewlistener
doacard.setOnClickListener(this);
ziarahcard.setOnClickListener(this);
return v;
}
#Override
public void onClick(View view) {
Intent i ;
switch (view.getId()) {
case R.id.doacard:
i = new Intent(getActivity(), listdoa.class);
startActivity(i);
break;
case R.id.ziarahcard:
i = new Intent(getActivity(), listziarah.class);
startActivity(i);
break;
}
}
}
and my listviewadapter
package com.example.testtt;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class ListViewAdapter extends BaseAdapter {
//Declare variables first
Context mContext;
LayoutInflater inflater;
private List<DoaSearchIndex> doaSearchIndexList = null;
private ArrayList<DoaSearchIndex> arrayList;
public ListViewAdapter(Context context, List<DoaSearchIndex> doaSearchIndexList) {
mContext = context;
this.doaSearchIndexList = doaSearchIndexList;
inflater = LayoutInflater.from(mContext);
this.arrayList = new ArrayList<DoaSearchIndex>();
this.arrayList.addAll(doaSearchIndexList);
}
public class ViewHolder {
TextView name;
}
#Override
public int getCount() {
return doaSearchIndexList.size();
}
#Override
public DoaSearchIndex getItem(int position) {
return doaSearchIndexList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.listview_item, null);
// Locate the TextViews in listview_item.xml
holder.name = (TextView) view.findViewById(R.id.name);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.name.setText(doaSearchIndexList.get(position).getDoaSearchIndex());
return view;
}
// Filter Class
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
doaSearchIndexList.clear();
if (charText.length() == 0) {
doaSearchIndexList.addAll(arrayList);
} else {
for (DoaSearchIndex wp : arrayList) {
if (wp.getDoaSearchIndex().toLowerCase(Locale.getDefault()).contains(charText)) {
doaSearchIndexList.add(wp);
}
}
}
notifyDataSetChanged();
}
}
and my doasearchindex class
package com.example.testtt;
public class DoaSearchIndex {
private String doaSearchIndex;
public DoaSearchIndex(String doaSearchIndex) {
this.doaSearchIndex = doaSearchIndex;
}
public String getDoaSearchIndex() {
return this.doaSearchIndex;
}
}

How can I get a value on a button click inside a WebView?

I have a native android app that goes into a WebView for the checkout process. I am implementing appsflyer to track revenue through the app. How can I detect which button was clicked on the page, and what the item price is for revenue?
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import com.appsflyer.AFInAppEventParameterName;
import com.appsflyer.AFInAppEventType;
import com.appsflyer.AppsFlyerLib;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class EventActivity extends AppCompatActivity {
ProgressDialog pDialog;
Boolean redirecting = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event);
String appsFlyerUID = AppCore.getInstance(getApplicationContext()).getAppsFlyerUID();
String idfa = AppCore.getInstance(getApplicationContext()).getMixpanelAdvertisingIdentifier();
Intent intent = getIntent();
try {
JSONObject event = new JSONObject(intent.getStringExtra("event"));
String eventId = event.getString("id");
String title = event.getString("title");
String startsAt = event.getString("starts_at");
String venue = event.getString("venue");
String city = event.getString("city");
String state = event.getString("state");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
Date newDate = format.parse(startsAt);
format = new SimpleDateFormat("EEEE, MMMM d # h:mm a");
String date = format.format(newDate);
((TextView)findViewById(R.id.event_title)).setText(title);
((TextView)findViewById(R.id.event_date)).setText(date);
((TextView)findViewById(R.id.event_venue)).setText(venue + " - " + city + ", " + state);
String url = "http://tlapi.ticketliquidator.com/event_map/" + eventId + "?utm_campaign=" + idfa + "&utm_term=" + appsFlyerUID;
Map<String, Object> eventValue = new HashMap<String, Object>();
AppsFlyerLib.getInstance().trackEvent(getApplicationContext(), "View Event " + eventId,eventValue);
final WebView wv = (WebView) findViewById(R.id.event_webview);
wv.getSettings().setJavaScriptEnabled(true);
final Activity self = this;
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
redirecting = true;
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
if(redirecting){
pDialog.dismiss();
}
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if(redirecting){
pDialog = new ProgressDialog(self);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setMessage(" Loading...");
pDialog.setCancelable(true);
pDialog.show();
}
}
});
pDialog = new ProgressDialog(this);
pDialog.setMessage("Getting event...");
pDialog.show();
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress == 100)
pDialog.dismiss();
}
});
wv.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is my android class for the WebView. I am trying to pull information from this web page...
Api WebView
I just need to know which button was clicked in the WebView, and get the price beside that button. Then I will send that back to appsflyer for tracking.
You'll have to trick it with java script as for that after loading the page you'll have to inject your javascript into the loaded webpage like this
#Override
public void onPageFinished(WebView view, String url){
// your javascript as string which works fine in scratchpad
String javaScript ="javascript:(function() {alert();})()";
webview.loadUrl(javaScript);
}
So that that you can inject the javascript and find the respective DOM as per your requirement and based on that you can call java method like this.
you can't access the event of button click inside your webview, webview is used to run an html page, and for that you have to code inside your html page, use JavaScript to capture onClick event

ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference

import android.content.Context;
import android.graphics.Color;
import android.icu.text.SimpleDateFormat;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.github.sundeepk.compactcalendarview.CompactCalendarView;
import com.github.sundeepk.compactcalendarview.domain.Event;
import java.util.Date;
import java.util.Locale;
public class Calendarpage extends AppCompatActivity {
//modify here
ActionBar actionBar = null;
CompactCalendarView compactCalendar;
private SimpleDateFormat dateFormatMonth = new SimpleDateFormat ("MMM- yyyy", Locale.getDefault());
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
// modify here
ActionBar myActionBar = getSupportActionBar();
if (myActionBar != null) {
myActionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(null);
}
compactCalendar = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendar.setUseThreeLetterAbbreviation(true);
Event ev1 = new Event(Color.RED, 1514160000L, "Chirstmas Day");
compactCalendar.addEvent(ev1);
compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
#Override
public void onDayClick(Date dateClicked) {
Context context = getApplicationContext();
if (dateClicked.toString().compareTo("Mon Dec 25 00:00:00 AST 2017") == 0) {
Toast.makeText(context, "Christmas Day", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(context, "No Events Planned That Day", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onMonthScroll(Date firstDayOfNewMonth) {
getSupportActionBar.setTitle(String.valueOf(dateFormatMonth.format(firstDayOfNewMonth)));
}
});
}
}
now added the changes you made but the getSupportActionBar. is in red? its just asking me to create local variables when right clicking. very stressed with this as I can't move on until this page works.. as I still need to be able to add events to dates
Try to make this change
In your OnCreate :
ActionBar myActionBar = getSupportActionBar();
if (myActionBar != null) {
myActionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(null);
}
In your setListener
#Override
public void onMonthScroll(Date firstDayOfNewMonth) {
getSupportActionBar().setTitle(String.valueOf(
dateFormatMonth.format(firstDayOfNewMonth)));
}
Good luck
EDIT try this
compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
#Override
public void onMonthScroll(Date firstDayOfNewMonth) {
setNewTitleBar(dateFormatMonth.format(firstDayOfNewMonth));
}
});
}
private void setNewTitleBar(String newTitle) {
getSupportActionBar().setTitle(newTitle);
}
}

D3 Intergration Vaadin (could not initialize javascript connector)

I Have D3 Intergrated in my Project.
Anytimes comes the Exception "could not initialize javascript connector because no javascript init function was found"
Here my Code
MainUI
package testd323.asdg;
import java.util.ArrayList;
import java.util.List;
import com.company.grafiktest5.ui.MainView;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Widgetset;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.xdev.ui.XdevUI;
import com.xdev.ui.navigation.XdevNavigator;
#Theme("mytheme")
#SuppressWarnings("serial")
#Widgetset("CircleD3.circle.AppWidgetSet")
#com.vaadin.annotations.JavaScript( {"d3.v3.min.js",
"CircleD3_circle_Diagram.js"} )
public class MainUI extends XdevUI {
final VerticalLayout layout = new VerticalLayout();
final TextField xCoordField = new TextField("X");
final TextField yCoordField = new TextField("Y");
final Button button = new Button("move circle");
final Diagram diagram = new Diagram();
final List<Integer> coords = new ArrayList<>();
#Override
protected void init(final VaadinRequest request) {
configureIntegerField(this.xCoordField); //not interesting, just adding converter/validator to the textFields
configureIntegerField(this.yCoordField);
this.button.addClickListener(new Button.ClickListener() { //ATTENTION! Here we get the coordinates from the textfields and apply them to our Diagram via calling diagram.setCoords()
#Override
public void buttonClick(final Button.ClickEvent event) {
if(MainUI.this.xCoordField.isValid() && MainUI.this.yCoordField.isValid()){
MainUI.this.coords.clear();
MainUI.this.coords.add(Integer.parseInt(MainUI.this.xCoordField.getValue()));
MainUI.this.coords.add(Integer.parseInt(MainUI.this.yCoordField.getValue()));
MainUI.this.diagram.setCoords(MainUI.this.coords);
}
}
});
//now we build the layout.
this.layout.setSpacing(true);
this.layout.addComponent(this.xCoordField);
this.layout.addComponent(this.yCoordField);
this.layout.addComponent(this.button);
this.layout.addComponent(this.diagram); //add the diagram like any other vaadin component, cool!
setContent(this.layout);
}
private void configureIntegerField(final TextField integerField) {
integerField.setConverter(Integer.class);
integerField.addValidator(new IntegerRangeValidator("only integer, 0-500", 0, 500));
integerField.setRequired(true);
integerField.setImmediate(true);
}
Diagramm.Java
package testd323.asdg;
import java.util.List;
import com.vaadin.annotations.JavaScript;
import com.vaadin.ui.AbstractJavaScriptComponent;
#JavaScript({"d3.v3.min.js",
"testd323.asdg.diagram_connector.js"})
public class Diagram extends AbstractJavaScriptComponent {
public void setCoords(final List<Integer> coords) {
getState().setCoords(coords);
}
#Override
public DiagramState getState() {
return (DiagramState) super.getState();
}
}
DiagramState.java
package testd323.asdg;
import java.util.List;
import com.vaadin.shared.ui.JavaScriptComponentState;
public class DiagramState extends JavaScriptComponentState {
private List<Integer> coords;
public List<Integer> getCoords() {
return this.coords;
}
public void setCoords(final List<Integer> coords) {
this.coords = coords;
}
}
diagram_connector.js
window.testd323_asdg_Diagram = function() {
var diagramElement = this.getElement();
var diagramFrame = d3.select(diagramElement).append("svg:svg").attr("width", 500).attr("height", 500);
diagramFrame.append("svg:circle").attr("cx", 250).attr("cy", 250).attr("r", 20).attr("fill", "red");
this.onStateChange = function() {
var coords = this.getState().coords;
d3.selectAll("circle").transition().attr("cx", parseInt(coords[0]));
d3.selectAll("circle").transition().delay(500).attr("cy", parseInt(coords[1]));
}
Hope that anyone can help me.
Thanks!
The JavaScript files need to be in resources/testd323/asdg in order to be found.

clicked listview to open detail view in android

I have an XML file that consists of a title, a link to the image, and description.
exp.
<?xml ?>
<wrap>
<content>
<title>Title</title>
<img>link of image</img>
<desc>Descrioption</desc>
</content>
<content>
<title>Title</title>
<img>link of image</img>
<desc>Descrioption</desc>
</content>
<content>
<title>Title</title>
<img>link of image</img>
<desc>Description</desc>
</content>
</wrap>
I want the title shown on Listview which when clicked will open a detail page complete with titles, pictures, and descriptions .
examples such as those found at the following link Google's developer:
http://developer.android.com/design/material/videos/ContactsAnim.mp4
this is my full code
Anggra.java (this is main activity of my project)
package com.tolhedo.akew.anggra;
import java.util.Locale;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.viewpagerindicator.TitlePageIndicator;
public class Anggra extends ActionBarActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
TitlePageIndicator titlePageIndicator;
private static final int numPages = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_anggra);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
titlePageIndicator = (TitlePageIndicator)findViewById(R.id.titles);
titlePageIndicator.setViewPager(mViewPager);
}
#Override
public void onBackPressed() {
if (mViewPager.getCurrentItem() == 0){
super.onBackPressed();
}
else {
mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_anggra, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position){
case 0:
fragment = new Welcome();
getPageTitle(position);
break;
case 1:
fragment = new ViewContent();
getPageTitle(position);
break;
case 2:
fragment = new ItemFragment();
getPageTitle(position);
break;
}
return fragment;
}
#Override
public int getCount() {
// Show 3 total pages.
return numPages;
}
#Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_anggra, container, false);
return view;
}
}
}
ItemFragment.java
package com.tolhedo.akew.anggra;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import com.tolhedo.akew.anggra.dummy.ResourcesAdapter;
public class ItemFragment extends Fragment{
public ItemFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item, container, false);
listView = (AbsListView) view.findViewById(R.id.list_item);
textView = (TextView) view.findViewById(R.id.name);
Resources resources = getActivity().getResources();
ResourcesAdapter resourcesAdapter = new ResourcesAdapter(resources, view, getActivity());
resourcesAdapter.stringResource();
return view;
}
}
ViewContent.java
package com.tolhedo.akew.anggra;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.tolhedo.akew.anggra.dummy.CustomView;
import com.tolhedo.akew.anggra.dummy.FullView;
import com.tolhedo.akew.anggra.dummy.ParsedDataSet;
import com.tolhedo.akew.anggra.dummy.XmlContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class ViewContent extends Fragment{
private TextView textView;
private AbsListView listView;
private ArrayList<ParsedDataSet> itemList;
private ProgressDialog pDialog;
private XmlContentHandler xmlContentHandler;
private String url = "http://oscom.meximas.com/imagelistview.xml";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.content_view, container, false);
textView = (TextView) view.findViewById(R.id.content);
listView = (AbsListView) view.findViewById(R.id.listView1);
doParsing(view);
itemList = new ArrayList<>();
setListViewClick(listView);
return view;
}
public void doParsing(View view){
if (isNetworkAvailable()){
textView.setText("Loading...");
new AsyncData().execute(url);
}
else
{
showToast("No Network Connection!!!");
}
}
private void showToast(String msg) {
Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT).show();
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivity = (ConnectivityManager) getActivity().getSystemService(getActivity().CONNECTIVITY_SERVICE);
if (connectivity == null)
{
return false;
}
else
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
{
for (int i = 0; i < info.length; i++)
{
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
}
}
return false;
}
private class AsyncData extends AsyncTask<String, Void, Void> {
#Override
protected void onPreExecute()
{
pDialog = new ProgressDialog(getActivity());
pDialog.setTitle("Loading....");
pDialog.setMessage("Please wait...");
pDialog.show();
super.onPreExecute();
}
#Override
protected Void doInBackground(String... params) {
try
{
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser = saxParserFactory.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlContentHandler = new XmlContentHandler();
xmlReader.setContentHandler(xmlContentHandler);
URL _url = new URL(params[0]);
xmlReader.parse(new InputSource(_url.openStream()));
}
catch (ParserConfigurationException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (SAXException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
textView.setText("Read all epic episode of Anggra");
if (pDialog != null && pDialog.isShowing()){
pDialog.dismiss();
}
itemList = xmlContentHandler.getListItem();
if (null != itemList && itemList.size() != 0){
for (int index = 0; index < itemList.size(); index++){
ParsedDataSet parsedDataSet = itemList.get(index);
}
}
itemList = xmlContentHandler.getListItem();
listView.setAdapter(new CustomView(getActivity(),itemList));
}
}
private void setListViewClick (AbsListView listView){
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
itemList = xmlContentHandler.getListItem();
if (null != itemList && itemList.size() != 0){
for (int index = 0; index < itemList.size(); index++){
ParsedDataSet parsedDataSet = itemList.get(index);
textView.setText(parsedDataSet.getDesc());
Intent intent = new Intent(getActivity(), FullView.class);
startActivity(intent);
}
}
}
});
}
public void loadImg(String url, ImageView img){
try{
URL url1 = new URL(url);
HttpURLConnection connection = (HttpURLConnection) url1.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
img.setImageBitmap(BitmapFactory.decodeStream(inputStream));
return;
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
CustomView.java
package com.tolhedo.akew.anggra.dummy;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.tolhedo.akew.anggra.R;
public class CustomView extends BaseAdapter {
Context mContext;
ArrayList<ParsedDataSet> dataSets;
LayoutInflater mInflater;
public CustomView(Context context, ArrayList<ParsedDataSet> itemList)
{
mContext = context;
dataSets = itemList;
mInflater = LayoutInflater.from(context);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return dataSets.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if(convertView == null){
vh= new ViewHolder();
convertView = mInflater.inflate(R.layout.custom_view, parent, false);
vh.tv1 = (TextView) convertView.findViewById(R.id.textView1);
vh.tv2 = (TextView) convertView.findViewById(R.id.textView2);
vh.tv3 = (TextView) convertView.findViewById(R.id.textView3);
vh.tv4 = (TextView) convertView.findViewById(R.id.textView4);
vh.img = (ImageView) convertView.findViewById(R.id.imageView);
convertView.setTag(vh);
}
else {
vh = (ViewHolder) convertView.getTag();
}
ParsedDataSet parsedDataSet = dataSets.get(position);
vh.tv1.setText(parsedDataSet.getTitle());
vh.tv2.setText(parsedDataSet.getDesc());
vh.tv3.setText(parsedDataSet.getPubDate());
vh.tv4.setText(parsedDataSet.getLink());
return convertView;
}
static class ViewHolder
{
TextView tv1,tv2,tv3, tv4;
ImageView img;
}
}
ParseDataSet.java
package com.tolhedo.akew.anggra.dummy;
/**
* Created by akew on 1/14/2015.
*/
public class ParsedDataSet {
private String id;
private String title;
private String desc;
private String pubDate;
private String link;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getPubDate() {
return pubDate;
}
public void setPubDate(String pubDate) {
this.pubDate = pubDate;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}
ResourcesAdapter.java
package com.tolhedo.akew.anggra.dummy;
import android.app.Activity;
import android.content.res.Resources;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.tolhedo.akew.anggra.R;
/**
* Created by akew on 1/8/2015.
*/
public class ResourcesAdapter {
Resources mResources;
View mView;
Activity mActivity;
String[] strings;
AbsListView mListView;
ListAdapter mAdapter;
TextView mTextView;
public ResourcesAdapter(Resources resources, View view, Activity activity){
mActivity = activity;
mResources = resources;
mView = view;
mListView = (AbsListView) view.findViewById(android.R.id.list);
}
public void stringResource(){
strings = mResources.getStringArray(R.array.list_title);
mAdapter = new ArrayAdapter<>(mActivity
, android.R.layout.simple_list_item_1
, android.R.id.text1
, strings);
mListView.setAdapter(mAdapter);
setListViewClick(mListView);
}
private void setListViewClick(AbsListView mListView){
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mTextView = (TextView) view;
Toast.makeText(mActivity
, mTextView.getText()
, Toast.LENGTH_SHORT).show();
}
});
}
}
XmlContentHandler.java
package com.tolhedo.akew.anggra.dummy;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
/**
* Created by akew on 1/14/2015.
*/
public class XmlContentHandler extends DefaultHandler {
Boolean currentElement = false;
String currentValue = "";
ParsedDataSet parsedDataSet = null;
private ArrayList<ParsedDataSet> itemList = new ArrayList<>();
public ArrayList<ParsedDataSet> getListItem() {
return itemList;
}
#Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
currentElement = true;
currentValue = "";
if (localName.equals("item")){
parsedDataSet = new ParsedDataSet();
}
}
#Override
public void endElement(String uri, String localName, String qName) throws SAXException {
currentElement = false;
if (localName.equals("id")){
parsedDataSet.setId(currentValue);
}
else if (localName.equals("title")){
parsedDataSet.setTitle(currentValue);
}
else if (localName.equals("desc")){
parsedDataSet.setDesc(currentValue);
}
else if (localName.equals("pubDate")){
parsedDataSet.setPubDate(currentValue);
}
else if (localName.equals("link")){
parsedDataSet.setLink(currentValue);
}
else if (localName.equals("item")){
itemList.add(parsedDataSet);
}
}
#Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (currentElement){
currentValue = currentValue + new String(ch, start, length);
}
}
}
thank you for help

Categories