Search Results

Search found 135 results on 6 pages for 'layoutparams'.

Page 4/6 | < Previous Page | 1 2 3 4 5 6  | Next Page >

  • Android: Programatically Add UI Elements to a View

    - by Shivan Raptor
    My view is written as follow: package com.mycompany; import android.view.View; import java.util.concurrent.TimeUnit; import java.util.ArrayList; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.util.AttributeSet; import android.graphics.Paint; import android.graphics.Point; import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.widget.*; public class GameEngineView extends View implements SensorEventListener { GameLoop gameloop; String txt_acc; float accY; ArrayList<Point> bugPath; private SensorManager sensorManager; private class GameLoop extends Thread { private volatile boolean running = true; public void run() { while (running) { try { TimeUnit.MILLISECONDS.sleep(1); postInvalidate(); pause(); } catch (InterruptedException ex) { running = false; } } } public void pause() { running = false; } public void start() { running = true; run(); } public void safeStop() { running = false; interrupt(); } } public void unload() { gameloop.safeStop(); } public GameEngineView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub init(context); } public GameEngineView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub init(context); } public GameEngineView(Context context) { super(context); // TODO Auto-generated constructor stub init(context); } private void init(Context context) { txt_acc = ""; // Adding SENSOR sensorManager=(SensorManager)context.getSystemService(Context.SENSOR_SERVICE); // add listener. The listener will be HelloAndroid (this) class sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL); // Adding UI Elements : How ? Button btn_camera = new Button(context); btn_camera.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); btn_camera.setClickable(true); btn_camera.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { System.out.println("clicked the camera."); } }); gameloop = new GameLoop(); gameloop.run(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub //super.onMeasure(widthMeasureSpec, heightMeasureSpec); System.out.println("Width " + widthMeasureSpec); setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub // super.onDraw(canvas); Paint p = new Paint(); p.setColor(Color.WHITE); p.setStyle(Paint.Style.FILL); p.setAntiAlias(true); p.setTextSize(30); canvas.drawText("|[ " + txt_acc + " ]|", 50, 500, p); gameloop.start(); } public void onAccuracyChanged(Sensor sensor,int accuracy){ } public void onSensorChanged(SensorEvent event){ if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){ //float x=event.values[0]; accY =event.values[1]; //float z=event.values[2]; txt_acc = "" + accY; } } } I would like to add a Button to the scene, but I don't know how to. Can anybody give me some lights? UPDATE: Here is my Activity : public class MyActivity extends Activity { private GameEngineView gameEngine; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // add Game Engine gameEngine = new GameEngineView(this); setContentView(gameEngine); gameEngine.requestFocus(); } }

    Read the article

  • OutofMemoryError: bitmap size exceeds VM budget (Android)

    - by Chrispix
    Getting an Exception in the BitmapFactory. Not sure what is the issue. (Well I can guess the issue, but not sure why its happening) ERROR/AndroidRuntime(7906): java.lang.OutOfMemoryError: bitmap size exceeds VM budget ERROR/AndroidRuntime(7906): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:295) My code is pretty straight forward. I defined an XML layout w/ a default image. I try to load a bm on the SDCard (if present - it is). If not it shows the default image. Anyway.. Here is code : public class showpicture extends Activity { public void onCreate(Bundle savedInstanceState) { /** Remove menu/status bar **/ requestWindowFeature(Window.FEATURE_NO_TITLE); final Window win = getWindow(); win.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); Bitmap bm; super.onCreate(savedInstanceState); setContentView(R.layout.showpicture); try { ImageView mImageButton = (ImageView)findViewById(R.id.displayPicture); bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile("/sdcard/dcim/Camera/20091018203339743.jpg"),100, 100, true); parkImageButton.setImageBitmap(bm); } catch (IllegalArgumentException ex) { Log.d("MYAPP",ex.getMessage()); } catch (IllegalStateException ex) { It fails on the bm=Bitmap.createScaledBitmap any thoughts? I did some research on the forums, and it pointed to this post I just don't know why it is not working. Any help would be great! Thanks, Chris.

    Read the article

  • Extended SurfaceView's onDraw() method never called

    - by Gab Royer
    Hi, I'm trying to modify the SurfaceView I use for doing a camera preview in order to display an overlaying square. However, the onDraw method of the extended SurfaceView is never called. Here is the source : public class CameraPreviewView extends SurfaceView { protected final Paint rectanglePaint = new Paint(); public CameraPreviewView(Context context, AttributeSet attrs) { super(context, attrs); rectanglePaint.setARGB(255, 200, 0, 0); rectanglePaint.setStyle(Paint.Style.FILL); rectanglePaint.setStrokeWidth(2); } @Override protected void onDraw(Canvas canvas){ canvas.drawRect(new Rect(10,10,200,200), rectanglePaint); Log.w(this.getClass().getName(), "On Draw Called"); } } public class CameraPreview extends Activity implements SurfaceHolder.Callback{ private SurfaceHolder holder; private Camera camera; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // We remove the status bar, title bar and make the application fullscreen requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // We set the content view to be the layout we made setContentView(R.layout.camera_preview); // We register the activity to handle the callbacks of the SurfaceView CameraPreviewView surfaceView = (CameraPreviewView) findViewById(R.id.camera_surface); holder = surfaceView.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters params = camera.getParameters(); params.setPreviewSize(width, height); camera.setParameters(params); try { camera.setPreviewDisplay(holder); } catch (IOException e) { e.printStackTrace(); } camera.startPreview(); } public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); } public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); } }

    Read the article

  • SlidingDrawer overlap the listview

    - by vycon
    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); cursor = fetchAllDiary(); this.setListAdapter(new DiaryListAdapter(this, cursor, true)); View drawer_view = mInflater.inflate(R.layout.drawer, null); LayoutParams params = new LayoutParams(200,150); getWindow().addContentView(drawer_view, params); } <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/frameLayout"> <SlidingDrawer android:id="@+id/diary_list_row_drawer" android:layout_height="wrap_content" android:handle="@+id/handle" android:content="@+id/content" android:orientation="vertical" android:layout_width="fill_parent" android:topOffset="50px"> <ImageView android:id="@id/handle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/bottom_switcher_collapsed" /> <LinearLayout android:id="@id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/backround_color_lightblue1"> <Button android:text="Button01" android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:text="Button02" android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </SlidingDrawer> </LinearLayout>

    Read the article

  • Extended SurfaceView onDraw never called

    - by Gab Royer
    Hi, I'm trying to modify the SurfaceView I use for doing a camera preview in order to display an overlaying square. However, the onDraw method of the extended SurfaceView is never called. Here is the source : public class CameraPreviewView extends SurfaceView { protected final Paint rectanglePaint = new Paint(); public CameraPreviewView(Context context, AttributeSet attrs) { super(context, attrs); rectanglePaint.setARGB(255, 200, 0, 0); rectanglePaint.setStyle(Paint.Style.FILL); rectanglePaint.setStrokeWidth(2); } @Override protected void onDraw(Canvas canvas){ canvas.drawRect(new Rect(10,10,200,200), rectanglePaint); Log.w(this.getClass().getName(), "On Draw Called"); } } public class CameraPreview extends Activity implements SurfaceHolder.Callback{ private SurfaceHolder holder; private Camera camera; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // We remove the status bar, title bar and make the application fullscreen requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // We set the content view to be the layout we made setContentView(R.layout.camera_preview); // We register the activity to handle the callbacks of the SurfaceView CameraPreviewView surfaceView = (CameraPreviewView) findViewById(R.id.camera_surface); holder = surfaceView.getHolder(); holder.addCallback(this); holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { Camera.Parameters params = camera.getParameters(); params.setPreviewSize(width, height); camera.setParameters(params); try { camera.setPreviewDisplay(holder); } catch (IOException e) { e.printStackTrace(); } camera.startPreview(); } public void surfaceCreated(SurfaceHolder holder) { camera = Camera.open(); } public void surfaceDestroyed(SurfaceHolder holder) { camera.stopPreview(); camera.release(); } }

    Read the article

  • Android: How to change my ExpandAnimation class to handle animation correctly?

    - by IamStalker
    here is my animation class that i have taken from Udnic - thanks m8, but i'm using it "not from closed position but from opened" and it's jumps and not behaving correctly. what should i do? public class ExpandAnimation extends Animation { private View mAnimatedView; private LinearLayout.LayoutParams mViewLayoutParams; public int mMarginStart, mMarginEnd; private boolean mIsVisibleAfter = false; private boolean mWasEndedAlready = false; private ImageView mImageView; /** * Initialize the animation * @param view The layout we want to animate * @param duration The duration of the animation, in ms */ public ExpandAnimation(View view, int duration, ImageView imageView) { setDuration(duration); mImageView = imageView; mAnimatedView = view; mViewLayoutParams = (LinearLayout.LayoutParams) view.getLayoutParams(); mMarginStart = mMarginEnd = 0; // decide to show or hide the view mIsVisibleAfter = (view.getVisibility() == View.VISIBLE); //mIsVisibleAfter = (mViewLayoutParams.bottomMargin == 0); mMarginStart = mViewLayoutParams.bottomMargin; if(mMarginStart != 0) mMarginStart = 0 - view.getHeight(); mMarginEnd = (mMarginStart == 0 ? (0 - view.getHeight()) : 0); view.setVisibility(View.VISIBLE); mImageView.setImageResource(R.drawable.expand_open); } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); if (interpolatedTime < 1.0f) { // Calculating the new bottom margin, and setting it mViewLayoutParams.bottomMargin = mMarginStart + (int) ((mMarginEnd - mMarginStart) * interpolatedTime); // Invalidating the layout, making us seeing the changes we made mAnimatedView.requestLayout(); // Making sure we didn't run the ending before (it happens!) } else if (!mWasEndedAlready) { mViewLayoutParams.bottomMargin = mMarginEnd; mAnimatedView.requestLayout(); // if (mIsVisibleAfter) { if(mMarginEnd != 0) { mAnimatedView.setVisibility(View.GONE); mImageView.setImageResource(R.drawable.expand_close); } mWasEndedAlready = true; } } }

    Read the article

  • Attempting to calculate width of Map Overlays on the fly

    - by Bloudermilk
    Hey all- I am working on an Android app that utilizes the Google Maps API MapView, MapController, MapActivity, and ItemizedOverlay. I am basically trying to recreate certain functionalities of the Maps app (damn Google for not providing speech bubbles—for lack of a better name—for items!), particularly those speech bubbles. I have an invisible XML structure for the speech bubble in the XML layout file containing my MapView. The first time I show a speech bubble I grab that XML and remove it from it's current parent, applying some ItemizedOverlay.LayoutParams to it, and add it to the MapView as an Overlay. I position it above the item that was selected, fill it with the proper text, then set it to visible. This all works great. The goal here, though, is to also automatically animate the map to reveal any parts of a speech bubble that may be off-screen when it opens. So I'm trying popup.getWidth() (popup is the instance of my LinearLayout that is the speech bubble) after I do all the manipulation to the bubble, even after I display it to the user. Problem is, popup.getWidth() is returning me the width of the previously displayed popup, not the currently displayed one. I can't figure out why this would be happening if I'm fetching the width after I set it to visible with its new dimensions (which, by the way, are relative when I'm setting them with LayoutParams: fill_content for both width and height).. I have even tried forcing both the MapView and the "popup" to invalidate() before trying to fetch the width. Any ideas why this may be happening? How can I force the View to settle into its new dimensions before trying to fetch them? Thanks! Nick

    Read the article

  • Dynamically adding custom view to RemoteViews

    - by Naidu
    Could any help me to do this?My code is like: public CustomClass extends View { //uses ondraw() to do something } For displaying my custom view on HomeScreen i created a class to extend Broadcast Receiver public class customAppWidgetProvider extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main); //Here i want to create my custom view class object and i want to add this view to linear layout in main.xml CustomClass object = new CustomClass(context) ; LinearLayout layout = new LinearLayout(context) ; layout.setLayoutParameters(new LayoutParameters(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); layout.addView(object); views.addview(R.id.linearlayout, (ViewGroup) layout) ; views.setOnClickPendingIntent(R.id.analog_appwidget, PendingIntent.getActivity(context, 0, new Intent(context, AlarmClock.class), PendingIntent.FLAG_CANCEL_CURRENT)); int[] appWidgetIds = intent.getIntArrayExtra( AppWidgetManager.EXTRA_APPWIDGET_IDS); AppWidgetManager gm = AppWidgetManager.getInstance(context); gm.updateAppWidget(appWidgetIds, views); } } } But adding viewgroup to RemoteView reference is not working... above main.xml contains only LinearLayout.I want to add custom view object to it.But after running this not showing anything on screen.. please help me to do this.Thanks in Advance.

    Read the article

  • Gallery items become off-center when switching into landscape orientation.

    - by Sandile
    Hey Guys, Thanks for your time. I'm writing an application for android 2.2 and I'm using a gallery to circulate through a list of images that the user can then click to navigate other portions of the application. In portrait orientation, everything is kosher: the images are displaying correctly (completely in the center of the screen as I intended); however, in landscape orientation, all the images in the gallery are strangely displaced a fixed distance to the left of the center of the screen. I've been researching this issue for hours now and haven't found a solution. I'm hoping that some android guru can aid me in the resolution of this bizarre rendering issue. MainMenuActivity.java relevant code snippet (the activity in which the gallery resides) Gallery optionList = (Gallery)findViewById(R.id.mainMenuOptionList); GalleryItem[] optionListItemIdArray = new GalleryItem[] { new GalleryItem(R.drawable.icon_main_menu_option_list_blackboard, "Start Next Lesson", "Start the next planned vocab lesson."), new GalleryItem(R.drawable.icon_main_menu_option_list_index_cards, "Review Words", "Manually look over old words."), new GalleryItem(R.drawable.icon_main_menu_option_list_dice, "Play Vocab Games", "Play games to reinforce knowledge."), new GalleryItem(R.drawable.icon_main_menu_option_list_calendar, "View Lesson Plan", "View the schedule for coming lessons."), new GalleryItem(R.drawable.icon_main_menu_option_list_pie_chart, "View Performance Report", "Evaluate your overall performance statistics."), new GalleryItem(R.drawable.icon_main_menu_option_list_settings, "Manage Settings", "Change and modify application settings.") }; optionList.setAdapter(new GalleryImageAdapter(this, optionListItemIdArray)); NOTE: A GalleryItem is a POJO with an image resource id, title and description. GalleryImageAdapter.java: public class GalleryImageAdapter extends BaseAdapter { private Context context; private GalleryItem[] galleryItemArray; public GalleryImageAdapter(Context context, GalleryItem[] galleryItemArray) { this.context = context; this.galleryItemArray = galleryItemArray; } @Override public int getCount() { return galleryItemArray.length; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(context); imageView.setImageResource(galleryItemArray[position].getImageId()); imageView.setScaleType(ImageView.ScaleType.FIT_START); imageView.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.WRAP_CONTENT, Gallery.LayoutParams.WRAP_CONTENT)); return imageView; } } Portrait version of main_menu.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuLinearLayout" android:background="#3067a8" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/mainMenuHeadingTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dip" android:textColor="#ffffff" android:textSize="50sp" android:text="@string/main_menu_heading" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <TextView android:id="@+id/mainMenuSubHeadingTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="15dip" android:textColor="#ffffff" android:textSize="15sp" android:text="@string/main_menu_sub_heading" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuOptionList" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="20dip" android:paddingBottom="10dip" android:spacing="40dip" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuOptionListDetailLinearLayout" android:gravity="center_vertical|center_horizontal" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/mainMenuOptionListLabelTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="25sp" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <TextView android:id="@+id/mainMenuOptionListDescriptionTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="15sp" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> </LinearLayout> </LinearLayout> Landscape version of main_menu.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuLinearLayout" android:background="#3067a8" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/mainMenuHeadingTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="10dip" android:textColor="#ffffff" android:textSize="50sp" android:text="@string/main_menu_heading" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <TextView android:id="@+id/mainMenuSubHeadingTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="15dip" android:textColor="#ffffff" android:textSize="15sp" android:text="@string/main_menu_sub_heading" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuOptionList" android:layout_width="fill_parent" android:layout_height="128dip" android:paddingLeft="0dip" android:paddingTop="5dip" android:spacing="10dip" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mainMenuOptionListDetailLinearLayout" android:gravity="center_vertical|center_horizontal" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/mainMenuOptionListLabelTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="25sp" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> <TextView android:id="@+id/mainMenuOptionListDescriptionTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:textSize="15sp" android:shadowColor="#555555" android:shadowDx="0" android:shadowDy="0" android:shadowRadius="2" /> </LinearLayout> </LinearLayout> Thank you for your time!

    Read the article

  • Android: who can help me with setting up this google maps class please??

    - by Capsud
    Hi, Firstly this has turned out to be quite a long post so please bear with me as its not too difficult but you may need to clarify something with me if i haven't explained it correctly. So with some help the other day from guys on this forum, i managed to partially set up my 'mapClass' class, but i'm having trouble with it and its not running correctly so i would like some help if possible. I will post the code below so you can see. What Ive got is a 'Dundrum' class which sets up the listView for an array of items. Then ive got a 'dundrumSelector' class which I use to set up the setOnClickListener() methods on the listItems and link them to their correct views. DundrumSelector class.. public static final int BUTTON1 = R.id.anandaAddressButton; public static final int BUTTON2 = R.id.bramblesCafeAddressButton; public static final int BUTTON3 = R.id.brannigansAddressButton; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); int position = getIntent().getExtras().getInt("position"); if(position == 0){ setContentView(R.layout.ananda); }; if(position == 1){ setContentView(R.layout.bramblescafe); }; if(position == 2){ setContentView(R.layout.brannigans); Button anandabutton = (Button) findViewById(R.id.anandaAddressButton); anandabutton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(),MapClass.class); myIntent.putExtra("button", BUTTON1); startActivityForResult(myIntent,0); } }); Button bramblesbutton = (Button) findViewById(R.id.bramblesCafeAddressButton); bramblesbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(),MapClass.class); myIntent.putExtra("button", BUTTON2); startActivityForResult(myIntent, 0); } }); etc etc.... Then what i did was set up static ints to represent the buttons which you can see at the top of this class, the reason for this is because in my mapClass activity I just want to have one method, because the only thing that is varying is the coordinates to each location. ie. i dont want to have 100+ map classes essentially doing the same thing other than different coordinates into the method. So my map class is as follows... case DundrumSelector.BUTTON1: handleCoordinates("53.288719","-6.241179"); break; case DundrumSelector.BUTTON2: handleCoordinates("53.288719","-6.241179"); break; case DundrumSelector.BUTTON3: handleCoordinates("53.288719","-6.241179"); break; } } private void handleCoordinates(String l, String b){ mapView = (MapView) findViewById(R.id.mapView); LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {l, b}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint( (int) (lat*1E6), (int) (lng*1E6)); mc.animateTo(p); mc.setZoom(17); mapView.invalidate(); } Now this is where my problem is. The onClick() events don't even work from the listView to get into the correct views. I have to comment out the methods in 'DundrumSelector' before I can get into their views. And this is what I dont understand, firstly why wont the onClick() events work, because its not even on that next view where the map is. I know this is a very long post and it might be quite confusing so let me know if you want any clarification.. Just to recap, what i'm trying to do is just have one class that sets up the map coordinates, like what i'm trying to do in my 'mapClass'. Please can someone help or suggest another way of doing this! Thanks alot everyone for reading this.

    Read the article

  • how to save state of dynamically created editTexts

    - by user922531
    I'm stuck at how to save the state of my EditTexts on screen orientation. Currently if text is inputted into the EditTexts and the screen is orientated, the fields are wiped (as expected). I am already calling onSaveInstanceState and saving a String, but I have no clue on how to save the EditTexts which are created in code and then retrieve them and add them to the EditTexts when redrawing the activity. Snippet of my code: My main activity is as follows: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // get the multidim array b = getIntent().getBundleExtra("obj"); m = (Methods) b.getSerializable("Methods"); // method to draw the layout InitialiseUI(); // Restore UI state from the savedInstanceState. if (savedInstanceState != null) { String strValue = savedInstanceState.getString("light"); if (strValue != null) { FLight = strValue; } } try { mCamera = Camera.open(); if (FLight.equals("true")) { flashLight(); } } catch (Exception e) { Log.d(TAG, "Thrown exception onCreate() camera: " + e); } } // end onCreate /** Called when the back button is pressed. */ @Override public void onResume() { super.onResume(); try { mCamera = Camera.open(); if (FLight.equals("true")) { flashLight(); } } catch (Exception e) { Log.d(TAG, "Thrown exception onCreate() camera: " + e); } } // end onCreate /** saves data before leaving the screen */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString("light", FLight); } /** called when exiting / leaving the screen */ @Override protected void onPause() { super.onPause(); Log.d(TAG, "onPause()"); if (mCamera != null) { mCamera.stopPreview(); mCamera.release(); mCamera = null; } } /* * set up the UI elements - add click listeners to buttons used in * onCreate() and onConfigurationChanged() * * Set the editTexts fields to show the previous readings as Hints */ public void InitialiseUI() { Log.d(TAG, "Start of InitialiseUI, Main activity"); // get a reference to the TableLayout final TableLayout myTLreads = (TableLayout) findViewById(R.id.myTLreads); // Create arrays to hold the TVs and ETs final TextView[] myTextViews = new TextView[m.getNoRows()]; // create an empty array; final EditText[] myEditTexts = new EditText[m.getNoRows()]; // create an empty array; for(int i =0; i<=m.getNoRows()-1;i++ ){ TableRow tr=new TableRow(this); tr.setLayoutParams(new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); // create a new textview / editText final TextView rowTextView = new TextView(this); final EditText rowEditText = new EditText(this); // setWidth is needed otherwise my landscape layout is OFF rowEditText.setWidth(400); // this stops the keyboard taking up the whole screen in landscape layout rowEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // add some padding to the right of the TV rowTextView.setPadding(0,0,10,0); // set colors to white rowTextView.setTextColor(Color.parseColor("#FFFFFF")); rowEditText.setTextColor(Color.parseColor("#FFFFFF")); // if readings already sent today set color to yellow if(m.getTransmit(i+1)==false){ rowEditText.setEnabled(false); rowEditText.setHintTextColor(Color.parseColor("#FFFF00")); } // set the text of the TV to the meter name rowTextView.setText(m.getMeterName(i+1)); // set the hint of the ET to the last submitted reading rowEditText.setHint(m.getLastReadString(i+1)); // add the textview to the linearlayout rowEditText.setInputType(InputType.TYPE_CLASS_PHONE);//InputType.TYPE_NUMBER_FLAG_DECIMAL); tr.addView(rowTextView); tr.addView(rowEditText); myTLreads.addView(tr); // add a reference to the textView myTextViews[i] = rowTextView; myEditTexts[i] = rowEditText; } final Button submit = (Button) findViewById(R.id.submitReadings); // add a click listener to the button try { submit.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.d(TAG, "Submit button clicked, Main activity"); preSubmitCheck(m.getAccNo(), m.getPostCode(), myEditTexts); // method to do HTML getting and sending } }); } catch (Exception e) { Log.d(TAG, "Exceptions (submit button)" + e.toString()); } }// end of InitialiseUI I don't need to do anything with these values until a button is clicked. Would it be easier if they were a ListView, i'm guessing I would still have the problem of saving them and retrieving them on rotation. If it helps I have an object m which is a string[][] I could temporarily somehow store them in

    Read the article

  • using Unity Android In a sub view and add actionbar and style

    - by aeroxr1
    I exported a simple animation from Unity3D (version 4.5) in android project. With eclipse I modified the manifest and added another activity. In this activity I put a button that it makes start the animation,and this is the result. The action bar appear in the main activity but it doesn't in the unity's activity :( How can I add the action bar and the style of the first activity to unity's animation activity ? This is the unity's activity's code : package com.rabidgremlin.tut.redcube; import android.app.NativeActivity; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import com.unity3d.player.UnityPlayer; public class UnityPlayerNativeActivity extends NativeActivity { protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { //requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); getWindow().takeSurface(null); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); /*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } // Pause Unity @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // eliminiamo questa onResume() e proviamo a modificare la onResume() // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } // inseriamo qualche modifica qui // This ensures the layout will be correct. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mUnityPlayer.configurationChanged(newConfig); } // Notify Unity of the focus change. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mUnityPlayer.windowFocusChanged(hasFocus); } // For some reason the multiple keyevent type is not supported by the ndk. // Force event injection by overriding dispatchKeyEvent(). @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.injectEvent(event); return super.dispatchKeyEvent(event); } // Pass any events not handled by (unfocused) views straight to UnityPlayer @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } } And this is the AndroidManifest.xml android:versionCode="1" android:versionName="1.0" > <!-- android:theme="@android:style/Theme.NoTitleBar"--> <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:xlargeScreens="true" /> <application android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light" > <activity android:name="com.rabidgremlin.tut.redcube.UnityPlayerNativeActivity" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale" android:label="@string/app_name" android:screenOrientation="portrait" > <!--android:launchMode="singleTask"--> <meta-data android:name="unityplayer.UnityActivity" android:value="true" /> <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" /> </activity> <activity android:name="com.rabidgremlin.tut.redcube.MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="19" /> <uses-feature android:glEsVersion="0x00020000" /> </manifest>

    Read the article

  • Android - Unity3D: setVisibility(View.VISIBLE) crashes

    - by Kazoeja
    I have a unity project and I use a Android (java) plugin to get camera data. I draw this on a TextureView. I want to hide/show this view when I press a button in unity. But my app crashes when I setVisibility onCreate UnityPlayer.currentActivity.addContentView(texView, new FrameLayout.LayoutParams(400, 400)); java: public void HideVideo() { //Hide view _TextureView.setVisibility(View.INVISIBLE); } Is there an extra function I need to call, or may I only call it on certain times? None of these thins work, they all make my app crash. _TextureView.setVisibility(View.INVISIBLE); _TextureView.setActivated(false); _TextureView.setAlpha(0); _TextureView.setTranslationY(-1000);

    Read the article

  • How do I specify image dimentions in dp for an Android Gallery?

    - by Richard
    All the examples I've see for using the Gallery view in Android set a specific pixel size for the images using: i.setLayoutParams(new Gallery.LayoutParams(200, 200)); I want to have my gallery images sized based on the screen density (ldpi, mdpi, hdpi). Can someone give me an example of how to specify gallery image dimensions using dp? Thanks!

    Read the article

  • Android GridView Custom BaseAdapter ImageView ImageButton OnItemClick doesn´t work

    - by Marek
    i have a problem using a GridView with a CustomAdapter (extends BaseAdapter). any Activity implements the OnItemClickListener. if i use ImageView as item everything works fine, OnItemClick-Events will be fired/catched I have not found a useful example for a GridView with a custom BaseAdapter using ImageButton. Has anyone an idea? Many thanks in advantage! Snippets: class MyActivity extends Activity implements OnItemClickListener { ... @Override public void onCreate() { ... GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setOnItemClickListener(this); gridview.setAdapter(new ImageButtonAdapter(this)); } ... @Override public void onItemClick(AdapterView<?> adapter, View view, int arg2, long arg3) { Log.e("onItemClick()", "arg2=" + arg2 + ", arg3=" + arg3); } } public class ImageButtonAdapter extends BaseAdapter { private Context mContext; public LayoutMenuAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { /* IF I USE THIS PART EVERYTHING WORKS FINE */ // ImageView imageView; // if (convertView == null) { // imageView = new ImageView(mContext); // imageView.setLayoutParams(new GridView.LayoutParams(100, 100)); // imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // imageView.setPadding(0, 0, 0, 0); // imageView.setFocusable(false); // } else { // imageView = (ImageView) convertView; // } // imageView.setImageResource(mThumbIds[position]); // return imageView; /* IF I USE THIS PART NO THE ACTIVITY/LISTENER RECEIVES NO EVENT */ ImageButton imageButton; if (convertView == null) { imageButton = new ImageButton(mContext); imageButton.setLayoutParams(new GridView.LayoutParams(100, 100)); imageButton.setScaleType(ImageView.ScaleType.CENTER_CROP); imageButton.setPadding(0, 0, 0, 0); imageButton.setFocusable(false); } else { imageButton = (ImageButton) convertView; } imageButton.setImageResource(mThumbIds[position]); return imageButton; } // references to images private Integer[] mThumbIds = { R.drawable.media}; }

    Read the article

  • Android - Linkify Problem

    - by Ryan
    I seem to be having trouble with the linkify I am using in my Custom Adapter. For some reason I recieve the following stack track when I click on one of the links: 06-07 20:49:34.696: ERROR/AndroidRuntime(813): Uncaught handler: thread main exiting due to uncaught exception 06-07 20:49:34.745: ERROR/AndroidRuntime(813): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.app.ApplicationContext.startActivity(ApplicationContext.java:550) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.content.ContextWrapper.startActivity(ContextWrapper.java:248) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.text.style.URLSpan.onClick(URLSpan.java:62) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:216) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.widget.TextView.onTouchEvent(TextView.java:6560) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.View.dispatchTouchEvent(View.java:3709) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 06-07 20:49:34.745: ERROR/AndroidRuntime(813): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) Here is the code that is calling it: TextView bot = new TextView( c ); bot.setText(li.getBottomText()); bot.setTextColor(Color.BLACK); bot.setTextSize(12); bot.setPadding(50, 35, 0, 10); Linkify.addLinks(bot, Linkify.ALL); rL.addView(bot,ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); I understand what the error is saying but I am not sure how to fix it. Does anyone have any ideas? Thanks in advance for your help!

    Read the article

  • Dim Window when Menu opened in Android

    - by Casebash
    In Android, when an alert appears, the background is dimmed. I would like a similar effect for when the menu is opened. I tried the following code, but it didn't work: @Override public boolean onMenuOpened(int featureId, Menu m) { boolean ret=super.onMenuOpened(featureId,m); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); return ret; } Does anyone know how to achieve this?

    Read the article

  • Scrolling RelativeLayout- white border over part of the content

    - by Tanis.7x
    I have a fairly simply Fragment that adds a handful of colored ImageViews to a RelativeLayout. There are more images than can fit on screen, so I implemented some custom scrolling. However, When I scroll around, I see that there is an approximately 90dp white border overlapping part of the content right where the edges of the screen are before I scroll. It is obvious that the ImageViews are still being created and drawn properly, but they are being covered up. How do I get rid of this? I have tried: Changing both the RelativeLayout and FrameLayout to WRAP_CONTENT, FILL_PARENT, MATCH_PARENT, and a few combinations of those. Setting the padding and margins of both layouts to 0dp. Example: Fragment: public class MyFrag extends Fragment implements OnTouchListener { int currentX; int currentY; RelativeLayout container; final int[] colors = {Color.BLACK, Color.RED, Color.BLUE}; @Override public View onCreateView(LayoutInflater inflater, ViewGroup fragContainer, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_myfrag, null); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); container = (RelativeLayout) getView().findViewById(R.id.container); container.setOnTouchListener(this); // Temp- Add a bunch of images to test scrolling for(int i=0; i<1500; i+=100) { for (int j=0; j<1500; j+=100) { int color = colors[(i+j)%3]; ImageView image = new ImageView(getActivity()); image.setScaleType(ImageView.ScaleType.CENTER); image.setBackgroundColor(color); LayoutParams lp = new RelativeLayout.LayoutParams(100, 100); lp.setMargins(i, j, 0, 0); image.setLayoutParams(lp); container.addView(image); } } } @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { currentX = (int) event.getRawX(); currentY = (int) event.getRawY(); break; } case MotionEvent.ACTION_MOVE: { int x2 = (int) event.getRawX(); int y2 = (int) event.getRawY(); container.scrollBy(currentX - x2 , currentY - y2); currentX = x2; currentY = y2; break; } case MotionEvent.ACTION_UP: { break; } } return true; } } XML: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".FloorPlanFrag"> <RelativeLayout android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </FrameLayout>

    Read the article

  • Using Flot's Bar Graph in an Android WebView with Highlighting

    - by Nicholi
    The issue is unhighlighting bars which are no longer selected in a bar graph plotted by flot in a WebView on Android. Got no other issues drawing the actual graphs (which look beautiful for something so simple btw). I am not extremely knowledgeable in terms of javascript and web design/development but it seems little should have been needed, if it would just work!! :( I believe I'm following the Flot API correctly, if not someone please scream and yell at me. It seems to work just fine in a non-mobile browser at least. Hoping someone has done this before, but if not I've got the minimal necessary code to poke at your droids if inquiring minds would like to test. I've tested on two Nexus Ones (both 2.2.1), and have tried targeting with Andriod 1.5 and 2.2 SDKs (my intention is to target 1.5 if possible). I've been attempting to hack away at this for far too long on my own now. What happens: 1. Graph loads fine with bars. All bars unhighlighted. 2. Select a bar in graph, gets highlighted fine (and a tooltip is placed). 3. Select a different bar in graph, old bar is unhighlighted, old tooltip removed, new bar highlighted and tooltip placed (still no problems). 4. Click in the vast darkness of the graph which should then unhighlight the last bar... but it doesn't. I've tried disabling flot's autohighlight and manually doing it as well to no avail. Looking into flot itself and only getting down to drawOverlay() where the issue seems to begin... An even more disturbing bug(?) appears if the fill bar option is enabled in the graph, but I'd rather just forget about that for now. Also grabbed the latest version of flot from their svn (r290), but made no different from last public release (v0.6). As a complete guess I'm thinking it's an issue with WebKit's javascript implementation (or something specific to Nexus Ones, which wouldn't be so bad), but if there is any ugly hack to just get it to work I'm all ears. I've thrown the graph data directly into the html/js, rather than deal with showing all the code involved in the Java-javascript handler and callbacks. The simple html placed in 'assets/flot/test/' with jquery.js and jquery.flot.js: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="jquery.js"></script> <script src="jquery.flot.js"></script> <script id="source" language="javascript" type="text/javascript"> var lastItem = null; var plot = null; $(document).ready(function () { //window.testhandler.loadGraph(); // bind plotclick here $("#graphHolder").bind("plotclick", function (event, pos, item) { if (item) { var lastPoint = null; if (lastItem != null) lastPoint = lastItem.datapoint; if (!pointEquals(lastPoint, item.datapoint)) { //if (lastItem != null) // plot.unhighlight(lastItem.series, lastItem.datapoint); lastItem = item; $("#tooltip").remove(); //plot.highlight(item.series, item.datapoint); showTooltip(item.pageX, item.pageY, item.datapoint[1]); } } else if (lastItem != null) { plot.unhighlight(lastItem.series, lastItem.datapoint); // not unhighlighting anything //plot.unhighlight(); // doesn't work either, supposed to unhighlight everything lastItem = null; $("#tooltip").remove(); } }); GotGraph(); }); /** * Show a tooltip above bar in graph * @param {int} x Left coordinate of div * @param {int} y Top coordinate of div * @param {String} contents text to place in div */ function showTooltip(x, y, contents) { $('<div id="tooltip">' + contents + '</div>').css( { position: 'absolute', display: 'none', top: y, left: x, border: '1px solid #fdd', padding: '2px', 'background-color': '#fee', opacity: 0.80 }).appendTo("body").fadeIn(200); } /** * Draw the graph. This is a callback which will be called by Java * * @param {Object} seriesData * @param {Object} seriesOptions */ function GotGraph() { //seriesData, seriesOptions) { var seriesData = [{ "bars":{"lineWidth":2,"show":true,"barWidth":86400000,"align":"center","fill":false}, "data":[[1288569600000,10],[1288656000000,5],[1288742400000,12],[1288828800000,20],[1288915200000,14],[1289001600000,3],[1289174400000,22],[1289260800000,20],[1289347200000,10],[1289433600000,5],[1289520000000,12],[1289606400000,20],[1289692800000,14],[1289779200000,35]]}]; var seriesOptions = { "xaxis":{"twelveHourClock":false,"minTickSize":[1,"day"],"tickSize":[1,"day"],"timeformat":"%d","mode":"time"}, "yaxis":{"min":0}, "grid":{"clickable":true,"autoHighlight":true,"hoverable":false}}; plot = $.plot($("#graphHolder"), seriesData, seriesOptions); } function pointEquals(point1, point2) { if (point1 != null && point2 != null && typeof(point1) == typeof(point2) && point1.length == point2.length) { var i; for (i=0;i<point1.length;i++) { if (point1[i] != point2[i]) { return false; } } return true; } return false; } </script> </head> <body> <div id="graphHolder" STYLE="height:200px;width:400px"></div> </body> </html> The minimal amount of code necessary in onCreate in startup activity: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView mytestView = new WebView(this); mytestView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); setContentView(mytestView); mytestView.setBackgroundColor(0); mytestView.getSettings().setJavaScriptEnabled(true); mytestView.setClickable(true); mytestView.setFocusable(false); mytestView.setFocusableInTouchMode(false); mytestView.loadUrl("file:///android_asset/flot/test/stats_graph.html"); }

    Read the article

  • Supress the Soft Keboard when an activity loads... yet again

    - by tunneling
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Same problem that I've read on other posts. I don't want the soft keyboard to pop up when the Activity loads. The above code snippet works, however my View no longer scrolls up so that the User can still see the EditText. It scrolls without this line of code. Any ideas?

    Read the article

  • ImageView place at center on click in gallery view

    - by TGMCians
    i used gallery view in which i place multiple imageview dynamically but on click imageview place at center and second question how to start first imageview from left of screen. I do not want to change the place until user scroll horizontally by finger . Is there any way to achieve this. Please help for this.. private class ImageAdapter extends BaseAdapter{ public ImageAdapter() { //To set blank at bottom and make visible TextView textView = (TextView)findViewById(R.id.textView2); textView.setVisibility(View.VISIBLE); //To set the visibility visible of gallery myGallery.setVisibility(View.VISIBLE); } public int getCount() { return ProductItemArray.Image_URL.length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } public View getView(int position, View arg1, ViewGroup arg2) { ImageView bottomImageView = new ImageView(context); if(Helper.isTablet(context)) bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(100, context), VirtualMirrorActivity.convertDpToPixel(100, context))); else bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(80, context), VirtualMirrorActivity.convertDpToPixel(80, context))); UrlImageViewHelper.setUrlDrawable(bottomImageView, ProductItemArray.Image_URL[position]); bottomImageView.setBackgroundResource(R.layout.border); return bottomImageView; } } myGallery.setAdapter(new ImageAdapter()); myGallery.setSelection(1); myGallery.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int position, long arg3) { linearLayout.removeView(frameImageView); Thread newThread = new Thread(new Runnable() { public void run() { URL url_1 = null; try { isAlreadyExistInWishlist = false; VMProductListPaging.productUrl = ProductItemArray.Image_small_URL[position]; VMProductListPaging.productId = ProductItemArray.productId[position]; VMProductListPaging.productName = ProductItemArray.product_Name[position]; url_1 = new URL(ProductItemArray.Image_small_URL[position]); bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream()); isExecuted = true; bitmapHandler.sendMessage(bitmapHandler.obtainMessage()); } catch (Exception e) { //Toast.makeText(context,"Sorry!! This link appears to be broken",Toast.LENGTH_LONG).show(); } } }); newThread.start(); } }); Layout.xml <Gallery android:id="@+id/galleryView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:spacing="5dp" android:layout_below="@+id/sendPhoto" android:layout_marginTop="10dp" android:visibility="gone"/>

    Read the article

  • Android: canvas.drawBitmap with Orientation(MagnetField)Sensor

    - by user368374
    hallo, i am developing Android app with orientation sensor. now i got problem. What i want to do is, change scale and position of bitmap which read from sd card. The scale and position depend on value from orientation sensor. i use canvas.drawBitmap(), then it cause problem. the app is just shut down. other drawXXX()methods have no problem..any suggestion? public class AnMagImgtestActivity extends Activity implements SensorEventListener { private SensorManager sensorManager; private MySurfaceView view; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); view = new MySurfaceView(this); ///make it fullscreen getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); ///give screen a hiropon getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(view); } @Override protected void onResume() { super.onResume(); List sensors = sensorManager.getSensorList(Sensor.TYPE_ORIENTATION); if (sensors.size() 0) { Sensor sensor = sensors.get(0); sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME); } } @Override protected void onPause() { super.onPause(); sensorManager.unregisterListener(this); } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { } @Override public void onSensorChanged(SensorEvent event) { view.onValueChanged(event.values); } class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback{ public MySurfaceView(Context context) { super(context); getHolder().addCallback(this); } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { onValueChanged(new float[3]); } @Override public void surfaceCreated(SurfaceHolder holder) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { } void onValueChanged(float[] values) { Canvas canvas = getHolder().lockCanvas(); //String imgfn = "/sdcard/seekcamera"+"/"+regcode+"/to"+"/"+tempnum+".jpg"; String imgfn = "/sdcard/seekcamera"+"/de"+"/to"+"1.jpg"; //String imgfn = "/sdcard/seekcamera"+"/00"+"/00"+"/"+"42.jpg"; File mf = new File(imgfn); Bitmap bitmap0 = BitmapFactory.decodeFile(mf.getPath()); if (canvas != null) { Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.GREEN); paint.setTextSize(12); canvas.drawColor(Color.BLACK); paint.setAlpha(200); for (int i = 0; i < values.length; i++) { canvas.drawText("values[" + i + "]: " + values[i], 0, paint.getTextSize() * (i + 1), paint); } paint.setColor(Color.WHITE); paint.setTextSize(100+values[2]); paint.setAlpha( (int) (255-values[2])); canvas.drawText("Germany", values[0]*1+20, paint.getTextSize() * 1+values[2]-80, paint); ///here is the problem.. canvas.drawBitmap(bitmap0, values[0],values[1], paint); getHolder().unlockCanvasAndPost(canvas); } } } }

    Read the article

  • using Unity Android In a sub view and add style and actionbar

    - by aeroxr1
    I exported a simple animation from Unity3D (version 4.5) in android project. With eclipse I modified the manifest and added another activity. In this activity I put a button that it makes start the animation,and this is the result. The action bar appear in the main activity but it doesn't in the unity's activity :( This is the unity's activity's code : package com.rabidgremlin.tut.redcube; import android.app.NativeActivity; import android.content.res.Configuration; import android.graphics.PixelFormat; import android.os.Bundle; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import com.unity3d.player.UnityPlayer; public class UnityPlayerNativeActivity extends NativeActivity { protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code // Setup activity layout @Override protected void onCreate (Bundle savedInstanceState) { //requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); getWindow().takeSurface(null); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); getWindow().setFormat(PixelFormat.RGB_565); mUnityPlayer = new UnityPlayer(this); /*if (mUnityPlayer.getSettings ().getBoolean ("hide_status_bar", true)) getWindow ().setFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); */ setContentView(mUnityPlayer); mUnityPlayer.requestFocus(); } // Quit Unity @Override protected void onDestroy () { mUnityPlayer.quit(); super.onDestroy(); } // Pause Unity @Override protected void onPause() { super.onPause(); mUnityPlayer.pause(); } // eliminiamo questa onResume() e proviamo a modificare la onResume() // Resume Unity @Override protected void onResume() { super.onResume(); mUnityPlayer.resume(); } // inseriamo qualche modifica qui // This ensures the layout will be correct. @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mUnityPlayer.configurationChanged(newConfig); } // Notify Unity of the focus change. @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); mUnityPlayer.windowFocusChanged(hasFocus); } // For some reason the multiple keyevent type is not supported by the ndk. // Force event injection by overriding dispatchKeyEvent(). @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_MULTIPLE) return mUnityPlayer.injectEvent(event); return super.dispatchKeyEvent(event); } // Pass any events not handled by (unfocused) views straight to UnityPlayer @Override public boolean onKeyUp(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return mUnityPlayer.injectEvent(event); } @Override public boolean onTouchEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } /*API12*/ public boolean onGenericMotionEvent(MotionEvent event) { return mUnityPlayer.injectEvent(event); } } How can I add the action bar and the style of the first activity to unity's animation activity ?

    Read the article

  • How do I load an image from sd card into coverview

    - by Jolene
    I am doing an application which consists of a cover flow. Currently I am trying to make the cover flow images be obtained from the sd card. But I am not exactly sure how should I display the image. this is the image adapter: public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; private FileInputStream fis; private Integer[] mImageIds = { //Instead of using r.drawable, i need to load the images from my sd card instead R.drawable.futsing, R.drawable.futsing2 }; private ImageView[] mImages; public ImageAdapter(Context c) { mContext = c; mImages = new ImageView[mImageIds.length]; } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } @TargetApi(8) public View getView(int position, View convertView, ViewGroup parent) { int screenSize = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK; ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); switch(screenSize) { case Configuration.SCREENLAYOUT_SIZE_XLARGE: //Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show(); Display display4 = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int rotation4 = display4.getRotation(); Log.d("XLarge:",String.valueOf(rotation4)); /** LANDSCAPE **/ if(rotation4 == 0 || rotation4 == 2) { i.setLayoutParams(new CoverFlow.LayoutParams(300, 300)); i.setScaleType(ImageView.ScaleType.CENTER_INSIDE); BitmapDrawable drawable = (BitmapDrawable) i.getDrawable(); drawable.setAntiAlias(true); return i; } /** PORTRAIT **/ else if (rotation4 == 1 || rotation4 == 3) { i.setLayoutParams(new CoverFlow.LayoutParams(650, 650)); i.setScaleType(ImageView.ScaleType.CENTER_INSIDE); BitmapDrawable drawable = (BitmapDrawable) i.getDrawable(); drawable.setAntiAlias(true); return i; } break; default: } return null; } /** Returns the size (0.0f to 1.0f) of the views * depending on the 'offset' to the center. */ public float getScale(boolean focused, int offset) { /* Formula: 1 / (2 ^ offset) */ return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset))); } } and this is how i download and save the file. I need to use the image saved and upload it into my coverflow // IF METHOD TO DOWNLOAD IMAGE void downloadFile() { new Thread(new Runnable(){ // RUN IN BACKGROUND THREAD TO AVOID FREEZING OF UI public void run(){ Bitmap bmImg; URL myFileUrl = null; try { //for (int i = 0; i < urlList.size(); i ++) //{ //url = urlList.get(i); myFileUrl = new URL("http://static.adzerk.net/Advertisers/d18eea9d28f3490b8dcbfa9e38f8336e.jpg"); // RETRIEVE IMAGE URL //} } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream in = conn.getInputStream(); Log.i("im connected", "Download"); bmImg = BitmapFactory.decodeStream(in); saveFile(bmImg); } catch (IOException e) { e.printStackTrace(); }} }).start(); // START THREAD } // SAVE THE IMAGE AS JPG FILE private void saveFile(Bitmap bmImg) { File filename; try { // GET EXTERNAL STORAGE, SAVE FILE THERE File storagePath = new File(Environment.getExternalStorageDirectory(),"Covers"); storagePath.mkdirs(); filename = new File(storagePath + "/image.jpg"); FileOutputStream out = new FileOutputStream(filename); bmImg.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); MediaStore.Images.Media.insertImage(getContentResolver(),filename.getAbsolutePath(), filename.getName(), filename.getName()); // ONCE THE DOWNLOAD FINISHES, CLOSE DIALOG Toast.makeText(getApplicationContext(), "Image Saved!", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } }

    Read the article

< Previous Page | 1 2 3 4 5 6  | Next Page >