Overriding Android Chronometer class - android

I want to override the android chronometer class. I want it to inflate a custom XML layout and to also have a quicker update interval.
I've found one that modifies the update interval from the default 1s to 0.1s on github.
But I want to do more and have imageViews or Buttons display the time instead of the default textView it uses. I haven't really done this before except for a recycle view, so some explanation would be nice.
My end goal is to have an efficient stopwatch with custom digits and display, like the one found on HTC one M7 in the default clock app or any Samsung phone. I also need it to run in its own Fragment and be able to handle orientation changes and the activities onPause() or onStop() without losing any time.
Would it be better to use Intent Service and a Results Reciever? if so how would i accomplish this?

Chronometer is good for certain extent, but instead of customizing it you can create your own custom layout and display the time based on your requirements using a handler which would be the best solution for your problem.Find the link below for example
http://www.shawnbe.com/index.php/tutorial/tutorial-3-a-simple-stopwatch-lets-add-the-code/

Related

Newbie in Android development. Implement several different processes in an activity

I'm begining to learn android development, and I'm trying to make an app just to learn the language and philosophy.
This app, has to show an image in the middle of the screen, a button below, and a chronometer in the right side. When the app starts, the chronometer has to begin a countdown. When the user press the button, a blur effect has to be applied to the image, and the seconds left to finish the countdown increase by 10.
I almost know how to program the blur efect to the image, the button press, and the countdown and increase by 10 whenever the button is pressed. But I'm not sure about putting all together.
As far as I know, it should be done by designing an activity, and putting inside the activity the image, the button, and another image or a set of changing images or text for the countdown clock. But as I advance in my studied, today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments. And I have found much complex programming fragments than activities.
So the question is: can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock or have I to make it with fragments?
Thank you very much.
today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments
To be blunt, either you either misunderstood what you read, or you are reading the wrong material.
can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock
Yes.
have I to make it with fragments?
No. It is possible that the whole UI might be a fragment, particularly if it might be shown alongside something else in some cases (e.g., a tablet) and not in others (e.g., a phone). And there is nothing stopping you from making that UI using several fragments, though that would be rather unusual.
As others have already conveyed, no need to go with fragments.. Activity wud suffice.. As far as putting it together is considered, I guess you need to learn more about layouts.. Layouts are the files which basically help you put things on UI as you want it to look like.. There are plenty of material available online for understanding layouts.. Happy learning.. :)

How to customize which items TimePicker shows?

I've been programming in Android just for a week now, so my philosophy might be a bit rigged from other IDEs. I am used to Visual C#'s style of dealing with components - just drag it on the screen, then choose possible preferences in its menu. That however doesnt seem to work here.
My problem: I am trying to make a simple countdown clock, with the user choosing the time through the timePicker. But for that, I need a different style of it than the default. Rather than choosing the "real" possible time, I would like it to have just minutes and seconds, sorted incrementally, so the user can choose "48 min, 9 sec" and press ok. How is this possible?
Thanks
Well, the TimePicker is meant for picking actual times... not quantities of time. So you can't do so using the TimePicker provided in the public SDK. You'll have to make your own custom view instead.
To do this, one thing you might consider trying is making your custom View extend TimePicker. Perhaps you could then override the appropriate methods to reach the desired behavior. It will require a bit of sifting through the source code on your part, however. I'm not 100% sure if it is possible either, but it seems like it should.

Switching back and forth between 2 layouts

I'm trying to make an application thats has blinking effect,
e.g. switching back and forth between 2 layouts, one is red and the other is blue for example.
(any layout has diffrent image in it)
When trying to switch fast between 2 activities or 2 fragments the application is crashing.
How can I programmatically change activity layout in a better way?
My personal reservations against blinking aside, you could change just the background color of your root layout with a timer.
You should just change the background color or the layout that is being displayed by the Activity.
Think about efficiency:
If you change layouts android will have to inflate the XML and its widgets and you will have to get handles to all these by querying and layout (ie findViewById). You can think of the first problem of this as refreshing a web page to change the color of an element instead of just rendering dynamically. You can think of the second part of this as not caching DOM handles and having to requery-ing the DOM every time you want to provide and action in JavaScript. Both are bad practice.
Or, you could just change the background of the current layout every X seconds, minutes or whatever you are trying to do. There are many ways to do this - the AlarmManager, or start a Thread with a timeout - or better yea, start a new Thread that will post a runnable back to the main thread to change the background color - then sleep the auxiliary thread for X seconds and repeat the loop.
The second idea is not only good practice - but you are using the SDK framework correctly.
Good Luck!

Android increase gridview click speed

I'm using a GridView in Android. I need to register as many clicks as possible, but gridview reacts to clicks very slow, even if there is no acutal code to execute... is there a possibility to speed this up?
Depending on the application, you might want to code up a custom component.
I had a similar problem and replaced the old gridview with a component based on TableLayout. It was more work, but was worth it in the end (faster and more flexible).
Here's a handy article to get you started:
http://developer.android.com/guide/topics/ui/custom-components.html

Android - Activities vs Views

I am working on an Android app that has multiple screens the user will need to navigate between and I am curious what the best practices are when switching between those screens. I am torn between creating a new Activity for each screen and simply changing the view (setContentView(R.layout.whatever)). The screens all share at least some variable values so I'm leaning toward changing views and using class level variables, but I'm worried a single activity could become very large and confusing with logic for multiple screens in a single file. I'd like to keep the code clean and separated, but I also don't want to be passing several variables around between views if that isn't needed.
Being new to Android development, I'm hoping some more experienced members of the community could share their thoughts and let me know how best to handle it.
Thanks!
Note:
I wasn't planning on using a viewflipper. My thought was to use a button click event and then call setContentView() to a new view for the page I wanted to bring up next.
Example: My application starts up using R.layout.main as it's view. User clicks the Help button and it calls a method that runs setContentView(R.layout.help); to display the help screen as opposed to switching to a help activity.
You should use an activity per screen as this will make the best use of the framework and allow the OS to selectively kill off screens if things get tight.
If you have a single activity and resources get tight the OS has two choices; kill everything or kill nothing, and if the user is not using your app then it's most likely it'll kill everything.
If you use an Activity per screen the OS can kill off some of the screens the user hasn't visited for a while, whilst still allowing others to remain active which allows the user to go back to them quickly.
As for sharing variables and values, you could use the SQLite database or SharedPreferences stores for passing them around if they are widely shared, or use the putExtra methods in Intent if they're only of use from one screen to the next.
If you have variables that you will reuse make a base class for them, that you will extend.
This can be a your custom activity that extends Activity.
As far I can tell you have to create separate activities for each views, only a few situation can be handled by viewflippers.

Categories

Resources