Monday, May 20, 2013

[android help] Removing common elements between two different Arraylist

java - Removing common elements between two different Arraylist - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















Sorry If you are thinking that it is a repeated post. But the situation is different here. I have read several posts for it but not getting the exact thing I am looking for. I know How to develop a complex logic for this but please take a look this is for android and we can't expect too much processing on the device due to to limited resources available.


I have an ArrayList of an bean class objects consisting five fields as


Java Bean -- MyShares


  1. fileName

  2. filePath

  3. fileSize

  4. isShared

  5. Creator

I have another ArrayList of String which contains only filepaths. Now what I want is to remove all the common elements between the two arraylist means the file paths in seconds arraylist and file path in first arraylist objects are similar then I have to remove from both of the arraylist But I Don't want a new arraylist which contains the uncommon elemenst But I want to get my both arraylist only without their common elements.


Please help me.





























You could use a Map from String to your object type (I used Obj in order to make a SSCCE).


Assume we are given a list objects and a list strings.


Steps:


  1. Put all objects in a map with their str variable as key

  2. Get all those str variables using map.keySet()

  3. Get all strings that are in objects but not in strings by keys.removeAll(strings)

  4. Get all strings that are in strings but not in objects by strings.removeAll(keys)

  5. Get the objects that correspond to the remaining keys

Note that you need to be careful in steps 3 and 4, because you need to back up one of the collections.



import java.util.*;

public class Test {
public static void main(String[] args) throws Exception {
new Test();
}

public Test() {
List objects = new ArrayList<>();
objects.add(new Obj("a"));
objects.add(new Obj("b"));
objects.add(new Obj("c"));

List strings = new ArrayList<>();
strings.add("a");
strings.add("d");
strings.add("e");

remove(objects, strings);

System.out.println(objects);
System.out.println(strings);
}

public void remove(List objects, List strings) {
Map map = new HashMap<>();
for (Obj object : objects) {
map.put(object.str, object);
}

Set keys = map.keySet();
List oldStrings = new ArrayList<>(strings);

strings.removeAll(keys);
keys.removeAll(oldStrings);

objects.clear();
for (String key: keys) {
objects.add(map.get(key));
}
}

public class Obj {
public String str;
public Obj(String str) {
this.str = str;
}
@Override
public String toString() {
return str;
}
}
}


Prints:



[b, c]
[d, e]

























Rough Java code:



HashSet commonKeys = new HashSet();
for (Share share : shares) {
commonKeys.add(share.filePath);
}
commonKeys.retainAll(filePaths);
for (Iterator it = shares.iterator(); it.hasNext(); ) {
Share share = it.next();
if (commonKeys.contains(share.filePath)) {
it.remove();
}
}
filePaths.removeAll(commonKeys);


This won't be O(N) because remove on an ArrayList is expensive. To get O(N) behavior you either need to create new ArrayList instances, or add the elements you don't want removed to temporary lists, and then clear() and add them back into the original lists.

























I will go with some clues for you


Suppose you have two lists one for bean objects namely myBeans and another for filePaths namely filePaths



List beansToRemove = new ArrayList();
List filePathsToRemove = new ArrayList();

for(Bean myBean : myBeans) {
for(FilePath filePath : filePaths) {
if(myBean.getfilePath.equals(filePath.getFilePath())) {
beansToRemove.add(myBean);
filePathsToRemove.add(filePath);
}
}
}

//Now remove filePaths and beans if any

for(Bean myBean : beansToRemove) {
myBeans.remove(myBean);
}

for(FilePath filePath : filePathsToRemove) {
filePaths.remove(filePath);
}


it is just a flow to make you clear for what to do; you can further customize it according to your needs.






















You can use an outer loop to scan over the Bean objects, and an inner loop to scan over the file paths.


pseudo code:



for (Bean i in beans) {
for (String p in paths) {
if (i.path.equals(p)) {
beansToRemove.add(i);
pathsToRemove.add(p);
}
}
}
beans.removeAll(beansToRemove);
paths.removeAll(pathsToRemove);


I'm not sure if my extra arraylists to track the removed arraylists go against your question or not since the original arrays remain. If you presort both arrays on the path and keep track of the position in each area (not exhaustive search) you can improve it from n2 to nlgn























lang-java






.

stackoverflow.comm

[android help] How to get the number of the largest value in a string


Ok, so I have the following string



String test= "0, 1, 3, 2, 2, 1, 1, 4, 2, 5, 1, 1, 0, 1, 241";


As you can see the largest value is the last one (241). I need to find a way to get the place of this String, not the number, so I need the result to be 15 (since 241 is the 15th number in the string, and the largest number in the row.


Another example



String test= "0, 1, 3, 2, 2, 1, 1, 4, 30, 5, 1, 1, 0, 1, 5";


Here the result should be 9 (since the highest number is on the 9th place in the string. But I have no idea how to do this, can anyone give me a good start?



.

stackoverflow.comm

Sunday, May 19, 2013

[General] How do I remove an account from the Play Store?


Version 4.0.4

I obtained an Android from a friend and created a second account for the Play Store. Now I want to remove the initial account (first on the list). It has as its ID a non Gmail account and I do not know the password associated with it.

I went into App settings and for Google Play Store clicked on Clear data. That did not remove either account.

What are the step to take to remove the initial account?



.

forum.xda-developers.com

[General] Anyone having location problem on their HTC One?


Hey,

Recently i got an On The Air Update for my HTC One, and i also updated my maps, google search too. On google now it will always show this card which say say to turn on my location services but i already turn it on. Is anyone having the same problem as me on their HTC One? Sorry if i didn't explain it in more details.



.

forum.xda-developers.com

[General] Cm 10 Reboot Loop P7500




Quote Originally Posted by Daniel Barbosa1 View Post

Good afternoon guys, something strange happened today on my tablet got cyanogem 10 installed and running on the tablet, when i go to market and installed the ebay application tablet reboot, and now will not start, I tried to format the partition / data tablet and after a few seconds Reboot...., can you help me? thank you



First some counter questions; are you sure the file you downloaded was for your exact model of device? Did you download and install the Google Apps file (gapps) and install that? Did you have any problems with the ROM before you went to Play?

If you have a copy of the stock ROM, I would reflash that, to start over. Next, retrace all your steps, making sure files are appropriate, etc. Cyanogen 10 is pretty widely used, but that doesn't mean you cancan flash it on anything.

What device is this?


.

forum.xda-developers.com

[General] customize folder look...


Hello all, i am a new android user, i got my new phone for about a week.
i played with it try to customize it for my needs, one thing that really disturb me is the way folder looks on the home page, not the icon of folder! but after u open a folder in your home screen i think it looks very nasty...
i would like to find a way to change that looks, i was google for it, and many people showed apps and ways to change the icon, but didnt found any way to change the looks of the folder it self, mainly i would like to change alpha and maybe color....
any ideas?
thanks a head for all replies...



.

forum.xda-developers.com

[android help] Android studio and gradle build error

Android studio and gradle build error - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I've been using the new preview of android studio and really like it. But recently my project won't build. I get the following error:



Gradle:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':TestProj:compileDebug'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.


Question is how do I enable the stack trace so I can get to the root of the error. As it is I really have no idea what's causing this.


























OK seems like a caching issue of some sort. There was indeed an error in code with the R.id.some_id not being found but the editor was not picking it up displaying that there were no errors.























I'm having the same issue. how did you manage to fix it?




















default






.

stackoverflow.comm

[android help] When I load ADT why do I receive the error "The Android SDK requires Android Developer Toolkit version XX.X.X or above?"

eclipse - When I load ADT why do I receive the error "The Android SDK requires Android Developer Toolkit version XX.X.X or above?" - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I just updated my Android SDK Tools to version 21.1. Unfortunately this is causing an error when I load the Android Developer Toolkit:



The Android SDK requires Android Developer Toolkit version 21.1.0 or above.


Current version is 21.0.1.2012-12-6-2-58.


Please update ADT to the latest version.



When I upgraded the SDK I was warned that I might need to upgrade ADT. I tried to do so by going to Help > Check for Updates. Unfortunately this returns a message that "No updates were found."


In case I've missed something here's a screenshot of my Android SDK Manager:


Android SDK Manager


Am I missing an install package? Do I need to go about updating ADT (Eclipse) another way? Should I just download a new copy of ADT?





























For some reason ADT (Eclipse) won't pick up on the fact that it does in fact need to be updated. Since the built in tools for updating are failing you you'll have to work around them. On the Help menu instead of selecting Check for Updates instead pick Install New Software (so Help > Install New Software).


On the Available Software screen in the Work With dropdown provide:
https://dl-ssl.google.com/android/eclipse/ if it's not already available. You should see a list of options including Developer Tools. Check everything that you want to update. In the list of checkboxes below uncheck "Contact all update sites during install to find required software."


Install New Software


Click Next and follow the remaining onscreen prompts. You may be warned that instead of an install an update will be performed. This is okay. Once the operation is complete you will no longer receive the "The Android SDK requires Android Developer Toolkit verxion 21.1.0 or above" error when you load ADT.




















default






.

stackoverflow.comm

[android help] maven dependency installation failure

android - maven dependency installation failure - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I am building an Android project with Eclipse and maven plugins. When I build it I get the error as following



27/1/12 2:34:02 PM IST: Build errors for ProjectName; org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal


com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.2.1:generate-sources (default-generate-sources) on project ProjectName: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:maven-android-plugin:2.2.1:generate-sources failed: Please provide a proper Android SDK directory path as configuration parameter ... in the plugin .


As an alternative, you may add the parameter to commandline: -Dandroid.sdk.path=... or by setting environment variable ANDROID_HOME



Even if I have set the ANDROID_HOME and path in ...





























Besides ANDROID_HOME environment variable, you also need add $ANDROID_HOME/tools and $ANDROID_HOME/platform-tools to your PATH environment variable:



Maven 3.0.3+ installed, see http://maven.apache.org/download.html


  1. Set environment variable ANDROID_HOME to the path of your installed Android SDK and add $ANDROID_HOME/tools as well as $ANDROID_HOME/platform-tools to your $PATH. (or on Windows %ANDROID_HOME%\tools and %ANDROID_HOME%\platform-tools).

  2. MacOS users: Note that for the path to work on the commandline and in IDE's started by launchd you have to set it in /etc/launchd.conf and NOT in .bashrc or something else


Check out the Getting Started page on android maven plugin website here.


Hope this help.























You also need to set the path location of the Android SDK in Eclispe as well, otherwise the m2e-android build will fail:


Go to Window -> Preferences and select Android. Click on the Browse... button next to the SDK Location text box and select the location of you locally installed Android SDK. Click Apply and then OK and your build should now work.




















default






.

stackoverflow.comm

[android help] Android will crash depending on layout positioning


Here's the layout that works :



xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip" >


android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
tools:context=".MainActivity" >





and here my Activity OnCreate method:



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pager = (ViewPager) findViewById(R.id.pager);

adapter = new MyPagerAdapter(getSupportFragmentManager());

pager.setAdapter(adapter);

tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);
tabs.setDividerColor(Color.BLUE);
tabs.setBackgroundColor(Color.DKGRAY);
tabs.setTextColor(Color.WHITE);
tabs.setIndicatorColor(Color.GREEN);

}


If in the layout I inverse the PagerSlidingTabStrip and the ViewPager, the project will crash at startup, while in the first implementation, it will work fine.


Here's the error :



05-19 16:50:11.636: E/AndroidRuntime(305): FATAL EXCEPTION: main
05-19 16:50:11.636: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hsware.peeem/com.hsware.peeem.MainActivity}: java.lang.ClassCastException: android.support.v4.view.ViewPager
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.os.Looper.loop(Looper.java:123)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-19 16:50:11.636: E/AndroidRuntime(305): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 16:50:11.636: E/AndroidRuntime(305): at java.lang.reflect.Method.invoke(Method.java:521)
05-19 16:50:11.636: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-19 16:50:11.636: E/AndroidRuntime(305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-19 16:50:11.636: E/AndroidRuntime(305): at dalvik.system.NativeStart.main(Native Method)
05-19 16:50:11.636: E/AndroidRuntime(305): Caused by: java.lang.ClassCastException: android.support.v4.view.ViewPager
05-19 16:50:11.636: E/AndroidRuntime(305): at com.hsware.peeem.MainActivity.onCreate(MainActivity.java:41)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-19 16:50:11.636: E/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)


It appears that it can't retrieve de R.id.pager, I'm not sure.



.

stackoverflow.comm

[android help] How to construct a button on runtime (Android)


There's nothing on this particular feature of Android in the documentation (for example here:


http://developer.android.com/reference/android/widget/Button.html#Button(android.content.Context)


How do i add a button to exsiting layout (or create a layout on runtime as well)?


And then, how do i apply attributes to said button i've just created?



.

stackoverflow.comm

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...