I have lower-intermediate experience with HTML and C++, but not Java. I'm getting my first android phone soon, and I'm looking to make a widget or two for it.
One widget will just be an analog clock, but I want it to have a custom look. From what I've seen, there's a standard analog clock in the SDK, but I've never seen anyone change it or use their own design. The best way I can think of to do it would be to have the clock face be static and the hour and minute hands be images on top of the clock face and rotate a certain number of degrees about the center based on the time. Is that a good way to think about doing it or no?
The other widget seems a bit more complicated. The 4 input variables will be time of day, day of week, calendar date, and moon phase. However, there will be 7 "moving pieces" or "outputs" based on those 4 variables. 3 dealing with the moon phases, 2 dealing with time of day, 1 dealing with date, and 1 dealing with day of week. How doable is this?
Also where is the best place to learn how to do the things required quickly? I've already found thenewboston's video series on YouTube which everyone seems to be talking about, but there are 159 lessons prior to getting to widgets, and the lessons are cumulative.
First learn Java which will be easy for you as you already know parts of C++. I learned Java using the Head's first Java book.
And for specific android things: The tutorials by Vogella (Google him) are great.
Btw, you will not need all 159 lessons before the widgets.
That's for you http://forum.xda-developers.com/showthread.php?t=1703238
PdroidAndroid said:
That's for you http://forum.xda-developers.com/showthread.php?t=1703238
Click to expand...
Click to collapse
Sweet find. Thank you very much. This will be perfect for me to get my feet wet.
Xperia Z
I'm using this block of code to launch the default Alarm Clock when tapping on my clock widget.
Code:
public Intent getAlarmPackage(Context context)
{
PackageManager packageManager = context.getPackageManager();
Intent AlarmClockIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
String clockImpls[][] = {
{ "Standard Alarm", "com.android.alarmclock",
"com.android.alarmclock.AlarmClock" },
{ "HTC Alarm ClockDT", "com.htc.android.worldclock",
"com.htc.android.worldclock.WorldClockTabControl" },
{ "Standard Alarm ClockDT", "com.android.deskclock",
"com.android.deskclock.AlarmClock" },
{ "Froyo Nexus Alarm ClockDT",
"com.google.android.deskclock",
"com.android.deskclock.DeskClock" },
{ "Moto Blur Alarm ClockDT",
"com.motorola.blur.alarmclock",
"com.motorola.blur.alarmclock.AlarmClock" },
{ "Samsung Galaxy S", "com.sec.android.app.clockpackage",
"com.sec.android.app.clockpackage.ClockPackage" } };
But this is not working with the Sony Xperia Z. Any suggestions?
Related
So I'm programming a application with a widget.
On my widget I got a button that starts an activity with a PendingIntent. This activity that's getting launched isn't my main activity.
Now when I'm doing it like this I get a Strange problem:
- Launching App as normal over appdrawer -> main activity opens up
- Pressing Home or Back button
- Add widget to homescreen
- Click button on widget -> nothing happens!
If I force stop my application before adding the widget to the homescreen, a click on the button on the widget opens up the activity like it should. Now I can also launch my main activity, pause it and the widget still works. So the widget only fully works if I my application isn't running in the background while adding the widget.
Has anyone of you experienced something like that?
Thank you in advance!
it is really dependent on how your onClickListener is added to the button. ive had problems where the first widget i create doesnt have the onClickListener attached but the second one will. do you mind sharing your code that you use to attach the onClickListener?
here is mine:
Code:
/** Called when the activity is first created. */
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Toast.makeText(context, "onUpdate()", Toast.LENGTH_SHORT).show();
//super.onUpdate(context, appWidgetManager, appWidgetIds);
//attach an onClick intent to the layout
final Intent onClick = new Intent(context, GITextCloud.class);
onClick.setAction(LAUNCH_GMAIL_GAPPS);
PendingIntent onClickPending = PendingIntent.getBroadcast(context, 0, onClick, 0);
RemoteViews rv1 = new RemoteViews(context.getPackageName(), R.layout.gitc_html);
rv1.setOnClickPendingIntent(R.id.full_widget, onClickPending);
for (int appWidgetId : appWidgetIds) {
appWidgetManager.updateAppWidget(appWidgetId, rv1);
}
}
My code is really almost the same. Just that I need PendingIntent.getActivity instead of getBroadcast.
what flags do you set for your intent? cause if your activity is already running and thats when the button wont work it could be that you need a Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT or some other flags in the PendingIntent
try setting onClick.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) or what ever your Intent is called. i think the fact that your widget and your app are going to be seperate programs means they must start in different threads. cause not all widgets need an Activity running to function
I got it now! I somehow managed to screw up my remoteviews, they didn't got updated properly.
Anyway, thanks a lot for your answers
I have multiple widgets provided by one app, and thus multiple classes that extend AppWidgetProvider. The idea is that every widget contains a Button, which starts a Service when pressed. This Service runs a bit of code and then stops. Now for the problem: for example, I have a Widget1a and a Widget1u. These widgets look like each other, but each widget does a slightly different thing. If I place a Widget1a on the homescreen and press it, a Service is started and the code that this Service should run is run, as it should be. Now I place a Widget1u on the homescreen, and suddenly Widget1a stops working and doesn't do anything when I press it. If I place a second Widget1a on the homescreen both Widget1as work again, but now Widget1u is disabled and doesn't respond when I press it. In short: it seems that at any particular time only one type's code works when it is pressed (and if there are multiple instances of the same type on the homescreen all of these instances will work, but no instances of any other widget of my app will do anything when pressed).
The code in the AppWidgetProvider of each widget is pretty basic. It merely contains an overrided onUpdate-method. It creates an Intent to start a Service that I previously created, this is then used to create a PendingIntent which is used by setOnClickPendingIntent to make sure it can be activated by a Button in the widget. Each widget makes, when its Button is pressed, a slightly different Intent so that a certain Service is executed slightly differently. So this only works for the instances of 1 widgettype at a time, namely those of which an instance was added to the homescreen most recently.
Why do all my app's other widgets stop working when I add a widget of a different type to my homescreen? Does anyone know more about widgets or how I can make sure that each widget keeps doing its job when I add a new one from the same app to the homescreen?
Here is the onUpdate method of one of my AppWidgetProviders for one of my widgets. All widgets operate similarly and I know I used a lot of copypasting which is a bad programming habit but it didn't seem to really want to work otherwise.
Code:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// Create an intent to launch the service
Intent serviceIntent = new Intent(context, SendService.class);
//I just put some extra data here to be used by the Service which wil eventually get this Intent and thus the data inside
serviceIntent.setData(Uri.parse("uri::somethingrandomandunique"));
serviceIntent.putExtra("Lamp", "1a");
// PendingIntent is required for the onClickPendingIntent that actually
// starts the service from a button click
PendingIntent pendingServiceIntent =
PendingIntent.getService(context, 0, serviceIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
// Get the layout for the App Widget and attach a click listener to the
// button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget1a);
views.setOnClickPendingIntent(R.id.button1a, pendingServiceIntent);
// super.onUpdate(context, appWidgetManager, appWidgetIds);
ComponentName componentName = new ComponentName(context.getPackageName(), Widget1a.class.getName());
appWidgetManager.updateAppWidget(componentName, views);
}
So what am I doing wrong?
At it's core... a simple clock app. I'm firing off updates scheduled on each second. On each second, I read the time, then display the time. This is not complicated. And it works, just fine, on my phone. Tick, tick, tick and it looks like a clock. Why wouldn't it, right?
Ok, so the same code on the nook doesn't update regularly. Here's an early video:
http://www.youtube.com/watch?v=URRrYhumt1Y
You can see there's a "double beat". It's like every other update gets displayed for maybe 1.5 seconds. So the overall rate doesn't change, it's still two updates in two seconds, and no updates are missed.
These are being done with a regular myView.setText(), no fancy graphics or anything.
Now, here's more interesting data. If I run the updates twice as often, or five times as often, it changes nothing. I assume the screen/OS is internally detecting no pixels have changed, and so it does nothing. However, if I add, to a totally different view on the screen, an area where I'm toggling from some text to no text (from " " to "+", in actuality, so, a blinking plus sign) AND I run everything at five times a second then the seconds area updates with a steady one hertz beat, just like you would expect from a clock.
Additionally, if I run the code so it only updates every other second, it will click along very predictably at every other second. So it's not a "some code problem with every other update".
I wonder if there's some internal timer in the OS watching for screen updates, and managing them? Perhaps "pushing" the display with a toggling update every 200ms keeps it active and within some timeout limit?
Or are there some nook-specific calls on this?
Cheers,
Anders
I believe that some of the super-duper fast-mode or-whatever-you-call-it throws away some screen updates.
Are you using such a thing or a kernel with such a thing?
No, I'm not attempting any speedy-screen stuff in this code. In the video you can see the grey in the bar, so I'm not in any kind of a 1-bit mode. Because really, one update a second should be no problem.
But if it was throwing away an update... why would the update show up half a second later? I would expect it to skip displaying that second entirely, and so jump to the next.
NoRefresh is installed on this device, but not set to start at boot (and honestly, I don't think I've actually gotten NoRefresh working yet, busy with other things). But I'll uninstall it to be sure and retest.
Is it possible some kind of low-power mode / sleep mode is kicking in? It wakes up half a second later, realizes it has an update, stays away for the next half second, makes the NEXT update (on time) then goes back to sleep after a 0.9ish seconds?
Anders
Yep, even after uninstalling NoRefresh, and rebooting, the behavior is the same. So that's definitely not related.
And running the normal updates to the screen at both 2Hz and 5Hz have the same result, so it's not related to the number of times the updates are called.
Anders
Here's an interesting video... watching the ADB output click along at a clean 1Hz, and the screen updates clearly not synced with the actual writes to the screen.
http://www.youtube.com/watch?v=sL299EUH3T0
Again, all on "stock" system, no special video modes / refresh / magic enabled.
Anders
Actually, I have run into this.
There's no documentation on modes or theory of operating a frame buffer for eInk.
I ran into this on the time display on my audio recorder app.
I ended up using a DL region in my app.
I'll have to look closer into how bad it looks without that.
Are those numbers a TextView or an ImageView?
If it isn't a TextView try one to see if it works better.
There may be slowness in caching/using images.
More questions:
Are you using Timer & TimerTask?
Are you using runOnUiThread?
I wrote a demo app that counts.
It works fine by itself on stock 1.2.1
Renate NST said:
Actually, I have run into this.
There's no documentation on modes or theory of operating a frame buffer for eInk.
I ran into this on the time display on my audio recorder app.
I ended up using a DL region in my app.
I'll have to look closer into how bad it looks without that.
Click to expand...
Click to collapse
DL region? Not familiar with the acronym.
Are those numbers a TextView or an ImageView?
Click to expand...
Click to collapse
It's a text view. Just a big blocky TTF font. (Although the same issue is present using stock fonts).
Are you using Timer & TimerTask?
Are you using runOnUiThread?
Click to expand...
Click to collapse
Using scheduled handlers. They are triggering normally, since A] the ADB output is firing at nice one second intervals, and B] the SystemClock.uptimeMillis shows a 1000 count between each wake up. It's off by one or two millis which is understandable given that it's not a hard-realtime system.
But I'm not familiar with Timer and runOnUiThread, so I'll google those and do some reading.
(In the below code, the "nookPing" area is a tiny spot where I just toggle some pixels. If I do this and run the whole thing at faster than 1Hz, the seconds digit updates on schedule. Turn off this toggling, (which is in a totally unrelated textarea) and back to wonky updates, even at the same update rate. )
Code:
// //////////////////////////////////////////////////////////////////////////////////////////////////
// The Tick task itself /////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
private Handler mHandler = new Handler();
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
Log.d(TAG, "---------------------Tick Called: " +String.valueOf(SystemClock.uptimeMillis()) );
Log.d(TAG, "---------------------");
updateTimeOnScreen();
scheduleNextScreenUpdate();
}
};
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Schedule next update /////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
private void scheduleNextScreenUpdate()
{
mHandler.removeCallbacks(mUpdateTimeTask);
mHandler.postAtTime(mUpdateTimeTask,UtilitiesTime.calculateNextScreenUpdateTime());
}
// //////////////////////////////////////////////////////////////////////////////////////////////////
// Show the time ////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////
static int nookPing=0;
private void updateTimeOnScreen() {
String hhmm;
int militaryhours,hour;
int minutes;
int seconds;
int tenths;
int milliseconds;
Calendar rightNow = Calendar.getInstance();
militaryhours=rightNow.get(Calendar.HOUR_OF_DAY);
hour=rightNow.get(Calendar.HOUR);
minutes=rightNow.get(Calendar.MINUTE);
seconds=rightNow.get(Calendar.SECOND);
milliseconds=rightNow.get(Calendar.MILLISECOND);
tenths=milliseconds/100;
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
if(true==settings.getBoolean("appSettingNookPingActive", false))
{
if(0==nookPing)
{
nookPing=1;
nookPingView.setText(".");
//nookPingView.setText(" ");
}
else{
nookPing=0;
nookPingView.setText(" ");
}
}
else{
nookPingView.setText(" ");
}
if(Configuration.ORIENTATION_PORTRAIT==getScreenOrientation())
{
if(1==MainActivity.appSettingMilitaryTimeFlag)
{
hhmm=String.format(Locale.US,"%02d:%02d",militaryhours, minutes);
}
else{
if(0==hour)
hour=12;
hhmm=String.format("%2d:%02d",hour, minutes);
}
}
else
{
if(1==MainActivity.appSettingMilitaryTimeFlag)
{
hhmm=String.format("%02d\n--\n%02d",militaryhours, minutes);
}
else{
if(0==hour)
hour=12;
hhmm=String.format("%2d\n--\n%02d",hour, minutes);
}
}
int secondsTens=seconds/10;
int secondsOnes=seconds%10;
secondsLeftView.setText(String.format("%d",secondsTens));
secondsRightView.setText(String.format("%d",secondsOnes));
hhmmView.setText(hhmm);
}
Hey guys,
I am not getting any response on Stack Overflow so I thought I would try here.
At this point I am suspicious that it is a Samsung device specific problem. A very basic app with just a single button produces the same issue on my S4 development device.
Here is me SO question:
I have a button on one of my fragments, that sits inside a relative layout.
It's a rather large button, and when I fat finger it I get a ACTION_CANCEL motion event rather than ACTION_DOWN (it works perfectly fine with finger tips). This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail.
Here is my onTouch implementation:
Code:
@Override
public boolean onTouch(View view, MotionEvent event) {
//debugging
Log.v("TOUCH EVENT", event.toString());
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mButton.getParent().requestDisallowInterceptTouchEvent(true);
//Do stuff...
return true;
} else if (action == MotionEvent.ACTION_UP) {
//Do other stuff...
return true;
} else if (action == MotionEvent.ACTION_CANCEL){
return false;
//Toast.makeText(context, "Your thumb is too fat.", Toast.LENGTH_SHORT).show();
}
return false;
}
Note that the button also uses custom background resources. I start an AsyncTask when the button is pressed and the background changes based on the progress of that task. I'm not sure if that has anything to do with the problem or not.
EDIT: I walked all the way up the View hierarchy to ViewRootImpl, and still no luck in calling requestDisallowInterceptTouchEvent() on it. Weird thing is this shows in the log when my button sticks:
Code:
08-26 11:06:15.287: D/ViewRootImpl(5428): [ViewRootImpl] action cancel - 1, s:31 s(atmel):-1.0 eccen:1.3333334
So obviously it seems that the action is either being cancelled before it even gets inside the ViewRootImpl or right after. How is this even possible?
Update: Still no progress on this... anyone?
masterjeff said:
Hey guys,
I am not getting any response on Stack Overflow so I thought I would try here.
At this point I am suspicious that it is a Samsung device specific problem. A very basic app with just a single button produces the same issue on my S4 development device.
Here is me SO question:
I have a button on one of my fragments, that sits inside a relative layout.
It's a rather large button, and when I fat finger it I get a ACTION_CANCEL motion event rather than ACTION_DOWN (it works perfectly fine with finger tips). This prevents it from registering the subsequent ACTION_UP (I assume the view's parent is taking over). I tried using the requestDisallowInterceptTouchEvent() method on the parent, to no avail.
Here is my onTouch implementation:
Code:
@Override
public boolean onTouch(View view, MotionEvent event) {
//debugging
Log.v("TOUCH EVENT", event.toString());
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mButton.getParent().requestDisallowInterceptTouchEvent(true);
//Do stuff...
return true;
} else if (action == MotionEvent.ACTION_UP) {
//Do other stuff...
return true;
} else if (action == MotionEvent.ACTION_CANCEL){
return false;
//Toast.makeText(context, "Your thumb is too fat.", Toast.LENGTH_SHORT).show();
}
return false;
}
Note that the button also uses custom background resources. I start an AsyncTask when the button is pressed and the background changes based on the progress of that task. I'm not sure if that has anything to do with the problem or not.
EDIT: I walked all the way up the View hierarchy to ViewRootImpl, and still no luck in calling requestDisallowInterceptTouchEvent() on it. Weird thing is this shows in the log when my button sticks:
Code:
08-26 11:06:15.287: D/ViewRootImpl(5428): [ViewRootImpl] action cancel - 1, s:31 s(atmel):-1.0 eccen:1.3333334
So obviously it seems that the action is either being cancelled before it even gets inside the ViewRootImpl or right after. How is this even possible?
Update: Still no progress on this... anyone?
Click to expand...
Click to collapse
Mmmh strange problem you've got there... Just an idea, maybe try to always return true in your onTouchEvent() method since you may be losing the event when an ACTION_MOVE event comes up and you return false. Other than that, could you show us your layout file? I doubt the change in background color has any effect on this, but it could be that some part of your layout is causing this.
SimplicityApks said:
Mmmh strange problem you've got there... Just an idea, maybe try to always return true in your onTouchEvent() method since you may be losing the event when an ACTION_MOVE event comes up and you return false. Other than that, could you show us your layout file? I doubt the change in background color has any effect on this, but it could be that some part of your layout is causing this.
Click to expand...
Click to collapse
Does anyone have a solution to this yet? More specifically, I think it's the Samsung's own implementation of ViewRootImpl that is causing this problem. I've been trying to figure out for a long time how to either pre-empt ViewRootImpl to intercept MotionEvents, or completely override ViewRootImpl. I found no success in either of these.
I also thought about reading from /dev/input/eventX directly, but this isn't feasible since it requires the phone to be rooted first. For myself it's ok, but if I'm writing an app for other devices that's not a solution.
Can someone from Samsung help?
Hello everyone ^_^
Ive been making zooper themes for some time, as well as Themer themes. What i would love to do now is to create an app that can install a zip file to a specific folder on the storage. I wish to make a Material themed app for installing the zip, that can show scereenshots or other shots which i use to display my themes. Also, I wish to include a link for the wallpaper for that specific theme. Ive scoured the internet a bit for this type of thing, and so far, ive been unable to find anything that would suit my requirement.
help would be appreciated a lot
PS, i havent done app developing or coding in a few years so you could say that im kinda noob to this now so guidance from scratch would be very helpful ^_^
You can use below code to create a zip and place it wherever you want.
Code:
private static void zipFolder(String inputFolderPath, String outZipPath) {
try {
FileOutputStream fos = new FileOutputStream(outZipPath);
ZipOutputStream zos = new ZipOutputStream(fos); File srcFile = new File(inputFolderPath);
File[] files = srcFile.listFiles();
Log.d("", "Zip directory: " + srcFile.getName());
for (int i = 0; i < files.length; i++) {
Log.d("", "Adding file: " + files[i].getName());
byte[] buffer = new byte[1024];
FileInputStream fis = new FileInputStream(files[i]); zos.putNextEntry(new ZipEntry(files[i].getName()));
int length;
while ((length = fis.read(buffer)) > 0) {
zos.write(buffer, 0, length); }
zos.closeEntry();
fis.close();
}
zos.close();
}
catch (IOException ioe) { Log.e("", ioe.getMessage());
}
}
And for the second one.
You can simple use intent to open your link in browser.
Intent n = new Intent(Intent.ACTION_VIEW , Uri.parse("link to your wallpaper"));
Sent from my A0001 using Tapatalk 2
Android Application Development Request
I am in need of some help I have a great idea for a new app that may change the face of advanced research. This will allow for the user to search all day and all night. While they are handling everyday life issues and events with family and what not. Yet still, allowing them to locate what they are looking for. Also will allow people with artifacts in there home. That the user may think is not worth anything yet it may be a goldmine. So instead of the user having to do research trying to locate these specific artifacts to see if they are worth money. This app will allow them to do advanced research all day with a touch of a button my idea is revolutionary when it comes to the advanced research that needs to be done. Please, I am looking for somebody to help me develop this app and bring it to life. So that I may present this idea to google for a possible sale. Thank you for your consideration ahead of time on helping me with this application.