How to add the SeekBar for resize the web-view text size Android? - android-webview

SeekBar seekbar = (SeekBar)root.findViewById(R.id.seekBar);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
webview.getSettings().setTextZoom(progress);
webview.loadData(abst.getAbstract_detail(), "text/html", "UTF-8");
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
}
});

Related

How to add ValueChangeHandler to the customize DateBox?

I want to add the functionality of value change handler to my customize class that extends the DateBox. I had already added the key handler but I also want to implement the value change handler to the same class.
I want my DateBox to work properly when I take input from DatePicker or Keyboard.
Any other suggestion will also be helpful.
public class ValidationDateBoxInternal extends DateBox implements KeyUpHandler{
private List<String> regexList;
public ValidationDateBoxInternal(){
super();
this.getTextBox().addKeyUpHandler(this);
regexList = new ArrayList<String>();
}
public void setAsNotEmpty() {
regexList.add(DateValidation.isNotEmpty);
isValid();
}
public void setAsValidDate(){
regexList.add(DateValidation.isValidDate);
isValid();
}
public void onKeyUp(KeyUpEvent event) {
isValid();
}
public void setText(String text) {
super.getTextBox().setText(text);
isValid();
}
public void clearRegexList() {
regexList.clear();
}
public String getText() {
if (regexList.size() == 0) {
return super.getTextBox().getText();
}
if (isValid()) {
for (String regex: regexList) {
if (regex.equals(DateValidation.isValidDate)) {
return super.getTextBox().getText().toLowerCase().trim();
}
}
return super.getTextBox().getText().trim();
}
else {
return null;
}
}
public boolean isValid() {
for (String regex: regexList) {
if (!DateValidation.isValid(super.getTextBox().getText(), regex)) {
this.addStyleName("invalid");
return false;
}
}
this.removeStyleName("invalid");
return true;
}
}
Your class extends DateBox, which implements the HasValueChangeHandlers interface. So you can call:
DateBox.addValueChangeHandler(ValueChangeHandler<java.util.Date> handler)
For example:
public class MyDateBox extends DateBox implements ValueChangeHandler<Date> {
void foo() {
addValueChangeHandler(this);
}
void onValueChange(ValueChangeEvent<Date> event) {
// validate the value of the DateBox
}
}

Android ListView - ExpandableHeightListView add a limit of 10 records per page

My listview is found inside a ScrollView. The ListView was extended by ExpandableHeightListView class. When, 20 row items are loaded, the image library freeze the UI until all images are loaded. Then, user can scroll and select an item. To handle this issue, I tried to load every 10 records in the arraylist. Can i do it directly in the ExpandableHeightListView , if so how ?
public class ExpandableHeightListView extends ListView {
boolean expanded = false;
public ExpandableHeightListView(Context context) {
super(context);
}
public ExpandableHeightListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExpandableHeightListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isExpanded() {
return expanded;
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isExpanded()) {
// int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Calculate entire height by providing a very large height hint.
// MEASURED_SIZE_MASK represents the largest height possible.
//int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
//super.onMeasure(widthMeasureSpec, expandSpec);
// Calculate entire height by providing a very large height hint.
// But do not use the highest 2 bits of this integer; those are
// reserved for the MeasureSpec mode.
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
}
The ListView adapter is as follows:
public class ResultatRechercheAdapter extends BaseAdapter {
public static final String IMAGE_CACHE_DIR = "images";
public static final String EXTRA_IMAGE = "extra_image";
public List<MRechercheResult> items;
public final OnClickListener itemButtonClickListener;
public final Context context;
public Activity activity;
public String agenda_date;
public String agenda_from;
public String agenda_to;
public ViewHolder holder;
public int agenda_from_hour=-1;
public int agenda_from_minute=-1;
public int agenda_to_hour;
public int agenda_to_minute;
public String from_am_pm;
public String to_am_pm;
private String monday;
private String tuesday;
private String wednesday;
private String thursday;
private String friday;
private String saturday;
private String sunday;
public ImageFetcher mImageFetcher;
public ResultatRechercheAdapter(Activity activity,Context context, List<MRechercheResult> resultat, OnClickListener itemButtonClickListener) {
this.activity = activity;
this.context = context;
this.items = resultat;
this.itemButtonClickListener = itemButtonClickListener;
//this.mImageFetcher = mImageFetcher;
try {
monday= activity.getResources().getString(R.string.monday);
tuesday= activity.getResources().getString(R.string.tuesday);
wednesday= activity.getResources().getString(R.string.wednesday);
thursday= activity.getResources().getString(R.string.thursday);
friday= activity.getResources().getString(R.string.friday);
saturday= activity.getResources().getString(R.string.saturday);
sunday= activity.getResources().getString(R.string.sunday);
} catch(Exception ex){}
}
#Override
public int getCount() {
return items.size();//items.size()
}
#Override
public MRechercheResult getItem(int position) {
return items.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public int getViewTypeCount() {
return 1;//items.size()
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.list_item_card, null);
holder = new ViewHolder();
holder.txRowTitle = (TextView) convertView.findViewById(R.id.txRowTitle);
holder.imThumbnail= (RecyclingImageView) convertView.findViewById(R.id.imThumbnail);
holder.itemButton1 = (Button) convertView.findViewById(R.id.list_item_card_close);
holder.itemButton2 = (Button) convertView.findViewById(R.id.list_item_card_button_2);
holder.imCircleLundi= (ImageView) convertView.findViewById(R.id.imCircleLundi);
holder.imCircleMardi= (ImageView) convertView.findViewById(R.id.imCircleMardi);
holder.imCircleMercredi= (ImageView) convertView.findViewById(R.id.imCircleMercredi);
holder.imCircleJeudi= (ImageView) convertView.findViewById(R.id.imCircleJeudi);
holder.imCircleVendredi= (ImageView) convertView.findViewById(R.id.imCircleVendredi);
holder.imCircleSamedi= (ImageView) convertView.findViewById(R.id.imCircleSamedi);
holder.imCircleDimanche= (ImageView) convertView.findViewById(R.id.imCircleDimanche);
holder.rlListRecherche= (RelativeLayout) convertView.findViewById(R.id.rlListRecherche);
holder.llImage= (LinearLayout) convertView.findViewById(R.id.llImage);
holder.rlListClose= (RelativeLayout) convertView.findViewById(R.id.rlListClose);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
boolean no_record = items.get(position).no_record;
if (no_record){ // listview is empty
holder.llImage.setVisibility(View.GONE);
holder.rlListClose.setVisibility(View.GONE);
holder.rlListRecherche.setVisibility(View.VISIBLE);
} else {
Utils.shortWeek(activity, convertView);
holder.llImage.setVisibility(View.VISIBLE);
holder.rlListClose.setVisibility(View.VISIBLE);
holder.rlListRecherche.setVisibility(View.GONE);
if (itemButtonClickListener != null) {
//holder.itemButton1.setOnClickListener(itemButtonClickListener);
holder.itemButton1.setVisibility(View.GONE);
holder.itemButton2.setOnClickListener(itemButtonClickListener);
}
final String image_url = items.get(position).profil_photo.toString().replace("\\","").replace("hepigo", "helpigo");
String item_title = items.get(position).profil.toString();
if (item_title.equalsIgnoreCase("Julien Perez")){
if (true){
String display_pos = String.valueOf(position);
System.out.println(display_pos);
}
}
//searchRequest(position,image_url);
//if (!TextUtils.isEmpty(image_url))
// mImageFetcher.loadImage(image_url, holder.imThumbnail);
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
if (TextUtils.isEmpty(items.get(position).profil_photo)) {
//no url
} else {
Picasso.with(activity)
.load(image_url)
.error(android.R.drawable.stat_notify_error)
.transform(transformation)
.placeholder(R.drawable.loading_image_placeholder)
.config(Config.RGB_565)
.into(holder.imThumbnail);
}
}
});
//if (!TextUtils.isEmpty(image_url))
// new DownloadImageTask(holder.imThumbnail).execute(image_url);
holder.txRowTitle.setText(item_title);
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
// TODO Auto-generated method stub
List<Agenda> agenda = items.get(position).agenda;
Utils.displayAgenda(agenda,holder.imCircleLundi,monday);
Utils.displayAgenda(agenda,holder.imCircleMardi,tuesday);
Utils.displayAgenda(agenda,holder.imCircleMercredi,wednesday);
Utils.displayAgenda(agenda,holder.imCircleJeudi,thursday);
Utils.displayAgenda(agenda,holder.imCircleVendredi,friday);
Utils.displayAgenda(agenda,holder.imCircleSamedi,saturday);
Utils.displayAgenda(agenda,holder.imCircleDimanche,sunday);
}
});
}
return convertView;
}
public static class ViewHolder {
public RelativeLayout rlListClose;
public LinearLayout llImage;
public RelativeLayout rlListRecherche;
public ImageView imCircleSamedi;
public ImageView imCircleDimanche;
public ImageView imCircleVendredi;
public ImageView imCircleJeudi;
public ImageView imCircleMercredi;
public ImageView imCircleMardi;
public ImageView imCircleLundi;
public RecyclingImageView imThumbnail;
public TextView txRowTitle;
public Button itemButton1;
public Button itemButton2;
}

Click handler of button

I want to add a button and add click handler to it after entering the values in database.
I want that button to be on onSucess of greeting service.
help me
public static void edit1(String fnme,String lnme,String clgn,String scn){
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>()
{
public void onSuccess(String result)
{
Window.alert("successfully entered");
// TODO Auto-generated method stub
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler);
}
public void onFailure(Throwable caught)
{
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler
{
public void onClick(ClickEvent e)
{
//create();
}
}
but this is not working.
Do you need the click handler?
Anyway this is what I think you're trying to do:
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler);
public static void edit1(String fnme,String lnme,String clgn,String scn)
{
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>()
{
public void onSuccess(String result)
{
Window.alert("successfully entered");
// TODO Auto-generated method stub
create();
}
public void onFailure(Throwable caught)
{
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler
{
public void onClick(ClickEvent e)
{
// create();
}
}
Your MyClickHandler does nothing inside the onClick() method. It should work as long as you put code. Try this:
public static void edit1(String fnme,String lnme,String clgn,String scn){
greetingService.enter(fnme,lnme,clgn,scn, new AsyncCallback<String>() {
public void onSuccess(String result) {
Window.alert("successfully entered");
// TODO Auto-generated method stub
Button bt =new Button("submit");
RootPanel.get().add(bt);
bt.addClickHandler(new MyClickHandler() {
public void onClick(ClickEvent e) {
//DO SOMETHING HERE
}
});
}
public void onFailure(Throwable caught) {
Window.alert("fail");
}
});
}
class MyClickHandler implements ClickHandler {
public void onClick(ClickEvent e) {
/* OR DO SOMETHING HERE, BUT THAT WILL AFFECT ALL
* INSTANCES OF MyClickHandler
*/
}
}

refresh listView by clicking outside of it

I have a viewpager with an adapter that extends FragmentStatePagerAdapter, this has to show some fragment that always repeats the same layout (in whic there is a listView) for every page ... now the problem is how can I update the listView that is currently visible by clicking on a button that is outside of the Fragment? I can refresh only the ones that are in the not visible pages,but not the ones that are displayed or adjacent...
One possible solution is to reset the adapter, but it doesn't seems to be right one, because it' s slow... could you please help me?
public class MainActivity extends FragmentActivity implements OnClickListener{
#Override
protected void onCreate(Bundle arg0) {
// TODO Auto-generated method stub
super.onCreate(arg0);
setContentView(R.layout.layout1);
pagerAdapter = new AdapterPager(getSupportFragmentManager());
ctx=this;
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(pagerAdapter);
pagerTab=(PagerTabStrip) findViewById(R.id.pager_tab_strip);
mViewPager.setCurrentItem(paginaCentrale);
modifica=(ImageView)findViewById(R.id.modifica);
modifica.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO onClick
switch (arg0.getId()){
case R.id.modifica:
//here I would like to call the method caricaLista() of the fragment
break;
}
}
public static class AdapterPager extends FragmentStatePagerAdapter {
public AdapterPager(FragmentManager fm) {
super(fm);
}
#Override
public int getItemPosition(Object object) {
// TODO Auto-generated method stub
return super.getItemPosition(object);
}
#Override
public Fragment getItem(int i) {
Fragment fragment;
Bundle args = new Bundle();
args.putInt("position", i);
fragment=new Fragment1();
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
return 1000;}
#Override
public CharSequence getPageTitle(int i) {
String title=String.valueOf(i);
return title;
}
}
public static class Fragment1 extends Fragment implements OnItemClickListener{
int fragmentPosition;
ListView lv;
List<Lista> lista= new ArrayList<Lista>();
public Fragment1(){
}
public static Fragment1 newInstance(){
return new Fragment1();
}
#Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
caricaLista("")}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle
savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment1, container, false);
lv=(ListView) rootView.findViewById(R.id.listViewCompiti);
Bundle args = getArguments();
int position= args.getInt("position");
fragmentPosition=position;
lv.setOnItemClickListener(this);
homeListAdapter= new HomeListAdapterWithCache(ctx,R.layout.list_item_home,lista);
lv.setAdapter(homeListAdapter);
return rootView;
}
You have to store the Current Fragment into your MainActivity , and change every time the page changes.
So you call the method of the current fragments.
Check out how your MainActivity should look like:
public class MainActivity extends FragmentActivity implements OnClickListener{
&Fragment mCurrentFragment;*
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.layout1);
pagerAdapter = new AdapterPager(getSupportFragmentManager());
ctx=this;
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(pagerAdapter);
pagerTab=(PagerTabStrip) findViewById(R.id.pager_tab_strip);
mViewPager.setCurrentItem(paginaCentrale);
modifica=(ImageView)findViewById(R.id.modifica);
modifica.setOnClickListener(this);
*mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
#Override
public void onPageSelected(int position) {
mCurrentFragment = pagerAdapter.getItem(position);
}*
});
#Override
public void onClick(View arg0) {
// TODO onClick
switch (arg0.getId()){
case R.id.modifica:
*mCurrentFragment.caricaLista();*
break;
}
}
}

Adding a Camera to my Android App and Initializing it on application start up

I'm pretty new to programming but here is a code I have. I'm trying to develop an app and I want it to open the camera feature right away. This is what I'm working with. It's asking me to add more details so I figure I should type more... Any help would be appreciated. This is my only grade for a class that is taught very poorly
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder sHolder;
public Camera camera= null;{
}
public CameraSurfaceView(Context context) {
super(context);
sHolder= getHolder();
sHolder .addCallback(this);
// TODO Auto-generated constructor stub
}
#Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
Camera.Parameters params= camera.getParameters();
params.setPreviewSize(width, height);
camera.setParameters(params);
camera.startPreview();
}
#Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try{
camera.setPreviewDisplay(sHolder);
}catch(Exception e){
}
// TODO Auto-generated method stub
}
#Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera= null;
}
public void capture (Camera.PictureCallback jpegHandler){
camera.takePicture(null, null, jpegHandler);
}
}