It seems like a support library bug, but when i make mSwipeRefreshLayout refreshing in fragment onCreateView using this code
mSwipeRefreshLayout.post(new Runnable() {
#Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
}
});
circle progress starts twice. First it appears and immediately hides and then appears again and then works like it supposed to do.
It doesn't happen on Android L devices, only when api < 21 with using support library.
Please help me out.
Related
I imagine someone has had this question before, I just don't quite know what the right keywords are to find the answer? I am making an android app with an activity that includes tabs using TabLayout. Nothing fancy, just really standard stuff. In fact, so far I've done literally nothing but make a completely new application with a single tabbed activity using the auto-generated code from Android Studio. Everything works fine, but there is one feature I cannot figure out how to turn off -- when I long click on any tab, a little rectangular alt text or something with the title of the tab pops up on screen just above the tab. It's not the end of the world if I can't eliminate it, I just find it to be irritating and incompatible with the overall desired feel of my app given that it's literally just duplicating the tab title. I can't find any code that is causing this to appear, so I don't know how to delete it. The picture below shows what I'm talking about circled in red.
If anyone needs me to post code to help answer, I can... but you can also just make a new tabbed activity in a throwaway application in Android Studio and get exactly the same boilerplate code I have.
Edit: I added the term "tooltip" to the title so others can find the relevant thread more easily if they have the same problem.
Kudos to Mike M. for the answer, shown in comments above. I implemented it successfully, so if anyone comes back here looking for the answer, here's the successful java code, which is placed in the onCreate() method of the activity containing the tabLayout:
// turn off that tooltip text thing immediately on activity creation
for (int i=0; i<tabs.getTabCount(); i++) {
TooltipCompat.setTooltipText(Objects.requireNonNull(tabs.getTabAt(i)).view, null);
}
tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
int tabPosition = tab.getPosition(); // syntactic sugar
viewPager2.setCurrentItem(tabPosition, true);
// Repeat of the code above -- tooltips reset themselves after any tab relayout, so I
// have to constantly keep turning them off again.
for (int i=0; i<tabs.getTabCount(); i++) {
TooltipCompat.setTooltipText(Objects.requireNonNull(tabs.getTabAt(i)).view, null);
}
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
I am working on an Android app that runs on only one devicerunning KitKat.
The smooth scrolling feature for a RecylerView I used that was working on other physical tablets and genymotion has unfortunately stopped working on the one device it needs to work on.
Instead of scrolling to a certain position it passes over the target position and scrolls all the way to the bottom and looks really bad.
I am able to track down the error to the abstract SmoothScroller in the RecyclerView class.
if (getChildPosition(mTargetView) == mTargetPosition) {
onTargetFound(mTargetView, recyclerView.mState, mRecyclingAction);
mRecyclingAction.runIfNecessary(recyclerView);
stop();
} else {
Log.e(TAG, "Passed over target position while smooth scrolling.");
mTargetView = null;
}
I was using a SnappingLinearLayoutManager that I found online, but swapped it out with the normal LinearLayoutManager from Android, and still am having the same problem.
The list is 7 items long (user can see 4 at a time) and I scroll to the 5th item (position 4) item.
When I scroll to the 3rd I don't receive this error.
Also after I scroll the list up and down once, the error stops happening.
EDIT:
I am able to use layoutManager.scrollToPositionWithOffset(); But I am trying to do this with the smooth scroll animation.
Here is some of my code and details:
private void setupMainRecyclerViewWithAdapter() {
mainLayoutManager = new SnappingLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mainListRecyclerView.setLayoutManager(mainLayoutManager);
settingsMainListAdapter = new SettingsListAdapter(SettingsActivity.this,
settingsPresenter.getSettingsItems(),
settingsPresenter);
mainListRecyclerView.setAdapter(settingsMainListAdapter);
mainListRecyclerView.addItemDecoration(new BottomOffsetDecoration(EXTRA_VERTICAL_SCROLLING_SPACE));
}
#Override
public void scrollMainList(boolean listAtTop) {
if(listAtTop) {
mainListRecyclerView.smoothScrollToPosition(4);
moveMainMoreButtonAboveList();
} else {
mainListRecyclerView.smoothScrollToPosition(0);
moveMainMoreButtonBelowList();
}
}
If you call recyclerView.smoothScrollToPosition(pos) will be called immediately on the UI thread and if recyclerView's Adapter is too much busy to generating view items then the calling of smoothScrollToPosition will be missed then because recyclerView has no data to smooth scroll. So it's better to do that in a background thread by recyclerView.post(). By calling this it goes into the Main thread queue and gets executed after the other pending tasks are finished.
Therefore you should do something like this which worked for my case:
recyclerView.post(new Runnable() {
#Override
public void run() {
recyclerView.smoothScrollToPosition(pos);
}
});
Well, I realize it's too late, however I tried some different solutions and found one...
in custom LinearSmoothScroller I override updateActionForInterimTarget
#Override
protected void updateActionForInterimTarget(Action action) {
action.jumpTo(position);
}
It's appears not very smooth, but not instant in contrast with scrollToPositionWithOffset.
Just add one line for smooth scroll
recyclerView.setNestedScrollingEnabled(false);
it will work fine
Take a look at hasPendingAdapterUpdates(). You can use this along with a delay() for coroutines or Thread.sleep() to enable the backing data to be available before doing the scroll.
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.
I currently have a WebView in an app I am working on and after each page loads in the WebView I would like to hide the TitleBar. I have looked at this question and the answer looks like it should do exactly what I want, however the TitleBar is never hidden after the page finishes loading.
The code I am using is the same as the answer I have linked to, but I have also included it bellow. I can confirm that onProgressChanged is being called and that progress does get reported as 100 when the page finishes loading, but setProgressBarIndeterminateVisibility(false) and setProgressBarVisibility(false) both seem to do nothing. I am using requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) and requestWindowFeature(Window.FEATURE_PROGRESS) before I sent content.
I have tested this on Android 2.3 and 4.1 and the result is the same for both, the TitleBar is not hidden.
mWebView.setWebChromeClient(new WebChromeClient() {
#Override
public void onProgressChanged(WebView view, int progress) {
setProgress(progress * 100);
if(progress == 100) {
setProgressBarIndeterminateVisibility(false);
setProgressBarVisibility(false);
}
}
});
I created a android web browser targeted towards android 2.3 and ran into this same problem.
The solution is to add this line of code somewhere in your main activity.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
make sure you put this line before your setContentView() method or your app will force close.
The old title bar is somewhat limited in functionality. You will probably have to make your own title bar within the layout of the activity and show/hide it yourself with setVisibility().
If you are using the ActionBar instead of the old title bar (which is what people should be doing anyways), it has show() and hide() methods you can use to do what you want.
public void onProgressChanged (WebView view, int progress)
{
if(progress<100 && pb.getVisibility()==pb.Invisible)
{
pb.setvisibility(pb.Visible)
}
pb.setProgress(progress);
if(progress==100)
{
pb.setVisibility(ProgressBar.INVISIBLE);
}
*where pb =(ProgressBar)findViewById(R.Id.progressbar);
its working correctly for me
hope you got my code simple and sweet.....
in my app i have place a text view in the middle of the layout and when i scroll screen to left i want to show the google maps. So far i am showing the google aps by ontouch method.
how to perform this...
You can use a third party called SwipeView.
It's an extension of the HorizontalScrollView class.
USE THIS , its working fine and no delays
hor = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
hor.postDelayed(new Runnable() {
public void run() {
hor.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 1L);