Skip to main content

Home/ Android Dev/ Group items tagged Java

Rss Feed Group items tagged

Vincent Tsao

How to disable a button on an appwidget? | Hello Android - 0 views

  • RemoteViews can't manipulate a buttons enabled/disabled state, but it can modify its visibility. So the trick is to have two buttons, the real one, and an other which is designed to look like the real one in disabled state, and change witch one is visible.
  • <Button android:id="@+id/startbutton" android:text="Start" android:visibility="visible"></Button> <Button android:id="@+id/startbutton_disabled" android:text="Start" android:clickable="false" android:textColor="#999999" android:visibility="gone"></Button>   <Button android:id="@+id/stopbutton" android:text="Stop"  android:visibility="gone"></Button> <Button android:id="@+id/stopbutton_disabled" android:text="Stop" android:clickable="false" android:textColor="#999999" android:visibility="visible"></Button>
  • RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget); remoteView.setViewVisibility(R.id.startbutton, View.GONE); remoteView.setViewVisibility(R.id.startbutton_disabled, View.VISIBLE); remoteView.setViewVisibility(R.id.stopbutton, View.VISIBLE); remoteView.setViewVisibility(R.id.stopbutton_disabled, View.GONE); AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);
  • ...1 more annotation...
  • RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget); remoteView.setViewVisibility(R.id.startbutton, View.VISIBLE); remoteView.setViewVisibility(R.id.startbutton_disabled, View.GONE); remoteView.setViewVisibility(R.id.stopbutton, View.GONE); remoteView.setViewVisibility(R.id.stopbutton_disabled, View.VISIBLE); AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteView);
Vincent Tsao

google-gson - Project Hosting on Google Code - 1 views

  • Gson is a Java library that can be used to convert Java Objects into its JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.
Vincent Tsao

using Java to get a file's md5 checksum? - Stack Overflow - 0 views

  • java.security.DigestInputStream
  • MessageDigest md = MessageDigest.getInstance("MD5");InputStream is = new FileInputStream("file.txt");try {  is = new DigestInputStream(is, md);  // read stream to EOF as normal...}finally {  is.close();}byte[] digest = md.digest();
Simon Pan

Tech Droid: Android WebView, Javascript and CSS - 5 views

  • Calling a Javascript method from your Java code: webView.loadUrl("javascript:jsToggle()"); Calling a Java method from Javascript: window.jsinterface.nativeToggle(); /*   // Before using the above code, you have to inject the interface object which   // has a name "jsinterface"   webView.addJavascriptInterface(jsInterface, "jsinterface"); */
    • Vincent Tsao
       
      useful tips
    • Simon Pan
       
      Is it use to auto-fill the form on WebView?
    • Vincent Tsao
       
      JSInterface lets you bind Java objects into the WebView so they can be controlled from the web pages JavaScript, which means we can do anything to the content from webview via javascript interface, like what we can do with the html DOM content with javascrpit
    • Simon Pan
       
      So, Can I retain username and password by this manner?
    • Vincent Tsao
       
      i think so, you can fill form field with jsinterface
    • Simon Pan
       
      thank you...go on together
Vincent Tsao

Avoiding Memory Leaks | Android Developers - 0 views

  • As part of my job, I ran into memory leaks issues in Android applications and they are most of the time due to the same mistake: keeping a long-lived reference to a Context.
  • There are two easy ways to avoid context-related memory leaks. The most obvious one is to avoid escaping the context outside of its own scope. The example above showed the case of a static reference but inner classes and their implicit reference to the outer class can be equally dangerous. The second solution is to use the Application context. This context will live as long as your application is alive and does not depend on the activities life cycle. If you plan on keeping long-lived objects that need a context, remember the application object. You can obtain it easily by calling Context.getApplicationContext() or Activity.getApplication().
  • In summary, to avoid context-related memory leaks, remember the following: Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself) Try using the context-application instead of a context-activity Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside. The solution to this issue is to use a static inner class with a WeakReference to the outer class, as done in ViewRoot and its W inner class for instance A garbage collector is not an insurance against memory leaks
Vincent Tsao

Fragments | Android Developers - 1 views

  • If you add multiple changes to the transaction (such as another add() or remove()) and call addToBackStack(), then all changes applied before you call commit() are added to the back stack as a single transaction and the BACK key will reverse them all together.
    • Vincent Tsao
       
      what's the point to provide such  mechanism?
  • The most significant difference in lifecycle between an activity and a fragment is how one is stored in its respective back stack. An activity is placed into a back stack of activities that's managed by the system when it's stopped, by default (so that the user can navigate back to it with the BACK key, as discussed in Tasks and Back Stack). However, a fragment is placed into a back stack managed by the host activity only when you explicitly request that the instance be saved by calling addToBackStack() during a transaction that removes the fragment.
  • In some cases, you might need a fragment to share events with the activity. A good way to do that is to define a callback interface inside the fragment and require that the host activity implement it. When the activity receives a callback through the interface, it can share the information with other fragments in the layout as necessary.
  •  
    好特別、好酷的一個類
Kiran Kuppa

AndroidAnnotations - 0 views

  •  
    Using Java annotations, developers can show their intent and let AndroidAnnotations generate the plumbing code at compile time. Few Features are * Dependency injection: inject views, extras, system services, resources, ... * Simplified threading model: annotate your methods so that they execute on the UI thread or on a background thread. * Event binding: annotate methods to handle events on views, no more ugly anonymous listener classes! * REST client: create a client interface, AndroidAnnotations generates the implementation. * AndroidAnnotations provide those good things and even more for less than 50kb, without any runtime perf impact!
Kiran Kuppa

Android Essentials: Creating Android-Compliant Libraries - Tuts+ Code Tutorial - 1 views

  •  
    For a library to be compatible with Android, it can only reference classes available as part of Android and other classes implemented specifically in the library itself.Android Libraries can contain Java classes, resources, and other project information, but not assets. They can reference other libraries and leverage third party JAR files. They have Android manifest files just like regular Android projects. However, they differ from normal Android projects in an important way: they cannot be compiled into their own application packages or deployed onto devices. They can also not be exported as standalone JAR files. Once referenced from an Android project, the library components are incorporated into the Android application that references them at build time and added to the application package. There is no need to declare the component as the library classes are rolled into the APK directly. In terms of compatibility, the Android project must have an API Level higher than or equal to the API Level set in the Android library.
Vincent Tsao

putExtra error on AppWidget - Android Developers | Google Groups - 0 views

  • I am just making some AppWidget and I want to pass some Strings through UpdateView to an Activity. But the Bundle is null. I try this: -Widget.java                       Intent defineIntent = new Intent(context, Visor.class);                        defineIntent.putExtra ("org.rss.androides.post2","artist");                        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, defineIntent, 0);                        updateViews.setOnClickPendingIntent (R.id.widget, pendingIntent); -Viewer.java           Bundle b = intent.getExtras();                 if (b == null) {                     finish();                     return;                 } b is always null.
  • Remember that PendingIntents aren't keyed using extras: http://groups.google.com/group/android-developers/msg/b296f43ae70c4587 You could hack the extras through by mangling them into Uri parameters, or if you're using a ContentProvider, just point to a specific row.
  • Or use PendingIntent.FLAG_UPDATE_CURRENT; just be careful that each active instance has its own unique Intent.
Vincent Tsao

Exploring the world of Android :: Part 2 « JTeam Blog / JTeam: Enterprise Jav... - 1 views

  • But in practice, you will notice that the AsyncTask is limited to 10 threads. This number is hardcoded somewhere in the Android SDK so we cannot change this. In this case it’s a limitation we cannot live with, because often more than 10 images are loaded at the same time.
    • Vincent Tsao
       
      使用AsyncTask类开辟的线程还有数量限制?必须小于10,这个倒是以前没有注意到的,要看看源代码怎么实现的
  • I’ve shown you how to improve performance of a ListView in three different ways: By loading images in a seperate thread By reusing rows in the list By caching views within a row
  • ...1 more annotation...
  • Notice that I used a SoftReference for caching images, to allow the garbage collector to clean the images from the cache when needed. How it works: Call loadDrawable(imageUrl, imageCallback) providing an anonymous implementation of the ImageCallback interface If the image doesn’t exist in the cache yet, the image is downloaded in a separate thread and the ImageCallback is called as soon as the download is complete. If the image DOES exist in the cache, it is immediately returned and the ImageCallback is never called.
  •  
    这个帖子完美解决了Image lazy load的性能问题, it works~
Vincent Tsao

Android: java.lang.SecurityException: Permission Denial: start Intent - Stack Overflow - 1 views

  •  
    我也遇到了相同问题,但是为什么这种办法就解决了问题呢,谁能解释?
Vincent Tsao

OrmLite - Lightweight Object Relational Mapping (ORM) Java Package - 0 views

shared by Vincent Tsao on 20 Sep 11 - No Cached
  •  
    shared by Tank
Vincent Tsao

Java Code Geeks - 2 views

  •  
    Anyone who familiar with this community?
1 - 20 of 36 Next ›
Showing 20 items per page