Friday, April 12, 2013

[android help] From BufferredImage to Byte[] without IO ---- failed


I am attempting to take continuous screenshots and stream them over a socket to my android phone. I used ImageIO for this like this:



while(true){
baos = new ByteArrayOutputStream();
ImageIO.write(screenshot, "png", baos);
byte[] imageArray = baos.toByteArray();
oos.writeInt(imageArray.length);
oos.write(imageArray);
oos.flush();
imageArray = null;
}


This worked fine, however, there was huge lag time in the pictures showing up on the phone, and I figured it was because of the ImageIO. so I looked around in stackoverflow for a solution to this, and found this method and tried it:



while(true){
//take screenshot of the screen periodically and send to the server
screenshot = robot.createScreenCapture(rectangle);
byte[] imageArray = ((DataBufferByte)screenshot.getRaster().getDataBuffer()).getData();
oos.writeInt(imageArray.length);
oos.write(imageArray);
oos.flush();
imageArray = null;
}


But this keeps giving me this exception:



Exception in thread "main" java.lang.ClassCastException: java.awt.image.DataBufferInt
cannot be cast to java.awt.image.DataBufferByte


Can someone please help?



.

stackoverflow.comm

[android help] Local Time to GMT/UTC Time


OK, I have a 2 time viewers (DigitalClock in Eclipse), sadly, in the same time zone (set to the phone). How would I change one of these to a UTC time?



.

stackoverflow.comm

[android help] How to use OpenGL ES 2.0? I just don't get it, Serious Q


This is a serious question, I am "stuck" at this point between understanding it and not at all. I got very confused with the time reading different resources and would like someone to point me in the right direction.


I am working with android platform, until now I have used the Canvas; some openGL ES 1.0, but mostly through engines or already built code to try and understand it.


My goal is to ACTUALLY understand OpenGL ES 2.0 . I do not want to go straight to the complicated stuff and start with easy stuff, but i just don't get how to do it. I can get a square, and I can set up a camera and matrices; to tell you the truth I really don't understand the whole matrix system and how it works, if I am right it was a fixed pipeline which you didn't need to change in openGL ES 1.0 but not it's an open pipeline which you have to set up on your own.


I do not get how to use the coordinate system, I know that the origin is the center of the device and each turn to the edge is 1, so from center to left it would be negative 1.


There were some ways however to make it into a different coordinate system, maybe just use proportions or multiply matrices to set the coordination to something that i was used to from the canvas.


Basically what I need help with is how do I progress from here? I feel as if I got to somewhere, but I am still nowhere.


I really need some advises on how to properly use OpenGL ES 2.0, for now all i am planning on is a simple 2d game, maybe side scroller too so i will have to mess with the camera matrices.


Thank you for your time, I will greatly appreciate any help.


*i am less interested in the transformation matrices since i do not think that 2d game would really use that, maybe only when i mirror the character's sprite so it would look as if he is walking the different direction, but im pretty sure this is possible to be made simple by changing the coordination and width.



.

stackoverflow.comm

[android help] Android create four buttons with even weight distribution programmatically


I am having major issues getting my program to properly display 4 buttons, side by side, with the same width. I have tried a bunch of combinations, and spent over an hour on StackOverflow searching solutions, with no luck on any of them. How can I go about making these four buttons all with the same height in the same row on a vertical interface?


This is what I have so far with no luck. Either buttons too large, too small, or are hidden since width 0.



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
layout.setWeightSum(1);

Button redButton = new Button(this);
redButton.setText("Red");
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
0,
LayoutParams.WRAP_CONTENT,
0.25f);
redButton.setWidth(0);
redButton.setLayoutParams(p);
layout.addView(redButton);

Button greenButton = new Button(this);
greenButton.setText("Green");
greenButton.setLayoutParams(p);
greenButton.setWidth(0);
layout.addView(greenButton);

Button blueButton = new Button(this);
blueButton.setText("Blue");
blueButton.setLayoutParams(p);
blueButton.setWidth(0);
layout.addView(blueButton);

Button yellowButton = new Button(this);
yellowButton.setText("Yellow");
yellowButton.setLayoutParams(p);
yellowButton.setWidth(0);
layout.addView(yellowButton);

setContentView(layout);
}


.

stackoverflow.comm

[android help] How to add class with listview to a viewpager


I'm very new to Android, so forgive me if this is a terrible question, but I've searched high and low and I've been reading lots of material and can't seem to figure this out. I've created an app in Eclipse using one of the default views (fixed tabs + swipe). I created a second class with a listview and I'm trying to add this class to load in one of the tabs.


EDIT to include full MainActivity.java



package com.sonnyparlin.gracietampa;

import java.util.Locale;
import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {

SectionsPagerAdapter mSectionsPagerAdapter;

/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;

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

// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);

// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});

// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}

@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}

/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new DummySectionFragment();
Bundle args = new Bundle();
args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
fragment.setArguments(args);
return fragment;
}

@Override
public int getCount() {
// Show 3 total pages.
return 3;
}

@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
case 2:
return getString(R.string.title_section3).toUpperCase(l);
}
return null;
}
}

/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";

public DummySectionFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView;

if (getArguments().getInt(ARG_SECTION_NUMBER) == 1) {
rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.section_label);
dummyTextView.setText(Html.fromHtml(getString(R.string.page1text)));
} else if (getArguments().getInt(ARG_SECTION_NUMBER) == 2) {


// I want to add my listview here


} else {
rootView = inflater.inflate(R.layout.fragment_main_dummy,
container, false);
TextView dummyTextView = (TextView) rootView
.findViewById(R.id.section_label);
dummyTextView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
}
return rootView;
}
}

}


My TechniqueActivity.java file:



public class TechniqueActivity extends ListActivity{

public TechniqueActivity() {
// TODO Auto-generated constructor stub
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// storing string resources into Array
String[] technique_list = getResources().getStringArray(R.array.technique_list);

// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter(this, R.layout.list_item, R.id.label, technique_list));

}

}


I would really appreciate it if someone could point me in the right direction so that I can populate the second tab of my application with the listview I've created in TechniqueActivity.java. Or maybe there's a completely different / better way of doing it?



.

stackoverflow.comm

[android help] How to know "Don't keep activities" is enabled in ICS?


I agree with @Kaediil that android applications must work well while "Don't keep activities" option is checked.


Bu for some reason if you have to check "alwaysFinishActivities" value you can use code below;



/**
* returns true if AlwaysFinishActivities option is enabled/checked
*/
private boolean isAlwaysFinishActivitiesOptionEnabled() {
int alwaysFinishActivitiesInt = 0;
if (Build.VERSION.SDK_INT >= 17) {
alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES, 0);
} else {
alwaysFinishActivitiesInt = Settings.System.getInt(getApplicationContext().getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES, 0);
}

if (alwaysFinishActivitiesInt == 1) {
return true;
} else {
return false;
}
}


If alwaysFinishActivities option is checked and you want it to be unchecked;


You can direct user to "Settings -> Developer options" to uncheck that value. (This is better than to get extra scary permissions and set this value programatically)



/**
* shows Settings -> Developer options screen
*/
private void showDeveloperOptionsScreen(){
Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
}


.

stackoverflow.comm

[General] Memory Card problem


Are you sure you can download Spotify music to your external card? I'm not sure, but I'm guessing that with both apps, you can only download music to internal storage, not external, so it probably won't matter how big a card you insert.

Sent from my DROID RAZR using Android Central Forums



.

forum.xda-developers.com

[android help] How to load image thumbnail fast android?

caching - How to load image thumbnail fast android? - Stack Overflow




















I have a custom gallery in my app for which I'm using my own thumbnail directory. Here I'm caching the image thumbnail and storing it on my own sdcard directory and showing the thumbnail by loading it from custom image directory. It works well, but if it has more pictures it takes too long to load. Is there any way to load it faster and i don't use android's default thumbnail directory.





























I guess you are loading them on the main thread. Try using an AsyncTask to load each thumbnail. First check if the thumbnail is cached and return it. If not - download, cache and return.























Have you tried using something like Smart Image View?


It already caches an image and save to external (in case you are trying to get an image from a server, for example).


It also uses a thread pool executor, so you won't have problems with asynctask (like here).


But smart image view is just an example, there are lot's of projects out there.






















You can also try ImageLoader Library.


It caches images transparently with a two-level in-memory/SD card caching strategy. Images are fetched in a background thread, keeping your UI responsive.


There is also great documentation and a demo application.






















You can use AsyncTask to load image in dynamic drawable faster as you want.




















default







.

stackoverflow.comm

[General] help!


I have a galaxy s Blaze 4G and i recently have been having trouble with. When i put in my beats by dre ear buds, only my right bud plays audio while the left bud plays no audio! Any help ?



.

forum.xda-developers.com

[General] Hide mp3 files from Music player


I've dumped my thumb drive and now use my smartphone (HTC V One) for the same purpose. One side effect is I now have a couple directories full of mp3 files that I'd like to hide from the music player (no, they aren't those kinds of files. They're work related, not music).

Is it possible to hide directories from the music player? Even better, can I tell the music player to only look under 'My Music' on the SD card?



.

forum.xda-developers.com

[android help] How to install an Android application on a real device without publishing and Eclipse?

deployment - How to install an Android application on a real device without publishing and Eclipse? - Stack Overflow




















How can I install an application without any developer tools (Eclipse, Android SDK tools)?


I've compiled and created an .apk file. Now I am gonna send this apk file to my friend.


He is not an Android developer; he doesn't know how to use Eclipse or the SDK. And I don't want to publish my application to android market.


Is there a way to launch the application on a real device without publishing it or having access to a machine with the SDK?





























You can deploy the .apk file on your local server(apache or jboss) with a static IP to make the file available for download. Now just open the download link of the apk file in your mobile browser. The device will automatically start the installation after the download completes.























The way I usually do this is:


  1. Plug in my USB cable to my PC and mount my SD card on my computer

  2. Get the APK file somewhere on my SD card on the phone

  3. Unmount the SD card on my PC, allowing the phone to see the SD card contents again

  4. Use Astro File Manager or some similar app to browse to that file on the SD card and select it, which will prompt you if you want to install the app on your phone.





















You should set Settings -> Application -> Unknown sources to allow installation from non-Market. Then, once your application is published somewhere, you can download it an install it.






















Also you can use 'adb install ' to install apk's to your device.


Though this approach requires you to have adb available on your computer and adb is part of the sdk.


Another, easier approach, is using DropBox. This enables you to save the apk in the dropbox/public folder, create a URI from there and supply this to your friend. Then have him download the apk. Android will notify him when it's done, so he only has to click the notification and Android will ask him whether or not he wants to install this software.






















Hopefully you will find the answer from here Install Android application on Android Device


Add your APK file to your device SD card and run it, you must allow to install non-market application on your device before you going to install.


Go to Setting -> Application Setting ->Unknown Source and tick check box which will allow to install non-market application on your device






















Use DeployGate.


Just upload your app and share privately via distribution page. It will guide your friend to install your app and you can see how is going, e.g. which version is installed or updated, or app is crashed, in realtime.


Though it's a very common question, there were no simple way to achieve it. Even if we can send the apk via any way, we need to change the non-Market setting and get asked for help of this kind everyday. It's simply a hassle. So we made DeployGate, a tester-friendly private app distribution service to help the developers just like you ;)

























what i usually do is: 1. Through mail: i send the .apk to their mail id. 2. do open his mail in his mobile. and download the attached .apk. 3. it will ask for installation and do run.























default







.

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...