It's an old book and has this example of drawing on the screen. So after typing the whole program, it's not behaving as it was said in the books that I'll allow you to draw on the screen.
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.Panel;
import android.view.MotionEvent;
import android.view.View;
import java.util.ArrayList;
import java.util.List;
public class dragAndDrawActivity extends Activity
{
Paint paint;
Point point1, point2;
Path path;
List<Path> paths=new ArrayList<Path>();
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(new Panel(this));
}
class Panel extends View implements View.OnTouchListener{
public Panel(Context context)
{
super(context);
paint=new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(10);
paint.setStyle(Paint.Style.STROKE);
this.setOnTouchListener(this);
}
#Override
public void onDraw(Canvas canvas)
{
canvas.drawColor(Color.BLACK);
for (Path path: paths)
{
canvas.drawPath(path,paint);
}
}
#Override
public boolean onTouch(View view,MotionEvent event)
{
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
point1=new Point();
point1.x=(int) event.getX();
point1.y=(int) event.getY();
path.moveTo(point1.x, point1.y);
}
else if(event.getAction()==MotionEvent.ACTION_MOVE)
{
point2 =new Point();
point2.x=(int) event.getX();
point2.y=(int) event.getY();
path.lineTo(point2.x, point2.y);
paths.add(path);
invalidate();
}
return true;
}
}
}
Build gets successful and apk install, but when you try to draw something on the screen, nothing happens.
and the background color also does not apply so there must be some issue with this code.
You should extract it to a custom view and add it to activity layout with alignment constrains. Furthermore, you need to init path variable before using it.
This is how I write it with Kotlin, you can convert back to Java
Panel class
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import androidx.annotation.Nullable
class Panel : View, View.OnTouchListener {
var paint: Paint? = null
var point1: Point? = null
var point2:Point? = null
var path: Path = Path()
var paths: ArrayList<Path> = ArrayList()
init {
paint = Paint()
paint?.color = Color.GREEN
paint?.strokeWidth = 10f
paint?.style = Paint.Style.STROKE
this.setOnTouchListener(this)
}
constructor(context: Context): super(context)
constructor(context: Context, #Nullable attrs: AttributeSet): super(context, attrs)
override fun onDraw(canvas: Canvas) {
canvas.drawColor(Color.BLACK)
paint?.let {
for (path in paths) {
canvas.drawPath(path, it)
}
}
}
override fun onTouch(view: View, event: MotionEvent): Boolean {
if (event.action == MotionEvent.ACTION_DOWN) {
point1 = Point()
point1?.x = event.x.toInt()
point1?.y = event.y.toInt()
path.moveTo((point1?.x?:0)*1f, (point1?.y?:0)*1f)
} else if (event.action == MotionEvent.ACTION_MOVE) {
point2 = Point()
point2?.x = event.x.toInt()
point2?.y = event.y.toInt()
path.lineTo((point2?.x?:0)*1f, (point2?.y?:0)*1f)
path.let {
paths.add(it)
}
invalidate()
}
return true
}
}
activity layout
<androidx.constraintlayout.widget.ConstraintLayout
android:clipToPadding="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<com.martin.screst.customviews.Panel
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Activity class
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
Related
Hey guys I'm trying to use this library (https://github.com/davemorrissey/subsampling-scale-image-view) and I tried out the example mentioned about PinView but I don't get the map displayed nor any Marker. ( the error says cannot cast Subsampling ImageView as PinView how do you solve this ?
MainActivity.java
package com.ascot.mxiv.mapzone;
import android.graphics.PointF;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.davemorrissey.labs.subscaleview.ImageSource;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PinView imageView = findViewById(R.id.imageView);
imageView.setImage(ImageSource.resource(R.drawable.completemap1).tilingDisabled());
imageView.setPin(new PointF(460f, 320f));
}
}
PinView.java ( no changes made other than the import test.T.drawable as i dont understand it ) and help would be appreciated :D .
import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.widget.Toast;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
//import com.davemorrissey.labs.subscaleview.test.R.drawable;
public class PinView extends SubsamplingScaleImageView {
private final Paint paint = new Paint();
private final PointF vPin = new PointF();
private PointF sPin;
private Bitmap pin;
Context context;
public PinView(Context context) {
this(context, null);
this.context = context;
}
public PinView(Context context, AttributeSet attr) {
super(context, attr);
this.context = context;
initialise();
}
public void setPin(PointF sPin) {
this.sPin = sPin;
initialise();
invalidate();
}
private void initialise() {
float density = getResources().getDisplayMetrics().densityDpi;
pin = BitmapFactory.decodeResource(this.getResources(), R.drawable.marker);
float w = (density/420f) * pin.getWidth();
float h = (density/420f) * pin.getHeight();
pin = Bitmap.createScaledBitmap(pin, (int)w, (int)h, true);
}
#Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// Don't draw pin before image is ready so it doesn't move around during setup.
if (!isReady()) {
return;
}
paint.setAntiAlias(true);
if (sPin != null && pin != null) {
sourceToViewCoord(sPin, vPin);
float vX = vPin.x - (pin.getWidth()/2);
float vY = vPin.y - pin.getHeight();
canvas.drawBitmap(pin, vX, vY, paint);
Toast.makeText(context,"works ? ", Toast.LENGTH_SHORT).show();
}
}
}
The problem is your in your layout, you should use PinView instead of SubsamplingScaleImageView as shown in the snippet below.
..
<com.example.myapp.PinView
android:id="#+id/floorplan_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
I'm looking for a colour picker and stumbled over a pretty good one. The Github page is here. However, when trying to use it the logcat spits out an error.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.education.clearmind.tutoria, PID: 6604
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:353)
at android.app.Dialog.requestWindowFeature(Dialog.java:1066)
at com.pes.androidmaterialcolorpickerdialog.ColorPicker.onCreate(ColorPicker.java:94)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at com.education.clearmind.tutoria.WhiteboardActivity.openColorPicker(WhiteboardActivity.java:58)
at com.education.clearmind.tutoria.WhiteboardActivity$1.onClick(WhiteboardActivity.java:49)
at android.view.View.performClick(View.java:4789)
at android.view.View$PerformClick.run(View.java:19881)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Here is the code in the WhiteboardActivity where the colour picker should be implemented :
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import com.education.clearmind.tutoria.ui.views.WhiteboardSurface;
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
import butterknife.Bind;
import butterknife.ButterKnife;
public class WhiteboardActivity extends Activity {
private Button mChangeBrushColorButton;
private ColorPicker mColorPicker;
private Button mOkColorButton;
private int optionsMenuNumberClicks = 0;
#Bind(R.id.whiteboardRelativeLayout) RelativeLayout mWhiteboardRelativeLayout;
#Bind(R.id.whiteboardSurface) WhiteboardSurface mWhiteboardSurface;
#Bind(R.id.floatingActionBar) ImageButton mFloatingActionBarButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_whiteboard);
initializeScreenUI();
onFloatingActionBarClick();
}
public void initializeScreenUI() {
ButterKnife.bind(this);
mColorPicker = new ColorPicker(WhiteboardActivity.this, Color.RED, Color.GREEN, Color.BLUE);
mOkColorButton = (Button) mColorPicker.findViewById(R.id.okColorButton);
}
public void onFloatingActionBarClick() {
mFloatingActionBarButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openColorPicker();
}
});
}
public void openColorPicker() {
mColorPicker.show();
mOkColorButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int selectedColorRGB = mColorPicker.getColor();
mWhiteboardSurface.changeBrushColor(selectedColorRGB);
mColorPicker.dismiss();
}
});
}
}
Here is the code in the WhiteboardSurface View:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.education.clearmind.tutoria.model.Brush;
/**
* Created by tomfinet on 06/03/16.
*/
public class WhiteboardSurface extends View {
private Paint mPaint = new Paint();
private Path mPath = new Path();
private Brush mBrush = new Brush(mPaint, mPath);
// Constructor sets up the paint and inherits the superclasses constructor
public WhiteboardSurface(Context context, AttributeSet attrs) {
super(context, attrs);
// Default brush setup
mPaint.setAntiAlias(true);
mPaint.setColor(Color.BLACK);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(10f);
}
#Override
protected void onDraw(Canvas canvas) {
// draws the path with the selected paint
canvas.drawPath(mBrush.getPath(), mBrush.getPaint());
}
#Override
public boolean onTouchEvent(MotionEvent motionEvent) {
/**
* gets the xPos and yPos of the touch on the screen and saves them in variables so
* that they can be manipulated into drawing lines and so on.
*/
float xPos = motionEvent.getX();
float yPos = motionEvent.getY();
//TODO: Add the functionality to open options menu on touch event
switch(motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
mPath.moveTo(xPos, yPos);
break;
case MotionEvent.ACTION_MOVE:
mPath.lineTo(xPos, yPos);
break;
default:
return false;
}
invalidate();
return true;
}
public void changeBrushColor(int colorRGB) {
mPaint.setColor(colorRGB);
}
}
Can someone please tell me what I am doing wrong and how to fix it.
If you need anything else, please just ask.
Cheers.
I am trying to create my first android game (in eclipse) and I cannot seem to get OnTouchListner to work, mostly because I don't know how or where to create it. I am trying to figure out where someone taps the screen. Can someone please tell me how and where to create the OnTouchListner!
Activity class:
package com.gregsapps.fallingbird;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
public class Game extends Activity implements OnTouchListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GameView(this));
}
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.){
System.out.println("TOUCH");
}
return false;
}
}
View class:
package com.gregsapps.fallingbird;
import android.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.view.MotionEvent;
import android.view.View;
public class GameView extends View{
private Bird bird;
private boolean runOnce = false;
private Context context;
public GameView(Context context) {
super(context);
this.context = context;
this.setDrawingCacheEnabled(true);
// TODO add setup code
}
protected void onDraw(Canvas canvas){
update(canvas);
//TODO add drawing code
this.buildDrawingCache();
//bird.canvasImage = this.getDrawingCache(true);
canvas.drawBitmap(bird.image, bird.x, bird.y, null);
System.out.println("drawing");
invalidate();
}
private void update(Canvas canvas){
//TODO add code to update stuff
if(runOnce == false){
bird = new Bird(canvas, com.gregsapps.fallingbird.R.drawable.bird, context);
runOnce = true;
}
bird.move();
}
}
Implement it like this :-
public class Game extends Activity implements OnTouchListener{
GameView gv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gv = new GameView(this);
setContentView(gv);
gv.setOnTouchListener(this);
}
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction() == MotionEvent.ACTION_DOWN){
int x = event.getX();
int y = event.getY();
System.out.println("Touched view at X: " + X + " Y: " + Y );
}
return false;
}
}
You should just be able to set it on the view you create:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GameView gv = new GameView(this);
setContentView(gv);
// set the touch listener for the view
gv.setOnTouchListener(this);
}
I need help regarding the viewpager. Basically I have a viewpager contained in a page container:
package com.example.CustomViews;
/**
* Created by imrankhan on 4/29/2015.
*/
import android.content.Context;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.graphics.Point;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.example.imrankhan.newlawdojo.DashboardActivity;
import com.example.imrankhan.newlawdojo.QuizActivity;
import com.example.imrankhan.newlawdojo.R;
/**
* PagerContainer: A layout that displays a ViewPager with its children that are outside
* the typical pager bounds.
*/
public class PageContainer extends FrameLayout implements ViewPager.OnPageChangeListener {
private ViewPager mPager;
boolean mNeedsRedraw = false;
private Camera mCamera = new Camera();
private int mMaxRotationAngle = 60;
private int mMaxZoom = -120;
public PageContainer(Context context) {
super(context);
init();
}
public PageContainer(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public PageContainer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
//Disable clipping of children so non-selected pages are visible
setClipChildren(false);
//Child clipping doesn't work with hardware acceleration in Android 3.x/4.x
//You need to set this value here if using hardware acceleration in an
// application targeted at these releases.
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
#Override
protected void onFinishInflate() {
try {
mPager = (ViewPager) getChildAt(0);
mPager.setOnPageChangeListener(this);
} catch (Exception e) {
throw new IllegalStateException("The root child of PagerContainer must be a ViewPager");
}
}
public ViewPager getViewPager() {
return mPager;
}
private Point mCenter = new Point();
private Point mInitialTouch = new Point();
#Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mCenter.x = w / 4;
mCenter.y = h / 4;
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
//We capture any touches not already handled by the ViewPager
// to implement scrolling from a touch outside the pager bounds.
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mInitialTouch.x = (int)ev.getX();
mInitialTouch.y = (int)ev.getY();
default:
ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
break;
}
return mPager.dispatchTouchEvent(ev);
}
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//Force the container to redraw on scrolling.
//Without this the outer pages render initially and then stay static
if (mNeedsRedraw) invalidate();
}
#Override
public void onPageSelected(int position) {
View v =this.getViewPager().getChildAt(position);
}
private void transformImageBitmap(View child, Transformation t, int rotationAngle) {
mCamera.save();
final Matrix imageMatrix = t.getMatrix();;
final int imageHeight = child.getLayoutParams().height;;
final int imageWidth = child.getLayoutParams().width;
final int rotation = Math.abs(rotationAngle);
mCamera.translate(0.0f, 0.0f, 100.0f);
if ( rotation < mMaxRotationAngle ) {
float zoomAmount = (float) (mMaxZoom + (rotation * 1.5));
mCamera.translate(0.0f, 0.0f, zoomAmount);
}
mCamera.rotateY(rotationAngle);
mCamera.getMatrix(imageMatrix);
imageMatrix.preTranslate(-(imageWidth/2), -(imageHeight/2));
imageMatrix.postTranslate((imageWidth/2), (imageHeight/2));
mCamera.restore();
}
#Override
public void onPageScrollStateChanged(int state) {
mNeedsRedraw = (state != ViewPager.SCROLL_STATE_IDLE);
}
}
on onPageSelected event I got the view I need to zoom in when selected and zoom out after selecting another item. Please help me out. I added an image to give you an idea what I want.
http://i.stack.imgur.com/xtE89.png
everyone! I'm new to Android development and I'm having troubles while trying to set an specific position to the seek bar's thumb.
I want to set the seek bar's progress to it's initial position (in this case 4) when the user releases the thumb, in order to do this, I'm trying to use the method onStopTrackingTouch, but it looks like it's not being called when the user releases the seek bar thumb. There are no errors indicated by Eclipse, the program runs normally, the only problem is that when I release the thumb, it does not return to the initial position.
Detail: I'm using a Vertical Seek Bar, can this be the reason of the problem?
Here's the activity code:
package renatox.play.bluetoothcommander;
import java.io.IOException;
import java.io.OutputStream;
import java.util.UUID;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.SeekBar;
public class MainActivity extends Activity implements SensorEventListener {
private VerticalSeekBar acelerador;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Sets the Main Activity layout
setContentView(R.layout.activity_main);
// Gets the VerticalSeekBar
acelerador = (VerticalSeekBar) findViewById(R.id.acelerador);
acelerador
.setOnSeekBarChangeListener(new VerticalSeekBar.OnSeekBarChangeListener() {
// I've tried using SeekBar.OnSeekBarChangeListener() and VerticalSeekBar.OnSeekBarChangeListener()
#Override
public void onStopTrackingTouch(SeekBar arg0) {
acelerador.setProgress(4);
Log.i("Acelerador", "O usuário soltou o acelerador");
}
#Override
public void onStartTrackingTouch(SeekBar arg0) {
Log.i("Acelerador", "O usuário pegou o acelerador");
}
// Pega os valores do acelerador quando mudam
#Override
public void onProgressChanged(SeekBar arg0, int arg1,
boolean arg2) {
int velocidade = acelerador.getProgress();
Log.i("Acelerador", "Velocidade atual: " + velocidade);
}
});
}
Here's the xml layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/fundo"
android:keepScreenOn="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<renatox.play.bluetoothcommander.VerticalSeekBar
android:id="#+id/acelerador"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginBottom="30dp"
android:layout_marginRight="5dp"
android:layout_marginTop="30dp"
android:max="8"
android:maxHeight="0dp"
android:minHeight="0dp"
android:progress="4"
android:progressDrawable="#drawable/progress"
android:thumb="#drawable/thumb" />
</RelativeLayout>
And here is the VerticalSeekBar class
package renatox.play.bluetoothcommander;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.SeekBar;
public class VerticalSeekBar extends SeekBar {
protected OnSeekBarChangeListener changeListener;
public VerticalSeekBar(Context context) {
super(context);
}
public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public VerticalSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(h, w, oldh, oldw);
}
#Override
protected synchronized void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
}
protected void onDraw(Canvas c) {
c.rotate(-90);
c.translate(-getHeight(), 0);
super.onDraw(c);
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
setSelected(true);
setPressed(true);
if (changeListener != null)
changeListener.onStartTrackingTouch(this);
break;
case MotionEvent.ACTION_UP:
setSelected(false);
setPressed(false);
if (changeListener != null)
changeListener.onStopTrackingTouch(this);
break;
case MotionEvent.ACTION_MOVE:
int progress = getMax()
- (int) (getMax() * event.getY() / getHeight());
setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
if (changeListener != null)
changeListener.onProgressChanged(this, progress, true);
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
}
Can anyone give me a hint of what might be happening?
Thank you very much!!
Thought I would post this as an official "answer" since it helped me with my code. (answered by Renato Henz)
I've just added this to the "VerticalSeekBar.java": #Override public void setOnSeekBarChangeListener(OnSeekBarChangeListener mListener) { this.changeListener = mListener; } If you need any further help, please tell me. Good luck with your code!
I found that adding in this code, along with the code previously mentioned, helps with some issues:
#Override
public synchronized void setProgress(int progress) {
super.setProgress(progress);
onSizeChanged(getWidth(), getHeight(), 0, 0);
}
Hello if you change your code like this it will work.
case MotionEvent.ACTION_UP:
super.onTouchEvent(event);
// your code here.
return true;
When I add in aboce setOnSeekBarChangeListner code in the VerticalSeekBar.java, the myControl.setOnseekBarChangeListener code stops working altogether. i.e. OnProgrressChanged stops.
I am trying to enable the code in my activity to the Toast fires (just a placeholder)
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
Toast.makeText(APG.this, "Change OD Done", Toast.LENGTH_SHORT).show();
}
you have to define OnSeekBarChangeListener in VerticalSeekbar then it will work
Try it in VerticalSeekBar like
private OnSeekBarChangeListener onChangeListener;
#Override
public void setOnSeekBarChangeListener(OnSeekBarChangeListener onChangeListener){
this.onChangeListener = onChangeListener;
}
If you have missed out, just call within onTouchEvent.
super.onTouchEvent(event);