Menu
  • HOME
  • TAGS

How to get default text size from TextView on widget?

android,android-widget,android-textview

Actually defaultTextView.getTextSize() returns size in pixels and setTextSize(size) takes input as sp, So your text becomes bigger. Thus instead of directly setting up the text size, first convert them according to density. float sourceTextSize = defaultTextView.getTextSize(); TextView.setTextSize(sourceTextSize / getResources().getDisplayMetrics().density); Here, getResources().getDisplayMetrics().density will returns the screen density as- 0.75 - ldpi...

Display UI like facebook messenger in Android java programatically

android,android-layout,android-activity,android-widget,android-xml

Ok, the image you are looking at is actually a ListView serving custom-made views. How does that work? You will need to subclass the BaseAdapter class. This subclass will contain the underlying data which in your case you are getting as a JSON-formatted reply from the web-server. When the getView()...

How to avoid to creating multiple widgets in homescreen?

android,android-widget,android-appwidget

By Approaching the above solution, a little change in the AppWidgetConfigurationActivity, public class AppWidgetConfigurationActivity extends ActionBarActivity { int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; private static final String TAG = AppWidgetConfigurationActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Util.logD(TAG, "---MYAPPWIDGET---"); // setResult(RESULT_CANCELED); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if...

Android homescreen Widget - Search

java,android,android-widget,android-softkeyboard

A TextView does not accept user input. A TextView is a label, for output. In an activity, you can use an EditText for user input. EditText is not supported in an app widget. Hence, to your question: I was wondering if it was possible to create a Android HomeScreen widget...

Best way to update Android widget exactly at time?

android,android-widget

my solution, based on AlarmManager: public class Widget extends AppWidgetProvider { public static String ACTION_AUTO_UPDATE_WIDGET = "ACTION_AUTO_UPDATE_WIDGET"; @Override public void onEnabled(Context context) { super.onEnabled(context); Intent intent = new Intent(Widget.ACTION_AUTO_UPDATE_WIDGET); PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0); Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 1); AlarmManager...

Styling ListPopupWindow widget

android,android-widget,android-styles

You should define a listPopupWindowStyle for your App's theme. <style name="AppTheme" parent="..."> <item name="android:listPopupWindowStyle">@style/MyListPopupWindow</item> </style> <style name="MyListPopupWindow"> <!-- attributes you want go here --> </style> ...

Widget not appearing in widget list

android,android-widget,android-appwidget,appwidgetprovider

It is an issue about the values you set in gulp_widget_info.xml for android:minHeight and android:minWidth. Try to set a smaller values and the widget should appear in the launcher's widget list: <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/layout_widget" android:minHeight="40dip" android:minWidth="40dip" android:updatePeriodMillis="86400000" android:widgetCategory="home_screen" android:resizeMode="none" /> I tested this settings in my phone with Google Now...

Is every object destroyed when widget is refreshed?

android,android-widget

Your process can and usually will be terminated between updates of the app widget. The new process will not have any of the static data members from the old process.

Rotate and scale a view based on one handle in Android

java,android,android-widget,android-imageview,android-view

In case you need to resize and rotate image simultaneously using one handler icon, some trigonometrical calculations should be performed. It is not so difficult to calculate angle by which image should be rotated, based on its initial angle and angle, by which the vector, that connects center of image...

How do I access the extras from an intent in RemoteViewsService?

android,android-intent,android-widget

i think your intention is to set the "widget_id" in widgetProvider and getting in RemoteViewsService class once try this Intent.putExtra(name, value) //set the data intent.getIntExtra(name, defaultValue)//get data ...

Giving each widget unique data

android,android-intent,widget,android-widget,android-service

This is a really common issue -- I suspect most widget developers have run into this. The second half of the overview for PendingIntent explains that, as you found, changing only the extras in an intent does not cause Android to make a separate PendingIntent: http://developer.android.com/reference/android/app/PendingIntent.html As the doc says,...

How to scale a view in android using a handle?

java,android,android-widget,android-imageview,android-view

So... The main problem is that getRawX() and getRawY() methods of MotionEvent provide absolute screen coordinates, while getX() and getY() provide layout coordinates. Coordinates thus differ on heights of progress bar and status bar, so when obtaining touch coordinates, we should recalculate them relatively to layout. dragHandle.setOnTouchListener(new View.OnTouchListener() { float...

How I can determine which text is selected in EditText? [duplicate]

java,android,android-studio,android-edittext,android-widget

Try this: int startSelection=et.getSelectionStart(); int endSelection=et.getSelectionEnd(); String selectedText = et.getText().substring(startSelection, endSelection); See this question: Android - get selection of text from EditText...

Multiple PendingIntents for a single widget

android,android-widget,android-pendingintent

I think my answer (here) to another question can help you. If you need more information or something is not clear don't hesitate and ask. Here is only a part of mentioned answer: // set action buttonOneIntent.setAction(BUTTON_ONE_CLICKED); buttonTwoIntent.setAction(BUTTON_TWO_CLICKED); buttonThreeIntent.setAction(BUTTON_THREE_CLICKED); buttonFourIntent.setAction(BUTTON_FOUR_CLICKED); // ...... ...

Widget click not responding

java,android,android-widget

here you are setting click pending intent for the appwidgetId, but that should be view id. RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); views.setOnClickPendingIntent(appWidgetId, pendingIntent); like: if the id of a Button is R.id.button1. which is in widget layout if you want to set click listener to that button. then that...

Android Home screen animation using widget

android,android-widget,android-animation,android-wallpaper,daydream

This can be done in three ways: A Widget A Live Wallpaper A Daydream Its even possible to create an app that has all three of these features and offers the user the option of using one or more of them simultaneously....

Change widget contents when a screenshot is being taken

android,android-widget

Yes you can! In your widget service, register a BroadcastReceiver with the intent android.intent.action.SCREENSHOT. It will trigger out every time you make a screenshot. Then execute your method there to hide the data or change the widget at your taste.

Advantage and disadvantage of CardView

android,performance,android-layout,android-widget,android-cardview

Advantage of Cardview is definitely its default implementation of the shadow and the rounded corners, in simple words Cardview is just a FrameLayout with shadow and rounded corners. You can do almost the same stuff with a Cardview that you can do with a Framelayout(as Cardview extends FrameLayout). The Cardview...

Why are these state variables in my AppWidgetProvider's onReceive null?

java,android,android-widget,android-appwidget

Your process may be terminated in between invocations of onReceive(). If you wish to hold onto data from a BroadcastReceiver, such as an AppWidgetProvider, do so using some persistent data store (database, SharedPreferences, or other sort of file). Static data members are only a cache, nothing more.

Programming functionality for an android app widget

android,android-widget

Intent is not needed to turn on the flashlight as it will always take you somewhere in activities or actions. The simplest thing to do is make your switchOnTheFlash() function static like this - public static void switchOnTheFlash() { // Your Function } and Now you can call this function...

Compare last text of a TextView with new, updated one, in android home widget using AsyncTask?

android,android-asynctask,android-widget,android-textview,android-pendingintent

You can use static int field where you can store last value: private static int lastValue1 = -1; // you can use other initial value private static int lastValue2 = -1; You can use it then, for example: if( lastValue1 < xv.getFieldValue1() ) { lastValue1 = xv.getFieldValue1(); views.setTextViewText(R.id.textView1, xv.getFieldValue1()); }...

runOnUiThread inside a widget

java,android,android-widget,ui-thread

I've already tried to use a Thread in onUpdate function That is not a very good idea. Your process can be terminated before your work completes. Instead, create an IntentService that does the network I/O and updates the app widget via an AppWidgetManager. the problem is that I can't...

Calling handler.removeCallbacks from onDeleted method in a widget throws a nullpointerexception

java,android,nullpointerexception,android-widget,android-handler

The problem is that you can't depend on the same instance of your widget being called by Android each time, and so keeping non-static fields in your widget provider is a problem. An easy solution would be to use static fields for handler and runnable. It looks like some of...

Android simple widget to show image into ImageView

android,android-widget

My problem resolved , i must be change second constructor as : public CIconButton(Context context, AttributeSet attrs) { super(context, attrs); } to: public CIconButton(Context context, AttributeSet attrs) { this(context, attrs, 0); } this call last this class constrctor...

Android control widget layout

android,android-layout,android-widget

Regarding to your issue I searched a little bit deeper. See: https://developer.android.com/guide/topics/appwidgets/index.html These are the classes which you can use with an appwidget to implement in your layout there is no such thing like a toggle button, but an imagebutton which I think us exactly what Google is using for...

How to declare a widget properly in the manifest?

android,android-widget

Your manifest should look like this to receive the Widget Update <receiver android:name="com.example.app.provider.CustomAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /> </receiver> And the Widget Provider resource xml should look something like this <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"...

Android Widget destroyed on orientation change

android,android-widget,super

What you are trying to do works for an Activity but not for a BroadcastReceiver. An AppWidgetProvider is a BroadcastReceiver and doesn't have the methods you are trying to override (onSaveInstanceState, onRestoreInstanceState). If you add the @Override annotation to the methods it tells you The method xyz() of type YourWidgetProvider...

Can't access DatePicker.ValidationCallback in my code

java,android,datepicker,android-widget

That was introduced around API version 21. If you MinSDK is lower you won't have visibility to that feature. However I just tested this by creating a sample project from scratch setting the min/max SDK to 22 and I still don't have visibility to that method. Potentially this is a...

Android Homescreen widgets without Java

android,cordova,android-widget,android-appwidget,kivy

You can interact with java from python using pyjnius (a kivy subproject, but it doesn't depend on kivy and can be used without it), including on android calling the apis to create and position native android widgets. For instance, kivy-gmaps is a kivy application that displays and controls a native...

In an activity, if the activity is paused and then invoked with an intent, getIntent() returns the old one

android,android-intent,android-widget

This is exactly why onNewIntent() exists: it is called: when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it. An...

Android Widget Update service, multiple onclick listeners

android,android-intent,android-widget,android-service,android-broadcast

I don't have enough reputation to comment your post, so my answer is only for getting more information from you and showing you a simple example how to add an action for AppWidget button. If you accept my answer I will help you more. By the way you didn't provide...

How to change selection color of tab host

android,tabs,android-widget

Just as an example, you can look into resources of android-sdk, Suppose, go to : android-sdk-windows\platforms\android-19\data\res\drawable and look at file tab_bottom_right.xml <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/tab_press_bar_right"/> <item android:state_focused="false" android:drawable="@drawable/tab_selected_bar_right"/> <item android:state_focused="true"...

Android Widgets w/ AdapterViewFlipper - Pending Intent Template does not get filled in with extras

android,android-layout,android-intent,android-widget

I was able to fix the issue by removing the extra in the pending intent template. Putting that extra there in the Template blew away the bundle of extras set by the adapter. //pI.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); remoteViews.setPendingIntentTemplate(R.id.widget_flipper, PendingIntent.getActivity(context, 0, pI, PendingIntent.FLAG_UPDATE_CURRENT)); Only place extras in the bundle set with setOnClickFillInIntent(). ...

Android Widget+Service

android,android-widget,android-service,android-broadcast

Create a custom Intent Action and set it as PendingIntent to the widget item ( button in your case) Intent intent = new Intent("com.example.app.ACTION_PLAY"); PendingIntent pendingIntent = PendingIntent.getService(context.getApplicationContext(), 100, intent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_layout); remoteViews.setOnClickPendingIntent(R.id.bPlay, pendingIntent); Then, change your manifest to handle the Action passed in PendingIntent <service...

Why does AppWidgetManager update Intent of all RemoteViews for Widgets?

android,android-intent,widget,android-widget

Pass a unique int as the first flag (second parameter) of the pendingIntent, preferably widgetID. PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), uniqueID, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); This will cause android to not override the existing pendingIntent, but create a new one. Here's a link to a different post with a similar problem. ...

Android widget update via service, that is doing http requests

android,android-widget,android-service

problem is that widget is not reachable from the post execute async task. It does not need to be. onPostExecute() can get an instance of AppWidgetManager via getInstance() and call updateAppWidget() on it....

The difference between LayoutInflater.inflate and findViewById

android,android-widget,layout-inflater,findviewbyid

What is the difference... The first one is retrieving an existing widget within your activity. The second one is reading in an XML file and is creating new widgets. The second one is also somewhat buggy, in that you infrequently want to use LayoutInflater.from() (you typically use getLayoutInflater() on...

Best control to be used as dropdown list in android

android,android-widget

You can always use expandable list view there are many examples online that could help u to create it much more flexible than a spinner and it looks elegant and easy to use, it also show the user directly what is used for by just giving it a look and...

Update ListView Widget with Application

android,listview,widget,android-widget

put this code in your application where you are updating content. AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int appWidgetIds[] = appWidgetManager.getAppWidgetIds(new ComponentName(context, WidgetListProvider.class)); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listViewWidget); ...

Android transparent property does not work on Android 4.1.1

android,android-layout,android-widget

Setting background as transparent is working api level 4.0 onwards add below line in your xml android:background="@android:color/transparent" or Try some thing like this <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/transparent" /> <stroke android:width="3px" android:color="#FFF" /> </shape> ...

creating persistent search bar in android

android,android-widget,android-ui

there is a library called persisten search which look likes google now, google play etc. have a look at it: https://github.com/Quinny898/PersistentSearch

AppWidget with collection - can`t run Config Activity when clicking on widget

android,android-widget,android-pendingintent,android-appwidget

After some investigation I came to a conclusion that if I use collection in appWidget and want to open Config Activity tapping on whole widget container that the best practice is using setPendingIntentTemplate method, even if you dont't want to handle item click but the whole list instead (list container)....

Android custom-view - java.lang.RuntimeException android.view.InflateException

java,android,android-widget,custom-view

Make your TAG class static. Since it is an inner class, if you make it non-static, then the compiler adds a hidden reference to the outer Activity class. That is why you are getting a NoSuchMethodException. public static class TAG extends View { public TAG(Context context, AttributeSet attrs) { super(context,...

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event

android,android-edittext,android-widget,contextmenu

Solution: Override isSuggestionsEnabled and canPaste in EditText. For the quick solution, copy the class below - this class overrides the EditText class, and blocks all events accordingly. For the gritty details, keep reading. The solution lies in preventing PASTE/REPLACE menu from appearing in the show() method of the (non-documented) android.widget.Editor...

Trouble with my widget service

android,android-widget,android-service,android-broadcast

There seem to be 2 issues in your UpdateWidgetService.getView() method. 1) You register a click listener on your widget with the following code: // Register an onClickListener Intent clickIntent = new Intent(this.getApplicationContext(), MyWidgetProvider.class); clickIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds); When the widget is clicked, it will broadcast an intent for your MyWidgetProvider class...

android widget or app for reliable repeated tasks

android,android-widget,android-service

You have to work with AlarmManager for reliable, long term scheduling. So it will work even on idle mode. No need to keep the aplication alive and powermangement locks to make the device active. it will drain your batt. and all other resources. instead you can apply a wakelock when...

What does android:progressTintMode, android:secondaryProgressTintMode and android:progressDrawable do?

java,android,android-widget,progressdialog,android-progressbar

the progressDrawable defines the shape and color of the progress bar, then the progressTintMode defines how the progress bar will fill up. E.G. if you want to have a progress bar with rounded corners, then the progressDrawable will define the shape with rounded corners. You would then use "src_in" as...

Android Appcompat v21 - use old spinner style

android,android-widget,android-spinner,appcompat

You can simply set the Style of the Spinner to Widget.Holo.Light.Spinner Example <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.Holo.Light.Spinner" /> This will give you the old Spinner-Style back though there are two drawbacks: This solution only works with API-Level 14 and up (no that big of a deal) The appearance of the...

android widget starts an new activity

android,android-activity,android-widget,android-pendingintent

sending broadcast when you widget clicked, will help you to the problem of starting activity. you can use the getBroadcast() method of PendingIntent. public static PendingIntent getBroadcast (Context context, int requestCode, Intent intent, int flags)...

ImageViews on Homescreen Widget slow the Homescreen performance

android,memory-management,android-widget,imageview,homescreen

Solved this issue by resizing the images, making them smaller.

Android ProgressBar setIndeterminateDrawable()

android,android-widget,android-drawable,android-progressbar

Looking at the ProgressBar source code, it looks like setIndeterminateDrawable doesn't call updateDrawableBounds so you'll have to manually set the bounds on your new drawable.

App Widget Provider Crashing

java,android,android-widget

Replace: for (int i : appWidgetIds) { int appWidgetId = appWidgetIds[i]; with: for (int appWidgetId : appWidgetIds) { If you use the enhanced for syntax for iterating over a collection, you are iterating over the values of the collection, not array indices....

Trouble with android.widget.PopUpMenu

java,android,android-widget,popupmenu

Thanks to a clue from kEN, I have resolved this issue. I was running the app on an emulator with 2.2.3 when I needed to run it on 4.0+. Simple solution was to set up a new emulator, restart eclipse and everything worked!

Individual Pending Intent for each button on widget

android,android-intent,widget,android-widget

When you create your PendingIntents, you are reusing the same one over and over again. You want to have 3 PendingIntents active simultaneously. To do that you need to make sure that the parameters to the call to PendingIntent.getBroadcast() ensure that you will get a unique PendingIntent. The easiest way...

How to save the configuration of widgets

android,android-widget,android-appwidget

App Widget configuration Activity is an optional Activity that launches when the user adds your App Widget and allows him or her to modify App Widget settings at create-time. In the configuration Activity you can set up update frequency, text in TextView, background drawable of the widget and so on...

Loading an ImageView from an URL in a widget

android,bitmap,imageview,android-widget

First, replace the AsyncTask with an IntentService. There is every possibility that your process will be terminated before you get your work done. Have your AppWidgetProvider delegate to the IntentService. Second, use better code for downloading the image than what you have, as it will not deal well with typical...

How do I start an Activity when Widget is clicked?

android,android-widget

Yoy can put widget in your application. In your manifest file: <receiver android:icon="@drawable/icon" android:label="Example Widget" android:name="MyWidgetProvider" > <intent-filter > <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_info" /> </receiver> ...

How do you avoid more than one instance of an Activity when created from widget?

android,android-activity,android-widget,instance

What about using launch mode flag: android:launchMode="singleTask" You activity should look like: <activity android:name=".YourActivity" android:launchMode="singleTask" android:configChanges="orientation|screenSize" > ...

Programmatically line up two views at a corner

java,android,android-widget,android-imageview,android-view

You are correct in your assumption. Translation does not affect the bounds of the view. However if you calculate the position offset (delta) of the second view from the first at the beginning of the gesture, you can translate both views at once. Here's a working sample that you can...

Spinner click effect can't include the view inside

android,android-layout,android-widget

Instead of: convertView.setBackgroundColor(group.getColor()); add to it selectable drawable: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:backround="@drawable/some_selectable_drawable> And this is what drawable should be alike: <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/button_sel"...

Android widget send Data to onRecive via intent

android,android-intent,android-widget

I think that this append because you override everytime the intent storage in PendingIntent because the requestCode doesn't change. PendingIntent pendingIntent = PendingIntent.getBroadcast(context,**0**, intent, PendingIntent.FLAG_UPDATE_CURRENT); If you want set more PendingIntent you must change the requestCode (0 in your case) Try PendingIntent pendingIntent = PendingIntent.getBroadcast(context, cnt, intent, PendingIntent.FLAG_UPDATE_CURRENT); In this...

Unable to launch app on device

android,android-widget

Your console message shows that your apk is isntalled sccuessfully on the device. Now the question is why it is not getting launched? To launch any application, it should have at least one activity with action as main and category as launcher. <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>...

Android: Button - Swapped rounded Corners APIs 8 till 12 - How to fix it?

android,android-widget,android-view,android-xml,android-button

I solved it by adding a "drawable"-folder in res/ and by moving the xml-file with the swapped values in drawable-hdpi to the "drawable"-folder. So at the end your folder structure should look like this: - drawable (xml-file with swapped values) - drawable-hdpi - drawable-ldpi - drawable-mdpi - drawable-v12 (xml-file with...

WidgetHost Activity to Fragment

android,android-fragments,android-widget

So the exception is quite straightforward. You must use smaller numbers than you use when calling: startActivityForResult(pickIntent, R.id.REQUEST_PICK_APPWIDGET); Create your own int constants and use it: public static final int CODE_PICK_APPWIDGET = 1; startActivityForResult(pickIntent, CODE_PICK_APPWIDGET); ...

HomeScreen Widget - Updates Only When New Instance

android,android-widget

The issue is that I was not updating the right ID for some reason... Either way I am now updated based on class. like the below ComponentName projectWidget = new ComponentName(context, TrinityWidget.class); appWidgetManager.updateAppWidget(projectWidget, views); ...

What is the name of this “spinner like” control?

android,android-widget

Found out it was a NumberPicker control. NumberPicker transportProviderPicker = (NumberPicker) findViewById(R.id.pkr_transport_provider); transportProviderPicker.setValue(0); transportProviderPicker.setMaxValue(0); transportProviderPicker.setDisplayedValues(transportProviders); ...

Text in widget not changing

android,android-layout,android-widget,android-textview

Never use a Timer in a widget. An AppWidgetProvider is a BroadcastReceiver, it's meant to remain active only for a short amount of time to handle the Broadcast Intent it received, then it can be destroyed at any moment after the broadcast has been handled and the onUpdate() method returns...

How to start an activity in a widget button

android,android-widget,android-appwidget

Change PendingIntent.getBroadcast(getApplicationContext(), 0, loginIntent, Intent.FLAG_ACTIVITY_NEW_TASK) into PendingIntent.getActivity(getApplicationContext(), 0, loginIntent, Intent.FLAG_ACTIVITY_NEW_TASK); ...