Using numberPickerView with differant APIs - android

In some old APIs numberPickerView not Working.So if i use this view in a project manifest have to be set to higher.That means program not working in old APIs.So my questions are
Is there any View give same functionality in all APIs in Android?
Or is any way to show NumberPickerView in layout when run in latest APIs and show another view to enter numbers(Like EditText) in the place of NumberPickerView when running on older version?

It was added in api 11. If you want pre-11, check this code:
https://github.com/michaelrnovak/numberpicker
You're welcome.

Related

How to get a resource's path from the app using an Android Library?

I'm using an Android Library (SDK A) and it has a customize option.
This option is used like this example below:
val sdk = SDK_A()
sdk.customizeFont("font/myFont.ttf")
sdk.show()
It means this library will look for "myFont.ttf" inside fonts folder to show something using my custom font.
My main goal is to make a new Android Library (SDK B) that uses this library and let users of my library have access to this customisation, they will need to place their custom fonts somewhere my library can access.
My library should be used like this:
val sdk = SDK_B()
sdk.customizeFont("font/myFont.ttf") // it could have another approach, like resource id or something like this
sdk.show()
Summing up, users of SDK B will have a custom font and will set it using sdk.customizeFont method from SDK B, SDK B will set this same font using sdk.customizeFont method of SDK A.
I cannot change SDK A, I can make changes to SDK B and tell users how to use it.
SDK A: Needs to use some path like "font/myFont.ttf" to know where the font is.
SDK B: Needs to know where the font is to set the path on SDK A, doesn't need to have the same approach.
Anyone have a good idea on how to solve it?
Thanks to CommonsWare:
To be clear, the font file goes in main/assets/font/myFont.ttf in your module. You would then pass font/myFont.ttf to setTextFontName().
On my test app using SDK B, I placed myFont.ttf in app/main/src/main/assets/font and set it using sdk_b.setTextFontName("font/myFont.ttf").

Remove initializeScrollBars() from Custom view in Android API level 21

I have one custom class having initializeScrollBars() in its constructor.
In API 21, the method was removed, so i am not able to build the app on Lollipop 5.0.I have searched and found that, there is no alternative provided by android officially.
(https://developer.android.com/sdk/api_diff/21/changes/android.view.View.html).
I have checked this link: initializeScrollbars is undefined? and noticed that one developer suggest us to remove the method and let it on the View class by defining R.styleable.View_scrollbars attr which is not internal.
I just don't get it.
Google have answered for this issue as:
"The API has been removed because R.styleable is not public or stable. There is no safe way to pass a TypedArray into that method. Don't call the method."(Ref: https://github.com/GDG-Korea/PinterestLikeAdapterView/issues/31)
Can anyone light me a path how to remove the method
initializeScrollbars() from the custom view?
Can i simply remove initializeScrollbars() from constructor ?
What is the best way to initialize scrollbars of a custom view.?

Change the title of Paypal PaymentActivity class

I included paypal sdk in the app and set the product name and price as shown in the attached image.
Is it possible to change the title of the paypal PaymentActivity class . ?
I used the entire code for paypal from this link
.Please suggest whether we could change the title to any text ,(I want to change the text that is marked in Red Circle)?
Jeff here from the PayPal Mobile SDK team.
The PayPal Android SDK doesn't support modifying any of the SDK activities. We don't plan to allow the ability to modify titles, as this would be an inconsistent user experience. However, we're open to feedback from users, so please feel free to file issues in GitHub if you have feature requests!
Couple observations, apparently:
The activity of off which you have put screenshot is PaymentMethodActivity (according to Hierarchy Viewer)
PayPal SDK uses ABS
According to the sample app provided in PayPal SDK page, onBuyPressed() launches PaymentActivity with startActivityForResult():
Now, according to SDK references, PaymentActivity does not provide any API for setting custom title. The page lists setTitle() as a part of "Methods inherited from class android.app.Activity", but does not give any details on how to extend PaymentActivity so that one could leverage those APIs.
So, currently, there is no way to use a custom title.
I personally would not bother to change the title on that screen as it clearly depicts itself as a PayPal screen (as one would see their homepage on a browser), but if you really want a custom title, you may need to file a new issue on their GitHub page.
Your AndroidManifest.xml file should have an entry for the PaymentActivity that looks like this:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
All you should have to do is add the label attribute to that to change the title:
<activity android:name="com.paypal.android.sdk.payments.PaymentActivity" android:label="#string/some_title" />
For other potentially useful attributes, refer to the activity tag documentation.
Note: I'm assuming here that the PayPal SDK will allow you to override the title. That is, I would expect it to only set a default title if none is given explicitly.
Edit: Unfortunately, the assumption above has proven to be incorrect. Diving a little deeper, it turns out every activity in the PayPal SDK always sets its title in the onCreate() method. That's actually a little surprising, because that means that PayPal isn't leveraging Android's built-in support for localisation and resources. Although I suppose it does allow them to offer developers the SDK as a jar, which doesn't support bundling Android resources.
In any case, since the various activities haven't been declared final, you could simply try to extend them and set the title after the super has done its work:
public class TitlePaymentMethodActivity extends PaymentMethodActivity {
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Custom Title")
// or:
setTitle(R.string.custom_title);
}
}
After that, you'll have to change the manifest to point to your TitlePaymentMethodActivity, in stead of directly to the activity in the SDK. Do note that this approach may break at any point, if PayPal decides to finalize the activity classes. With that in mind, I suggest you follow #shoe rat's recommendation and file a request with PayPal for 'official' support.

how can i set Street view for Google map in Android?

For Displaying the street view in the map i am putting the following code:
mapView.setStreetView(true);
But, it is not executed it shows the following message when i write the method.
The method setStreetView(boolean) from the type MapView is deprecated
Is there any alternative for that?
No other alternative yet in place of setStreetView(boolean) method from google api 11 onwards, but if you read document carefully, it will show you blue line if street view is available of particular place
There is NO alternative because isStreetView(boolean) is NOT deprecated. I have used this method on several phones running Android 4.0.4 and it works on ALL of them. Perhaps it is deprecated on some phones but not on the Galaxy Nexus. isStreetView(boolean) works, so use it.

Android Calendar View for Date Picker

I'm writing my first app, and I have a question about DatePicker.
My app requires the user to input a date. The most user-friendly way would be to popup a calendar-like widget that displays the current month like a calendar grid - something like this:
I want to use that in place of the DatePicker interface - which has Month, Day, and Year fields, each with an up and down button to increment/decrement.
Is this type of functionality built into any Android widget or view, or would I have to design my own custom component to do this? I figured this would already exist, seeing how much this type of UI is used so frequently in non-mobile apps and web pages.
Thanks!
Now, in 2014, even the native DatePicker (link) contains small Holo looking CalendarView (link) to pick a day in month.
You can choose, if both spinners and CalendarView or just one of them is displayed by setting:
android:calendarViewShown
android:spinnersShown
I'm not sure if it's just API level 16+ or if it was even in Ice Cream Sandwich, but it's there. This is how it looks by default:
Moreover, on API level 21 and higher there is a new Material themed DatePicker that looks like following:
This is default on API 21+ and there are no spinners anymore, but you can switch back to the Holo one by setting
android:datePickerMode="spinner"
in your XML.
Since the API 11 there natively: CalendarView
This View is in HoloEverywhere since API 7.
Is this type of functionality built into any android widget or view, or would I have to design my own custom > component to do this?
There is no component for that in the Android SDK, sorry. The widget you illustrate is too small for a touchscreen. You can implement something larger (see the Calendar app), but you are largely on your own for that.
what i found so far:
http://code.google.com/p/android-calendar-view
http://code.google.com/p/openintents/wiki/CalendarPickerAPI
I have recently written exactly this as a modular app. Here is some sample code, documentation with screenshots, and .apk download.
Found a good implemetation in http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/
Also Since API level 11 (Android 3.0) there has been the native implementation of the CalendarView http://developer.android.com/reference/android/widget/CalendarView.html
Try to use this component:
https://github.com/truefedex/android-date-picker
If you want to use it like popup write on your onclick:
if (calendarPopup == null) {
calendarPopup = new PopupWindow(getContext());
CalendarPickerView calendarView = new CalendarPickerView(getContext());
CalendarNumbersView calendar = (CalendarNumbersView) calendarView.findViewById(com.phlox.datepick.R.id.calendar);
calendar.setShowDayNames(false);
calendarView.setListener(onDateSelectionListener);
calendarPopup.setContentView(calendarView);
calendarPopup.setWindowLayoutMode(
MeasureSpec.makeMeasureSpec(llCalendar.getWidth(), MeasureSpec.EXACTLY),
ViewGroup.LayoutParams.WRAP_CONTENT);
calendarPopup.setHeight(1);
calendarPopup.setWidth(llCalendar.getWidth());
calendarPopup.setOutsideTouchable(true);
}
calendarPopup.showAsDropDown(llCalendar);
you can use this lib for date selection
https://github.com/square/android-times-square/

Categories

Resources