commonsware

Why do recipes promote overriding getItemViewType and getViewTypeCount when it doesn't seem necessary?

倖福魔咒の 提交于 2019-12-04 04:32:32
I've been working through the Commonsware Android Programming Tutorials and in tutorial 5, extra credit 2, the challenge is to use multiple layouts for displaying rows in a ListView depending on the "type name" of the object (a Restaurant's "type" attribute, which is a String). As such, it suggests overriding getItemViewType and getViewTypeCount in a custom ArrayAdapter. In addition, the android docs and other online recipes or blog posts suggest the same. In this situation, following this recipe and overriding those two methods works fine but results in redundant logic based on inspecting the

What's the difference between passing this vs. ClassName.this from an event handler when passed to Intent constructor?

痴心易碎 提交于 2019-12-03 12:57:24
In the earlier Android Programming Tutorial, page 192, we see an implementation of LunchList#onOptionsItemSelected . Within this implementation we see two Intent s passed to startActivity : one whose constructor is passed LunchList.this , the other whose constructor is passed this . What's the difference? See lines 78 - 91 here . Note how onOptionsItemSelected is not declared within an inner class. In Android/Java does the value of this change within the context of event handlers or function binding via reflection? Could both Intent instances be passed this ? In Java, this refers to the

Wake Service directly from AlarmManager

谁说我不能喝 提交于 2019-11-29 19:14:25
问题 In the https://github.com/commonsguy/cwac-wakeful demo, the OnAlarmReceiver (a BroadcastReceiver) onReceive() method is called in response to an Alarm. The onReceive() method starts the Service. There are two Intents used, one received by the BroadcastReceiver and one by the Service. This seems more complicated that it needs to be, why not just have the Service receive the Intent from the AlamManager? I understand that the Phone is guaranteed not to sleep while onReceive() is executing i.e.

how to keep an Intent service running

随声附和 提交于 2019-11-29 09:42:02
问题 I have two examples of Intentservice. One is the Download example in the commonsware book. the other is at http://www.vogella.com/articles/AndroidServices/article.html#servicecommunication_handler. Both of these examples show the service executing a finite task and they both apparently destroy themselves by running to the end of the scope of the onHandleIntent event. The service I am writing has to have events and listen for things. One is a LocationListener listening for GPS movement.

Develop Alarm Application

时光总嘲笑我的痴心妄想 提交于 2019-11-28 07:26:29
问题 I'd like develop an Alarm Application. The application should work like this: launch it the activity show me the time I can set the alarm I can close the application when the alarm time comes , it starts an activity (even if the device is locked) I have tried to adapt this sample https://github.com/commonsguy/cwac-wakeful but I cannot launch an activity when the alarm time comes. I use this code to setup the alarm (for test I have inserted this code on an onCreate method of activity): Intent

Android Reduce Size Of Camera Picture

冷暖自知 提交于 2019-11-27 19:56:12
UPDATE maybe changing the Bitmap size in the new Activity may fix the problem String myRef = this.getIntent().getStringExtra("filepath"); File imgFile = new File(myRef); Log.e("BeatEmUp", myRef); if(imgFile.exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); ImageView myImage = (ImageView) findViewById(R.id.imagepunch); myImage.setImageBitmap(myBitmap); } Something like this maybe? Bitmap scaled = Bitmap.createScaledBitmap(bit, 200, 200, true); Or Maybe this is the best way below So far I have my app which is taking a picture and then using an Intent to carry the

Why it is not possible to use ViewPager within a Fragment? It actually is

筅森魡賤 提交于 2019-11-27 06:27:40
There are information that it is impossible to use ViewPager within a Fragment in many sources like " The Busy Coders Guide for Android Developers " by Mark Murphy, or posts like this on SO. I'm confused because I don't have such a problem and I successfully use ViewPager within my Fragment . The only distinction is that I instantiate a ViewPager not in onCreateView() method but in onActivityCreated() . And everything works perfectly fine. So the question is - may be I just don't know something and this is not recommended for some reason to make UI instantiations in onActivityCreated() ? But

Android Reduce Size Of Camera Picture

谁都会走 提交于 2019-11-26 22:51:41
问题 UPDATE maybe changing the Bitmap size in the new Activity may fix the problem String myRef = this.getIntent().getStringExtra("filepath"); File imgFile = new File(myRef); Log.e("BeatEmUp", myRef); if(imgFile.exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); ImageView myImage = (ImageView) findViewById(R.id.imagepunch); myImage.setImageBitmap(myBitmap); } Something like this maybe? Bitmap scaled = Bitmap.createScaledBitmap(bit, 200, 200, true); Or Maybe this is

Why it is not possible to use ViewPager within a Fragment? It actually is

╄→гoц情女王★ 提交于 2019-11-26 12:54:08
问题 There are information that it is impossible to use ViewPager within a Fragment in many sources like \"The Busy Coders Guide for Android Developers\" by Mark Murphy, or posts like this on SO. I\'m confused because I don\'t have such a problem and I successfully use ViewPager within my Fragment . The only distinction is that I instantiate a ViewPager not in onCreateView() method but in onActivityCreated() . And everything works perfectly fine. So the question is - may be I just don\'t know