scratch/touch problem detection in android - android

I am looking for a solution to test the touch screen of the android device like Amazon/Flipkart etc. do.
Can I get any working reference link which does a similar functionality?

Have you tried ScratchView? It seems very easy to integrate for ImageView and Textview both.
You may also check on this tutorial.
In addition, if you would like to create your own solution, you may place a view on top of ImageView and erase the Bitmap on touch with approach as mentioned in this StackOverflow answer.

Use this library
compile 'com.github.cooltechworks:ScratchView:v1.1'
Use the scratchable view in your xml
<com.cooltechworks.views.ScratchImageView
android:id="#+id/sample_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:src="#drawable/img_sample2"
/>
Add the listener for your scratch view like below and check for the percentage
scratchImageView.setRevealListener(new ScratchImageView.IRevealListener() {
#Override
public void onRevealed(ScratchImageView tv) {
// on reveal
}
#Override
public void onRevealPercentChangedListener(ScratchImageView siv, float percent) {
// if the percent is 1, then whole portion is scratched
}
});
For more info https://github.com/sharish/ScratchView

Related

WebRTC for Android : VideoRendererGUI take a screenshot in the video call

The demand is that saving a video frame in the video call. I have made a demo that take a screenshot through the GLSurfaceView's method "onDrawFrame". But when I use the webrtc, it have its own renderer "VideoRendererGUI" .And then when I want to override it, I find it can't be overrided. the main part code :
vsv = (GLSurfaceView) findViewById(R.id.glviewchild_call);
vsv.setPreserveEGLContextOnPause(true);
vsv.setKeepScreenOn(true);
VideoRendererGui.setView(vsv, new Runnable() {
#Override
public void run() {
init();
}
});
And If you have another way to take a screenshot, you can also share with me.
Thanks a lot!
If you use a SurfaceViewRenderer to display the stream, you can use the solution in this answer to capture a frame on the call.
Basically, using surfaceViewRenderer.AddFrameListener with a class that implements EGLRenderer.FrameListener
I will assume that the SurfaceViewRenderer of the peer you want to take a screenshot of is called remotePeerSurfaceViewRenderer, also I will asume that the button that you will use to take a screenshot is called btnScreenshot
So all what you need to do is as "Webo80" said in the answer above use the FrameListener, the issue is the FrameListener implementation of the webrtc takes only the first frame available once the Listener is attached to the SurfaceViewRenderer, so my approach to do that is by attaching the webrtc implementation of the FrameListsner at the second I need to take a screenshot and remove it once it is taken:
btnScreenshot.setOnClickListener((view)-> {
remotePeerSurfaceViewRenderer.addFrameListsner(new EglRenderer.FrameListener() {
#Override
public void onFrame(Bitmap bitmap) {
runOnUiThread(() -> {
/*
do what ever you want with the bitmap for example
imgView.setImageBitmap(bitmap);
*/
localVideoView.removeFrameListener(this);
});
}
}, 1);
})
Important note:
1. Please don't forget to runOnUiThread as Iam doing
2. Please don't forget to remove the listener inside the button onClick() method
I have tried this solution and it is working more than fine, if you want to make your custom solution you have to completely implement the interface "EglRenderer.FrameListener"
I am sorry to say due to unavailability of canvas and other facilities in Android It's not possible to capture screenshot programatically using WebRTC. One can dodge this situation by animating the app's UI and capturing the screenshot manually , store it at configured location and exchange it with other party.

Android partially active Activity

I have an activity A. I am creating a kind of tutorial for user for this activity, to teach him how he can use the app on that screen.
For that, my requirement is :
I want to blur all the views of the activity except one view. I want to prompt user to click on that view through a hand image pointing at that view.
Nothing should happen if the user clicks on the blurred/greyed out area, but if he taps on that particular active view, it should react to that touch.
I was thinking of using a full screen fragment for this. The Fragment will take the following input from the activity :
for what coordinates, is should not blur the screen and pass the touch event to the activity
the coordinates on which it should show that pointing hand image.
After from these coordinates, the fragment background would be blur.
I wanted to confirm if that's possible, to make the fragment partially active, i.e. delegate it's touch events to the activity for a particular view of the activity.
Also, please let me know if there is any other better approach of achieving the same thing.
Edit1 :
Thinking of using a fragment here, because I'd want this type of behaviour on different screen in future. In that case, I'd make that fragment generic which takes some inputs (as described above) and use it on different screens.
There's a very good library called SCV which does what you're trying to achieve, you're able to customize the styles for it too. I've used this for first time the app is opened to show the user a tutorial.
According to their Github
The ShowcaseView (SCV) library is designed to highlight and showcase specific parts of apps to the user with a distinctive and attractive overlay. This library is great for pointing out points of interest for users, gestures, or obscure but useful items.
Further Reading:
Android Arsenal - Showcase Views Tutorial
ShowCaseView on Android - Indipendev
I found it much easier to include an 'extra' layout around the UI of my activity, and then to add a highest-z grey mostly-transparent filter to it and put the instructions on that.
Each "step" of the instructions was a different layout that was dynamically loaded into that layout container as they clicked. (Just another approach)
The 'container' layout is a: FrameLayout
then in my Activity I have: (ignore bad naming)
private void addOverlayLayout() {
frameLayout = (FrameLayout) findViewById(R.id.framelayoutInner);
frameLayout3 = (FrameLayout) findViewById(R.id.framelayout3);
frameLayout3.setBackgroundColor(Color.DKGRAY);
frameLayout3.setAlpha(0.3f);
// Dynamically create a relativelayout which will be appended to framelayout
relativeLayout = new RelativeLayout(getApplicationContext());
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
instructionOverlays.add(createSimpleClickInstruction(R.layout.instruction_reader_1));
instructionOverlays.add(createSimpleClickInstruction(R.layout.instruction_reader_2));
if (FullscreenReaderActivity.isFirstRun) {
displayNextGuide();
}
}
public void displayNextGuide() {
// clean relative layout if it has views
relativeLayout.removeAllViews();
// clean frame layout if it has child (safe if empty)
frameLayout.removeView(relativeLayout);
if (!isFirstRun) {
return;
}
if (instructionOverlays.size() > 0) {
runOnUiThread(instructionOverlays.get(0));
instructionOverlays.remove(0);
} else {
frameLayout3.setBackgroundColor(Color.TRANSPARENT);
frameLayout3.setAlpha(1.0f);
}
}
public Runnable createSimpleClickInstruction(final int resource) {
return new Runnable() {
#Override
public void run() {
getLayoutInflater().inflate(
resource,
relativeLayout,
true
);
relativeLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
displayNextGuide();
}
});
frameLayout.addView(relativeLayout);
}
};
}

How could I create a custom textview which has specifed distance to its left when meet some characters,for instance ,like '#'

I don't know how to solve this issue,there are some strings needed to fill in the textview,"#Tony#Tom#James#Brown...",what I want to do is like following "#Tony #Tom #James #Brown..." this will be displayed in the textview,the spacing is also specified,for example,"20dp" is the distance between '#Tony' and '#Tom'.I don't know how to create a textview likes above,I have a another question,when the content is out of range,the content should start from next line,so do I deal with this problem?Thank you anyone who gives an answer. If I didn't discribe this question in detail,forgive me.
You can use https://android-arsenal.com/details/1/2242 .
<com.apradanas.simplelinkabletext.LinkableEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
// find username
Link linkUsername = new Link(Pattern.compile("(#\\w+)"))
.setUnderlined(false)
.setTextColor(Color.parseColor("#D00000"))
.setTextStyle(TextStyle.BOLD)
.setClickListener(new Link.OnClickListener() {
#Override
public void onClick(String text) {
// do something
}
});
more information is available on the android arsenal page

How to implement first launch tutorial like Android Lollipop apps: Like Sheets, Slides app?

I have Android 5.0 final build flashed in my Nexus 5. I noticed it has very beautiful, clean and elegant way of showing tutorial at first launch. Apps like "Sheets", "Slides" etc.
How can we implement that in our Android L compatible apps?
Also the app fades off the first launch screen and then shows the tutorial.
There is a pretty good library for emulating these first run tutorials:
https://github.com/PaoloRotolo/AppIntro
Click for larger image
First of all, there's no secret. The quality of the illustrations is the key to get this pretty result. So unless you're a designer yourself, you'll have to find a good designer for them.
Appart from that, I can see several ways to get close to this.
First, there's a very subtle parallax effect on the illustrations. You can achieve it by using this ParallaxTransformPage gist. I use it and it works pretty well.
Also, here's a lib that let you smoothly change the screen's background color while switching pages.
For the splashscreen fade out animation, you can do something like this :
final ImageView launchScreen = (ImageView) context.findViewById(R.id.launch_screen_view);
new Handler().postDelayed(new Runnable()
{
#Override
public void run()
{
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.fade_out);
animation.setAnimationListener(new Animation.AnimationListener()
{
// ...
#Override
public void onAnimationEnd(Animation animation)
{
launchScreen.setVisibility(View.GONE);
}
});
launchScreen.startAnimation(animation);
}
}, 2000);
Follow linkas's answer for the use of a ViewPagerIndicator and how to launch the tutorial only the first time user launches the app.
This git should help you implement what you want:
https://github.com/spongebobrf/MaterialIntroTutorial,
This android Library demonstrating a material intro tutorial much like the ones on Google Sheets, as you mention.
In addition, this library takes the background color set for each page and when scrolling between the two pages, the two colors will fade into one another
Here are few more intro gits that can help you out:
https://github.com/HeinrichReimer/material-intro
https://github.com/PaoloRotolo/AppIntro
I found this library here:
CircleIndicator Library
It creates an Lollipop-like ViewPager with those circles. Just format the layout so that it's suitable for your app and then you should be fine. It doesn't contain an animation, but I think it's a start.
You can use ViewPagerIndicator here: http://viewpagerindicator.com/#download. Then, you should define SharedPreferences, to show that ViewPager only once. You can write:
public class MainActivity extends Activity {
public static final String MyPrefs = "MyPrefs";
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sp = getSharedPreferences(MyPrefs, Context.MODE_PRIVATE);
if (!sp.getBoolean("first", false)) {
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("first", true);
editor.commit();
Intent intent = new Intent(this, SampleCirclesDefault.class); //call your ViewPager class
startActivity(intent);
}
}
}
Maybe you would like to use one of Roman Nurik solutions: https://github.com/romannurik/Android-WizardPager
If you do not want to use a library, it is pretty simple. I used to use a library before, but I started implementing a custom version. All you have to do is use a tabbed view and view pager. Then design all these pages in the tutorial as fragments. These fragments can have any buttons, in any position, and different styling as you like because you are implementing each fragment yourself. And it is not difficult. In the end, just use shared preferences, to check if it is the first run. If it is how the activity which has all the fragments. Else do not show that activity.

ImageView onClickListener changing the image source

Im working on changing the image being shown when I have my ImageView Clicked. Im trying to use a similar code that I used for accomplishing this with a TextView but I can't seem to find the right terms to get it to work. Here is my current code. Thanks
electronconfiguration.setOnClickListener(new View.OnClickListener() {
public void onClick(View drawable) {
if (drawable.equals(R.drawable.element_el))
electronconfiguration.setImageDrawable(R.drawable.aluminum_el);
else if (drawable.equals(R.drawable.aluminum_el))
electronconfiguration.setImageDrawable(R.drawable.element_el);
}
});
Why don't you use a ViewSwitcher, it's designed to switch between two views
drawable probably doesn't equal R.drawable.element_el. R.drawable.element_el is probably some random implementation of the image. Try drawable.getId().equals(R.drawable.element_el). I've never tried this so I have no idea

Categories

Resources