Android Pull To Refresh ListView: eliminate arrow hint - android

I am using this library from Chris Banes (I will never thank this man enough). It has two different behaviors depending on the android version. I want to get rid of the graphical hint on the PullToRefresListView (circled in the image below) that is shown only on devices with android lower than 4.0.
Does anybody knows how to do it?
SOLUTION:
for anybody in the future searching for the same solution here it is: in the PullToRefreshAdapterViewBase class change getShowIndicatorInternal method from this:
private boolean getShowIndicatorInternal() {
return mShowIndicator && isPullToRefreshEnabled();
}
to this:
private boolean getShowIndicatorInternal() {
return false;
}

If you use a layout XML file, you can also specify ptr:ptrShowIndicator="false" inside the PullToRefreshView's declaration. For example:
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/pullToRefreshListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
ptr:ptrShowIndicator="false" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
For other attributes, you can refer to /res/values/attrs.xml in the library, which is self-documented.
You may also find the sample project worth looking at.

Quick and dirty- Simply replace the image file for arrow hint with a transparent image in res folder of library.

I'd say try to see if you can adjust the code to simply take it out.
I don't know if there are any methods added to do this for you, but if there are they should be easy to find.
Scrolling through the code a bit quickly, this might be something;
https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/internal/IndicatorLayout.java
Although i'm not sure if this is actually that arrow, since it doesn't show any hints in this class about being version-based.

Related

error with fab button design with vector assets

I have used the dependencies to be used as suggested. below is the pic.
build_gradle(module)
now I have selected a black plus icon from vector assets and named it as fab_plus, now I have this file in my drawable folder.
fab_plus_XML
now I tried to used that fab_plus_XML like this. Pic below.
activity_main
Now my question is why is the fab_plus is showing in red.
thanks in advance. pls, help me, someone.
There are two things wrong with the way you are specifying the drawable. To refer to a drawable within your project, you simply use #drawable/your_drawable and to allow backward compatibility of VectorDrawables you should use app:srcCompat as per the guidance.
So in your ImageView, instead of
android:src="#android:drawable/fab_plus"
you should have
app:srcCompat="#drawable/fab_plus"
You will also need to make sure the app namespace is included at the top of your layout xmlns:app="http://schemas.android.com/apk/res-auto" along with the current android and tools namespaces.
you need to use:
app:srcCompat
instead of
android:src
but the tooltip there should exactly tell you this and AFAIR even offer a quick-fix

How do I create the semi-transparent grey tutorial overlay in Android?

You know when you run an Android device for the first time (something you see a lot if you use the emulator) that there's a helpful little tutorial about how to use the launcher and add widgets, etc. I'm trying to find an example of this on Google, but I can't. I'm hoping you know what I mean. It's the one with the blue "okay" buttons at each step.
Anyway, I want to create one for my app, but I'm not sure which is the best way to go about doing it.
Do I create a Fragment that I can make semi-transparent on top of my regular activity and have it show up on only the first run?
Do I make a semi-transparent .png for each section of the tutorial and overlay it over the regular launcher activity on the first run?
If I do the latter, how can I adjust for all the various screen sizes? I could just render the image in Photoshop to various dimensions, but that won't cover all of them. If I go the fragment route, I can just say "match_parent" and not worry about it. But then I have to figure out how Fragments work, and they confuse the hell out of me.
I think this open-source library is exactly what you're looking for:
Showcase View
You can grab the source code and setup instructions from GitHub.
Use a hexadecimal color code, which consists of two digits for alpha and six for the color itself, like this:
android:background="#22FFFFFF"
It'll make it semi-transparent.
android:background="#c0000000" for more darkness
Edited
Generally hexadecimak color code structure is like '#FFFF'
For attaining transparency add two digits after '#' to any color code.
Eg : #110000, #220000, #330000.
The greater those two digits, the lesser transparency.
You can try something like this
<LinearLayout ... >
<!-- your Normal layout goes here -->
<RelativeLayout android:id="#+id/tutorialView" android:background="#D0000000"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:src="#drawable/hint_menu" android:layout_alignParentLeft="true"
android:layout_centerVertical="true" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
</LinearLayout>
And in your onCreate method
View tutorialView = findViewById(R.id.tutorialView);
boolean tutorialShown = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getBoolean(Constants.PREF_KEY_TUT_MAIN, false);
if (!tutorialShown) {
tutorialView.setVisibility(View.VISIBLE);
} else {
tutorialView.setVisibility(View.GONE);
}
tutorialView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.setVisibility(View.GONE);
PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit().putBoolean(Constants.PREF_KEY_TUT_MAIN, true).commit();
}
});
There is an award-winning library for this called "FancyShowcaseView":
https://github.com/faruktoptas/FancyShowCaseView
Add to your project like this:
In the top-level build.gradle (not the module level):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
In the module-level (app) build.gradle
dependencies {
compile 'com.github.faruktoptas:FancyShowCaseView:1.0.0'
}
Then you can call:
new FancyShowCaseView.Builder(this)
.focusOn(view)
.title("Focus on View")
.build()
.show();
You don't need to use Photoshop. You can Use for example a LinearLayout with android:background="#50134BE8". This will make it transparent blue. You can place the layout on top of everything and hide it when the user is done. You can use any background color, but to make it transparent, place a number from 01 to FE, after the "#" symbol to change its transparency. Set the width and the height to fill_parent to occupy the whole area. Place this view directly in the main layout. Hope this helps.

How to make segmented seekbar/slider look like following?

I was wondering if anyone can provide hint or source to achieve following slider widget used in "Circle – Who's Around?" This is the first time I have ever came across this and I am not sure what to exactly name this widget.:
I was thinking of using custom seekbar background to do this but, I am not sure how do I figure out exact pixels that the seekbar will reach of next step. Since, that will be independent to devices. In my case I am planning to use images, rather than the indicators.
Please don't point to this link http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ because this is not what I want to achieve. They seem to have used static image footer to show D,W,K. I have tried that app and it doesn't even step to the exact dots or D,W,K. I have looked at AT&T Android Slider Controls but, they don't seem to provide any source for it. I have found some iOS devs achieving that but, I don't really understand obj C code in order to achieve that in Android.
This is just a seekbar with a custom thumb and background. You could use a 9patch for the background so it fills nicely and just set them in your styles
Following #Milanix answer using the library at https://github.com/karabaralex/android-comboseekbar here it is a minimum example code that worked for me:
<com.infteh.comboseekbar.ComboSeekBar
android:id="#+id/seekbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
custom:color="#000"
custom:textSize="12sp"
custom:multiline="false"
/>
Then in the Activity
private ComboSeekBar mSeekBar;
List<String> seekBarStep = Arrays.asList("All","1","5","10","20");
mDistanceSeekBar.setAdapter(seekBarStep);
This will create a black segmented seekbar using default drawables. If you need to add some customization have a look at ComboSeekBar.onDraw(), CustomDrawable.draw() and CustomThumbDrawable.draw().
This project is all but finished but still a solid starting point.
#Giulio thank you for your post, I have the same problem as Ron Eskinder.
I heve fixed it by removing :"custom:color" , "custom:textsize" and "custom:multiline" in xml file. then in Java I put this:
mSeekBar = (ComboSeekBar) findViewById(R.id.seekbar);
List<String> seekBarStep = Arrays.asList("All","1","5","10","20");
mSeekBar.setAdapter(seekBarStep);
Hope this will help

Android package/class name in layout XML?

This is probably a trivia question, but why are there package/class names in some people's XML layout files?
(please don't downvote this question if it is something trivial, i don't even know what this is called, so i couldn't look it up).
i was looking at a tutorial, and i saw something like this (in "sample.xml"):
<com.tutorials.foo
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- some buttons and views here -->
</com.tutorials.foo>
My questions are:
1) i'm assuming that "foo" is a custom view? say, like you want to extend TextView with your own version of TextView?
2) what is this pattern/technique even called?
3) what would be the advantages of using this method?
Thanks so much in advance!!!
Yes, <com.tutorials.foo .../> is a custom view.
Calling it will be as same as others.ex:
Foo foo=(Foo)findViewById(R.id.foo);
I assume you mean creating layout static(.xml) or dynamically with code. xml layout would be in advantage when you know that you will use this layout in the program and will not change its format. Of course you can add to it or edit it with code later on. It is also in advantage for readabilty.

Custom state drawables not working in Library Projects

Any searches for any information on how to provide your own custom state for use in a drawable state list selector pulls up very little but almost all of them (here and elsewhere) refer to this google groups post.
I have getters and setters like this: (Not included in the above post, but using their wording to keep it simple)
public void setFried(boolean fried){
if(mFried != fried){
mFried = fried;
refreshDrawableState();
}
}
public void isFried(){
return mFried;
}
I have been trying to get it to work for the last couple hours and nothing seems to be working. It just simply does not change the appearance. I watched what happened as it called onCreateDrawableState(), and I watched what would come out of getDrawableState() after I changed the custom state. The custom state values are in fact appearing in the drawableState array.
Since I can see the state is actually being merged into the array, and since it seems to be completely ignoring any of my custom state in the selector, I think the xml must be wrong.
Here is what the post suggested:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/my.app.package">
<item android:drawable="#drawable/item_baked" state_baked="true"
state_fried="false" />
<item android:drawable="#drawable/item_fried" state_baked="false"
state_fried="true" />
<item android:drawable="#drawable/item_overcooked" state_baked="true"
state_fried="true" />
<item android:drawable="#drawable/item_raw" state_baked="false"
state_fried="false" />
</selector>
Can you really just write state_fried and state_baked or do they need a prefix like app:state_fried? If I try adding a prefix I get a Console error like: No resource identifier found for attribute 'state_fried' in package my.app.package
Has anyone actually got custom states to work? Is the referenced post all you need to get this to work or is there something wrong with it or missing?
I don't know if it makes any difference but I am using an Android Library Project and the selector and the attr.xml is in the Library project.
Thanks
Update
Looks like the problem is that Library Projects don't play well with custom attributes. See here, here, here.
Haven't seen much of a workaround unfortunately...
I wrote that original question. IIRC, that was when Android was in beta, and things have changed a bit. Custom attributes do indeed work; I use them. You do indeed need the app: prefix for custom state attributes. You also need to substitute your app's package in place of my.app.package in the xmlns declaration.
use
xmlns:app="http://schemas.android.com/apk/lib/my.app.package
for attributes declared in the library.

Categories

Resources